hookehuyr

h5和小程序获取表单配置调整

1 /* 1 /*
2 * @Date: 2023-03-23 11:17:54 2 * @Date: 2023-03-23 11:17:54
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2023-03-24 13:13:44 4 + * @LastEditTime: 2023-03-24 16:01:10
5 * @FilePath: /custom_form/src/app.config.js 5 * @FilePath: /custom_form/src/app.config.js
6 * @Description: 文件描述 6 * @Description: 文件描述
7 */ 7 */
......
1 /* 1 /*
2 * @Date: 2023-03-23 11:17:54 2 * @Date: 2023-03-23 11:17:54
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2023-03-24 14:14:27 4 + * @LastEditTime: 2023-03-24 16:04:21
5 * @FilePath: /custom_form/src/app.js 5 * @FilePath: /custom_form/src/app.js
6 * @Description: 文件描述 6 * @Description: 文件描述
7 */ 7 */
8 import { createApp } from 'vue' 8 import { createApp } from 'vue'
9 import { createPinia } from 'pinia' 9 import { createPinia } from 'pinia'
10 import './app.less' 10 import './app.less'
11 +import { mainStore } from '@/stores'
12 +import { getFormSettingAPI } from '@/api/form.js'
13 +import { getUrlParams } from '@/utils/tools'
11 14
12 const App = createApp({ 15 const App = createApp({
13 // 可以使用所有的 Vue 生命周期方法 16 // 可以使用所有的 Vue 生命周期方法
14 - mounted() { 17 + async mounted() {
18 + if (process.env.TARO_ENV === 'h5') {
19 + const code = getUrlParams(location.href)
20 + ? getUrlParams(location.href).code
21 + : ''
22 + const store = mainStore();
23 + // 数据收集设置
24 + const { data } = await getFormSettingAPI({ form_code: code });
25 + const form_setting = {};
26 + if (data.length) {
27 + Object.assign(form_setting, data[0]['property_list'], data[0]['extend']);
28 + }
29 + // 缓存表单设置
30 + store.changeFormSetting(form_setting);
31 + }
15 }, 32 },
16 33
17 // 对应 onLaunch 34 // 对应 onLaunch
......
...@@ -8,15 +8,15 @@ ...@@ -8,15 +8,15 @@
8 8
9 <script setup> 9 <script setup>
10 import { ref, computed, watchEffect, onMounted } from "vue"; 10 import { ref, computed, watchEffect, onMounted } from "vue";
11 -import Taro from '@tarojs/taro'
12 -import { mainStore } from '@/stores'
13 import { wxInfo, getUrlParams } from "@/utils/tools"; 11 import { wxInfo, getUrlParams } from "@/utils/tools";
14 // 初始化WX环境 12 // 初始化WX环境
15 import wx from 'weixin-js-sdk' 13 import wx from 'weixin-js-sdk'
16 import { wxJsAPI } from '@/api/wx/config' 14 import { wxJsAPI } from '@/api/wx/config'
17 import { apiList } from '@/api/wx/jsApiList.js' 15 import { apiList } from '@/api/wx/jsApiList.js'
18 import { styleColor } from "@/constant.js"; 16 import { styleColor } from "@/constant.js";
19 -import { getFormSettingAPI } from "@/api/form.js"; 17 +import { mainStore } from '@/stores'
18 +import { getFormSettingAPI } from '@/api/form.js'
19 +import Taro from '@tarojs/taro'
20 20
21 // TAG: 自定义主题颜色 21 // TAG: 自定义主题颜色
22 const themeVars = { 22 const themeVars = {
...@@ -37,7 +37,6 @@ const onOk = () => { ...@@ -37,7 +37,6 @@ const onOk = () => {
37 37
38 onMounted(async () => { 38 onMounted(async () => {
39 const store = mainStore(); 39 const store = mainStore();
40 - const raw_url = encodeURIComponent(location.pathname + location.hash);
41 // 数据收集设置 40 // 数据收集设置
42 const { data } = await getFormSettingAPI({ form_code: code }); 41 const { data } = await getFormSettingAPI({ form_code: code });
43 const form_setting = {}; 42 const form_setting = {};
...@@ -46,6 +45,8 @@ onMounted(async () => { ...@@ -46,6 +45,8 @@ onMounted(async () => {
46 } 45 }
47 // 缓存表单设置 46 // 缓存表单设置
48 store.changeFormSetting(form_setting); 47 store.changeFormSetting(form_setting);
48 +
49 + const raw_url = encodeURIComponent(location.pathname + location.hash);
49 // 没有授权判断 50 // 没有授权判断
50 const no_auth_info = form_setting.wxzq_enable && !form_setting.x_field_weixin_openid; 51 const no_auth_info = form_setting.wxzq_enable && !form_setting.x_field_weixin_openid;
51 const no_preview_model = model !== 'preview'; 52 const no_preview_model = model !== 'preview';
......
1 <!-- 1 <!--
2 * @Date: 2023-03-24 09:19:27 2 * @Date: 2023-03-24 09:19:27
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2023-03-24 15:19:34 4 + * @LastEditTime: 2023-03-24 15:55:18
5 - * @FilePath: /custom_form/src/pages/table/index.vue 5 + * @FilePath: /custom_form/src/pages/index/index.vue
6 * @Description: 文件描述 6 * @Description: 文件描述
7 --> 7 -->
8 <template> 8 <template>
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
13 </template> 13 </template>
14 14
15 <script setup> 15 <script setup>
16 -import Taro from '@tarojs/taro' 16 +import Taro, { useLoad } from '@tarojs/taro'
17 import { $ } from '@tarojs/extend' 17 import { $ } from '@tarojs/extend'
18 import { createComponentType } from "@/hooks/useComponentType"; 18 import { createComponentType } from "@/hooks/useComponentType";
19 import { ref, computed, watchEffect, onMounted } from "vue"; 19 import { ref, computed, watchEffect, onMounted } from "vue";
...@@ -125,6 +125,7 @@ onMounted(async () => { ...@@ -125,6 +125,7 @@ onMounted(async () => {
125 // TAG: 全局背景色 125 // TAG: 全局背景色
126 $('body').css('background-color', styleColor.backgroundColor) 126 $('body').css('background-color', styleColor.backgroundColor)
127 const { data } = await queryFormAPI({ form_code }); 127 const { data } = await queryFormAPI({ form_code });
128 +
128 const form_data = data; 129 const form_data = data;
129 // 动态修改标题 130 // 动态修改标题
130 Taro.setNavigationBarTitle({ 131 Taro.setNavigationBarTitle({
......