2023-02-11 00:44:00 +08:00
|
|
|
|
<template>
|
2023-03-30 22:59:29 +08:00
|
|
|
|
<!-- 搜索工作栏 -->
|
|
|
|
|
<el-row :gutter="20">
|
|
|
|
|
<!--部门数据-->
|
|
|
|
|
<el-col :span="4" :xs="24">
|
|
|
|
|
<content-wrap class="h-1/1">
|
|
|
|
|
<UserDeptTree @node-click="handleDeptNodeClick" />
|
|
|
|
|
</content-wrap>
|
|
|
|
|
</el-col>
|
|
|
|
|
<!--用户数据-->
|
|
|
|
|
<el-col :span="20" :xs="24">
|
|
|
|
|
<content-wrap>
|
|
|
|
|
<el-form
|
|
|
|
|
:model="queryParams"
|
|
|
|
|
ref="queryFormRef"
|
|
|
|
|
:inline="true"
|
|
|
|
|
v-show="showSearch"
|
|
|
|
|
label-width="68px"
|
|
|
|
|
>
|
|
|
|
|
<el-form-item label="用户名称" prop="username">
|
|
|
|
|
<el-input
|
|
|
|
|
v-model="queryParams.username"
|
|
|
|
|
placeholder="请输入用户名称"
|
|
|
|
|
clearable
|
|
|
|
|
style="width: 240px"
|
|
|
|
|
@keyup.enter="handleQuery"
|
2023-03-27 09:44:23 +08:00
|
|
|
|
/>
|
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
|
|
|
|
|
style="width: 240px"
|
|
|
|
|
@keyup.enter="handleQuery"
|
2023-03-27 09:44:23 +08:00
|
|
|
|
/>
|
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
|
|
|
|
|
style="width: 240px"
|
|
|
|
|
>
|
|
|
|
|
<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"
|
|
|
|
|
style="width: 240px"
|
|
|
|
|
value-format="YYYY-MM-DD HH:mm:ss"
|
|
|
|
|
type="datetimerange"
|
|
|
|
|
range-separator="-"
|
|
|
|
|
start-placeholder="开始日期"
|
|
|
|
|
end-placeholder="结束日期"
|
2023-03-27 09:44:23 +08:00
|
|
|
|
/>
|
2023-03-30 22:59:29 +08:00
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item>
|
|
|
|
|
<el-button type="primary" @click="handleQuery"><Icon icon="ep:search" />搜索</el-button>
|
|
|
|
|
<el-button @click="resetQuery"><Icon icon="ep:refresh" />重置</el-button>
|
|
|
|
|
<el-button type="primary" plain @click="handleAdd" v-hasPermi="['system:user:create']">
|
|
|
|
|
<Icon icon="ep:plus" /> 新增
|
|
|
|
|
</el-button>
|
|
|
|
|
<el-button
|
|
|
|
|
type="info"
|
|
|
|
|
size="small"
|
|
|
|
|
@click="handleImport"
|
|
|
|
|
v-hasPermi="['system:user:import']"
|
2023-03-27 09:44:23 +08:00
|
|
|
|
>
|
2023-03-30 22:59:29 +08:00
|
|
|
|
<Icon icon="ep:upload" /> 导入
|
|
|
|
|
</el-button>
|
|
|
|
|
<el-button
|
|
|
|
|
type="warning"
|
|
|
|
|
size="small"
|
|
|
|
|
@click="handleExport"
|
|
|
|
|
:loading="exportLoading"
|
|
|
|
|
v-hasPermi="['system:user:export']"
|
2023-03-27 09:44:23 +08:00
|
|
|
|
>
|
2023-03-30 22:59:29 +08:00
|
|
|
|
<Icon icon="ep:download" />导出
|
|
|
|
|
</el-button>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-form>
|
|
|
|
|
</content-wrap>
|
|
|
|
|
<content-wrap>
|
|
|
|
|
<el-table v-loading="loading" :data="userList">
|
|
|
|
|
<el-table-column
|
|
|
|
|
label="用户编号"
|
|
|
|
|
align="center"
|
|
|
|
|
key="id"
|
|
|
|
|
prop="id"
|
|
|
|
|
v-if="columns[0].visible"
|
2023-02-11 00:44:00 +08:00
|
|
|
|
/>
|
2023-03-30 22:59:29 +08:00
|
|
|
|
<el-table-column
|
|
|
|
|
label="用户名称"
|
|
|
|
|
align="center"
|
|
|
|
|
key="username"
|
|
|
|
|
prop="username"
|
|
|
|
|
v-if="columns[1].visible"
|
|
|
|
|
:show-overflow-tooltip="true"
|
|
|
|
|
/>
|
|
|
|
|
<el-table-column
|
|
|
|
|
label="用户昵称"
|
|
|
|
|
align="center"
|
|
|
|
|
key="nickname"
|
|
|
|
|
prop="nickname"
|
|
|
|
|
v-if="columns[2].visible"
|
|
|
|
|
:show-overflow-tooltip="true"
|
|
|
|
|
/>
|
|
|
|
|
<el-table-column
|
|
|
|
|
label="部门"
|
|
|
|
|
align="center"
|
|
|
|
|
key="deptName"
|
|
|
|
|
prop="dept.name"
|
|
|
|
|
v-if="columns[3].visible"
|
|
|
|
|
:show-overflow-tooltip="true"
|
|
|
|
|
/>
|
|
|
|
|
<el-table-column
|
|
|
|
|
label="手机号码"
|
|
|
|
|
align="center"
|
|
|
|
|
key="mobile"
|
|
|
|
|
prop="mobile"
|
|
|
|
|
v-if="columns[4].visible"
|
|
|
|
|
width="120"
|
|
|
|
|
/>
|
|
|
|
|
<el-table-column label="状态" key="status" v-if="columns[5].visible" align="center">
|
|
|
|
|
<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"
|
|
|
|
|
v-if="columns[6].visible"
|
|
|
|
|
width="160"
|
|
|
|
|
>
|
|
|
|
|
<template #default="scope">
|
|
|
|
|
<span>{{ parseTime(scope.row.createTime) }}</span>
|
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
|
|
|
|
label="操作"
|
|
|
|
|
align="center"
|
|
|
|
|
width="160"
|
|
|
|
|
class-name="small-padding fixed-width"
|
|
|
|
|
>
|
|
|
|
|
<template #default="scope">
|
|
|
|
|
<div class="flex justify-center items-center">
|
|
|
|
|
<el-button
|
|
|
|
|
type="primary"
|
|
|
|
|
link
|
|
|
|
|
@click="handleUpdate(scope.row)"
|
|
|
|
|
v-hasPermi="['system:user:update']"
|
|
|
|
|
><Icon icon="ep:edit" />修改</el-button
|
|
|
|
|
>
|
|
|
|
|
<el-dropdown
|
|
|
|
|
@command="(command) => handleCommand(command, scope.$index, scope.row)"
|
|
|
|
|
v-hasPermi="[
|
|
|
|
|
'system:user:delete',
|
|
|
|
|
'system:user:update-password',
|
|
|
|
|
'system:permission:assign-user-role'
|
|
|
|
|
]"
|
|
|
|
|
>
|
|
|
|
|
<el-button type="primary" link><Icon icon="ep:d-arrow-right" />更多</el-button>
|
|
|
|
|
<template #dropdown>
|
|
|
|
|
<el-dropdown-menu>
|
|
|
|
|
<!-- div包住避免控制台报错:Runtime directive used on component with non-element root node -->
|
|
|
|
|
<div v-if="scope.row.id !== 1" v-hasPermi="['system:user:delete']">
|
|
|
|
|
<el-dropdown-item command="handleDelete" type="text"
|
|
|
|
|
><Icon icon="ep:delete" />删除</el-dropdown-item
|
|
|
|
|
>
|
|
|
|
|
</div>
|
|
|
|
|
<div v-hasPermi="['system:user:update-password']">
|
|
|
|
|
<el-dropdown-item command="handleResetPwd" type="text"
|
|
|
|
|
><Icon icon="ep:key" />重置密码</el-dropdown-item
|
|
|
|
|
></div
|
|
|
|
|
>
|
|
|
|
|
<div v-hasPermi="['system:permission:assign-user-role']">
|
|
|
|
|
<el-dropdown-item command="handleRole" type="text"
|
|
|
|
|
><Icon icon="ep:circle-check" />分配角色</el-dropdown-item
|
|
|
|
|
></div
|
|
|
|
|
>
|
|
|
|
|
</el-dropdown-menu>
|
|
|
|
|
</template>
|
|
|
|
|
</el-dropdown>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
|
|
|
|
</el-table>
|
|
|
|
|
<pagination
|
|
|
|
|
v-show="total > 0"
|
|
|
|
|
:total="total"
|
|
|
|
|
v-model:page="queryParams.pageNo"
|
|
|
|
|
v-model:limit="queryParams.pageSize"
|
|
|
|
|
@pagination="getList"
|
|
|
|
|
/>
|
|
|
|
|
</content-wrap>
|
|
|
|
|
</el-col>
|
|
|
|
|
</el-row>
|
|
|
|
|
|
|
|
|
|
<!-- 添加或修改用户对话框 -->
|
|
|
|
|
<UserForm ref="userFormRef" @success="getList" />
|
|
|
|
|
<!-- 用户导入对话框 -->
|
|
|
|
|
<UserImportForm ref="userImportFormRef" @success="getList" />
|
|
|
|
|
<!-- 分配角色 -->
|
|
|
|
|
<UserAssignRoleForm ref="userAssignRoleFormRef" @success="getList" />
|
2023-03-21 23:33:40 +08:00
|
|
|
|
</template>
|
2023-03-04 13:19:49 +08:00
|
|
|
|
|
2023-03-22 23:37:29 +08:00
|
|
|
|
<script setup lang="ts" name="User">
|
2023-03-29 22:07:53 +08:00
|
|
|
|
import download from '@/utils/download'
|
|
|
|
|
import { parseTime } from '@/utils/formatTime'
|
|
|
|
|
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
|
|
|
|
|
import { CommonStatusEnum } from '@/utils/constants'
|
|
|
|
|
|
2023-03-21 23:33:40 +08:00
|
|
|
|
import {
|
2023-03-27 09:44:23 +08:00
|
|
|
|
deleteUserApi,
|
|
|
|
|
exportUserApi,
|
|
|
|
|
resetUserPwdApi,
|
|
|
|
|
updateUserStatusApi,
|
2023-03-29 22:07:53 +08:00
|
|
|
|
getUserPageApi,
|
2023-03-27 09:44:23 +08:00
|
|
|
|
UserVO
|
2023-03-21 23:33:40 +08:00
|
|
|
|
} from '@/api/system/user'
|
2023-03-29 22:07:53 +08:00
|
|
|
|
|
|
|
|
|
import UserForm from './components/UserForm.vue'
|
|
|
|
|
import UserImportForm from './components/UserImportForm.vue'
|
|
|
|
|
import UserAssignRoleForm from './components/UserAssignRoleForm.vue'
|
|
|
|
|
import UserDeptTree from './components/UserDeptTree.vue'
|
|
|
|
|
|
2023-02-11 00:44:00 +08:00
|
|
|
|
const message = useMessage() // 消息弹窗
|
2023-03-27 09:44:23 +08:00
|
|
|
|
const { t } = useI18n() // 国际化
|
2023-02-11 00:44:00 +08:00
|
|
|
|
|
2023-03-22 23:37:29 +08:00
|
|
|
|
const queryParams = reactive({
|
|
|
|
|
pageNo: 1,
|
|
|
|
|
pageSize: 10,
|
|
|
|
|
username: undefined,
|
|
|
|
|
mobile: undefined,
|
|
|
|
|
status: undefined,
|
|
|
|
|
deptId: undefined,
|
|
|
|
|
createTime: []
|
|
|
|
|
})
|
|
|
|
|
const showSearch = ref(true)
|
2023-03-27 09:44:23 +08:00
|
|
|
|
|
2023-03-22 23:37:29 +08:00
|
|
|
|
const handleDeptNodeClick = async (row: { [key: string]: any }) => {
|
|
|
|
|
queryParams.deptId = row.id
|
|
|
|
|
getList()
|
|
|
|
|
}
|
2023-02-11 00:44:00 +08:00
|
|
|
|
|
2023-03-22 23:37:29 +08:00
|
|
|
|
// 用户列表
|
|
|
|
|
const userList = ref<UserVO[]>([])
|
|
|
|
|
const loading = ref(false)
|
|
|
|
|
const total = ref(0)
|
|
|
|
|
const columns = ref([
|
|
|
|
|
{ key: 0, label: `用户编号`, visible: true },
|
|
|
|
|
{ key: 1, label: `用户名称`, visible: true },
|
|
|
|
|
{ key: 2, label: `用户昵称`, visible: true },
|
|
|
|
|
{ key: 3, label: `部门`, visible: true },
|
|
|
|
|
{ key: 4, label: `手机号码`, visible: true },
|
|
|
|
|
{ key: 5, label: `状态`, visible: true },
|
|
|
|
|
{ key: 6, label: `创建时间`, visible: true }
|
|
|
|
|
])
|
2023-03-30 22:59:29 +08:00
|
|
|
|
|
|
|
|
|
/** 查询列表 */
|
2023-03-22 23:37:29 +08:00
|
|
|
|
const getList = () => {
|
|
|
|
|
loading.value = true
|
|
|
|
|
getUserPageApi(queryParams).then((response) => {
|
|
|
|
|
userList.value = response.list
|
|
|
|
|
total.value = response.total
|
|
|
|
|
loading.value = false
|
|
|
|
|
})
|
|
|
|
|
}
|
2023-03-30 22:59:29 +08:00
|
|
|
|
|
2023-03-27 09:44:23 +08:00
|
|
|
|
/** 搜索按钮操作 */
|
|
|
|
|
const handleQuery = () => {
|
|
|
|
|
queryParams.pageNo = 1
|
|
|
|
|
getList()
|
2023-03-04 13:19:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-27 09:44:23 +08:00
|
|
|
|
/** 重置按钮操作 */
|
|
|
|
|
const queryFormRef = ref()
|
|
|
|
|
const resetQuery = () => {
|
|
|
|
|
queryFormRef.value?.resetFields()
|
|
|
|
|
handleQuery()
|
2023-02-11 00:44:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-27 09:44:23 +08:00
|
|
|
|
// 添加或编辑
|
2023-03-29 22:07:53 +08:00
|
|
|
|
const userFormRef = ref()
|
2023-03-27 09:44:23 +08:00
|
|
|
|
// 添加用户
|
|
|
|
|
const handleAdd = () => {
|
2023-03-29 22:07:53 +08:00
|
|
|
|
userFormRef.value?.openForm()
|
2023-02-11 00:44:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-27 09:44:23 +08:00
|
|
|
|
// 用户导入
|
2023-03-29 22:07:53 +08:00
|
|
|
|
const userImportFormRef = ref()
|
2023-03-27 09:44:23 +08:00
|
|
|
|
const handleImport = () => {
|
2023-03-29 22:07:53 +08:00
|
|
|
|
userImportFormRef.value?.openForm()
|
2023-02-11 00:44:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-27 09:44:23 +08:00
|
|
|
|
// 用户导出
|
2023-03-22 23:37:29 +08:00
|
|
|
|
const exportLoading = ref(false)
|
2023-03-27 09:44:23 +08:00
|
|
|
|
const handleExport = () => {
|
|
|
|
|
message
|
|
|
|
|
.confirm('是否确认导出所有用户数据项?')
|
2023-03-29 22:07:53 +08:00
|
|
|
|
.then(async () => {
|
2023-03-27 09:44:23 +08:00
|
|
|
|
// 处理查询参数
|
|
|
|
|
let params = { ...queryParams }
|
|
|
|
|
params.pageNo = 1
|
|
|
|
|
params.pageSize = 99999
|
|
|
|
|
exportLoading.value = true
|
2023-03-29 22:07:53 +08:00
|
|
|
|
const response = await exportUserApi(params)
|
2023-03-27 09:44:23 +08:00
|
|
|
|
download.excel(response, '用户数据.xls')
|
|
|
|
|
})
|
|
|
|
|
.catch(() => {})
|
|
|
|
|
.finally(() => {
|
|
|
|
|
exportLoading.value = false
|
|
|
|
|
})
|
2023-02-11 00:44:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-27 09:44:23 +08:00
|
|
|
|
// 操作分发
|
|
|
|
|
const handleCommand = (command: string, index: number, row: UserVO) => {
|
|
|
|
|
console.log(index)
|
|
|
|
|
switch (command) {
|
|
|
|
|
case 'handleUpdate':
|
|
|
|
|
handleUpdate(row) //修改客户信息
|
|
|
|
|
break
|
|
|
|
|
case 'handleDelete':
|
|
|
|
|
handleDelete(row) //红号变更
|
|
|
|
|
break
|
|
|
|
|
case 'handleResetPwd':
|
|
|
|
|
handleResetPwd(row)
|
|
|
|
|
break
|
|
|
|
|
case 'handleRole':
|
|
|
|
|
handleRole(row)
|
|
|
|
|
break
|
|
|
|
|
default:
|
|
|
|
|
break
|
|
|
|
|
}
|
2023-02-11 00:44:00 +08:00
|
|
|
|
}
|
2023-03-27 09:44:23 +08:00
|
|
|
|
|
|
|
|
|
// 用户状态修改
|
|
|
|
|
const handleStatusChange = (row: UserVO) => {
|
|
|
|
|
let text = row.status === CommonStatusEnum.ENABLE ? '启用' : '停用'
|
2023-02-11 00:44:00 +08:00
|
|
|
|
message
|
|
|
|
|
.confirm('确认要"' + text + '""' + row.username + '"用户吗?', t('common.reminder'))
|
2023-03-29 22:07:53 +08:00
|
|
|
|
.then(async () => {
|
2023-02-11 00:44:00 +08:00
|
|
|
|
row.status =
|
|
|
|
|
row.status === CommonStatusEnum.ENABLE ? CommonStatusEnum.ENABLE : CommonStatusEnum.DISABLE
|
2023-03-29 22:07:53 +08:00
|
|
|
|
await updateUserStatusApi(row.id, row.status)
|
2023-02-11 00:44:00 +08:00
|
|
|
|
message.success(text + '成功')
|
|
|
|
|
// 刷新列表
|
2023-03-27 09:44:23 +08:00
|
|
|
|
getList()
|
2023-02-11 00:44:00 +08:00
|
|
|
|
})
|
|
|
|
|
.catch(() => {
|
|
|
|
|
row.status =
|
|
|
|
|
row.status === CommonStatusEnum.ENABLE ? CommonStatusEnum.DISABLE : CommonStatusEnum.ENABLE
|
|
|
|
|
})
|
|
|
|
|
}
|
2023-03-27 09:44:23 +08:00
|
|
|
|
|
|
|
|
|
// 具体数据单行操作
|
|
|
|
|
/** 修改按钮操作 */
|
|
|
|
|
const handleUpdate = (row: UserVO) => {
|
2023-03-29 22:07:53 +08:00
|
|
|
|
userFormRef.value?.openForm(row)
|
2023-03-27 09:44:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 删除用户
|
|
|
|
|
const handleDelete = (row: UserVO) => {
|
|
|
|
|
const ids = row.id
|
|
|
|
|
message
|
|
|
|
|
.confirm('是否确认删除用户编号为"' + ids + '"的数据项?')
|
2023-03-29 22:07:53 +08:00
|
|
|
|
.then(async () => {
|
|
|
|
|
await deleteUserApi(ids)
|
2023-03-27 09:44:23 +08:00
|
|
|
|
message.success('删除成功')
|
2023-03-29 22:07:53 +08:00
|
|
|
|
getList()
|
|
|
|
|
})
|
|
|
|
|
.catch((e) => {
|
|
|
|
|
console.error(e)
|
2023-03-27 09:44:23 +08:00
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-11 00:44:00 +08:00
|
|
|
|
// 重置密码
|
2023-03-27 09:44:23 +08:00
|
|
|
|
const handleResetPwd = (row: UserVO) => {
|
2023-03-29 22:07:53 +08:00
|
|
|
|
message
|
|
|
|
|
.prompt('请输入"' + row.username + '"的新密码', t('common.reminder'))
|
|
|
|
|
.then(async ({ value }) => {
|
|
|
|
|
await resetUserPwdApi(row.id, value)
|
|
|
|
|
message.success('修改成功,新密码是:' + value)
|
|
|
|
|
})
|
|
|
|
|
.catch((e) => {
|
|
|
|
|
console.error(e)
|
|
|
|
|
})
|
2023-02-11 00:44:00 +08:00
|
|
|
|
}
|
2023-03-27 09:44:23 +08:00
|
|
|
|
|
2023-02-11 00:44:00 +08:00
|
|
|
|
// 分配角色
|
2023-03-29 22:07:53 +08:00
|
|
|
|
const userAssignRoleFormRef = ref()
|
|
|
|
|
const handleRole = (row: UserVO) => {
|
|
|
|
|
userAssignRoleFormRef.value?.openForm(row)
|
2023-02-11 00:44:00 +08:00
|
|
|
|
}
|
2023-03-27 09:44:23 +08:00
|
|
|
|
|
2023-03-22 23:37:29 +08:00
|
|
|
|
// ========== 初始化 ==========
|
|
|
|
|
onMounted(async () => {
|
|
|
|
|
getList()
|
|
|
|
|
})
|
2023-02-11 00:44:00 +08:00
|
|
|
|
</script>
|