1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<template>
  <a-modal :visible="visible" :title="title" width="50%" :maskClosable="false" @cancel="handleModalClose"
           :footer="null">
    <a-form-model layout="inline">
      <a-form-item label="名称">
        <a-input readOnly :value="currentTreeNodeInfo.title"></a-input>
      </a-form-item>
      <a-form-item label="是否同时配置子节点" v-if="currentTreeNodeInfo.type!==2">
        <a-switch v-model="isAssignSonNode"></a-switch>
      </a-form-item>
    </a-form-model>
 
    <a-tabs v-model="activeTabKey">
      <a-tab-pane :key="1" tab="分配用户">
        <UserPermissionTransfer ref="userPermissionTransferRef" :currentTreeNodeInfo="currentTreeNodeInfo"
                                :dataSource="allUsersList" :isAssignSonNode="isAssignSonNode"
                                @setAdminDisabled="setAdminDisabled"/>
      </a-tab-pane>
    </a-tabs>
  </a-modal>
</template>
 
<script>
  import dncApi from '@/api/dnc'
  import UserPermissionTransfer from './UserPermissionTransfer'
 
  export default {
    name: 'AssignPermissionModal',
    components: { UserPermissionTransfer },
    props: {
      currentTreeNodeInfo: {
        type: Object
      }
    },
    data() {
      return {
        visible: false,
        title: '',
        isAssignSonNode: true,
        activeTabKey: 1,
        allDepartmentsList: [],
        allUsersList: [],
        allTreeKeys: [],
        hasLoadedDataTabKeyArray: []
      }
    },
    watch: {
      visible: {
        handler(value) {
          if (value) {
            if (this.currentTreeNodeInfo.type === 1) this.isAssignSonNode = true
            else this.isAssignSonNode = false
            this.getAllUsersListByApi()
          }
        }
      }
    },
    created() {
      this.$bus.$on('treeMenuItemMethodTrigger', this.triggerCorrespondingMethod)
    },
    methods: {
      // 点击树节点右键菜单权限配置按钮后触发
      handleAssignPermission() {
        this.visible = true
      },
 
      // 调用接口获取所有用户列表
      getAllUsersListByApi() {
        dncApi.getAllUsersListApi()
          .then(res => {
            if (res.success) {
              this.allUsersList = res.result
              this.$nextTick(() => this.$refs.userPermissionTransferRef.getHasPermissionUserByApi())
            }
          })
      },
 
      setAdminDisabled() {
        this.allUsersList = this.allUsersList.map(item => {
          return {
            ...item,
            disabled: item.username === 'admin'
          }
        })
      },
 
      // 控制弹窗关闭
      handleModalClose() {
        this.visible = false
      },
 
      triggerCorrespondingMethod({ methodName, modalTitle }) {
        if (this[methodName]) {
          this[methodName]()
          this.title = modalTitle
        }
      }
    }
  }
</script>
 
<style scoped>
 
</style>