From 9057e04efad1b7d61c77a72e5c37a504d0aee935 Mon Sep 17 00:00:00 2001 From: doum <doum> Date: 星期五, 26 九月 2025 09:24:03 +0800 Subject: [PATCH] H5静态化 --- admin/src/components/system/role/MenuConfigWindow.vue | 124 +++++++++++++++++++++++++++++++++++++++++ 1 files changed, 124 insertions(+), 0 deletions(-) diff --git a/admin/src/components/system/role/MenuConfigWindow.vue b/admin/src/components/system/role/MenuConfigWindow.vue new file mode 100644 index 0000000..29811f7 --- /dev/null +++ b/admin/src/components/system/role/MenuConfigWindow.vue @@ -0,0 +1,124 @@ +<template> + <GlobalWindow + class="menu-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="menus" + 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 { createRoleMenu } from '@/api/system/role' +import { fetchTree as fetchMenuList } from '@/api/system/menu' +export default { + name: 'MenuConfigWindow', + components: { GlobalWindow }, + data () { + return { + visible: false, + isWorking: false, + // 瑙掕壊 + role: null, + // 鎵�鏈夎彍鍗� + menus: [], + // 宸查�変腑鐨勮彍鍗� + selectedIds: [] + } + }, + methods: { + /** + * 鎵撳紑绐楀彛 + * + * @param role 鐩爣瑙掕壊 + */ + open (role) { + fetchMenuList({}) + .then(records => { + this.role = role + this.menus = records + // 濡傛灉涓哄浐瀹氳鑹诧紝鍒欏浐瀹氳彍鍗曚笉鍙洿鏀� + this.__handleFixedMenus(this.menus, this.role) + // 鎵惧嚭鍙惰妭鐐� + role.menus = role.menus.filter(menu => role.menus.findIndex(m => m.parentId === menu.id) === -1) + // 鍒濆鍖栭�変腑 + this.selectedIds = role.menus.map(r => r.id) + this.visible = true + }) + .catch(e => { + this.$tip.apiFailed(e) + }) + }, + /** + * 纭閫夋嫨鑿滃崟 + */ + confirm () { + const selectedMenus = this.$refs.tree.getCheckedNodes(false, true) + this.isWorking = true + createRoleMenu({ + roleId: this.role.id, + menuIds: selectedMenus.map(menu => menu.id) + }) + .then(() => { + this.$tip.apiSuccess('鑿滃崟鎺堟潈鎴愬姛') + this.visible = false + this.$emit('success') + }) + .catch(e => { + this.$tip.apiFailed(e) + }) + .finally(() => { + this.isWorking = false + }) + }, + /** + * 澶勭悊鍥哄畾鑿滃崟 + * + * @param menus 鑿滃崟鍒楄〃 + * @param role 瑙掕壊 + * @private + */ + __handleFixedMenus (menus, role) { + if (menus == null || menus.length === 0) { + return + } + for (const menu of menus) { + menu.disabled = false + if (role.fixed && menu.fixed) { + menu.disabled = true + } + this.__handleFixedMenus(menu.children, role) + } + } + } +} +</script> + +<style scoped lang="scss"> +@import "@/assets/style/variables.scss"; +.global-window { + .tip { + margin-bottom: 12px; + em { + font-style: normal; + color: $primary-color; + font-weight: bold; + } + } +} +</style> -- Gitblit v1.9.3