liu
3 天以前 2b695bfabdceccb0ee19c12c8e655bd7f47a6e2f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { WxCpNoticeApi } from '#/api/wxcp/notice';
 
import { NOTICE_STATUS_OPTIONS, PUSH_STATUS_OPTIONS } from '../data';
 
/** 表单类型 */
export type NoticeFormType = 'create' | 'update' | 'detail';
 
/** 通知模板类型 */
export const NOTICE_TYPE = {
  TEXT: 1,
  CARD: 2,
  FILE: 3,
  NEWS: 4,
  IMAGE: 5,
  VIDEO: 6,
  MARKDOWN: 7,
  MULTI_NEWS: 8,
} as const;
 
export const NOTICE_TYPE_OPTIONS = [
  { label: '纯文本通知', value: NOTICE_TYPE.TEXT },
  { label: '图文卡片(填报/链接)', value: NOTICE_TYPE.CARD },
  { label: '文件通知(上传文件推送)', value: NOTICE_TYPE.FILE },
  { label: '图片通知(上传图片推送)', value: NOTICE_TYPE.IMAGE },
  { label: '视频通知(上传视频推送)', value: NOTICE_TYPE.VIDEO },
  { label: 'Markdown 通知(富文本排版)', value: NOTICE_TYPE.MARKDOWN },
  { label: '多图文消息(多条链接图文)', value: NOTICE_TYPE.MULTI_NEWS },
  { label: '图文消息(标题+摘要+封面)', value: NOTICE_TYPE.NEWS },
];
 
/** 通知表单 */
export function useNoticeFormSchema(formType: NoticeFormType): VbenFormSchema[] {
  const readonly = formType === 'detail';
  return [
    {
      fieldName: 'id',
      component: 'Input',
      dependencies: { triggerFields: [''], show: () => false },
    },
    {
      fieldName: 'noticeType',
      label: '通知模板',
      component: 'Select',
      componentProps: {
        options: NOTICE_TYPE_OPTIONS,
        placeholder: '请选择通知模板',
        disabled: readonly,
      },
      rules: 'required',
    },
    {
      fieldName: 'title',
      label: '通知标题',
      component: 'Input',
      componentProps: { placeholder: '请输入通知标题', disabled: readonly },
      rules: 'required',
    },
    {
      fieldName: 'content',
      label: '通知正文',
      component: 'Textarea',
      componentProps: {
        rows: 6,
        placeholder: '纯文本通知必填;其它模板可作为补充说明',
        disabled: readonly,
      },
      help: '纯文本推送超过 600 字会自动截断;Markdown 模板支持 # 标题、**加粗**、- 列表、> 引用,正文需控制在 2048 字节内',
      formItemClass: 'col-span-2',
    },
    {
      fieldName: 'summary',
      label: '摘要',
      component: 'Textarea',
      componentProps: {
        rows: 3,
        placeholder: '图文卡片/图文消息展示的摘要',
        disabled: readonly,
      },
      dependencies: {
        triggerFields: ['noticeType'],
        show: (values) =>
          values.noticeType === NOTICE_TYPE.CARD ||
          values.noticeType === NOTICE_TYPE.NEWS,
      },
      formItemClass: 'col-span-2',
    },
    {
      fieldName: 'linkUrl',
      label: '跳转链接',
      component: 'Input',
      componentProps: {
        placeholder: '填报页面或详情页地址,如 https://...',
        disabled: readonly,
      },
      dependencies: {
        triggerFields: ['noticeType'],
        show: (values) =>
          values.noticeType === NOTICE_TYPE.CARD ||
          values.noticeType === NOTICE_TYPE.NEWS,
      },
      formItemClass: 'col-span-2',
    },
    {
      fieldName: 'linkBtnText',
      label: '按钮文案',
      component: 'Input',
      componentProps: {
        placeholder: '如:去填报 / 查看详情',
        disabled: readonly,
      },
      dependencies: {
        triggerFields: ['noticeType'],
        show: (values) => values.noticeType === NOTICE_TYPE.CARD,
      },
    },
    {
      fieldName: 'coverUrl',
      label: '封面图地址',
      component: 'Input',
      componentProps: {
        placeholder: '图文消息封面图地址(选填)',
        disabled: readonly,
      },
      dependencies: {
        triggerFields: ['noticeType'],
        show: (values) => values.noticeType === NOTICE_TYPE.NEWS,
      },
      formItemClass: 'col-span-2',
    },
    {
      // 图片通知:推送时逐张发送图片消息,最多 9 张
      fieldName: 'imageBlobIds',
      label: '推送图片',
      component: 'ImageUpload',
      componentProps: {
        valueKey: 'id',
        resultField: 'id',
        maxNumber: 9,
        multiple: true,
        disabled: readonly,
      },
      dependencies: {
        triggerFields: ['noticeType'],
        show: (values) => values.noticeType === NOTICE_TYPE.IMAGE,
      },
      help: '推送时逐张发送图片消息,单张不超过 10MB,最多 9 张;推送后附「查看全部图片」卡片,成员可在页面内放大查看',
      formItemClass: 'col-span-2',
    },
    {
      // 附件通知:推送时逐个发文件消息,接收人可直接下载
      fieldName: 'fileBlobIds',
      label: '推送附件',
      component: 'FileUpload',
      componentProps: {
        valueKey: 'id',
        maxNumber: 5,
        multiple: true,
        showDescription: !readonly,
        disabled: readonly,
      },
      dependencies: {
        triggerFields: ['noticeType'],
        show: (values) => values.noticeType === NOTICE_TYPE.FILE,
      },
      help: '推送时逐个发送文件消息,单个不超过 20MB,最多 5 个;推送后附「查看全部附件」卡片',
      formItemClass: 'col-span-2',
    },
    {
      // 视频通知:上传 1 个视频,推送时发送视频消息
      fieldName: 'videoBlobIds',
      label: '推送视频',
      component: 'FileUpload',
      componentProps: {
        valueKey: 'id',
        maxNumber: 1,
        multiple: false,
        accept: ['mp4', 'mov', 'm4v'],
        showDescription: !readonly,
        disabled: readonly,
      },
      dependencies: {
        triggerFields: ['noticeType'],
        show: (values) => values.noticeType === NOTICE_TYPE.VIDEO,
      },
      help: '推送时发送视频消息,建议使用 mp4,单个不超过 10MB;推送后附「查看通知详情」卡片,成员可全屏播放',
      formItemClass: 'col-span-2',
    },
    {
      fieldName: 'remark',
      label: '备注',
      component: 'Textarea',
      componentProps: { rows: 2, placeholder: '内部备注,不推送', disabled: readonly },
      formItemClass: 'col-span-2',
    },
  ];
}
 
/** 通知搜索表单 */
export function useNoticeSearchFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'title',
      label: '通知标题',
      component: 'Input',
      componentProps: { allowClear: true, placeholder: '请输入通知标题' },
    },
    {
      fieldName: 'status',
      label: '状态',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: NOTICE_STATUS_OPTIONS,
        placeholder: '请选择状态',
      },
    },
    {
      fieldName: 'pushStatus',
      label: '推送状态',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: PUSH_STATUS_OPTIONS,
        placeholder: '请选择推送状态',
      },
    },
  ];
}
 
/** 通知列表字段 */
export function useNoticeGridColumns(): VxeTableGridOptions<WxCpNoticeApi.Notice>['columns'] {
  return [
    {
      field: 'noticeTypeName',
      title: '模板',
      width: 150,
    },
    {
      field: 'title',
      title: '通知标题',
      minWidth: 220,
      slots: { default: 'title' },
    },
    {
      field: 'content',
      title: '正文摘要',
      minWidth: 260,
      slots: { default: 'content' },
    },
    {
      field: 'status',
      title: '状态',
      width: 90,
      slots: { default: 'status' },
    },
    {
      field: 'pushScopeName',
      title: '推送范围',
      width: 110,
    },
    {
      field: 'pushStatus',
      title: '推送',
      width: 90,
      slots: { default: 'pushStatus' },
    },
    { field: 'pushTime', title: '推送时间', width: 170 },
    { field: 'createTime', title: '创建时间', width: 170 },
    { title: '操作', width: 220, fixed: 'right', slots: { default: 'actions' } },
  ];
}