Blame view

ant-design-vue-jeecg/src/views/system/RoleUserList.vue 17.4 KB
肖超群 authored
1
2
3
4
5
6
7
8
9
<template>
  <a-row :gutter="10">
    <a-col :md="leftColMd" :sm="24" style="margin-bottom: 20px">
      <a-card :bordered="false">
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
          <!-- 搜索区域 -->
          <a-form layout="inline" @keyup.enter.native="searchQuery">
            <a-row :gutter="24">
谭毅彬 authored
10
11
              <a-col :xl="6" :lg="7" :md="8" :sm="24">
                <a-form-item label="角色名称">
12
                  <a-input placeholder="请输入角色名称" v-model="queryParam.roleName"></a-input>
肖超群 authored
13
14
15
16
17
18
19
20
21
22
23
                </a-form-item>
              </a-col>
              <!--
              <a-col :md="11" :sm="12">
                <a-form-item label="创建时间" :labelCol="{span: 5}" :wrapperCol="{span: 18, offset: 1}">
                  <j-date v-model="queryParam.createTime_begin" :showTime="true" date-format="YYYY-MM-DD HH:mm:ss" style="width:45%" placeholder="请选择开始时间" ></j-date>
                  <span style="width: 10px;">~</span>
                  <j-date v-model="queryParam.createTime_end" :showTime="true" date-format="YYYY-MM-DD HH:mm:ss" style="width:45%" placeholder="请选择结束时间"></j-date>
                </a-form-item>
              </a-col>
              -->
谭毅彬 authored
24
25
26
27
28
29
              <a-col :xl="6" :lg="7" :md="8" :sm="24">
                <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
                  <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
                  <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
                </span>
              </a-col>
肖超群 authored
30
31
32
33
            </a-row>
          </a-form>
        </div>
        <!-- 操作按钮区域 -->
34
        <div class="table-operator">
易文鹏 authored
35
          <a-button @click="handleAdd" v-has="'role:add'" type="primary" icon="plus">新建角色</a-button>
肖超群 authored
36
          <!--<a-button @click="handleEdit(model1)" type="primary" icon="plus">角色编辑</a-button>-->
37
          <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
易文鹏 authored
38
            <a-button v-has="'role:import'" type="primary" icon="import">导入</a-button>
肖超群 authored
39
          </a-upload>
易文鹏 authored
40
          <a-button v-has="'role:export'" type="primary" icon="download" @click="handleExportXls('角色管理')">导出</a-button>
肖超群 authored
41
42
        </div>
43
        <div>
肖超群 authored
44
45
46
47
48
49
50
51
52
53
54
55
          <a-table
            style="height:500px"
            ref="table"
            size="middle"
            bordered
            rowKey="id"
            :columns="columns"
            :dataSource="dataSource"
            :pagination="ipagination"
            :loading="loading"
            :rowSelection="{selectedRowKeys: selectedRowKeys1, onChange: onSelectChange1, type:'radio'}"
            @change="handleTableChange">
56
57
58
            <span slot="action" slot-scope="text, record">
              <a @click="handleOpen(record)">用户</a>
              <a-divider type="vertical"/>
59
60
              <a v-has="'role:authorize'" @click="handlePerssion(record.id)">授权</a>
              <a-divider type="vertical"/>
61
              <a-dropdown>
谭毅彬 authored
62
                <a class="ant-dropdown-link">更多 <a-icon type="down"/></a>
63
64
65
66
                <a-menu slot="overlay">
                  <a-menu-item>
                    <a v-has="'role:edit'" @click="handleEdit(record)">编辑</a>
                  </a-menu-item>
67
                  <a-menu-item v-has="'role:delete'">
68
69
70
71
72
73
74
                    <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete1(record.id)">
                      <a v-has="'role:delete'">删除</a>
                    </a-popconfirm>
                  </a-menu-item>
                </a-menu>
              </a-dropdown>
            </span>
肖超群 authored
75
76
77
78
79
80
81
82
83
84
          </a-table>
        </div>
        <!-- 右侧的角色权限配置 -->
        <user-role-modal ref="modalUserRole"></user-role-modal>
        <role-modal ref="modalForm" @ok="modalFormOk"></role-modal>
      </a-card>
    </a-col>
    <a-col :md="rightColMd" :sm="24" v-if="this.rightcolval == 1">
      <a-card :bordered="false">
        <div style="text-align: right;">
肖超群 authored
85
          <a-icon type="close-circle" @click="hideUserList"/>
肖超群 authored
86
87
88
89
90
91
92
93
        </div>
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
          <a-form layout="inline">
            <a-row :gutter="24">

              <a-col :md="12" :sm="12">
                <a-form-item label="用户账号">
94
                  <a-input placeholder="请输入用户账号" v-model="queryParam2.username"></a-input>
肖超群 authored
95
96
97
98
99
100
101
102
103
104
105
106
107
108
                </a-form-item>
              </a-col>
              <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
            <a-col :md="9" :sm="24">
             <a-button type="primary" @click="searchQuery2" icon="search" style="margin-left: 21px">查询</a-button>
              <a-button type="primary" @click="searchReset2" icon="reload" style="margin-left: 8px">重置</a-button>

            </a-col>
          </span>
            </a-row>
          </a-form>
        </div>
        <!-- 操作按钮区域 -->
        <div class="table-operator" :md="24" :sm="24">
109
          <a-button @click="handleAdd2" v-has="'role:addUserWithRole'" type="primary" icon="plus" style="margin-top: 16px">新增用户</a-button>
肖超群 authored
110
          <!--<a-button @click="handleEdit2" type="primary" icon="edit" style="margin-top: 16px">用户编辑</a-button>-->
111
          <a-button @click="handleAddUserRole" v-has="'role:addUserExistingRole'" type="primary" icon="plus" style="margin-top: 16px">已有用户</a-button>
肖超群 authored
112
113
          <a-dropdown v-if="selectedRowKeys2.length > 0">
            <a-menu slot="overlay">
易文鹏 authored
114
              <a-menu-item key="1" @click="batchDel2" v-has="'role:deleteBatchExistingRoleUser'">
115
                <a-icon type="delete"/>删除
肖超群 authored
116
117
              </a-menu-item>
            </a-menu>
118
            <a-button style="margin-left: 8px">批量操作
肖超群 authored
119
120
121
122
123
124
125
              <a-icon type="down"/>
            </a-button>
          </a-dropdown>
        </div>
        <!-- table区域-begin -->
        <div>
          <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
126
            <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys2.length }}</a> 项
肖超群 authored
127
128
129
130
131
132
133
134
135
136
137
138
139
140
            <a style="margin-left: 24px" @click="onClearSelected2">清空</a>
          </div>
          <a-table
            style="height:500px"
            ref="table2"
            bordered
            size="middle"
            rowKey="id"
            :columns="columns2"
            :dataSource="dataSource2"
            :pagination="ipagination2"
            :loading="loading2"
            :rowSelection="{selectedRowKeys: selectedRowKeys2, onChange: onSelectChange2}"
            @change="handleTableChange2">
141
142
143
144
145
146
147
            <span slot="action" slot-scope="text, record">
              <a @click="handleEdit2(record)">编辑</a>
              <a-divider type="vertical"/>
              <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete2(record.id)">
                <a>删除</a>
              </a-popconfirm>
            </span>
肖超群 authored
148
149
150
151
152
153
154
155
156
157
158
          </a-table>
        </div>
        <!-- 表单区域 -->
        <role-modal ref="modalForm" @ok="modalFormOk"></role-modal>
        <user-modal ref="modalForm2" @ok="modalFormOk2"></user-modal>
        <Select-User-Modal ref="selectUserModal" @selectFinished="selectOK"></Select-User-Modal>
      </a-card>
    </a-col>
  </a-row>
</template>
<script>
159
160
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { deleteAction, postAction, getAction } from '@/api/manage'
肖超群 authored
161
162
163
import SelectUserModal from './modules/SelectUserModal'
import RoleModal from './modules/RoleModal'
import UserModal from './modules/UserModal'
164
import { filterObj } from '@/utils/util'
肖超群 authored
165
166
import UserRoleModal from './modules/UserRoleModal'
import moment from 'moment'
肖超群 authored
167
肖超群 authored
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
export default {
  name: 'RoleUserList',
  mixins: [JeecgListMixin],
  components: {
    UserRoleModal,
    SelectUserModal,
    RoleModal,
    UserModal,
    moment
  },
  data() {
    return {
      model1: {},
      model2: {},
      currentRoleId: '',
      queryParam1: {},
      queryParam2: {},
      dataSource1: [],
      dataSource2: [],
      ipagination1: {
        current: 1,
        pageSize: 10,
        pageSizeOptions: ['10', '20', '30'],
        showTotal: (total, range) => {
          return range[0] + '-' + range[1] + ' 共' + total + '条'
肖超群 authored
193
        },
肖超群 authored
194
195
196
197
198
199
200
201
202
203
        showQuickJumper: true,
        showSizeChanger: true,
        total: 0
      },
      ipagination2: {
        current: 1,
        pageSize: 10,
        pageSizeOptions: ['10', '20', '30'],
        showTotal: (total, range) => {
          return range[0] + '-' + range[1] + ' 共' + total + '条'
肖超群 authored
204
        },
肖超群 authored
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
        showQuickJumper: true,
        showSizeChanger: true,
        total: 0
      },
      isorter1: {
        column: 'createTime',
        order: 'desc'
      },
      isorter2: {
        column: 'createTime',
        order: 'desc'
      },
      filters1: {},
      filters2: {},
      loading1: false,
      loading2: false,
      selectedRowKeys1: [],
      selectedRowKeys2: [],
      selectionRows1: [],
      selectionRows2: [],
      test: {},
      rightcolval: 0,
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
      columns: [
        {
          title: '角色编码',
          align: 'center',
          dataIndex: 'roleCode'
        },
        {
          title: '角色名称',
          align: 'center',
          dataIndex: 'roleName'
        },
        {
          title: '创建时间',
          dataIndex: 'createTime',
          align: 'center',
          sorter: true,
          customRender: text => {
            return moment(text).format('YYYY-MM-DD')
肖超群 authored
245
          }
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          scopedSlots: { customRender: 'action' },
          width: 155
        }
      ],
      columns2: [
        {
          title: '用户账号',
          align: 'center',
          width: 300,
          dataIndex: 'username'
        },
肖超群 authored
262
263
264
        {
          title: '用户名称',
          align: 'center',
265
          width: 300,
肖超群 authored
266
267
268
269
270
271
272
273
274
275
276
          dataIndex: 'realname'
        },
        {
          title: '状态',
          align: 'center',
          width: 80,
          dataIndex: 'status_dictText'
        },
        {
          title: '操作',
          dataIndex: 'action',
277
          scopedSlots: { customRender: 'action' },
肖超群 authored
278
          align: 'center',
谭毅彬 authored
279
          width: 147
280
281
        }
      ],
肖超群 authored
282
283
284
285
286
287
288
289
290
291
292
293
294
295

      // 高级查询参数
      superQueryParams2: '',
      // 高级查询拼接条件
      superQueryMatchType2: 'and',
      url: {
        list: '/sys/role/list',
        delete: '/sys/role/delete',
        list2: '/sys/user/userRoleList',
        addUserRole: '/sys/user/addSysUserRole',
        delete2: '/sys/user/deleteUserRole',
        deleteBatch2: '/sys/user/deleteUserRoleBatch',
        exportXlsUrl: 'sys/role/exportXls',
        importExcelUrl: 'sys/role/importExcel'
肖超群 authored
296
      }
肖超群 authored
297
298
299
    }
  },
  computed: {
300
    importExcelUrl: function() {
肖超群 authored
301
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
肖超群 authored
302
    },
肖超群 authored
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
    leftColMd() {
      return this.selectedRowKeys1.length === 0 ? 24 : 12
    },
    rightColMd() {
      return this.selectedRowKeys1.length === 0 ? 0 : 12
    }
  },
  methods: {
    onSelectChange2(selectedRowKeys, selectionRows) {
      this.selectedRowKeys2 = selectedRowKeys
      this.selectionRows2 = selectionRows
    },
    onClearSelected2() {
      this.selectedRowKeys2 = []
      this.selectionRows2 = []
    },
    onClearSelected1() {
      this.selectedRowKeys1 = []
      this.selectionRows1 = []
    },
    onSelectChange1(selectedRowKeys, selectionRows) {
      this.rightcolval = 1
      this.selectedRowKeys1 = selectedRowKeys
326
      this.selectionRows1 = selectionRows[0]
肖超群 authored
327
328
329
330
331
      this.model1 = Object.assign({}, selectionRows[0])
      console.log(this.model1)
      this.currentRoleId = selectedRowKeys[0]
      this.loadData2()
    },
332
    onClearSelected() {},
肖超群 authored
333
334
335
336
337
338
339

    getQueryParams2() {
      //获取查询条件
      let sqp = {}
      if (this.superQueryParams2) {
        sqp['superQueryParams'] = encodeURI(this.superQueryParams2)
        sqp['superQueryMatchType'] = this.superQueryMatchType2
肖超群 authored
340
      }
肖超群 authored
341
342
343
344
345
      var param = Object.assign(sqp, this.queryParam2, this.isorter2, this.filters2)
      param.field = this.getQueryField2()
      param.pageNo = this.ipagination2.current
      param.pageSize = this.ipagination2.pageSize
      return filterObj(param)
肖超群 authored
346
    },
肖超群 authored
347
348
349
    getQueryField2() {
      //TODO 字段权限控制
      var str = 'id,'
350
      this.columns2.forEach(function(value) {
肖超群 authored
351
352
353
354
        str += ',' + value.dataIndex
      })
      return str
    },
355
    handleEdit2: function(record) {
肖超群 authored
356
357
358
359
      this.$refs.modalForm2.title = '编辑'
      this.$refs.modalForm2.roleDisabled = true
      this.$refs.modalForm2.edit(record)
    },
360
    handleAdd2: function() {
肖超群 authored
361
362
363
364
365
      if (this.currentRoleId == '') {
        this.$message.error('请选择一个角色!')
      } else {
        this.$refs.modalForm2.roleDisabled = true
        this.$refs.modalForm2.title = '新增'
366
367
368
369
370
371
        this.$refs.modalForm2.edit({
          activitiSync: '1',
          userIdentity: 1,
          selectedroles: this.currentRoleId,
          selectedRoles: this.selectionRows1.id.toString()
        })
肖超群 authored
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
      }
    },
    modalFormOk2() {
      // 新增/修改 成功时,重载列表
      this.loadData2()
    },
    loadData2(arg) {
      if (!this.url.list2) {
        this.$message.error('请设置url.list2属性!')
        return
      }
      //加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.ipagination2.current = 1
      }
      if (this.currentRoleId === '') return
388
      let params = this.getQueryParams2() //查询条件
肖超群 authored
389
390
      params.roleId = this.currentRoleId
      this.loading2 = true
391
      getAction(this.url.list2, params).then(res => {
肖超群 authored
392
393
394
        if (res.success) {
          this.dataSource2 = res.result.records
          this.ipagination2.total = res.result.total
肖超群 authored
395
        }
肖超群 authored
396
397
398
        this.loading2 = false
      })
    },
399
    handleDelete1: function(id) {
肖超群 authored
400
401
402
403
      this.handleDelete(id)
      this.dataSource2 = []
      this.currentRoleId = ''
    },
404
    handleDelete2: function(id) {
肖超群 authored
405
406
407
408
409
      if (!this.url.delete2) {
        this.$message.error('请设置url.delete2属性!')
        return
      }
      var that = this
410
      deleteAction(that.url.delete2, { roleId: this.currentRoleId, userId: id }).then(res => {
肖超群 authored
411
412
413
        if (res.success) {
          that.$message.success(res.message)
          that.loadData2()
肖超群 authored
414
        } else {
肖超群 authored
415
          that.$message.warning(res.message)
肖超群 authored
416
        }
肖超群 authored
417
418
      })
    },
419
    batchDel2: function() {
肖超群 authored
420
421
422
423
424
425
426
427
428
429
430
      if (!this.url.deleteBatch2) {
        this.$message.error('请设置url.deleteBatch2属性!')
        return
      }
      if (this.selectedRowKeys2.length <= 0) {
        this.$message.warning('请选择一条记录!')
        return
      } else {
        var ids = ''
        for (var a = 0; a < this.selectedRowKeys2.length; a++) {
          ids += this.selectedRowKeys2[a] + ','
肖超群 authored
431
432
        }
        var that = this
肖超群 authored
433
434
435
436
        console.log(this.currentDeptId)
        this.$confirm({
          title: '确认删除',
          content: '是否删除选中数据?',
437
438
          onOk: function() {
            deleteAction(that.url.deleteBatch2, { roleId: that.currentRoleId, userIds: ids }).then(res => {
肖超群 authored
439
440
441
442
443
444
445
446
              if (res.success) {
                that.$message.success(res.message)
                that.loadData2()
                that.onClearSelected()
              } else {
                that.$message.warning(res.message)
              }
            })
肖超群 authored
447
448
          }
        })
肖超群 authored
449
450
451
452
453
454
455
456
457
458
      }
    },
    selectOK(data) {
      let params = {}
      params.roleId = this.currentRoleId
      params.userIdList = []
      for (var a = 0; a < data.length; a++) {
        params.userIdList.push(data[a])
      }
      console.log(params)
459
      postAction(this.url.addUserRole, params).then(res => {
肖超群 authored
460
461
462
        if (res.success) {
          this.loadData2()
          this.$message.success(res.message)
肖超群 authored
463
        } else {
肖超群 authored
464
          this.$message.warning(res.message)
肖超群 authored
465
        }
肖超群 authored
466
467
      })
    },
肖超群 authored
468
肖超群 authored
469
470
471
472
473
474
475
476
477
478
    handleAddUserRole() {
      if (this.currentRoleId == '') {
        this.$message.error('请选择一个角色!')
      } else {
        this.$refs.selectUserModal.visible = true
      }
    },
    handleOpen(record) {
      this.rightcolval = 1
      this.selectedRowKeys1 = [record.id]
479
      this.selectionRows1 = record
肖超群 authored
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
      this.model1 = Object.assign({}, record)
      this.currentRoleId = record.id
      this.onClearSelected2()
      this.loadData2()
    },
    /*handleEdit: function(record) {
      if (this.currentRoleId == '') {
        this.$message.error('请选择一个角色!')
      } else {
        this.$refs.modalForm.edit(record)
        this.$refs.modalForm.title = '编辑'
      }
    },*/
    searchQuery2() {
      this.loadData2(1)
    },
    searchReset2() {
      this.queryParam2 = {}
      this.loadData2(1)
    },
    handleTableChange2(pagination, filters, sorter) {
      //分页、排序、筛选变化时触发
      //TODO 筛选
      if (Object.keys(sorter).length > 0) {
        this.isorter2.column = sorter.field
        this.isorter2.order = 'ascend' == sorter.order ? 'asc' : 'desc'
      }
      this.ipagination2 = pagination
      this.loadData2()
    },
    hideUserList() {
      //this.rightcolval = 0
      this.selectedRowKeys1 = []
    },
    handlePerssion(roleId) {
515
516
      this.$refs.modalUserRole.show(roleId)
    }
肖超群 authored
517
  }
肖超群 authored
518
}
肖超群 authored
519
520
521
</script>
<style scoped>
@import '~@assets/less/common.less';
肖超群 authored
522
523
/** Button按钮间距 */
.ant-btn {
524
  margin-left: 0px;
肖超群 authored
525
}
肖超群 authored
526
</style>