|
@@ -14,54 +14,11 @@
|
|
</t-form-item>
|
|
</t-form-item>
|
|
|
|
|
|
<t-form-item label="绑定权限" required-mark>
|
|
<t-form-item label="绑定权限" required-mark>
|
|
- <div>
|
|
|
|
- <div class="m-b-10px">
|
|
|
|
- <t-button theme="primary" @click="allCheckHandler(true)"
|
|
|
|
- >全选</t-button
|
|
|
|
- >
|
|
|
|
- <t-button
|
|
|
|
- theme="primary"
|
|
|
|
- variant="outline"
|
|
|
|
- @click="allCheckHandler(false)"
|
|
|
|
- class="m-l-10px"
|
|
|
|
- >全不选</t-button
|
|
|
|
- >
|
|
|
|
- </div>
|
|
|
|
- <t-table
|
|
|
|
- row-key="id"
|
|
|
|
- :columns="columns"
|
|
|
|
- :data="treeFlatArr"
|
|
|
|
- bordered
|
|
|
|
- v-loading="loading"
|
|
|
|
- >
|
|
|
|
- <template #page="{ row }">
|
|
|
|
- <t-checkbox
|
|
|
|
- v-model="row.hasRole"
|
|
|
|
- @change="pageRoleChange(row)"
|
|
|
|
- ></t-checkbox>
|
|
|
|
- </template>
|
|
|
|
- <template #conditions="{ row }">
|
|
|
|
- <div v-for="item in row.conditions" :key="item.id">
|
|
|
|
- <t-checkbox v-model="item.hasRole">{{ item.name }}</t-checkbox>
|
|
|
|
- </div>
|
|
|
|
- </template>
|
|
|
|
- <template #buttons="{ row }">
|
|
|
|
- <div v-for="item in row.buttons" :key="item.id">
|
|
|
|
- <t-checkbox v-model="item.hasRole">{{ item.name }}</t-checkbox>
|
|
|
|
- </div>
|
|
|
|
- </template>
|
|
|
|
- <template #lists="{ row }">
|
|
|
|
- <div v-for="item in row.lists" :key="item.id">
|
|
|
|
- <t-checkbox v-model="item.hasRole">{{ item.name }}</t-checkbox>
|
|
|
|
- </div>
|
|
|
|
- </template>
|
|
|
|
- <template #links="{ row }">
|
|
|
|
- <div v-for="item in row.links" :key="item.id">
|
|
|
|
- <t-checkbox v-model="item.hasRole">{{ item.name }}</t-checkbox>
|
|
|
|
- </div>
|
|
|
|
- </template>
|
|
|
|
- </t-table>
|
|
|
|
- </div>
|
|
|
|
|
|
+ <privilege-edit
|
|
|
|
+ v-if="menus && menus.length"
|
|
|
|
+ ref="privilegeSetRef"
|
|
|
|
+ :menus="menus"
|
|
|
|
+ ></privilege-edit>
|
|
</t-form-item>
|
|
</t-form-item>
|
|
</t-form>
|
|
</t-form>
|
|
<template #foot>
|
|
<template #foot>
|
|
@@ -78,9 +35,10 @@
|
|
</my-drawer>
|
|
</my-drawer>
|
|
</template>
|
|
</template>
|
|
<script setup name="EditRoleDialog">
|
|
<script setup name="EditRoleDialog">
|
|
-import { ref, reactive, watch, computed } from 'vue';
|
|
|
|
|
|
+import { ref, reactive, watch, computed, onMounted, nextTick } from 'vue';
|
|
import { getAllMenuResource, addRole, getRoleDetail } from '@/api/user';
|
|
import { getAllMenuResource, addRole, getRoleDetail } from '@/api/user';
|
|
import { MessagePlugin } from 'tdesign-vue-next';
|
|
import { MessagePlugin } from 'tdesign-vue-next';
|
|
|
|
+import PrivilegeEdit from './privilege-edit.vue';
|
|
|
|
|
|
const props = defineProps({
|
|
const props = defineProps({
|
|
visible: Boolean,
|
|
visible: Boolean,
|
|
@@ -93,8 +51,10 @@ const title = computed(() => {
|
|
});
|
|
});
|
|
|
|
|
|
const formRef = ref(null);
|
|
const formRef = ref(null);
|
|
|
|
+const privilegeSetRef = ref(null);
|
|
const formData = reactive({
|
|
const formData = reactive({
|
|
name: '',
|
|
name: '',
|
|
|
|
+ privilegeIds: [],
|
|
});
|
|
});
|
|
const curRoleBindIds = ref([]);
|
|
const curRoleBindIds = ref([]);
|
|
const rules = {
|
|
const rules = {
|
|
@@ -105,125 +65,66 @@ const rules = {
|
|
},
|
|
},
|
|
],
|
|
],
|
|
};
|
|
};
|
|
-let loading = ref(false);
|
|
|
|
-let treeFlatArr = ref([]);
|
|
|
|
|
|
+let menus = ref([]);
|
|
|
|
|
|
-const allCheckHandler = (bool) => {
|
|
|
|
- setAllCheckStatus(treeFlatArr.value, bool);
|
|
|
|
-};
|
|
|
|
-const setAllCheckStatus = (data, bool) => {
|
|
|
|
- for (let i = 0; i < data.length; i++) {
|
|
|
|
- data[i].hasRole = bool;
|
|
|
|
- setAllCheckStatus(data[i].children || [], bool);
|
|
|
|
- setAllCheckStatus(data[i].conditions || [], bool);
|
|
|
|
- setAllCheckStatus(data[i].buttons || [], bool);
|
|
|
|
- setAllCheckStatus(data[i].lists || [], bool);
|
|
|
|
- setAllCheckStatus(data[i].links || [], bool);
|
|
|
|
- }
|
|
|
|
-};
|
|
|
|
-const setAllCheckStatusInArr = (arr, bool) => {
|
|
|
|
- for (let i = 0; i < arr.length; i++) {
|
|
|
|
- arr[i].hasRole = bool;
|
|
|
|
- }
|
|
|
|
-};
|
|
|
|
-const setPageRangeSubCheckStatus = (row, bool) => {
|
|
|
|
- setAllCheckStatusInArr(row.children || [], bool);
|
|
|
|
- setAllCheckStatusInArr(row.conditions || [], bool);
|
|
|
|
- setAllCheckStatusInArr(row.buttons || [], bool);
|
|
|
|
- setAllCheckStatusInArr(row.lists || [], bool);
|
|
|
|
- setAllCheckStatusInArr(row.links || [], bool);
|
|
|
|
-};
|
|
|
|
-const pageRoleChange = (row) => {
|
|
|
|
- console.log('rrr', row);
|
|
|
|
- setPageRangeSubCheckStatus(row, row.hasRole);
|
|
|
|
-};
|
|
|
|
|
|
+onMounted(() => {
|
|
|
|
+ getMenus();
|
|
|
|
+});
|
|
|
|
+
|
|
|
|
+async function getMenus() {
|
|
|
|
+ const data = await getAllMenuResource();
|
|
|
|
+ menus.value = (data || []).map((item) => {
|
|
|
|
+ item.parentId = null;
|
|
|
|
+ return item;
|
|
|
|
+ });
|
|
|
|
+}
|
|
const getDetail = async () => {
|
|
const getDetail = async () => {
|
|
|
|
+ let privilegeIds = [],
|
|
|
|
+ dataPermissionInfo = [],
|
|
|
|
+ disabledIds = [];
|
|
|
|
+
|
|
let id = props.curRow?.id;
|
|
let id = props.curRow?.id;
|
|
- loading.value = true;
|
|
|
|
if (id) {
|
|
if (id) {
|
|
let roleDetail = await getRoleDetail({ roleId: id });
|
|
let roleDetail = await getRoleDetail({ roleId: id });
|
|
- formData.name = roleDetail.name;
|
|
|
|
- curRoleBindIds.value = JSON.parse(roleDetail.privilegeIds || '[]').map(
|
|
|
|
- (item) => String(item)
|
|
|
|
|
|
+ privilegeIds = JSON.parse(roleDetail.privilegeIds || '[]').map((item) =>
|
|
|
|
+ String(item)
|
|
);
|
|
);
|
|
|
|
+ dataPermissionInfo = roleDetail.dataPermissionInfo || [];
|
|
|
|
+ formData.name = roleDetail.name;
|
|
|
|
+ formData.privilegeIds = privilegeIds;
|
|
}
|
|
}
|
|
- let treeData = await getAllMenuResource();
|
|
|
|
- treeFlatArr.value = treeToArr(treeData || []);
|
|
|
|
- loading.value = false;
|
|
|
|
-};
|
|
|
|
|
|
|
|
-const columns = [
|
|
|
|
- { colKey: 'level1', title: '一级页面' },
|
|
|
|
- { colKey: 'level2', title: '二级页面' },
|
|
|
|
- { colKey: 'level3', title: '三级页面' },
|
|
|
|
- { colKey: 'page', title: '页面', width: 80, align: 'center' },
|
|
|
|
- { colKey: 'conditions', title: '查询条件', width: 160 },
|
|
|
|
- { colKey: 'buttons', title: '功能按钮', width: 160 },
|
|
|
|
- { colKey: 'lists', title: '列表展示', width: 150 },
|
|
|
|
- { colKey: 'links', title: '操作列', width: 150 },
|
|
|
|
-];
|
|
|
|
-const initCheckBoxValue = (arr) => {
|
|
|
|
- return arr.map((item) => {
|
|
|
|
- item.hasRole = curRoleBindIds.value.includes(item.id) ? true : false;
|
|
|
|
- return item;
|
|
|
|
|
|
+ nextTick(() => {
|
|
|
|
+ formRef.value.clearValidate();
|
|
|
|
+ privilegeSetRef.value.buildTableData(
|
|
|
|
+ privilegeIds,
|
|
|
|
+ dataPermissionInfo,
|
|
|
|
+ disabledIds
|
|
|
|
+ );
|
|
});
|
|
});
|
|
};
|
|
};
|
|
-const treeToArr = (tree, arr = [], level = 1) => {
|
|
|
|
- for (let i = 0; i < tree.length; i++) {
|
|
|
|
- let l = level;
|
|
|
|
- arr.push({
|
|
|
|
- ...tree[i],
|
|
|
|
- level: l,
|
|
|
|
- level1: l == 1 ? tree[i].name : '',
|
|
|
|
- level2: l == 2 ? tree[i].name : '',
|
|
|
|
- level3: l == 3 ? tree[i].name : '',
|
|
|
|
- hasRole: curRoleBindIds.value.includes(tree[i].id) ? true : false,
|
|
|
|
- conditions: tree[i].conditions
|
|
|
|
- ? initCheckBoxValue(tree[i].conditions)
|
|
|
|
- : [],
|
|
|
|
- buttons: tree[i].buttons ? initCheckBoxValue(tree[i].buttons) : [],
|
|
|
|
- links: tree[i].links ? initCheckBoxValue(tree[i].links) : [],
|
|
|
|
- lists: tree[i].lists ? initCheckBoxValue(tree[i].lists) : [],
|
|
|
|
- });
|
|
|
|
- l++;
|
|
|
|
- if (tree[i].children && tree[i].children.length) {
|
|
|
|
- treeToArr(tree[i].children, arr, l);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return arr;
|
|
|
|
-};
|
|
|
|
-const getHasRoleIds = (data, arr = []) => {
|
|
|
|
- for (let i = 0; i < data.length; i++) {
|
|
|
|
- if (data[i].hasRole) {
|
|
|
|
- arr.push(data[i].id);
|
|
|
|
- }
|
|
|
|
- getHasRoleIds(data[i].children || [], arr);
|
|
|
|
- getHasRoleIds(data[i].conditions || [], arr);
|
|
|
|
- getHasRoleIds(data[i].buttons || [], arr);
|
|
|
|
- getHasRoleIds(data[i].lists || [], arr);
|
|
|
|
- getHasRoleIds(data[i].links || [], arr);
|
|
|
|
|
|
+
|
|
|
|
+const submitHandler = async () => {
|
|
|
|
+ const valid = await formRef.value.validate();
|
|
|
|
+ if (valid !== true) return;
|
|
|
|
+
|
|
|
|
+ const { privilegeIds } = privilegeSetRef.value.getSelectedPrivileges();
|
|
|
|
+ if (!privilegeIds.length) {
|
|
|
|
+ MessagePlugin.error('请设置功能权限!');
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
- return Array.from(new Set(arr));
|
|
|
|
-};
|
|
|
|
-const addHandler = () => {
|
|
|
|
- let checkIds = getHasRoleIds(treeFlatArr.value);
|
|
|
|
- // console.log('checkIds', checkIds, checkIds.length);
|
|
|
|
- addRole({
|
|
|
|
|
|
+
|
|
|
|
+ const res = await addRole({
|
|
name: formData.name,
|
|
name: formData.name,
|
|
- privilegeIds: checkIds,
|
|
|
|
|
|
+ privilegeIds,
|
|
id: props.curRow?.id || undefined,
|
|
id: props.curRow?.id || undefined,
|
|
- }).then(() => {
|
|
|
|
- MessagePlugin.success('操作成功');
|
|
|
|
- emit('update:visible', false);
|
|
|
|
- emit('success');
|
|
|
|
- });
|
|
|
|
-};
|
|
|
|
-const submitHandler = () => {
|
|
|
|
- formRef.value.validate().then(async (result) => {
|
|
|
|
- if (result === true) {
|
|
|
|
- addHandler();
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
|
|
+ }).catch(() => {});
|
|
|
|
+
|
|
|
|
+ if (!res) return;
|
|
|
|
+
|
|
|
|
+ MessagePlugin.success('操作成功');
|
|
|
|
+ emit('update:visible', false);
|
|
|
|
+ emit('success');
|
|
};
|
|
};
|
|
|
|
|
|
watch(
|
|
watch(
|