user-system-auth.vue
3.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<template>
<div>
<div class="group-row clearfix" v-for="(pi, line) in resourceList">
<div class="form-group" v-for="(index, item) in line">
<div class="label">
<checkbox
:list="[{value: item.parent.id, label:item.parent.name}]"
:layout="['bold']"
:selected.sync="selectedHeadArray[pi * 3 + index]"
@manual-change="selectAll(pi * 3 + index)"></checkbox>
</div>
<div class="control">
<checkbox
v-for="child in item.children"
:selected.sync="selectedArray[pi * 3 + index]"
:list="[{value: child.id, label: child.name}]"
:layout="['block']"></checkbox>
</div>
</div>
</div>
</div>
</template>
<script>
module.exports ={
props: {
'resource': {
type: Array
},
'selectedResource': {
type: Array,
twoWay: true
}
},
data: function () {
return {
resourceArray: [],
resourceList: [],
isManual: false,
selectedHeadArray: [[], [], [], [], [], [], []],
selectedArray: [[], [], [], [], [], [], []]
};
},
watch: {
'selectedResource': function (arr) {
// 如果是手动同步值,不再修改状态
if (this.isManual) {
return true;
}
var self = this;
_.each(this.resourceArray, function (classify, index) {
var selected = [];
_.each(classify.children, function (item) {
if (_.indexOf(arr, item.id) > -1) {
selected.push(item.id);
}
});
self.selectedArray.$set(index, selected);
});
},
'resource': function (val) {
//var list = flushAuth(val);
//
alert(val);
this.resourceArray =val;// [].concat(list);
///this.resourceList = [];
// this.resourceList.push(list.slice(0, 3));
//this.resourceList.push(list.slice(3, 6));
},
selectedArray: function (arr) {
alert(arr);
var self = this;
_.each(this.resourceArray, function (classify, index) {
var totalLen = classify.children.length;
if (arr[index].length === totalLen) {
self.selectedHeadArray.$set(index, [classify.parent.id]);
} else {
self.selectedHeadArray.$set(index, []);
}
});
}
},
methods: {
selectAll: function (index) {
if (this.selectedHeadArray[index].length) {
var result = _.map(this.resourceArray[index].children, function (item) {
return item.id;
});
this.selectedArray.$set(index, result);
} else {
this.selectedArray.$set(index, []);
}
}
},
events: {
'sync-resource': function () {
var self = this;
this.isManual = true;
var _concat = [].concat;
this.selectedResource = _concat.apply(_concat.apply([], this.selectedHeadArray), this.selectedArray);
window.setTimeout(function () {
self.isManual = false;
}, 50)
}
}
};
function flushAuth(sysAuthList) {
var parentList = {};
var sortArray = new Array(6);
_.each(sysAuthList, function (item) {
if (!item.parentId) {
if (!parentList[item.id]) {
parentList[item.id] = {
children: []
};
}
sortArray[item.storNo - 1] = item.id;
parentList[item.id].parent = item;
} else {
if (!parentList[item.parentId]) {
parentList[item.parentId] = {
children: []
};
}
parentList[item.parentId].children.push(item);
}
});
var result = [];
for (var i = 0, len = sortArray.length; i < len; i++) {
result.push(parentList[sortArray[i]]);
}
return result;
}
</script>