Blame view

ant-design-vue-jeecg/src/views/system/modules/UserRoleModal.vue 6.31 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
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
    <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}">
                {{ 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-tab-pane key="2" tab="数据权限" force-render>
        <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}">
                {{ 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>
83
import { 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: '',
肖超群 authored
94
95
96
97
98
99
100
      treeData: [],
      defaultCheckedKeys: [],
      checkedKeys: [],
      expandedKeysss: [],
      allTreeKeys: [],
      autoExpandParent: true,
      checkStrictly: true,
101
      title: '角色权限配置',
肖超群 authored
102
103
      visible: false,
      loading: false,
104
105
      selectedKeys: [],
      activeKey: "1"
肖超群 authored
106
107
108
109
110
111
112
113
    }
  },
  methods: {
    onTreeNodeSelect(id) {
      if (id && id.length > 0) {
        this.selectedKeys = id
      }
      this.$refs.datarule.show(this.selectedKeys[0], this.roleId)
肖超群 authored
114
    },
肖超群 authored
115
116
    onCheck(o) {
      if (this.checkStrictly) {
117
        this.checkedKeys = o.checked
肖超群 authored
118
119
      } else {
        this.checkedKeys = o
肖超群 authored
120
121
      }
    },
肖超群 authored
122
123
    show(roleId) {
      this.roleId = roleId
124
      this.visible = true
肖超群 authored
125
126
127
    },
    close() {
      this.reset()
128
129
      this.$emit('close')
      this.visible = false
肖超群 authored
130
131
    },
    onExpand(expandedKeys) {
132
      this.expandedKeysss = expandedKeys
肖超群 authored
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
      this.autoExpandParent = false
    },
    reset() {
      this.expandedKeysss = []
      this.checkedKeys = []
      this.defaultCheckedKeys = []
      this.loading = false
    },
    expandAll() {
      this.expandedKeysss = this.allTreeKeys
    },
    closeAll() {
      this.expandedKeysss = []
    },
    checkALL() {
      this.checkedKeys = this.allTreeKeys
    },
    cancelCheckALL() {
      //this.checkedKeys = this.defaultCheckedKeys
      this.checkedKeys = []
    },
    switchCheckStrictly(v) {
155
      if (v === 1) {
肖超群 authored
156
        this.checkStrictly = false
157
      } else if (v === 2) {
肖超群 authored
158
        this.checkStrictly = true
肖超群 authored
159
160
      }
    },
肖超群 authored
161
162
163
164
    handleCancel() {
      this.close()
    },
    handleSubmit(exit) {
165
      let that = this
肖超群 authored
166
167
      let params = {
        roleId: that.roleId,
168
169
170
171
        permissionIds: that.checkedKeys.join(','),
        lastpermissionIds: that.defaultCheckedKeys.join(',')
      }
      that.loading = true
肖超群 authored
172
173
      saveRolePermission(params).then((res) => {
        if (res.success) {
174
175
          that.$message.success(res.message)
          that.loading = false
肖超群 authored
176
177
178
179
          if (exit) {
            that.close()
          }
        } else {
180
181
          that.$message.error(res.message)
          that.loading = false
肖超群 authored
182
183
184
185
          if (exit) {
            that.close()
          }
        }
186
        this.loadData()
肖超群 authored
187
188
189
190
191
192
      })
    },
    loadData() {
      queryTreeListForRole().then((res) => {
        this.treeData = res.result.treeList
        this.allTreeKeys = res.result.ids
193
194
195
196
        queryRolePermission({ roleId: this.roleId }).then((res) => {
          this.checkedKeys = [...res.result]
          this.defaultCheckedKeys = [...res.result]
          //this.expandedKeysss = this.allTreeKeys 注释为了加载数据后,控件不展开
肖超群 authored
197
198
199
200
        })
      })
    }
  },
肖超群 authored
201
  watch: {
肖超群 authored
202
    visible() {
肖超群 authored
203
      if (this.visible) {
204
        this.loadData()
肖超群 authored
205
206
207
      }
    }
  }
肖超群 authored
208
}
肖超群 authored
209
210
211

</script>
<style lang="less" scoped>
肖超群 authored
212
213
214
215
216
217
218
219
220
221
222
.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
223
224

</style>