¶Ô±ÈÐÂÎļþ |
| | |
| | | <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: [], |
| | | // å·²éä¸çæéID |
| | | 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> |