| | |
| | | > |
| | | <template #left> |
| | | <ElSpace wrap> |
| | | <ElButton v-auth="'add'" @click="handleAdd" v-ripple>新增部门</ElButton> |
| | | <ElButton v-auth="'add'" @click="handleAdd" v-ripple>{{ t('pages.system.dept.buttons.add') }}</ElButton> |
| | | <ElButton @click="toggleExpand" v-ripple> |
| | | {{ isExpanded ? '收起' : '展开' }} |
| | | {{ isExpanded ? t('common.actions.collapse') : t('common.actions.expand') }} |
| | | </ElButton> |
| | | </ElSpace> |
| | | </template> |
| | |
| | | |
| | | <script setup> |
| | | import { ElMessage, ElMessageBox } from 'element-plus' |
| | | import { useI18n } from 'vue-i18n' |
| | | import { guardRequestWithMessage } from '@/utils/sys/requestGuard' |
| | | import { useTableColumns } from '@/hooks/core/useTableColumns' |
| | | import { |
| | |
| | | |
| | | defineOptions({ name: 'Dept' }) |
| | | |
| | | const { t } = useI18n() |
| | | const loading = ref(false) |
| | | const isExpanded = ref(false) |
| | | const tableRef = ref() |
| | |
| | | |
| | | const searchItems = computed(() => [ |
| | | { |
| | | label: '部门名称', |
| | | label: t('pages.system.dept.table.name'), |
| | | key: 'condition', |
| | | type: 'input', |
| | | props: { |
| | | clearable: true, |
| | | placeholder: '请输入部门名称' |
| | | placeholder: t('pages.system.dept.search.conditionPlaceholder') |
| | | } |
| | | } |
| | | ]) |
| | | |
| | | const { columnChecks, columns } = useTableColumns(() => |
| | | createDeptTableColumns({ |
| | | t, |
| | | handleEdit: handleEdit, |
| | | handleDelete: handleDelete |
| | | }) |
| | |
| | | fetchGetDeptTree(buildDeptSearchParams(searchForm)), |
| | | [], |
| | | { |
| | | timeoutMessage: '部门加载超时,已停止等待' |
| | | timeoutMessage: t('pages.system.dept.messages.pageTimeout') |
| | | } |
| | | ) |
| | | const normalizedRows = normalizeDeptTreeRows(tree || []) |
| | |
| | | deptTreeOptions.value = buildDeptTreeOptions(tableData.value, row.id) |
| | | dialogVisible.value = true |
| | | } catch (error) { |
| | | ElMessage.error(error?.message || '获取部门详情失败') |
| | | ElMessage.error(error?.message || t('pages.system.dept.messages.detailFailed')) |
| | | } |
| | | } |
| | | |
| | | async function handleDelete(row) { |
| | | try { |
| | | await ElMessageBox.confirm(`确定要删除部门「${row.name || row.id}」吗?`, '删除确认', { |
| | | confirmButtonText: '确定', |
| | | cancelButtonText: '取消', |
| | | type: 'warning' |
| | | }) |
| | | await ElMessageBox.confirm( |
| | | t('crud.confirm.deleteMessage', { |
| | | entity: t('pages.system.dept.entity'), |
| | | label: row.name || row.id |
| | | }), |
| | | t('crud.confirm.deleteTitle'), |
| | | { |
| | | confirmButtonText: t('common.confirm'), |
| | | cancelButtonText: t('common.cancel'), |
| | | type: 'warning' |
| | | } |
| | | ) |
| | | await fetchDeleteDept(row.id) |
| | | ElMessage.success('删除成功') |
| | | ElMessage.success(t('crud.messages.deleteSuccess')) |
| | | await loadDeptTree() |
| | | } catch (error) { |
| | | if (error !== 'cancel') { |
| | | ElMessage.error(error?.message || '删除失败') |
| | | ElMessage.error(error?.message || t('crud.messages.deleteFailed')) |
| | | } |
| | | } |
| | | } |
| | |
| | | async function handleDialogSubmit(formData) { |
| | | const payload = buildDeptSavePayload(formData) |
| | | if (payload.id && payload.id === payload.parentId) { |
| | | ElMessage.error('上级部门不能选择当前部门') |
| | | ElMessage.error(t('pages.system.dept.messages.parentSelfInvalid')) |
| | | return |
| | | } |
| | | |
| | | try { |
| | | if (payload.id) { |
| | | await fetchUpdateDept(payload) |
| | | ElMessage.success('修改成功') |
| | | ElMessage.success(t('crud.messages.updateSuccess')) |
| | | } else { |
| | | await fetchSaveDept(payload) |
| | | ElMessage.success('新增成功') |
| | | ElMessage.success(t('crud.messages.createSuccess')) |
| | | } |
| | | dialogVisible.value = false |
| | | currentDeptData.value = buildDeptDialogModel() |
| | | await loadDeptTree() |
| | | } catch (error) { |
| | | ElMessage.error(error?.message || '提交失败') |
| | | ElMessage.error(error?.message || t('crud.messages.submitFailed')) |
| | | } |
| | | } |
| | | |