Blame view

ant-design-vue-jeecg/src/views/system/modules/UserRoleModal.vue 8.56 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
    <a-tabs v-model="activeKey">
12
13
14
15
16
17
18
19
20
21
22
      <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"
23
              :expandedKeys="expandedKeys"
24
25
              :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
37
38
39
40
41
42
43
              @check="dataOnCheck"
              :checkedKeys="dataCheckedKeys"
              :treeData="dataTreeData"
              @expand="dataOnExpand"
              :selectedKeys="dataSelectedKeys"
              :expandedKeys="dataExpandedKeys"
              :checkStrictly="dataCheckStrictly">
44
45
46
47
48
49
50
51
              <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
52
53
54
55
56
57
58
59
60
61
62
63

    <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
64
          树操作
65
          <a-icon type="up" />
肖超群 authored
66
67
68
69
70
        </a-button>
      </a-dropdown>
      <a-popconfirm title="确定放弃编辑?" @confirm="close" okText="确定" cancelText="取消">
        <a-button style="margin-right: .8rem">取消</a-button>
      </a-popconfirm>
肖超群 authored
71
72
      <a-button @click="handleSubmit(false)" type="primary" :loading="loading" ghost style="margin-right: 0.8rem">仅保存
      </a-button>
肖超群 authored
73
74
75
76
77
78
79
80
81
      <a-button @click="handleSubmit(true)" type="primary" :loading="loading">保存并关闭</a-button>
    </div>

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

  </a-drawer>

</template>
<script>
82
import { queryRolePermission, queryTreeListForRole, saveRolePermission } from '@/api/api'
肖超群 authored
83
import RoleDataruleModal from './RoleDataruleModal.vue'
肖超群 authored
84
肖超群 authored
85
export default {
86
  name: 'RoleModal',
肖超群 authored
87
88
89
90
91
  components: {
    RoleDataruleModal
  },
  data() {
    return {
92
      roleId: '',
pengyongcheng authored
93
94
95
96
97
      title: '角色权限配置',
      visible: false,
      loading: false,
      activeKey: '1',
肖超群 authored
98
99
      treeData: [],
      defaultCheckedKeys: [],
pengyongcheng authored
100
      selectedKeys: [],
肖超群 authored
101
      checkedKeys: [],
102
      expandedKeys: [],
肖超群 authored
103
104
105
      allTreeKeys: [],
      autoExpandParent: true,
      checkStrictly: true,
pengyongcheng authored
106
107
108
109
110
111
112
113
114
      dataTreeData: [],
      dataDefaultCheckedKeys: [],
      dataSelectedKeys: [],
      dataCheckedKeys: [],
      dataExpandedKeys: [],
      dataAllTreeKeys: [],
      dataAutoExpandParent: true,
      dataCheckStrictly: true,
肖超群 authored
115
116
117
118
119
120
121
122
    }
  },
  methods: {
    onTreeNodeSelect(id) {
      if (id && id.length > 0) {
        this.selectedKeys = id
      }
      this.$refs.datarule.show(this.selectedKeys[0], this.roleId)
肖超群 authored
123
    },
肖超群 authored
124
125
    onCheck(o) {
      if (this.checkStrictly) {
126
        this.checkedKeys = o.checked
肖超群 authored
127
128
      } else {
        this.checkedKeys = o
肖超群 authored
129
130
      }
    },
131
132
133
    dataOnCheck(o) {
      if (this.dataCheckStrictly) {
        this.dataCheckedKeys = o.checked
pengyongcheng authored
134
      } else {
135
        this.dataCheckedKeys = o
pengyongcheng authored
136
137
      }
    },
肖超群 authored
138
139
    show(roleId) {
      this.roleId = roleId
140
      this.visible = true
肖超群 authored
141
142
143
    },
    close() {
      this.reset()
144
145
      this.$emit('close')
      this.visible = false
肖超群 authored
146
147
    },
    onExpand(expandedKeys) {
148
      this.expandedKeys = expandedKeys
肖超群 authored
149
150
      this.autoExpandParent = false
    },
151
152
153
    dataOnExpand(expandedKeys) {
      this.dataExpandedKeys = expandedKeys
      this.dataAutoExpandParent = false
pengyongcheng authored
154
    },
肖超群 authored
155
    reset() {
156
157
      this.expandedKeys = []
      this.dataExpandedKeys = []
肖超群 authored
158
      this.checkedKeys = []
159
      this.dataCheckedKeys = []
肖超群 authored
160
      this.defaultCheckedKeys = []
161
      this.dataDefaultCheckedKeys = []
肖超群 authored
162
163
164
      this.loading = false
    },
    expandAll() {
pengyongcheng authored
165
166
      let activeKey = this.activeKey
      if (activeKey === '1') {
167
        this.expandedKeys = this.allTreeKeys
pengyongcheng authored
168
      } else if (activeKey === '2') {
169
        this.dataExpandedKeys = this.dataAllTreeKeys
pengyongcheng authored
170
      }
肖超群 authored
171
172
    },
    closeAll() {
pengyongcheng authored
173
174
      let activeKey = this.activeKey
      if (activeKey === '1') {
175
        this.expandedKeys = []
pengyongcheng authored
176
      } else if (activeKey === '2') {
177
        this.dataExpandedKeys = []
pengyongcheng authored
178
      }
肖超群 authored
179
180
    },
    checkALL() {
pengyongcheng authored
181
182
183
184
      let activeKey = this.activeKey
      if (activeKey === '1') {
        this.checkedKeys = this.allTreeKeys
      } else if (activeKey === '2') {
185
        this.dataCheckedKeys = this.dataAllTreeKeys
pengyongcheng authored
186
      }
肖超群 authored
187
188
    },
    cancelCheckALL() {
pengyongcheng authored
189
190
191
192
      let activeKey = this.activeKey
      if (activeKey === '1') {
        this.checkedKeys = []
      } else if (activeKey === '2') {
193
        this.dataCheckedKeys = []
pengyongcheng authored
194
      }
肖超群 authored
195
196
    },
    switchCheckStrictly(v) {
pengyongcheng authored
197
      let activeKey = this.activeKey
198
      if (v === 1) {
pengyongcheng authored
199
200
201
        if (activeKey === '1') {
          this.checkStrictly = false
        } else if (activeKey === '2') {
202
          this.dataCheckStrictly = false
pengyongcheng authored
203
        }
204
      } else if (v === 2) {
pengyongcheng authored
205
206
207
        if (activeKey === '1') {
          this.checkStrictly = true
        } else if (activeKey === '2') {
208
          this.dataCheckStrictly = true
pengyongcheng authored
209
        }
肖超群 authored
210
211
      }
    },
肖超群 authored
212
213
214
215
    handleCancel() {
      this.close()
    },
    handleSubmit(exit) {
216
      let that = this
肖超群 authored
217
218
      let params = {
        roleId: that.roleId,
219
        permissionIds: that.checkedKeys.join(','),
220
221
222
        lastPermissionIds: that.defaultCheckedKeys.join(','),
        dataPermissionIds: that.dataCheckedKeys.join(','),
        dataLastPermissionIds: that.dataDefaultCheckedKeys.join(',')
223
224
      }
      that.loading = true
肖超群 authored
225
226
      saveRolePermission(params).then((res) => {
        if (res.success) {
227
228
          that.$message.success(res.message)
          that.loading = false
肖超群 authored
229
230
231
232
          if (exit) {
            that.close()
          }
        } else {
233
234
          that.$message.error(res.message)
          that.loading = false
肖超群 authored
235
236
237
238
          if (exit) {
            that.close()
          }
        }
239
        this.loadData()
肖超群 authored
240
241
242
243
244
      })
    },
    loadData() {
      queryTreeListForRole().then((res) => {
        this.treeData = res.result.treeList
245
        this.dataTreeData = res.result.dataTreeList
肖超群 authored
246
        this.allTreeKeys = res.result.ids
247
        this.dataAllTreeKeys = res.result.dataIds
248
        queryRolePermission({ roleId: this.roleId }).then((res) => {
pengyongcheng authored
249
250
          this.checkedKeys = [...res.result.permissionIds]
          this.defaultCheckedKeys = [...res.result.permissionIds]
251
252
253
          this.dataCheckedKeys = [...res.result.dataPermissionIds]
          this.dataDefaultCheckedKeys = [...res.result.dataPermissionIds]
          //this.expandedKeys = this.allTreeKeys 注释为了加载数据后,控件不展开
肖超群 authored
254
255
        })
      })
pengyongcheng authored
256
257

      /*queryDataTreeListForRole().then((res) => {
258
259
        this.dataTreeData = res.result.treeList
        this.dataAllTreeKeys = res.result.ids
pengyongcheng authored
260
        queryRoleDataPermission({ roleId: this.roleId }).then((res) => {
261
262
263
          this.dataCheckedKeys = [...res.result]
          this.dataDefaultCheckedKeys = [...res.result]
          //this.expandedKeys = this.dataAllTreeKeys 注释为了加载数据后,控件不展开
pengyongcheng authored
264
265
        })
      })*/
肖超群 authored
266
267
    }
  },
肖超群 authored
268
  watch: {
肖超群 authored
269
    visible() {
肖超群 authored
270
      if (this.visible) {
271
        this.loadData()
肖超群 authored
272
273
274
      }
    }
  }
肖超群 authored
275
}
肖超群 authored
276
277
278

</script>
<style lang="less" scoped>
肖超群 authored
279
280
281
282
283
284
285
286
287
288
289
.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
290
291

</style>