Bladeren bron

角色新增与授权

zhaoxiaohai 2 jaren geleden
bovenliggende
commit
ff4aeb1948

+ 46 - 12
components/My_categoryListings/index.js

@@ -29,21 +29,20 @@ Component({
         systemIndex: 0, //系统index
         portIndex: 0, //选择端口Index
         moduleIndex: 0, //选择模块Index
-        result: ['a', 'b'],
         portID: null, //端口ID
         leftIntoViewId: null,
         rightIntoViewId: null,
         heightList: [],
         modulesIndex: 0, //模块列表
-        scrollTop: 0
+        scrollTop: 0,
+        checkList: [], //选中列表
     },
 
     observers: {
         'list': function (list) {
+            console.log(12)
             if (!list.length) return;
             let data = list[0].clients[0];
-            console.log("list", list)
-            console.log("data", data)
             let id = data.modules[0] ? "M" + data.modules[0].systemmoduleid : '';
             if (this.data.portID == null) this.setData({
                 portID: 'S' + data.systemclientid,
@@ -60,6 +59,36 @@ Component({
      * 组件的方法列表
      */
     methods: {
+        /* 模块选择 */
+        checkBack(e) {
+            let list = this.data.checkList,
+                obj = {
+                    id: e.target.id - 0,
+                    arr: JSON.parse(JSON.stringify(e.detail.arr))
+                };
+            const index = list.findIndex(v => v.id == obj.id);
+            if (index == -1) {
+                list.push(obj)
+            } else {
+                list.splice(index, 1, obj)
+            }
+            let idList = e.detail.apps.map(v => v.systemappid);
+            const i = list.findIndex(v => v.id == obj.id);
+            list[i].arr = list[i].arr.filter(v => idList.includes(v.systemappid));
+            this.setData({
+                checkList: list
+            });
+            const mIndex = this.data.list[this.data.systemIndex].clients[this.data.portIndex].modules.findIndex(v => v.systemmoduleid == obj.id);
+            this.setData({
+                [`list[${this.data.systemIndex}].clients[${this.data.portIndex}].modules[${mIndex}].apps`]: e.detail.apps
+            })
+
+        },
+        backData() {
+            let newArr = [];
+            this.data.checkList.forEach(v => newArr = newArr.concat(v.arr));
+            return newArr;
+        },
         /* 系统分类 */
         changePortID(e) {
             const {
@@ -93,15 +122,20 @@ Component({
                 query.exec(res => {
                     if (!res[0]) return this.getAppsHeight();
                     heightList.push(res[0])
-                    if (list.length == heightList.length) this.setData({
-                        heightList,
-                        leftIntoViewId: id,
-                        rightIntoViewId: id
-                    })
+                    if (list.length == heightList.length) {
+                        this.setData({
+                            heightList,
+                            leftIntoViewId: id,
+                            rightIntoViewId: id
+                        })
+                        let MyArr = that.selectAllComponents('.My_group');
+                        for (let k = 0; k < MyArr.length; k++) {
+                            MyArr[k].refactorDom();
+                        }
+                    }
                 })
-            }
+            };
         },
-
         viewScroll({
             detail
         }) {
@@ -119,7 +153,7 @@ Component({
                 })
             } else if (scrollTop < top) {
                 if (!arr[i - 1] || id == arr[0].id) return;
-                if (scrollTop < Math.abs(arr[i - 1].top - arr[i - 1].height + 80)) this.setData({
+                if (scrollTop < Math.abs(arr[i - 1].top - arr[i - 1].height / 2)) this.setData({
                     leftIntoViewId: arr[i - 1].id
                 })
             } else {

+ 1 - 2
components/My_categoryListings/index.json

@@ -1,7 +1,6 @@
 {
     "component": true,
     "usingComponents": {
-        "van-checkbox": "@vant/weapp/checkbox/index",
-        "van-checkbox-group": "@vant/weapp/checkbox-group/index"
+        "group": "./modules/group"
     }
 }

+ 2 - 14
components/My_categoryListings/index.scss

@@ -94,22 +94,10 @@
                 margin-top: 0rpx;
             }
 
-            .custom-checkbox {
-                margin-top: 20rpx;
-                width: 50% !important;
-                margin-left: 15rpx;
-            }
 
-            .check-label {
-                margin-left: -10rpx;
-            }
 
-            .label-text {
-                padding-left: 10rpx;
-                font-size: 28rpx;
-                font-family: PingFang SC-Medium, PingFang SC;
-                color: #666666;
-            }
+         
+
         }
     }
 }

+ 2 - 7
components/My_categoryListings/index.wxml

@@ -15,13 +15,8 @@
     </scroll-view>
 
     <scroll-view class="right-list" bindscroll='viewScroll' scroll-top='{{scrollTop}}' scroll-into-view='{{rightIntoViewId}}' scroll-with-animation scroll-y style="height: {{height}}rpx;">
-        <view class="group {{'M1'+item.systemmoduleid}}" wx:for="{{list[systemIndex].clients[portIndex].modules}}" id="{{'M'+item.systemmoduleid}}">
-            <block wx:for="{{item.apps}}" wx:for-item="apps">
-                <van-checkbox icon-size='28rpx' custom-class='custom-checkbox check-label' label-class='label-text' shape='square' name="{{apps.systemappid}}">{{apps.systemappname}}</van-checkbox>
-                <van-checkbox-group value="{{ result }}" bind:change="onChange">
-                    <van-checkbox wx:for="{{apps.options}}" wx:for-item="options" icon-size='28rpx' custom-class='custom-checkbox ' label-class='label-text' shape='square' name="{{options.optionid}}">{{options.optionname}}</van-checkbox>
-                </van-checkbox-group>
-            </block>
+        <view class="group {{'M1'+item.systemmoduleid}}" wx:for="{{list[systemIndex].clients[portIndex].modules}}" wx:for-index="in" id="{{'M'+item.systemmoduleid}}">
+            <group class="My_group" apps="{{item.apps}}" id='{{item.systemmoduleid}}' bind:callback='checkBack' />
         </view>
         <view style="height: {{height-80}}rpx;" />
     </scroll-view>

+ 135 - 0
components/My_categoryListings/modules/group.js

@@ -0,0 +1,135 @@
+// components/My_categoryListings/modules/group.js
+Component({
+    /**
+     * 组件的属性列表
+     */
+    properties: {
+        apps: {
+            type: Array,
+            value: []
+        },
+        callback: {
+            type: Function
+        },
+    },
+    observers: {
+        "apps": function (apps) {
+            if (this.data.count == 1) return;
+            this.refactorDom();
+        }
+    },
+
+    /**
+     * 组件的初始数据
+     */
+    data: {
+        backupArrays: [],
+        nubArr: [],
+        count: 0,
+        show: true,
+    },
+    /**
+     * 组件的方法列表
+     */
+    methods: {
+        /* 功能单选 */
+        onChange(e) {
+            const {
+                index
+            } = e.currentTarget.dataset;
+            let obj = {
+                systemappid: e.currentTarget.id - 0,
+                optionids: e.detail
+            };
+            let arr = this.data.backupArrays,
+                nubArr = this.data.nubArr,
+                i = arr.findIndex(v => v.systemappid == obj.systemappid);
+            if (e.detail.length > 0) {
+                if (i == -1) {
+                    arr.push(obj);
+                    nubArr.push(obj.systemappid);
+                } else {
+                    arr[i] = obj;
+                }
+            } else {
+                nubArr.splice(i, 1)
+                arr.splice(i, 1)
+            };
+            this.setData({
+                ["apps[" + index + "].optionids"]: obj.optionids,
+                backupArrays: arr,
+                nubArr
+            });
+            this.triggerEvent("callback", {
+                arr: this.data.backupArrays,
+                apps: this.data.apps
+            });
+        },
+        /* 类选择 */
+        classClick(e) {
+            const {
+                item
+            } = e.currentTarget.dataset;
+            let i = this.data.nubArr.findIndex(v => v == item.systemappid);
+            if (i == -1) {
+                const obj = {
+                    systemappid: item.systemappid,
+                    optionids: item.options.map(v => v.optionid.toString())
+                };
+                this.data.backupArrays.push(obj);
+                this.data.nubArr.push(item.systemappid);
+                let index = this.data.apps.findIndex(v => v.systemappid == item.systemappid);
+                this.setData({
+                    backupArrays: this.data.backupArrays,
+                    nubArr: this.data.nubArr,
+                    ["apps[" + index + "].optionids"]: obj.optionids
+                })
+            } else {
+                let index = this.data.apps.findIndex(v => v.systemappid == item.systemappid);
+                this.setData({
+                    ["apps[" + index + "].optionids"]: [],
+                    nubArr: this.data.nubArr.filter(v => v != item.systemappid),
+                    backupArrays: this.data.backupArrays.filter(v => v.systemappid != item.systemappid)
+                });
+            };
+            this.triggerEvent("callback", {
+                arr: this.data.backupArrays,
+                apps: this.data.apps
+            });
+        },
+        /* 重构 */
+        refactorDom() {
+            let apps = this.data.apps;
+            let arr = [],
+                nubArr = [];
+            for (let i = 0; i < apps.length; i++) {
+                if (apps[i].optionids.length == 0) continue;
+                let obj = {
+                    systemappid: apps[i].systemappid,
+                    optionids: apps[i].optionids.map(v => v + '')
+                };
+                arr.push(obj);
+                nubArr.push(apps[i].systemappid);
+                this.setData({
+                    [`apps[${i}].optionids`]: apps[i].optionids.map(v => v + '')
+                })
+            };
+            this.setData({
+                backupArrays: arr,
+                nubArr,
+                count: 1
+            })
+            if (arr.length == 0) return;
+            this.triggerEvent("callback", {
+                arr: this.data.backupArrays,
+                apps: this.data.apps
+            });
+            this.setData({
+                show: false
+            })
+            this.setData({
+                show: true
+            })
+        },
+    }
+})

+ 7 - 0
components/My_categoryListings/modules/group.json

@@ -0,0 +1,7 @@
+{
+    "component": true,
+    "usingComponents": {
+        "van-checkbox": "@vant/weapp/checkbox/index",
+        "van-checkbox-group": "@vant/weapp/checkbox-group/index"
+    }
+}

+ 16 - 0
components/My_categoryListings/modules/group.scss

@@ -0,0 +1,16 @@
+.custom-checkbox {
+    margin-top: 20rpx;
+    width: 100% !important;
+    margin-left: 15rpx;
+}
+
+.check-label {
+    margin-left: -10rpx;
+}
+
+.label-text {
+    padding-left: 10rpx;
+    font-size: 28rpx;
+    font-family: PingFang SC-Medium, PingFang SC;
+    color: #666666;
+}

+ 14 - 0
components/My_categoryListings/modules/group.wxml

@@ -0,0 +1,14 @@
+<view wx:for="{{apps}}" wx:for-item="apps">
+    <van-checkbox icon-size='28rpx' custom-class='custom-checkbox check-label' label-class='label-text' value="{{isCheck.isCheck(apps.systemappid,nubArr)}}" shape='square' data-item="{{apps}}" bindtap="classClick">{{apps.systemappname}}</van-checkbox>
+    <van-checkbox-group wx:if="{{show}}" wx:key="index" value="{{apps.optionids}}" data-index="{{index}}" id="{{apps.systemappid}}" bind:change="onChange">
+        <van-checkbox wx:for="{{apps.options}}" wx:key="{{options.optionid}}" wx:for-item="options" icon-size='28rpx' custom-class='custom-checkbox ' label-class='label-text' shape='square' name="{{options.optionid}}">{{options.optionname}}</van-checkbox>
+    </van-checkbox-group>
+</view>
+<!-- <button bindtap="cha">2121</button> -->
+<wxs module="isCheck">
+    module.exports.isCheck = function (id, arr) {
+        for (var i = 0; i < arr.length; i++) {
+            if (arr[i] == id) return true;
+        };
+    }
+</wxs>

+ 15 - 0
pages/teams/addRole.js

@@ -78,6 +78,7 @@ Page({
             isReturn,
             returnData
         } = this.selectComponent("#form").getData();
+
         _Http.basic({
             "classname": "sale.role.role",
             "method": "insertormodify_role",
@@ -86,6 +87,7 @@ Page({
                 ...returnData
             }
         }).then(res => {
+            console.log("新建角色", res)
             this.setData({
                 loading: false
             })
@@ -96,6 +98,19 @@ Page({
             this.setData({
                 disabled: true
             })
+            let systemapps = this.selectComponent("#myCateg").backData();
+
+            if (systemapps.length > 0) _Http.basic({
+                "classname": "sale.role.role",
+                "method": "add_appauth",
+                "content": {
+                    "roleid": res.data.roleid,
+                    systemapps
+                }
+            }).then(res => {
+                console.log("绑定授权", res)
+            })
+
             let pages = getCurrentPages(),
                 prevPage = pages[pages.length - 2];
             prevPage.getList(true);

+ 1 - 1
pages/teams/addRole.wxml

@@ -5,7 +5,7 @@
     <view>模块</view>
     <view>应用</view>
 </view>
-<My_categoryListings height='{{height}}' list='{{appList}}'></My_categoryListings>
+<My_categoryListings id="myCateg" height='{{height}}' list='{{appList}}' />
 
 <view class="footer">
     <van-button disabled='{{disabled}}' loading='{{loading}}' bindtap="submitRole" loading-text="保存中..." custom-class='submit'>保存</van-button>

+ 1 - 1
project.config.json

@@ -52,7 +52,7 @@
     },
     "compileType": "miniprogram",
     "libVersion": "2.19.4",
-    "appid": "wx210f6f5080f20d0c",
+    "appid": "wx8fa10446dd041b67",
     "projectname": "miniprogram-92",
     "condition": {},
     "editorSetting": {