diff --git a/apps/web-antd/src/views/system/dept/data.ts b/apps/web-antd/src/views/system/dept/data.ts index b1fb3d62b..c94cb93fc 100644 --- a/apps/web-antd/src/views/system/dept/data.ts +++ b/apps/web-antd/src/views/system/dept/data.ts @@ -93,7 +93,7 @@ export function useFormSchema(): VbenFormSchema[] { componentProps: { placeholder: '请输入邮箱', }, - rules: z.string().email('请输入正确的邮箱地址').optional(), + rules: z.string().email('邮箱格式不正确').or(z.literal('')).optional(), }, { fieldName: 'status', @@ -118,6 +118,7 @@ export function useGridColumns( { field: 'name', title: '部门名称', + minWidth: 150, align: 'left', fixed: 'left', treeNode: true, @@ -125,15 +126,18 @@ export function useGridColumns( { field: 'leaderUserId', title: '负责人', + minWidth: 150, formatter: ({ cellValue }) => getLeaderName?.(cellValue) || '-', }, { field: 'sort', title: '显示顺序', + minWidth: 100, }, { field: 'status', title: '部门状态', + minWidth: 100, cellRender: { name: 'CellDict', props: { type: DICT_TYPE.COMMON_STATUS }, @@ -142,6 +146,7 @@ export function useGridColumns( { field: 'createTime', title: '创建时间', + minWidth: 180, formatter: 'formatDateTime', }, { diff --git a/apps/web-antd/src/views/system/dept/index.vue b/apps/web-antd/src/views/system/dept/index.vue index e4aa69d9c..9ab792250 100644 --- a/apps/web-antd/src/views/system/dept/index.vue +++ b/apps/web-antd/src/views/system/dept/index.vue @@ -5,7 +5,7 @@ import type { SystemUserApi } from '#/api/system/user'; import { onMounted, ref } from 'vue'; -import { Page, useVbenModal } from '@vben/common-ui'; +import { confirm, Page, useVbenModal } from '@vben/common-ui'; import { isEmpty } from '@vben/utils'; import { message } from 'ant-design-vue'; @@ -61,14 +61,28 @@ function handleEdit(row: SystemDeptApi.Dept) { async function handleDelete(row: SystemDeptApi.Dept) { const hideLoading = message.loading({ content: $t('ui.actionMessage.deleting', [row.name]), - key: 'action_key_msg', + duration: 0, }); try { await deleteDept(row.id as number); - message.success({ - content: $t('ui.actionMessage.deleteSuccess', [row.name]), - key: 'action_key_msg', - }); + message.success($t('ui.actionMessage.deleteSuccess', [row.name])); + onRefresh(); + } finally { + hideLoading(); + } +} + +/** 批量删除部门 */ +async function handleDeleteBatch() { + await confirm($t('ui.actionMessage.deleteBatchConfirm')); + const hideLoading = message.loading({ + content: $t('ui.actionMessage.deletingBatch'), + duration: 0, + }); + try { + await deleteDeptList(checkedIds.value); + checkedIds.value = []; + message.success($t('ui.actionMessage.deleteSuccess')); onRefresh(); } finally { hideLoading(); @@ -84,23 +98,6 @@ function handleRowCheckboxChange({ checkedIds.value = records.map((item) => item.id!); } -/** 批量删除部门 */ -async function handleDeleteBatch() { - const hideLoading = message.loading({ - content: $t('ui.actionMessage.deleting'), - duration: 0, - key: 'action_process_msg', - }); - try { - await deleteDeptList(checkedIds.value); - checkedIds.value = []; - message.success($t('ui.actionMessage.deleteSuccess')); - onRefresh(); - } finally { - hideLoading(); - } -} - const [Grid, gridApi] = useVbenVxeGrid({ gridOptions: { columns: useGridColumns(getLeaderName), @@ -166,9 +163,9 @@ onMounted(async () => { label: '批量删除', type: 'primary', danger: true, - disabled: isEmpty(checkedIds), icon: ACTION_ICON.DELETE, auth: ['system:dept:delete'], + disabled: isEmpty(checkedIds), onClick: handleDeleteBatch, }, ]" @@ -197,7 +194,7 @@ onMounted(async () => { danger: true, icon: ACTION_ICON.DELETE, auth: ['system:dept:delete'], - disabled: !!(row.children && row.children.length > 0), + disabled: row.children && row.children.length > 0, popConfirm: { title: $t('ui.actionMessage.deleteConfirm', [row.name]), confirm: handleDelete.bind(null, row), diff --git a/apps/web-antd/src/views/system/dept/modules/form.vue b/apps/web-antd/src/views/system/dept/modules/form.vue index 16677a642..87b821f3b 100644 --- a/apps/web-antd/src/views/system/dept/modules/form.vue +++ b/apps/web-antd/src/views/system/dept/modules/form.vue @@ -59,21 +59,20 @@ const [Modal, modalApi] = useVbenModal({ return; } // 加载数据 - let data = modalApi.getData(); - if (!data) { + const data = modalApi.getData(); + if (!data || !data.id) { return; } - if (data.id) { - modalApi.lock(); - try { - data = await getDept(data.id); - } finally { - modalApi.unlock(); + modalApi.lock(); + try { + formData.value = await getDept(data.id); + // 设置到 values + if (formData.value) { + await formApi.setValues(formData.value); } + } finally { + modalApi.unlock(); } - // 设置到 values - formData.value = data; - await formApi.setValues(formData.value); }, }); diff --git a/apps/web-ele/src/api/system/dept/index.ts b/apps/web-ele/src/api/system/dept/index.ts index d2677a793..e0c729d32 100644 --- a/apps/web-ele/src/api/system/dept/index.ts +++ b/apps/web-ele/src/api/system/dept/index.ts @@ -45,3 +45,8 @@ export async function updateDept(data: SystemDeptApi.Dept) { export async function deleteDept(id: number) { return requestClient.delete(`/system/dept/delete?id=${id}`); } + +/** 批量删除部门 */ +export async function deleteDeptList(ids: number[]) { + return requestClient.delete(`/system/dept/delete-list?ids=${ids.join(',')}`); +} \ No newline at end of file diff --git a/apps/web-ele/src/views/system/dept/data.ts b/apps/web-ele/src/views/system/dept/data.ts index bc104b8cf..c94cb93fc 100644 --- a/apps/web-ele/src/views/system/dept/data.ts +++ b/apps/web-ele/src/views/system/dept/data.ts @@ -1,8 +1,7 @@ import type { VbenFormSchema } from '#/adapter/form'; -import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table'; +import type { VxeTableGridOptions } from '#/adapter/vxe-table'; import type { SystemDeptApi } from '#/api/system/dept'; -import { useAccess } from '@vben/access'; import { CommonStatusEnum, DICT_TYPE } from '@vben/constants'; import { getDictOptions } from '@vben/hooks'; import { handleTree } from '@vben/utils'; @@ -11,8 +10,6 @@ import { z } from '#/adapter/form'; import { getDeptList } from '#/api/system/dept'; import { getSimpleUserList } from '#/api/system/user'; -const { hasAccessByCodes } = useAccess(); - /** 新增/修改的表单 */ export function useFormSchema(): VbenFormSchema[] { return [ @@ -114,10 +111,10 @@ export function useFormSchema(): VbenFormSchema[] { /** 列表的字段 */ export function useGridColumns( - onActionClick?: OnActionClickFn, getLeaderName?: (userId: number) => string | undefined, ): VxeTableGridOptions['columns'] { return [ + { type: 'checkbox', width: 40 }, { field: 'name', title: '部门名称', @@ -130,9 +127,7 @@ export function useGridColumns( field: 'leaderUserId', title: '负责人', minWidth: 150, - formatter: (row) => { - return getLeaderName?.(row.cellValue) || '-'; - }, + formatter: ({ cellValue }) => getLeaderName?.(cellValue) || '-', }, { field: 'sort', @@ -155,39 +150,10 @@ export function useGridColumns( formatter: 'formatDateTime', }, { - field: 'operation', title: '操作', - minWidth: 200, - align: 'right', + width: 220, fixed: 'right', - headerAlign: 'center', - showOverflow: false, - cellRender: { - attrs: { - nameField: 'name', - nameTitle: '部门', - onClick: onActionClick, - }, - name: 'CellOperation', - options: [ - { - code: 'append', - text: '新增下级', - show: hasAccessByCodes(['system:dept:create']), - }, - { - code: 'edit', - show: hasAccessByCodes(['system:dept:update']), - }, - { - code: 'delete', - show: hasAccessByCodes(['system:dept:delete']), - disabled: (row: SystemDeptApi.Dept) => { - return !!(row.children && row.children.length > 0); - }, - }, - ], - }, + slots: { default: 'actions' }, }, ]; } diff --git a/apps/web-ele/src/views/system/dept/index.vue b/apps/web-ele/src/views/system/dept/index.vue index fa057d648..d8e5b69dd 100644 --- a/apps/web-ele/src/views/system/dept/index.vue +++ b/apps/web-ele/src/views/system/dept/index.vue @@ -1,20 +1,17 @@ diff --git a/apps/web-ele/src/views/system/notice/index.vue b/apps/web-ele/src/views/system/notice/index.vue index 909daba73..fd8fa21a4 100644 --- a/apps/web-ele/src/views/system/notice/index.vue +++ b/apps/web-ele/src/views/system/notice/index.vue @@ -5,7 +5,7 @@ import type { SystemNoticeApi } from '#/api/system/notice'; import { ref } from 'vue'; import { confirm, Page, useVbenModal } from '@vben/common-ui'; -import { downloadFileFromBlobPart, isEmpty } from '@vben/utils'; +import { isEmpty } from '@vben/utils'; import { ElLoading, ElMessage } from 'element-plus'; @@ -14,6 +14,7 @@ import { deleteNotice, deleteNoticeList, getNoticePage, + pushNotice, } from '#/api/system/notice'; import { $t } from '#/locales'; @@ -30,31 +31,31 @@ function onRefresh() { gridApi.query(); } -/** 创建通知公告 */ +/** 创建公告 */ function handleCreate() { formModalApi.setData(null).open(); } -/** 编辑通知公告 */ +/** 编辑公告 */ function handleEdit(row: SystemNoticeApi.Notice) { formModalApi.setData(row).open(); } -/** 删除通知公告 */ +/** 删除公告 */ async function handleDelete(row: SystemNoticeApi.Notice) { const loadingInstance = ElLoading.service({ - text: $t('ui.actionMessage.deleting', [row.id]), + text: $t('ui.actionMessage.deleting', [row.title]), }); try { await deleteNotice(row.id as number); - ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.id])); + ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.title])); onRefresh(); } finally { loadingInstance.close(); } } -/** 批量删除通知公告 */ +/** 批量删除公告 */ async function handleDeleteBatch() { await confirm($t('ui.actionMessage.deleteBatchConfirm')); const loadingInstance = ElLoading.service({ @@ -79,10 +80,17 @@ function handleRowCheckboxChange({ checkedIds.value = records.map((item) => item.id!); } -/** 导出表格 */ -async function handleExport() { - const data = await exportNotice(await gridApi.formApi.getValues()); - downloadFileFromBlobPart({ fileName: '通知公告.xls', source: data }); +/** 推送公告 */ +async function handlePush(row: SystemNoticeApi.Notice) { + const loadingInstance = ElLoading.service({ + text: '正在推送中...', + }); + try { + await pushNotice(row.id as number); + ElMessage.success($t('ui.actionMessage.operationSuccess')); + } finally { + loadingInstance.close(); + } } const [Grid, gridApi] = useVbenVxeGrid({ @@ -123,24 +131,17 @@ const [Grid, gridApi] = useVbenVxeGrid({