feat: dept
parent
9baa13e804
commit
bcf8353fdc
|
@ -15,12 +15,14 @@ import { isArray, isFunction } from '@/utils/is'
|
||||||
import { get } from 'lodash-es'
|
import { get } from 'lodash-es'
|
||||||
import { propTypes } from '@/utils/propTypes'
|
import { propTypes } from '@/utils/propTypes'
|
||||||
import { LoadingOutlined } from '@ant-design/icons-vue'
|
import { LoadingOutlined } from '@ant-design/icons-vue'
|
||||||
|
import { handleTree } from '@/utils/tree'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
api: { type: Function as PropType<(arg?: Recordable) => Promise<Recordable>> },
|
api: { type: Function as PropType<(arg?: Recordable) => Promise<Recordable>> },
|
||||||
params: { type: Object },
|
params: { type: Object },
|
||||||
immediate: { type: Boolean, default: true },
|
immediate: { type: Boolean, default: true },
|
||||||
resultField: propTypes.string.def('')
|
resultField: propTypes.string.def(''),
|
||||||
|
handleTree: { type: String, default: '' }
|
||||||
})
|
})
|
||||||
const emit = defineEmits(['options-change', 'change'])
|
const emit = defineEmits(['options-change', 'change'])
|
||||||
const attrs = useAttrs()
|
const attrs = useAttrs()
|
||||||
|
@ -74,6 +76,9 @@ async function fetch() {
|
||||||
if (!isArray(result)) {
|
if (!isArray(result)) {
|
||||||
result = get(result, props.resultField)
|
result = get(result, props.resultField)
|
||||||
}
|
}
|
||||||
|
if (props.handleTree) {
|
||||||
|
result = handleTree(result, props.handleTree)
|
||||||
|
}
|
||||||
treeData.value = (result as Recordable[]) || []
|
treeData.value = (result as Recordable[]) || []
|
||||||
isFirstLoaded.value = true
|
isFirstLoaded.value = true
|
||||||
emit('options-change', treeData.value)
|
emit('options-change', treeData.value)
|
||||||
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
<template>
|
||||||
|
<BasicModal v-bind="$attrs" @register="registerModal" :title="getTitle" @ok="handleSubmit">
|
||||||
|
<BasicForm @register="registerForm" />
|
||||||
|
</BasicModal>
|
||||||
|
</template>
|
||||||
|
<script lang="ts" setup name="DeptModal">
|
||||||
|
import { ref, computed, unref } from 'vue'
|
||||||
|
import { BasicModal, useModalInner } from '@/components/Modal'
|
||||||
|
import { BasicForm, useForm } from '@/components/Form'
|
||||||
|
import { formSchema } from './dept.data'
|
||||||
|
import { createDeptApi, getDeptApi, updateDeptApi } from '@/api/system/dept'
|
||||||
|
|
||||||
|
const emit = defineEmits(['success', 'register'])
|
||||||
|
const isUpdate = ref(true)
|
||||||
|
const rowId = ref()
|
||||||
|
|
||||||
|
const [registerForm, { setFieldsValue, resetFields, validate }] = useForm({
|
||||||
|
labelWidth: 100,
|
||||||
|
baseColProps: { span: 24 },
|
||||||
|
schemas: formSchema,
|
||||||
|
showActionButtonGroup: false,
|
||||||
|
actionColOptions: {
|
||||||
|
span: 23
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
|
||||||
|
resetFields()
|
||||||
|
setModalProps({ confirmLoading: false })
|
||||||
|
isUpdate.value = !!data?.isUpdate
|
||||||
|
|
||||||
|
if (unref(isUpdate)) {
|
||||||
|
const res = await getDeptApi(data.record.id)
|
||||||
|
rowId.value = res.id
|
||||||
|
setFieldsValue({
|
||||||
|
...res
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const getTitle = computed(() => (!unref(isUpdate) ? '新增部门' : '编辑部门'))
|
||||||
|
|
||||||
|
async function handleSubmit() {
|
||||||
|
try {
|
||||||
|
const values = await validate()
|
||||||
|
setModalProps({ confirmLoading: true })
|
||||||
|
if (unref(isUpdate)) {
|
||||||
|
await updateDeptApi(values)
|
||||||
|
} else {
|
||||||
|
await createDeptApi(values)
|
||||||
|
}
|
||||||
|
closeModal()
|
||||||
|
emit('success')
|
||||||
|
} finally {
|
||||||
|
setModalProps({ confirmLoading: false })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
|
@ -0,0 +1,130 @@
|
||||||
|
import { listSimpleDeptApi } from '@/api/system/dept'
|
||||||
|
import { getListSimpleUsersApi } from '@/api/system/user'
|
||||||
|
import { BasicColumn, FormSchema, useRender } from '@/components/Table'
|
||||||
|
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
|
||||||
|
|
||||||
|
export const columns: BasicColumn[] = [
|
||||||
|
{
|
||||||
|
title: '部门名称',
|
||||||
|
dataIndex: 'name',
|
||||||
|
width: 260,
|
||||||
|
align: 'left'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '负责人',
|
||||||
|
dataIndex: 'leader',
|
||||||
|
width: 120
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '排序',
|
||||||
|
dataIndex: 'sort',
|
||||||
|
width: 60
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '状态',
|
||||||
|
dataIndex: 'status',
|
||||||
|
width: 180,
|
||||||
|
customRender: ({ text }) => {
|
||||||
|
return useRender.renderDict(text, DICT_TYPE.COMMON_STATUS)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '创建时间',
|
||||||
|
dataIndex: 'createTime',
|
||||||
|
width: 180,
|
||||||
|
customRender: ({ text }) => {
|
||||||
|
return useRender.renderDate(text)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
export const searchFormSchema: FormSchema[] = [
|
||||||
|
{
|
||||||
|
label: '部门名称',
|
||||||
|
field: 'name',
|
||||||
|
component: 'Input',
|
||||||
|
colProps: { span: 8 }
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '状态',
|
||||||
|
field: 'status',
|
||||||
|
component: 'Select',
|
||||||
|
componentProps: {
|
||||||
|
options: getIntDictOptions(DICT_TYPE.COMMON_STATUS)
|
||||||
|
},
|
||||||
|
colProps: { span: 8 }
|
||||||
|
}
|
||||||
|
]
|
||||||
|
export const formSchema: FormSchema[] = [
|
||||||
|
{
|
||||||
|
label: '编号',
|
||||||
|
field: 'id',
|
||||||
|
show: false,
|
||||||
|
component: 'Input'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '上级部门',
|
||||||
|
field: 'parentId',
|
||||||
|
required: true,
|
||||||
|
component: 'ApiTreeSelect',
|
||||||
|
componentProps: {
|
||||||
|
api: () => listSimpleDeptApi(),
|
||||||
|
fieldNames: {
|
||||||
|
label: 'name',
|
||||||
|
key: 'id',
|
||||||
|
value: 'id'
|
||||||
|
},
|
||||||
|
handleTree: 'id'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '部门名称',
|
||||||
|
field: 'name',
|
||||||
|
required: true,
|
||||||
|
component: 'Input'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '岗位顺序',
|
||||||
|
field: 'sort',
|
||||||
|
required: true,
|
||||||
|
component: 'InputNumber'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '负责人',
|
||||||
|
field: 'leaderUserId',
|
||||||
|
component: 'ApiSelect',
|
||||||
|
componentProps: {
|
||||||
|
api: () => getListSimpleUsersApi(),
|
||||||
|
labelField: 'nickname',
|
||||||
|
valueField: 'id'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '联系电话',
|
||||||
|
field: 'phone',
|
||||||
|
required: true,
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
pattern: /^(?:(?:\+|00)86)?1(?:3[\d]|4[5-79]|5[0-35-9]|6[5-7]|7[0-8]|8[\d]|9[189])\d{8}$/,
|
||||||
|
message: '请输入正确的手机号码',
|
||||||
|
trigger: 'blur'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
component: 'Input'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '邮箱',
|
||||||
|
field: 'email',
|
||||||
|
required: true,
|
||||||
|
component: 'Input'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '部门状态',
|
||||||
|
field: 'status',
|
||||||
|
component: 'Select',
|
||||||
|
defaultValue: 0,
|
||||||
|
componentProps: {
|
||||||
|
options: getIntDictOptions(DICT_TYPE.COMMON_STATUS)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
|
@ -1,3 +1,132 @@
|
||||||
<template>
|
<template>
|
||||||
<div>开发中</div>
|
<div>
|
||||||
|
<BasicTable @register="register" @fetch-success="onFetchSuccess">
|
||||||
|
<template #toolbar>
|
||||||
|
<a-button type="primary" @click="handleCreate"> 新增 </a-button>
|
||||||
|
<a-button type="info" @click="expandAll">展开全部</a-button>
|
||||||
|
<a-button type="info" @click="collapseAll">折叠全部</a-button>
|
||||||
|
</template>
|
||||||
|
<template #leader="{ text }">
|
||||||
|
<span> {{ userNicknameFormat(text) }} </span>
|
||||||
|
</template>
|
||||||
|
<template #bodyCell="{ column, record }">
|
||||||
|
<template v-if="column.key === 'action'">
|
||||||
|
<TableAction
|
||||||
|
:actions="[
|
||||||
|
{
|
||||||
|
icon: 'clarity:note-edit-line',
|
||||||
|
onClick: handleEdit.bind(null, record)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon: 'ant-design:delete-outlined',
|
||||||
|
color: 'error',
|
||||||
|
popConfirm: {
|
||||||
|
title: '是否确认删除',
|
||||||
|
placement: 'left',
|
||||||
|
confirm: handleDelete.bind(null, record)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</template>
|
||||||
|
</BasicTable>
|
||||||
|
<DeptModel @register="registerModal" @success="reload()" />
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
<script lang="ts" setup name="Dept">
|
||||||
|
import { BasicTable, useTable, TableAction } from '@/components/Table'
|
||||||
|
import { deleteDeptApi, getDeptPageApi } from '@/api/system/dept'
|
||||||
|
import { columns, searchFormSchema } from './dept.data'
|
||||||
|
import { useModal } from '@/components/Modal'
|
||||||
|
import DeptModel from './DeptModel.vue'
|
||||||
|
import { useMessage } from '@/hooks/web/useMessage'
|
||||||
|
import { handleTree } from '@/utils/tree'
|
||||||
|
import { nextTick, ref } from 'vue'
|
||||||
|
import { getListSimpleUsersApi } from '@/api/system/user'
|
||||||
|
import { onMounted } from 'vue'
|
||||||
|
|
||||||
|
const { createMessage } = useMessage()
|
||||||
|
const [registerModal, { openModal }] = useModal()
|
||||||
|
|
||||||
|
const [register, { expandAll, collapseAll, getForm, reload }] = useTable({
|
||||||
|
title: '部门列表',
|
||||||
|
api: getList,
|
||||||
|
columns,
|
||||||
|
rowKey: 'id',
|
||||||
|
formConfig: {
|
||||||
|
labelWidth: 120,
|
||||||
|
schemas: searchFormSchema
|
||||||
|
},
|
||||||
|
isTreeTable: true,
|
||||||
|
pagination: false,
|
||||||
|
striped: false,
|
||||||
|
useSearchForm: true,
|
||||||
|
showTableSetting: true,
|
||||||
|
bordered: true,
|
||||||
|
showIndexColumn: false,
|
||||||
|
canResize: false,
|
||||||
|
actionColumn: {
|
||||||
|
width: 120,
|
||||||
|
title: '操作',
|
||||||
|
dataIndex: 'action',
|
||||||
|
fixed: 'right'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
async function getList() {
|
||||||
|
const res = await getDeptPageApi(getForm().getFieldsValue() as any)
|
||||||
|
return handleTree(res, 'id')
|
||||||
|
}
|
||||||
|
|
||||||
|
const users = ref<any[]>([])
|
||||||
|
|
||||||
|
async function getUserList() {
|
||||||
|
const res = await getListSimpleUsersApi()
|
||||||
|
users.value = res
|
||||||
|
}
|
||||||
|
|
||||||
|
function userNicknameFormat(row) {
|
||||||
|
console.info(row)
|
||||||
|
if (!row.leaderUserId) {
|
||||||
|
return '未设置'
|
||||||
|
}
|
||||||
|
for (const user of users.value) {
|
||||||
|
if (row.leaderUserId === user.id) {
|
||||||
|
return user.nickname
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return '未知【' + row.leaderUserId + '】'
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleCreate() {
|
||||||
|
openModal(true, {
|
||||||
|
isUpdate: false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleEdit(record: Recordable) {
|
||||||
|
openModal(true, {
|
||||||
|
record,
|
||||||
|
isUpdate: true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleDelete(record: Recordable) {
|
||||||
|
console.log(record)
|
||||||
|
const res = await deleteDeptApi(record.id)
|
||||||
|
if (res) {
|
||||||
|
createMessage.success('删除成功')
|
||||||
|
reload()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function onFetchSuccess() {
|
||||||
|
// 演示默认展开所有表项
|
||||||
|
nextTick(expandAll)
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
await getUserList()
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
</BasicTable>
|
</BasicTable>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts" setup name="Post">
|
<script lang="ts" setup name="Menu">
|
||||||
import { BasicTable, useTable } from '@/components/Table'
|
import { BasicTable, useTable } from '@/components/Table'
|
||||||
import { getMenuListApi } from '@/api/system/menu'
|
import { getMenuListApi } from '@/api/system/menu'
|
||||||
import { columns, searchFormSchema } from './menu.data'
|
import { columns, searchFormSchema } from './menu.data'
|
||||||
|
|
Loading…
Reference in New Issue