Files
laws_weilai/jero-web/src/views/system/RoleUserList.vue
T

439 lines
13 KiB
Java

<template>
<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="6" :sm="8">
<div class="box-title-text">
<div class="title-text" :title="$t('roleName')">
<span>{{$t('roleName')}}</span>
</div>
<j-input class="box-input" :placeholder="$t('PleaseEnter')+$t('roleName')"
v-model="queryParam.roleName"></j-input>
</div>
</a-col>
<span style="float: right;overflow: hidden;margin-right: 11px" class="table-page-search-submitButtons">
<a-col :md="6" :sm="24">
<a-button class="box-button" type="primary" @click="searchQuery">{{$t('query')}}</a-button>
<a-button class="box-button" style="margin-left: 8px" @click="searchReset">{{$t('reset')}}</a-button>
</a-col>
</span>
</a-row>
</a-form>
</div>
<!-- 操作按钮区域 -->
<div class="table-operator add-flex">
<a-button @click="handleAdd" v-has="'sys:role:add'" type="primary" icon="plus">{{$t('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">{{$t('import')}}</a-button>-->
<!-- </a-upload>-->
<!-- <div @click="handleExportXls($t('RoleManagement'))" class="operator-text">-->
<!-- <a-icon type="export" :rotate="-90"/>-->
<!-- {{$t('export')}}-->
<!-- </div>-->
</div>
<!-- <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">-->
<!-- <i class="anticon anticon-info-circle ant-alert-icon">-->
<!-- </i> {{$t('selected')}} <a><b>{{ selectedRowKeys1.length }}</b></a>{{$t('term')}}-->
<!-- <a style="margin-left: 24px" @click="onClearSelected1">{{$t('empty')}}</a>-->
<!-- </div>-->
<div style="margin-top: 15px">
<a-table
ref="table"
rowKey="id"
:components="drag(columns,'columns')"
:columns="columns"
:dataSource="dataSource"
:pagination="ipagination"
:loading="loading"
:scroll="{x: '100%'}"
@change="handleTableChange">
<span slot="action" slot-scope="text, record">
<a @click="handlePerssion(record.id)"
v-has="'sys:role:auth'"
class="text">{{$t('toGrantAuthorization')}}</a>
<a @click="handleEdit(record)"
v-has="'sys:role:edit'"
class="text">{{$t('edit')}}</a>
<a-popconfirm :title="$t('areYouSure')" @confirm="() => handleDelete1(record.id)">
<a class="text" v-has="'sys:role:del'">{{$t('delete')}}</a>
</a-popconfirm>
<!-- <a @click="handleOpen(record)">{{$t('user')}}</a>-->
<!-- <a-divider type="vertical"/>-->
</span>
</a-table>
</div>
<!-- 右侧的角色权限配置 -->
<user-role-modal ref="modalUserRole"></user-role-modal>
<role-modal ref="modalForm" @ok="modalFormOk"></role-modal>
</a-card>
</template>
<script>
import { JeroListMixin } from '@/mixins/JeroListMixin'
import { deleteAction, 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,
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] + ' ' + this.$t('total') + total + this.$t('strip')
},
showQuickJumper: true,
showSizeChanger: true,
total: 0
},
isorter1: {
column: 'createTime',
order: 'desc'
},
filters1: {},
filters2: {},
loading1: false,
loading2: false,
selectedRowKeys1: [],
selectedRowKeys2: [],
selectionRows1: [],
selectionRows2: [],
test: {},
rightcolval: 0,
columns: [
{
title: this.$t('serialNumber'),
dataIndex: '',
key: 'rowIndex',
width: 90,
align: 'left',
customRender: function(t, r, index) {
return parseInt(index) + 1
}
},
{
title: this.$t('RoleCode'),
align: 'left',
dataIndex: 'roleCode',
width: 280
},
{
title: this.$t('roleName'),
align: 'left',
dataIndex: 'roleName',
width: 280
},
{
title: this.$t('createTime'),
dataIndex: 'createTime',
align: 'left',
width: 280,
sorter: true,
customRender: (text) => {
return moment(text).format('YYYY-MM-DD')
}
},
{
title: this.$t('operation'),
width: 200,
dataIndex: 'action',
align: 'left',
scopedSlots: { customRender: 'action' }
}
],
// 高级查询拼接条件
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'
}
}
},
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: {
onClearSelected2() {
this.selectedRowKeys2 = []
this.selectionRows2 = []
},
onClearSelected() {
},
getQueryParams2() {
//获取查询条件
let sqp = {}
if (this.superQueryParams2) {
sqp['superQueryParams'] = encodeURI(this.superQueryParams2)
sqp['superQueryMatchType'] = this.superQueryMatchType2
}
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)
},
getQueryField2() {
//TODO 字段权限控制
var 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.error(this.$t('selectOneRule'))
} else {
this.$refs.modalForm2.roleDisabled = true
this.$refs.modalForm2.selectedRole = [this.currentRoleId]
this.$refs.modalForm2.add()
this.$refs.modalForm2.title = this.$t('add')
}
},
modalFormOk2() {
// 新增/修改 成功时,重载列表
this.loadData2()
},
loadData2(arg) {
if (!this.url.list2) {
this.$message.error(this.$t('setAttribute'))
return
}
//加载数据 若传入参数1则加载第一页的内容
if (arg === 1) {
this.ipagination2.current = 1
}
if (this.currentRoleId === '') return
let 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) {
let that = this
getAction(this.url.delete, { id: id }).then((res) => {
if (res.success) {
that.$message.success(res.message)
that.loadData()
} else {
that.$message.warning(res.message)
}
})
this.dataSource2 = []
this.currentRoleId = ''
},
handleDelete2: function(id) {
if (!this.url.delete2) {
this.$message.error(this.$t('setDelAttribute'))
return
}
var that = this
getAction(that.url.delete2, { roleId: this.currentRoleId, userId: id }).then((res) => {
if (res.success) {
that.$message.success(res.message)
that.loadData2()
} else {
that.$message.warning(res.message)
}
})
},
batchDel2: function() {
if (!this.url.deleteBatch2) {
this.$message.error(this.$t('setDelBatAttribute'))
return
}
if (this.selectedRowKeys2.length <= 0) {
this.$message.warning(this.$t('selectARecored'))
return
} else {
var ids = ''
for (var a = 0; a < this.selectedRowKeys2.length; a++) {
ids += this.selectedRowKeys2[a] + ','
}
var that = this
console.log(this.currentDeptId)
this.$confirm({
title: this.$t('confirmDeletion'),
content: this.$t('deleteAData'),
onOk: function() {
deleteAction(that.url.deleteBatch2, { roleId: that.currentRoleId, userIds: ids }).then((res) => {
if (res.success) {
that.$message.success(res.message)
that.loadData2()
that.onClearSelected()
} else {
that.$message.warning(res.message)
}
})
}
})
}
},
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)
postAction(this.url.addUserRole, params).then((res) => {
if (res.success) {
this.loadData2()
this.$message.success(res.message)
} else {
this.$message.warning(res.message)
}
})
},
handleAddUserRole() {
if (this.currentRoleId == '') {
this.$message.error(this.$t('selectOneRule'))
} else {
this.$refs.selectUserModal.visible = true
}
},
handleOpen(record) {
this.rightcolval = 1
this.selectedRowKeys1 = [record.id]
this.model1 = Object.assign({}, record)
this.currentRoleId = record.id
this.onClearSelected2()
this.loadData2()
},
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) {
this.$refs.modalUserRole.show(roleId)
}
}
}
</script>
<style scoped>
/** Button按钮间距 */
.ant-btn {
margin-left: 8px
}
.box-title-text {
line-height: 1.4;
display: flex;
align-items: center;
margin-bottom: 10px;
}
.title-text {
width: 20%;
min-width: 90px;
color: #000F16;
display: inline-block;
font-weight: 500;
font-size: 14px;
margin-right: 16px;
margin-top: 3px;
text-align: right;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.box-input {
display: inline-block;
width: 70%;
height: 38px;
margin-top: 2px;
}
.box-button {
height: 38px;
/*margin-top: 2px;*/
}
.text {
margin-right: 8px;
}
.add-flex{
display: flex;
justify-content: flex-end;
}
</style>