|
@@ -3,7 +3,9 @@
|
|
|
<template #header>
|
|
|
<el-input style="width: 200px" v-model="searchRoleContent" placeholder="请输入角色名称"></el-input>
|
|
|
<el-divider direction="vertical"></el-divider>
|
|
|
- <el-button type="primary" icon="Upload" @click="beforeSaveMenus">保存更改</el-button>
|
|
|
+ <el-button type="primary" icon="Upload" @click="beforeSaveMenus">
|
|
|
+ {{ tabsVal === 'first' ? "菜单" : "报表" }}
|
|
|
+ </el-button>
|
|
|
</template>
|
|
|
<template #main>
|
|
|
<el-row :gutter="5">
|
|
@@ -16,102 +18,141 @@
|
|
|
</el-table>
|
|
|
</el-col>
|
|
|
<el-col :span="5">
|
|
|
- <el-tree
|
|
|
- ref="tree"
|
|
|
- :data="menus"
|
|
|
- :props="defaultProps"
|
|
|
- :style="{ height: tableHeight + 'px', overflowY: 'scroll' }"
|
|
|
- show-checkbox
|
|
|
- node-key="id"
|
|
|
- default-expand-all
|
|
|
- ></el-tree>
|
|
|
+ <el-tabs v-model="tabsVal">
|
|
|
+ <el-tab-pane label="菜单权限" name="first">
|
|
|
+ <el-tree
|
|
|
+ ref="tree"
|
|
|
+ :data="menus"
|
|
|
+ :props="defaultProps"
|
|
|
+ :style="{ height: tableHeight - 40 - 15 + 'px', overflowY: 'scroll' }"
|
|
|
+ show-checkbox
|
|
|
+ node-key="id"
|
|
|
+ default-expand-all
|
|
|
+ ></el-tree>
|
|
|
+ </el-tab-pane>
|
|
|
+ <el-tab-pane label="报表权限" name="second">
|
|
|
+ <el-tree :data="reportForms"
|
|
|
+ show-checkbox
|
|
|
+ node-key="id"
|
|
|
+ ref="reportFormsTree"
|
|
|
+ :style="{ height: tableHeight - 40 - 15 + 'px', overflowY: 'scroll' }">
|
|
|
+ <template #default="{node,data}">
|
|
|
+ <div :id="'report_forms-' + data.id">
|
|
|
+ <el-icon>
|
|
|
+ <Document v-if="data.type === 0"/>
|
|
|
+ <Folder v-else/>
|
|
|
+ </el-icon>
|
|
|
+ {{ data.name }}
|
|
|
+ </div>
|
|
|
+ </template>
|
|
|
+ </el-tree>
|
|
|
+ </el-tab-pane>
|
|
|
+ </el-tabs>
|
|
|
</el-col>
|
|
|
</el-row>
|
|
|
</template>
|
|
|
</page-layer>
|
|
|
</template>
|
|
|
|
|
|
-<script>
|
|
|
-import { computed, onMounted, ref } from 'vue'
|
|
|
+<script setup lang="ts">
|
|
|
+import {computed, onMounted, ref} from 'vue'
|
|
|
import store from '@/store'
|
|
|
-import { getAllRoles, getAllMenus, getRoleMenus, saveRoleMenus } from '@/api/settings/permission-settings'
|
|
|
-import { ElMessage } from 'element-plus'
|
|
|
+import {getAllRoles, getAllMenus, getRoleMenus, saveRoleMenus} from '@/api/settings/permission-settings'
|
|
|
+import {ElMessage, ElTree} from 'element-plus'
|
|
|
import PageLayer from "@/layout/PageLayer";
|
|
|
-export default {
|
|
|
- components: {PageLayer},
|
|
|
- setup() {
|
|
|
- const windowSize = store.state.app.windowSize
|
|
|
- const tableHeight = windowSize.h - 10
|
|
|
+import {getPermissionsByUserCode, getReportCenterTree, setPermissions} from "@/api/base-data/report-center";
|
|
|
+import {Document, Folder} from "@element-plus/icons-vue";
|
|
|
+import {useCompRef} from "@/utils/useCompRef";
|
|
|
+import XEUtils from "xe-utils";
|
|
|
|
|
|
- const searchRoleContent = ref('')
|
|
|
- const roles = ref([])
|
|
|
- const cptRoles = computed(() => {
|
|
|
- return roles.value.filter((item) => {
|
|
|
- return item.name.indexOf(searchRoleContent.value) !== -1
|
|
|
- })
|
|
|
- })
|
|
|
- const currentRole = ref({})
|
|
|
- const handleClickRole = (row) => {
|
|
|
- currentRole.value = row
|
|
|
- getRoleMenus(row.id).then((res) => {
|
|
|
- tree.value.setCheckedKeys(res)
|
|
|
- })
|
|
|
- }
|
|
|
+const windowSize = store.state.app.windowSize
|
|
|
+const tableHeight = windowSize.h - 10
|
|
|
|
|
|
- const tree = ref(null)
|
|
|
- const menus = ref([])
|
|
|
- const defaultProps = {
|
|
|
- id: 'id',
|
|
|
- children: 'children',
|
|
|
- label: 'metaTitle',
|
|
|
- }
|
|
|
- const beforeSaveMenus = () => {
|
|
|
- if (!currentRole.value.id) {
|
|
|
- ElMessage({
|
|
|
- message: '请先选择角色!',
|
|
|
- type: 'warning',
|
|
|
- duration: 2500,
|
|
|
- showClose: true,
|
|
|
- })
|
|
|
- } else {
|
|
|
- const checkedKeys = tree.value.getCheckedKeys()
|
|
|
- const halfCheckKeys = tree.value.getHalfCheckedKeys()
|
|
|
- halfCheckKeys.forEach((item) => checkedKeys.push(item))
|
|
|
- const param = {
|
|
|
- id: currentRole.value.id,
|
|
|
- menus: checkedKeys,
|
|
|
- }
|
|
|
- saveRoleMenus(param).then(() => {
|
|
|
- ElMessage({
|
|
|
- message: '保存成功',
|
|
|
- type: 'success',
|
|
|
- duration: 2500,
|
|
|
- showClose: true,
|
|
|
- })
|
|
|
- })
|
|
|
- }
|
|
|
+const searchRoleContent = ref('')
|
|
|
+const roles = ref([])
|
|
|
+const reportForms = ref([])
|
|
|
+const cptRoles = computed(() => {
|
|
|
+ return roles.value.filter((item) => {
|
|
|
+ return item.name.indexOf(searchRoleContent.value) !== -1
|
|
|
+ })
|
|
|
+})
|
|
|
+const currentRole = ref({})
|
|
|
+
|
|
|
+const handleClickRole = (row) => {
|
|
|
+ currentRole.value = row
|
|
|
+ getRoleMenus(row.id).then((res) => {
|
|
|
+ tree.value.setCheckedKeys(res)
|
|
|
+ })
|
|
|
+ getPermissionsByUserCode(row.id).then(res => {
|
|
|
+ for (let key in reportFormsTree.value.store.nodesMap) {
|
|
|
+ reportFormsTree.value.store.nodesMap[key].expanded = res.includes(key);
|
|
|
}
|
|
|
+ reportFormsTree.value.setCheckedKeys(res)
|
|
|
+ })
|
|
|
+}
|
|
|
|
|
|
- onMounted(() => {
|
|
|
- getAllRoles().then((res) => {
|
|
|
- roles.value = res
|
|
|
- })
|
|
|
- getAllMenus().then((res) => {
|
|
|
- menus.value = res
|
|
|
- })
|
|
|
+const tree = ref(null)
|
|
|
+const reportFormsTree = useCompRef(ElTree)
|
|
|
+const menus = ref([])
|
|
|
+const tabsVal = ref('second')
|
|
|
+const defaultProps = {
|
|
|
+ id: 'id',
|
|
|
+ children: 'children',
|
|
|
+ label: 'metaTitle',
|
|
|
+}
|
|
|
+const beforeSaveMenus = () => {
|
|
|
+ if (!currentRole.value.id) {
|
|
|
+ ElMessage({
|
|
|
+ message: '请先选择角色!',
|
|
|
+ type: 'warning',
|
|
|
+ duration: 2500,
|
|
|
+ showClose: true,
|
|
|
})
|
|
|
-
|
|
|
- return {
|
|
|
- tableHeight,
|
|
|
- tree,
|
|
|
- menus,
|
|
|
- searchRoleContent,
|
|
|
- defaultProps,
|
|
|
- roles,
|
|
|
- cptRoles,
|
|
|
- handleClickRole,
|
|
|
- beforeSaveMenus,
|
|
|
+ } else {
|
|
|
+ if (tabsVal.value === 'first') {
|
|
|
+ saveRoleMenusFunc()
|
|
|
+ } else {
|
|
|
+ saveReportForms()
|
|
|
}
|
|
|
- },
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+function saveReportForms() {
|
|
|
+ const halfCheckKeys = reportFormsTree.value.getHalfCheckedKeys()
|
|
|
+ const checkedKeys = reportFormsTree.value.getCheckedKeys()
|
|
|
+ let temp = [...checkedKeys, ...halfCheckKeys]
|
|
|
+ setPermissions({userCode: currentRole.value.id, ids: temp})
|
|
|
+}
|
|
|
+
|
|
|
+function saveRoleMenusFunc() {
|
|
|
+ const checkedKeys = tree.value.getCheckedKeys()
|
|
|
+ const halfCheckKeys = tree.value.getHalfCheckedKeys()
|
|
|
+ halfCheckKeys.forEach((item) => checkedKeys.push(item))
|
|
|
+
|
|
|
+ const param = {
|
|
|
+ id: currentRole.value.id,
|
|
|
+ menus: checkedKeys,
|
|
|
+ }
|
|
|
+ saveRoleMenus(param).then(() => {
|
|
|
+ ElMessage({
|
|
|
+ message: '保存成功',
|
|
|
+ type: 'success',
|
|
|
+ duration: 2500,
|
|
|
+ showClose: true,
|
|
|
+ })
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+onMounted(() => {
|
|
|
+ getAllRoles().then((res) => {
|
|
|
+ roles.value = res
|
|
|
+ })
|
|
|
+ getAllMenus().then((res) => {
|
|
|
+ menus.value = res
|
|
|
+ })
|
|
|
+ getReportCenterTree().then(res => {
|
|
|
+ reportForms.value = res
|
|
|
+ })
|
|
|
+})
|
|
|
+
|
|
|
</script>
|