From 6f2abed09bb02b22f73477642c21a333fe741207 Mon Sep 17 00:00:00 2001
From: jiangping <jp@doumee.com>
Date: 星期四, 19 六月 2025 16:55:35 +0800
Subject: [PATCH] ss
---
admin/src/components/system/role/PermissionConfigWindow.vue | 129 +++++++++++++++++++++++++++++++++++++++++++
1 files changed, 129 insertions(+), 0 deletions(-)
diff --git a/admin/src/components/system/role/PermissionConfigWindow.vue b/admin/src/components/system/role/PermissionConfigWindow.vue
new file mode 100644
index 0000000..468b73d
--- /dev/null
+++ b/admin/src/components/system/role/PermissionConfigWindow.vue
@@ -0,0 +1,129 @@
+<template>
+ <GlobalWindow
+ class="permission-config-dialog"
+ :visible.sync="visible"
+ :confirm-working="isWorking"
+ width="576px"
+ title="鎺堟潈鏉冮檺"
+ @confirm="confirm"
+ >
+ <p class="tip" v-if="role != null">涓鸿鑹� <em>{{role.name}}</em> 閰嶇疆鏉冮檺</p>
+ <el-tree
+ ref="tree"
+ :data="permissions"
+ show-checkbox
+ node-key="id"
+ default-expand-all
+ :default-checked-keys="selectedIds"
+ :expand-on-click-node="false"
+ :check-on-click-node="true"
+ :props="{children: 'children',label: 'name'}">
+ </el-tree>
+ </GlobalWindow>
+</template>
+
+<script>
+import GlobalWindow from '@/components/common/GlobalWindow'
+import { createRolePermission } from '@/api/system/role'
+import { fetchTree } from '@/api/system/permission'
+export default {
+ name: 'PermissionConfigWindow',
+ components: { GlobalWindow },
+ data () {
+ return {
+ visible: false,
+ isWorking: false,
+ // 瑙掕壊瀵硅薄
+ role: null,
+ // 鏉冮檺鍒楄〃
+ permissions: [],
+ // 宸查�変腑鐨勬潈闄怚D
+ selectedIds: []
+ }
+ },
+ methods: {
+ /**
+ * 鎵撳紑绐楀彛
+ *
+ * @param role 鐩爣瑙掕壊
+ */
+ open (role) {
+ fetchTree()
+ .then(records => {
+ this.role = role
+ this.permissions = records
+ // 濡傛灉涓哄浐瀹氳鑹诧紝鍒欏浐瀹氭潈闄愪笉鍙洿鏀�
+ if (this.role.fixed) {
+ this.__handleFixedPermissions(this.permissions)
+ }
+ this.selectedIds = role.permissions.map(r => r.id)
+ this.visible = true
+ })
+ .catch(e => {
+ this.$tip.apiFailed(e)
+ })
+ },
+ /**
+ * 纭閫夋嫨鏉冮檺
+ */
+ confirm () {
+ const selectedPermissions = this.$refs.tree.getCheckedNodes(false, true).filter(item => item.type !== 'module').map(item => item.id)
+ this.isWorking = true
+ createRolePermission({
+ roleId: this.role.id,
+ permissionIds: selectedPermissions
+ })
+ .then(() => {
+ this.visible = false
+ this.$emit('success')
+ setTimeout(() => {
+ this.$dialog.attentionConfirm('鏉冮檺閰嶇疆鎴愬姛锛岀敤鎴烽渶閲嶆柊鐧诲綍鍚庣敓鏁�').then(() => {})
+ }, 300)
+ })
+ .catch(e => {
+ this.$tip.apiFailed(e)
+ })
+ .finally(() => {
+ this.isWorking = false
+ })
+ },
+ /**
+ * 澶勭悊鍥哄畾鏉冮檺
+ *
+ * @param permissions 鏉冮檺鍒楄〃
+ * @param module 鎵�灞炴ā鍧�
+ * @private
+ */
+ __handleFixedPermissions (permissions, module) {
+ if (permissions == null) {
+ return
+ }
+ for (const permission of permissions) {
+ if (permission.type !== 'module') {
+ if (permission.fixed) {
+ permission.disabled = true
+ if (module != null) {
+ module.disabled = true
+ }
+ }
+ continue
+ }
+ this.__handleFixedPermissions(permission.children, permission)
+ }
+ }
+ }
+}
+</script>
+
+<style scoped lang="scss">
+@import "@/assets/style/variables.scss";
+.global-window {
+ .tip {
+ em {
+ font-style: normal;
+ color: $primary-color;
+ font-weight: bold;
+ }
+ }
+}
+</style>
--
Gitblit v1.9.3