Showing
3 changed files
with
81 additions
and
35 deletions
| ... | @@ -2,7 +2,7 @@ | ... | @@ -2,7 +2,7 @@ |
| 2 | * @Author: hookehuyr hookehuyr@gmail.com | 2 | * @Author: hookehuyr hookehuyr@gmail.com |
| 3 | * @Date: 2022-05-26 23:52:36 | 3 | * @Date: 2022-05-26 23:52:36 |
| 4 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 4 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 5 | - * @LastEditTime: 2024-12-25 18:13:56 | 5 | + * @LastEditTime: 2025-06-04 16:34:33 |
| 6 | * @FilePath: /data-table/src/App.vue | 6 | * @FilePath: /data-table/src/App.vue |
| 7 | * @Description: | 7 | * @Description: |
| 8 | --> | 8 | --> |
| ... | @@ -78,8 +78,9 @@ onMounted(async () => { | ... | @@ -78,8 +78,9 @@ onMounted(async () => { |
| 78 | const flow_node_code = getUrlParams(location.href) ? getUrlParams(location.href).flow_node_code : ''; // flow_node_code 表示随机选择的流程节点的ID | 78 | const flow_node_code = getUrlParams(location.href) ? getUrlParams(location.href).flow_node_code : ''; // flow_node_code 表示随机选择的流程节点的ID |
| 79 | const force_back = getUrlParams(location.href) ? getUrlParams(location.href).force_back : ''; // force_back=1 时,强制按照后台用户模式检查权限 | 79 | const force_back = getUrlParams(location.href) ? getUrlParams(location.href).force_back : ''; // force_back=1 时,强制按照后台用户模式检查权限 |
| 80 | const x_cycle = getUrlParams(location.href) ? getUrlParams(location.href).x_cycle : ''; // 周期ID标识 | 80 | const x_cycle = getUrlParams(location.href) ? getUrlParams(location.href).x_cycle : ''; // 周期ID标识 |
| 81 | + const volunteer_source = getUrlParams(location.href) ? getUrlParams(location.href).volunteer_source : ''; // 义工来源 | ||
| 81 | // 数据收集设置 | 82 | // 数据收集设置 |
| 82 | - const { data } = await getFormSettingAPI({ form_code: code, page_type, data_id, flow_node_code, force_back, x_cycle }); | 83 | + const { data } = await getFormSettingAPI({ form_code: code, page_type, data_id, flow_node_code, force_back, x_cycle, volunteer_source }); |
| 83 | const form_setting = {}; | 84 | const form_setting = {}; |
| 84 | if (data.length) { | 85 | if (data.length) { |
| 85 | Object.assign(form_setting, data[0]['property_list'], data[0]['extend']); | 86 | Object.assign(form_setting, data[0]['property_list'], data[0]['extend']); | ... | ... |
| 1 | /* | 1 | /* |
| 2 | * @Date: 2022-06-17 14:54:29 | 2 | * @Date: 2022-06-17 14:54:29 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2023-02-07 13:23:19 | 4 | + * @LastEditTime: 2025-06-04 16:46:38 |
| 5 | * @FilePath: /data-table/src/api/form.js | 5 | * @FilePath: /data-table/src/api/form.js |
| 6 | * @Description: 表单接口 | 6 | * @Description: 表单接口 |
| 7 | */ | 7 | */ |
| ... | @@ -14,6 +14,7 @@ const Api = { | ... | @@ -14,6 +14,7 @@ const Api = { |
| 14 | ADD_FORM_SETTING: '/srv/?a=add_form_setting', | 14 | ADD_FORM_SETTING: '/srv/?a=add_form_setting', |
| 15 | QUERY_FORM_SETTING: '/srv/?a=query_form_setting', | 15 | QUERY_FORM_SETTING: '/srv/?a=query_form_setting', |
| 16 | VERIFY_PASSWORD: '/srv/?a=verify_password', | 16 | VERIFY_PASSWORD: '/srv/?a=verify_password', |
| 17 | + VOLUNTEER_SOURCE_LEADER: '/srv/?a=volunteer_source_leader', | ||
| 17 | }; | 18 | }; |
| 18 | 19 | ||
| 19 | /** | 20 | /** |
| ... | @@ -67,3 +68,14 @@ export const getFormSettingAPI = (params) => fn(fetch.get(Api.QUERY_FORM_SETTING | ... | @@ -67,3 +68,14 @@ export const getFormSettingAPI = (params) => fn(fetch.get(Api.QUERY_FORM_SETTING |
| 67 | * @returns: | 68 | * @returns: |
| 68 | */ | 69 | */ |
| 69 | export const postVerifyPasswordAPI = (params) => fn(fetch.post(Api.VERIFY_PASSWORD, params)); | 70 | export const postVerifyPasswordAPI = (params) => fn(fetch.post(Api.VERIFY_PASSWORD, params)); |
| 71 | + | ||
| 72 | +/** | ||
| 73 | + * 义工组长按手机号查询义工信息 | ||
| 74 | + * @param form_code 表单唯一标识 | ||
| 75 | + * @param page_type 页面类型 | ||
| 76 | + * @param force_back 是否强制后台账号模式检查权限,1=是,0=否 | ||
| 77 | + * @param volunteer_source 义工报名渠道。self=自己报名,leader=组长给义工报名 | ||
| 78 | + * @param volunteer_phone 义工的手机号 | ||
| 79 | + * @returns | ||
| 80 | + */ | ||
| 81 | +export const getVolunteerSourceLeaderAPI = (params) => fn(fetch.get(Api.VOLUNTEER_SOURCE_LEADER, params)); | ... | ... |
| 1 | <!-- | 1 | <!-- |
| 2 | * @Date: 2022-07-18 10:22:22 | 2 | * @Date: 2022-07-18 10:22:22 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2025-03-27 13:53:23 | 4 | + * @LastEditTime: 2025-06-04 18:15:14 |
| 5 | * @FilePath: /data-table/src/views/index.vue | 5 | * @FilePath: /data-table/src/views/index.vue |
| 6 | * @Description: 首页 | 6 | * @Description: 首页 |
| 7 | --> | 7 | --> |
| ... | @@ -195,7 +195,7 @@ import "@vant/touch-emulator"; // PC上引入时使得表格组件按钮插件 | ... | @@ -195,7 +195,7 @@ import "@vant/touch-emulator"; // PC上引入时使得表格组件按钮插件 |
| 195 | import { createComponentType } from "@/hooks/useComponentType"; | 195 | import { createComponentType } from "@/hooks/useComponentType"; |
| 196 | import { Cookies, $, _, axios, storeToRefs, mainStore, Toast, useTitle, } from "@/utils/generatePackage.js"; | 196 | import { Cookies, $, _, axios, storeToRefs, mainStore, Toast, useTitle, } from "@/utils/generatePackage.js"; |
| 197 | import { useRoute } from "vue-router"; | 197 | import { useRoute } from "vue-router"; |
| 198 | -import { queryFormAPI, postVerifyPasswordAPI } from "@/api/form.js"; | 198 | +import { queryFormAPI, postVerifyPasswordAPI, getVolunteerSourceLeaderAPI } from "@/api/form.js"; |
| 199 | import { addFormDataAPI, queryFormDataAPI, modiFormDataAPI, flowFormDataAPI } from "@/api/data.js"; | 199 | import { addFormDataAPI, queryFormDataAPI, modiFormDataAPI, flowFormDataAPI } from "@/api/data.js"; |
| 200 | import { showSuccessToast, showFailToast, showConfirmDialog, showToast } from "vant"; | 200 | import { showSuccessToast, showFailToast, showConfirmDialog, showToast } from "vant"; |
| 201 | import { wxInfo, getUrlParams, formatDate, prettyLog } from "@/utils/tools"; | 201 | import { wxInfo, getUrlParams, formatDate, prettyLog } from "@/utils/tools"; |
| ... | @@ -238,35 +238,6 @@ const PCommit = ref({}); | ... | @@ -238,35 +238,6 @@ const PCommit = ref({}); |
| 238 | */ | 238 | */ |
| 239 | const formData = ref([]); | 239 | const formData = ref([]); |
| 240 | 240 | ||
| 241 | -// 为每个表单字段创建单独的监听器 | ||
| 242 | -// 可以监听到简单组件的字段的值变化,自定义的组件无法监听到 | ||
| 243 | -const setupFieldWatchers = () => { | ||
| 244 | - formData.value.forEach((field) => { | ||
| 245 | - watch( | ||
| 246 | - () => field.value, | ||
| 247 | - (newValue, oldValue) => { | ||
| 248 | - if (newValue !== oldValue) { | ||
| 249 | - console.log('字段变化:', { | ||
| 250 | - key: field.key, | ||
| 251 | - name: field.name, | ||
| 252 | - oldValue: oldValue, | ||
| 253 | - newValue: newValue | ||
| 254 | - }); | ||
| 255 | - } | ||
| 256 | - } | ||
| 257 | - ); | ||
| 258 | - }); | ||
| 259 | -}; | ||
| 260 | - | ||
| 261 | -// TAG: 监听formData的变化,当有新的字段添加时重新设置监听器 | ||
| 262 | -watch( | ||
| 263 | - () => formData.value, | ||
| 264 | - () => { | ||
| 265 | - setupFieldWatchers(); | ||
| 266 | - }, | ||
| 267 | - { immediate: true } | ||
| 268 | -); | ||
| 269 | - | ||
| 270 | /** | 241 | /** |
| 271 | * 格式化表单数据 | 242 | * 格式化表单数据 |
| 272 | */ | 243 | */ |
| ... | @@ -313,6 +284,8 @@ const x_cycle = $route.query.x_cycle ? $route.query.x_cycle : null; | ... | @@ -313,6 +284,8 @@ const x_cycle = $route.query.x_cycle ? $route.query.x_cycle : null; |
| 313 | const iframe_openid = getUrlParams(location.href) ? getUrlParams(location.href).openid : ''; | 284 | const iframe_openid = getUrlParams(location.href) ? getUrlParams(location.href).openid : ''; |
| 314 | // 强制后台检查标识 | 285 | // 强制后台检查标识 |
| 315 | const force_back = $route.query.force_back ? $route.query.force_back : ''; | 286 | const force_back = $route.query.force_back ? $route.query.force_back : ''; |
| 287 | +// 义工来源 | ||
| 288 | +const volunteer_source = $route.query.volunteer_source ? $route.query.volunteer_source : ''; | ||
| 316 | 289 | ||
| 317 | const notice_text = ref(""); // 顶部提示文字 | 290 | const notice_text = ref(""); // 顶部提示文字 |
| 318 | const show_qrcode = ref(false); // 显示二维码 | 291 | const show_qrcode = ref(false); // 显示二维码 |
| ... | @@ -418,7 +391,7 @@ onMounted(async () => { | ... | @@ -418,7 +391,7 @@ onMounted(async () => { |
| 418 | document | 391 | document |
| 419 | .querySelector("body") | 392 | .querySelector("body") |
| 420 | .setAttribute("style", `background-color: ${styleColor.backgroundColor}`); | 393 | .setAttribute("style", `background-color: ${styleColor.backgroundColor}`); |
| 421 | - const { data, flow_process_list, code } = await queryFormAPI({ form_code: $route.query.code, page_type, data_id, flow_node_code, force_back, openid: iframe_openid, x_cycle }); // flow_node_code 表示随机选择的流程节点的ID | 394 | + const { data, flow_process_list, code } = await queryFormAPI({ form_code: $route.query.code, page_type, data_id, flow_node_code, force_back, openid: iframe_openid, x_cycle, volunteer_source }); // flow_node_code 表示随机选择的流程节点的ID |
| 422 | const form_data = data; | 395 | const form_data = data; |
| 423 | // 处理审批意见显示 | 396 | // 处理审批意见显示 |
| 424 | if (code) { | 397 | if (code) { |
| ... | @@ -1200,6 +1173,66 @@ const onFailed = (errorInfo) => { // 提交表单且验证不通过后触发 | ... | @@ -1200,6 +1173,66 @@ const onFailed = (errorInfo) => { // 提交表单且验证不通过后触发 |
| 1200 | }); | 1173 | }); |
| 1201 | showToast(error_name + ': ' + error_item.message); | 1174 | showToast(error_name + ': ' + error_item.message); |
| 1202 | } | 1175 | } |
| 1176 | + | ||
| 1177 | +// TAG: 监听formData的变化,当有新的字段添加时重新设置监听器 | ||
| 1178 | +watch( | ||
| 1179 | + () => formData.value, | ||
| 1180 | + () => { | ||
| 1181 | + setupFieldWatchers(); | ||
| 1182 | + }, | ||
| 1183 | + { | ||
| 1184 | + immediate: false, // 是否在初始化时立即执行一次回调 | ||
| 1185 | + flush: 'post', // 在组件更新后执行(可访问 DOM) | ||
| 1186 | + } | ||
| 1187 | +); | ||
| 1188 | + | ||
| 1189 | +// 为每个表单字段创建单独的监听器 | ||
| 1190 | +// 可以监听到简单组件的字段的值变化,自定义的组件无法监听到 | ||
| 1191 | +const setupFieldWatchers = () => { | ||
| 1192 | + formData.value.forEach((field) => { | ||
| 1193 | + watch( | ||
| 1194 | + () => field.value, | ||
| 1195 | + (newValue, oldValue) => { | ||
| 1196 | + if (newValue !== oldValue) { | ||
| 1197 | + console.log('字段变化:', { | ||
| 1198 | + key: field.key, | ||
| 1199 | + name: field.name, | ||
| 1200 | + comment: field.component_props.comment, | ||
| 1201 | + oldValue: oldValue, | ||
| 1202 | + newValue: newValue | ||
| 1203 | + }); | ||
| 1204 | + // TAG: 大义工新增功能 | ||
| 1205 | + /** | ||
| 1206 | + * 必须表单是新增表单时才触发 | ||
| 1207 | + * 如果别名是手机号, 并且是11位, 类型是义工,设置义工数据 | ||
| 1208 | + */ | ||
| 1209 | + if (volunteer_source === 'leader' | ||
| 1210 | + && field.component_props.comment === 'phone' | ||
| 1211 | + && (/^1\d{10}$/).test(newValue) | ||
| 1212 | + && ( page_type === 'add' || page_type === undefined) | ||
| 1213 | + ) { | ||
| 1214 | + // 设置义工数据 | ||
| 1215 | + setVolunteerData(newValue); | ||
| 1216 | + } | ||
| 1217 | + } | ||
| 1218 | + } | ||
| 1219 | + ); | ||
| 1220 | + }); | ||
| 1221 | +}; | ||
| 1222 | + | ||
| 1223 | +// 获取义工信息 | ||
| 1224 | +const setVolunteerData = async (volunteer_phone) => { | ||
| 1225 | + const volunteer_data = await getVolunteerSourceLeaderAPI({ form_code: $route.query.code, force_back, page_type, volunteer_source, volunteer_phone }); | ||
| 1226 | + if (volunteer_data.code) { | ||
| 1227 | + let object = volunteer_data.data; | ||
| 1228 | + const objectMap = new Map(Object.entries(object)); // 将 object 转换为 Map,Object.entries() 方法用于返回一个给定对象自身可枚举属性的键值对数组,数组中的每个元素是一个包含键值对的数组,[ ["name", "Alice"], ["age", 30], ["city", "New York"] ] | ||
| 1229 | + formData.value.forEach((item) => { | ||
| 1230 | + if (objectMap.has(item.key)) { | ||
| 1231 | + item.component_props.default = objectMap.get(item.key); | ||
| 1232 | + } | ||
| 1233 | + }); | ||
| 1234 | + } | ||
| 1235 | +} | ||
| 1203 | </script> | 1236 | </script> |
| 1204 | 1237 | ||
| 1205 | <style lang="less"> | 1238 | <style lang="less"> | ... | ... |
-
Please register or login to post a comment