hookehuyr

✨ feat: 规则功能调整(下拉控件绑定值方式修改),测试分享功能

1 <!-- 1 <!--
2 * @Date: 2022-08-30 13:46:51 2 * @Date: 2022-08-30 13:46:51
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2023-02-27 14:24:03 4 + * @LastEditTime: 2023-03-01 18:17:40
5 * @FilePath: /data-table/src/components/PickerField/index.vue 5 * @FilePath: /data-table/src/components/PickerField/index.vue
6 * @Description: 单列选择器组件 6 * @Description: 单列选择器组件
7 --> 7 -->
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
12 {{ item.component_props.label }} 12 {{ item.component_props.label }}
13 </div> 13 </div>
14 <van-field 14 <van-field
15 - v-model="item.value" 15 + v-model="picker_value"
16 is-link 16 is-link
17 readonly 17 readonly
18 :name="item.key" 18 :name="item.key"
...@@ -58,12 +58,14 @@ onMounted(() => { ...@@ -58,12 +58,14 @@ onMounted(() => {
58 58
59 const selectedValues = ref(""); 59 const selectedValues = ref("");
60 const showPicker = ref(false); 60 const showPicker = ref(false);
61 +const picker_value = ref(props.item.component_props.default);
61 62
62 const onConfirm = ({ selectedOptions }) => { 63 const onConfirm = ({ selectedOptions }) => {
63 - props.item.value = selectedOptions[0]?.value; 64 + picker_value.value = selectedOptions[0]?.value;
64 showPicker.value = false; 65 showPicker.value = false;
65 // 触发点自定义监听事件,配合规则显示隐藏其他字段 66 // 触发点自定义监听事件,配合规则显示隐藏其他字段
66 - emit("active", { key: props.item.key, value: selectedOptions[0]?.value, type: "picker" }); 67 + props.item.value = { key: props.item.key, value: picker_value.value, type: "picker" };
68 + emit("active", props.item.value);
67 // if (add_info_key.value === props.item.value) { 69 // if (add_info_key.value === props.item.value) {
68 // has_add_info.value = true; 70 // has_add_info.value = true;
69 // } 71 // }
......
1 +/*
2 + * @Date: 2022-06-13 17:42:32
3 + * @LastEditors: hookehuyr hookehuyr@gmail.com
4 + * @LastEditTime: 2023-03-01 17:07:58
5 + * @FilePath: /data-table/src/composables/useShare.js
6 + * @Description: 文件描述
7 + */
8 +import wx from 'weixin-js-sdk';
9 +// import { Toast } from 'vant';
10 +
11 +/**
12 + * @description: 微信分享功能
13 + * @param {*} title 标题
14 + * @param {*} desc 描述
15 + * @param {*} imgUrl 图标
16 + * @return {*}
17 + */
18 +export const sharePage = ({title = '自定义表单', desc = '数据收集', imgUrl = ''}) => {
19 + const shareData = {
20 + title, // 分享标题
21 + desc, // 分享描述
22 + link: location.origin + location.pathname + location.hash, // 分享链接,该链接域名或路径必须与当前页面对应的公众号 JS 安全域名一致
23 + imgUrl, // 分享图标
24 + success: function () {
25 + // console.warn('设置成功');
26 + }
27 + }
28 + // 分享好友(微信好友或qq好友)
29 + wx.updateAppMessageShareData(shareData);
30 + // 分享到朋友圈或qq空间
31 + wx.updateTimelineShareData(shareData);
32 + // 分享到腾讯微博
33 + wx.onMenuShareWeibo(shareData);
34 + // // 获取“分享给朋友”按钮点击状态及自定义分享内容接口(即将废弃)
35 + // wx.onMenuShareAppMessage(shareData);
36 + // // 获取“分享到朋友圈”按钮点击状态及自定义分享内容接口(即将废弃)
37 + // wx.onMenuShareTimeline(shareData);
38 + // // 获取“分享到QQ”按钮点击状态及自定义分享内容接口(即将废弃)
39 + // wx.onMenuShareQQ(shareData);
40 +}
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: 2023-02-27 18:52:17 4 + * @LastEditTime: 2023-03-01 18:19:28
5 * @FilePath: /data-table/src/views/index.vue 5 * @FilePath: /data-table/src/views/index.vue
6 * @Description: 首页 6 * @Description: 首页
7 --> 7 -->
...@@ -98,6 +98,8 @@ import { addFormDataAPI } from "@/api/data.js"; ...@@ -98,6 +98,8 @@ import { addFormDataAPI } from "@/api/data.js";
98 import { showSuccessToast, showFailToast } from "vant"; 98 import { showSuccessToast, showFailToast } from "vant";
99 import { wxInfo, getUrlParams } from "@/utils/tools"; 99 import { wxInfo, getUrlParams } from "@/utils/tools";
100 import { styleColor } from "@/constant.js"; 100 import { styleColor } from "@/constant.js";
101 +import { sharePage } from '@/composables/useShare.js'
102 +import wx from 'weixin-js-sdk'
101 103
102 // 获取表单设置 104 // 获取表单设置
103 const store = mainStore(); 105 const store = mainStore();
...@@ -183,6 +185,7 @@ const show = ref(false); ...@@ -183,6 +185,7 @@ const show = ref(false);
183 const qr_url = ref(""); 185 const qr_url = ref("");
184 const pwd_show = ref(false); 186 const pwd_show = ref(false);
185 const mmtx_password = ref(''); 187 const mmtx_password = ref('');
188 +const form_name = ref('')
186 189
187 // 提交表单密码 190 // 提交表单密码
188 const onSubmitPwd = async () => { 191 const onSubmitPwd = async () => {
...@@ -201,6 +204,7 @@ onMounted(async () => { ...@@ -201,6 +204,7 @@ onMounted(async () => {
201 const form_data = data; 204 const form_data = data;
202 // 表单网页标题 205 // 表单网页标题
203 useTitle(form_data.name); 206 useTitle(form_data.name);
207 + form_name.value = form_data.name;
204 // 重构数据结构 208 // 重构数据结构
205 let page_header = {}; 209 let page_header = {};
206 let page_commit = {}; 210 let page_commit = {};
...@@ -216,7 +220,6 @@ onMounted(async () => { ...@@ -216,7 +220,6 @@ onMounted(async () => {
216 page_form.push(element); 220 page_form.push(element);
217 } 221 }
218 }); 222 });
219 - // TODO: 后期需要适配多种图片展示方式,展示只显示单张图片模式
220 /** 页眉属性 223 /** 页眉属性
221 * @param label 表单标题 224 * @param label 表单标题
222 * @param banner_type 页眉类型:["文字", "单张图", "轮播图"] text=文字,image=单张图,carousel=轮播图 225 * @param banner_type 页眉类型:["文字", "单张图", "轮播图"] text=文字,image=单张图,carousel=轮播图
...@@ -241,81 +244,6 @@ onMounted(async () => { ...@@ -241,81 +244,6 @@ onMounted(async () => {
241 }; 244 };
242 } 245 }
243 formData.value = formatData(page_form); 246 formData.value = formatData(page_form);
244 -
245 - // TODO: 等待真实数据结构 重构规则数据结构
246 - const rule_list = [
247 - {
248 - "mode": "SHOW",
249 - "field_names": [
250 - "man_inpu"
251 - ],
252 - "logical_op": "OR",
253 - "expr_list": [
254 - {
255 - "field_name": "sex",
256 - "op": "IN",
257 - "values": [
258 - "男"
259 - ]
260 - }
261 - ],
262 - "text": ""
263 - },
264 - {
265 - "mode": "SHOW",
266 - "field_names": [
267 - "woman_input"
268 - ],
269 - "logical_op": "OR",
270 - "expr_list": [
271 - {
272 - "field_name": "sex",
273 - "op": "IN",
274 - "values": [
275 - "女"
276 - ]
277 - }
278 - ],
279 - "text": ""
280 - },
281 - {
282 - "mode": "HIDE",
283 - "field_names": [
284 - "phone",
285 - "id_card"
286 - ],
287 - "logical_op": "AND",
288 - "expr_list": [
289 - {
290 - "field_name": "more",
291 - "op": "IN",
292 - "values": [
293 - "不想填了",
294 - ]
295 - },
296 - {
297 - "field_name": "field_9",
298 - "op": "IN",
299 - "values": [
300 - "说明1",
301 - ]
302 - }
303 - ],
304 - "text": ""
305 - }
306 - ];
307 - formData.value.forEach(item => {
308 - rule_list.forEach(rule => {
309 - if (rule.field_names?.includes(item.key)) {
310 - item.field_rules = {
311 - mode: rule.mode,
312 - logical_op: rule.logical_op,
313 - expr_list: rule.expr_list,
314 - }
315 - }
316 - })
317 - })
318 -
319 mockData.value = [ 247 mockData.value = [
320 { 248 {
321 key: "111", 249 key: "111",
...@@ -354,7 +282,11 @@ onMounted(async () => { ...@@ -354,7 +282,11 @@ onMounted(async () => {
354 localStorage.setItem('weixin_subscribe', 0); 282 localStorage.setItem('weixin_subscribe', 0);
355 } 283 }
356 // 判断是否弹出密码输入框 284 // 判断是否弹出密码输入框
357 - checkUserPassword() 285 + checkUserPassword();
286 + wx.ready(() => {
287 + // 自定义分享内容
288 + sharePage({ title: form_name.value, desc: '活动报名' });
289 + });
358 }); 290 });
359 291
360 // 打开轮询用户是否关注 292 // 打开轮询用户是否关注
...@@ -405,8 +337,24 @@ const checkUserPassword = async () => { ...@@ -405,8 +337,24 @@ const checkUserPassword = async () => {
405 } 337 }
406 338
407 // 根据规则隐藏相应字段 339 // 根据规则隐藏相应字段
408 -const checkRules = (field) => { 340 +const checkRules = async () => {
341 + // 数据收集设置
342 + const { data } = await getFormSettingAPI({ form_code: $route.query.code });
343 + let rule_list = [];
344 + if (data.length) {
345 + rule_list = [...data[0]['rules']]
346 + }
409 formData.value.forEach(item => { 347 formData.value.forEach(item => {
348 + // 给受作用的字段绑定判断规则
349 + rule_list.forEach(rule => {
350 + if (rule.field_names?.includes(item.key)) {
351 + item.field_rules = {
352 + mode: rule.mode,
353 + logical_op: rule.logical_op,
354 + expr_list: rule.expr_list,
355 + }
356 + }
357 + });
410 // 只检查存在规则的字段 358 // 只检查存在规则的字段
411 if (item.field_rules) { 359 if (item.field_rules) {
412 let condition = ''; 360 let condition = '';
...@@ -415,11 +363,11 @@ const checkRules = (field) => { ...@@ -415,11 +363,11 @@ const checkRules = (field) => {
415 item.field_rules?.expr_list.forEach(expr => { 363 item.field_rules?.expr_list.forEach(expr => {
416 if (typeof postData.value[expr['field_name']] === 'string') { // 表单值为字符串(单选,下拉) 364 if (typeof postData.value[expr['field_name']] === 'string') { // 表单值为字符串(单选,下拉)
417 const k = !!expr['values'].includes(postData.value[expr['field_name']]) 365 const k = !!expr['values'].includes(postData.value[expr['field_name']])
418 - condition += `${k} ${op}` 366 + condition += `${k}${op}`
419 } 367 }
420 if (typeof postData.value[expr['field_name']] === 'object') { // 表单值为数组(多选) 368 if (typeof postData.value[expr['field_name']] === 'object') { // 表单值为数组(多选)
421 const k = !!(_.intersection(expr['values'], postData.value[expr['field_name']])).length; 369 const k = !!(_.intersection(expr['values'], postData.value[expr['field_name']])).length;
422 - condition += `${k} ${op}` 370 + condition += `${k}${op}`
423 } 371 }
424 }); 372 });
425 // 把结果转换为布尔值 373 // 把结果转换为布尔值
...@@ -459,9 +407,9 @@ const onActive = (item) => { ...@@ -459,9 +407,9 @@ const onActive = (item) => {
459 if (item.type === "rate") { 407 if (item.type === "rate") {
460 postData.value = _.assign(postData.value, { [item.key]: item.value }); 408 postData.value = _.assign(postData.value, { [item.key]: item.value });
461 } 409 }
462 - // if (item.type === "picker") { // 下拉框控件 410 + if (item.type === "picker") { // 下拉框控件
463 - // // console.warn(item); 411 + postData.value = _.assign(postData.value, { [item.key]: item.value });
464 - // } 412 + }
465 if (item.type === "radio") { // 单选控件 413 if (item.type === "radio") { // 单选控件
466 postData.value = _.assign(postData.value, { [item.key]: item.affix ? item.affix : item.value }); 414 postData.value = _.assign(postData.value, { [item.key]: item.affix ? item.affix : item.value });
467 } 415 }
...@@ -476,9 +424,8 @@ const onActive = (item) => { ...@@ -476,9 +424,8 @@ const onActive = (item) => {
476 }); 424 });
477 postData.value = _.assign(postData.value, { [item.key]: checkbox_value }); 425 postData.value = _.assign(postData.value, { [item.key]: checkbox_value });
478 } 426 }
479 -
480 // 检查规则,会影响字段显示 427 // 检查规则,会影响字段显示
481 - checkRules(item); 428 + checkRules();
482 }; 429 };
483 430
484 // 检验没有绑定name的输入项 431 // 检验没有绑定name的输入项
...@@ -601,6 +548,12 @@ const onSubmit = async (values) => { ...@@ -601,6 +548,12 @@ const onSubmit = async (values) => {
601 // } 548 // }
602 } 549 }
603 }; 550 };
551 +
552 +// setTimeout(() => {
553 +// // TAG:微信分享
554 +// // 自定义分享内容
555 +// sharePage({ title: form_name.value, desc: '活动报名', imgUrl: '' });
556 +// }, 500)
604 </script> 557 </script>
605 558
606 <style lang="less"> 559 <style lang="less">
......