FlowVue/src/views/system/user/index.vue

360 lines
11 KiB
Vue
Raw Normal View History

<template>
<doc-alert title="用户体系" url="https://doc.iocoder.cn/user-center/" />
<doc-alert title="三方登陆" url="https://doc.iocoder.cn/social-user/" />
<doc-alert title="Excel 导入导出" url="https://doc.iocoder.cn/excel-import-and-export/" />
2023-03-30 22:59:29 +08:00
<el-row :gutter="20">
2023-03-31 07:54:33 +08:00
<!-- 左侧部门树 -->
2023-03-30 22:59:29 +08:00
<el-col :span="4" :xs="24">
<ContentWrap class="h-1/1">
2023-03-31 07:54:33 +08:00
<DeptTree @node-click="handleDeptNodeClick" />
</ContentWrap>
2023-03-30 22:59:29 +08:00
</el-col>
<el-col :span="20" :xs="24">
2023-03-31 07:54:33 +08:00
<!-- 搜索 -->
<ContentWrap>
2023-03-30 22:59:29 +08:00
<el-form
2023-03-31 07:54:33 +08:00
class="-mb-15px"
2023-03-30 22:59:29 +08:00
:model="queryParams"
ref="queryFormRef"
:inline="true"
label-width="68px"
>
<el-form-item label="用户名称" prop="username">
<el-input
v-model="queryParams.username"
placeholder="请输入用户名称"
clearable
@keyup.enter="handleQuery"
2023-03-31 07:54:33 +08:00
class="!w-240px"
/>
2023-03-30 22:59:29 +08:00
</el-form-item>
<el-form-item label="手机号码" prop="mobile">
<el-input
v-model="queryParams.mobile"
placeholder="请输入手机号码"
clearable
@keyup.enter="handleQuery"
2023-03-31 07:54:33 +08:00
class="!w-240px"
/>
2023-03-30 22:59:29 +08:00
</el-form-item>
<el-form-item label="状态" prop="status">
<el-select
v-model="queryParams.status"
placeholder="用户状态"
clearable
2023-03-31 07:54:33 +08:00
class="!w-240px"
2023-03-30 22:59:29 +08:00
>
<el-option
v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
:key="dict.value"
:label="dict.label"
:value="dict.value"
/>
</el-select>
</el-form-item>
<el-form-item label="创建时间" prop="createTime">
<el-date-picker
v-model="queryParams.createTime"
value-format="YYYY-MM-DD HH:mm:ss"
type="datetimerange"
start-placeholder="开始日期"
end-placeholder="结束日期"
2023-03-31 07:54:33 +08:00
class="!w-240px"
/>
2023-03-30 22:59:29 +08:00
</el-form-item>
<el-form-item>
2023-03-31 07:54:33 +08:00
<el-button @click="handleQuery"><Icon icon="ep:search" />搜索</el-button>
2023-03-30 22:59:29 +08:00
<el-button @click="resetQuery"><Icon icon="ep:refresh" />重置</el-button>
<el-button
2023-03-31 07:54:33 +08:00
type="primary"
plain
@click="openForm('create')"
v-hasPermi="['system:user:create']"
>
2023-03-31 07:54:33 +08:00
<Icon icon="ep:plus" /> 新增
</el-button>
<el-button
type="warning"
plain
@click="handleImport"
v-hasPermi="['system:user:import']"
>
2023-03-30 22:59:29 +08:00
<Icon icon="ep:upload" /> 导入
</el-button>
<el-button
type="success"
2023-03-31 07:54:33 +08:00
plain
2023-03-30 22:59:29 +08:00
@click="handleExport"
:loading="exportLoading"
v-hasPermi="['system:user:export']"
>
2023-03-30 22:59:29 +08:00
<Icon icon="ep:download" />导出
</el-button>
</el-form-item>
</el-form>
</ContentWrap>
<ContentWrap>
2023-03-31 07:54:33 +08:00
<el-table v-loading="loading" :data="list">
<el-table-column label="用户编号" align="center" key="id" prop="id" />
2023-03-30 22:59:29 +08:00
<el-table-column
label="用户名称"
align="center"
prop="username"
:show-overflow-tooltip="true"
/>
<el-table-column
label="用户昵称"
align="center"
prop="nickname"
:show-overflow-tooltip="true"
/>
<el-table-column
label="部门"
align="center"
key="deptName"
prop="dept.name"
:show-overflow-tooltip="true"
/>
2023-03-31 07:54:33 +08:00
<el-table-column label="手机号码" align="center" prop="mobile" width="120" />
<el-table-column label="状态" key="status">
2023-03-30 22:59:29 +08:00
<template #default="scope">
<el-switch
v-model="scope.row.status"
:active-value="0"
:inactive-value="1"
@change="handleStatusChange(scope.row)"
/>
</template>
</el-table-column>
<el-table-column
label="创建时间"
align="center"
prop="createTime"
2023-03-31 07:54:33 +08:00
:formatter="dateFormatter"
width="180"
/>
<el-table-column label="操作" align="center" width="160">
2023-03-30 22:59:29 +08:00
<template #default="scope">
<div class="flex justify-center items-center">
<el-button
type="primary"
link
2023-03-31 07:54:33 +08:00
@click="openForm('update', scope.row.id)"
2023-03-30 22:59:29 +08:00
v-hasPermi="['system:user:update']"
>
2023-03-31 07:54:33 +08:00
<Icon icon="ep:edit" />修改
</el-button>
2023-03-30 22:59:29 +08:00
<el-dropdown
2023-04-01 09:14:59 +08:00
@command="(command) => handleCommand(command, scope.row)"
2023-03-30 22:59:29 +08:00
v-hasPermi="[
'system:user:delete',
'system:user:update-password',
'system:permission:assign-user-role'
]"
>
2023-03-31 07:54:33 +08:00
<el-button type="primary" link><Icon icon="ep:d-arrow-right" /> 更多</el-button>
2023-03-30 22:59:29 +08:00
<template #dropdown>
<el-dropdown-menu>
2023-04-01 09:14:59 +08:00
<el-dropdown-item
command="handleDelete"
v-if="checkPermi(['system:user:delete'])"
>
<Icon icon="ep:delete" />删除
</el-dropdown-item>
<el-dropdown-item
command="handleResetPwd"
v-if="checkPermi(['system:user:update-password'])"
>
<Icon icon="ep:key" />重置密码
</el-dropdown-item>
<el-dropdown-item
command="handleRole"
v-if="checkPermi(['system:permission:assign-user-role'])"
>
<Icon icon="ep:circle-check" />分配角色
</el-dropdown-item>
2023-03-30 22:59:29 +08:00
</el-dropdown-menu>
</template>
</el-dropdown>
</div>
</template>
</el-table-column>
</el-table>
2023-03-31 07:54:33 +08:00
<Pagination
2023-03-30 22:59:29 +08:00
:total="total"
v-model:page="queryParams.pageNo"
v-model:limit="queryParams.pageSize"
@pagination="getList"
/>
</ContentWrap>
2023-03-30 22:59:29 +08:00
</el-col>
</el-row>
<!-- 添加或修改用户对话框 -->
2023-03-31 07:54:33 +08:00
<UserForm ref="formRef" @success="getList" />
2023-03-30 22:59:29 +08:00
<!-- 用户导入对话框 -->
2023-03-31 07:54:33 +08:00
<UserImportForm ref="importFormRef" @success="getList" />
2023-03-30 22:59:29 +08:00
<!-- 分配角色 -->
2023-03-31 07:54:33 +08:00
<UserAssignRoleForm ref="assignRoleFormRef" @success="getList" />
2023-03-21 23:33:40 +08:00
</template>
<script setup lang="ts" name="User">
2023-03-29 22:07:53 +08:00
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
2023-04-01 09:14:59 +08:00
import { checkPermi } from '@/utils/permission'
2023-03-31 07:54:33 +08:00
import { dateFormatter } from '@/utils/formatTime'
import download from '@/utils/download'
2023-03-29 22:07:53 +08:00
import { CommonStatusEnum } from '@/utils/constants'
2023-03-31 07:54:33 +08:00
import * as UserApi from '@/api/system/user'
2023-03-31 23:34:19 +08:00
import UserForm from './UserForm.vue'
2023-04-01 00:04:28 +08:00
import UserImportForm from './UserImportForm.vue'
import UserAssignRoleForm from './UserAssignRoleForm.vue'
2023-03-31 07:54:33 +08:00
import DeptTree from './DeptTree.vue'
const message = useMessage() // 消息弹窗
const { t } = useI18n() // 国际化
2023-03-31 07:54:33 +08:00
const loading = ref(true) // 列表的加载中
const total = ref(0) // 列表的总页数
const list = ref([]) // 列表的数
const queryParams = reactive({
pageNo: 1,
pageSize: 10,
username: undefined,
mobile: undefined,
status: undefined,
deptId: undefined,
createTime: []
})
2023-03-31 07:54:33 +08:00
const queryFormRef = ref() // 搜索的表单
2023-03-30 22:59:29 +08:00
/** 查询列表 */
2023-03-31 07:54:33 +08:00
const getList = async () => {
loading.value = true
2023-03-31 07:54:33 +08:00
try {
const data = await UserApi.getUserPage(queryParams.value)
list.value = data.list
total.value = data.total
} finally {
loading.value = false
2023-03-31 07:54:33 +08:00
}
}
2023-03-30 22:59:29 +08:00
/** 搜索按钮操作 */
const handleQuery = () => {
queryParams.pageNo = 1
getList()
}
/** 重置按钮操作 */
const resetQuery = () => {
queryFormRef.value?.resetFields()
handleQuery()
}
2023-03-31 07:54:33 +08:00
/** 处理部门被点击 */
const handleDeptNodeClick = async (row) => {
queryParams.deptId = row.id
await getList()
}
2023-03-31 07:54:33 +08:00
/** 添加/修改操作 */
const formRef = ref()
const openForm = (type: string, id?: number) => {
formRef.value.open(type, id)
}
2023-04-01 00:04:28 +08:00
/** 用户导入 */
2023-03-31 07:54:33 +08:00
const importFormRef = ref()
const handleImport = () => {
2023-04-01 00:04:28 +08:00
importFormRef.value.open()
}
/** 修改用户状态 */
const handleStatusChange = async (row: UserApi.UserVO) => {
try {
// 修改状态的二次确认
const text = row.status === CommonStatusEnum.ENABLE ? '启用' : '停用'
await message.confirm('确认要"' + text + '""' + row.username + '"用户吗?')
// 发起修改状态
await UserApi.updateUserStatus(row.id, row.status)
// 刷新列表
await getList()
} catch {
// 取消后,进行恢复按钮
row.status =
row.status === CommonStatusEnum.ENABLE ? CommonStatusEnum.DISABLE : CommonStatusEnum.ENABLE
}
}
/** 导出按钮操作 */
const exportLoading = ref(false)
const handleExport = async () => {
try {
// 导出的二次确认
await message.exportConfirm()
// 发起导出
exportLoading.value = true
const data = await UserApi.exportUser(queryParams)
download.excel(data, '用户数据.xls')
} catch {
} finally {
exportLoading.value = false
}
}
/** 操作分发 */
2023-04-01 09:14:59 +08:00
const handleCommand = (command: string, row: UserApi.UserVO) => {
switch (command) {
case 'handleDelete':
2023-03-31 07:54:33 +08:00
handleDelete(row.id)
break
case 'handleResetPwd':
handleResetPwd(row)
break
case 'handleRole':
handleRole(row)
break
default:
break
}
}
2023-03-31 07:54:33 +08:00
/** 删除按钮操作 */
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) => {
2023-03-31 07:54:33 +08:00
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 {}
}
/** 分配角色 */
2023-03-31 07:54:33 +08:00
const assignRoleFormRef = ref()
const handleRole = (row: UserApi.UserVO) => {
assignRoleFormRef.value.open(row)
}
2023-03-31 07:54:33 +08:00
/** 初始化 */
onMounted(() => {
getList()
})
</script>