lilei 2 سال پیش
والد
کامیت
e73e8a50b5
2فایلهای تغییر یافته به همراه44 افزوده شده و 8 حذف شده
  1. 42 6
      src/views/power/role/menuModal.vue
  2. 2 2
      vue.config.js

+ 42 - 6
src/views/power/role/menuModal.vue

@@ -90,6 +90,7 @@ export default {
       authAllPrice: [],
       leafNode:[],
       checkLeafNode:[],
+      priceCheckNode:[],
       form: {},
       rules: {},
       authType: '1',
@@ -165,9 +166,18 @@ export default {
       const _this = this
       this.$refs.ruleForm.validate(valid => {
         if (valid) {
-          const arr = [...this.checkedKeys, ...this.halfCheckedKeys, ...this.checkedData].filter((x, index,self)=>self.indexOf(x)===index) 
-          console.log(this.checkedData)
-
+          // 功能权限时的已选价格菜单或价格权限时的已选功能菜单
+          const checkData = this.authType == 1 ? this.priceCheckNode : this.checkedData.filter(item => !this.priceCheckNode.includes(item))
+          // 功能权限时,首次半选节点拿不到值(this.halfCheckedKeys为空时),
+          // 此时通过从所有已选checkedData数据中过滤当前选择的功能菜单和已选的价格菜单,剩下的就是半选节点
+          let halfCheckedKeys = this.halfCheckedKeys.length ? this.halfCheckedKeys : this.checkedData.filter(item => ![...this.checkedKeys,...checkData].includes(item))
+          // 功能权限没有选择任何菜单或价格权限时,halfCheckedKeys 半选节点为空
+          if(this.checkedKeys.length==0 || this.authType == 0){
+            halfCheckedKeys = []
+          }
+          // 最终保存的节点,包括当前已选的和半选的节点
+          const arr = [...this.checkedKeys, ...halfCheckedKeys, ...checkData].filter((x, index,self)=>self.indexOf(x)===index) 
+          console.log(arr, '--444--')
           _this.spinning = true
           addMenuPower({ id: this.id, menuIds: arr.join(',') }).then(res => {
             if (res.status == 200) {
@@ -257,6 +267,25 @@ export default {
         }
       }
     },
+    // 根据id查找是否价格菜单
+    getPriceTreeNode(data, arr){
+      const _this = this
+      for (let i = 0; i < data.length; i++) {
+        const node = data[i]
+        if(_this.isPriceNode(node)){
+           // 默认回显已选节点
+          const hasCheck = _this.priceCheckNode.find(item => item == node.id)
+          // 已选节点勾选
+          const hasNode = arr.find(item => item == node.id)
+          if (hasNode && !hasCheck) {
+            _this.priceCheckNode.push(node.id)
+          }
+        }
+        if (node.children && node.children.length) {
+          _this.getPriceTreeNode(node.children, arr)
+        }
+      }
+    },
     pageInit(){
       this.id = this.nowData.role.id
       this.titleText = (this.nowData.type == 1 ? '功能权限分配': '价格权限分配') + '(' + this.nowData.role.name + ')'
@@ -265,20 +294,26 @@ export default {
       // 权限类型, 1功能权限设置,0 价格权限设置
       this.authType = this.nowData.type
       this.checkedData = arr ? arr.split(',') : []
+
       // 找出叶子节点
       const treeData = this.nowData.allMenuList
-      
       this.expandedKeys.push(treeData.id)
+
+      // 获取已选的价格菜单
+      this.getPriceTreeNode(treeData, this.checkedData)
+
+      // 功能权限设置
       if(this.authType == 1){
         this.findLeaf(treeData, this.checkedData)
       }
+      // 价格权限设置
       if(this.authType == 0){
         this.findPrice(treeData, this.checkedData)
         this.hasAllSelect()
       }
-      this.checkedData = this.checkedData.filter(item => !this.checkedKeys.includes(item))
-      // console.log(this.checkedData)
       // console.log(this.checkedKeys)
+      // console.log(this.checkedData)
+      
       this.treeData = treeData
 
       if(this.authType == 0){
@@ -308,6 +343,7 @@ export default {
         this.id = ''
         this.authAllPrice = []
         this.checkLeafNode = []
+        this.priceCheckNode = []
         this.leafNode = []
         this.checkedKeys = []
         this.expandedKeys = []

+ 2 - 2
vue.config.js

@@ -108,9 +108,9 @@ const vueConfig = {
     // If you want to turn on the proxy, please remosve the mockjs /src/main.jsL11
     proxy: {
       '/api': {
-        target: 'http://192.168.2.117/ocs-admin',
+        // target: 'http://192.168.2.117/ocs-admin',
         // target: 'https://t.ocs.360arrow.com/ocs-admin', //  练习
-        // target: 'https://p.ocs.360arrow.com/ocs-admin', //  预发布
+        target: 'https://p.ocs.360arrow.com/ocs-admin', //  预发布
         ws: false,
         changeOrigin: true,
         pathRewrite: {