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.

108 lines
2.9 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, LazyGetDeptListParams } from '@/api/system/dept/types'
import { usePermission } from '@/hooks/web/usePermission'
2 years ago
defineOptions({ name: 'SystemDept' })
2 years ago
const { t } = useI18n()
2 years ago
const [registerModal, { openModal }] = useModal<Department>()
const { hasPermission } = usePermission()
async function lazyGetDeptListWrap(params: LazyGetDeptListParams) {
try {
const list = await lazyGetDeptList(params)
return list.map(item => ({
...item,
children: item.hasChildren ? [] : undefined,
}))
}
catch {
return []
}
}
const [register, { reload }] = useTable<Department>({
api: lazyGetDeptListWrap,
load(record) {
return lazyGetDeptListWrap({ parentId: record.id })
},
2 years ago
columns,
formConfig: {
labelWidth: 80,
schemas: searchFormSchema,
},
bordered: true,
canResize: false,
2 years ago
useSearchForm: true,
pagination: false,
2 years ago
actionColumn: {
width: 140,
2 years ago
title: t('common.action'),
2 years ago
dataIndex: 'action',
fixed: 'right',
auth: ['dept_delete', 'dept_edit'],
},
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 v-if="hasPermission('dept_add')" #tableTitle>
<a-button type="primary" @click="openModal">
<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'),
auth: 'dept_edit',
onClick: () => openModal(true, record),
},
{
icon: IconEnum.DELETE,
danger: true,
label: t('action.delete'),
auth: 'dept_delete',
popConfirm: {
title: t('common.delMessage'),
placement: 'left',
confirm: handleDelete.bind(null, record.id),
},
},
]"
/>
</template>
</template>
</BasicTable>
<DeptFormModal @register="registerModal" @success="reload()" />
</div>
</template>