Blame view

ant-design-vue-jeecg/src/views/system/modules/UserRoleModal.vue 8.71 KB
肖超群 authored
1
2
3
4
5
6
7
8
9
10
<template>
  <a-drawer
    :title="title"
    :maskClosable="true"
    width=650
    placement="right"
    :closable="true"
    @close="close"
    :visible="visible"
    style="overflow: auto;padding-bottom: 53px;">
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
    <a-tabs v-model:activeKey="activeKey">
      <a-tab-pane key="1" tab="菜单权限">
        <a-form>
          <a-form-item label='所拥有的权限'>
            <a-tree
              checkable
              @check="onCheck"
              :checkedKeys="checkedKeys"
              :treeData="treeData"
              @expand="onExpand"
              @select="onTreeNodeSelect"
              :selectedKeys="selectedKeys"
              :expandedKeys="expandedKeysss"
              :checkStrictly="checkStrictly">
              <span slot="hasDatarule" slot-scope="{slotTitle,ruleFlag}">
pengyongcheng authored
26
                {{ slotTitle }}<a-icon v-if="ruleFlag" type="align-left" style="margin-left:5px;color: red;"></a-icon>
27
28
29
30
31
32
33
34
35
36
              </span>
            </a-tree>
          </a-form-item>
        </a-form>
      </a-tab-pane>
      <a-tab-pane key="2" tab="数据权限" force-render>
        <a-form>
          <a-form-item label='所拥有的权限'>
            <a-tree
              checkable
pengyongcheng authored
37
38
39
40
41
42
43
44
              @check="onCheck2"
              :checkedKeys="checkedKeys2"
              :treeData="treeData2"
              @expand="onExpand2"
              @select="onTreeNodeSelect2"
              :selectedKeys="selectedKeys2"
              :expandedKeys="expandedKeysss2"
              :checkStrictly="checkStrictly2">
45
46
47
48
49
50
51
52
              <span slot="hasDatarule" slot-scope="{slotTitle,ruleFlag}">
                {{ slotTitle }}<a-icon v-if="ruleFlag" type="align-left" style="margin-left:5px;color: red;"></a-icon>
              </span>
            </a-tree>
          </a-form-item>
        </a-form>
      </a-tab-pane>
    </a-tabs>
肖超群 authored
53
54
55
56
57
58
59
60
61
62
63
64

    <div class="drawer-bootom-button">
      <a-dropdown style="float: left" :trigger="['click']" placement="topCenter">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="switchCheckStrictly(1)">父子关联</a-menu-item>
          <a-menu-item key="2" @click="switchCheckStrictly(2)">取消关联</a-menu-item>
          <a-menu-item key="3" @click="checkALL">全部勾选</a-menu-item>
          <a-menu-item key="4" @click="cancelCheckALL">取消全选</a-menu-item>
          <a-menu-item key="5" @click="expandAll">展开所有</a-menu-item>
          <a-menu-item key="6" @click="closeAll">合并所有</a-menu-item>
        </a-menu>
        <a-button>
肖超群 authored
65
          树操作
66
          <a-icon type="up" />
肖超群 authored
67
68
69
70
71
        </a-button>
      </a-dropdown>
      <a-popconfirm title="确定放弃编辑?" @confirm="close" okText="确定" cancelText="取消">
        <a-button style="margin-right: .8rem">取消</a-button>
      </a-popconfirm>
肖超群 authored
72
73
      <a-button @click="handleSubmit(false)" type="primary" :loading="loading" ghost style="margin-right: 0.8rem">仅保存
      </a-button>
肖超群 authored
74
75
76
77
78
79
80
81
82
      <a-button @click="handleSubmit(true)" type="primary" :loading="loading">保存并关闭</a-button>
    </div>

    <role-datarule-modal ref="datarule"></role-datarule-modal>

  </a-drawer>

</template>
<script>
pengyongcheng authored
83
import { queryDataTreeListForRole, queryRoleDataPermission, queryRolePermission, queryTreeListForRole, saveRolePermission } from '@/api/api'
肖超群 authored
84
import RoleDataruleModal from './RoleDataruleModal.vue'
肖超群 authored
85
肖超群 authored
86
export default {
87
  name: 'RoleModal',
肖超群 authored
88
89
90
91
92
  components: {
    RoleDataruleModal
  },
  data() {
    return {
93
      roleId: '',
pengyongcheng authored
94
95
96
97
98
      title: '角色权限配置',
      visible: false,
      loading: false,
      activeKey: '1',
肖超群 authored
99
100
      treeData: [],
      defaultCheckedKeys: [],
pengyongcheng authored
101
      selectedKeys: [],
肖超群 authored
102
103
104
105
106
      checkedKeys: [],
      expandedKeysss: [],
      allTreeKeys: [],
      autoExpandParent: true,
      checkStrictly: true,
pengyongcheng authored
107
108
109
110
111
112
113
114
115

      treeData2: [],
      defaultCheckedKeys2: [],
      selectedKeys2: [],
      checkedKeys2: [],
      expandedKeysss2: [],
      allTreeKeys2: [],
      autoExpandParent2: true,
      checkStrictly2: true,
肖超群 authored
116
117
118
119
120
121
122
123
    }
  },
  methods: {
    onTreeNodeSelect(id) {
      if (id && id.length > 0) {
        this.selectedKeys = id
      }
      this.$refs.datarule.show(this.selectedKeys[0], this.roleId)
肖超群 authored
124
    },
pengyongcheng authored
125
126
127
128
129
130
    onTreeNodeSelect2(id) {
      if (id && id.length > 0) {
        this.selectedKeys2 = id
      }
      this.$refs.datarule.show(this.selectedKeys2[0], this.roleId)
    },
肖超群 authored
131
132
    onCheck(o) {
      if (this.checkStrictly) {
133
        this.checkedKeys = o.checked
肖超群 authored
134
135
      } else {
        this.checkedKeys = o
肖超群 authored
136
137
      }
    },
pengyongcheng authored
138
139
140
141
142
143
144
    onCheck2(o) {
      if (this.checkStrictly2) {
        this.checkedKeys2 = o.checked
      } else {
        this.checkedKeys2 = o
      }
    },
肖超群 authored
145
146
    show(roleId) {
      this.roleId = roleId
147
      this.visible = true
肖超群 authored
148
149
150
    },
    close() {
      this.reset()
151
152
      this.$emit('close')
      this.visible = false
肖超群 authored
153
154
    },
    onExpand(expandedKeys) {
155
      this.expandedKeysss = expandedKeys
肖超群 authored
156
157
      this.autoExpandParent = false
    },
pengyongcheng authored
158
159
160
161
    onExpand2(expandedKeys) {
      this.expandedKeysss2 = expandedKeys
      this.autoExpandParent2 = false
    },
肖超群 authored
162
163
    reset() {
      this.expandedKeysss = []
pengyongcheng authored
164
      this.expandedKeysss2 = []
肖超群 authored
165
      this.checkedKeys = []
pengyongcheng authored
166
      this.checkedKeys2 = []
肖超群 authored
167
      this.defaultCheckedKeys = []
pengyongcheng authored
168
      this.defaultCheckedKeys2 = []
肖超群 authored
169
170
171
      this.loading = false
    },
    expandAll() {
pengyongcheng authored
172
173
174
175
176
177
      let activeKey = this.activeKey
      if (activeKey === '1') {
        this.expandedKeysss = this.allTreeKeys
      } else if (activeKey === '2') {
        this.expandedKeysss2 = this.allTreeKeys2
      }
肖超群 authored
178
179
    },
    closeAll() {
pengyongcheng authored
180
181
182
183
184
185
      let activeKey = this.activeKey
      if (activeKey === '1') {
        this.expandedKeysss = []
      } else if (activeKey === '2') {
        this.expandedKeysss2 = []
      }
肖超群 authored
186
187
    },
    checkALL() {
pengyongcheng authored
188
189
190
191
192
193
      let activeKey = this.activeKey
      if (activeKey === '1') {
        this.checkedKeys = this.allTreeKeys
      } else if (activeKey === '2') {
        this.checkedKeys2 = this.allTreeKeys2
      }
肖超群 authored
194
195
    },
    cancelCheckALL() {
pengyongcheng authored
196
197
198
199
200
201
      let activeKey = this.activeKey
      if (activeKey === '1') {
        this.checkedKeys = []
      } else if (activeKey === '2') {
        this.checkedKeys2 = []
      }
肖超群 authored
202
203
    },
    switchCheckStrictly(v) {
pengyongcheng authored
204
      let activeKey = this.activeKey
205
      if (v === 1) {
pengyongcheng authored
206
207
208
209
210
        if (activeKey === '1') {
          this.checkStrictly = false
        } else if (activeKey === '2') {
          this.checkStrictly2 = false
        }
211
      } else if (v === 2) {
pengyongcheng authored
212
213
214
215
216
        if (activeKey === '1') {
          this.checkStrictly = true
        } else if (activeKey === '2') {
          this.checkStrictly2 = true
        }
肖超群 authored
217
218
      }
    },
肖超群 authored
219
220
221
222
    handleCancel() {
      this.close()
    },
    handleSubmit(exit) {
223
      let that = this
肖超群 authored
224
225
      let params = {
        roleId: that.roleId,
226
        permissionIds: that.checkedKeys.join(','),
pengyongcheng authored
227
228
229
        lastpermissionIds: that.defaultCheckedKeys.join(','),
        permissionIds2: that.checkedKeys2.join(','),
        lastpermissionIds2: that.defaultCheckedKeys2.join(',')
230
231
      }
      that.loading = true
肖超群 authored
232
233
      saveRolePermission(params).then((res) => {
        if (res.success) {
234
235
          that.$message.success(res.message)
          that.loading = false
肖超群 authored
236
237
238
239
          if (exit) {
            that.close()
          }
        } else {
240
241
          that.$message.error(res.message)
          that.loading = false
肖超群 authored
242
243
244
245
          if (exit) {
            that.close()
          }
        }
246
        this.loadData()
肖超群 authored
247
248
249
250
251
      })
    },
    loadData() {
      queryTreeListForRole().then((res) => {
        this.treeData = res.result.treeList
pengyongcheng authored
252
        this.treeData2 = res.result.treeList2
肖超群 authored
253
        this.allTreeKeys = res.result.ids
pengyongcheng authored
254
        this.allTreeKeys2 = res.result.ids2
255
        queryRolePermission({ roleId: this.roleId }).then((res) => {
pengyongcheng authored
256
257
258
259
          this.checkedKeys = [...res.result.permissionIds]
          this.defaultCheckedKeys = [...res.result.permissionIds]
          this.checkedKeys2 = [...res.result.dataPermissionIds]
          this.defaultCheckedKeys2 = [...res.result.dataPermissionIds]
260
          //this.expandedKeysss = this.allTreeKeys 注释为了加载数据后,控件不展开
肖超群 authored
261
262
        })
      })
pengyongcheng authored
263
264
265
266
267
268
269
270
271
272

      /*queryDataTreeListForRole().then((res) => {
        this.treeData2 = res.result.treeList
        this.allTreeKeys2 = res.result.ids
        queryRoleDataPermission({ roleId: this.roleId }).then((res) => {
          this.checkedKeys2 = [...res.result]
          this.defaultCheckedKeys2 = [...res.result]
          //this.expandedKeysss = this.allTreeKeys2 注释为了加载数据后,控件不展开
        })
      })*/
肖超群 authored
273
274
    }
  },
肖超群 authored
275
  watch: {
肖超群 authored
276
    visible() {
肖超群 authored
277
      if (this.visible) {
278
        this.loadData()
肖超群 authored
279
280
281
      }
    }
  }
肖超群 authored
282
}
肖超群 authored
283
284
285

</script>
<style lang="less" scoped>
肖超群 authored
286
287
288
289
290
291
292
293
294
295
296
.drawer-bootom-button {
  position: absolute;
  bottom: 0;
  width: 100%;
  border-top: 1px solid #e8e8e8;
  padding: 10px 16px;
  text-align: right;
  left: 0;
  background: #fff;
  border-radius: 0 0 2px 2px;
}
肖超群 authored
297
298

</style>