莳松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

213 lines
6.1 KiB

10 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">
<!-- 搜索 -->
<el-form :model="queryParams" ref="queryFormRef" inline label-width="68px">
8 months ago
<el-form-item label="姓名" prop="nickname">
10 months ago
<el-input
8 months ago
v-model="queryParams.nickname"
placeholder="请输入姓名"
10 months ago
clearable
@keyup.enter="handleQuery"
class="!w-240px"
/>
</el-form-item>
<el-form-item label="手机号码" prop="mobile">
<el-input
v-model="queryParams.mobile"
placeholder="请输入手机号码"
clearable
@keyup.enter="handleQuery"
class="!w-240px"
/>
</el-form-item>
<el-form-item>
10 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>
10 months ago
</el-form-item>
</el-form>
<el-table v-loading="loading" :data="list">
<el-table-column label="用户编号" key="id" prop="id" />
9 months ago
<el-table-column label="登录账号" prop="username" />
<el-table-column label="用户姓名" prop="nickname" />
10 months ago
<el-table-column label="部门" key="deptName" prop="deptName" />
10 months ago
<el-table-column label="手机号码" prop="mobile" width="120" />
<el-table-column label="状态" key="status">
<template #default="scope">
<el-switch
v-model="scope.row.status"
:active-value="0"
:inactive-value="1"
10 months ago
v-hasPermi="['basic:employee:update']"
10 months ago
@change="handleStatusChange(scope.row)"
/>
</template>
</el-table-column>
10 months ago
<el-table-column
label="创建时间"
prop="createTime"
width="180"
:formatter="dateFormatter"
/>
10 months ago
<el-table-column label="操作" width="260">
<template #default="scope">
10 months ago
<el-button
type="primary"
link
@click="openForm('update', scope.row.id)"
v-hasPermi="['basic:employee:update']"
>
10 months ago
修改
</el-button>
10 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>
10 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'
10 months ago
import { dateFormatter } from '@/utils/formatTime'
10 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([]) // 列表的数
const queryParams = reactive({
pageNo: 1,
pageSize: 10,
username: undefined,
8 months ago
nickname: undefined,
10 months ago
mobile: undefined,
deptId: undefined
})
const queryFormRef = ref() // 搜索的表单
/** 查询列表 */
const getList = async () => {
loading.value = true
try {
10 months ago
const data = await UserApi.getUserPage(queryParams)
10 months ago
list.value = data.list
total.value = data.total
} finally {
loading.value = false
}
}
/** 搜索按钮操作 */
const handleQuery = () => {
queryParams.pageNo = 1
getList()
}
/** 重置按钮操作 */
const resetQuery = () => {
queryFormRef.value?.resetFields()
handleQuery()
}
/** 处理部门被点击 */
const handleDeptNodeClick = async (row) => {
queryParams.deptId = row.id
await getList()
}
/** 添加/修改操作 */
const formRef = ref()
const openForm = (type: string, id?: number) => {
formRef.value.open(type, id)
}
/** 修改用户状态 */
const handleStatusChange = async (row: UserApi.UserVO) => {
try {
// 修改状态的二次确认
const text = row.status === CommonStatusEnum.ENABLE ? '启用' : '停用'
await message.confirm('确认要"' + text + '""' + row.username + '"用户吗?')
// 发起修改状态
10 months ago
await UserApi.updateUserStatus(row.id, row.status)
10 months ago
// 刷新列表
await getList()
} catch {
// 取消后,进行恢复按钮
row.status =
row.status === CommonStatusEnum.ENABLE ? CommonStatusEnum.DISABLE : CommonStatusEnum.ENABLE
}
}
/** 删除按钮操作 */
const handleDelete = async (id: number) => {
try {
// 删除的二次确认
await message.delConfirm()
// 发起删除
10 months ago
await UserApi.deleteUser(id)
10 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
// 发起重置
10 months ago
await UserApi.resetUserPwd(row.id, password)
10 months ago
message.success('修改成功,新密码是:' + password)
} catch {}
}
/** 初始化 */
onMounted(() => {
getList()
})
</script>