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.

102 lines
2.7 KiB

<script lang="ts" setup>
import { PlusOutlined } from '@ant-design/icons-vue'
import DeptFormModal from './DeptFormModal.vue'
import { columns, searchFormSchema } from './data'
2 years ago
import { useI18n } from '@/hooks/web/useI18n'
import { useMessage } from '@/hooks/web/useMessage'
2 years ago
import { useModal } from '@/components/Modal'
2 years ago
import { IconEnum } from '@/enums/appEnum'
import { BasicTable, TableAction, useTable } from '@/components/Table'
import { deleteDept, lazyGetDeptList } from '@/api/system/dept'
import type { Department } from '@/api/system/dept/types'
2 years ago
defineOptions({ name: 'SystemDept' })
2 years ago
const { t } = useI18n()
2 years ago
const [registerModal, { openModal }] = useModal<Department>()
const [register, { reload }] = useTable({
async api(params) {
const list = await lazyGetDeptList(params)
return list.map(item => ({
...item,
children: item.hasChildren ? [] : undefined,
}))
},
async onExpand(isExpand, data: Department) {
if (!isExpand || data.children.length)
return
try {
data.children = await lazyGetDeptList({ parentId: data.id })
}
catch {}
},
2 years ago
columns,
formConfig: {
labelWidth: 80,
schemas: searchFormSchema,
},
bordered: true,
canResize: false,
2 years ago
isTreeTable: true,
useSearchForm: true,
pagination: false,
2 years ago
actionColumn: {
width: 140,
2 years ago
title: t('common.action'),
2 years ago
dataIndex: 'action',
fixed: 'right',
},
2 years ago
})
async function handleDelete(id: string) {
try {
await deleteDept(id)
useMessage().createMessage.success(t('common.delSuccessText'))
reload()
2 years ago
}
catch {}
2 years ago
}
2 years ago
</script>
<template>
<div>
<BasicTable :api="async () => ([] as Department[])" @register="register">
<template #tableTitle>
<a-button type="primary" @click="openModal(true)">
<PlusOutlined />
{{ t('action.create') }}
</a-button>
</template>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'action'">
<TableAction
:actions="[
{
icon: IconEnum.EDIT,
label: t('action.edit'),
onClick: () => openModal(true, record),
},
{
icon: IconEnum.DELETE,
danger: true,
label: t('action.delete'),
popConfirm: {
title: t('common.delMessage'),
placement: 'left',
confirm: handleDelete.bind(null, record.id),
},
},
]"
/>
</template>
</template>
</BasicTable>
<DeptFormModal @register="registerModal" @success="reload()" />
</div>
</template>