From 7d84f860819d66290ca8d0156e370f0690aba698 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Fri, 31 Mar 2023 13:40:57 +0800 Subject: [PATCH] =?UTF-8?q?REVIEW=20=E7=94=A8=E6=88=B7=E7=AE=A1=E7=90=86?= =?UTF-8?q?=EF=BC=88=E5=88=86=E9=85=8D=E7=94=A8=E6=88=B7=E8=A7=92=E8=89=B2?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/system/permission/index.ts | 4 +- src/api/system/user/index.ts | 4 +- src/views/system/user/UserAssignRoleForm.vue | 93 +++++++++++++ .../user/components/UserAssignRoleForm.vue | 108 --------------- src/views/system/user/index.vue | 123 +++++++++--------- 5 files changed, 157 insertions(+), 175 deletions(-) create mode 100644 src/views/system/user/UserAssignRoleForm.vue delete mode 100644 src/views/system/user/components/UserAssignRoleForm.vue diff --git a/src/api/system/permission/index.ts b/src/api/system/permission/index.ts index c529f884..6e2adcdf 100644 --- a/src/api/system/permission/index.ts +++ b/src/api/system/permission/index.ts @@ -32,11 +32,11 @@ export const assignRoleDataScopeApi = async (data: PermissionAssignRoleDataScope } // 查询用户拥有的角色数组 -export const listUserRolesApi = async (userId: number) => { +export const getUserRoleList = async (userId: number) => { return await request.get({ url: '/system/permission/list-user-roles?userId=' + userId }) } // 赋予用户角色 -export const assignUserRoleApi = async (data: PermissionAssignUserRoleReqVO) => { +export const assignUserRole = async (data: PermissionAssignUserRoleReqVO) => { return await request.post({ url: '/system/permission/assign-user-role', data }) } diff --git a/src/api/system/user/index.ts b/src/api/system/user/index.ts index 3ae4928c..90b07fe5 100644 --- a/src/api/system/user/index.ts +++ b/src/api/system/user/index.ts @@ -53,7 +53,7 @@ export const importUserTemplateApi = () => { } // 用户密码重置 -export const resetUserPwdApi = (id: number, password: string) => { +export const resetUserPwd = (id: number, password: string) => { const data = { id, password @@ -62,7 +62,7 @@ export const resetUserPwdApi = (id: number, password: string) => { } // 用户状态修改 -export const updateUserStatusApi = (id: number, status: number) => { +export const updateUserStatus = (id: number, status: number) => { const data = { id, status diff --git a/src/views/system/user/UserAssignRoleForm.vue b/src/views/system/user/UserAssignRoleForm.vue new file mode 100644 index 00000000..2dc04e52 --- /dev/null +++ b/src/views/system/user/UserAssignRoleForm.vue @@ -0,0 +1,93 @@ + + diff --git a/src/views/system/user/components/UserAssignRoleForm.vue b/src/views/system/user/components/UserAssignRoleForm.vue deleted file mode 100644 index bbf37739..00000000 --- a/src/views/system/user/components/UserAssignRoleForm.vue +++ /dev/null @@ -1,108 +0,0 @@ - - - diff --git a/src/views/system/user/index.vue b/src/views/system/user/index.vue index cdd47436..e57a62b4 100644 --- a/src/views/system/user/index.vue +++ b/src/views/system/user/index.vue @@ -193,13 +193,10 @@ import { DICT_TYPE, getIntDictOptions } from '@/utils/dict' import { dateFormatter } from '@/utils/formatTime' import download from '@/utils/download' import { CommonStatusEnum } from '@/utils/constants' - -import { resetUserPwdApi, updateUserStatusApi, UserVO } from '@/api/system/user' import * as UserApi from '@/api/system/user' - import UserForm from './components/UserForm.vue' import UserImportForm from './components/UserImportForm.vue' -import UserAssignRoleForm from './components/UserAssignRoleForm.vue' +import UserAssignRoleForm from './UserAssignRoleForm.vue' import DeptTree from './DeptTree.vue' const message = useMessage() // 消息弹窗 const { t } = useI18n() // 国际化 @@ -260,54 +257,21 @@ const handleImport = () => { importFormRef.value?.openForm() } -// 操作分发 -const handleCommand = (command: string, index: number, row: UserApi.UserVO) => { - console.log(index) - switch (command) { - case 'handleDelete': - handleDelete(row.id) - break - case 'handleResetPwd': - handleResetPwd(row) - break - case 'handleRole': - handleRole(row) - break - default: - break - } -} - -// 用户状态修改 -const handleStatusChange = (row: UserVO) => { - let text = row.status === CommonStatusEnum.ENABLE ? '启用' : '停用' - message - .confirm('确认要"' + text + '""' + row.username + '"用户吗?', t('common.reminder')) - .then(async () => { - row.status = - row.status === CommonStatusEnum.ENABLE ? CommonStatusEnum.ENABLE : CommonStatusEnum.DISABLE - await updateUserStatusApi(row.id, row.status) - message.success(text + '成功') - // 刷新列表 - getList() - }) - .catch(() => { - row.status = - row.status === CommonStatusEnum.ENABLE ? CommonStatusEnum.DISABLE : CommonStatusEnum.ENABLE - }) -} - -/** 删除按钮操作 */ -const handleDelete = async (id: number) => { +/** 修改用户状态 */ +const handleStatusChange = async (row: UserApi.UserVO) => { try { - // 删除的二次确认 - await message.delConfirm() - // 发起删除 - await UserApi.deleteUser(id) - message.success(t('common.delSuccess')) + // 修改状态的二次确认 + const text = row.status === CommonStatusEnum.ENABLE ? '启用' : '停用' + await message.confirm('确认要"' + text + '""' + row.username + '"用户吗?') + // 发起修改状态 + await UserApi.updateUserStatus(row.id, row.status) // 刷新列表 await getList() - } catch {} + } catch { + // 取消后,进行恢复按钮 + row.status = + row.status === CommonStatusEnum.ENABLE ? CommonStatusEnum.DISABLE : CommonStatusEnum.ENABLE + } } /** 导出按钮操作 */ @@ -326,23 +290,56 @@ const handleExport = async () => { } } -// 重置密码 -const handleResetPwd = (row: UserVO) => { - message - .prompt('请输入"' + row.username + '"的新密码', t('common.reminder')) - .then(async ({ value }) => { - await resetUserPwdApi(row.id, value) - message.success('修改成功,新密码是:' + value) - }) - .catch((e) => { - console.error(e) - }) +/** 操作分发 */ +const handleCommand = (command: string, index: number, row: UserApi.UserVO) => { + console.log(index) + switch (command) { + case 'handleDelete': + handleDelete(row.id) + break + case 'handleResetPwd': + handleResetPwd(row) + break + case 'handleRole': + handleRole(row) + break + default: + break + } } -// 分配角色 +/** 删除按钮操作 */ +const handleDelete = async (id: number) => { + try { + // 删除的二次确认 + await message.delConfirm() + // 发起删除 + await UserApi.deleteUser(id) + message.success(t('common.delSuccess')) + // 刷新列表 + await getList() + } catch {} +} + +/** 重置密码 */ +const handleResetPwd = async (row: UserApi.UserVO) => { + try { + // 重置的二次确认 + const result = await message.prompt( + '请输入"' + row.username + '"的新密码', + t('common.reminder') + ) + const password = result.value + // 发起重置 + await UserApi.resetUserPwd(row.id, password) + message.success('修改成功,新密码是:' + password) + } catch {} +} + +/** 分配角色 */ const assignRoleFormRef = ref() -const handleRole = (row: UserVO) => { - assignRoleFormRef.value?.openForm(row) +const handleRole = (row: UserApi.UserVO) => { + assignRoleFormRef.value.open(row) } /** 初始化 */