Commit f10b1857 by xinla

Merge branch 'master' into xxj-智能短链-2023.01.11

2 parents 18147b3d afca2e1f
// 带 插入 表情/客户昵称 等扩展工具栏的文本内容框
<script>
export default {
name: '',
props: {
value: '',
// ['emoji','insertCustomerNickName']
toolbar: {
type: Array,
default: () => ['emoji'],
export default {
name: '',
props: {
value: '',
// ['emoji','insertCustomerNickName']
toolbar: {
type: Array,
default: () => ['emoji']
}
},
},
components: {
SelectEmoji: () => import('@/components/SelectEmoji'),
},
data() {
return {}
},
computed: {
proxyValue: {
get() {
return this.value
},
set(val) {
this.$emit('input', val)
},
components: {
SelectEmoji: () => import('@/components/SelectEmoji')
},
},
watch: {},
created() {},
mounted() {},
methods: {
// 插入内容
insertContent(value) {
const $textarea = this.$refs.textarea.$el.children[0]
const content = this.proxyValue || ''
const textIndex = $textarea.selectionStart
this.proxyValue = content.slice(0, textIndex) + value + content.slice(textIndex)
data() {
return {}
},
},
}
computed: {
proxyValue: {
get() {
return this.value
},
set(val) {
this.$emit('input', val)
}
}
},
watch: {},
created() {},
mounted() {},
methods: {
// 插入内容
insertContent(value) {
const $textarea = this.$refs.textarea.$el.children[0]
const content = this.proxyValue || ''
const textIndex = $textarea.selectionStart
this.proxyValue = content.slice(0, textIndex) + value + content.slice(textIndex)
}
}
}
</script>
<template>
......@@ -55,4 +55,8 @@ export default {
</div>
</template>
<style lang="scss" scoped></style>
<style lang="scss" scoped>
textarea {
white-space: pre-wrap; //保留所有空格
}
</style>
......@@ -16,214 +16,152 @@
</template>
<script>
import { constantRoutes } from '@/router'
import { isExternal } from '@/utils/validate'
import { constantRoutes } from '@/router'
import { isExternal } from '@/utils/validate'
export default {
data() {
return {
name: '',
// 顶部栏初始数
visibleNumber: 5,
// 是否为首次加载
isFrist: false,
// 当前激活菜单的
currentIndex: ''
}
export default {
data() {
return {
// name: '',
// 顶部栏初始数
visibleNumber: 5,
// 是否为首次加载
isFrist: false,
// 当前激活菜单的
currentIndex: '',
}
},
computed: {
theme() {
return this.$store.state.settings.theme
},
computed: {
theme() {
return this.$store.state.settings.theme
},
// 顶部显示菜单
topMenus() {
let topMenus = []
this.routers.map((menu) => {
if (menu.hidden !== true) {
// 兼容顶部栏一级菜单内部跳转 (you bug)
// if (menu.path === '/') {
// topMenus.push(menu.children[0])
// } else {
// }
topMenus.push(menu)
}
})
return topMenus
},
// 所有的路由信息
routers() {
return this.$store.state.permission.topbarRouters
},
// 设置子路由
childrenMenus() {
var childrenMenus = []
this.routers.map((router) => {
for (var item in router.children) {
if (router.children[item].parentPath === undefined) {
if (router.path === '/') {
router.children[item].path = router.children[item].path
} else {
if (!this.ishttp(router.children[item].path)) {
router.children[item].path = router.path + '/' + router.children[item].path
}
}
router.children[item].parentPath = router.path
}
childrenMenus.push(router.children[item])
}
})
return constantRoutes.concat(childrenMenus)
},
// 默认激活的菜单
activeMenu() {
const path = this.$route.path
let activePath = this.defaultRouter()
if (path.lastIndexOf('/') > 0) {
const tmpPath = path.substring(1, path.length)
activePath = '/' + tmpPath.substring(0, tmpPath.indexOf('/'))
}
// else if ('/index' == path || '' == path) {
// if (!this.isFrist) {
// this.isFrist = true
// activePath = '/index'
// } else {
// activePath = '/index'
// }
// }
var routes = this.activeRoutes(activePath)
if (routes.length === 0) {
activePath = path
// 顶部显示菜单
topMenus() {
let topMenus = []
this.routers.map((menu) => {
if (menu.hidden !== true) {
// 兼容顶部栏一级菜单内部跳转 (you bug)
// if (menu.path === '/') {
// topMenus.push(menu.children[0])
// } else {
// }
topMenus.push(menu)
}
return activePath
}
})
return topMenus
},
beforeMount() {
window.addEventListener('resize', this.setVisibleNumber)
routers() {
return this.$store.state.permission.topbarRouters
},
beforeDestroy() {
window.removeEventListener('resize', this.setVisibleNumber)
// 默认激活的一级菜单路径 eg:/drainageCode
activeMenu() {
const path = this.$route.path
let activePath = this.routers.filter((e) => !e.hidden).path
if (path.lastIndexOf('/') > 0) {
activePath = path.substring(0, path.indexOf('/', 1))
}
var routes = this.activeRoutes(activePath)
if (routes.length === 0) {
activePath = path
}
return activePath
},
mounted() {
this.setVisibleNumber()
this.setName()
// this.handleSelect(this.topMenus[0].path)
},
beforeMount() {
window.addEventListener('resize', this.setVisibleNumber)
},
beforeDestroy() {
window.removeEventListener('resize', this.setVisibleNumber)
},
mounted() {
this.setVisibleNumber()
// this.setName()
// this.handleSelect(this.topMenus[0].path)
},
methods: {
// setName() {
// this.topMenus.map((dd) => {
// if (this.activeMenu == dd.path) {
// this.name = dd.meta.title
// }
// })
// },
// 根据宽度计算设置显示栏数
setVisibleNumber() {
const width = document.body.getBoundingClientRect().width / 3
this.visibleNumber = parseInt(width / 85)
},
methods: {
setName() {
this.topMenus.map((dd) => {
if (this.activeMenu == dd.path) {
this.name = dd.meta.title
}
})
},
// 根据宽度计算设置显示栏数
setVisibleNumber() {
const width = document.body.getBoundingClientRect().width / 3
this.visibleNumber = parseInt(width / 85)
},
// 默认激活的路由
defaultRouter() {
let router
Object.keys(this.routers).some((key) => {
if (!this.routers[key].hidden) {
router = this.routers[key].path
return true
}
})
return router
},
// 菜单选择事件
handleSelect(path, keyPath) {
this.currentIndex = path
let index = ''
this.topMenus.map((dd, cc) => {
if (path == dd.path) {
this.name = dd.meta.title
index = cc
}
})
if (this.ishttp(path)) {
// http(s):// 路径新窗口打开
window.open(path, '_blank')
} else if (path.indexOf('/redirect') !== -1) {
// /redirect 路径内部打开
this.$router.push({ path: path.replace('/redirect', '') })
} else {
// 显示左侧联动菜单
// if (path === '/index') {
// this.$router.push(path)
// } else {
// }
this.activeRoutes(path)
let obj = this.topMenus[index]
// let path = this.topMenus[index].children[0].path
// console.log(this.topMenus[index].children[0])
let path = ''
if (obj.children && obj.children.length) {
path = path + obj.children[0].path
}
if (obj.children[0].children && obj.children[0].children.length) {
path = path + '/' + obj.children[0].children[0].path
}
if (!isExternal(path)) {
this.$router.push({ path })
}
}
},
// 当前激活的路由
activeRoutes(key) {
var routes = []
if (this.childrenMenus && this.childrenMenus.length > 0) {
this.childrenMenus.map((item) => {
if (key == item.parentPath) {
routes.push(item)
}
})
// 菜单选择事件
handleSelect(path, keyPath) {
this.currentIndex = path
let index = ''
this.topMenus.map((dd, cc) => {
if (path == dd.path) {
// this.name = dd.meta.title
index = cc
}
if (routes.length > 0) {
this.$store.commit('SET_SIDEBAR_ROUTERS', routes)
})
if (this.ishttp(path)) {
// http(s):// 路径新窗口打开
window.open(path, '_blank')
} else if (path.indexOf('/redirect') !== -1) {
// /redirect 路径内部打开
this.$router.push({ path: path.replace('/redirect', '') })
} else {
this.activeRoutes(path)
if (!isExternal(path)) {
this.$router.push({ path })
}
return routes
},
ishttp(url) {
return url.indexOf('http://') !== -1 || url.indexOf('https://') !== -1
}
}
}
},
// 当前激活的路由
activeRoutes(path) {
let routes = this.routers.filter((e) => e.path == path)
if (routes.length > 0) {
this.$store.commit('SET_SIDEBAR_ROUTERS', routes)
}
return routes
},
ishttp(url) {
return /^(\/|http)/.test(url)
},
},
}
</script>
<style lang="scss">
.el-menu {
background-color: transparent !important;
}
.el-menu.el-menu--horizontal {
border: none !important;
}
.el-menu--horizontal > .el-menu-item {
float: left;
height: 50px !important;
line-height: 50px !important;
color: #fff !important;
// padding: 0 5px !important;
margin: 0 10px !important;
}
.el-menu-item:hover {
background-color: transparent !important;
}
.el-menu {
background-color: transparent !important;
}
.el-menu.el-menu--horizontal {
border: none !important;
}
.el-menu--horizontal > .el-menu-item {
float: left;
height: 50px !important;
line-height: 50px !important;
color: #fff !important;
// padding: 0 5px !important;
margin: 0 10px !important;
}
.el-menu-item:hover {
background-color: transparent !important;
}
.el-menu--horizontal > .el-menu-item.is-active,
.el-menu--horizontal > .el-submenu.is-active .el-submenu__title {
border-bottom: 2px solid #fff !important;
// color: #303133;
}
.el-menu--horizontal > .el-menu-item.is-active,
.el-menu--horizontal > .el-submenu.is-active .el-submenu__title {
border-bottom: 2px solid #fff !important;
// color: #303133;
}
/* submenu item */
.el-menu--horizontal > .el-submenu .el-submenu__title {
float: left;
height: 50px !important;
line-height: 50px !important;
color: #999093 !important;
padding: 0 5px !important;
margin: 0 10px !important;
}
/* submenu item */
.el-menu--horizontal > .el-submenu .el-submenu__title {
float: left;
height: 50px !important;
line-height: 50px !important;
color: #999093 !important;
padding: 0 5px !important;
margin: 0 10px !important;
}
</style>
......@@ -30,8 +30,12 @@ import visitor from '@/layout/visitor'
}
*/
// 开发路由,总后台配置完菜单务必删除或注释,只在开发环境生效
const devRoutes = []
export let devRoutes = []
// 开发环境路由,总后台配置完菜单务必删除或注释,只在开发环境生效
if (process.env.VUE_APP_ENV === 'development') {
devRoutes = devRoutes.concat()
}
// 公共路由
export const constantRoutes = [
......@@ -44,26 +48,26 @@ export const constantRoutes = [
isNoLogin: true,
},
},
{
path: '/drainageCode/qrCode',
component: Layout,
hidden: true,
meta: {
title: '客群活码',
},
children: [
{
path: 'analyse',
name: 'group-code-analyse',
component: (resolve) => require(['@/views/drainageCode/group/analyse'], resolve),
meta: {
title: '活码统计',
activeMenu: '/drainageCode/qrCode/customerGroup',
breadcrumb: true,
},
},
],
},
// {
// path: '',
// component: Layout,
// hidden: true,
// meta: {
// title: '客群活码',
// },
// children: [
// {
// path: '/drainageCode/qrCode/analyse',
// name: 'group-code-analyse',
// component: (resolve) => require(['@/views/drainageCode/group/analyse'], resolve),
// meta: {
// title: '活码统计',
// activeMenu: '/drainageCode/qrCode/customerGroup',
// breadcrumb: true,
// },
// },
// ],
// },
{
path: '/redirect',
component: Layout,
......
const getters = {
sidebar: state => state.app.sidebar,
size: state => state.app.size,
device: state => state.app.device,
visitedViews: state => state.tagsView.visitedViews,
cachedViews: state => state.tagsView.cachedViews,
token: state => state.user.token,
avatar: state => state.user.avatar,
name: state => state.user.name,
introduction: state => state.user.introduction,
roles: state => state.user.roles,
permissions: state => state.user.permissions,
configParamInfo: state => state.user.configParamInfo,
permission_routes: state => state.permission.routes,
topbarRouters: state => state.permission.topbarRouters,
defaultRoutes: state => state.permission.defaultRoutes,
sidebarRouters: state => state.permission.sidebarRouters,
sidebar: (state) => state.app.sidebar,
size: (state) => state.app.size,
device: (state) => state.app.device,
visitedViews: (state) => state.tagsView.visitedViews,
cachedViews: (state) => state.tagsView.cachedViews,
token: (state) => state.user.token,
avatar: (state) => state.user.avatar,
name: (state) => state.user.name,
introduction: (state) => state.user.introduction,
roles: (state) => state.user.roles,
permissions: (state) => state.user.permissions,
configParamInfo: (state) => state.user.configParamInfo,
permission_routes: (state) => state.permission.routes,
topbarRouters: (state) => state.permission.topbarRouters,
sidebarRouters: (state) => state.permission.sidebarRouters,
}
export default getters
import router, { constantRoutes } from '@/router'
import router, { constantRoutes, devRoutes } from '@/router'
import { getRouters } from '@/api/menu'
import Layout from '@/layout/index'
import View from '@/layout/components/View'
......@@ -8,9 +8,8 @@ const permission = {
state: {
routes: [],
addRoutes: [],
defaultRoutes: [],
topbarRouters: [],
sidebarRouters: [],
sidebarRouters: [], // 当前显示的侧边栏菜单,通过topbarRouters筛选当前激活的顶部菜单下的子菜单
},
mutations: {
SET_ROUTES: (state, routes) => {
......@@ -19,17 +18,8 @@ const permission = {
// 根据roles权限生成可访问的路由表
routes.forEach((e) => router.addRoute(e))
},
SET_DEFAULT_ROUTES: (state, routes) => {
state.defaultRoutes = constantRoutes.concat(routes)
},
SET_TOPBAR_ROUTES: (state, routes) => {
// 顶部导航菜单默认添加统计报表栏指向首页
// const index = [{
// path: 'index',
// meta: { title: '统计报表', icon: 'dashboard' }
// }]
// state.topbarRouters = routes.concat(index);
state.topbarRouters = routes
state.topbarRouters = routes.concat(devRoutes)
},
SET_SIDEBAR_ROUTERS: (state, routes) => {
state.sidebarRouters = routes
......@@ -42,11 +32,6 @@ const permission = {
// 向后端请求路由数据
getRouters()
.then(({ data }) => {
// const accessedRoutes = filterAsyncRouter(data)
// // 设置为匹配路由重定向404
// accessedRoutes.push({ path: '*', redirect: '/404', hidden: true })
// commit('SET_ROUTES', accessedRoutes)
// resolve(accessedRoutes)
if (!data || !data.length) {
MessageBox.confirm('您的角色菜单权限不足,请联系所在企业管理员', '系统提示', {
confirmButtonText: '重新登录',
......@@ -59,10 +44,8 @@ const permission = {
})
return reject()
}
const sdata = JSON.parse(JSON.stringify(data))
const rdata = JSON.parse(JSON.stringify(data))
const sidebarRoutes = filterAsyncRouter(sdata)
const rewriteRoutes = filterAsyncRouter(rdata, false, true)
const rewriteRoutes = filterAsyncRouter(rdata)
// // 设置首页重定向
let indexRoute = router.getRoutes().find((e) => e.path == '')
......@@ -70,9 +53,7 @@ const permission = {
rewriteRoutes.push({ path: '*', redirect: '/404', hidden: true })
commit('SET_ROUTES', rewriteRoutes)
commit('SET_SIDEBAR_ROUTERS', constantRoutes.concat(sidebarRoutes))
commit('SET_DEFAULT_ROUTES', sidebarRoutes)
commit('SET_TOPBAR_ROUTES', sidebarRoutes)
commit('SET_TOPBAR_ROUTES', rewriteRoutes)
resolve(rewriteRoutes)
})
.catch((error) => {
......@@ -84,30 +65,6 @@ const permission = {
},
}
function filterChildren(childrenMap, lastRouter = false) {
var children = []
childrenMap.forEach((el, index) => {
if (el.children && el.children.length) {
if (el.component === 'ParentView' && !lastRouter) {
el.children.forEach((c) => {
c.path = el.path + '/' + c.path
if (c.children && c.children.length) {
children = children.concat(filterChildren(c.children, c))
return
}
children.push(c)
})
return
}
}
if (lastRouter) {
el.path = lastRouter.path + '/' + el.path
}
children = children.concat(el)
})
return children
}
// export const loadView = (view) => {
// if (process.env.NODE_ENV === 'development') {
// return (resolve) => require([`@/views/${view}`], resolve)
......@@ -119,20 +76,24 @@ function filterChildren(childrenMap, lastRouter = false) {
// // 遍历后台传来的路由字符串,转换为组件对象
let level = 0
function filterAsyncRouter(asyncRouterMap) {
function filterAsyncRouter(asyncRouterMap, parentPath) {
level++
let res = asyncRouterMap.filter((route) => {
route.meta = route.meta || {}
route.meta.hidden = route.hidden
if (parentPath) {
let path = route.path
route.path = /^(\/|http)/.test(path) ? path : parentPath + '/' + path
}
if (route.component) {
// Layout组件特殊处理
if (route.redirect === 'noRedirect' && route.children.length) {
let firstChildPath = route.children[0].path
route.redirect = firstChildPath.startsWith('/') ? firstChildPath : route.path + '/' + firstChildPath
}
if (route.component === 'Layout') {
if (route.redirect === 'noRedirect' && route.children.length) {
let firstChildPath = route.children[0].path
route.redirect = firstChildPath.startsWith('/')
? firstChildPath
: route.path + '/' + firstChildPath
}
if (level != 1) {
route.component = View
} else {
......@@ -142,8 +103,9 @@ function filterAsyncRouter(asyncRouterMap) {
route.component = loadView(route.component)
}
}
if (route.children != null && route.children && route.children.length) {
route.children = filterAsyncRouter(route.children)
let children = route.children
if (children && children.length) {
route.children = filterAsyncRouter(route.children, route.path)
}
return true
})
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!