You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

717 lines
24 KiB

<template>
<div class="mod-user">
<el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
<el-form-item>
<el-input v-model="dataForm.userName" :placeholder="this.$t('user.table.userNameplaceholder')" clearable></el-input>
</el-form-item>
<el-form-item>
<el-button @click="getDataList()" type="primary">{{ $t('user.table.search') }}</el-button>
<el-button type="primary" @click="addOrUpdateHandle()">
{{ $t('user.table.add') }}
</el-button>
<el-button v-if="isAuth('sys:user:save')" :disabled="this.showButton" type="primary"
@click="specialAuthorize()"
>{{ buttons.specialCompetencies || $t('sys.user.specialPermissions') }}
</el-button>
<el-button v-if="isAuth('sys:user:save')" :disabled="this.showButton" type="primary"
@click="siteAuthorize()"
> {{ buttons.factoryAuthorization || $t('sys.user.factoryAuthorization') }}
</el-button>
<el-button type="primary" :disabled="this.showButton"
@click="warehouseAuthorize()"
> {{ buttons.warehouseAuthorization || $t('sys.user.warehouseAuthorization') }}
</el-button>
</el-form-item>
</el-form>
<el-table
:data="dataList"
border
:height="height"
v-loading="dataListLoading"
@selection-change="selectionChangeHandle"
highlight-current-row
@current-change="handleCurrentChange"
style="width: 100%;">
<el-table-column
prop="username"
header-align="center"
align="center"
:label="this.$t('user.table.userNameplaceholder')">
</el-table-column>
<el-table-column
prop="userDisplay"
header-align="center"
align="center"
:label="buttons.userDisplay||$t('sys.user.userName')">
</el-table-column>
<el-table-column
prop="domainAccount"
header-align="center"
align="center"
:label="buttons.domainAccount||$t('sys.user.domainAccount')">
</el-table-column>
<el-table-column
prop="email"
header-align="center"
align="center"
:label="buttons.email||$t('sys.user.email')">
</el-table-column>
<el-table-column
prop="mobile"
header-align="center"
align="center"
:label="buttons.mobile||$t('sys.user.mobile')">
</el-table-column>
<el-table-column
prop="status"
header-align="center"
align="center"
:label="buttons.status||$t('sys.user.status')">
<template slot-scope="scope">
<el-link v-if="scope.row.status === 0" type="success">{{ buttons.disable || $t('sys.user.disabled') }}</el-link>
<el-link v-else type="danger">{{ buttons.normal || $t('sys.user.normal') }}</el-link>
</template>
</el-table-column>
<el-table-column
prop="createTime"
header-align="center"
align="center"
width="180"
:label="buttons.createTime||$t('sys.common.createTime')">
</el-table-column>
<el-table-column
fixed="right"
header-align="center"
align="center"
width="200"
:label="buttons.cz||$t('sys.common.operation')">
<template slot-scope="scope">
<!-- <a type="text" @click="generateData(scope.row)">{{ buttons.auth || '审核' }}</a>-->
<a type="text" v-if="scope.row.username!=='sys_wms'" @click="addOrUpdateHandle(scope.row.userId)">{{ buttons.edit || $t('sys.common.edit') }}</a>
<a type="text" v-if="scope.row.username!=='sys_wms'&&scope.row.username!=='admin'" @click="deleteHandle(scope.row.userId)">{{ buttons.delete || $t('sys.common.delete') }}</a>
<a type="text" v-if="scope.row.username!=='sys_wms'" @click="forceLogoutHandle(scope.row)" style="color: #F56C6C;">{{ buttons.forceLogout || $t('sys.user.kickout') }}</a>
</template>
</el-table-column>
</el-table>
<el-pagination
@size-change="sizeChangeHandle"
@current-change="currentChangeHandle"
:current-page="pageIndex"
:page-sizes="[20, 50, 100, 200,500]"
:page-size="pageSize"
:total="totalPage"
layout="total, sizes, prev, pager, next, jumper">
</el-pagination>
<!-- 弹窗, 新增 / 修改 -->
<add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
<!-- 审核权限 -->
<el-dialog :close-on-click-modal="false" :close-on-press-escape="false" v-drag :title="inputSearch1"
:visible.sync="setUp.reviewFlag" width="518px">
<template>
<el-transfer v-model="checked" :data="transferData"
:titles="[buttons.allAuth || $t('sys.user.allPermissions'), buttons.currentAuth || $t('sys.user.currentPermissions')]"></el-transfer>
</template>
<span slot="footer" class="dialog-footer">
<div style="margin-top: 5px">
<el-button type="primary" :disabled="setUp.saveButton" @click="saveUserRoleFlag()">确定</el-button>
<el-button type="primary" @click="setUp.reviewFlag = false">取消</el-button>
</div>
</span>
</el-dialog>
<!-- 特殊权限 -->
<el-dialog
v-drag
:title="'特殊性权限'"
:visible.sync="specialVisible"
width="820px"
:append-to-body="true">
<el-table
:data="securityList"
border
:height="securityHeight"
v-loading="dataListLoading"
style="width: 100%;">
<el-table-column
v-for="(item,index) in columnList" :key="index"
:sortable="item.columnSortable"
:prop="item.columnProp"
:header-align="item.headerAlign"
:show-overflow-tooltip="item.showOverflowTooltip"
:align="item.align"
:fixed="item.fixed==''?false:item.fixed"
:min-width="item.columnWidth"
:label="item.columnLabel">
<template slot-scope="scope">
<span v-if="!item.columnHidden"> {{ scope.row[item.columnProp] }}</span>
<span v-if="item.columnHidden">
<el-checkbox v-model="scope.row[item.columnProp] "></el-checkbox>
</span>
<span v-if="item.columnImage"><img :src="scope.row[item.columnProp]"
style="width: 100px; height: 80px"/></span>
</template>
</el-table-column>
</el-table>
<span slot="footer" class="dialog-footer">
<el-button type="primary" @click="saveUserSecurity()">确定</el-button>
<el-button @click="specialVisible = false" type="primary">取消</el-button>
</span>
</el-dialog>
<!-- 工厂授权 -->
<el-dialog
style="font-size: 12px"
v-drag
:title="'工厂/子site授权'"
:visible.sync="siteVisible"
width="518px"
:append-to-body="true">
<el-transfer v-model="selectSitList" :data="siteList" :titles="['未授权子site', '已授权子site']"></el-transfer>
<span slot="footer" class="dialog-footer">
<div style="margin-top: 5px">
<el-button type="primary" @click="saveUserAssessSite()">确定</el-button>
<el-button @click="siteVisible = false" type="primary">取消</el-button>
</div>
</span>
</el-dialog>
<!-- 仓库授权 -->
<el-dialog
style="font-size: 12px"
v-drag
:title="'仓库授权'"
:visible.sync="warehouseVisible"
width="518px"
:append-to-body="true">
<el-transfer v-model="selectWarehouseList" :data="warehouseList" :titles="['未授权仓库', '已授权仓库']"></el-transfer>
<span slot="footer" class="dialog-footer">
<div style="margin-top: 5px">
<el-button type="primary" @click="saveUserAccessWarehouse()">确定</el-button>
<el-button @click="warehouseVisible = false" type="primary">取消</el-button>
</div>
</span>
</el-dialog>
</div>
</template>
<script>
import {getActiveSubSiteOptions, getUserAuthorizedSiteAccess, saveUserAccessSiteList} from '@/api/factory/accessSite.js'
import {getUserAccessWarehouseList, saveUserAccessWarehouseList, getWarehouseListForAuth} from '@/api/warehouse/warehouse.js'
import AddOrUpdate from './user-add-or-update'
import {getUserBusinessRoleList, saveUserBusinessRole,} from '@/api/auditManagement/auditType.js'
import {
getUserSpecialSecurity,
saveUserSpecialSecurity,
updateUserSpecialSecurity
} from '@/api/factory/userSpecialSecurity.js'
import {debounce, throttle} from "../../../utils/common";
import {
searchFunctionButtonList,
} from "@/api/sysLanguage.js"
export default {
data() {
return {
showButton: true,
height: 200,
securityHeight: 300,
specialVisible: false,
siteVisible: false,
warehouseVisible: false,
forceLogoutLoading: false,
currentData: {},
userId: this.$store.state.user.name,
transferData: [],
checked: [],
inputSearch1: '审核权限',
//设置
setUp: {
reviewFlag: false,
saveButton: false,
},
dataForm: {
userName: ''
},
columnList: [
{
userId: this.$store.state.user.name,
serialNumber: 'security' + this.$route.meta.menuId + 'securitydesc',
tableId: this.$route.meta.menuId + 'security',
tableName: "securityTable",
columnProp: "securitydesc",
headerAlign: "center",
align: "left",
columnLabel: "参数描述",
columnHidden: false,
columnImage: false,
columnWidth: 70,
columnSortable: false,
sortLv: 0,
status: true,
fixed: '',
},
{
userId: this.$store.state.user.name,
serialNumber: 'security' + this.$route.meta.menuId + 'securitydesc',
tableId: this.$route.meta.menuId + 'security',
tableName: "securityTable",
columnProp: "module",
headerAlign: "center",
align: "left",
columnLabel: "模块",
columnHidden: false,
columnImage: false,
columnSortable: false,
columnWidth: 20,
sortLv: 0,
status: true,
fixed: '',
},
{
userId: this.$store.state.user.name,
serialNumber: 'security' + this.$route.meta.menuId + 'securitydesc',
tableId: this.$route.meta.menuId + 'security',
tableName: "securityTable",
columnProp: "itemvalue",
headerAlign: "center",
align: "center",
columnLabel: "参数值",
columnHidden: true,
columnImage: false,
columnSortable: false,
columnWidth: 10,
sortLv: 0,
status: true,
fixed: '',
},
],
buttons: {
cz: this.$t('sys.common.operation'), search: this.$t('sys.common.search'), add: this.$t('sys.common.add'), edit: this.$t('sys.common.edit'), delete: this.$t('sys.common.delete'),
forceLogout: this.$t('sys.user.kickout'), specialCompetencies: this.$t('sys.user.specialPermissions'), factoryAuthorization: this.$t('sys.user.factoryAuthorization'), warehouseAuthorization: this.$t('sys.user.warehouseAuthorization'),
createTime: this.$t('sys.common.createTime'), username: this.$t('sys.user.account'), userDisplay: this.$t('sys.user.userName'), domainAccount: this.$t('sys.user.domainAccount'), email: this.$t('sys.user.email'), mobile: this.$t('sys.user.mobile'),
status: this.$t('sys.user.status'), disable: this.$t('sys.user.disabled'), normal: this.$t('sys.user.normal'), auth: this.$t('sys.user.review'), allAuth: this.$t('sys.user.allPermissions'), currentAuth: this.$t('sys.user.currentPermissions')
},
dataList: [],
securityList: [],
selectSpecialList: [],
siteList: [],
selectSitList: [],
warehouseList: [],
selectWarehouseList: [],
selectUser: {},
pageIndex: 1,
pageSize: 20,
totalPage: 0,
dataListLoading: false,
dataListSelections: [],
addOrUpdateVisible: false
}
},
components: {
AddOrUpdate
},
activated() {
this.getDataList()
},
mounted() {
this.$nextTick(() => {
this.securityHeight = window.innerHeight - 300;
this.height = window.innerHeight - 200;
})
},
methods: {
// 获取button的词典
getFunctionButtonList() {
let queryButton = {
functionId: this.$route.meta.menuId,
tableId: '*',
languageCode: this.$i18n.locale,
objectType: 'button'
}
searchFunctionButtonList(queryButton).then(({data}) => {
if (data.code == 0 && data.data) {
this.buttons = data.data
}
})
},
// 特殊权限
specialAuthorize() {
this.specialVisible = true
this.searchUserSpecialSecurity()
},
// 获取特殊权限
searchUserSpecialSecurity() {
saveUserSpecialSecurity({userid: this.selectUser.username}).then(({data}) => {
if (data.code === 0) {
getUserSpecialSecurity(this.selectUser.username).then(({data}) => {
if (data.code === 0) {
this.securityList = data.dataList.map(item => {
item.itemvalue = item.itemvalue == 'Y' ? true : false;
return item;
})
}
})
}
})
},
// 保存用户权限
saveUserSecurity() {
let securityList = JSON.parse(JSON.stringify(this.securityList)).map(item => {
item.itemvalue = item.itemvalue === true ? 'Y' : 'N';
return item;
})
updateUserSpecialSecurity(securityList).then(({data}) => {
if (data.code === 0) {
this.$message.success(data.msg)
this.specialVisible = false
} else {
this.$message.success(data.msg)
}
})
},
// 授权工厂
siteAuthorize() {
this.siteVisible = true
this.searchSiteList()
},
// 授权仓库
warehouseAuthorize() {
this.warehouseVisible = true
this.searchWarehouseList()
},
buildSiteAuthKey(siteId, subSiteId) {
if (!siteId) {
return ''
}
const keySubSiteId = subSiteId || '__NO_SUBSITE__'
return `${siteId}::${keySubSiteId}`
},
parseSiteAuthKey(key) {
const tokens = (key || '').split('::')
const rawSubSiteId = tokens[1] || ''
return {
site: tokens[0] || '',
subSiteId: rawSubSiteId === '__NO_SUBSITE__' ? '' : rawSubSiteId
}
},
// 保存选中的授权子site
saveUserAssessSite() {
let accessSiteList = this.selectSitList.map(item => {
const siteInfo = this.parseSiteAuthKey(item)
let itemSite = {
userid: this.selectUser.username,
site: siteInfo.site,
subSiteId: siteInfo.subSiteId
}
return itemSite;
}).filter(item => item.site)
let accessSite = {
userid: this.selectUser.username,
accessSiteList: accessSiteList
}
saveUserAccessSiteList(accessSite).then(({data}) => {
if (data.code === 0) {
this.$message.success(data.msg)
this.siteList = []
this.selectSitList = []
this.siteVisible = false
} else {
this.$message.warning(data.msg)
}
})
},
// 获取用户已授权的子site列表
searchUserAccessSiteList() {
getUserAuthorizedSiteAccess({userName: this.selectUser.username}).then(({data}) => {
if (data && data.code === 0) {
this.selectSitList = (data.data || []).map(item => {
return this.buildSiteAuthKey(item.siteId || item.siteCode, item.subSiteId)
}).filter(item => !!item)
}
})
},
// 获取所有可用工厂-子site选项
searchSiteList() {
getActiveSubSiteOptions({}).then(({data}) => {
if (data && data.code === 0) {
const optionMap = {}
;(data.data || []).forEach(item => {
if (!item.siteId) {
return
}
const key = this.buildSiteAuthKey(item.siteId, item.subSiteId)
optionMap[key] = {
key: key,
label: item.subSiteId
? `${item.siteId} - ${item.siteName || item.siteId} - ${item.subSiteId}`
: `${item.siteId} - ${item.siteName || item.siteId}`
}
})
this.siteList = Object.keys(optionMap).map(key => optionMap[key])
this.searchUserAccessSiteList()
}
})
},
// 保存选中的授权仓库
saveUserAccessWarehouse() {
let accessWarehouseData = {
userid: this.selectUser.username,
accessWarehouseList: this.selectWarehouseList // selectWarehouseList已经是仓库ID数组
}
saveUserAccessWarehouseList(accessWarehouseData).then(({data}) => {
if (data.code === 0) {
this.$message.success(data.msg || '操作成功')
this.warehouseList = []
this.selectWarehouseList = []
this.warehouseVisible = false
} else {
this.$message.warning(data.msg || '操作失败')
}
}).catch(() => {
this.$message.error(this.$t('sys.user.saveWarehouseFailed'))
})
},
// 获取用户已授权的仓库列表
searchUserAccessWarehouseList() {
getUserAccessWarehouseList({userid: this.selectUser.username}).then(({data}) => {
if (data.code === 0) {
this.selectWarehouseList = data.dataList || []
}
}).catch(() => {
this.$message.error(this.$t('sys.user.getWarehouseFailed'))
})
},
// 获取所有可用仓库
searchWarehouseList() {
getWarehouseListForAuth({active: 'Y',site:localStorage.getItem('site')}).then(({data}) => {
if (data.code === 0) {
// 转换为el-transfer需要的数据格式
this.warehouseList = (data.dataList || []).map(item => ({
key: item.wareHouseId,
label: `${item.wareHouseId} - ${item.wareHouseName || item.wareHouseId}`
}))
this.searchUserAccessWarehouseList()
}
}).catch(() => {
this.$message.error('获取仓库列表失败')
})
},
// 选中行
handleCurrentChange(val) {
this.selectUser = val
this.showButton = false
},
saveUserRoleFlag() {
let saveList = []
let currentList = this.checked
// 当前未选择记录
if (currentList.length == 0) {
this.$confirm(this.$t('sys.common.confirm'), this.$t('sys.common.tip'), {
confirmButtonText: this.$t('sys.common.confirm'),
cancelButtonText: this.$t('sys.common.cancel'),
}).then(() => {
let data = {
userId: this.currentData.userId,
}
saveList.push(data);
this.saveUserBusinessRole(saveList)
}).catch(() => {
return
})
} else {
for (let i = 0; i < currentList.length; i++) {
let data = {
userId: this.currentData.userId,
roleItemNo: currentList[i],
selectFlag: 'Y',
}
saveList.push(data);
}
this.saveUserBusinessRole(saveList)
}
},
saveUserBusinessRole(saveList) {
saveUserBusinessRole(saveList).then(({data}) => {
this.$alert(data.msg, '操作提示', {
confirmButtonText: '确定',
callback: action => {
if (data.code == 0) {
this.setUp.reviewFlag = false
}
this.setUp.saveButton = false
}
});
})
},
generateData(row) {
this.currentData = row
let queryData = {
active: 'Y',
userId: this.currentData.userId,
}
getUserBusinessRoleList(queryData).then(({data}) => {
let rows1Data = data.map.rows1
let rows2Data = data.map.rows2
let forData = []
let checkedList = []
for (let i = 0; i < rows1Data.length; i++) {
forData.push({
key: rows1Data[i].roleItemNo,
label: rows1Data[i].roleDesc,
});
}
for (let j = 0; j < rows2Data.length; j++) {
checkedList.push(rows2Data[j].roleItemNo)
}
this.transferData = forData;
this.checked = checkedList
this.setUp.reviewFlag = true
})
},
// 获取数据列表
getDataList: throttle(function () {
this.dataListLoading = true
this.$http({
url: this.$http.adornUrl('/sys/user/list'),
method: 'get',
params: this.$http.adornParams({
'page': this.pageIndex,
'limit': this.pageSize,
'username': this.dataForm.userName
})
}).then(({data}) => {
if (data && data.code === 0) {
this.dataList = data.page.list
this.totalPage = data.page.totalCount
} else {
this.dataList = []
this.totalPage = 0
}
this.dataListLoading = false
})
}, 1000),
// 每页数
sizeChangeHandle(val) {
this.pageSize = val
this.pageIndex = 1
this.getDataList()
},
// 当前页
currentChangeHandle(val) {
this.pageIndex = val
this.getDataList()
},
// 多选
selectionChangeHandle(val) {
this.dataListSelections = val
},
// 新增 / 修改
addOrUpdateHandle(id) {
this.addOrUpdateVisible = true
this.$nextTick(() => {
this.$refs.addOrUpdate.init(id)
})
},
// 删除
deleteHandle(id) {
var userIds = id ? [id] : this.dataListSelections.map(item => {
return item.userId
})
this.$confirm(`确定对[id=${userIds.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
this.$http({
url: this.$http.adornUrl('/sys/user/delete'),
method: 'post',
data: this.$http.adornData(userIds, false)
}).then(({data}) => {
if (data && data.code === 0) {
this.$message.success(this.$t('sys.common.success'))
this.getDataList()
} else {
this.$message.error(data.msg)
}
})
}).catch(() => {
})
},
// 踢出登录 - rqrq
forceLogoutHandle(row) {
this.$confirm(this.$t('sys.user.kickoutConfirm'), this.$t('sys.user.kickout'), {
confirmButtonText: this.$t('sys.common.confirm'),
cancelButtonText: this.$t('sys.common.cancel'),
type: 'warning'
}).then(() => {
this.forceLogoutLoading = true
this.$http({
url: this.$http.adornUrl('/sys/user/forceLogout'),
method: 'post',
data: this.$http.adornData({
userId: row.userId
})
}).then(({data}) => {
if (data && data.code === 0) {
this.$message.success(this.$t('sys.user.kickoutSuccess'))
this.getDataList()
} else {
this.$alert(data.msg || '踢出登录失败', '错误')
}
}).catch(() => {
this.$message.error(this.$t('warehouse.message.operationFailed'))
}).finally(() => {
this.forceLogoutLoading = false
})
}).catch(() => {
})
}
},
created() {
//this.getFunctionButtonList()
}
}
</script>
<style>
.el-transfer-panel {
border: 2px solid #17b3a3;
border-radius: 4px;
overflow: hidden;
background: #fff;
display: inline-block;
vertical-align: middle;
width: 200px;
max-height: 100%;
-webkit-box-sizing: border-box;
box-sizing: border-box;
position: relative;
}
.el-transfer-panel .el-transfer-panel__header {
height: 40px;
line-height: 40px;
background: #17b3a3;
margin: 0;
padding-left: 15px;
border-bottom: 1px solid #17b3a3;
-webkit-box-sizing: border-box;
box-sizing: border-box;
color: #000;
}
.el-transfer-panel .el-transfer-panel__header .el-checkbox .el-checkbox__label {
font-size: 14px;
color: #303133;
font-weight: 400;
}
.el-dialog__title {
line-height: 24px;
font-size: 16px;
color: #303133;
}
</style>