@peng_kai/kit 0.2.27 → 0.2.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import { Checkbox } from 'ant-design-vue';
|
|
2
|
+
import { Checkbox, FormItemRest } from 'ant-design-vue';
|
|
3
3
|
import { computed, triggerRef, watch } from 'vue';
|
|
4
4
|
|
|
5
5
|
interface TTree {
|
|
@@ -9,19 +9,6 @@ interface TTree {
|
|
|
9
9
|
children?: TTree[]
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
export function treeToIds(tree: TTree[]) {
|
|
13
|
-
const ids = [] as number[];
|
|
14
|
-
|
|
15
|
-
const isCheckedFn = (node: TTree) => {
|
|
16
|
-
node.checked && ids.push(node.id);
|
|
17
|
-
node.children?.length && node.children.forEach(isCheckedFn);
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
tree.forEach(isCheckedFn);
|
|
21
|
-
|
|
22
|
-
return ids;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
12
|
function treeToTable(tree: TTree[]) {
|
|
26
13
|
interface TD {
|
|
27
14
|
id: number
|
|
@@ -79,47 +66,36 @@ function treeToStates(tree: TTree[]) {
|
|
|
79
66
|
|
|
80
67
|
tree.forEach(assId);
|
|
81
68
|
|
|
82
|
-
// for (const id in ids) {
|
|
83
|
-
// const state = states[id];
|
|
84
|
-
// state.indet = isIndet(state.children.map(cid => states[cid].checked));
|
|
85
|
-
// state.children.forEach(cid => states[cid].checked = state.checked);
|
|
86
|
-
// [...state.parents].reverse().forEach((pid) => {
|
|
87
|
-
// const checks = states[pid].children.map(cid => states[cid].checked);
|
|
88
|
-
// state.indet = isIndet(checks);
|
|
89
|
-
// state.checked = checks.every(checked => checked);
|
|
90
|
-
// });
|
|
91
|
-
// }
|
|
92
|
-
|
|
93
|
-
// Object.keys(states)
|
|
94
|
-
// [...ids].forEach((id) => {
|
|
95
|
-
// const state = states[id];
|
|
96
|
-
// state.checked = true;
|
|
97
|
-
// state.children.forEach((cid) => {
|
|
98
|
-
// states[cid].checked = true;
|
|
99
|
-
// states[cid].indet = false;
|
|
100
|
-
// });
|
|
101
|
-
// });
|
|
102
|
-
|
|
103
69
|
return states;
|
|
104
70
|
}
|
|
105
71
|
|
|
106
72
|
function updateStates(states: ReturnType<typeof treeToStates>, id: number, checked: boolean) {
|
|
107
73
|
const state = states[id];
|
|
74
|
+
|
|
75
|
+
if (!state)
|
|
76
|
+
return;
|
|
77
|
+
|
|
108
78
|
state.checked = checked;
|
|
109
79
|
state.indet = false;
|
|
110
80
|
state.children.forEach((cid) => {
|
|
111
|
-
states[cid]
|
|
112
|
-
|
|
81
|
+
const cState = states[cid];
|
|
82
|
+
if (cState) {
|
|
83
|
+
cState.checked = checked;
|
|
84
|
+
cState.indet = false;
|
|
85
|
+
}
|
|
113
86
|
});
|
|
114
|
-
[...state.parents].
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
87
|
+
[...state.parents].forEach((pid) => {
|
|
88
|
+
const pState = states[pid];
|
|
89
|
+
if (pState) {
|
|
90
|
+
const checks = pState.children.map(cid => states[cid]?.checked);
|
|
91
|
+
pState.indet = isIndet(checks);
|
|
92
|
+
pState.checked = checks.every(checked => checked);
|
|
93
|
+
}
|
|
118
94
|
});
|
|
119
95
|
}
|
|
120
96
|
|
|
121
97
|
function statesToIds(states: ReturnType<typeof treeToStates>) {
|
|
122
|
-
return Object.keys(states).map(Number).filter(id => states[id]
|
|
98
|
+
return Object.keys(states).map(Number).filter(id => states[id]?.checked);
|
|
123
99
|
}
|
|
124
100
|
|
|
125
101
|
function findAllParents(tree: any[], id: number, path: any[] = []): any[] | undefined {
|
|
@@ -157,60 +133,71 @@ function isIndet(arr: boolean[]) {
|
|
|
157
133
|
|
|
158
134
|
<script setup lang="ts">
|
|
159
135
|
const props = defineProps<{
|
|
160
|
-
treeData: TTree[]
|
|
136
|
+
treeData: TTree[] | null | undefined
|
|
161
137
|
}>();
|
|
162
138
|
const ids = defineModel<number[]>('value', { default: [] });
|
|
163
|
-
const tableData = computed(() => treeToTable(props.treeData));
|
|
164
|
-
const stateMap = computed(() => treeToStates(props.treeData));
|
|
139
|
+
const tableData = computed(() => props.treeData && treeToTable(props.treeData));
|
|
140
|
+
const stateMap = computed(() => props.treeData && treeToStates(props.treeData));
|
|
165
141
|
|
|
166
142
|
watch(ids, (newV, oldV) => {
|
|
167
|
-
if (newV === oldV)
|
|
143
|
+
if (newV === oldV || !stateMap.value)
|
|
168
144
|
return;
|
|
169
145
|
|
|
170
|
-
newV.forEach(id => updateStates(stateMap.value
|
|
146
|
+
newV.forEach(id => updateStates(stateMap.value!, id, true));
|
|
171
147
|
triggerRef(stateMap);
|
|
172
148
|
}, { immediate: true });
|
|
173
149
|
|
|
150
|
+
watch(stateMap, (newV) => {
|
|
151
|
+
if (newV) {
|
|
152
|
+
ids.value.forEach(id => updateStates(newV, id, true));
|
|
153
|
+
triggerRef(stateMap);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
|
|
174
157
|
function onCheckChange(id: number) {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
158
|
+
if (stateMap.value) {
|
|
159
|
+
const checked = !ids.value.includes(id);
|
|
160
|
+
updateStates(stateMap.value, id, checked);
|
|
161
|
+
ids.value = statesToIds(stateMap.value);
|
|
162
|
+
}
|
|
178
163
|
}
|
|
179
164
|
</script>
|
|
180
165
|
|
|
181
166
|
<template>
|
|
182
167
|
<table class="w-full border-collapse border-$antd-colorBorderSecondary" border>
|
|
183
|
-
<
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
<
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
<
|
|
196
|
-
:checked="stateMap[row[1].id].indet ? false : stateMap[row[1].id].checked"
|
|
197
|
-
:indeterminate="stateMap[row[1].id].indet" @change="onCheckChange(row[1].id)"
|
|
198
|
-
>
|
|
199
|
-
{{ row[1].label }}
|
|
200
|
-
</Checkbox>
|
|
201
|
-
</td>
|
|
202
|
-
<!-- 功能 -->
|
|
203
|
-
<td v-if="row[2]" class="px-[1em] py-0.5em">
|
|
204
|
-
<div class="feat-list">
|
|
168
|
+
<FormItemRest>
|
|
169
|
+
<tr v-for="(row, ri) of tableData" :key="ri">
|
|
170
|
+
<!-- 模块 -->
|
|
171
|
+
<td v-if="row[0]" class="w-[6em] px-[1em] py-0.5em" :rowspan="row[0].span">
|
|
172
|
+
<Checkbox
|
|
173
|
+
:checked="stateMap?.[row[0].id].indet ? false : stateMap?.[row[0].id].checked"
|
|
174
|
+
:indeterminate="stateMap?.[row[0].id].indet" @change="onCheckChange(row[0].id)"
|
|
175
|
+
>
|
|
176
|
+
{{ row[0].label }}{{ row[0].id }}
|
|
177
|
+
</Checkbox>
|
|
178
|
+
</td>
|
|
179
|
+
<!-- 页面 -->
|
|
180
|
+
<td v-if="row[1]" class="w-[9em] px-[1em] py-0.5em">
|
|
205
181
|
<Checkbox
|
|
206
|
-
|
|
207
|
-
@change="onCheckChange(
|
|
182
|
+
:checked="stateMap?.[row[1].id].indet ? false : stateMap?.[row[1].id].checked"
|
|
183
|
+
:indeterminate="stateMap?.[row[1].id].indet" @change="onCheckChange(row[1].id)"
|
|
208
184
|
>
|
|
209
|
-
{{
|
|
185
|
+
{{ row[1].label }} {{ row[1].id }}
|
|
210
186
|
</Checkbox>
|
|
211
|
-
</
|
|
212
|
-
|
|
213
|
-
|
|
187
|
+
</td>
|
|
188
|
+
<!-- 功能 -->
|
|
189
|
+
<td v-if="row[2]" class="px-[1em] py-0.5em">
|
|
190
|
+
<div class="feat-list">
|
|
191
|
+
<Checkbox
|
|
192
|
+
v-for="fItem of row[2]" :key="fItem?.id" :checked="stateMap?.[fItem.id].checked"
|
|
193
|
+
@change="onCheckChange(fItem.id)"
|
|
194
|
+
>
|
|
195
|
+
{{ fItem.label }} {{ fItem.id }}
|
|
196
|
+
</Checkbox>
|
|
197
|
+
</div>
|
|
198
|
+
</td>
|
|
199
|
+
</tr>
|
|
200
|
+
</FormItemRest>
|
|
214
201
|
</table>
|
|
215
202
|
</template>
|
|
216
203
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { default as PermissionTreeCheckbox
|
|
1
|
+
export { default as PermissionTreeCheckbox } from './PermissionTree.vue';
|