From 99797f6618817421c6c0ef3a4c01fa64962053cd Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sun, 6 Apr 2025 09:53:19 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E5=A2=9E=E5=8A=A0=20notice=20?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/web-antd/src/api/system/notice/index.ts | 46 +++++ apps/web-antd/src/views/system/notice/data.ts | 170 ++++++++++++++++++ .../src/views/system/notice/index.vue | 135 ++++++++++++++ .../src/views/system/notice/modules/form.vue | 77 ++++++++ 4 files changed, 428 insertions(+) create mode 100644 apps/web-antd/src/api/system/notice/index.ts create mode 100644 apps/web-antd/src/views/system/notice/data.ts create mode 100644 apps/web-antd/src/views/system/notice/index.vue create mode 100644 apps/web-antd/src/views/system/notice/modules/form.vue diff --git a/apps/web-antd/src/api/system/notice/index.ts b/apps/web-antd/src/api/system/notice/index.ts new file mode 100644 index 000000000..260bb501f --- /dev/null +++ b/apps/web-antd/src/api/system/notice/index.ts @@ -0,0 +1,46 @@ +import { requestClient } from '#/api/request'; +import type { PageParam, PageResult } from '@vben/request'; + +export namespace SystemNoticeApi { + /** 公告信息 */ + export interface SystemNotice { + id?: number; + title: string; + type: number; + content: string; + status: number; + remark: string; + creator?: string; + createTime?: Date; + } +} + +/** 查询公告列表 */ +export function getNoticePage(params: PageParam) { + return requestClient.get>('/system/notice/page', { params }); +} + +/** 查询公告详情 */ +export function getNotice(id: number) { + return requestClient.get(`/system/notice/get?id=${id}`); +} + +/** 新增公告 */ +export function createNotice(data: SystemNoticeApi.SystemNotice) { + return requestClient.post('/system/notice/create', data); +} + +/** 修改公告 */ +export function updateNotice(data: SystemNoticeApi.SystemNotice) { + return requestClient.put('/system/notice/update', data); +} + +/** 删除公告 */ +export function deleteNotice(id: number) { + return requestClient.delete(`/system/notice/delete?id=${id}`); +} + +/** 推送公告 */ +export function pushNotice(id: number) { + return requestClient.post(`/system/notice/push?id=${id}`); +} diff --git a/apps/web-antd/src/views/system/notice/data.ts b/apps/web-antd/src/views/system/notice/data.ts new file mode 100644 index 000000000..2e1bfb626 --- /dev/null +++ b/apps/web-antd/src/views/system/notice/data.ts @@ -0,0 +1,170 @@ +import {type VbenFormSchema, z} from '#/adapter/form'; +import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table'; +import type { SystemNoticeApi } from '#/api/system/notice'; + +import { DICT_TYPE, getDictOptions } from '#/utils/dict'; +import { CommonStatusEnum } from '#/utils/constants'; +import { useAccess } from '@vben/access'; + +const { hasAccessByCodes } = useAccess(); + +/** 新增/修改的表单 */ +export function useFormSchema(): VbenFormSchema[] { + return [ + { + fieldName: 'id', + label: 'id', + component: 'Input', + dependencies: { + triggerFields: [''], + show: () => false, + }, + }, + { + fieldName: 'title', + label: '公告标题', + component: 'Input', + rules: 'required', + }, + { + fieldName: 'type', + label: '公告类型', + component: 'RadioGroup', + componentProps: { + options: getDictOptions(DICT_TYPE.SYSTEM_NOTICE_TYPE, 'number'), + buttonStyle: 'solid', + optionType: 'button', + }, + rules: 'required', + }, + { + fieldName: 'content', + label: '公告内容', + component: 'Textarea', + componentProps: { + placeholder: '请输入公告内容', + }, + // component: 'Editor', // TODO @芋艿:富文本编辑器 + // componentProps: { + // height: '200px', + // }, + rules: 'required', + }, + { + fieldName: 'status', + label: '公告状态', + component: 'RadioGroup', + componentProps: { + options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'), + buttonStyle: 'solid', + optionType: 'button', + }, + rules: z.number().default(CommonStatusEnum.ENABLE), + }, + { + fieldName: 'remark', + label: '备注', + component: 'Textarea', + componentProps: { + placeholder: '请输入备注', + } + }, + ]; +} + +/** 列表的搜索表单 */ +export function useGridFormSchema(): VbenFormSchema[] { + return [ + { + fieldName: 'title', + label: '公告标题', + component: 'Input', + componentProps: { + placeholder: '请输入公告标题', + allowClear: true, + } + }, + { + fieldName: 'status', + label: '公告状态', + component: 'Select', + componentProps: { + options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'), + placeholder: '请选择公告状态', + allowClear: true, + }, + } + ]; +} + +/** 列表的字段 */ +export function useGridColumns( + onActionClick: OnActionClickFn, +): VxeTableGridOptions['columns'] { + return [ + { + field: 'id', + title: '公告编号', + minWidth: 100, + }, + { + field: 'title', + title: '公告标题', + minWidth: 200, + }, + { + field: 'type', + title: '公告类型', + minWidth: 100, + cellRender: { + name: 'CellDict', + props: { type: DICT_TYPE.SYSTEM_NOTICE_TYPE }, + }, + }, + { + field: 'status', + title: '公告状态', + minWidth: 100, + cellRender: { + name: 'CellDict', + props: { type: DICT_TYPE.COMMON_STATUS }, + }, + }, + { + field: 'createTime', + title: '创建时间', + minWidth: 180, + formatter: 'formatDateTime', + }, + { + field: 'operation', + title: '操作', + minWidth: 180, + align: 'center', + fixed: 'right', + cellRender: { + attrs: { + nameField: 'title', + nameTitle: '公告', + onClick: onActionClick, + }, + name: 'CellOperation', + options: [ + { + code: 'edit', + show: hasAccessByCodes(['system:notice:update']), + }, + { + code: 'push', + text: '推送', + show: hasAccessByCodes(['system:notice:update']), + }, + { + code: 'delete', + show: hasAccessByCodes(['system:notice:delete']), + }, + ], + }, + }, + ]; +} diff --git a/apps/web-antd/src/views/system/notice/index.vue b/apps/web-antd/src/views/system/notice/index.vue new file mode 100644 index 000000000..e3c1aa35a --- /dev/null +++ b/apps/web-antd/src/views/system/notice/index.vue @@ -0,0 +1,135 @@ + + + \ No newline at end of file diff --git a/apps/web-antd/src/views/system/notice/modules/form.vue b/apps/web-antd/src/views/system/notice/modules/form.vue new file mode 100644 index 000000000..1285af8a0 --- /dev/null +++ b/apps/web-antd/src/views/system/notice/modules/form.vue @@ -0,0 +1,77 @@ + + +