Files
laws_chery_client/src/views/system/RoleUserList.vue
T

593 lines
19 KiB
Vue

<template>
<a-row :gutter="10" style="width: 100%">
<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">
<a-col :md="this.selectedRowKeys1.length === 0 ? 6: 12" :sm="12">
<a-form-item :label="$t('roleManage.roleName')"
:labelCol="{span: 5}"
:wrapperCol="{span: 18, offset: 1}">
<j-input :placeholder="$t('pleaseEnter') + $t('roleManage.roleName')"
v-model="queryParam.roleName"></j-input>
</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>
-->
<div style="float: right;overflow: hidden;margin-right: 11px" class="table-page-search-submitButtons">
<a-button type="primary" @click="searchQuery" icon="search" style="margin-left: 21px">{{ $t('query')
}}
</a-button>
<a-button type="primary" @click="searchReset" icon="reload" ghost style="margin-left: 8px">
{{ $t('reset') }}
</a-button>
</div>
</a-row>
</a-form>
</div>
<!-- 操作按钮区域 -->
<div class="table-operator">
<a-button @click="handleAdd" type="primary" icon="plus" v-has="'sys:role:add'">{{ $t('roleManage.newRole') }}</a-button>
<!--<a-button @click="handleEdit(model1)" type="primary" icon="plus">角色编辑</a-button>-->
<!-- <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">-->
<!-- <a-button type="primary" icon="import">导入</a-button>-->
<!-- </a-upload>-->
<!-- <a-button type="primary" icon="download" @click="handleExportXls('角色管理')">导出</a-button>-->
</div>
<div style="margin-top: 15px">
<j-table
ref="table"
style="max-height: 500px"
size="middle"
:can-drag="true"
rowKey="id"
:columns="columns"
:dataSource="dataSource"
:pagination="ipagination"
:loading="loading"
:scroll="{x: 500, y: yScrollHeight}"
:rowSelection="{selectedRowKeys: selectedRowKeys1, onChange: onSelectChange1, type:'radio'}"
:operationList="operationList"
@operationClick="operationClick"
@change="handleTableChange">
</j-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 class="user-top-box">
<!-- 查询区域 -->
<div class="table-page-search-wrapper">
<a-form layout="inline" @keyup.enter.native="searchQuery2">
<a-row :gutter="24">
<a-col :md="12" :sm="12">
<a-form-item :label="$t('user.userAccount')">
<a-input :placeholder="$t('pleaseEnter') + $t('user.userAccount')"
v-model="queryParam2.username"></a-input>
</a-form-item>
</a-col>
<div style="float: right;overflow: hidden;" class="table-page-search-submitButtons">
<a-button type="primary" @click="searchQuery2" icon="search">{{ $t('query') }}</a-button>
<a-button type="primary" @click="searchReset2" icon="reload" ghost style="margin-left: 8px">
{{ $t('reset') }}
</a-button>
</div>
</a-row>
</a-form>
</div>
<a-icon type="close-circle" class="close-icon" @click="hideUserList" />
</div>
<!-- 操作按钮区域 -->
<div class="table-operator">
<!--<a-button @click="handleAdd2" type="primary" icon="plus" style="margin-top: 16px">{{ $t('roleManage.newUser') }}</a-button>-->
<!--<a-button @click="handleEdit2" type="primary" icon="edit" style="margin-top: 16px">用户编辑</a-button>-->
<a-button @click="handleAddUserRole" type="primary" icon="plus">{{ $t('roleManage.existingUsers') }}
</a-button>
<a-button @click="batchDel2" ghost type="danger" icon="delete">{{ $t('batchDelete') }}</a-button>
</div>
<!-- table区域-begin -->
<div>
<j-table
ref="table2"
:can-drag="true"
style="max-height: 500px"
size="middle"
rowKey="id"
:columns="columns2"
:dataSource="dataSource2"
:pagination="ipagination2"
:loading="loading2"
:scroll="{x: 500, y: yScrollHeight}"
:rowSelection="{selectedRowKeys: selectedRowKeys2, onChange: onSelectChange2}"
@change="handleTableChange2">
<template slot="action" slot-scope="{text, record}">
<a class="operate-del-btn" @click="handleDelete2(record.id)">{{ $t('delete') }}</a>
</template>
</j-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>
import '@assets/less/common.less'
import { JeroListMixin } from '@/mixins/JeroListMixin'
import { postAction, getAction } from '@/api/manage'
import SelectUserModal from './modules/SelectUserModal'
import RoleModal from './modules/RoleModal'
import UserModal from './modules/UserModal'
import { filterObj } from '@/utils/util'
import UserRoleModal from './modules/UserRoleModal'
import moment from 'moment'
import { ResizeHeader, ResizeColumnProvide } from '@/mixins/header'
export default {
name: 'RoleUserList',
mixins: [JeroListMixin, ResizeHeader, ResizeColumnProvide],
components: {
UserRoleModal,
SelectUserModal,
RoleModal,
UserModal
},
data () {
return {
model1: {},
model2: {},
currentRoleId: '',
queryParam1: {},
queryParam2: {},
dataSource1: [],
dataSource2: [],
ipagination1: {
current: 1,
pageSize: 10,
pageSizeOptions: ['10', '30', '50', '100', '150', '200'],
showTotal: (total, range) => {
return range[0] + '-' + range[1] + ' ' + this.$t('total') + total + this.$t('strip')
},
showQuickJumper: true,
showSizeChanger: true,
total: 0
},
ipagination2: {
current: 1,
pageSize: 10,
pageSizeOptions: ['10', '30', '50', '100', '150', '200'],
showTotal: (total, range) => {
return range[0] + '-' + range[1] + ' ' + this.$t('total') + total + this.$t('strip')
},
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,
columns:
[
{
title: this.$t('roleManage.roleCode'),
align: 'center',
dataIndex: 'roleCode',
width: 100
},
{
title: this.$t('roleManage.roleName'),
align: 'center',
dataIndex: 'roleName',
width: 100
},
{
title: this.$t('createTime'),
dataIndex: 'createTime',
align: 'center',
sorter: true,
customRender: (text) => {
return moment(text).format('YYYY-MM-DD')
},
width: 100
},
{
title: this.$t('operation'),
dataIndex: 'action',
align: 'center',
scopedSlots: { customRender: 'action' },
width: 80
}
],
columns2: [
{
title: this.$t('user.userAccount'),
align: 'center',
dataIndex: 'username',
width: 120
},
{
title: this.$t('user.userName'),
align: 'center',
width: 100,
dataIndex: 'realname'
},
{
title: this.$t('status'),
align: 'center',
width: 80,
dataIndex: 'status_dictText',
scopedSlots: { customRender: 'dictText' }
},
{
title: this.$t('operation'),
dataIndex: 'action',
scopedSlots: { customRender: 'action' },
align: 'center',
width: 80
}
],
// 高级查询参数
superQueryParams2: '',
// 高级查询拼接条件
superQueryMatchType2: 'and',
url: {
list: '/sys/role/page',
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'
},
operationList: [
// 用户
{
text: this.$t('roleManage.userBtn'),
clickEvent: 'handleOpen',
has: 'sys:role:user'
},
// 授权
{
text: this.$t('roleManage.toGrantAuthorization'),
clickEvent: 'handlePerssion',
has: 'sys:role:permission'
},
// 编辑
{
text: this.$t('edit'),
clickEvent: 'handleEdit',
has: 'sys:role:edit'
},
// 删除
{
text: this.$t('delete'),
clickEvent: 'handleDelete1',
has: 'sys:role:del'
}
]
}
},
computed: {
importExcelUrl: function () {
return `${window._CONFIG.domianURL}/${this.url.importExcelUrl}`
},
leftColMd () {
return this.selectedRowKeys1.length === 0 ? 24 : 12
},
rightColMd () {
return this.selectedRowKeys1.length === 0 ? 0 : 12
}
},
methods: {
operationClick (operation, record) {
if (operation.clickEvent === 'handleDelete1') {
this.handleDelete1(record.id)
} else if (operation.clickEvent === 'handlePerssion') {
this.handlePerssion(record.id)
} else {
this[operation.clickEvent](record)
}
},
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
this.selectionRows1 = selectionRows
this.model1 = Object.assign({}, selectionRows[0])
console.log(this.model1)
this.currentRoleId = selectedRowKeys[0]
this.loadData2()
},
onClearSelected () {
this.selectedRowKeys2 = []
this.selectionRows2 = []
},
getQueryParams2 () {
// 获取查询条件
const sqp = {}
if (this.superQueryParams2) {
sqp.superQueryParams = encodeURI(this.superQueryParams2)
sqp.superQueryMatchType = this.superQueryMatchType2
}
const 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)
},
getQueryField2 () {
// TODO 字段权限控制
let str = 'id,'
this.columns2.forEach(function (value) {
str += ',' + value.dataIndex
})
return str
},
handleEdit2: function (record) {
this.$refs.modalForm2.title = this.$t('edit')
this.$refs.modalForm2.roleDisabled = true
this.$refs.modalForm2.edit(record)
},
handleAdd2: function () {
if (!this.currentRoleId) {
this.$message.warning(this.$t('roleManage.pleaseSelectARole'))
} else {
this.$refs.modalForm2.roleDisabled = true
this.$refs.modalForm2.title = this.$t('newlyAdded')
this.$refs.modalForm2.edit({
activitiSync: '1',
userIdentity: 1,
selectedroles: this.currentRoleId
})
}
},
modalFormOk2 () {
// 新增/修改 成功时,重载列表
this.loadData2()
},
loadData2 (arg) {
if (!this.url.list2) {
this.$message.warning('请设置url.list2属性!')
return
}
// 加载数据 若传入参数1则加载第一页的内容
if (arg === 1) {
this.ipagination2.current = 1
}
if (this.currentRoleId === '') return
const params = this.getQueryParams2()// 查询条件
params.roleId = this.currentRoleId
this.loading2 = true
getAction(this.url.list2, params).then((res) => {
if (res.success) {
this.dataSource2 = res.result.records
this.ipagination2.total = res.result.total
}
this.loading2 = false
})
},
handleDelete1: function (id) {
this.handleDelete(id)
this.dataSource2 = []
this.currentRoleId = ''
},
handleDelete2: function (id) {
if (!this.url.delete2) {
this.$message.warning('请设置url.delete2属性!')
return
}
const that = this
postAction(that.url.delete2, {
roleId: this.currentRoleId,
userId: id
}).then((res) => {
if (res.success) {
that.$message.success(res.message)
// 判断当前删除的数据是否是最后一页的最后一条数据,如果是的话页码减一
if (that.ipagination2.current > 1 && ((that.ipagination2.current - 1) * that.ipagination2.pageSize) + 1 === that.ipagination2.total) {
that.ipagination2.current -= 1
}
that.loadData2()
} else {
that.$message.warning(res.message)
}
})
},
batchDel2: function () {
if (!this.url.deleteBatch2) {
this.$message.warning('请设置url.deleteBatch2属性!')
return
}
if (this.selectedRowKeys2.length <= 0) {
this.$message.warning(this.$t('selectARecord'))
} else {
let ids = ''
for (let a = 0; a < this.selectedRowKeys2.length; a++) {
ids += this.selectedRowKeys2[a] + ','
}
const that = this
console.log(this.currentDeptId)
this.$confirm({
title: this.$t('confirmDeletion'),
content: this.$t('deleteAData'),
onOk: () => {
postAction(that.url.deleteBatch2, {
roleId: that.currentRoleId,
userIds: ids
}).then((res) => {
if (res.success) {
that.$message.success(res.message)
// 总数量-count
const count = this.selectedRowKeys2.length
const total = this.ipagination2.total - count
// 获取删除后的分页数
const currentIndex = Math.ceil(total / this.ipagination2.pageSize)
// 删除后的分页数<所在当前页
if (currentIndex < this.ipagination2.current) {
this.ipagination2.current = currentIndex
}
that.loadData2()
that.onClearSelected()
} else {
that.$message.warning(res.message)
}
})
}
})
}
},
selectOK (data) {
const params = {}
params.roleId = this.currentRoleId
params.userIdList = []
for (let a = 0; a < data.length; a++) {
params.userIdList.push(data[a])
}
console.log(params)
postAction(this.url.addUserRole, params).then((res) => {
if (res.success) {
this.loadData2()
this.$message.success(res.message)
} else {
this.$message.warning(res.message)
}
})
},
searchReset () {
this.queryParam = {}
this.loadData(1)
this.onClearSelected1()
},
handleAddUserRole () {
if (!this.currentRoleId) {
this.$message.warning(this.$t('roleManage.pleaseSelectARole'))
} else {
this.$refs.selectUserModal.visible = true
this.$refs.selectUserModal.searchQuery()
}
},
handleOpen (record) {
this.rightcolval = 1
this.selectedRowKeys1 = [record.id]
this.model1 = Object.assign({}, record)
this.currentRoleId = record.id
this.onClearSelected2()
this.loadData2()
},
/* handleEdit: function(record) {
if (this.currentRoleId == '') {
this.$message.warning('请选择一个角色!')
} else {
this.$refs.modalForm.edit(record)
this.$refs.modalForm.title = '编辑'
}
}, */
searchQuery2 () {
this.loadData2(1)
},
searchReset2 () {
this.queryParam2 = {}
this.onClearSelected2()
this.loadData2(1)
},
handleTableChange2 (pagination, filters, sorter) {
// 分页、排序、筛选变化时触发
// TODO 筛选
if (Object.keys(sorter).length > 0) {
this.isorter2.column = sorter.field
this.isorter2.order = sorter.order === 'ascend' ? 'asc' : 'desc'
}
this.ipagination2 = pagination
this.loadData2()
},
hideUserList () {
// this.rightcolval = 0
this.selectedRowKeys1 = []
},
handlePerssion (roleId) {
this.$refs.modalUserRole.show(roleId)
}
}
}
</script>
<style lang="less" scoped>
@import '~@assets/less/common.less';
/** Button按钮间距 */
.ant-btn {
margin-left: 8px
}
/deep/ .table-page-search-wrapper .ant-form-inline .ant-form-item > .ant-form-item-label {
min-width: 60px;
}
.user-top-box {
display: flex;
justify-content: space-between;
.table-page-search-wrapper {
flex: 1;
width: 0;
.ant-row {
margin-right: 0 !important;
}
}
.table-page-search-submitButtons {
margin-right: 0;
}
.close-icon {
margin-left: 8px;
cursor: pointer;
}
}
</style>