This commit is contained in:
qsh
2024-05-23 15:24:05 +08:00
parent 3050b9a2fe
commit 33be215c0a
11 changed files with 60 additions and 127 deletions

View File

@@ -23,7 +23,7 @@
<script lang="ts" name="SystemUserDeptTree" setup>
import { ElTree } from 'element-plus'
// import * as DeptApi from '@/api/system/dept'
import * as DeptApi from '@/api/system/dept'
import { defaultProps, handleTree } from '@/utils/tree'
const deptName = ref('')
@@ -32,59 +32,7 @@ const treeRef = ref<InstanceType<typeof ElTree>>()
/** 获得部门树 */
const getTree = async () => {
// const res = await DeptApi.getSimpleDeptList()
const res = [
{
id: 100,
name: '芋道源码',
parentId: 0
},
{
id: 101,
name: '深圳总公司',
parentId: 100
},
{
id: 103,
name: '研发部门',
parentId: 101
},
{
id: 108,
name: '市场部门',
parentId: 102
},
{
id: 102,
name: '长沙分公司',
parentId: 100
},
{
id: 104,
name: '市场部门',
parentId: 101
},
{
id: 109,
name: '财务部门',
parentId: 102
},
{
id: 105,
name: '测试部门',
parentId: 101
},
{
id: 106,
name: '财务部门',
parentId: 101
},
{
id: 107,
name: '运维部门',
parentId: 101
}
]
const res = await DeptApi.getSimpleDeptList()
deptList.value = []
deptList.value.push(...handleTree(res))
}

View File

@@ -93,10 +93,10 @@
</template>
<script lang="ts" name="SystemUserForm" setup>
import { CommonStatusEnum } from '@/utils/constants'
import { defaultProps } from '@/utils/tree'
// import * as PostApi from '@/api/system/post'
// import * as DeptApi from '@/api/system/dept'
// import * as UserApi from '@/api/system/user'
import { defaultProps, handleTree } from '@/utils/tree'
import * as RoleApi from '@/api/system/role'
import * as DeptApi from '@/api/system/dept'
import * as UserApi from '@/api/system/user'
const { t } = useI18n() // 国际化
const message = useMessage() // 消息弹窗
@@ -114,7 +114,6 @@ const formData = ref({
username: '',
password: '',
sex: 1,
postIds: [],
remark: '',
status: CommonStatusEnum.ENABLE,
roleIds: []
@@ -140,7 +139,6 @@ const formRules = {
}
const formRef = ref() // 表单 Ref
const deptList = ref<Tree[]>([]) // 树形结构
const postList = ref([]) // 岗位列表
const roleOptions = ref([])
/** 打开弹窗 */
@@ -153,31 +151,15 @@ const open = async (type: string, id?: number) => {
if (id) {
formLoading.value = true
try {
// formData.value = await UserApi.getUser(id)
formData.value = {
nickname: '',
deptId: '',
mobile: '',
email: '',
id: undefined,
username: '',
password: '',
sex: 1,
postIds: [],
remark: '',
status: CommonStatusEnum.ENABLE,
roleIds: []
}
formData.value = await UserApi.getUser(id)
} finally {
formLoading.value = false
}
}
// 加载部门树
// deptList.value = handleTree(await DeptApi.getSimpleDeptList())
deptList.value = []
deptList.value = handleTree(await DeptApi.getSimpleDeptList())
// 加载岗位列表
// postList.value = await PostApi.getSimplePostList()
postList.value = []
roleOptions.value = await RoleApi.getSimpleRoleList()
}
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
@@ -191,12 +173,12 @@ const submitForm = async () => {
// 提交请求
formLoading.value = true
try {
// const data = formData.value as unknown as UserApi.UserVO
const data = formData.value as unknown as UserApi.UserVO
if (formType.value === 'create') {
// await UserApi.createUser(data)
await UserApi.createUser(data)
message.success(t('common.createSuccess'))
} else {
// await UserApi.updateUser(data)
await UserApi.updateUser(data)
message.success(t('common.updateSuccess'))
}
dialogVisible.value = false
@@ -217,8 +199,7 @@ const resetForm = () => {
id: undefined,
username: '',
password: '',
sex: undefined,
postIds: [],
sex: 1,
remark: '',
status: CommonStatusEnum.ENABLE,
roleIds: []

View File

@@ -35,7 +35,7 @@
<el-table-column label="用户编号" key="id" prop="id" />
<el-table-column label="用户名称" prop="username" />
<el-table-column label="用户昵称" prop="nickname" />
<el-table-column label="部门" key="deptName" prop="dept.name" />
<el-table-column label="部门" key="deptName" prop="deptName" />
<el-table-column label="手机号码" prop="mobile" width="120" />
<el-table-column label="状态" key="status">
<template #default="scope">
@@ -47,7 +47,12 @@
/>
</template>
</el-table-column>
<el-table-column label="创建时间" prop="createTime" width="180" />
<el-table-column
label="创建时间"
prop="createTime"
width="180"
:formatter="dateFormatter"
/>
<el-table-column label="操作" width="260">
<template #default="scope">
<el-button type="primary" link @click="openForm('update', scope.row.id)">
@@ -72,6 +77,7 @@
</template>
<script setup lang="ts" name="SystemUser">
import { CommonStatusEnum } from '@/utils/constants'
import { dateFormatter } from '@/utils/formatTime'
import * as UserApi from '@/api/system/user'
import UserForm from './UserForm.vue'
import DeptTree from './DeptTree.vue'
@@ -94,11 +100,7 @@ const queryFormRef = ref() // 搜索的表单
const getList = async () => {
loading.value = true
try {
// const data = await UserApi.getUserPage(queryParams)
const data = {
list: [{ username: '测试', status: 0 }],
total: 0
}
const data = await UserApi.getUserPage(queryParams)
list.value = data.list
total.value = data.total
} finally {
@@ -137,7 +139,7 @@ const handleStatusChange = async (row: UserApi.UserVO) => {
const text = row.status === CommonStatusEnum.ENABLE ? '启用' : '停用'
await message.confirm('确认要"' + text + '""' + row.username + '"用户吗?')
// 发起修改状态
// await UserApi.updateUserStatus(row.id, row.status)
await UserApi.updateUserStatus(row.id, row.status)
// 刷新列表
await getList()
} catch {
@@ -150,12 +152,10 @@ const handleStatusChange = async (row: UserApi.UserVO) => {
/** 删除按钮操作 */
const handleDelete = async (id: number) => {
try {
console.log(id)
// 删除的二次确认
await message.delConfirm()
// 发起删除
// await UserApi.deleteUser(id)
await UserApi.deleteUser(id)
message.success(t('common.delSuccess'))
// 刷新列表
await getList()
@@ -172,7 +172,7 @@ const handleResetPwd = async (row: UserApi.UserVO) => {
)
const password = result.value
// 发起重置
// await UserApi.resetUserPwd(row.id, password)
await UserApi.resetUserPwd(row.id, password)
message.success('修改成功,新密码是:' + password)
} catch {}
}