浏览代码

添加頁面權限

achao 2 年之前
父节点
当前提交
4777da7e3f

+ 156 - 157
src/global/directive.js

@@ -28,182 +28,181 @@
  * 拖动
  */
 const drag = {
-  install(Vue, options = {}) {
-    Vue.directive('drag', {
-      bind(el, binding, vnode) {
-        const dialogHeaderEl = el.querySelector('.el-dialog__header')
-        const dragDom = el.querySelector('.el-dialog')
-        dialogHeaderEl.style.cssText += ';cursor:move;'
-        dragDom.style.cssText += ';top:0px;'
-
-        // 获取原有属性 ie dom元素.currentStyle 火狐谷歌 window.getComputedStyle(dom元素, null);
-        const getStyle = (function() {
-          if (window.document.currentStyle) {
-            return (dom, attr) => dom.currentStyle[attr]
-          } else {
-            return (dom, attr) => getComputedStyle(dom, false)[attr]
-          }
-        })()
-
-        dialogHeaderEl.onmousedown = e => {
-          // 鼠标按下,计算当前元素距离可视区的距离
-          const disX = e.clientX - dialogHeaderEl.offsetLeft
-          const disY = e.clientY - dialogHeaderEl.offsetTop
-
-          const dragDomWidth = dragDom.offsetWidth
-          const dragDomHeight = dragDom.offsetHeight
-
-          const screenWidth = document.body.clientWidth
-          const screenHeight = document.body.scrollHeight
-
-          const minDragDomLeft = dragDom.offsetLeft
-          const maxDragDomLeft = screenWidth - dragDom.offsetLeft - dragDomWidth
-
-          const minDragDomTop = dragDom.offsetTop
-          const maxDragDomTop = screenHeight - dragDom.offsetTop - dragDomHeight
-
-          // 获取到的值带px 正则匹配替换
-          let styL = getStyle(dragDom, 'left')
-          let styT = getStyle(dragDom, 'top')
-
-          if (styL.includes('%')) {
-            styL = +document.body.clientWidth * (+styL.replace(/\\%/g, '') / 100)
-            styT = +document.body.scrollHeight * (+styT.replace(/\\%/g, '') / 100)
-          } else {
-            styL = +styL.replace(/\px/g, '')
-            styT = +styT.replace(/\px/g, '')
-          }
-
-          document.onmousemove = function(e) {
-            // 通过事件委托,计算移动的距离
-            let left = e.clientX - disX
-            let top = e.clientY - disY
-            if ((left <= 5 && left >= -5) || (top <= 5 && top >= -5)) {
-              return
+    install(Vue, options = {}) {
+        Vue.directive('drag', {
+            bind(el, binding, vnode) {
+                const dialogHeaderEl = el.querySelector('.el-dialog__header')
+                const dragDom = el.querySelector('.el-dialog')
+                dialogHeaderEl.style.cssText += ';cursor:move;'
+                dragDom.style.cssText += ';top:0px;'
+
+                // 获取原有属性 ie dom元素.currentStyle 火狐谷歌 window.getComputedStyle(dom元素, null);
+                const getStyle = (function() {
+                    if (window.document.currentStyle) {
+                        return (dom, attr) => dom.currentStyle[attr]
+                    } else {
+                        return (dom, attr) => getComputedStyle(dom, false)[attr]
+                    }
+                })()
+
+                dialogHeaderEl.onmousedown = e => {
+                    // 鼠标按下,计算当前元素距离可视区的距离
+                    const disX = e.clientX - dialogHeaderEl.offsetLeft
+                    const disY = e.clientY - dialogHeaderEl.offsetTop
+
+                    const dragDomWidth = dragDom.offsetWidth
+                    const dragDomHeight = dragDom.offsetHeight
+
+                    const screenWidth = document.body.clientWidth
+                    const screenHeight = document.body.scrollHeight
+
+                    const minDragDomLeft = dragDom.offsetLeft
+                    const maxDragDomLeft = screenWidth - dragDom.offsetLeft - dragDomWidth
+
+                    const minDragDomTop = dragDom.offsetTop
+                    const maxDragDomTop = screenHeight - dragDom.offsetTop - dragDomHeight
+
+                    // 获取到的值带px 正则匹配替换
+                    let styL = getStyle(dragDom, 'left')
+                    let styT = getStyle(dragDom, 'top')
+
+                    if (styL.includes('%')) {
+                        styL = +document.body.clientWidth * (+styL.replace(/\\%/g, '') / 100)
+                        styT = +document.body.scrollHeight * (+styT.replace(/\\%/g, '') / 100)
+                    } else {
+                        styL = +styL.replace(/\px/g, '')
+                        styT = +styT.replace(/\px/g, '')
+                    }
+
+                    document.onmousemove = function(e) {
+                        // 通过事件委托,计算移动的距离
+                        let left = e.clientX - disX
+                        let top = e.clientY - disY
+                        if ((left <= 5 && left >= -5) || (top <= 5 && top >= -5)) {
+                            return
+                        }
+
+                        // 边界处理
+                        if (-left > minDragDomLeft) {
+                            left = -minDragDomLeft
+                        } else if (left > maxDragDomLeft) {
+                            left = maxDragDomLeft
+                        }
+
+                        if (-top > minDragDomTop) {
+                            top = -minDragDomTop
+                        } else if (top > maxDragDomTop) {
+                            top = maxDragDomTop
+                        }
+
+                        // 移动当前元素
+                        dragDom.style.cssText += `;left:${left + styL}px;top:${top + styT}px;`
+                        console.info(dragDom.style.cssText)
+
+                        // emit onDrag event
+                        vnode.child.$emit('dragDialog')
+                    }
+
+                    document.onmouseup = function(e) {
+                        document.onmousemove = null
+                        document.onmouseup = null
+                    }
+                }
             }
-
-            // 边界处理
-            if (-left > minDragDomLeft) {
-              left = -minDragDomLeft
-            } else if (left > maxDragDomLeft) {
-              left = maxDragDomLeft
-            }
-
-            if (-top > minDragDomTop) {
-              top = -minDragDomTop
-            } else if (top > maxDragDomTop) {
-              top = maxDragDomTop
-            }
-
-            // 移动当前元素
-            dragDom.style.cssText += `;left:${left + styL}px;top:${top + styT}px;`
-            console.info(dragDom.style.cssText)
-
-            // emit onDrag event
-            vnode.child.$emit('dragDialog')
-          }
-
-          document.onmouseup = function(e) {
-            document.onmousemove = null
-            document.onmouseup = null
-          }
-        }
-      }
-    })
-  }
+        })
+    }
 }
 
 function onInput(el, ele, binding, vnode) {
-  function handle() {
-    let val = ele.value
-    // modifiers为修饰符对象, 传入了float, 则其float属性为true
-    if (binding.modifiers.float) {
-      // 清除"数字"和"."以外的字符
-      val = val.replace(/[^\d.]/g, '')
-      // 只保留第一个, 清除多余的
-      val = val.replace(/\.{2,}/g, '.')
-      // 第一个字符如果是.号,则补充前缀0
-      val = val.replace(/^\./g, '0.')
-      if (typeof binding.value !== 'undefined') {
-        // 期望保留的最大小数位数
-        let pointKeep = 0
-        if (typeof binding.value === 'string' ||
-          typeof binding.value === 'number') {
-          pointKeep = parseInt(binding.value)
+    function handle() {
+        let val = ele.value
+            // modifiers为修饰符对象, 传入了float, 则其float属性为true
+        if (binding.modifiers.float) {
+            // 清除"数字"和"."以外的字符
+            val = val.replace(/[^\d.]/g, '')
+                // 只保留第一个, 清除多余的
+            val = val.replace(/\.{2,}/g, '.')
+                // 第一个字符如果是.号,则补充前缀0
+            val = val.replace(/^\./g, '0.')
+            if (typeof binding.value !== 'undefined') {
+                // 期望保留的最大小数位数
+                let pointKeep = 0
+                if (typeof binding.value === 'string' ||
+                    typeof binding.value === 'number') {
+                    pointKeep = parseInt(binding.value)
+                }
+                const str = '^(\\d+)\\.(\\d\\{' + pointKeep + '}).*$'
+                const reg = new RegExp(str)
+                if (pointKeep === 0) {
+                    // 不需要小数点
+                    val = val.replace(reg, '$1')
+                } else {
+                    // 通过正则保留小数点后指定的位数
+                    val = val.replace(reg, '$1.$2')
+                }
+            }
         }
-        const str = '^(\\d+)\\.(\\d\\{' + pointKeep + '}).*$'
-        const reg = new RegExp(str)
-        if (pointKeep === 0) {
-          // 不需要小数点
-          val = val.replace(reg, '$1')
+        ele.value = val
+        if (vnode.componentInstance) {
+            vnode.componentInstance.$emit('input', ele.value)
         } else {
-          // 通过正则保留小数点后指定的位数
-          val = val.replace(reg, '$1.$2')
+            vnode.elm.dispatchEvent(new CustomEvent('input', ele.value))
         }
-      }
     }
-    ele.value = val
-    if (vnode.componentInstance) {
-      vnode.componentInstance.$emit('input', ele.value)
-    } else {
-      vnode.elm.dispatchEvent(new CustomEvent('input', ele.value))
-    }
-  }
-  return handle
+    return handle
 }
 
 const numberInput = {
-  install(Vue, options = {}) {
-    Vue.directive('number-input', {
-      bind(el, binding, vnode) {
-        const ele = (el && el.tagName === 'INPUT') ? el : el.querySelector('input')
-        ele.addEventListener('input', onInput(el, ele, binding, vnode), true)
-      },
-    })
-  }
+    install(Vue, options = {}) {
+        Vue.directive('number-input', {
+            bind(el, binding, vnode) {
+                const ele = (el && el.tagName === 'INPUT') ? el : el.querySelector('input')
+                ele.addEventListener('input', onInput(el, ele, binding, vnode), true)
+            },
+        })
+    }
 }
 
 const loadmore = {
-  install(Vue, options = {}) {
-    Vue.directive('loadmore', {
-      bind(el, binding, vnode) {
-        const selectWrap = el.querySelector('.el-table__body-wrapper')
-        selectWrap.addEventListener('scroll', function() {
-          let sign = 0;
-          const scrollDistance = this.scrollHeight - this.scrollTop - this.clientHeight
-          if (scrollDistance <= sign) {
-            binding.value()
-          }
+    install(Vue, options = {}) {
+        Vue.directive('loadmore', {
+            bind(el, binding, vnode) {
+                const selectWrap = el.querySelector('.el-table__body-wrapper')
+                selectWrap.addEventListener('scroll', function() {
+                    let sign = 0;
+                    const scrollDistance = this.scrollHeight - this.scrollTop - this.clientHeight
+                    if (scrollDistance <= sign) {
+                        binding.value()
+                    }
+                })
+            }
         })
-      }
-    })
-  }
+    }
 }
 const permission = (el, binding, vnode) => {
-  // debugger
-  const roles = vnode.context.$store.getters.roles;
-  if (!roles) {
-    return;
-  }
-
-  let userPermissionList = Array.isArray(binding.value) ? binding.value : [binding.value];
-  // 当前用户的权限列表
-  if (!userPermissionList.some(e => roles.includes(e))) {
-    el.parentNode && el.parentNode.removeChild(el);
-  }
+    const roles = vnode.context.$store.getters.roles;
+    if (!roles) {
+        return;
+    }
+
+    let userPermissionList = Array.isArray(binding.value) ? binding.value : [binding.value];
+    // 当前用户的权限列表
+    if (!userPermissionList.some(e => roles.includes(e))) {
+        el.parentNode && el.parentNode.removeChild(el);
+    }
 }
 
 const permissionCheck = {
-  install(Vue, options = {}) {
-    Vue.directive('hasPermission', {
-      inserted: permission,
-      componentUpdated: permission
-    })
-  }
+    install(Vue, options = {}) {
+        Vue.directive('hasPermission', {
+            inserted: permission,
+            componentUpdated: permission
+        })
+    }
 }
 export default {
-  numberInput,
-  loadmore,
-  drag,
-  permissionCheck
-}
+    numberInput,
+    loadmore,
+    drag,
+    permissionCheck
+}

+ 5 - 76
src/layout/components/Sidebar/index.vue

@@ -26,86 +26,15 @@
     },
     computed: {
       ...mapGetters([
-        'sidebar'
+        'sidebar',
+        'menu'
       ]),
       routes() {
         console.log('----------------------', this.$router.options.routes)
+          console.log('----------------------', this.menu)
         // this.socketInfo()
-        return this.$router.options.routes
-      },
-      socketInfo() {
-        // var staffId = JSON.parse(localStorage.getItem('winseaview-userInfo')).content.staffId
-        var staffId = '84f62127b7384dcdbaeaddfe460329fc'
-
-        // getAdminId().toPromise().then(response => {console.log(11111)})
-        this.loading = false
-        // WebSocket
-        // this.$store.dispatch('setAdminId', response.data.data)
-        if ('WebSocket' in window) {
-          if (process.env.NODE_ENV === 'production') {
-            this.websocket = new WebSocket('wss://www.zthymaoyi.com/wss/websocket/' + staffId)
-          } else {
-            //  this.websocket = new WebSocket('ws://192.168.1.115:8090/commonUser/api/onOpen?adminId=84f62127b7384dcdbaeaddfe460329fc' )
-            // this.websocket = new WebSocket('ws://192.168.1.119:9100/websocket/' + staffId)
-            this.websocket = new WebSocket('ws://192.168.1.114:8090/websocket/' + staffId)
-          }
-          console.log('knjhdfkhedfkh',process.env.NODE_ENV)
-          this.initWebSocket()
-        } else {
-          alert('当前浏览器不支持websocket')
-        }
-      },
-      initWebSocket() {
-        console.log('有该方法·',this.websocket)
-        // 连接错误
-        this.websocket.onerror = this.setErrorMessage
-        // 连接成功
-        this.websocket.onopen = this.setOnopenMessage
-
-        // 收到消息的回调
-        this.websocket.onmessage = this.setOnmessageMessage
-
-        // 连接关闭的回调
-        this.websocket.onclose = this.setOncloseMessage
-
-        // 监听窗口关闭事件,当窗口关闭时,主动去关闭websocket连接,防止连接还没断开就关闭窗口,server端会抛异常。
-        window.onbeforeunload = this.onbeforeunload
-      },
-      setErrorMessage() {
-        console.log('WebSocket连接发生错误   状态码:' + this.websocket.readyState)
-      },
-      setOnopenMessage() {
-        // console.log(this.websocket)
-        console.log('WebSocket连接成功    状态码:' + this.websocket.readyState)
-      },
-      setOnmessageMessage(event) {
-        // console.log(3333)
-        // 根据服务器推送的消息做自己的业务处理
-        console.log('服务端返回:' + event.data)
-        // var msg = event.data.split('$')
-        // var that = this
-
-        // this.$notify.warning({
-        //   title: '新消息提醒',
-        //   message: msg[0],
-        //   duration: 0,
-        //   onClick() {
-        //     that.$router.push({
-        //       path: msg[1]
-        //     }) // 你要跳转的路由 还可以传参 当然也可以通过其他方式跳转
-        //   }
-        // })
-        // var currentPage = that.$router.history.current.path
-        // that.$router.push({
-        //   path: '/'
-        // })
-        // that.$router.push({
-        //   path: currentPage
-        // })
-      },
-      setOncloseMessage() {
-        // console.log(this.websocket)
-        console.log('WebSocket连接关闭    状态码:' + this.websocket.readyState)
+        // return this.$router.options.routes
+        return this.menu
       },
       activeMenu() {
         const route = this.$route

+ 38 - 31
src/router/cargoOwnerManagement/index.js

@@ -6,43 +6,50 @@ const cargoOwnerManagementRouter = {
     path: '/cargoOwnerManagement',
     component: Layout,
     redirect: 'noRedirect',
-    t:new Date(),
+    t: new Date(),
     name: 'cargoOwnerManagement',
     meta: {
         title: '货主管理',
-        icon: 'huozhuguanli'
+        icon: 'huozhuguanli',
+        module: 'changyuntong.huozhuguanli.view',
     },
     children: [{
-        path: 'empowerExamine',
-        name: 'empowerExamine',
-        t:new Date(),
-        component: () => import('@/views/cargoOwnerManagement/empowerExamine'),
-        meta: {
-            title: '货主信息',
-            icon: ''
+            path: 'empowerExamine',
+            name: 'empowerExamine',
+            t: new Date(),
+            component: () =>
+                import ('@/views/cargoOwnerManagement/empowerExamine'),
+            meta: {
+                title: '货主信息',
+                icon: '',
+                module: 'changyuntong.huozhuguanli.view',
+            }
+        },
+        {
+            path: 'merchantVerification',
+            name: 'merchantVerification',
+            t: new Date(),
+            component: () =>
+                import ('@/views/cargoOwnerManagement/merchantVerification'),
+            meta: {
+                title: '授权审核',
+                icon: '',
+                module: 'changyuntong.huozhuguanli.shouquan.view',
+            }
+        },
+        {
+            path: 'taskAudit',
+            name: 'taskAudit',
+            t: new Date(),
+            component: () =>
+                import ('@/views/cargoOwnerManagement/taskAudit'),
+            meta: {
+                title: '任务审核',
+                icon: '',
+                module: 'changyuntong.huozhuguanli.renwu.view',
+            }
         }
-    },
-    {
-        path: 'merchantVerification',
-        name: 'merchantVerification',
-        t:new Date(),
-        component: () => import('@/views/cargoOwnerManagement/merchantVerification'),
-        meta: {
-            title: '授权审核',
-            icon: ''
-        }
-    },
-    {
-        path: 'taskAudit',
-        name: 'taskAudit',
-        t:new Date(),
-        component: () => import('@/views/cargoOwnerManagement/taskAudit'),
-        meta: {
-            title: '任务审核',
-            icon: ''
-        }
-    }
     ]
 }
 
-export default cargoOwnerManagementRouter
+export default cargoOwnerManagementRouter

+ 8 - 6
src/router/contractManagement/index.js

@@ -9,19 +9,21 @@ const contractManagementRouter = {
     name: 'contractManagement',
     meta: {
         title: '合同管理',
-        icon: 'hetongguanli'
+        icon: 'hetongguanli',
+        module: 'changyuntong.hetongguanli',
     },
     alwaysShow: true,
     children: [{
         path: 'contractModel',
         name: 'contractModel',
-        component: () => import('@/views/contractManagement/contractModel'),
+        component: () =>
+            import ('@/views/contractManagement/contractModel'),
         meta: {
             title: '合同模板',
-            icon: ''
+            icon: '',
+            module: 'changyuntong.hetongguanli.view',
         }
-    }
-    ]
+    }]
 }
 
-export default contractManagementRouter
+export default contractManagementRouter

+ 36 - 28
src/router/driverManagement/index.js

@@ -9,37 +9,45 @@ const driverManagementRouter = {
     name: 'driverManagement',
     meta: {
         title: '司机管理',
-        icon: 'sijiguanli'
+        icon: 'sijiguanli',
+        module: 'changyuntong.sijiguanli',
     },
     children: [{
-        path: 'identityExamine',
-        name: 'identityExamine',
-        component: () => import('@/views/driverManagement/identityExamine'),
-        meta: {
-            title: '司机信息',
-            icon: ''
-        }
-    },
-    {
-        path: 'fleetInfo',
-        name: 'fleetInfo',
-        component: () => import('@/views/driverManagement/fleetInfo'),
-        meta: {
-            title: '车队信息',
-            icon: ''
-        }
-    },
-    {
-        path: 'vehicleExamine',
-        name: 'vehicleExamine',
-        component: () => import('@/views/driverManagement/vehicleExamine'),
-        meta: {
-            title: '车辆信息',
-            icon: ''
-        }
-    },
+            path: 'identityExamine',
+            name: 'identityExamine',
+            component: () =>
+                import ('@/views/driverManagement/identityExamine'),
+            meta: {
+                title: '司机信息',
+                icon: '',
+                module: 'changyuntong.sijiguanli.view',
+
+            }
+        },
+        {
+            path: 'fleetInfo',
+            name: 'fleetInfo',
+            component: () =>
+                import ('@/views/driverManagement/fleetInfo'),
+            meta: {
+                title: '车队信息',
+                icon: '',
+                module: 'changyuntong.sijiguanli.chedui.view',
+            }
+        },
+        {
+            path: 'vehicleExamine',
+            name: 'vehicleExamine',
+            component: () =>
+                import ('@/views/driverManagement/vehicleExamine'),
+            meta: {
+                title: '车辆信息',
+                icon: '',
+                module: 'changyuntong.sijiguanli.cheliang.view',
+            }
+        },
 
     ]
 }
 
-export default driverManagementRouter
+export default driverManagementRouter

+ 8 - 6
src/router/enterpriseManagement/index.js

@@ -9,19 +9,21 @@ const enterpriseManagementRouter = {
     name: 'enterpriseManagement',
     meta: {
         title: '企业管理',
-        icon: 'qiyeguanli'
+        icon: 'qiyeguanli',
+        module: 'changyuntong.qiyeguanli.view',
     },
     alwaysShow: true,
     children: [{
         path: 'enterpriseAudit',
         name: 'enterpriseAudit',
-        component: () => import('@/views/enterpriseManagement/enterpriseAudit'),
+        component: () =>
+            import ('@/views/enterpriseManagement/enterpriseAudit'),
         meta: {
             title: '企业信息',
-            icon: ''
+            icon: '',
+            module: 'changyuntong.qiyeguanli.view'
         }
-    }
-    ]
+    }]
 }
 
-export default enterpriseManagementRouter
+export default enterpriseManagementRouter

+ 8 - 6
src/router/feedbackManagement/index.js

@@ -9,19 +9,21 @@ const feedbackManagementRouter = {
     name: 'feedbackManagement',
     meta: {
         title: '投诉举报管理',
-        icon: 'fankuiguanli'
+        icon: 'fankuiguanli',
+        module: 'changyuntong.jubaoguanli',
     },
     // alwaysShow: true,
     children: [{
         path: 'userFeedback',
         name: 'userFeedback',
-        component: () => import('@/views/feedbackManagement/userFeedback'),
+        component: () =>
+            import ('@/views/feedbackManagement/userFeedback'),
         meta: {
             title: '投诉举报管理',
-            icon: ''
+            icon: '',
+            module: 'changyuntong.jubaoguanli.view',
         }
-    }
-    ]
+    }]
 }
 
-export default feedbackManagementRouter
+export default feedbackManagementRouter

+ 85 - 93
src/router/index.js

@@ -18,106 +18,98 @@ import operationLog from './operationLog/index'
 
 
 export const constantRoutes = [{
-    path: '/login',
-    component: () =>
-      import('@/views/login/index'),
-    hidden: true
-  },
-
-  {
-    path: '/404',
-    component: () =>
-      import('@/views/404'),
-    hidden: true
-  },
-  {
-    path: '/',
-    component: Layout,
-    redirect: '/dashboard',
-    children: [{
-      path: 'dashboard',
-      name: 'Dashboard',
-      component: () =>
-        import('@/views/dashboard/index'),
-      meta: {
-        title: '首页',
-        icon: 'shouye'
-      }
-    }]
-  },
-  driverManagement,
-  cargoOwnerManagement,
-  enterpriseManagement,
-  orderManagement,
-  contractManagement,
-  platformManagement,
-  feedbackManagement,
-  officialWebsiteManagement,
-  parkReportManagement,
-  settlementManagement,
-  operationLog,
-  {
-    path: '/permissionSetting',
-    component: Layout,
-    redirect: '/permissionSettingManagement',
-    name: 'permissionSettingManagement',
-    meta: {
-      title: '权限设置',
-      icon: 'shouye'
-    },
-    children: [{
-        path: 'permissionSetting',
-        name: 'permissionSetting',
+        path: '/login',
         component: () =>
-          import('@/views/permissionSetting/permissionSetting'),
-        meta: {
-          title: '角色设置',
-          icon: 'shouye'
-        }
-      },
-      {
-        path: 'permissionSettingPerson',
-        name: 'permissionSettingPerson',
+            import ('@/views/login/index'),
+        hidden: true
+    },
+
+    {
+        path: '/404',
         component: () =>
-          import('@/views/permissionSetting/permissionSettingPerson'),
+            import ('@/views/404'),
+        hidden: true
+    },
+    {
+        path: '/',
+        component: Layout,
+        redirect: '/dashboard',
+        children: [{
+            path: 'dashboard',
+            name: 'Dashboard',
+            component: () =>
+                import ('@/views/dashboard/index'),
+            meta: {
+                title: '首页',
+                icon: 'shouye'
+            }
+        }]
+    },
+    {
+        path: '/permissionSetting',
+        component: Layout,
+        redirect: '/permissionSettingManagement',
+        name: 'permissionSettingManagement',
         meta: {
-          title: '人员设置',
-          icon: 'shouye'
-        }
-      }
-    ]
-  },
-  {
-    path: '*',
-    redirect: '/404',
-    hidden: true
-  }
+            title: '权限设置',
+            icon: 'shouye'
+        },
+        children: [{
+                path: 'permissionSetting',
+                name: 'permissionSetting',
+                component: () =>
+                    import ('@/views/permissionSetting/permissionSetting'),
+                meta: {
+                    title: '角色设置',
+                    icon: 'shouye'
+                }
+            },
+            {
+                path: 'permissionSettingPerson',
+                name: 'permissionSettingPerson',
+                component: () =>
+                    import ('@/views/permissionSetting/permissionSettingPerson'),
+                meta: {
+                    title: '人员设置',
+                    icon: 'shouye'
+                }
+            }
+        ]
+    },
+    {
+        path: '*',
+        redirect: '/404',
+        hidden: true
+    }
 ]
-let cofigRouter = []
-// const modulesFiles = require.context('../views', true, /.js$/)
-// modulesFiles.keys().forEach((model_item, key) => {
-//         if (model_item === 'index.js' || modulesFiles(model_item).default === undefined || modulesFiles(model_item)
-//             .default.path === undefined) return
-//         cofigRouter = cofigRouter.concat(modulesFiles(model_item).default)
-//     })
-// 需要根据用户角色动态加载的路由
-export const dynamicRoutes = cofigRouter
+let cofigRouter = [
+    driverManagement,
+    cargoOwnerManagement,
+    enterpriseManagement,
+    orderManagement,
+    contractManagement,
+    platformManagement,
+    feedbackManagement,
+    officialWebsiteManagement,
+    parkReportManagement,
+    settlementManagement,
+    operationLog,
+]
+export const asyncRoutes = cofigRouter
 const createRouter = () =>
-  new Router({
-    // mode: 'history',
-    scrollBehavior: () => ({
-      y: 0
-    }),
-    linkActiveClass: 'active', // router-link  .active样式
-    routes: constantRoutes
-  })
+    new Router({
+        // mode: 'history',
+        scrollBehavior: () => ({
+            y: 0
+        }),
+        linkActiveClass: 'active', // router-link  .active样式
+        routes: constantRoutes
+    })
 
 const router = createRouter()
-
-// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
 export function resetRouter() {
-  const newRouter = createRouter()
-  router.matcher = newRouter.matcher // reset router
+    const newRouter = createRouter()
+    router.matcher = newRouter.matcher // reset router
 }
 
-export default router
+export default router

+ 132 - 120
src/router/officialWebsiteManagement/index.js

@@ -2,136 +2,148 @@
 
 import Layout from '@/layout'
 
-const officialWebsiteManagement  = {
+const officialWebsiteManagement = {
     path: '/officialWebsiteManagement',
     component: Layout,
     redirect: 'noRedirect',
     name: 'officialWebsiteManagement',
     meta: {
         title: '官网管理',
-        icon: 'fankuiguanli'
+        icon: 'fankuiguanli',
+        module: 'changyuntong.guanwangguanli',
     },
     alwaysShow: true,
-    children: [
-      {
-        path: '/news',
-        name: 'news',
-        component: () => import('@/views/officialWebsiteManagement/news'),
-        meta: {
-            title: '公告信息',
-            icon: ''
-        }
-    },
-    {
-    	path: '/newsAdd',
-    	name: 'newsAdd',
-    	component: () => import('@/views/officialWebsiteManagement/newsAdd'),
-    	meta: {
-    	    title: '公告信息新增',
-    	    icon: ''
-    	},
-    	hidden: true
-    },
-    {
-    	path: '/newsLook',
-    	name: 'newsLook',
-    	component: () => import('@/views/officialWebsiteManagement/newsLook'),
-    	meta: {
-    	    title: '公告信息查看',
-    	    icon: ''
-    	},
-    	hidden: true
-    },
-    {
-    	path: '/newsEdit',
-    	name: 'newsEdit',
-    	component: () => import('@/views/officialWebsiteManagement/newsEdit'),
-    	meta: {
-    	    title: '公告信息编辑',
-    	    icon: ''
-    	},
-    	hidden: true
-    },
-    {
-        path: '/notice',
-        name: 'notice',
-        component: () => import('@/views/officialWebsiteManagement/notice'),
-        meta: {
-            title: '处理公示',
-            icon: ''
+    children: [{
+            path: '/news',
+            name: 'news',
+            component: () =>
+                import ('@/views/officialWebsiteManagement/news'),
+            meta: {
+                title: '公告信息',
+                icon: '',
+            }
+        },
+        {
+            path: '/newsAdd',
+            name: 'newsAdd',
+            component: () =>
+                import ('@/views/officialWebsiteManagement/newsAdd'),
+            meta: {
+                title: '公告信息新增',
+                icon: ''
+            },
+            hidden: true
+        },
+        {
+            path: '/newsLook',
+            name: 'newsLook',
+            component: () =>
+                import ('@/views/officialWebsiteManagement/newsLook'),
+            meta: {
+                title: '公告信息查看',
+                icon: ''
+            },
+            hidden: true
+        },
+        {
+            path: '/newsEdit',
+            name: 'newsEdit',
+            component: () =>
+                import ('@/views/officialWebsiteManagement/newsEdit'),
+            meta: {
+                title: '公告信息编辑',
+                icon: ''
+            },
+            hidden: true
+        },
+        {
+            path: '/notice',
+            name: 'notice',
+            component: () =>
+                import ('@/views/officialWebsiteManagement/notice'),
+            meta: {
+                title: '处理公示',
+                icon: ''
+            },
+        },
+        {
+            path: '/noticeAdd',
+            name: 'noticeAdd',
+            component: () =>
+                import ('@/views/officialWebsiteManagement/noticeAdd'),
+            meta: {
+                title: '处理公示新增',
+                icon: ''
+            },
+            hidden: true
+        },
+        {
+            path: '/noticeLook',
+            name: 'noticeLook',
+            component: () =>
+                import ('@/views/officialWebsiteManagement/noticeLook'),
+            meta: {
+                title: '处理公示查看',
+                icon: ''
+            },
+            hidden: true
+        },
+        {
+            path: '/noticeEdit',
+            name: 'noticeEdit',
+            component: () =>
+                import ('@/views/officialWebsiteManagement/noticeEdit'),
+            meta: {
+                title: '处理公示编辑',
+                icon: ''
+            },
+            hidden: true
         },
-    },
-    {
-    	path: '/noticeAdd',
-    	name: 'noticeAdd',
-    	component: () => import('@/views/officialWebsiteManagement/noticeAdd'),
-    	meta: {
-    	    title: '处理公示新增',
-    	    icon: ''
-    	},
-    	hidden: true
-    },
-    {
-    	path: '/noticeLook',
-    	name: 'noticeLook',
-    	component: () => import('@/views/officialWebsiteManagement/noticeLook'),
-    	meta: {
-    	    title: '处理公示查看',
-    	    icon: ''
-    	},
-    	hidden: true
-    },
-    {
-    	path: '/noticeEdit',
-    	name: 'noticeEdit',
-    	component: () => import('@/views/officialWebsiteManagement/noticeEdit'),
-    	meta: {
-    	    title: '处理公示编辑',
-    	    icon: ''
-    	},
-    	hidden: true
-    },
 
-    {
-        path: '/publicity',
-        name: 'publicity',
-        component: () => import('@/views/officialWebsiteManagement/publicity'),
-        meta: {
-            title: '行业资讯',
-            icon: ''
-        }
-    },
-    {
-    	path: '/publicityAdd',
-    	name: 'publicityAdd',
-    	component: () => import('@/views/officialWebsiteManagement/publicityAdd'),
-    	meta: {
-    	    title: '行业资讯新增',
-    	    icon: ''
-    	},
-    	hidden: true
-    },
-    {
-    	path: '/publicityLook',
-    	name: 'publicityLook',
-    	component: () => import('@/views/officialWebsiteManagement/publicityLook'),
-    	meta: {
-    	    title: '行业资讯查看',
-    	    icon: ''
-    	},
-    	hidden: true
-    },
-    {
-    	path: '/publicityEdit',
-    	name: 'publicityEdit',
-    	component: () => import('@/views/officialWebsiteManagement/publicityEdit'),
-    	meta: {
-    	    title: '行业资讯编辑',
-    	    icon: ''
-    	},
-    	hidden: true
-    },
+        {
+            path: '/publicity',
+            name: 'publicity',
+            component: () =>
+                import ('@/views/officialWebsiteManagement/publicity'),
+            meta: {
+                title: '行业资讯',
+                icon: ''
+            }
+        },
+        {
+            path: '/publicityAdd',
+            name: 'publicityAdd',
+            component: () =>
+                import ('@/views/officialWebsiteManagement/publicityAdd'),
+            meta: {
+                title: '行业资讯新增',
+                icon: ''
+            },
+            hidden: true
+        },
+        {
+            path: '/publicityLook',
+            name: 'publicityLook',
+            component: () =>
+                import ('@/views/officialWebsiteManagement/publicityLook'),
+            meta: {
+                title: '行业资讯查看',
+                icon: ''
+            },
+            hidden: true
+        },
+        {
+            path: '/publicityEdit',
+            name: 'publicityEdit',
+            component: () =>
+                import ('@/views/officialWebsiteManagement/publicityEdit'),
+            meta: {
+                title: '行业资讯编辑',
+                icon: ''
+            },
+            hidden: true
+        },
     ]
 }
 
-export default officialWebsiteManagement
+export default officialWebsiteManagement

+ 9 - 8
src/router/operationLog/index.js

@@ -9,20 +9,21 @@ const operationLogRouter = {
     name: 'operationLog',
     meta: {
         title: '操作日志',
-        icon: 'dingdanguanli'
+        icon: 'dingdanguanli',
+        module: 'changyuntong.caozuorizhi',
     },
     alwaysShow: true,
-    children: [
-      {
+    children: [{
         path: 'logManagement',
         name: 'logManagement',
-        component: () => import('@/views/operationLog/logManagement'),
+        component: () =>
+            import ('@/views/operationLog/logManagement'),
         meta: {
             title: '日志管理',
-            icon: ''
+            icon: '',
+            module: 'changyuntong.caozuorizhi.view',
         }
-    }
-    ]
+    }]
 }
 
-export default operationLogRouter
+export default operationLogRouter

+ 25 - 21
src/router/orderManagement/index.js

@@ -9,30 +9,34 @@ const orderManagementRouter = {
     name: 'orderManagement',
     meta: {
         title: '订单管理',
-        icon: 'dingdanguanli'
+        icon: 'dingdanguanli',
+        module: 'changyuntong.dingdanguanli',
     },
     alwaysShow: true,
-    children: [
-      {
-        path: 'orderAudit',
-        name: 'orderAudit',
-        component: () => import('@/views/orderManagement/orderAudit'),
-        meta: {
-            title: '订单信息',
-            icon: ''
-        }
-    },
-    {
-        path: 'trajectory',
-        name: 'trajectory',
-        component: () => import('@/views/orderManagement/trajectory'),
-        meta: {
-            title: '轨迹',
-            icon: ''
+    children: [{
+            path: 'orderAudit',
+            name: 'orderAudit',
+            component: () =>
+                import ('@/views/orderManagement/orderAudit'),
+            meta: {
+                title: '订单信息',
+                icon: '',
+                module: 'changyuntong.dingdanguanli.view',
+            }
         },
-        	hidden: true
-    }
+        {
+            path: 'trajectory',
+            name: 'trajectory',
+            component: () =>
+                import ('@/views/orderManagement/trajectory'),
+            meta: {
+                title: '轨迹',
+                icon: '',
+                module: 'changyuntong.dingdanguanli.view',
+            },
+            hidden: true
+        }
     ]
 }
 
-export default orderManagementRouter
+export default orderManagementRouter

+ 12 - 5
src/router/parkReportManagement/index.js

@@ -9,7 +9,9 @@ const parkReportManagement = {
     name: 'parkReportManagement',
     meta: {
         title: '园区上报',
-        icon: 'pingtaiguanli'
+        icon: 'pingtaiguanli',
+        module: 'changyuntong.yuanqushangbao',
+
     },
     alwaysShow: true,
     children: [{
@@ -19,7 +21,8 @@ const parkReportManagement = {
                 import ('@/views/parkReportManagement/waybillReporting'),
             meta: {
                 title: '运单上报',
-                icon: ''
+                icon: '',
+                module: 'changyuntong.yuanqushangbao.yundan.view',
             }
         },
         {
@@ -29,7 +32,8 @@ const parkReportManagement = {
                 import ('@/views/parkReportManagement/dailyReport'),
             meta: {
                 title: '流水单上报',
-                icon: ''
+                icon: '',
+                module: 'changyuntong.yuanqushangbao.liushui.view',
             }
         },
         {
@@ -39,7 +43,9 @@ const parkReportManagement = {
                 import ('@/views/parkReportManagement/driverInformationReporting'),
             meta: {
                 title: '司机信息上报',
-                icon: ''
+                icon: '',
+                module: 'changyuntong.yuanqushangbao.sishang.view',
+
             }
         },
         {
@@ -49,7 +55,8 @@ const parkReportManagement = {
                 import ('@/views/parkReportManagement/vehicleInformationReporting'),
             meta: {
                 title: '车辆信息上报',
-                icon: ''
+                icon: '',
+                module: 'changyuntong.yuanqushangbao.cheshang.view',
             }
         },
     ]

+ 36 - 29
src/router/platformManagement/index.js

@@ -9,39 +9,46 @@ const platformManagementRouter = {
     name: 'platformManagement',
     meta: {
         title: '平台规定管理',
-        icon: 'pingtaiguanli'
+        icon: 'pingtaiguanli',
+        module: 'changyuntong.guidingguanli',
     },
     alwaysShow: true,
     children: [{
-        path: 'specifiedRecords',
-        name: 'specifiedRecords',
-        component: () => import('@/views/platformManagement/specifiedRecords'),
-        meta: {
-            title: '规定记录',
-            icon: ''
+            path: 'specifiedRecords',
+            name: 'specifiedRecords',
+            component: () =>
+                import ('@/views/platformManagement/specifiedRecords'),
+            meta: {
+                title: '规定记录',
+                icon: '',
+                module: 'changyuntong.guidingguanli.view',
+            }
+        },
+        {
+            path: 'specifiedRecordsAdd',
+            name: 'specifiedRecordsAdd',
+            component: () =>
+                import ('@/views/platformManagement/specifiedRecordsAdd'),
+            meta: {
+                title: '新增规定记录',
+                icon: '',
+                module: 'changyuntong.guidingguanli.add',
+            },
+            hidden: true
+        },
+        {
+            path: 'specifiedRecordsLook',
+            name: 'specifiedRecordsLook',
+            component: () =>
+                import ('@/views/platformManagement/specifiedRecordsLook'),
+            meta: {
+                title: '规定记录查看',
+                icon: '',
+                module: 'changyuntong.guidingguanli.view',
+            },
+            hidden: true
         }
-    },
-	{
-		path: 'specifiedRecordsAdd',
-		name: 'specifiedRecordsAdd',
-		component: () => import('@/views/platformManagement/specifiedRecordsAdd'),
-		meta: {
-		    title: '新增规定记录',
-		    icon: ''
-		},
-		hidden: true
-	},
-	{
-		path: 'specifiedRecordsLook',
-		name: 'specifiedRecordsLook',
-		component: () => import('@/views/platformManagement/specifiedRecordsLook'),
-		meta: {
-		    title: '规定记录查看',
-		    icon: ''
-		},
-		hidden: true
-	}
     ]
 }
 
-export default platformManagementRouter
+export default platformManagementRouter

+ 12 - 6
src/router/settlementManagement/index.js

@@ -9,7 +9,8 @@ const settlementManagement = {
     name: 'settlementManagement',
     meta: {
         title: '结算管理',
-        icon: 'fankuiguanli'
+        icon: 'fankuiguanli',
+        module: 'changyuntong.jiesuanguanli',
     },
     alwaysShow: true,
     children: [{
@@ -19,7 +20,8 @@ const settlementManagement = {
                 import ('@/views/settlementManagement/driverFeeSettlement'),
             meta: {
                 title: '司机费用结算',
-                icon: ''
+                icon: '',
+                module: 'changyuntong.sifei.view',
             }
         },
         {
@@ -29,7 +31,8 @@ const settlementManagement = {
                 import ('@/views/settlementManagement/advancePaymentAndRepaymentSettlement'),
             meta: {
                 title: '垫付还款结算',
-                icon: ''
+                icon: '',
+                module: 'changyuntong.dianfu.view',
             },
         },
         {
@@ -39,7 +42,8 @@ const settlementManagement = {
                 import ('@/views/settlementManagement/CashOwner'),
             meta: {
                 title: '货主提现',
-                icon: ''
+                icon: '',
+                module: 'changyuntong.tixian.view',
             },
         },
         {
@@ -49,7 +53,8 @@ const settlementManagement = {
                 import ('@/views/settlementManagement/ownerFlow'),
             meta: {
                 title: '货主银行流水',
-                icon: ''
+                icon: '',
+                module: 'changyuntong.hangliu.view',
             },
         },
         {
@@ -59,7 +64,8 @@ const settlementManagement = {
                 import ('@/views/settlementManagement/statisticalReport'),
             meta: {
                 title: '统计报表',
-                icon: ''
+                icon: '',
+                module: 'changyuntong.baobiao.view',
             },
         },
     ]

+ 8 - 8
src/store/getters.js

@@ -1,10 +1,10 @@
 const getters = {
-  sidebar: state => state.app.sidebar,
-  device: state => state.app.device,
-  token: state => state.user.token,
-  avatar: state => state.user.avatar,
-  name: state => state.user.name,
-  menuList: state => state.menu.menuList,
-  roles: state => state.user.roles,
+    sidebar: state => state.app.sidebar,
+    device: state => state.app.device,
+    token: state => state.user.token,
+    avatar: state => state.user.avatar,
+    name: state => state.user.name,
+    menu: state => state.permission.menu,
+    roles: state => state.user.roles,
 }
-export default getters
+export default getters

+ 70 - 124
src/store/modules/permission.js

@@ -1,14 +1,13 @@
 import {
-  asyncRoutes,
-  constantRoutes,
-  resetRouter
+    asyncRoutes,
+    constantRoutes,
+    resetRouter
 } from '@/router'
 import {
-  getRoule
+    getRoule
 } from '@/api/user'
 import {
-  clearStorage,
-  removeToken
+    clearStorage
 } from '../../utils/auth'
 /**
  * 递归过滤异步路由表,返回符合用户角色权限的路由表
@@ -16,26 +15,26 @@ import {
  * @param roles 传递参数-用户权限内容
  */
 function filterAsyncRoutes(routes, roles) {
-  const res = []
-  routes.forEach(route => {
-    const currentRoute = {
-      ...route
-    }
-    if (currentRoute.meta && currentRoute.meta.module) {
-      const routeModule = currentRoute.meta.module
-      // console.log(roles)
-      if (roles.some(role => role.indexOf(routeModule) === 0)) {
-        if (Array.isArray(currentRoute.children) && currentRoute.children.length > 0) {
-          currentRoute.children = filterAsyncRoutes(currentRoute.children, roles)
-        }
-        res.push(currentRoute)
-      }
-    } else {
-      res.push(currentRoute)
-    }
-  })
-  // console.log(routes)
-  return res
+    const res = []
+    routes.forEach(route => {
+            const currentRoute = {
+                ...route
+            }
+            if (currentRoute.meta && currentRoute.meta.module) {
+                const routeModule = currentRoute.meta.module
+                    // console.log(roles)
+                if (roles.some(role => role.indexOf(routeModule) === 0)) {
+                    if (Array.isArray(currentRoute.children) && currentRoute.children.length > 0) {
+                        currentRoute.children = filterAsyncRoutes(currentRoute.children, roles)
+                    }
+                    res.push(currentRoute)
+                }
+            } else {
+                // res.push(currentRoute)
+            }
+        })
+        // console.log(routes)
+    return res
 }
 
 /**
@@ -45,114 +44,61 @@ function filterAsyncRoutes(routes, roles) {
  * @param {*} parentModule
  */
 function handleRoles(roles, res, parentModule) {
-  // console.log(roles, res, parentModule)
-  roles.forEach((role) => {
-    if (Array.isArray(role.children) && role.children.length > 0) {
-      handleRoles(role.children, res, parentModule + role.name + '.')
-    } else {
-      const lastIndex = role.name.lastIndexOf('.')
-      if (parentModule.indexOf(role.name.split('.')[0]) != -1) {
-        res.push(`${parentModule}${role.name.substring(lastIndex + 1)}`)
-      } else {
-        res.push(`${parentModule}${role.name}`)
-      }
-    }
-  })
+    // console.log(roles, res, parentModule)
+    roles.forEach((role) => {
+        if (Array.isArray(role.children) && role.children.length > 0) {
+            handleRoles(role.children, res, parentModule + role.name + '.')
+        } else {
+            const lastIndex = role.name.lastIndexOf('.')
+            if (parentModule.indexOf(role.name.split('.')[0]) != -1) {
+                res.push(`${parentModule}${role.name.substring(lastIndex + 1)}`)
+            } else {
+                res.push(`${parentModule}${role.name}`)
+            }
+        }
+    })
 }
 const state = {
-  routes: [],
-  menu: []
+    routes: [],
+    menu: []
 }
 
 const mutations = {
-  SET_ROUTES: (state, routes) => {
-    const routerList = constantRoutes.concat(routes)
-    // console.log(routerList)
-    state.menu = leftMenu(routerList, {})
-    state.routes = routerList
-    // console.log(routerList)
-  },
-  SET_MENU: (state, menu) => {
-    state.menu = menu
-  }
-}
-
-const group = (routerChild = []) => {
-  const groupChild = []
-  routerChild.forEach(item => {
-    const routerGroup = [
-      item.path,
-      ...group(item.children || [])
-    ]
-    groupChild.push(...routerGroup)
-  })
-  return groupChild.filter(item => item)
-}
-const formatUrl = (url = '') => {
-  return url.replace(/\/\//g, '/')
-}
-/**
- * 获取左侧菜单列表 数据模型  供日后后台提供接口使用
- * @param {*} menuList 按权限区分出来的集合
- * @param {*} param1 {path=''} 父节点路径
- */
-const leftMenu = (menuList, {
-  path = ''
-}) => {
-  const res = []
-  menuList.filter(item => !item.hidden).forEach(route => {
-    // console.info(route, 'route.children')
-    const currentRoute = {
-      'alias': 'menu',
-      'code': route.name,
-      'name': route.meta ? route.meta.title : route.name,
-      'path': formatUrl(path + (route.path.indexOf('/') > -1 ? '' : '/') + route.path),
-      'source': route.meta ? `iconfont icon${route.meta.icon}` : '',
-      'sort': 1,
-      'category': 1,
-      'isOpen': 1,
-      'children': leftMenu(route.children || [], route),
-      'hasChildren': false,
-      'actionName': '',
-      'isOpenName': '',
-      'group': group(route.children || [])
+    SET_ROUTES: (state, routes) => {
+        const routerList = constantRoutes.concat(routes)
+        state.menu = routerList
+        state.routes = routerList
+    },
+    SET_MENU: (state, menu) => {
+        state.menu = menu
     }
-    res.push(currentRoute)
-  })
-  // console.info(JSON.stringify(res), 'luyou')
-  return res
 }
 
 const actions = {
-  generateRoutes({
-    commit
-  }) {
-    return new Promise(async resolve => {
-      getRoule().then(response => {
-        const roles = []
-        handleRoles(response.data, roles, '')
-        console.log('roles', roles)
-        const accessedRoutes = filterAsyncRoutes(constantRoutes, roles)
-
-        commit('user/SET_ROLES', roles, {
-          root: true
+    generateRoutes({
+        commit
+    }) {
+        return new Promise(async resolve => {
+            const data = await getRoule().then().catch(error => {
+                clearStorage()
+                resetRouter()
+            })
+            const roles = []
+            handleRoles(data.data, roles, '')
+            console.log('roles', roles)
+            const accessedRoutes = filterAsyncRoutes(asyncRoutes, roles)
+            commit('user/SET_ROLES', roles, {
+                root: true
+            })
+            commit('SET_ROUTES', accessedRoutes)
+            resolve(accessedRoutes)
         })
-        commit('SET_ROUTES', accessedRoutes)
-        resolve(accessedRoutes)
-      }).catch((err) => {
-        console.error('获取角色错误')
-        clearStorage()
-        resetRouter()
-        removeToken()
-        window.location.href='https://admin.changyuntong56.com/#/login'
-      })
-    })
-  }
+    }
 }
 
 export default {
-  namespaced: true,
-  state,
-  mutations,
-  actions
-}
+    namespaced: true,
+    state,
+    mutations,
+    actions
+}

+ 139 - 147
src/store/modules/user.js

@@ -1,172 +1,164 @@
 import {
-  login,
-  logout,
-  getInfo,
-  getRoule
+    login,
+    logout,
+    getInfo,
+    getRoule
 } from '@/api/user'
 import {
-  getToken,
-  setToken,
-  removeToken
+    getToken,
+    setToken,
+    removeToken,
+    asyncRoutes
 } from '@/utils/auth'
 import {
-  resetRouter
+    resetRouter
 } from '@/router'
 
 const getDefaultState = () => {
-  return {
-    token: getToken(),
-    name: '',
-    avatar: '',
-    roles: [],
-  }
+    return {
+        token: getToken(),
+        name: '',
+        avatar: '',
+        roles: [],
+    }
 }
 
 const state = getDefaultState()
 
 const mutations = {
-  RESET_STATE: (state) => {
-    Object.assign(state, getDefaultState())
-  },
-  SET_TOKEN: (state, token) => {
-    state.token = token
-  },
-  SET_NAME: (state, name) => {
-    state.name = name
-  },
-  SET_AVATAR: (state, avatar) => {
-    state.avatar = avatar
-  },
-  SET_ROLES: (state, roles) => {
-    state.roles = roles
-  },
+    RESET_STATE: (state) => {
+        Object.assign(state, getDefaultState())
+    },
+    SET_TOKEN: (state, token) => {
+        state.token = token
+    },
+    SET_NAME: (state, name) => {
+        state.name = name
+    },
+    SET_AVATAR: (state, avatar) => {
+        state.avatar = avatar
+    },
+    SET_ROLES: (state, roles) => {
+        state.roles = roles
+    },
 }
 
 const actions = {
-  // user login
-  login({
-    commit
-  }, userInfo) {
-    const {
-      companyName,
-      username,
-      password
-    } = userInfo
-    return new Promise((resolve, reject) => {
-      login({
-        companyName: companyName,
-        username: username.trim(),
-        password: password
-      }).then(response => {
-        // const { data } = response
-        // commit('SET_TOKEN', data.token)
-        // setToken(data.token)
-        commit('SET_TOKEN', 'Admin-Token')
-        setToken('Admin-Token')
-        resolve(response)
-      }).catch(error => {
-        reject(error)
-      })
-    })
-  },
-
-  // get user info
-  getInfo({
-    commit,
-    state
-  }) {
-    return new Promise((resolve, reject) => {
-
-      getInfo().then(response => {
+    // user login
+    login({
+        commit
+    }, userInfo) {
         const {
-          data
-        } = response
-        if (!data) {
-          reject('Verification failed, please Login again.')
-        }
-        const {
-          staffName,
-          deptId,
-          deptName,
-          deptNameEn,
-          vessels = [],
-          majorRole: {
-            roleName = '',
-            roleId = '',
-            dutyId = ''
-          },
-          roles
-        } = data
+            companyName,
+            username,
+            password
+        } = userInfo
+        return new Promise((resolve, reject) => {
+            login({
+                companyName: companyName,
+                username: username.trim(),
+                password: password
+            }).then(response => {
+                commit('SET_TOKEN', 'Admin-Token')
+                setToken('Admin-Token')
+                resolve(response)
+            }).catch(error => {
+                reject(error)
+            })
+        })
+    },
 
-        // roles must be a non-empty array
-        // if (!roles || roles.length <= 0) {
-        //   reject('getInfo: roles must be a non-null array!')
-        // }
+    // get user info
+    getInfo({
+        commit,
+        state
+    }) {
+        return new Promise((resolve, reject) => {
 
-        localStorage.setItem('ws-pf_dutyId', dutyId || data.roles[0].dutyId)
-        localStorage.setItem('ws-pf_roleName', roleName || roles[0].roleName)
+            getInfo().then(response => {
+                const {
+                    data
+                } = response
+                if (!data) {
+                    reject('Verification failed, please Login again.')
+                }
+                const {
+                    staffName,
+                    deptId,
+                    deptName,
+                    deptNameEn,
+                    vessels = [],
+                    majorRole: {
+                        roleName = '',
+                        roleId = '',
+                        dutyId = ''
+                    },
+                    roles
+                } = data
+                localStorage.setItem('ws-pf_dutyId', dutyId || data.roles[0].dutyId)
+                localStorage.setItem('ws-pf_roleName', roleName || roles[0].roleName)
 
-        localStorage.setItem('ws-pf_staffName', staffName)
-        localStorage.setItem('ws-pf_deptId', deptId)
-        localStorage.setItem('ws-pf_deptName', deptName)
-        localStorage.setItem('ws-pf_deptNameEn', deptNameEn)
-        localStorage.setItem('ws-pf_vessels', JSON.stringify(vessels))
-        localStorage.setItem('ws-pf_roleId', roleId || roles[0].roleId)
-        resolve(data)
-      }).catch(error => {
-        reject(error)
-      })
-    })
-  },
-  getRoule({
-    commit,
-    state
-  }) {
-    return new Promise(async (resolve, reject) => {
-      try {
-        const data = await getRoule(state.roles)
-        data.forEach(route => {
-          asyncRoutes.push(route)
+                localStorage.setItem('ws-pf_staffName', staffName)
+                localStorage.setItem('ws-pf_deptId', deptId)
+                localStorage.setItem('ws-pf_deptName', deptName)
+                localStorage.setItem('ws-pf_deptNameEn', deptNameEn)
+                localStorage.setItem('ws-pf_vessels', JSON.stringify(vessels))
+                localStorage.setItem('ws-pf_roleId', roleId || roles[0].roleId)
+                resolve(data)
+            }).catch(error => {
+                reject(error)
+            })
         })
-        commit('SET_ROUTES', asyncRoutes)
-        resolve(asyncRoutes)
-      } catch (error) {
-        reject(error)
-      }
-    })
-  },
-  // user logout
-  logout({
-    commit,
-    state
-  }) {
-    return new Promise((resolve, reject) => {
-      logout(state.token).then(() => {
-        removeToken() // must remove  token  first
-        resetRouter()
-        commit('RESET_STATE')
-        resolve()
-      }).catch(error => {
-        reject(error)
-      })
-    })
-  },
+    },
+    getRoule({
+        commit,
+        state
+    }) {
+        return new Promise(async(resolve, reject) => {
+            try {
+                const data = await getRoule(state.roles)
+                data.forEach(route => {
+                    asyncRoutes.push(route)
+                })
+                commit('SET_ROUTES', asyncRoutes)
+                resolve(asyncRoutes)
+            } catch (error) {
+                reject(error)
+            }
+        })
+    },
+    // user logout
+    logout({
+        commit,
+        state
+    }) {
+        return new Promise((resolve, reject) => {
+            logout(state.token).then(() => {
+                removeToken() // must remove  token  first
+                resetRouter()
+                commit('RESET_STATE')
+                resolve()
+            }).catch(error => {
+                reject(error)
+            })
+        })
+    },
 
-  // remove token
-  resetToken({
-    commit
-  }) {
-    return new Promise(resolve => {
-      removeToken() // must remove  token  first
-      commit('RESET_STATE')
-      resolve()
-    })
-  }
+    // remove token
+    resetToken({
+        commit
+    }) {
+        return new Promise(resolve => {
+            removeToken() // must remove  token  first
+            commit('RESET_STATE')
+            resolve()
+        })
+    }
 }
 
 export default {
-  namespaced: true,
-  state,
-  mutations,
-  actions
-}
+    namespaced: true,
+    state,
+    mutations,
+    actions
+}

+ 339 - 26
src/utils/validate.js

@@ -1,47 +1,360 @@
 /**
- * Created by PanJiaChen on 16/11/18.
+ * @param {string} str
+ * @returns {Boolean}
  */
+export function validUsername(str) {
+    // const valid_map = ['admin', 'editor']
+    // return valid_map.indexOf(str.trim()) >= 0
+    return str.length == 11
+}
+
+export function isEnglish(str) {
+    const reg = /^[a-zA-Z, ]+$/;
+    return reg.test(str);
+}
 
 /**
- * @param {string} path
- * @returns {Boolean}
+ * Created by jiachenpan on 16/11/18.
  */
+
 export function isExternal(path) {
-  return /^(https?:|mailto:|tel:)/.test(path)
+    return /^(https?:|mailto:|tel:)/.test(path)
 }
 
-/**
- * @param {string} str
- * @returns {Boolean}
- */
-export function validUsername(str) {
-  // const valid_map = ['admin', 'editor']
-  // return valid_map.indexOf(str.trim()) >= 0
-  return str.length == 11
+export function validPassword(str) {
+    const reg = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,20}$/
+    return reg.test(str)
 }
 
-export function isNumber(str) {
-  const reg = /^[0-9]+$/;
-  return reg.test(str);
+export function validUserVeriCode(str) {
+    const reg = /^\d{6}$/
+    return reg.test(str)
 }
 
-export function isEnglish(str) {
-  const reg = /^[a-zA-Z, ]+$/;
-  return reg.test(str);
+export function validUserCellPhone(str) {
+    const reg = /^1[34578]\d{9}$/
+    return reg.test(str)
 }
 
-export function validPassword(str) {
-  const reg = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,20}$/
-  return reg.test(str)
+export function validURL(url) {
+    const reg = /^(https?|ftp):\/\/([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&%$-]+)*@)*((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:[0-9]+)*(\/($|[a-zA-Z0-9.,?'\\+&%$#=~_-]+))*$/
+    return reg.test(url)
+}
+
+export function validLowerCase(str) {
+    const reg = /^[a-z]+$/
+    return reg.test(str)
+}
+
+export function validUpperCase(str) {
+    const reg = /^[A-Z]+$/
+    return reg.test(str)
+}
+
+export function validAlphabets(str) {
+    const reg = /^[A-Za-z]+$/
+    return reg.test(str)
 }
 
 export function validEmail(email) {
-  const reg =
-    /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
-  return reg.test(email)
+    const reg = /^(([^<>()\\[\]\\.,;:\s@"]+(\.[^<>()\\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
+    return reg.test(email)
+}
+
+export function isString(str) {
+    if (typeof str === 'string' || str instanceof String) {
+        return true
+    }
+    return false
+}
+
+export function isArray(arg) {
+    if (typeof Array.isArray === 'undefined') {
+        return Object.prototype.toString.call(arg) === '[object Array]'
+    }
+    return Array.isArray(arg)
+}
+export function isNumber(str) {
+    const reg = /^[0-9]+$/
+    return reg.test(str)
+}
+export function cardId(str) {
+    const reg = /^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/
+    return reg.test(str)
+}
+// 正整数
+export function isNumberInteger(str) {
+    const reg = /^[1-9]\d*$/
+    return reg.test(str)
+}
+// 其他电话
+export function otherPhone(str) {
+    const reg = /^[0-9-\-;]*$/
+    return reg.test(str)
 }
 // 纯11位手机号码
 export function mobilePhone(str) {
-  const reg = /^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\d{8}$/
-  return reg.test(str)
+    const reg = /^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\d{8}$/
+    return reg.test(str)
+}
+export function convertTwoDigitNumber(value) {
+    return value.replace(/[^\d.]/g, '')
+        .replace(/\.{2,}/g, '.')
+        .replace('.', '$#$')
+        .replace(/\./g, '')
+        .replace('$#$', '.')
+        .replace(/^(\\-)*(\d+)\.(\d\d).*$/, '$1$2.$3')
+        .replace(/^\./g, '')
+}
+
+
+
+export function isvalidUsername(str) {
+    const valid_map = ['admin', 'editor']
+    return valid_map.indexOf(str.trim()) >= 0
+}
+
+/* 合法uri*/
+export function validateURL(textval) {
+    const urlregex = /^(https?|ftp):\/\/([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&%$-]+)*@)*((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:[0-9]+)*(\/($|[a-zA-Z0-9.,?'\\+&%$#=~_-]+))*$/
+    return urlregex.test(textval)
+}
+/**
+ * 邮箱
+ * @param {*} s
+ */
+export function isEmail(s) {
+    return /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((.[a-zA-Z0-9_-]{2,3}){1,2})$/.test(s)
+}
+
+/**
+ * 手机号码
+ * @param {*} s
+ */
+export function isMobile(s) {
+    return /^1[0-9]{10}$/.test(s)
+}
+
+/**
+ * 电话号码
+ * @param {*} s
+ */
+export function isPhone(s) {
+    return /^([0-9]{3,4}-)?[0-9]{7,8}$/.test(s)
+}
+
+/**
+ * URL地址
+ * @param {*} s
+ */
+export function isURL(s) {
+    return /^http[s]?:\/\/.*/.test(s)
+}
+
+/* 小写字母*/
+export function validateLowerCase(str) {
+    const reg = /^[a-z]+$/
+    return reg.test(str)
+}
+
+/* 大写字母*/
+export function validateUpperCase(str) {
+    const reg = /^[A-Z]+$/
+    return reg.test(str)
+}
+
+/* 大小写字母*/
+export function validatAlphabets(str) {
+    const reg = /^[A-Za-z]+$/
+    return reg.test(str)
+}
+/*验证pad还是pc*/
+export const vaildatePc = function() {
+        const userAgentInfo = navigator.userAgent;
+        const Agents = ['Android', 'iPhone',
+            'SymbianOS', 'Windows Phone',
+            'iPad', 'iPod'
+        ];
+        let flag = true;
+        for (var v = 0; v < Agents.length; v++) {
+            if (userAgentInfo.indexOf(Agents[v]) > 0) {
+                flag = false;
+                break;
+            }
+        }
+        return flag;
+    }
+    /**
+     * validate email
+     * @param email
+     * @returns {boolean}
+     */
+export function validateEmail(email) {
+    const re = /^(([^<>()\\[\]\\.,;:\s@"]+(\.[^<>()\\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
+    return re.test(email)
 }
+
+/**
+ * 判断身份证号码
+ */
+export function cardid(code) {
+    let list = [];
+    let result = true;
+    let msg = '';
+    var city = {
+        11: '北京',
+        12: '天津',
+        13: '河北',
+        14: '山西',
+        15: '内蒙古',
+        21: '辽宁',
+        22: '吉林',
+        23: '黑龙江 ',
+        31: '上海',
+        32: '江苏',
+        33: '浙江',
+        34: '安徽',
+        35: '福建',
+        36: '江西',
+        37: '山东',
+        41: '河南',
+        42: '湖北 ',
+        43: '湖南',
+        44: '广东',
+        45: '广西',
+        46: '海南',
+        50: '重庆',
+        51: '四川',
+        52: '贵州',
+        53: '云南',
+        54: '西藏 ',
+        61: '陕西',
+        62: '甘肃',
+        63: '青海',
+        64: '宁夏',
+        65: '新疆',
+        71: '台湾',
+        81: '香港',
+        82: '澳门',
+        91: '国外 '
+    };
+    if (!validatenull(code)) {
+        if (code.length == 18) {
+            if (!code || !/(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(code)) {
+                msg = '证件号码格式错误';
+            } else if (!city[code.substr(0, 2)]) {
+                msg = '地址编码错误';
+            } else {
+                //18位身份证需要验证最后一位校验位
+                code = code.split('');
+                //∑(ai×Wi)(mod 11)
+                //加权因子
+                var factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
+                //校验位
+                var parity = [1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2, 'x'];
+                var sum = 0;
+                var ai = 0;
+                var wi = 0;
+                for (var i = 0; i < 17; i++) {
+                    ai = code[i];
+                    wi = factor[i];
+                    sum += ai * wi;
+                }
+                if (parity[sum % 11] != code[17]) {
+                    msg = '证件号码校验位错误';
+                } else {
+                    result = false;
+                }
+
+            }
+        } else {
+            msg = '证件号码长度不为18位';
+        }
+
+    } else {
+        msg = '证件号码不能为空';
+    }
+    list.push(result);
+    list.push(msg);
+    return list;
+}
+/**
+ * 判断手机号码是否正确
+ */
+export function isvalidatemobile(phone) {
+    let list = [];
+    let result = true;
+    let msg = '';
+    var isPhone = /^0\d{2,3}-?\d{7,8}$/;
+    //增加134 减少|1349[0-9]{7},增加181,增加145,增加17[678]
+    if (!validatenull(phone)) {
+        if (phone.length == 11) {
+            if (isPhone.test(phone)) {
+                msg = '手机号码格式不正确';
+            } else {
+                result = false;
+            }
+        } else {
+            msg = '手机号码长度不为11位';
+        }
+    } else {
+        msg = '手机号码不能为空';
+    }
+    list.push(result);
+    list.push(msg);
+    return list;
+}
+/**
+ * 判断姓名是否正确
+ */
+export function validatename(name) {
+    var regName = /^[\u4e00-\u9fa5]{2,4}$/;
+    if (!regName.test(name)) return false;
+    return true;
+}
+/**
+ * 判断是否为整数
+ */
+export function validatenum(num, type) {
+    let regName = /[^\d.]/g;
+    if (type == 1) {
+        if (!regName.test(num)) return false;
+    } else if (type == 2) {
+        regName = /[^\d]/g;
+        if (!regName.test(num)) return false;
+    }
+    return true;
+}
+/**
+ * 判断是否为小数
+ */
+export function validatenumord(num, type) {
+    let regName = /[^\d.]/g;
+    if (type == 1) {
+        if (!regName.test(num)) return false;
+    } else if (type == 2) {
+        regName = /[^\d.]/g;
+        if (!regName.test(num)) return false;
+    }
+    return true;
+}
+/**
+ * 判断是否为空
+ */
+export function validatenull(val) {
+    if (typeof val == 'boolean') {
+        return false;
+    }
+    if (typeof val == 'number') {
+        return false;
+    }
+    if (val instanceof Array) {
+        if (val.length == 0) return true;
+    } else if (val instanceof Object) {
+        if (JSON.stringify(val) === '{}') return true;
+    } else {
+        if (val == 'null' || val == null || val == 'undefined' || val == undefined || val == '') return true;
+        return false;
+    }
+    return false;
+}