perf: dept

This commit is contained in:
xingyu 2022-08-01 21:05:42 +08:00
parent 7d3c59af6d
commit 40c92a9ea2
4 changed files with 42 additions and 17 deletions

View File

@ -1,9 +1,12 @@
export type DeptVO = { export type DeptVO = {
id: number id: number
name: string name: string
status: number
parentId: number parentId: number
createTime: string status: number
sort: number
leaderUserId: number
phone: string
email: string
} }
export type DeptListReqVO = { export type DeptListReqVO = {

View File

@ -17,7 +17,7 @@ export const modelSchema = reactive<FormSchema[]>([
}, },
{ {
label: '负责人', label: '负责人',
field: 'email', field: 'leaderUserId',
component: 'Input' component: 'Input'
}, },
{ {
@ -33,7 +33,7 @@ export const modelSchema = reactive<FormSchema[]>([
{ {
label: '显示排序', label: '显示排序',
field: 'sort', field: 'sort',
component: 'Input' component: 'InputNumber'
}, },
{ {
label: '状态', label: '状态',

View File

@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import { useI18n } from '@/hooks/web/useI18n' import { useI18n } from '@/hooks/web/useI18n'
import { ElInput, ElCard, ElTree, ElTreeSelect } from 'element-plus' import { ElInput, ElCard, ElTree, ElTreeSelect, ElSelect, ElOption } from 'element-plus'
import { handleTree } from '@/utils/tree' import { handleTree } from '@/utils/tree'
import { onMounted, ref, unref, watch } from 'vue' import { onMounted, ref, unref, watch } from 'vue'
import * as DeptApi from '@/api/system/dept' import * as DeptApi from '@/api/system/dept'
@ -8,6 +8,7 @@ import { Form, FormExpose } from '@/components/Form'
import { modelSchema } from './dept.data' import { modelSchema } from './dept.data'
import { DeptVO } from '@/api/system/dept/types' import { DeptVO } from '@/api/system/dept/types'
import { useMessage } from '@/hooks/web/useMessage' import { useMessage } from '@/hooks/web/useMessage'
import { getListSimpleUsersApi } from '@/api/system/user'
const message = useMessage() const message = useMessage()
interface Tree { interface Tree {
id: number id: number
@ -34,7 +35,7 @@ const filterText = ref('')
const deptOptions = ref() // const deptOptions = ref() //
const treeRef = ref<InstanceType<typeof ElTree>>() const treeRef = ref<InstanceType<typeof ElTree>>()
const getTree = async () => { const getTree = async () => {
const res = await DeptApi.getDeptPageApi(null) const res = await DeptApi.listSimpleDeptApi()
deptOptions.value = handleTree(res) deptOptions.value = handleTree(res)
} }
const filterNode = (value: string, data: Tree) => { const filterNode = (value: string, data: Tree) => {
@ -44,6 +45,13 @@ const filterNode = (value: string, data: Tree) => {
watch(filterText, (val) => { watch(filterText, (val) => {
treeRef.value!.filter(val) treeRef.value!.filter(val)
}) })
//
const userOption = ref()
const leaderUserId = ref()
const getUserList = async () => {
const res = await getListSimpleUsersApi()
userOption.value = res
}
// //
const handleAdd = (data: { id: number }) => { const handleAdd = (data: { id: number }) => {
// //
@ -54,11 +62,12 @@ const handleAdd = (data: { id: number }) => {
} }
// //
const handleUpdate = async (data: { id: number }) => { const handleUpdate = async (data: { id: number }) => {
showForm.value = true
const res = await DeptApi.getDeptApi(data.id) const res = await DeptApi.getDeptApi(data.id)
formTitle.value = '修改- ' + res?.name formTitle.value = '修改- ' + res?.name
deptParentId.value = res.parentId deptParentId.value = res.parentId
leaderUserId.value = res.leaderUserId
unref(formRef)?.setValues(res) unref(formRef)?.setValues(res)
showForm.value = true
} }
// //
const handleDelete = async (data: { id: number }) => { const handleDelete = async (data: { id: number }) => {
@ -78,7 +87,7 @@ const submitForm = async () => {
try { try {
const data = unref(formRef)?.formModel as DeptVO const data = unref(formRef)?.formModel as DeptVO
data.parentId = deptParentId.value data.parentId = deptParentId.value
// TODO: data.leaderUserId = leaderUserId.value
if (formTitle.value.startsWith('新增')) { if (formTitle.value.startsWith('新增')) {
await DeptApi.createDeptApi(data) await DeptApi.createDeptApi(data)
} else if (formTitle.value.startsWith('修改')) { } else if (formTitle.value.startsWith('修改')) {
@ -92,6 +101,7 @@ const submitForm = async () => {
} }
onMounted(async () => { onMounted(async () => {
await getTree() await getTree()
await getUserList()
}) })
</script> </script>
<template> <template>
@ -159,6 +169,16 @@ onMounted(async () => {
check-strictly check-strictly
/> />
</template> </template>
<template #leaderUserId>
<el-select v-model="leaderUserId">
<el-option
v-for="item in userOption"
:key="parseInt(item.id)"
:label="item.nickname"
:value="parseInt(item.id)"
/>
</el-select>
</template>
</Form> </Form>
<!-- 操作按钮 --> <!-- 操作按钮 -->
<el-button <el-button

View File

@ -9,6 +9,7 @@ import {
ElTreeSelect, ElTreeSelect,
ElSelect, ElSelect,
ElOption, ElOption,
ElTransfer,
ElForm, ElForm,
ElFormItem, ElFormItem,
ElUpload, ElUpload,
@ -482,7 +483,7 @@ getList()
</template> </template>
</Dialog> </Dialog>
<!-- 分配用户角色 --> <!-- 分配用户角色 -->
<Dialog v-model="roleDialogVisible" title="分配角色"> <Dialog v-model="roleDialogVisible" title="分配角色" maxHeight="450px">
<el-form :model="userRole" label-width="80px"> <el-form :model="userRole" label-width="80px">
<el-form-item label="用户名称"> <el-form-item label="用户名称">
<el-input v-model="userRole.username" :disabled="true" /> <el-input v-model="userRole.username" :disabled="true" />
@ -491,14 +492,15 @@ getList()
<el-input v-model="userRole.nickname" :disabled="true" /> <el-input v-model="userRole.nickname" :disabled="true" />
</el-form-item> </el-form-item>
<el-form-item label="角色"> <el-form-item label="角色">
<el-select v-model="userRole.roleIds" multiple> <el-transfer
<el-option v-model="userRole.roleIds"
v-for="item in roleOptions" :titles="['角色列表', '已选择']"
:key="parseInt(item.id)" :props="{
:label="item.name" key: 'id',
:value="parseInt(item.id)" label: 'name'
}"
:data="roleOptions"
/> />
</el-select>
</el-form-item> </el-form-item>
</el-form> </el-form>
<!-- 操作按钮 --> <!-- 操作按钮 -->