莳松crm管理系统
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.
ss-crm-manage-web/src/views/Basic/User/index.vue

279 lines
8.4 KiB

11 months ago
<template>
<el-row :gutter="20">
<!-- 左侧部门树 -->
<el-col :span="4" :xs="24">
<DeptTree @node-click="handleDeptNodeClick" />
</el-col>
<el-col :span="20" :xs="24">
<!-- 搜索 -->
7 months ago
<el-form :model="queryParams" ref="queryFormRef" inline label-width="0">
<el-form-item>
11 months ago
<el-input
9 months ago
v-model="queryParams.nickname"
placeholder="请输入姓名"
11 months ago
clearable
@keyup.enter="handleQuery"
class="!w-240px"
/>
</el-form-item>
7 months ago
<el-form-item>
11 months ago
<el-input
v-model="queryParams.mobile"
placeholder="请输入手机号码"
clearable
@keyup.enter="handleQuery"
class="!w-240px"
/>
</el-form-item>
7 months ago
<el-form-item>
<el-radio-group v-model="queryParams.status" @change="handleQuery">
<el-radio :label="0"> 在职 </el-radio>
<el-radio :label="1"> 离职 </el-radio>
</el-radio-group>
</el-form-item>
11 months ago
<el-form-item>
11 months ago
<el-button @click="handleQuery" v-hasPermi="['basic:employee:search']">搜索</el-button>
<el-button @click="resetQuery" v-hasPermi="['basic:employee:reset']">重置</el-button>
<el-button
type="primary"
plain
@click="openForm('create')"
v-hasPermi="['basic:employee:add']"
>
新增
</el-button>
11 months ago
</el-form-item>
</el-form>
<el-table v-loading="loading" :data="list">
5 months ago
<el-table-column label="用户编号" key="id" prop="id" width="100" />
10 months ago
<el-table-column label="登录账号" prop="username" />
<el-table-column label="用户姓名" prop="nickname" />
5 months ago
<el-table-column label="部门" key="deptName" prop="deptName" width="100" />
11 months ago
<el-table-column label="手机号码" prop="mobile" width="120" />
5 months ago
<el-table-column label="微信号" prop="wxAlias" min-width="80" />
5 months ago
<el-table-column label="在职状态" key="hireStatus" width="120">
11 months ago
<template #default="scope">
<el-switch
5 months ago
v-model="scope.row.hireStatus"
11 months ago
:active-value="0"
:inactive-value="1"
7 months ago
active-text="在职"
inactive-text="离职"
5 months ago
size="small"
11 months ago
v-hasPermi="['basic:employee:update']"
11 months ago
@change="handleStatusChange(scope.row)"
/>
</template>
</el-table-column>
5 months ago
<el-table-column label="启用状态" key="status" width="120">
5 months ago
<template #default="scope">
<el-switch
5 months ago
v-model="scope.row.status"
5 months ago
:active-value="0"
:inactive-value="1"
active-text="启用"
inactive-text="禁用"
size="small"
5 months ago
:disabled="scope.row.hireStatus == 1"
5 months ago
v-hasPermi="['basic:employee:update']"
@change="handleUseChange(scope.row)"
/>
</template>
</el-table-column>
5 months ago
<el-table-column label="入职日期" prop="hireDate" width="120" :formatter="dateFormatter" />
<el-table-column label="离职日期" prop="" width="120" :formatter="dateFormatter" />
5 months ago
<el-table-column label="操作" width="180">
11 months ago
<template #default="scope">
11 months ago
<el-button
type="primary"
link
@click="openForm('update', scope.row.id)"
v-hasPermi="['basic:employee:update']"
>
11 months ago
修改
</el-button>
11 months ago
<el-button
type="primary"
link
@click="handleDelete(scope.row.id)"
v-hasPermi="['basic:employee:delete']"
>
删除
</el-button>
<el-button
type="primary"
link
@click="handleResetPwd(scope.row)"
v-hasPermi="['basic:employee:password']"
>
重置密码
</el-button>
11 months ago
</template>
</el-table-column>
</el-table>
<Pagination
:total="total"
v-model:page="queryParams.pageNo"
v-model:limit="queryParams.pageSize"
@pagination="getList"
/>
</el-col>
</el-row>
<!-- 添加或修改用户对话框 -->
<UserForm ref="formRef" @success="getList" />
</template>
<script setup lang="ts" name="SystemUser">
import { CommonStatusEnum } from '@/utils/constants'
11 months ago
import { dateFormatter } from '@/utils/formatTime'
11 months ago
import * as UserApi from '@/api/system/user'
import UserForm from './UserForm.vue'
import DeptTree from './DeptTree.vue'
const message = useMessage() // 消息弹窗
const { t } = useI18n() // 国际化
const loading = ref(true) // 列表的加载中
const total = ref(0) // 列表的总页数
const list = ref([]) // 列表的数
7 months ago
const queryParams = ref({
11 months ago
pageNo: 1,
7 months ago
pageSize: 20,
11 months ago
username: undefined,
9 months ago
nickname: undefined,
11 months ago
mobile: undefined,
7 months ago
deptId: undefined,
status: undefined
11 months ago
})
const queryFormRef = ref() // 搜索的表单
/** 查询列表 */
const getList = async () => {
loading.value = true
try {
7 months ago
const data = await UserApi.getUserPage(queryParams.value)
11 months ago
list.value = data.list
total.value = data.total
} finally {
loading.value = false
}
}
/** 搜索按钮操作 */
const handleQuery = () => {
7 months ago
queryParams.value.pageNo = 1
11 months ago
getList()
}
/** 重置按钮操作 */
const resetQuery = () => {
queryFormRef.value?.resetFields()
7 months ago
queryParams.value = {
pageNo: 1,
pageSize: 20,
username: undefined,
nickname: undefined,
mobile: undefined,
deptId: undefined,
status: undefined
}
11 months ago
handleQuery()
}
/** 处理部门被点击 */
const handleDeptNodeClick = async (row) => {
7 months ago
queryParams.value.deptId = row.id
11 months ago
await getList()
}
/** 添加/修改操作 */
const formRef = ref()
const openForm = (type: string, id?: number) => {
formRef.value.open(type, id)
}
5 months ago
/** 修改在职状态 */
11 months ago
const handleStatusChange = async (row: UserApi.UserVO) => {
try {
// 修改状态的二次确认
5 months ago
const text = row.hireStatus === CommonStatusEnum.ENABLE ? '入职' : '离职'
5 months ago
let result = { value: '' }
5 months ago
if (text == '入职') {
await message.confirm('确认要"' + text + '""' + row.nickname + '"吗?')
5 months ago
} else {
result = await message.prompt(
'请输入年月日,如2024-01-01',
5 months ago
'确认要"' + text + '""' + row.nickname + '"用户吗?'
5 months ago
)
const regex = /^\d{4}-\d{2}-\d{2}$/
if (!regex.test(result.value)) {
message.error('请输入离职日期')
throw new Error()
}
}
11 months ago
// 发起修改状态
5 months ago
await UserApi.updateUserStatus(row.id, row.status, result.value, row.hireStatus)
5 months ago
message.success('修改成功')
// 刷新列表
await getList()
} catch {
// 取消后,进行恢复按钮
5 months ago
row.hireStatus =
row.hireStatus === CommonStatusEnum.ENABLE
? CommonStatusEnum.DISABLE
: CommonStatusEnum.ENABLE
5 months ago
}
}
// 修改启用状态
const handleUseChange = async (row: UserApi.UserVO) => {
try {
// 修改状态的二次确认
const text = row.status === CommonStatusEnum.ENABLE ? '启用' : '禁用'
await message.confirm('确认要"' + text + '""' + row.nickname + '"吗?')
// 发起修改状态
5 months ago
await UserApi.updateUserStatus(row.id, row.status, row.retireDate, row.hireStatus)
5 months ago
message.success('修改成功')
11 months ago
// 刷新列表
await getList()
} catch {
// 取消后,进行恢复按钮
row.status =
row.status === CommonStatusEnum.ENABLE ? CommonStatusEnum.DISABLE : CommonStatusEnum.ENABLE
}
}
/** 删除按钮操作 */
const handleDelete = async (id: number) => {
try {
// 删除的二次确认
await message.delConfirm()
// 发起删除
11 months ago
await UserApi.deleteUser(id)
11 months ago
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
// 发起重置
11 months ago
await UserApi.resetUserPwd(row.id, password)
11 months ago
message.success('修改成功,新密码是:' + password)
} catch {}
}
/** 初始化 */
onMounted(() => {
getList()
})
</script>