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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

120 lines
3.4 KiB

<template>
2 years ago
<div>
<BasicTable @register="register" @fetch-success="onFetchSuccess">
<template #toolbar>
2 years ago
<a-button type="primary" :preIcon="IconEnum.ADD" v-auth="['system:dept:create']" @click="handleCreate">
{{ t('action.create') }}
</a-button>
2 years ago
<a-button type="info" @click="expandAll">{{ t('component.tree.expandAll') }}</a-button>
<a-button type="info" @click="collapseAll">{{ t('component.tree.unExpandAll') }}</a-button>
2 years ago
</template>
<template #leader="{ text }">
<span> {{ userNicknameFormat(text) }} </span>
</template>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'action'">
<TableAction
:actions="[
2 years ago
{ icon: IconEnum.EDIT, label: t('action.edit'), auth: 'system:dept:update', onClick: handleEdit.bind(null, record) },
2 years ago
{
2 years ago
icon: IconEnum.DELETE,
2 years ago
color: 'error',
2 years ago
label: t('action.delete'),
2 years ago
auth: 'system:dept:delete',
2 years ago
popConfirm: {
2 years ago
title: t('common.delMessage'),
2 years ago
placement: 'left',
confirm: handleDelete.bind(null, record)
}
}
]"
/>
</template>
</template>
</BasicTable>
<DeptModal @register="registerModal" @success="reload()" />
2 years ago
</div>
</template>
<script lang="ts" setup name="SystemDept">
2 years ago
import { nextTick, ref, onMounted } from 'vue'
import { handleTree } from '@/utils/tree'
import { useI18n } from '@/hooks/web/useI18n'
import { useMessage } from '@/hooks/web/useMessage'
2 years ago
import { useModal } from '@/components/Modal'
import DeptModal from './DeptModal.vue'
2 years ago
import { IconEnum } from '@/enums/appEnum'
2 years ago
import { BasicTable, useTable, TableAction } from '@/components/Table'
import { getListSimpleUsers } from '@/api/system/user'
import { deleteDept, getDeptPage } from '@/api/system/dept'
2 years ago
import { columns, searchFormSchema } from './dept.data'
2 years ago
2 years ago
const { t } = useI18n()
const { createMessage } = useMessage()
2 years ago
const [registerModal, { openModal }] = useModal()
const [register, { expandAll, collapseAll, getForm, reload }] = useTable({
title: '部门列表',
api: getList,
columns,
rowKey: 'id',
formConfig: { labelWidth: 120, schemas: searchFormSchema },
2 years ago
isTreeTable: true,
pagination: false,
useSearchForm: true,
showTableSetting: true,
showIndexColumn: false,
actionColumn: {
width: 140,
2 years ago
title: t('common.action'),
2 years ago
dataIndex: 'action',
fixed: 'right'
}
})
async function getList() {
const res = await getDeptPage(getForm().getFieldsValue() as any)
2 years ago
return handleTree(res, 'id')
}
const users = ref<any[]>([])
async function getUserList() {
const res = await getListSimpleUsers()
2 years ago
users.value = res
}
function handleCreate() {
2 years ago
openModal(true, { isUpdate: false })
2 years ago
}
function handleEdit(record: Recordable) {
2 years ago
openModal(true, { record, isUpdate: true })
2 years ago
}
async function handleDelete(record: Recordable) {
await deleteDept(record.id)
2 years ago
createMessage.success(t('common.delSuccessText'))
reload()
2 years ago
}
function onFetchSuccess() {
nextTick(expandAll)
}
2 years ago
function userNicknameFormat(row) {
if (!row.leaderUserId) {
return '未设置'
}
for (const user of users.value) {
if (row.leaderUserId === user.id) {
return user.nickname
}
}
return '未知【' + row.leaderUserId + '】'
}
2 years ago
onMounted(async () => {
await getUserList()
})
</script>