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.

131 lines
3.4 KiB

<template>
2 years ago
<div>
<BasicTable @register="register" @fetch-success="onFetchSuccess">
<template #toolbar>
2 years ago
<a-button type="primary" @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>
2 years ago
</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',
2 years ago
label: t('action.edit'),
2 years ago
onClick: handleEdit.bind(null, record)
},
{
icon: 'ant-design:delete-outlined',
color: 'error',
2 years ago
label: t('action.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>
<DeptModel @register="registerModal" @success="reload()" />
</div>
</template>
2 years ago
<script lang="ts" setup name="Dept">
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 DeptModel from './DeptModel.vue'
2 years ago
import { BasicTable, useTable, TableAction } from '@/components/Table'
2 years ago
import { getListSimpleUsersApi } from '@/api/system/user'
2 years ago
import { deleteDeptApi, getDeptPageApi } from '@/api/system/dept'
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
},
isTreeTable: true,
pagination: false,
striped: false,
useSearchForm: true,
showTableSetting: true,
bordered: true,
showIndexColumn: false,
canResize: false,
actionColumn: {
2 years ago
width: 160,
title: t('common.action'),
2 years ago
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) {
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) {
2 years ago
await deleteDeptApi(record.id)
createMessage.success(t('common.delSuccessText'))
reload()
2 years ago
}
function onFetchSuccess() {
nextTick(expandAll)
}
onMounted(async () => {
await getUserList()
})
</script>