hookehuyr

fix 代码整理

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: 2024-08-14 13:43:10 4 + * @LastEditTime: 2024-08-14 14:28:08
5 * @FilePath: /data-table/src/views/index.vue 5 * @FilePath: /data-table/src/views/index.vue
6 * @Description: 首页 6 * @Description: 首页
7 --> 7 -->
...@@ -133,7 +133,7 @@ ...@@ -133,7 +133,7 @@
133 <!-- TODO: 签到二维码,待用 --> 133 <!-- TODO: 签到二维码,待用 -->
134 <!-- <van-image width="50" height="50" src="https://oa-dev.onwall.cn/admin/?a=get_qrcode&m=srv&key=123'"></van-image> --> 134 <!-- <van-image width="50" height="50" src="https://oa-dev.onwall.cn/admin/?a=get_qrcode&m=srv&key=123'"></van-image> -->
135 </div> 135 </div>
136 - <van-overlay :show="show"> 136 + <van-overlay :show="show_qrcode">
137 <div class="wrapper"> 137 <div class="wrapper">
138 <div class="block"> 138 <div class="block">
139 <div style="text-align: center; margin-top: 0.5rem;">请先关注公众号</div> 139 <div style="text-align: center; margin-top: 0.5rem;">请先关注公众号</div>
...@@ -204,19 +204,22 @@ import { sharePage } from '@/composables/useShare.js' ...@@ -204,19 +204,22 @@ import { sharePage } from '@/composables/useShare.js'
204 import wx from 'weixin-js-sdk' 204 import wx from 'weixin-js-sdk'
205 import LoginBox from '@/components/LoginBox/index.vue'; 205 import LoginBox from '@/components/LoginBox/index.vue';
206 206
207 +const $route = useRoute();
208 +const $router = useRouter();
209 +
207 // 获取表单设置 210 // 获取表单设置
208 const store = mainStore(); 211 const store = mainStore();
209 const { formSetting, formInfo, successInfo } = storeToRefs(store); 212 const { formSetting, formInfo, successInfo } = storeToRefs(store);
210 213
211 -// web端判断封面图片高度 214 +// // web端判断封面图片高度
212 -const is_pc = computed(() => wxInfo().isPC); 215 +// const is_pc = computed(() => wxInfo().isPC);
213 -const PHeaderHeight = computed(() => { 216 +// const PHeaderHeight = computed(() => {
214 - if (is_pc.value) { 217 +// if (is_pc.value) {
215 - return "35vh"; 218 +// return "35vh";
216 - } else { 219 +// } else {
217 - return "20vh"; 220 +// return "20vh";
218 - } 221 +// }
219 -}); 222 +// });
220 223
221 // TAG: 自定义主题颜色 224 // TAG: 自定义主题颜色
222 const themeVars = { 225 const themeVars = {
...@@ -225,15 +228,39 @@ const themeVars = { ...@@ -225,15 +228,39 @@ const themeVars = {
225 pickerConfirmActionColor: styleColor.baseColor, 228 pickerConfirmActionColor: styleColor.baseColor,
226 }; 229 };
227 230
228 -const $route = useRoute();
229 -const $router = useRouter();
230 const PHeader = ref({}); 231 const PHeader = ref({});
231 const PCommit = ref({}); 232 const PCommit = ref({});
232 -const PHeader_cover = ref(""); 233 +// const PHeader_cover = ref("");
233 -const PHeader_title = ref(""); 234 +// const PHeader_title = ref("");
234 -const mockData = ref([]); 235 +// const mockData = ref([]);
236 +/**
237 + * 表单结构数据
238 + */
235 const formData = ref([]); 239 const formData = ref([]);
240 +/**
241 + * 格式化表单数据
242 +*/
243 +const formatData = (data) => {
244 + const arr = [];
245 + data.forEach((field) => {
246 + const { interaction_type, data_type, field_id, field_name, ...component_props } = field;
247 + // 生成组件属性
248 + const temp = {
249 + key: field_name,
250 + value: component_props.default ? component_props.default : "",
251 + component_props,
252 + };
253 + arr.push(temp);
254 + });
255 + return arr;
256 +};
257 +/**
258 + * 表单提交数据
259 + */
236 const postData = ref({}); 260 const postData = ref({});
261 +/**
262 + * 表单历史数据
263 + */
237 const historyData = ref({}); 264 const historyData = ref({});
238 265
239 // 编辑模式不能提交操作 266 // 编辑模式不能提交操作
...@@ -256,55 +283,13 @@ const x_cycle = $route.query.x_cycle ? $route.query.x_cycle : null; ...@@ -256,55 +283,13 @@ const x_cycle = $route.query.x_cycle ? $route.query.x_cycle : null;
256 const iframe_openid = getUrlParams(location.href) ? getUrlParams(location.href).openid : ''; 283 const iframe_openid = getUrlParams(location.href) ? getUrlParams(location.href).openid : '';
257 // 强制后台检查标识 284 // 强制后台检查标识
258 const force_back = $route.query.force_back ? $route.query.force_back : ''; 285 const force_back = $route.query.force_back ? $route.query.force_back : '';
259 -// 格式化表单数据结构
260 -const formatData = (data) => {
261 - const arr = [];
262 - data.forEach((field) => {
263 - const { interaction_type, data_type, field_id, field_name, ...component_props } = field;
264 - // 生成组件属性
265 - const temp = {
266 - key: field_name,
267 - value: component_props.default ? component_props.default : "",
268 - component_props,
269 - };
270 - arr.push(temp);
271 - });
272 - return arr;
273 -};
274 286
275 -// 处理没有绑定值的组件的赋值 287 +const notice_text = ref(""); // 顶部提示文字
276 -// 省市区选择,图片上传,文件上传,电子签名,评分组件 288 +const show_qrcode = ref(false); // 显示二维码
277 -const area_picker = ref([]); 289 +const qr_url = ref(""); // qrcode
278 -const image_uploader = ref([]);
279 -const file_uploader = ref([]);
280 -const table_editor = ref([]);
281 -const sign = ref([]);
282 -const rate_picker = ref([]);
283 -const appointment = ref([]);
284 -// 动态绑定ref数据
285 -const setRefMap = (el, item) => {
286 - if (el) {
287 - if (item.component_props.tag === "image_uploader") {
288 - image_uploader.value.push(el);
289 - }
290 - if (item.component_props.tag === "file_uploader") {
291 - file_uploader.value.push(el);
292 - }
293 - if (item.component_props.tag === "table_editor") {
294 - table_editor.value.push(el);
295 - }
296 - // if (item.component_props.tag === "sign") {
297 - // sign.value.push(el);
298 - // }
299 - }
300 -};
301 -
302 -const notice_text = ref("");
303 -const show = ref(false);
304 -const qr_url = ref("");
305 const pwd_show = ref(false); 290 const pwd_show = ref(false);
306 const mmtx_password = ref(''); 291 const mmtx_password = ref('');
307 -const form_name = ref('') 292 +const form_name = ref(''); // 表单名称
308 293
309 // 提交表单密码 294 // 提交表单密码
310 const onSubmitPwd = async () => { 295 const onSubmitPwd = async () => {
...@@ -469,20 +454,6 @@ onMounted(async () => { ...@@ -469,20 +454,6 @@ onMounted(async () => {
469 if (data_id) { // 如果有data_id,则获取历史数据 否则获取表单默认值 454 if (data_id) { // 如果有data_id,则获取历史数据 否则获取表单默认值
470 const history_data = await queryFormDataAPI({ form_code: $route.query.code, data_id, openid: iframe_openid, force_back }); 455 const history_data = await queryFormDataAPI({ form_code: $route.query.code, data_id, openid: iframe_openid, force_back });
471 if (history_data.code) { 456 if (history_data.code) {
472 - // let object = history_data.data; // 表单数据
473 - // formData.value.forEach((item) => { // 把对应数据赋值到表单
474 - // for (const key in object) {
475 - // const element = object[key];
476 - // if (item.key === key) {
477 - // item.component_props.default = element;
478 - // // 设置读写权限 read_only read_write
479 - // if (page_type === 'info') {
480 - // item.component_props.readonly = true;
481 - // PCommit.value.visible = false; // 只读模式下,提交按钮隐藏
482 - // }
483 - // }
484 - // }
485 - // });
486 // 结构优化一下 457 // 结构优化一下
487 let object = history_data.data; 458 let object = history_data.data;
488 const isInfoPage = page_type === 'info'; 459 const isInfoPage = page_type === 'info';
...@@ -511,14 +482,16 @@ onMounted(async () => { ...@@ -511,14 +482,16 @@ onMounted(async () => {
511 show_loading.value = false; 482 show_loading.value = false;
512 } 483 }
513 484
485 + // TAG:创建组件类型
514 createComponentType(formData.value); 486 createComponentType(formData.value);
487 +
515 // TAG:不同类型提交表单处理 488 // TAG:不同类型提交表单处理
516 if (page_type === 'add') { // 表单为新增状态 489 if (page_type === 'add') { // 表单为新增状态
517 // 过期时间显示 490 // 过期时间显示
518 notice_text.value = `表单报名将在 ${formSetting.value.sjsj_end_time} 后结束`; 491 notice_text.value = `表单报名将在 ${formSetting.value.sjsj_end_time} 后结束`;
519 // 判断是否需要关注公众号, 弹出二维码识别 492 // 判断是否需要关注公众号, 弹出二维码识别
520 if (formSetting.value.wxzq_must_follow && !formSetting.value.x_field_weixin_subscribe) { 493 if (formSetting.value.wxzq_must_follow && !formSetting.value.x_field_weixin_subscribe) {
521 - show.value = true; 494 + show_qrcode.value = true;
522 qr_url.value = formSetting.value.wxzq_mp_qrcode; 495 qr_url.value = formSetting.value.wxzq_mp_qrcode;
523 // 标记用户还未关注 496 // 标记用户还未关注
524 localStorage.setItem('weixin_subscribe', 0); 497 localStorage.setItem('weixin_subscribe', 0);
...@@ -586,7 +559,7 @@ const checkUserSubscribe = () => { ...@@ -586,7 +559,7 @@ const checkUserSubscribe = () => {
586 if (formSetting.value.wxzq_must_follow && formSetting.value.x_field_weixin_subscribe) { 559 if (formSetting.value.wxzq_must_follow && formSetting.value.x_field_weixin_subscribe) {
587 // 标记用户已关注 560 // 标记用户已关注
588 localStorage.setItem('weixin_subscribe', 1); 561 localStorage.setItem('weixin_subscribe', 1);
589 - show.value = false; 562 + show_qrcode.value = false;
590 } 563 }
591 // 凭密码填写设置 564 // 凭密码填写设置
592 if (formSetting.value.mmtx_enable) { 565 if (formSetting.value.mmtx_enable) {
...@@ -606,23 +579,36 @@ const checkUserPassword = () => { ...@@ -606,23 +579,36 @@ const checkUserPassword = () => {
606 } 579 }
607 } 580 }
608 581
609 -function mergeAndDeduplicate(data) { 582 +/**
583 + * 合并并去重数据
584 + * @param {Array} data - 输入的数据数组,每个元素包含mode、logical_op和expr_list属性
585 + * @returns {Array} - 合并并去重后的数据数组
586 + *
587 + * 此函数旨在处理一组配置项,每个配置项由mode、logical_op和expr_list组成。
588 + * 它首先根据mode和logical_op属性合并相同的项目,然后在每个合并的项目中去重expr_list。
589 + * 合并的逻辑是基于mode和logical_op完全一致的情况下进行的。
590 + * 去重的逻辑是通过比较op、values和field_name属性来确定expr_list中的表达式是否重复。
591 + */
592 +const mergeAndDeduplicate = (data) => {
593 + // 使用reduce函数合并数据
610 return data.reduce((acc, current) => { 594 return data.reduce((acc, current) => {
595 + // 查找是否已存在相同的项
611 const existingItemIndex = acc.findIndex(item => 596 const existingItemIndex = acc.findIndex(item =>
612 item.mode === current.mode && item.logical_op === current.logical_op 597 item.mode === current.mode && item.logical_op === current.logical_op
613 ); 598 );
614 599
615 if (existingItemIndex !== -1) { 600 if (existingItemIndex !== -1) {
616 - // Merge expr_list values 601 + // 如果存在相同项,则合并expr_list值
617 acc[existingItemIndex].expr_list = acc[existingItemIndex].expr_list.concat(current.expr_list); 602 acc[existingItemIndex].expr_list = acc[existingItemIndex].expr_list.concat(current.expr_list);
618 } else { 603 } else {
619 - // Push new item to the accumulator 604 + // 如果不存在相同项,则将当前项添加到累积器中
620 acc.push(current); 605 acc.push(current);
621 } 606 }
622 607
608 + // 返回处理后的累积器
623 return acc; 609 return acc;
624 }, []).map(item => { 610 }, []).map(item => {
625 - // Remove duplicates from expr_list 611 + // 从expr_list中移除重复项
626 item.expr_list = item.expr_list.filter((expr, index, self) => 612 item.expr_list = item.expr_list.filter((expr, index, self) =>
627 index === self.findIndex(e => ( 613 index === self.findIndex(e => (
628 e.op === expr.op && JSON.stringify(e.values) === JSON.stringify(expr.values) && e.field_name === expr.field_name 614 e.op === expr.op && JSON.stringify(e.values) === JSON.stringify(expr.values) && e.field_name === expr.field_name
...@@ -746,6 +732,34 @@ const checkRules = () => { ...@@ -746,6 +732,34 @@ const checkRules = () => {
746 }); 732 });
747 } 733 }
748 734
735 +
736 +// 处理没有绑定值的组件的赋值
737 +// 省市区选择,图片上传,文件上传,电子签名,评分组件
738 +// const area_picker = ref([]);
739 +const image_uploader = ref([]);
740 +const file_uploader = ref([]);
741 +const table_editor = ref([]);
742 +const sign = ref([]);
743 +// const rate_picker = ref([]);
744 +// const appointment = ref([]);
745 +// 动态绑定ref数据
746 +const setRefMap = (el, item) => {
747 + if (el) {
748 + if (item.component_props.tag === "image_uploader") {
749 + image_uploader.value.push(el);
750 + }
751 + if (item.component_props.tag === "file_uploader") {
752 + file_uploader.value.push(el);
753 + }
754 + if (item.component_props.tag === "table_editor") {
755 + table_editor.value.push(el);
756 + }
757 + // if (item.component_props.tag === "sign") {
758 + // sign.value.push(el);
759 + // }
760 + }
761 +};
762 +
749 // 操作绑定自定义字段回调 763 // 操作绑定自定义字段回调
750 const onActive = (item) => { 764 const onActive = (item) => {
751 if (item?.key === "image_uploader") { 765 if (item?.key === "image_uploader") {
...@@ -862,24 +876,24 @@ const onRemove = (value) => { // 处理组件删除事件回调, 数据结构是 ...@@ -862,24 +876,24 @@ const onRemove = (value) => { // 处理组件删除事件回调, 数据结构是
862 }); 876 });
863 } 877 }
864 878
865 -const adjGroupData = (values) => { // 调整group组件的数据结构 879 +// const adjGroupData = (values) => { // 调整group组件的数据结构
866 - // let obj = { 880 +// // let obj = {
867 - // "field_10_group[0]_7653" : "1", 881 +// // "field_10_group[0]_7653" : "1",
868 - // "field_10_group[1]_4154" : "11", 882 +// // "field_10_group[1]_4154" : "11",
869 - // "field_11_group[0]_3440" : "2", 883 +// // "field_11_group[0]_3440" : "2",
870 - // "field_11_group[1]_4282" : "22" 884 +// // "field_11_group[1]_4282" : "22"
871 - // } 885 +// // }
872 886
873 - // let arr = [{ 887 +// // let arr = [{
874 - // "field_10": "1", 888 +// // "field_10": "1",
875 - // "field_11": "2", 889 +// // "field_11": "2",
876 - // }, { 890 +// // }, {
877 - // "field_10": "11", 891 +// // "field_10": "11",
878 - // "field_11": "22", 892 +// // "field_11": "22",
879 - // }] 893 +// // }]
880 -} 894 +// }
881 895
882 -const submitStatus = ref(false); 896 +const submitStatus = ref(false); // 表单提交按钮状态
883 897
884 const successHandle = () => { // 表单成功提交后续操作 898 const successHandle = () => { // 表单成功提交后续操作
885 //在 iframe 中调用父页面中定义的变量 - Doris需要自由控制 899 //在 iframe 中调用父页面中定义的变量 - Doris需要自由控制
......