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.
127 lines
3.4 KiB
127 lines
3.4 KiB
<template> |
|
<div> |
|
<BasicTable @register="register" @fetch-success="onFetchSuccess"> |
|
<template #toolbar> |
|
<a-button type="primary" :preIcon="IconEnum.ADD" @click="handleCreate"> {{ t('action.create') }} </a-button> |
|
<a-button type="info" @click="expandAll">{{ t('component.tree.expandAll') }}</a-button> |
|
<a-button type="info" @click="collapseAll">{{ t('component.tree.unExpandAll') }}</a-button> |
|
</template> |
|
<template #leader="{ text }"> |
|
<span> {{ userNicknameFormat(text) }} </span> |
|
</template> |
|
<template #bodyCell="{ column, record }"> |
|
<template v-if="column.key === 'action'"> |
|
<TableAction |
|
:actions="[ |
|
{ icon: IconEnum.EDIT, label: t('action.edit'), onClick: handleEdit.bind(null, record) }, |
|
{ |
|
icon: IconEnum.DELETE, |
|
color: 'error', |
|
label: t('action.delete'), |
|
popConfirm: { |
|
title: t('common.delMessage'), |
|
placement: 'left', |
|
confirm: handleDelete.bind(null, record) |
|
} |
|
} |
|
]" |
|
/> |
|
</template> |
|
</template> |
|
</BasicTable> |
|
<DeptModal @register="registerModal" @success="reload()" /> |
|
</div> |
|
</template> |
|
<script lang="ts" setup name="Dept"> |
|
import { nextTick, ref, onMounted } from 'vue' |
|
import { handleTree } from '@/utils/tree' |
|
import { useI18n } from '@/hooks/web/useI18n' |
|
import { useMessage } from '@/hooks/web/useMessage' |
|
import { useModal } from '@/components/Modal' |
|
import DeptModal from './DeptModal.vue' |
|
import { IconEnum } from '@/enums/appEnum' |
|
import { BasicTable, useTable, TableAction } from '@/components/Table' |
|
import { getListSimpleUsers } from '@/api/system/user' |
|
import { deleteDept, getDeptPage } from '@/api/system/dept' |
|
import { columns, searchFormSchema } from './dept.data' |
|
|
|
const { t } = useI18n() |
|
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: 140, |
|
title: t('common.action'), |
|
dataIndex: 'action', |
|
fixed: 'right' |
|
} |
|
}) |
|
|
|
async function getList() { |
|
const res = await getDeptPage(getForm().getFieldsValue() as any) |
|
return handleTree(res, 'id') |
|
} |
|
|
|
const users = ref<any[]>([]) |
|
|
|
async function getUserList() { |
|
const res = await getListSimpleUsers() |
|
users.value = res |
|
} |
|
|
|
function userNicknameFormat(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) { |
|
await deleteDept(record.id) |
|
createMessage.success(t('common.delSuccessText')) |
|
reload() |
|
} |
|
|
|
function onFetchSuccess() { |
|
nextTick(expandAll) |
|
} |
|
|
|
onMounted(async () => { |
|
await getUserList() |
|
}) |
|
</script>
|
|
|