liu
3 天以前 fe2d6627b8f1002af7a31b08f6f43bec034d04ee
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { WxCpActivityApi } from '#/api/wxcp/activity';
 
import { ACTIVITY_TYPE } from '#/api/wxcp/activity';
 
import {
  ACTIVITY_STATUS_OPTIONS,
  PUSH_SCOPE_OPTIONS,
  PUSH_STATUS_OPTIONS,
  SIGNUP_STATUS_OPTIONS,
} from '../data';
 
/** 表单类型 */
export type ActivityFormType = 'create' | 'update' | 'detail';
 
/** 活动模板类型选项 */
export const ACTIVITY_TYPE_OPTIONS = [
  {
    label: '纯通知(只推一条文本)',
    value: ACTIVITY_TYPE.TEXT,
  },
  {
    label: '单条消息(可点击卡片)',
    value: ACTIVITY_TYPE.MESSAGE,
  },
  {
    label: '图片通知(上传图片推送)',
    value: ACTIVITY_TYPE.IMAGE,
  },
  {
    label: '附件通知(推送文件供下载)',
    value: ACTIVITY_TYPE.FILE,
  },
  {
    label: '数据采集/评价(填写表单)',
    value: ACTIVITY_TYPE.FORM,
  },
];
 
/** 采集字段类型选项 */
export const FIELD_TYPE_OPTIONS = [
  { label: '单行文本', value: 'text' },
  { label: '多行文本', value: 'textarea' },
  { label: '数字', value: 'number' },
  { label: '日期', value: 'date' },
  { label: '下拉选择', value: 'select' },
  { label: '单选', value: 'radio' },
  { label: '多选', value: 'checkbox' },
  { label: '评分', value: 'rating' },
];
 
const DATETIME_PROPS = {
  showTime: true,
  valueFormat: 'YYYY-MM-DD HH:mm:ss',
  format: 'YYYY-MM-DD HH:mm:ss',
} as const;
 
/** 仅数据采集模板需要报名时间与名额 */
function isFormType(values: Record<string, unknown>) {
  return values.activityType === ACTIVITY_TYPE.FORM;
}
 
/** 活动表单 */
export function useActivityFormSchema(
  formType: ActivityFormType,
): VbenFormSchema[] {
  const readonly = formType === 'detail';
  return [
    {
      fieldName: 'id',
      component: 'Input',
      dependencies: { triggerFields: [''], show: () => false },
    },
    {
      fieldName: 'activityType',
      label: '活动模板',
      component: 'Select',
      componentProps: {
        options: ACTIVITY_TYPE_OPTIONS,
        placeholder: '请选择活动模板',
        disabled: readonly,
      },
      rules: 'required',
      help: '不同模板决定推送形态:纯通知/单条消息/图片/附件,或带表单的数据采集',
      formItemClass: 'col-span-2',
    },
    {
      fieldName: 'title',
      label: '活动标题',
      component: 'Input',
      componentProps: {
        placeholder: '请输入活动标题',
        disabled: readonly,
      },
      rules: 'required',
      formItemClass: 'col-span-2',
    },
    {
      fieldName: 'buttonText',
      label: '按钮文案',
      component: 'Input',
      componentProps: {
        placeholder: '如:查看详情 / 立即报名',
        disabled: readonly,
      },
      dependencies: {
        triggerFields: ['activityType'],
        show: (values) =>
          values.activityType === ACTIVITY_TYPE.MESSAGE ||
          values.activityType === ACTIVITY_TYPE.FORM,
      },
      formItemClass: 'col-span-2',
    },
    {
      fieldName: 'location',
      label: '活动地点',
      component: 'Input',
      componentProps: { placeholder: '如:公司大会议室', disabled: readonly },
      formItemClass: 'col-span-2',
    },
    {
      fieldName: 'startTime',
      label: '活动开始',
      component: 'DatePicker',
      componentProps: { ...DATETIME_PROPS, disabled: readonly },
    },
    {
      fieldName: 'endTime',
      label: '活动结束',
      component: 'DatePicker',
      componentProps: { ...DATETIME_PROPS, disabled: readonly },
    },
    {
      fieldName: 'signupStartTime',
      label: '报名开始',
      component: 'DatePicker',
      componentProps: { ...DATETIME_PROPS, disabled: readonly },
      dependencies: {
        triggerFields: ['activityType'],
        show: isFormType,
      },
    },
    {
      fieldName: 'signupEndTime',
      label: '报名截止',
      component: 'DatePicker',
      componentProps: { ...DATETIME_PROPS, disabled: readonly },
      dependencies: {
        triggerFields: ['activityType'],
        show: isFormType,
      },
    },
    {
      fieldName: 'signupLimit',
      label: '报名上限',
      component: 'InputNumber',
      componentProps: {
        placeholder: '不限请填 0',
        min: 0,
        class: 'w-full',
        disabled: readonly,
      },
      defaultValue: 0,
      rules: 'required',
      help: '填 0 表示不限名额',
      dependencies: {
        triggerFields: ['activityType'],
        show: isFormType,
      },
    },
    {
      // 封面走附件中间表:这里提交 blobIds,回显读 attachmentList(见 form.vue 的映射函数)
      fieldName: 'blobIds',
      label: '封面图',
      component: 'ImageUpload',
      componentProps: {
        valueKey: 'id',
        // 关键:ImageUpload 在 maxNumber=1 时 getValue() 只吐 URL 字符串,
        // form-ui 的 valueKey 转换又要求「值是带 status 的对象数组」,字符串会被跳过,
        // 结果 blobIds 被 normalizeBlobIds 转成 NaN → [],后端把空数组理解为「清空封面」。
        // resultField 非空时组件改返回 item.response(上传响应对象 {url,name,id}),
        // 才拿得到真正的 blobId。
        resultField: 'id',
        maxNumber: 1,
        multiple: false,
        disabled: readonly,
      },
      help: '选填,建议 16:9;保存后展示在活动报名页顶部',
      formItemClass: 'col-span-2',
    },
    {
      fieldName: 'content',
      label: '活动详情',
      component: 'Textarea',
      componentProps: {
        rows: 4,
        placeholder: '活动介绍、注意事项等(报名页按纯文本展示)',
        disabled: readonly,
      },
      formItemClass: 'col-span-2',
    },
    {
      // 详情图片走另一套附件关系(recordType = wxcp_activity_detail),与封面互不影响。
      // 报名页把它排在「活动详情」文字下方、按原图比例完整展示(不裁剪),
      // 所以二维码/海报这类被裁就失效的图必须放这里,别放封面。
      fieldName: 'detailBlobIds',
      label: '详情图片',
      component: 'ImageUpload',
      componentProps: {
        valueKey: 'id',
        resultField: 'id',
        maxNumber: 5,
        multiple: true,
        disabled: readonly,
      },
      help: '选填,最多 5 张;活动页按原图比例完整显示不裁剪,二维码建议放这里',
      formItemClass: 'col-span-2',
    },
    {
      // 图片通知模板:推送时逐张发图片消息(企业微信图片消息)
      fieldName: 'imageBlobIds',
      label: '推送图片',
      component: 'ImageUpload',
      componentProps: {
        valueKey: 'id',
        resultField: 'id',
        maxNumber: 9,
        multiple: true,
        disabled: readonly,
      },
      dependencies: {
        triggerFields: ['activityType'],
        show: (values) => values.activityType === ACTIVITY_TYPE.IMAGE,
      },
      help: '推送时逐张发送图片消息,最多 9 张',
      formItemClass: 'col-span-2',
    },
    {
      // 附件通知模板:推送时逐个发文件消息,接收人可直接下载
      fieldName: 'fileBlobIds',
      label: '推送附件',
      component: 'FileUpload',
      componentProps: {
        valueKey: 'id',
        maxNumber: 5,
        multiple: true,
        showDescription: !readonly,
        disabled: readonly,
      },
      dependencies: {
        triggerFields: ['activityType'],
        show: (values) => values.activityType === ACTIVITY_TYPE.FILE,
      },
      help: '推送时逐个发送文件消息,单个不超过 20MB,最多 5 个',
      formItemClass: 'col-span-2',
    },
    {
      fieldName: 'ratingEnabled',
      label: '开启评价',
      component: 'Switch',
      componentProps: { disabled: readonly },
      dependencies: {
        triggerFields: ['activityType'],
        show: isFormType,
      },
    },
    {
      fieldName: 'ratingTitle',
      label: '评价标题',
      component: 'Input',
      componentProps: {
        placeholder: '如:活动满意度评价',
        disabled: readonly,
      },
      dependencies: {
        triggerFields: ['activityType', 'ratingEnabled'],
        show: (values) => isFormType(values) && values.ratingEnabled === true,
      },
    },
    {
      fieldName: 'ratingMax',
      label: '最高星级',
      component: 'InputNumber',
      componentProps: {
        min: 1,
        max: 10,
        class: 'w-full',
        disabled: readonly,
      },
      defaultValue: 5,
      dependencies: {
        triggerFields: ['activityType', 'ratingEnabled'],
        show: (values) => isFormType(values) && values.ratingEnabled === true,
      },
    },
    {
      fieldName: 'remark',
      label: '备注',
      component: 'Textarea',
      componentProps: { rows: 2, placeholder: '内部备注,不展示给成员', disabled: readonly },
      formItemClass: 'col-span-2',
    },
  ];
}
 
/** 活动搜索表单 */
export function useActivitySearchFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'title',
      label: '活动标题',
      component: 'Input',
      componentProps: { allowClear: true, placeholder: '请输入活动标题' },
    },
    {
      fieldName: 'status',
      label: '状态',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: ACTIVITY_STATUS_OPTIONS,
        placeholder: '请选择状态',
      },
    },
    {
      fieldName: 'pushStatus',
      label: '推送状态',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: PUSH_STATUS_OPTIONS,
        placeholder: '请选择推送状态',
      },
    },
  ];
}
 
/** 活动列表字段 */
export function useActivityGridColumns(): VxeTableGridOptions<WxCpActivityApi.Activity>['columns'] {
  return [
    {
      field: 'activityTypeName',
      title: '模板',
      width: 150,
    },
    {
      field: 'title',
      title: '活动标题',
      minWidth: 200,
      slots: { default: 'title' },
    },
    { field: 'location', title: '活动地点', minWidth: 140 },
    { field: 'startTime', title: '活动开始', width: 170 },
    { field: 'endTime', title: '活动结束', width: 170 },
    {
      field: 'signupCount',
      title: '报名/上限',
      width: 110,
      slots: { default: 'signupCount' },
    },
    {
      field: 'status',
      title: '状态',
      width: 90,
      slots: { default: 'status' },
    },
    {
      field: 'pushStatus',
      title: '推送',
      width: 90,
      slots: { default: 'pushStatus' },
    },
    { field: 'createTime', title: '创建时间', width: 170 },
    { title: '操作', width: 300, fixed: 'right', slots: { default: 'actions' } },
  ];
}
 
/** 报名记录搜索表单 */
export function useSignupSearchFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'name',
      label: '姓名',
      component: 'Input',
      componentProps: { allowClear: true, placeholder: '请输入姓名' },
    },
    {
      fieldName: 'mobile',
      label: '手机号',
      component: 'Input',
      componentProps: { allowClear: true, placeholder: '请输入手机号' },
    },
    {
      fieldName: 'status',
      label: '状态',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: SIGNUP_STATUS_OPTIONS,
        placeholder: '请选择状态',
      },
    },
  ];
}
 
/** 报名记录列表字段 */
export function useSignupGridColumns(): VxeTableGridOptions<WxCpActivityApi.Signup>['columns'] {
  return [
    { field: 'name', title: '姓名', minWidth: 100 },
    { field: 'mobile', title: '手机号', width: 130 },
    { field: 'deptName', title: '部门', minWidth: 120 },
    { field: 'wxUserId', title: '企业微信账号', minWidth: 110 },
    {
      field: 'content',
      title: '参与说明',
      minWidth: 160,
      slots: { default: 'content' },
    },
    {
      field: 'fieldValues',
      title: '采集内容',
      minWidth: 200,
      slots: { default: 'fieldValues' },
    },
    {
      field: 'ratingScore',
      title: '评价',
      width: 80,
      slots: { default: 'ratingScore' },
    },
    {
      field: 'attachment',
      title: '附件',
      width: 80,
      slots: { default: 'attachment' },
    },
    {
      field: 'status',
      title: '状态',
      width: 90,
      slots: { default: 'status' },
    },
    { field: 'signupTime', title: '报名时间', width: 170 },
    { field: 'checkInTime', title: '签到时间', width: 170 },
    { title: '操作', width: 150, fixed: 'right', slots: { default: 'actions' } },
  ];
}