【新增】新增用户管理的授权角色与授权资源,新增前端导入功能,新增导出某用户的模板信息,优化部分代码

pull/87/head
小诺 2023-03-10 01:52:06 +08:00 committed by 俞宝山
parent e4a6b7aad0
commit b87a7f5d65
20 changed files with 1119 additions and 153 deletions

View File

@ -69,5 +69,43 @@ export default {
// 给用户授权角色
grantRole(data) {
return request('grantRole', data)
},
// 获取用户拥有资源
userOwnResource(data) {
return request('ownResource', data, 'get')
},
// 给用户授权资源
userGrantResource(data) {
return request('grantResource', data)
},
// 获取用户拥有权限
userOwnPermission(data) {
return request('ownPermission', data, 'get')
},
// 给用户授权权限
userGrantPermission(data) {
return request('grantPermission', data)
},
// 下载用户导入模板
userDownloadImportUserTemplate(data) {
return request('downloadImportUserTemplate', data, 'get', {
responseType: 'blob'
})
},
// 用户导入
userImport(data) {
return request('import', data)
},
// 用户导出
userExport(data) {
return request('export', data, 'get', {
responseType: 'blob'
})
},
// 按模板导出用户个人信息
userExportUserInfo(data) {
return request('exportUserInfo', data, 'get', {
responseType: 'blob'
})
}
}

View File

@ -16,7 +16,10 @@ export default {
editButton: 'edit',
removeButton: 'delete',
batchRemoveButton: 'batch Remove',
detailButton: 'detail'
detailButton: 'detail',
searchKey: 'Search Key',
imports: 'import',
more: 'More'
},
model: {
user: 'user',
@ -50,5 +53,10 @@ export default {
emailCodePlaceholder: 'Please input a Email code',
restPhoneType: 'For phone rest',
restEmailType: 'For email rest'
},
user: {
userStatus: 'User Status',
resetPassword: 'Reset Password',
role: 'Role',
}
}

View File

@ -18,7 +18,10 @@ export default {
editButton: '编辑',
removeButton: '删除',
batchRemoveButton: '批量删除',
detailButton: '详情'
detailButton: '详情',
searchKey: '关键词',
imports: '导入',
more: '更多',
},
model: {
user: '用户',
@ -52,5 +55,10 @@ export default {
emailCodePlaceholder: '请输入邮件验证码',
restPhoneType: '手机号找回',
restEmailType: '邮箱找回'
},
user: {
userStatus: '用户状态',
resetPassword: '重置密码',
role: '角色',
}
}

View File

@ -109,9 +109,7 @@
})
//
const onSubmit = () => {
formRef.value
.validate()
.then(() => {
formRef.value.validate().then(() => {
submitLoading.value = true
positionApi.submitForm(formData.value, !formData.value.id).then(() => {
visible = false

View File

@ -57,9 +57,7 @@
//
const onSubmit = () => {
formRef.value
.validate()
.then(() => {
formRef.value.validate().then(() => {
const defParam = {
category: 'BUTTON',
// module: recordData.value.module,

View File

@ -63,9 +63,7 @@
}
//
const onSubmit = () => {
formRef.value
.validate()
.then(() => {
formRef.value.validate().then(() => {
const defParam = {
category: 'FIELD',
parentId: recordData.value.id

View File

@ -14,17 +14,12 @@
</a-form-item>
<a-form-item label="所属目录:" name="module" v-if="formData.parentId === '0'">
<a-radio-group v-model:value="formData.module" button-style="solid">
<a-radio-button
v-for="module in moduleTypeList"
:key="module.id"
:value="module.id"
>
<a-radio-button v-for="module in moduleTypeList" :key="module.id" :value="module.id">
<component :is="module.icon" />
{{ module.title }}</a-radio-button
>
</a-radio-group>
</a-form-item>
</a-form>
<template #footer>
<a-button style="margin-right: 8px" @click="onClose"></a-button>
@ -65,23 +60,24 @@
//
const formRules = {
module: [required('请选择所属目录')],
module: [required('请选择所属目录')]
}
//
const onSubmit = () => {
formRef.value
.validate()
.then(() => {
formRef.value.validate().then(() => {
const param = {
id: formData.value.id,
module: formData.value.module
}
submitLoading.value = true
menuApi.menuChangeModule(param).then(() => {
menuApi
.menuChangeModule(param)
.then(() => {
submitLoading.value = false
emit('successful')
}).finally(() => {
})
.finally(() => {
visible = false
})
})

View File

@ -199,7 +199,8 @@
onClose()
emit('successful')
})
}).finally(() => {
})
.finally(() => {
submitLoading.value = false
})
}

View File

@ -74,9 +74,7 @@
//
const onSubmit = () => {
formRef.value
.validate()
.then(() => {
formRef.value.validate().then(() => {
moduleApi.submitForm(formData.value, !formData.value.id).then(() => {
onClose()
emit('successful')

View File

@ -143,15 +143,16 @@
//
const onSubmit = () => {
formRef.value
.validate()
.then(() => {
formRef.value.validate().then(() => {
const param = parameterChanges(formData.value)
submitLoading.value = true
spaApi.submitForm(param, !param.id).then(() => {
spaApi
.submitForm(param, !param.id)
.then(() => {
visible = false
emit('successful')
}).finally(() => {
})
.finally(() => {
submitLoading.value = false
})
})

View File

@ -102,9 +102,7 @@
})
//
const onSubmit = () => {
formRef.value
.validate()
.then(() => {
formRef.value.validate().then(() => {
submitLoading.value = true
roleApi
.submitForm(formData.value, !formData.value.id)

View File

@ -225,7 +225,7 @@
}
//
const handleResizeColumn = (w, col) => {
col.width = w;
col.width = w
}
//
const removeOrg = (record) => {

View File

@ -0,0 +1,337 @@
<template>
<a-drawer
title="授权权限"
:width="drawerWidth"
:visible="visible"
:destroy-on-close="true"
:show-pagination="false"
:body-style="{ paddingBottom: '80px' }"
:footer-style="{ textAlign: 'right' }"
@close="onClose"
>
<a-alert
message="注:此功能界面需要与代码查询条件配合使用,并非所有接口都需设置数据范围,多用于业务模块!"
type="warning"
closable
/>
<a-spin :spinning="spinningLoading">
<a-table
class="mt-4"
size="middle"
:columns="columns"
:data-source="loadDatas"
bordered
:row-key="(record) => record.api"
>
<template #headerCell="{ column }">
<template v-if="column.key === 'api'">
<a-checkbox @update:checked="(val) => onCheckAllChange(val)"> 接口 </a-checkbox>
</template>
</template>
<template #bodyCell="{ column, record }">
<template v-if="column.dataIndex === 'api'">
<a-checkbox :checked="record.check" @update:checked="(val) => changeApi(record, val)">
{{ record.api }}
</a-checkbox>
</template>
<template v-if="column.dataIndex === 'dataScope'">
<template v-if="record.dataScope.length > 0">
<template v-for="item in record.dataScope" :key="item.id + record.api">
<a-radio
v-model:checked="item.check"
:name="item.title"
@change="(evt) => changeDataScope(record, evt)"
>
<a-badge
v-if="
(item.value === 'SCOPE_ORG_DEFINE') &
record.dataScope[4].check &
(item.scopeDefineOrgIdList !== undefined)
"
:count="item.scopeDefineOrgIdList.length"
:number-style="{ backgroundColor: '#52c41a' }"
>
{{ item.title }}</a-badge
>
<div v-else>{{ item.title }}</div>
</a-radio>
</template>
<a-button v-if="record.dataScope[4].check" type="link" size="small" @click="handleDefineOrg(record)"
>选择机构</a-button
>
</template>
</template>
</template>
</a-table>
</a-spin>
<template #footer>
<a-button style="margin-right: 8px" @click="onClose"></a-button>
<a-button type="primary" :loading="submitLoading" @click="onSubmit"></a-button>
</template>
<ScopeDefineOrg ref="scopeDefineOrgModal" @click="scopeDefineOrgClick" />
</a-drawer>
</template>
<script setup name="grantResourceForm">
import userApi from '@/api/sys/userApi'
import roleApi from '@/api/sys/roleApi'
import ScopeDefineOrg from './scopeDefineOrg.vue'
let visible = ref(false)
const spinningLoading = ref(false)
const scopeDefineOrgModal = ref(null)
const emit = defineEmits({ successful: null })
const submitLoading = ref(false)
const CustomValue = 'SCOPE_ORG_DEFINE'
//
const drawerWidth = 1000
// 90%
//(window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth) * 0.9
let loadDatas = ref([])
const columns = [
{
key: 'api',
title: '接口',
dataIndex: 'api',
width: 380
},
{
key: 'dataScope',
title: '数据范围',
dataIndex: 'dataScope'
}
]
//
const loadData = async () => {
spinningLoading.value = true
const res = await roleApi.rolePermissionTreeSelector()
//
const param = {
id: grantPermissionParam.id
}
const resOwn = await userApi.userOwnPermission(param)
//
echoModuleData(res, resOwn)
spinningLoading.value = false
}
//
const echoModuleData = (res, resOwn) => {
res.forEach((api) => {
const obj = {
api: api,
dataScope: datascope(api),
check: false
}
if (resOwn.grantInfoList.length > 0) {
resOwn.grantInfoList.forEach((item) => {
if (item.apiUrl === subStrApi(api)) {
obj.check = true
// dataScopeInfo
obj.dataScope.forEach((o) => {
if (o.value === item.scopeCategory) {
o.check = true
//
if (item.scopeCategory === 'SCOPE_ORG_DEFINE') {
o.scopeDefineOrgIdList = item.scopeDefineOrgIdList
}
}
})
}
})
}
loadDatas.value.push(obj)
})
}
const datascope = (id) => {
return [
{
id: `SCOPE_ALL_${id}`,
title: '全部',
value: 'SCOPE_ALL',
check: false
},
{
id: `SCOPE_SELF_${id}`,
title: '仅自己',
value: 'SCOPE_SELF',
check: false
},
{
id: `SCOPE_ORG_${id}`,
title: '所属组织',
value: 'SCOPE_ORG',
check: false
},
{
id: `SCOPE_ORG_CHILD_${id}`,
title: '所属组织及以下',
value: 'SCOPE_ORG_CHILD',
check: false
},
{
id: `SCOPE_ORG_DEFINE_${id}`,
title: '自定义',
value: 'SCOPE_ORG_DEFINE',
check: false
}
]
}
//
const changeDataScope = (record, evt) => {
const name = evt.target.name
//
record.dataScope.forEach((item) => {
if (item.title !== name) {
item.check = false
}
})
changeChildCheckBox(record, evt)
}
//
const handleDefineOrg = (recordDataScope) => {
//
const data = recordDataScope.dataScope.find((f) => f.value === CustomValue)
//
if (data.check) {
// key
const checkKeysStr = recordDataScope.dataScope[4].scopeDefineOrgIdList
scopeDefineOrgModal.value.onOpen(data.id, checkKeysStr)
} else {
// ,
handleDatascope(false, record.id, null)
}
}
//
const scopeDefineOrgClick = (value) => {
handleDatascope(true, value.dataScopeId, value.defineOrgIdData.scopeDefineOrgIdList)
}
// Datascope
const handleDatascope = (check, id, orgData) => {
loadDatas.value.forEach((item) => {
if (id === 'SCOPE_ORG_DEFINE_' + item.api) {
item.dataScope.forEach((items) => {
if (items.value === 'SCOPE_ORG_DEFINE') {
if (check) {
items.scopeDefineOrgIdList = orgData
} else {
items.scopeDefineOrgIdList = []
}
}
})
}
})
}
//
const onOpen = (record) => {
grantPermissionParam.id = record.id
visible.value = true
loadData()
}
//
const onClose = () => {
//
loadDatas.value = []
visible.value = false
}
//
const onCheckAllChange = (value) => {
spinningLoading.value = true
loadDatas.value.forEach((data) => {
changeApi(data, value)
spinningLoading.value = false
})
}
//
const changeApi = (record, val) => {
record.check = val
if (val) {
let checkStatus = 0
for (let i = 0; i < record.dataScope.length; i++) {
if (record.dataScope[i].check) {
checkStatus++
}
}
if (checkStatus === 0) {
record.dataScope[0].check = true
}
} else {
//
record.dataScope.forEach((item) => {
item.check = false
if (item.value === 'SCOPE_ORG_DEFINE') {
item.scopeDefineOrgIdList = []
}
})
}
}
//
const changeChildCheckBox = (record, evt) => {
let checked = evt.target.checked
if (!checked) {
record.check = false
} else if (checked) {
record.check = checked
}
}
//
let grantPermissionParam = {
// id
id: '',
//
grantInfoList: []
}
//
const convertData = () => {
grantPermissionParam.grantInfoList = []
loadDatas.value.forEach((table) => {
if (table.check) {
table.dataScope.forEach((item) => {
if (item.check) {
const dataScopeInfo = {
apiUrl: subStrApi(table.api),
scopeCategory: item.value,
scopeDefineOrgIdList: item.scopeDefineOrgIdList === undefined ? [] : item.scopeDefineOrgIdList
}
grantPermissionParam.grantInfoList.push(dataScopeInfo)
}
})
}
})
return grantPermissionParam
}
// api
const subStrApi = (api) => {
return api.substring(0, api.indexOf('['))
}
//
const onSubmit = () => {
const param = convertData()
submitLoading.value = true
userApi
.userGrantPermission(param)
.then(() => {
onClose()
emit('successful')
})
.finally(() => {
submitLoading.value = false
})
}
//
defineExpose({
onOpen
})
</script>
<style scoped>
/* 重写复选框的样式 */
.ant-checkbox-wrapper {
margin-left: 0px !important;
padding-top: 2px !important;
padding-bottom: 2px !important;
}
</style>

View File

@ -0,0 +1,315 @@
<template>
<a-drawer
title="授权资源"
:width="drawerWidth"
:visible="visible"
:destroy-on-close="true"
:show-pagination="false"
:body-style="{ paddingBottom: '80px' }"
:footer-style="{ textAlign: 'right' }"
@close="onClose"
>
<a-spin :spinning="spinningLoading">
<a-radio-group v-model:value="moduleId" button-style="solid" style="padding-bottom: 10px">
<a-radio-button
:key="module.id"
v-for="module in echoDatalist"
:value="module.id"
@click="moduleClock(module.id)"
>
<component :is="module.icon" />
{{ module.title }}</a-radio-button
>
</a-radio-group>
<a-table size="middle" :columns="columns" :data-source="loadDatas" :pagination="false" bordered>
<template #bodyCell="{ column, record }">
<template v-if="column.dataIndex === 'parentName'">
<a-checkbox :checked="record.parentCheck" @update:checked="(val) => changeParent(record, val)">
{{ record.parentName }}
</a-checkbox>
</template>
<template v-if="column.dataIndex === 'title'">
<a-checkbox :checked="record.nameCheck" @update:checked="(val) => changeSub(record, val)">{{
record.title
}}</a-checkbox>
</template>
<template v-if="column.dataIndex === 'button'">
<template v-if="record.button.length > 0">
<template v-for="(item, index) in record.button" :key="item.id">
<a-checkbox v-model:checked="item.check" @change="(evt) => changeChildCheckBox(record, evt)">{{
item.title
}}</a-checkbox>
<br v-if="(index + 1) % 5 === 0" />
</template>
</template>
</template>
</template>
</a-table>
</a-spin>
<template #footer>
<a-button style="margin-right: 8px" @click="onClose"></a-button>
<a-button type="primary" :loading="submitLoading" @click="onSubmit"></a-button>
</template>
</a-drawer>
</template>
<script setup name="grantResourceForm">
import { nextTick } from 'vue'
import tool from '@/utils/tool'
import userApi from '@/api/sys/userApi'
import roleApi from '@/api/sys/roleApi'
import userCenterApi from '@/api/sys/userCenterApi'
const spinningLoading = ref(false)
let firstShowMap = $ref({})
const emit = defineEmits({ successful: null })
const submitLoading = ref(false)
//
const drawerWidth = 1000
// 90%
//(window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth) * 0.9
const columns = [
{
key: 'parentName',
title: '一级目录',
dataIndex: 'parentName',
customCell: (row, index) => {
const parentName = row.parentName
const indexArr = firstShowMap[parentName]
if (index === indexArr[0]) {
return { rowSpan: indexArr.length }
}
return { rowSpan: 0 }
},
width: 150
},
{
key: 'title',
title: '菜单',
dataIndex: 'title',
width: 200
},
{
key: 'button',
title: '按钮授权',
dataIndex: 'button'
}
]
const echoDatalist = ref([])
const moduleId = ref('')
const loadDatas = ref([])
//
const loadData = async () => {
// firstShowMap = {} //
//
if (echoDatalist.value.length > 0) {
let data = echoDatalist.value.find((f) => f.id === moduleId.value).menu
loadDatas.value = data
} else {
//
spinningLoading.value = true
const res = await roleApi.roleResourceTreeSelector()
const param = {
id: resultDataModel.id
}
//
const resEcho = await userApi.userOwnResource(param)
spinningLoading.value = false
echoDatalist.value = echoModuleData(res, resEcho)
moduleId.value = res[0].id
loadDatas.value = echoDatalist.value[0].menu
}
}
const checkFieldKeys = ['button']
let visible = $ref(false)
//
let resultDataModel = {
id: '',
grantInfoList: []
}
//
const onOpen = (record) => {
resultDataModel.id = record.id
visible = true
firstShowMap = {}
loadData()
}
//
const echoModuleData = (data, resEcho) => {
//
data.forEach((module) => {
if (module.menu) {
//
module.menu.forEach((item) => {
const menueCheck = ref(0)
if (resEcho.grantInfoList.length > 0) {
resEcho.grantInfoList.forEach((grant) => {
if (item.id === grant.menuId) {
menueCheck.value++
//
if (grant.buttonInfo.length > 0) {
grant.buttonInfo.forEach((button) => {
item.button.forEach((itemButton) => {
if (button === itemButton.id) {
itemButton.check = true
}
})
})
}
}
})
}
// 2
if (menueCheck.value > 0) {
item.parentCheck = true
item.nameCheck = true
}
})
//
module.menu = module.menu.sort((a, b) => {
return a.parentId - b.parentId
})
//
module.menu.forEach((item, index) => {
//
if (firstShowMap[item.parentName]) {
firstShowMap[item.parentName].push(index)
} else {
firstShowMap[item.parentName] = [index]
}
})
}
})
return data
}
//
const moduleClock = (value) => {
moduleId.value = value
loadData()
}
//
const handleOnlySelf = (record, key, val) => {
record[key].forEach((item) => {
// 'button'
item.check = val
})
}
const checkAllChildNotChecked = (record) => {
const allChecked = checkFieldKeys.every((key) => {
//
const child = record[key]
return child.every((field) => !field.check)
})
return allChecked
}
const changeChildCheckBox = (record, evt) => {
let checked = evt.target.checked
if (!checked && checkAllChildNotChecked(record)) {
//
/*record.nameCheck = false
record.parentCheck = false*/
} else if (checked) {
record.nameCheck = checked
record.parentCheck = checked
}
}
//
const changeSub = (record, val) => {
//
record.nameCheck = val
checkFieldKeys.forEach((key) => {
//
handleOnlySelf(record, key, val)
})
}
//
const changeParent = (record, val) => {
record.parentCheck = val
// id
const moduleMenu = echoDatalist.value.find((f) => record.module === f.id)
const parentName = record.parentName
//
const indexArr = firstShowMap[parentName]
indexArr.forEach((indexItem) => {
//
const row = moduleMenu.menu[indexItem]
//
changeSub(row, val)
})
}
//
const onClose = () => {
//
echoDatalist.value = []
moduleId.value = ''
loadDatas.value = []
firstShowMap = {}
visible = false
}
//
const convertData = () => {
resultDataModel.grantInfoList = []
echoDatalist.value.forEach((table) => {
if (table.menu) {
table.menu.forEach((item) => {
const grantInfo = {
menuId: '',
buttonInfo: []
}
if (item.nameCheck) {
grantInfo.menuId = item.id
item.button.forEach((button) => {
if (button.check) {
grantInfo.buttonInfo.push(button.id)
}
})
resultDataModel.grantInfoList.push(grantInfo)
}
})
}
})
return resultDataModel
}
//
const onSubmit = () => {
const param = convertData()
submitLoading.value = true
userApi
.userGrantResource(param)
.then(() => {
onClose()
emit('successful')
refreshCacheMenu()
})
.finally(() => {
submitLoading.value = false
})
}
//
const refreshCacheMenu = () => {
nextTick(() => {
userCenterApi.userLoginMenu().then((res) => {
tool.data.set('MENU', res)
})
})
}
//
defineExpose({
onOpen
})
</script>
<style scoped>
/* 重写复选框的样式 */
.ant-checkbox-wrapper {
margin-left: 0px !important;
padding-top: 2px !important;
padding-bottom: 2px !important;
}
</style>

View File

@ -0,0 +1,112 @@
<template>
<a-drawer
title="导入导出"
:width="620"
:visible="visible"
:destroy-on-close="true"
:footer-style="{ textAlign: 'right' }"
@close="onClose"
>
<span
>导入数据格式严格按照系统模板进行数据录入请点击
<a-button type="primary" size="small" @click="downloadImportUserTemplate"></a-button>
</span>
<a-divider dashed />
<div>
<a-spin :spinning="impUploadLoading">
<a-upload-dragger :show-upload-list="false" :custom-request="customRequestLocal">
<p class="ant-upload-drag-icon">
<inbox-outlined></inbox-outlined>
</p>
<p class="ant-upload-text">单击或拖动文件到此区域进行上传</p>
<p class="ant-upload-hint">仅支持xlsxlsx格式文件</p>
</a-upload-dragger>
</a-spin>
</div>
<a-alert v-if="impAlertStatus" type="info" :show-icon="false" banner closable @close="onImpClose" class="mt-3">
<template #description>
<p>导入总数{{ impResultData.totalCount }} </p>
<p>导入成功{{ impResultData.successCount }} </p>
<div v-if="impResultData.errorCount > 0">
<p><span style="color: red">失败条数</span>{{ impResultData.errorCount }} </p>
<a-table :dataSource="impResultErrorDataSource" :columns="impErrorColumns" size="small" />
</div>
</template>
</a-alert>
</a-drawer>
</template>
<script setup name="userImpExp">
import userApi from '@/api/sys/userApi'
const impUploadLoading = ref(false)
const impAlertStatus = ref(false)
const impResultData = ref({})
const impResultErrorDataSource = ref([])
//
const customRequestLocal = (data) => {
impUploadLoading.value = true
const fileData = new FormData()
fileData.append('file', data.file)
return userApi
.userImport(fileData)
.then((res) => {
impAlertStatus.value = true
impResultData.value = res
impResultErrorDataSource.value = res.errorDetail
})
.finally(() => {
impUploadLoading.value = false
})
}
//
const onImpClose = () => {
impAlertStatus.value = false
}
const impErrorColumns = [
{
title: '索引',
dataIndex: 'index',
width: '80px'
},
{
title: '原因',
dataIndex: 'msg'
}
]
// emit
const emit = defineEmits({ successful: null })
//
let visible = ref(false)
const submitLoading = ref(false)
//
const onOpen = () => {
visible.value = true
}
//
const onClose = () => {
visible.value = false
//
onImpClose()
}
//
const downloadImportUserTemplate = () => {
userApi.userDownloadImportUserTemplate().then((res) => {
const blob = new Blob([res.data], { type: 'application/octet-stream;charset=UTF-8' })
const contentDisposition = res.headers['content-disposition']
const patt = new RegExp('filename=([^;]+\\.[^\\.;]+);*')
const $link = document.createElement('a')
$link.href = URL.createObjectURL(blob)
$link.download = decodeURIComponent(patt.exec(contentDisposition)[1])
$link.click()
document.body.appendChild($link)
document.body.removeChild($link) //
window.URL.revokeObjectURL($link.href) // blob
})
}
//
defineExpose({
onOpen
})
</script>

View File

@ -14,6 +14,36 @@
</a-card>
</a-col>
<a-col :span="19">
<a-card :bordered="false" style="margin-bottom: 10px">
<a-form ref="searchFormRef" name="advanced_search" class="ant-advanced-search-form" :model="searchFormState">
<a-row :gutter="24">
<a-col :span="8">
<a-form-item name="searchKey" :label="$t('common.searchKey')">
<a-input v-model:value="searchFormState.searchKey" placeholder="请输入姓名或账号关键词"></a-input>
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item name="userStatus" :label="$t('user.userStatus')">
<a-select v-model:value="searchFormState.userStatus" placeholder="请选择状态">
<a-select-option v-for="item in statusData" :key="item.dictValue" :value="item.dictValue">{{
item.name
}}</a-select-option>
</a-select>
</a-form-item>
</a-col>
<a-col :span="8">
<a-button type="primary" @click="table.refresh(true)">
<template #icon><SearchOutlined /></template>
{{ $t('common.searchButton') }}
</a-button>
<a-button class="snowy-buttom-left" @click="() => searchFormRef.resetFields()">
<template #icon><redo-outlined /></template>
{{ $t('common.resetButton') }}
</a-button>
</a-col>
</a-row>
</a-form>
</a-card>
<a-card :bordered="false">
<s-table
ref="table"
@ -26,43 +56,18 @@
:row-selection="options.rowSelection"
>
<template #operator class="table-operator">
<a-form
ref="searchFormRef"
name="advanced_search"
class="ant-advanced-search-form"
:model="searchFormState"
>
<a-row :gutter="24">
<a-col :span="6">
<a-form-item name="searchKey">
<a-input v-model:value="searchFormState.searchKey" placeholder="请输入姓名或账号"></a-input>
</a-form-item>
</a-col>
<a-col :span="6">
<a-form-item name="userStatus">
<a-select v-model:value="searchFormState.userStatus" placeholder="请选择状态">
<a-select-option v-for="item in statusData" :key="item.dictValue" :value="item.dictValue">{{
item.name
}}</a-select-option>
</a-select>
</a-form-item>
</a-col>
<a-col :span="6">
<a-button type="primary" @click="table.refresh(true)">{{ $t('common.searchButton') }}</a-button>
<a-button class="snowy-buttom-left" @click="() => searchFormRef.resetFields()">{{
$t('common.resetButton')
}}</a-button>
</a-col>
<a-col :span="6">
<a-button type="primary" class="primaryAdd" @click="form.onOpen()">
<template #icon><plus-outlined /></template>
<span>{{ $t('common.addButton') }}{{ $t('model.user') }}</span>
</a-button>
<a-button danger @click="removeBatchUser()">{{
$t('common.batchRemoveButton')
}}</a-button>
</a-col>
</a-row>
</a-form>
<a-button class="primaryAdd" @click="ImpExpRef.onOpen()">
<template #icon><import-outlined /></template>
<span>{{ $t('common.imports') }}</span>
</a-button>
<a-button danger @click="removeBatchUser()">
<template #icon><delete-outlined /></template>
{{ $t('common.batchRemoveButton') }}
</a-button>
</template>
<template #bodyCell="{ column, record }">
<template v-if="column.dataIndex === 'avatar'">
@ -72,26 +77,44 @@
{{ $TOOL.dictTypeData('GENDER', record.gender) }}
</template>
<template v-if="column.dataIndex === 'userStatus'">
<a-switch
:loading="loading"
:checked="record.userStatus === 'ENABLE'"
@change="editStatus(record)"
/>
<a-switch :loading="loading" :checked="record.userStatus === 'ENABLE'" @change="editStatus(record)" />
</template>
<template v-if="column.dataIndex === 'action'">
<a @click="form.onOpen(record)">{{ $t('common.editButton') }}</a>
<a-divider type="vertical" />
<a @click="selectRole(record)"></a>
<a-divider type="vertical" />
<a-popconfirm title="确定重置此用户密码?" @confirm="resetPassword(record)">
<a>重置密码</a>
<a-popconfirm title="确定要删除此用户吗?" placement="topRight" @confirm="removeUser(record)">
<a-button type="link" danger size="small">
{{ $t('common.removeButton') }}
</a-button>
</a-popconfirm>
<a-divider type="vertical" />
<a-popconfirm title="确定要删除此用户吗?" @confirm="removeUser(record)">
<a-button type="link" danger size="small">{{
$t('common.removeButton')
}}</a-button>
<a-dropdown>
<a class="ant-dropdown-link">
{{ $t('common.more') }}
<DownOutlined />
</a>
<template #overlay>
<a-menu>
<a-menu-item>
<a-popconfirm title="确定重置此用户密码?" placement="topRight" @confirm="resetPassword(record)">
<a>{{ $t('user.resetPassword') }}</a>
</a-popconfirm>
</a-menu-item>
<a-menu-item>
<a @click="selectRole(record)"></a>
</a-menu-item>
<a-menu-item>
<a @click="grantResourceFormRef.onOpen(record)"></a>
</a-menu-item>
<a-menu-item>
<a @click="grantPermissionFormRef.onOpen(record)"></a>
</a-menu-item>
<a-menu-item>
<a @click="exportUserInfo(record)"></a>
</a-menu-item>
</a-menu>
</template>
</a-dropdown>
</template>
</template>
</s-table>
@ -105,14 +128,20 @@
org-url="/sys/user/orgTreeSelector"
@onBack="roleBack"
/>
<ImpExp ref="ImpExpRef" />
<grantResourceForm ref="grantResourceFormRef" @successful="table.refresh(true)" />
<grantPermissionForm ref="grantPermissionFormRef" @successful="table.refresh(true)" />
</template>
<script setup name="sysUser">
import { message, Empty } from 'ant-design-vue'
import { getCurrentInstance } from 'vue'
import tool from '@/utils/tool'
import userApi from '@/api/sys/userApi'
import roleSelectorPlus from '@/components/Selector/roleSelectorPlus.vue'
import Form from './form.vue'
import ImpExp from './impExp.vue'
import grantResourceForm from './grantResourceForm.vue'
import grantPermissionForm from './grantPermissionForm.vue'
const columns = [
{
@ -159,11 +188,10 @@
title: '操作',
dataIndex: 'action',
align: 'center',
width: '240px'
width: '220px'
}
]
const { proxy } = getCurrentInstance()
const statusData = proxy.$TOOL.dictTypeList('COMMON_STATUS')
const statusData = tool.dictTypeList('COMMON_STATUS')
const searchFormRef = ref()
let defaultExpandedKeys = ref([])
let searchFormState = reactive({})
@ -172,11 +200,13 @@
let selectedRowKeys = ref([])
const treeFieldNames = { children: 'children', title: 'name', key: 'id' }
let form = ref(null)
let RoleSelector = ref()
let RoleSelectorPlus = ref()
const selectedRecord = ref({})
const loading = ref(false)
const cardLoading = ref(true)
const ImpExpRef = ref()
const grantResourceFormRef = ref()
const grantPermissionFormRef = ref()
// Promise
const loadData = (parameter) => {
@ -304,6 +334,24 @@
const resetPassword = (record) => {
userApi.userResetPassword(record).then(() => {})
}
//
const exportUserInfo = (record) => {
const params = {
id: record.id
}
userApi.userExportUserInfo(params).then((res) => {
const blob = new Blob([res.data], { type: 'application/octet-stream;charset=UTF-8' })
const contentDisposition = res.headers['content-disposition']
const patt = new RegExp('filename=([^;]+\\.[^\\.;]+);*')
const $link = document.createElement('a')
$link.href = URL.createObjectURL(blob)
$link.download = decodeURIComponent(patt.exec(contentDisposition)[1])
$link.click()
document.body.appendChild($link)
document.body.removeChild($link) //
window.URL.revokeObjectURL($link.href) // blob
})
}
</script>
<style scoped>

View File

@ -0,0 +1,112 @@
<template>
<a-modal
v-model:visible="visible"
title="选择机构"
:width="400"
:mask-closable="false"
:destroy-on-close="true"
@ok="handleOk"
@cancel="onClose"
>
<div class="scopeDefineOrgTreeDiv">
<a-tree
v-model:expandedKeys="defaultExpandedKeys"
v-model:checkedKeys="checkedKeys"
:tree-data="treeData"
:field-names="treeFieldNames"
checkable
:selectable="false"
@check="treeCheck"
>
</a-tree>
</div>
</a-modal>
</template>
<script setup="props, context" name="userScopeDefineOrg">
import userApi from '@/api/sys/userApi'
const visible = ref(false)
let defaultExpandedKeys = ref([])
let checkedKeys = ref([])
const treeData = ref([])
const resultDataModel = {
dataScopeId: '',
defineOrgIdData: {
scopeCategory: 'SCOPE_ORG_DEFINE',
scopeDefineOrgIdList: []
}
}
// id
const onOpen = (id, checkKeys) => {
visible.value = true
resultDataModel.dataScopeId = id
// const treeData = data.data;
userApi.userOrgTreeSelector().then((res) => {
if (res !== null) {
treeData.value = res
//
echoOrgSelectKeys(checkKeys)
// 2
treeData.value.forEach((item) => {
// 0
if (item.parentId === '0') {
defaultExpandedKeys.value.push(item.id)
// ID
if (item.children) {
item.children.forEach((items) => {
defaultExpandedKeys.value.push(items.id)
})
}
}
})
}
})
}
const onClose = () => {
visible.value = false
}
//
const echoOrgSelectKeys = (checkKeys) => {
checkedKeys.value = []
if (checkKeys && checkKeys.length > 0) {
checkKeys
.toString()
.split(',')
.forEach((key) => {
checkedKeys.value.push(key)
})
}
}
// treeNode title,key,children
const treeFieldNames = { children: 'children', title: 'name', key: 'id' }
//
const treeCheck = (checkedKeys) => {
resultDataModel.defineOrgIdData.scopeDefineOrgIdList = checkedKeys
}
// emit
const emit = defineEmits({
click: null
})
const handleOk = () => {
emit('click', resultDataModel)
visible.value = false
}
defineExpose({
onOpen
})
</script>
<style lang="less">
// 穿
.ant-transfer-list {
width: 220px !important;
}
.scopeDefineOrgTreeDiv {
max-height: 450px;
overflow: auto;
}
</style>

View File

@ -64,7 +64,7 @@
<script setup>
import { onMounted } from 'vue'
import { useRoute } from 'vue-router';
import { useRoute } from 'vue-router'
import tool from '@/utils/tool'
import store from '@/store'
import userCenterApi from '@/api/sys/userCenterApi'
@ -108,12 +108,12 @@
const onTabChange = (key) => {
noTitleKey.value = key
}
const Route = useRoute();
const Route = useRoute()
onMounted(() => {
if (Route.query.tab) {
noTitleKey.value = Route.query.tab
}
});
})
//
const cropUploadSuccess = (data) => {
// file