hookehuyr

refactor(感恩模块): 优化感恩对象字段命名和表单处理逻辑

将接口中的 gratitude_people 字段统一改为 gratitude_form_list 以保持一致性
优化 AddTargetDialog 组件对初始值的处理逻辑
删除不再使用的 gratitude.js 接口文件
1 /* 1 /*
2 * @Date: 2025-06-06 09:26:16 2 * @Date: 2025-06-06 09:26:16
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2025-12-17 09:47:48 4 + * @LastEditTime: 2025-12-17 10:31:54
5 * @FilePath: /mlaj/src/api/checkin.js 5 * @FilePath: /mlaj/src/api/checkin.js
6 * @Description: 签到模块相关接口 6 * @Description: 签到模块相关接口
7 */ 7 */
...@@ -102,7 +102,7 @@ export const addUploadTaskAPI = (params) => fn(fetch.post(Api.TASK_UPLOAD_ADD, ...@@ -102,7 +102,7 @@ export const addUploadTaskAPI = (params) => fn(fetch.post(Api.TASK_UPLOAD_ADD,
102 * file_type 上传附件的类型 image=上传图片,video=视频,audio=音频, like_count 点赞数, is_my 是不是我的打卡, is_like 我是否已经点赞, is_makeup 是否补卡 102 * file_type 上传附件的类型 image=上传图片,video=视频,audio=音频, like_count 点赞数, is_my 是不是我的打卡, is_like 我是否已经点赞, is_makeup 是否补卡
103 * subtask_title 小作业标题 103 * subtask_title 小作业标题
104 * gratitude_count 感恩次数 104 * gratitude_count 感恩次数
105 - * gratitude_people 感恩对象列表 [{id,name,city,unit}] 105 + * gratitude_form_list 感恩对象列表 [{id,name,city,unit}]
106 * }] 106 * }]
107 */ 107 */
108 export const getUploadTaskListAPI = (params) => fn(fetch.post(Api.TASK_UPLOAD_LIST, params)) 108 export const getUploadTaskListAPI = (params) => fn(fetch.post(Api.TASK_UPLOAD_LIST, params))
......
1 -/*
2 - * @Date: 2025-06-06 09:26:16
3 - * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2025-12-16 17:52:19
5 - * @FilePath: /mlaj/src/api/gratitude.js
6 - * @Description: 计数模块相关接口
7 - */
8 -
9 -import { fn, fetch } from './fn'
10 -
11 -const Api = {
12 - GET_GRATITUDE_LIST: '/srv/?a=gratitude_people&t=list',
13 - POST_GRATITUDE_ADD: '/srv/?a=gratitude_people&t=add',
14 - POST_GRATITUDE_EDIT: '/srv/?a=gratitude_people&t=edit',
15 - POST_GRATITUDE_DEL: '/srv/?a=gratitude_people&t=del',
16 -}
17 -
18 -/**
19 - * @description: 计数对象列表
20 - * @param: person_type 计数对象类型 teacher=老师, doctor=医生, parent=父母, sage=圣贤
21 - * @return: data.gratitude_people [{ id 计数对象ID, name 计数对象名称, city 地址, unit 单位 }]
22 - */
23 -
24 -export const getGratitudeListAPI = (params) => fn(fetch.get(Api.GET_GRATITUDE_LIST, params))
25 -
26 -/**
27 - * @description: 添加感恩对象
28 - * @param person_type 计数对象类型 teacher=老师, doctor=医生, parent=父母, sage=圣贤
29 - * 下面的值应该是动态字段绑定的值, 通过field_list获取里面的field_name, 再根据field_name绑定值
30 - * @param name 感恩对象名称
31 - * @param city 地址
32 - * @param unit 单位
33 - * @returns
34 - */
35 -export const gratitudeAddAPI = (params) => fn(fetch.post(Api.POST_GRATITUDE_ADD, params))
36 -
37 -/**
38 - * @description: 编辑感恩对象
39 - * @param id 感恩对象ID
40 - * 下面的值应该是动态字段绑定的值, 通过field_list获取里面的field_name, 再根据field_name绑定值
41 - * @param name 感恩对象名称
42 - * @param city 地址
43 - * @param unit 单位
44 - * @returns
45 - */
46 -export const gratitudeEditAPI = (params) => fn(fetch.post(Api.POST_GRATITUDE_EDIT, params))
47 -
48 -/**
49 - * @description: 删除感恩对象
50 - * @param id 感恩对象ID
51 - * @returns
52 - */
53 -export const gratitudeDelAPI = (params) => fn(fetch.post(Api.POST_GRATITUDE_DEL, params))
...@@ -67,14 +67,17 @@ const emit = defineEmits(['update:show', 'confirm']) ...@@ -67,14 +67,17 @@ const emit = defineEmits(['update:show', 'confirm'])
67 // 本地表单字段状态 67 // 本地表单字段状态
68 const localFields = ref([]) 68 const localFields = ref([])
69 69
70 -// 监听弹窗显示状态和字段配置变化,初始化表单 70 +// 监听弹窗显示状态、字段配置和初始值的变化
71 -watch([() => props.show, () => props.fields], ([showVal, fieldsVal]) => { 71 +watch([() => props.show, () => props.fields, () => props.initialValues], ([showVal, fieldsVal, initialValuesVal]) => {
72 if (showVal) { 72 if (showVal) {
73 // 初始化字段,添加 value 属性 73 // 初始化字段,添加 value 属性
74 - localFields.value = fieldsVal.map(field => ({ 74 + localFields.value = fieldsVal.map(field => {
75 - ...field, 75 + const val = (initialValuesVal && initialValuesVal[field.id]);
76 - value: (props.initialValues && props.initialValues[field.id]) || '' 76 + return {
77 - })) 77 + ...field,
78 + value: val || ''
79 + }
80 + })
78 } 81 }
79 }, { immediate: true, deep: true }) 82 }, { immediate: true, deep: true })
80 83
......
...@@ -228,7 +228,7 @@ const taskOptions = ref([]) ...@@ -228,7 +228,7 @@ const taskOptions = ref([])
228 const fetchTargetList = async (subtask_id) => { 228 const fetchTargetList = async (subtask_id) => {
229 const { code, data } = await reuseGratitudeFormAPI({ subtask_id }) 229 const { code, data } = await reuseGratitudeFormAPI({ subtask_id })
230 if (code) { 230 if (code) {
231 - targetList.value = data.gratitude_people || [] 231 + targetList.value = data || []
232 } 232 }
233 } 233 }
234 234
...@@ -245,7 +245,7 @@ const updateDynamicFormFields = (option) => { ...@@ -245,7 +245,7 @@ const updateDynamicFormFields = (option) => {
245 // 处理动态表单字段 245 // 处理动态表单字段
246 dynamicFormFields.value = option.field_list.map(field => { 246 dynamicFormFields.value = option.field_list.map(field => {
247 return { 247 return {
248 - id: field.field, 248 + id: field.field || field.field_name || field.name || field.id, // 兼容多种字段名
249 label: field.label || '未命名', 249 label: field.label || '未命名',
250 type: field.type || 'text', // 默认类型,如果后端有类型字段可替换 250 type: field.type || 'text', // 默认类型,如果后端有类型字段可替换
251 required: true // 默认必填,如果后端有必填字段可替换 251 required: true // 默认必填,如果后端有必填字段可替换
......