hookehuyr

✨ feat: 配置pinia和处理多平台网络请求问题

1 +/*
2 + * @Date: 2023-03-23 11:17:54
3 + * @LastEditors: hookehuyr hookehuyr@gmail.com
4 + * @LastEditTime: 2023-03-23 15:55:13
5 + * @FilePath: /custom_form/babel.config.js
6 + * @Description: 文件描述
7 + */
1 // babel-preset-taro 更多选项和默认值: 8 // babel-preset-taro 更多选项和默认值:
2 // https://github.com/NervJS/taro/blob/next/packages/babel-preset-taro/README.md 9 // https://github.com/NervJS/taro/blob/next/packages/babel-preset-taro/README.md
3 module.exports = { 10 module.exports = {
4 presets: [ 11 presets: [
5 - ['taro', { 12 + [
13 + 'taro',
14 + {
6 framework: 'vue3', 15 framework: 'vue3',
7 - ts: false 16 + ts: false,
8 - }] 17 + 'dynamic-import-node': true,
9 - ] 18 + },
19 + ],
20 + ],
10 } 21 }
......
...@@ -7,7 +7,6 @@ export {} ...@@ -7,7 +7,6 @@ export {}
7 7
8 declare module '@vue/runtime-core' { 8 declare module '@vue/runtime-core' {
9 export interface GlobalComponents { 9 export interface GlobalComponents {
10 - NutButton: typeof import('@nutui/nutui-taro')['Button']
11 NutCol: typeof import('@nutui/nutui-taro')['Col'] 10 NutCol: typeof import('@nutui/nutui-taro')['Col']
12 NutRow: typeof import('@nutui/nutui-taro')['Row'] 11 NutRow: typeof import('@nutui/nutui-taro')['Row']
13 RouterLink: typeof import('vue-router')['RouterLink'] 12 RouterLink: typeof import('vue-router')['RouterLink']
......
1 +import { createProxy } from './proxy'
2 +import { DEV_PROXY_TARGET, PROXY_PREFIX } from './env'
3 +
1 module.exports = { 4 module.exports = {
2 env: { 5 env: {
3 - NODE_ENV: '"development"' 6 + NODE_ENV: '"development"',
4 - },
5 - defineConstants: {
6 }, 7 },
8 + defineConstants: {},
7 mini: {}, 9 mini: {},
8 - h5: {} 10 + h5: {
11 + target: 'web',
12 + // 配置代理,解决跨域问题
13 + devServer: {
14 + port: '10086', // 设置端口号
15 + // https: true, //是否使用https协议
16 + open: false, //启动后,使用默认浏览器打开网页
17 + hot: true, //是否启用模块的热替换功能,devServer的默认行为是在发现源代码被变更后,通过自动刷新整个页面来做到事实预览,开启hot后,将在不刷新整个页面的情况下通过新模块替换老模块来做到实时预览。
18 + proxy: createProxy(PROXY_PREFIX, DEV_PROXY_TARGET),
19 + },
20 + },
9 } 21 }
......
1 +/*
2 + * @Date: 2023-03-23 17:51:33
3 + * @LastEditors: hookehuyr hookehuyr@gmail.com
4 + * @LastEditTime: 2023-03-23 17:51:46
5 + * @FilePath: /custom_form/config/config.js
6 + * @Description: 文件描述
7 + */
8 +// 反向代理服务器地址
9 +
10 +export const DEV_PROXY_TARGET = 'http://oa-dev.onwall.cn'
11 +export const PROD_PROXY_TARGET = 'https://oa.onwall.cn'
12 +
13 +// API请求前缀
14 +export const PROXY_PREFIX = '/srv/'
15 +
16 +// 项目前缀
17 +export const PROGRAM_PREFIX = 'custom_form'
1 +/*
2 + * @Date: 2023-03-23 11:17:54
3 + * @LastEditors: hookehuyr hookehuyr@gmail.com
4 + * @LastEditTime: 2023-03-23 17:55:06
5 + * @FilePath: /custom_form/config/index.js
6 + * @Description: 文件描述
7 + */
1 const path = require('path') 8 const path = require('path')
2 9
3 import ComponentsPlugin from 'unplugin-vue-components/webpack' 10 import ComponentsPlugin from 'unplugin-vue-components/webpack'
...@@ -20,6 +27,7 @@ const config = { ...@@ -20,6 +27,7 @@ const config = {
20 }, 27 },
21 alias: { 28 alias: {
22 // 配置目录别名 29 // 配置目录别名
30 + '@': path.resolve(__dirname, '../src'),
23 '@/utils': path.resolve(__dirname, '../src/utils'), 31 '@/utils': path.resolve(__dirname, '../src/utils'),
24 '@/components': path.resolve(__dirname, '../src/components'), 32 '@/components': path.resolve(__dirname, '../src/components'),
25 '@/images': path.resolve(__dirname, '../src/assets/images'), 33 '@/images': path.resolve(__dirname, '../src/assets/images'),
...@@ -31,7 +39,17 @@ const config = { ...@@ -31,7 +39,17 @@ const config = {
31 }, 39 },
32 sourceRoot: 'src', 40 sourceRoot: 'src',
33 outputRoot: `dist/${process.env.TARO_ENV}`, 41 outputRoot: `dist/${process.env.TARO_ENV}`,
34 - plugins: ['@tarojs/plugin-html'], 42 + plugins: [
43 + '@tarojs/plugin-html',
44 + [
45 + '@tarojs/plugin-http',
46 + {
47 + disabledFormData: false,
48 + disabledBlob: false,
49 + enableCookie: true,
50 + },
51 + ],
52 + ],
35 defineConstants: {}, 53 defineConstants: {},
36 copy: { 54 copy: {
37 patterns: [], 55 patterns: [],
...@@ -77,7 +95,7 @@ const config = { ...@@ -77,7 +95,7 @@ const config = {
77 }, 95 },
78 }, 96 },
79 }, 97 },
80 - enableSourceMap: false 98 + enableSourceMap: false,
81 }, 99 },
82 h5: { 100 h5: {
83 webpackChain(chain) { 101 webpackChain(chain) {
...@@ -102,7 +120,7 @@ const config = { ...@@ -102,7 +120,7 @@ const config = {
102 generateScopedName: '[name]__[local]___[hash:base64:5]', 120 generateScopedName: '[name]__[local]___[hash:base64:5]',
103 }, 121 },
104 }, 122 },
105 - }, 123 + }
106 }, 124 },
107 } 125 }
108 126
......
1 +import { createProxy } from './proxy'
2 +import { PROD_PROXY_TARGET, PROXY_PREFIX } from './env'
3 +
1 module.exports = { 4 module.exports = {
2 env: { 5 env: {
3 - NODE_ENV: '"production"' 6 + NODE_ENV: '"production"',
4 - },
5 - defineConstants: {
6 }, 7 },
8 + defineConstants: {},
7 mini: {}, 9 mini: {},
8 h5: { 10 h5: {
9 /** 11 /**
...@@ -33,5 +35,14 @@ module.exports = { ...@@ -33,5 +35,14 @@ module.exports = {
33 // postProcess: (context) => ({ ...context, outputPath: path.join(staticDir, 'index.html') }) 35 // postProcess: (context) => ({ ...context, outputPath: path.join(staticDir, 'index.html') })
34 // })) 36 // }))
35 // } 37 // }
36 - } 38 + target: 'web',
39 + // 配置代理,解决跨域问题
40 + devServer: {
41 + port: '10086', // 设置端口号
42 + // https: true, //是否使用https协议
43 + open: false, //启动后,使用默认浏览器打开网页
44 + hot: true, //是否启用模块的热替换功能,devServer的默认行为是在发现源代码被变更后,通过自动刷新整个页面来做到事实预览,开启hot后,将在不刷新整个页面的情况下通过新模块替换老模块来做到实时预览。
45 + proxy: createProxy(PROXY_PREFIX, PROD_PROXY_TARGET),
46 + },
47 + },
37 } 48 }
......
1 +export function createProxy(prefix, target) {
2 + const ret = {};
3 + ret[prefix] = {
4 + target,
5 + changeOrigin: true,
6 + ws: true,
7 + // rewrite: (path) => path.replace(/^\/api/, '')
8 + // rewrite: (path) => path.replace(new RegExp(`^${prefix}`), ''),
9 + }
10 + return ret
11 +}
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
43 "@tarojs/helper": "3.6.2", 43 "@tarojs/helper": "3.6.2",
44 "@tarojs/plugin-framework-vue3": "3.6.2", 44 "@tarojs/plugin-framework-vue3": "3.6.2",
45 "@tarojs/plugin-html": "3.6.2", 45 "@tarojs/plugin-html": "3.6.2",
46 + "@tarojs/plugin-http": "^3.6.2",
46 "@tarojs/plugin-platform-alipay": "3.6.2", 47 "@tarojs/plugin-platform-alipay": "3.6.2",
47 "@tarojs/plugin-platform-h5": "3.6.2", 48 "@tarojs/plugin-platform-h5": "3.6.2",
48 "@tarojs/plugin-platform-jd": "3.6.2", 49 "@tarojs/plugin-platform-jd": "3.6.2",
...@@ -53,9 +54,11 @@ ...@@ -53,9 +54,11 @@
53 "@tarojs/runtime": "3.6.2", 54 "@tarojs/runtime": "3.6.2",
54 "@tarojs/shared": "3.6.2", 55 "@tarojs/shared": "3.6.2",
55 "@tarojs/taro": "3.6.2", 56 "@tarojs/taro": "3.6.2",
57 + "axios-miniprogram": "^2.0.0-rc-2",
56 "dayjs": "^1.11.7", 58 "dayjs": "^1.11.7",
57 "pinia": "^2.0.33", 59 "pinia": "^2.0.33",
58 - "vue": "^3.0.0" 60 + "vue": "^3.0.0",
61 + "weixin-js-sdk": "^1.6.0"
59 }, 62 },
60 "devDependencies": { 63 "devDependencies": {
61 "@babel/core": "^7.8.0", 64 "@babel/core": "^7.8.0",
......
1 +/*
2 + * @Date: 2022-06-17 14:54:29
3 + * @LastEditors: hookehuyr hookehuyr@gmail.com
4 + * @LastEditTime: 2022-12-01 16:26:27
5 + * @FilePath: /data-table/src/api/common.js
6 + * @Description: 通用接口
7 + */
8 +import { fn, fetch, uploadFn } from '@/api/fn';
9 +
10 +const Api = {
11 + SMS: '/srv/?a=sms',
12 + TOKEN: '/srv/?a=upload',
13 + SAVE_FILE: '/srv/?a=upload&t=save_file',
14 +}
15 +
16 +/**
17 + * @description: 发送验证码
18 + * @param {*} phone 手机号码
19 + * @returns
20 + */
21 +export const smsAPI = (params) => fn(fetch.post(Api.SMS, params));
22 +
23 +/**
24 + * @description: 获取七牛token
25 + * @returns
26 + */
27 +export const qiniuTokenAPI = (params) => fn(fetch.stringifyPost(Api.TOKEN, params));
28 +
29 +/**
30 + * @description: 上传七牛
31 + * @param {*}
32 + * @returns
33 + */
34 +export const qiniuUploadAPI = (url, data, config) => uploadFn(fetch.basePost(url, data, config));
35 +
36 +/**
37 + * @description: 保存图片
38 + * @param {*} format
39 + * @param {*} hash
40 + * @param {*} height
41 + * @param {*} width
42 + * @param {*} filekey
43 + * @returns
44 + */
45 +export const saveFileAPI = (params) => fn(fetch.stringifyPost(Api.SAVE_FILE, params));
1 +/*
2 + * @Date: 2022-06-17 14:54:29
3 + * @LastEditors: hookehuyr hookehuyr@gmail.com
4 + * @LastEditTime: 2022-11-17 16:00:04
5 + * @FilePath: /data-table/src/api/component.js
6 + * @Description: 组件接口
7 + */
8 +import { fn, fetch } from '@/api/fn';
9 +
10 +const Api = {
11 + QUERY_COMPONENT: '/srv/?a=query_component',
12 +}
13 +
14 +/**
15 + * @description: 查询组件
16 + * @param: group_code 分组标识
17 + * @param: component_code 组件标识
18 + * @param: name 组件名称;条件:模糊查询;
19 + */
20 +export const getComponentAPI = (params) => fn(fetch.get(Api.QUERY_COMPONENT, params));
1 +/*
2 + * @Date: 2022-06-17 14:54:29
3 + * @LastEditors: hookehuyr hookehuyr@gmail.com
4 + * @LastEditTime: 2022-11-17 13:49:35
5 + * @FilePath: /data-table/src/api/data.js
6 + * @Description: 表单数据接口
7 + */
8 +import { fn, fetch } from '@/api/fn';
9 +
10 +const Api = {
11 + ADD_FORM_DATA: '/srv/?a=add_formdata',
12 +}
13 +/**
14 + * @description: 添加表单数据
15 + * @param: form_code 表单唯一标识
16 + * @param: data 待添加的数据,json对象结构;键值对记录变更的字段和值;
17 + */
18 +export const addFormDataAPI = (params) => fn(fetch.post(Api.ADD_FORM_DATA, params));
1 +/*
2 + * @Date: 2022-05-18 22:56:08
3 + * @LastEditors: hookehuyr hookehuyr@gmail.com
4 + * @LastEditTime: 2023-03-23 14:47:14
5 + * @FilePath: /custom_form/src/api/fn.js
6 + * @Description: 文件描述
7 + */
8 +import axios from '@/utils/request'
9 +import qs from 'Qs'
10 +import Taro from '@tarojs/taro'
11 +
12 +/**
13 + * 网络请求功能函数
14 + * @param {*} api 请求axios接口
15 + * @returns 请求成功后,获取数据
16 + */
17 +export const fn = (api) => {
18 + return api
19 + .then(res => {
20 + if (res.data.code === 1) {
21 + return res.data || true;
22 + } else {
23 + // tslint:disable-next-line: no-console
24 + // if (!res.data.show) return false;
25 + Taro.showToast({
26 + title: res.data.msg,
27 + icon: 'none',
28 + duration: 2000
29 + });
30 + return false;
31 + }
32 + })
33 + .catch(err => {
34 + // tslint:disable-next-line: no-console
35 + console.error(err);
36 + return false;
37 + })
38 + .finally(() => { // 最终执行
39 + })
40 +}
41 +
42 +/**
43 + * 七牛返回格式
44 + * @param {*} api
45 + * @returns
46 + */
47 +export const uploadFn = (api) => {
48 + return api
49 + .then(res => {
50 + if (res.status === 200) {
51 + return res.data || true;
52 + } else {
53 + // tslint:disable-next-line: no-console
54 + console.warn(res);
55 + if (!res.data.show) return false;
56 + Taro.showToast({
57 + title: res.data.msg,
58 + icon: 'close',
59 + duration: 2000,
60 + })
61 + return false;
62 + }
63 + })
64 + .catch(err => {
65 + // tslint:disable-next-line: no-console
66 + console.error(err);
67 + return false;
68 + })
69 +}
70 +
71 +/**
72 + * 统一 GET/POST 不同传参形式
73 + */
74 +export const fetch = {
75 + get: function (api, params) {
76 + return axios.get(api, { params })
77 + },
78 + post: function (api, params) {
79 + return axios.post(api, params)
80 + },
81 + stringifyPost: function (api, params) {
82 + return axios.post(api, qs.stringify(params))
83 + },
84 + basePost: function (url, data, config) {
85 + return axios.post(url, data, config)
86 + }
87 +}
1 +/*
2 + * @Date: 2022-06-17 14:54:29
3 + * @LastEditors: hookehuyr hookehuyr@gmail.com
4 + * @LastEditTime: 2023-02-07 13:23:19
5 + * @FilePath: /data-table/src/api/form.js
6 + * @Description: 表单接口
7 + */
8 +import { fn, fetch } from '@/api/fn';
9 +
10 +const Api = {
11 + FORM_ADD: '/srv/?a=add_form',
12 + FORM_QUERY: '/srv/?a=query_form_all_field',
13 + ADD_FORM_FIELD: '/srv/?a=add_form_field',
14 + ADD_FORM_SETTING: '/srv/?a=add_form_setting',
15 + QUERY_FORM_SETTING: '/srv/?a=query_form_setting',
16 + VERIFY_PASSWORD: '/srv/?a=verify_password',
17 +};
18 +
19 +/**
20 + * @description: 新增表单
21 + * @param: client_id 主体客户id
22 + * @param: name 表单名称
23 + * @param: note 表单描述
24 + */
25 +export const addFormAPI = (params) => fn(fetch.post(Api.FORM_ADD, params));
26 +
27 +/**
28 + * @description: 查询表单
29 + * @param: client_id 主体客户id
30 + * @param: form_code 表单唯一标识
31 + * @param: name 表单名称,模糊查询
32 + */
33 +export const queryFormAPI = (params) => fn(fetch.get(Api.FORM_QUERY, params));
34 +
35 +/**
36 + * @description: 添加表单字段
37 + * @param: form_code 表单唯一标识
38 + * @param: component_code 组件标识
39 + */
40 +export const addFormFieldAPI = (params) => fn(fetch.post(Api.ADD_FORM_FIELD, params));
41 +
42 +/**
43 + * @description: 添加或修改表单字段属性设置
44 + * @param: form_code 表单唯一标识
45 + * @param: field_name 表单字段名。如果设置表单级(非字段级)的属性,可为空。
46 + * @param: component_code 组件标识
47 + * @param: property_code 属性标识
48 + * @param: setting_value 待设置的属性值。json数组,内部必须双引号。如果属性值是单值,数组只有一个元素。
49 + */
50 +export const addFormSettingAPI = (params) => fn(fetch.post(Api.ADD_FORM_SETTING, params));
51 +
52 +/**
53 + * @description: 查询表单的设置类组件的属性值
54 + * @param: form_code 表单唯一标识
55 + * @returns: enable 开启/停止表单 0=停止表单,1=开启表单
56 + * @returns: is_time_range 是否设定开启/停止时间 0=不设定,1=设定
57 + * @returns: is_count_down 是否显示停止倒计时 0=不显示,1-显示
58 + * @returns: begin_time 开启时间
59 + * @returns: end_time 停止时间
60 + */
61 +export const getFormSettingAPI = (params) => fn(fetch.get(Api.QUERY_FORM_SETTING, params));
62 +
63 +/**
64 + * @description: 验证便当密码
65 + * @param: form_code 表单唯一标识
66 + * @param: mmtx_password 用户输入的密码
67 + * @returns:
68 + */
69 +export const postVerifyPasswordAPI = (params) => fn(fetch.post(Api.VERIFY_PASSWORD, params));
1 +/*
2 + * @Date: 2022-06-17 14:54:29
3 + * @LastEditors: hookehuyr hookehuyr@gmail.com
4 + * @LastEditTime: 2022-11-17 13:46:01
5 + * @FilePath: /data-table/src/api/index.js
6 + * @Description: 首页接口
7 + */
8 +import { fn, fetch } from '@/api/fn';
9 +
10 +const Api = {
11 + INDEX: '/srv/?a=home_page',
12 +}
13 +/**
14 + * @description: 首页接口
15 + * @returns HOMEBANNER 轮播区
16 + * @returns HOMEZIXUN 观宗资讯
17 + * @returns HOMEVIDEO 视频展示
18 + * @returns HOMEKAISHI 本源法师开示
19 + * @returns spec_list 专题报告
20 + */
21 +export const indexAPI = (params) => fn(fetch.get(Api.INDEX, params));
1 +/*
2 + * @Author: hookehuyr hookehuyr@gmail.com
3 + * @Date: 2022-06-09 13:32:44
4 + * @LastEditors: hookehuyr hookehuyr@gmail.com
5 + * @LastEditTime: 2023-02-23 18:42:57
6 + * @FilePath: /data-table/src/api/wx/config.js
7 + * @Description:
8 + */
9 +import { fn, fetch } from '@/api/fn';
10 +
11 +const Api = {
12 + WX_JSAPI: '/srv/?a=wx_share',
13 +}
14 +
15 +/**
16 + * @description 获取微信CONFIG配置文件
17 + * @param {*} url
18 + * @returns {*} cfg
19 + */
20 +export const wxJsAPI = (params) => fn(fetch.get(Api.WX_JSAPI, params));
1 +/*
2 + * @Date: 2022-06-13 14:18:57
3 + * @LastEditors: hookehuyr hookehuyr@gmail.com
4 + * @LastEditTime: 2022-06-13 14:27:21
5 + * @FilePath: /tswj/src/api/wx/jsApiList.js
6 + * @Description: 文件描述
7 + */
8 +export const apiList = [
9 + // "updateAppMessageShareData",
10 + // "updateTimelineShareData",
11 + "onMenuShareTimeline",
12 + "onMenuShareAppMessage",
13 + "onMenuShareQQ",
14 + "onMenuShareWeibo",
15 + "onMenuShareQZone",
16 + "startRecord",
17 + "stopRecord",
18 + "onVoiceRecordEnd",
19 + "playVoice",
20 + "pauseVoice",
21 + "stopVoice",
22 + "onVoicePlayEnd",
23 + "uploadVoice",
24 + "downloadVoice",
25 + "chooseImage",
26 + "previewImage",
27 + "uploadImage",
28 + "downloadImage",
29 + "translateVoice",
30 + "getNetworkType",
31 + "openLocation",
32 + "getLocation",
33 + "hideOptionMenu",
34 + "showOptionMenu",
35 + "hideMenuItems",
36 + "showMenuItems",
37 + "hideAllNonBaseMenuItem",
38 + "showAllNonBaseMenuItem",
39 + "closeWindow",
40 + "scanQRCode",
41 + "chooseWXPay",
42 + "openProductSpecificView",
43 + "addCard",
44 + "chooseCard",
45 + "openCard"
46 +]
1 +/*
2 + * @Author: hookehuyr hookehuyr@gmail.com
3 + * @Date: 2022-06-09 13:32:44
4 + * @LastEditors: hookehuyr hookehuyr@gmail.com
5 + * @LastEditTime: 2022-06-09 13:42:06
6 + * @FilePath: /tswj/src/api/wx/config.js
7 + * @Description:
8 + */
9 +import { fn, fetch } from '@/api/fn';
10 +
11 +const Api = {
12 + WX_PAY: 'c/bill_paymentForBill.do',
13 +}
14 +
15 +/**
16 + * @description 微信支付接口
17 + * @param {*}
18 + * @returns {*}
19 + */
20 +export const wxPayAPI = (params) => fn(fetch.get(Api.WX_PAY, params));
1 +/*
2 + * @Date: 2022-07-18 10:22:22
3 + * @LastEditors: hookehuyr hookehuyr@gmail.com
4 + * @LastEditTime: 2023-03-23 17:45:36
5 + * @FilePath: /custom_form/src/constant.js
6 + * @Description: 文件描述
7 + */
8 +// 颜色变量
9 +export const styleColor = {
10 + baseColor: '#C2915F',
11 + backgroundColor: '#FFF9EF',
12 +}
...@@ -9,10 +9,18 @@ ...@@ -9,10 +9,18 @@
9 </template> 9 </template>
10 10
11 <script setup> 11 <script setup>
12 +import { computed, watchEffect, onMounted } from "vue";
13 +import { useDidShow } from '@tarojs/taro'
14 +import request from '@/utils/request';
12 import { storeToRefs } from 'pinia' 15 import { storeToRefs } from 'pinia'
13 import { mainStore } from '@/stores' 16 import { mainStore } from '@/stores'
14 import { wxInfo, getUrlParams } from "@/utils/tools"; 17 import { wxInfo, getUrlParams } from "@/utils/tools";
15 -import { computed, watchEffect, onMounted } from "vue"; 18 +// 初始化WX环境
19 +import wx from 'weixin-js-sdk'
20 +import { wxJsAPI } from '@/api/wx/config'
21 +import { apiList } from '@/api/wx/jsApiList.js'
22 +import { styleColor } from "@/constant.js";
23 +import { getFormSettingAPI } from "@/api/form.js";
16 24
17 // web端判断 25 // web端判断
18 const is_pc = computed(() => process.env.TARO_ENV === 'h5' && wxInfo().isPC); 26 const is_pc = computed(() => process.env.TARO_ENV === 'h5' && wxInfo().isPC);
...@@ -22,6 +30,83 @@ const { formInfo } = storeToRefs(store); ...@@ -22,6 +30,83 @@ const { formInfo } = storeToRefs(store);
22 30
23 console.warn(is_pc.value); 31 console.warn(is_pc.value);
24 32
33 +onMounted(async () => {
34 + const code = getUrlParams(location.href) ? getUrlParams(location.href).code : '';
35 + const model = getUrlParams(location.href) ? getUrlParams(location.href).model : '';
36 + const raw_url = encodeURIComponent(location.pathname + location.hash);
37 + // 数据收集设置
38 + const { data } = await getFormSettingAPI({ form_code: code });
39 + const form_setting = {};
40 + if (data.length) {
41 + Object.assign(form_setting, data[0]['property_list'], data[0]['extend']);
42 + }
43 + // 缓存表单设置
44 + store.changeFormSetting(form_setting);
45 + // 没有授权判断
46 + const no_auth_info = form_setting.wxzq_enable && !form_setting.x_field_weixin_openid;
47 + const no_preview_model = model !== 'preview';
48 + // 需要网页授权-必须要域名相同,需要上传到线上测试
49 + /**
50 + * 微信公众号授权模式
51 + * 空字符串=不授权,snsapi_base=静默授权,snsapi_userinfo=显式授权
52 + */
53 + // 非测试环境,没有授权信息,需要授权
54 + if (process.env.NODE_ENV !== 'development' && no_auth_info && form_setting.wxzq_scope) {
55 + // 预览模式不开启
56 + if (no_preview_model) {
57 + $router.replace({
58 + path: '/auth',
59 + query: {
60 + href: location.hash,
61 + code
62 + }
63 + });
64 + }
65 + } else {
66 + // 判断跳转页面
67 + if (form_setting.sjsj_enable === 0 && !form_setting.sjsj_enable) {
68 + // 表单已结束 -
69 + $router.push("/stop?status=disable");
70 + }
71 + // 开启后有开始和结束时间,不在时间范围的显示表单还未开始或者已经结束
72 + if (form_setting.sjsj_is_time_range && form_setting.sjsj_is_time_range) {
73 + // 未开始
74 + if (form_setting.server_time < form_setting.sjsj_begin_time) {
75 + $router.push("/stop?status=apply");
76 + }
77 + // 已结束
78 + if (form_setting.server_time > form_setting.sjsj_end_time) {
79 + $router.push("/stop?status=finish");
80 + }
81 + }
82 + // 启用分享功能,非预览模式
83 + if (form_setting.wxzq_is_share && no_preview_model) {
84 + const wxJs = await wxJsAPI({ form_code: code, url: raw_url });
85 + wxJs.data.jsApiList = apiList;
86 + wx.config(wxJs.data);
87 + wx.ready(() => {
88 + wx.showAllNonBaseMenuItem();
89 + });
90 + wx.error((err) => {
91 + console.warn(err);
92 + });
93 + }
94 + // 当数据量达到限额时,该表单将不能继续提交数据。
95 + if (form_setting.is_reach_sjsj_max_count) {
96 + showDialog({
97 + title: '温馨提示',
98 + message: '表单收集量已达到限额,无法再提交数据。',
99 + theme: 'round-button',
100 + confirmButtonColor: styleColor.baseColor
101 + });
102 + }
103 + // 设定填写次数
104 + if (form_setting.wxzq_scope && no_preview_model) {
105 +
106 + }
107 + }
108 +});
109 +
25 </script> 110 </script>
26 111
27 <style lang="less"> 112 <style lang="less">
......
1 +/*
2 + * @Date: 2022-10-28 14:34:22
3 + * @LastEditors: hookehuyr hookehuyr@gmail.com
4 + * @LastEditTime: 2022-11-01 13:27:09
5 + * @FilePath: /swx/src/stores/router.js
6 + * @Description: 缓存路由信息
7 + */
8 +import { defineStore } from 'pinia'
9 +
10 +export const routerStore = defineStore('router', {
11 + state: () => {
12 + return {
13 + url: '',
14 + }
15 + },
16 + actions: {
17 + add (path) {
18 + this.url = path
19 + },
20 + remove () {
21 + this.url = ''
22 + },
23 + },
24 +})
1 +/*
2 + * @Date: 2022-09-19 14:11:06
3 + * @LastEditors: hookehuyr hookehuyr@gmail.com
4 + * @LastEditTime: 2023-03-23 17:56:29
5 + * @FilePath: /custom_form/src/utils/request.js
6 + * @Description: 简单axios封装,后续按实际处理
7 + */
8 +
9 +// var axios = '';
10 +// if (process.env.TARO_ENV === 'weapp') {
11 +// console.warn(0);
12 +// // axios = require("axios-miniprogram");
13 +// axios = import("axios-miniprogram");
14 +// console.warn(axios);
15 +// } else if (process.env.TARO_ENV === 'h5') {
16 +// // axios = require('axios')
17 +// console.warn(1);
18 +// }
19 +// console.warn(await axios);
20 +// import axios from 'axios'
21 +// axios = await import('axios-miniprogram')
22 +// import axios from 'axios-miniprogram';
23 +import axios from 'axios'
24 +import Taro from '@tarojs/taro'
25 +import { routerStore } from '@/stores/router'
26 +import { DEV_PROXY_TARGET, PROD_PROXY_TARGET, PROGRAM_PREFIX } from '../../config/env'
27 +
28 +// import { ProgressStart, ProgressEnd } from '@/components/axios-progress/progress';
29 +// import store from '@/store'
30 +// import { getToken } from '@/utils/auth'
31 +// import BASE_URL from './config';
32 +let BASE_URL = ''
33 +if (process.env.NODE_ENV !== 'development') {
34 + BASE_URL = DEV_PROXY_TARGET // 测试服务器
35 +} else {
36 + BASE_URL = PROD_PROXY_TARGET // 正式服务器
37 +}
38 +
39 +// create an axios instance
40 +const service = axios.create({
41 + // 小程序跨域需要定义域名前缀,H5跨域有配置不需要
42 + baseURL: process.env.TARO_ENV === 'weapp' ? BASE_URL : '', // url = base url + request url
43 + // withCredentials: true, // send cookies when cross-domain requests
44 + timeout: 5000, // request timeout
45 +})
46 +
47 +service.defaults.params = {
48 + f: PROGRAM_PREFIX,
49 +}
50 +
51 +// request interceptor
52 +service.interceptors.request.use(
53 + config => {
54 + // console.warn(config)
55 + // console.warn(store)
56 + /**
57 + * POST PHP需要修改数据格式
58 + * 序列化POST请求时需要屏蔽上传相关接口,上传相关接口序列化后报错
59 + */
60 + // config.data = config.method === 'post' && !strExist(['a=upload', 'upload.qiniup.com'], config.url) ? qs.stringify(config.data) : config.data;
61 + return config
62 + },
63 + error => {
64 + // do something with request error
65 + console.error(error, 'err') // for debug
66 + return Promise.reject(error)
67 + }
68 +)
69 +
70 +// response interceptor
71 +service.interceptors.response.use(
72 + /**
73 + * If you want to get http information such as headers or status
74 + * Please return response => response
75 + */
76 +
77 + /**
78 + * Determine the request status by custom code
79 + * Here is just an example
80 + * You can also judge the status by HTTP Status Code
81 + */
82 + response => {
83 +
84 + // wx.hideLoading();
85 + // const res = response.data
86 + // // Toast.clear();
87 + // // if the custom code is not 20000, it is judged as an error.
88 + // if (res.code !== 100000) {
89 + // // 50008: Illegal token; 50012: Other clients logged in; 50014: Token expired;
90 + // if (res.code === 50008 || res.code === 50012 || res.code === 50014) {
91 + // // to re-login
92 + // // Toast.confirm('You have been logged out, you can cancel to stay on this page, or log in again', 'Confirm logout', {
93 + // // confirmButtonText: 'Re-Login',
94 + // // cancelButtonText: 'Cancel',
95 + // // type: 'warning'
96 + // // }).then(() => {
97 + // // // store.dispatch('user/resetToken').then(() => {
98 + // // // location.reload()
99 + // // // })
100 + // // })
101 + // } else {
102 + // // Toast.fail({
103 + // // message: res.message,
104 + // // duration: 1.5 * 1000
105 + // // })
106 + // // Tips.error(res.message, false)
107 + // }
108 + // return Promise.reject(new Error(res.message || 'Error'))
109 + // } else {
110 + // return res
111 + // }
112 + if (response.data.code === 401) {
113 + /**
114 + * 未授权跳转登录页
115 + * 授权完成后 返回当前页面
116 + */
117 + setTimeout(() => {
118 + Taro.navigateTo({
119 + url: '../../pages/auth/index?url=' + routerStore().url
120 + });
121 + }, 1000);
122 + }
123 + return response
124 + },
125 + error => {
126 + // Toast.clear();
127 + console.error('err' + error) // for debug
128 + // Toast.fail({
129 + // message: error.message,
130 + // duration: 1.5 * 1000
131 + // })
132 + return Promise.reject(error)
133 + }
134 +)
135 +
136 +export default service
...@@ -1684,6 +1684,15 @@ ...@@ -1684,6 +1684,15 @@
1684 "@tarojs/service" "3.6.2" 1684 "@tarojs/service" "3.6.2"
1685 "@tarojs/shared" "3.6.2" 1685 "@tarojs/shared" "3.6.2"
1686 1686
1687 +"@tarojs/plugin-http@^3.6.2":
1688 + version "3.6.2"
1689 + resolved "https://mirrors.cloud.tencent.com/npm/@tarojs/plugin-http/-/plugin-http-3.6.2.tgz#e3133a70626f42a3cf9f36c3d330aab7a0cd31ee"
1690 + integrity sha512-RzVqgtGzg5RDQN57zN7IjJqNR7yzRLYN799aaEAA/WL9mEImcmv5SjnnmcLjW8+D3M0hXOGrA6f+kHFhFoCNDg==
1691 + dependencies:
1692 + "@tarojs/runtime" "3.6.2"
1693 + "@tarojs/service" "3.6.2"
1694 + "@tarojs/shared" "3.6.2"
1695 +
1687 "@tarojs/plugin-platform-alipay@3.6.2": 1696 "@tarojs/plugin-platform-alipay@3.6.2":
1688 version "3.6.2" 1697 version "3.6.2"
1689 resolved "https://mirrors.cloud.tencent.com/npm/@tarojs/plugin-platform-alipay/-/plugin-platform-alipay-3.6.2.tgz#6e9ae8d801699addbc23ca3e858c3d9845d4c1d8" 1698 resolved "https://mirrors.cloud.tencent.com/npm/@tarojs/plugin-platform-alipay/-/plugin-platform-alipay-3.6.2.tgz#6e9ae8d801699addbc23ca3e858c3d9845d4c1d8"
...@@ -2930,6 +2939,11 @@ aws4@^1.8.0: ...@@ -2930,6 +2939,11 @@ aws4@^1.8.0:
2930 resolved "https://mirrors.cloud.tencent.com/npm/aws4/-/aws4-1.12.0.tgz#ce1c9d143389679e253b314241ea9aa5cec980d3" 2939 resolved "https://mirrors.cloud.tencent.com/npm/aws4/-/aws4-1.12.0.tgz#ce1c9d143389679e253b314241ea9aa5cec980d3"
2931 integrity sha512-NmWvPnx0F1SfrQbYwOi7OeaNGokp9XhzNioJ/CSBs8Qa4vxug81mhJEAVZwxXuBmYB5KDRfMq/F3RR0BIU7sWg== 2940 integrity sha512-NmWvPnx0F1SfrQbYwOi7OeaNGokp9XhzNioJ/CSBs8Qa4vxug81mhJEAVZwxXuBmYB5KDRfMq/F3RR0BIU7sWg==
2932 2941
2942 +axios-miniprogram@^2.0.0-rc-2:
2943 + version "2.0.0-rc-2"
2944 + resolved "https://mirrors.cloud.tencent.com/npm/axios-miniprogram/-/axios-miniprogram-2.0.0-rc-2.tgz#2431d61d4cd8813b420843907feb35ae254dccc1"
2945 + integrity sha512-GL1yDds9P/evGPqJFXIU/2VD9/9rUL7I4WnvExuocGWAfEO9oYV7DUt6Vjd5a6F1jkltVCwxtpMPQO9ZWGRZhQ==
2946 +
2933 babel-code-frame@^6.26.0, babel-code-frame@^6.8.0: 2947 babel-code-frame@^6.26.0, babel-code-frame@^6.8.0:
2934 version "6.26.0" 2948 version "6.26.0"
2935 resolved "https://mirrors.cloud.tencent.com/npm/babel-code-frame/-/babel-code-frame-6.26.0.tgz#63fd43f7dc1e3bb7ce35947db8fe369a3f58c74b" 2949 resolved "https://mirrors.cloud.tencent.com/npm/babel-code-frame/-/babel-code-frame-6.26.0.tgz#63fd43f7dc1e3bb7ce35947db8fe369a3f58c74b"
...@@ -13023,6 +13037,11 @@ websocket-extensions@>=0.1.1: ...@@ -13023,6 +13037,11 @@ websocket-extensions@>=0.1.1:
13023 resolved "https://mirrors.cloud.tencent.com/npm/websocket-extensions/-/websocket-extensions-0.1.4.tgz#7f8473bc839dfd87608adb95d7eb075211578a42" 13037 resolved "https://mirrors.cloud.tencent.com/npm/websocket-extensions/-/websocket-extensions-0.1.4.tgz#7f8473bc839dfd87608adb95d7eb075211578a42"
13024 integrity sha512-OqedPIGOfsDlo31UNwYbCFMSaO9m9G/0faIHj5/dZFDMFqPTcx6UwqyOy3COEaEOg/9VsGIpdqn62W5KhoKSpg== 13038 integrity sha512-OqedPIGOfsDlo31UNwYbCFMSaO9m9G/0faIHj5/dZFDMFqPTcx6UwqyOy3COEaEOg/9VsGIpdqn62W5KhoKSpg==
13025 13039
13040 +weixin-js-sdk@^1.6.0:
13041 + version "1.6.0"
13042 + resolved "https://mirrors.cloud.tencent.com/npm/weixin-js-sdk/-/weixin-js-sdk-1.6.0.tgz#ff50484d8118ce1208f11248cf4a1c0831577514"
13043 + integrity sha512-3IYQH7aalJGFJrwdT3epvTdR1MboMiH7vIZ5BRL2eYOJ12BNah7csoMkmSZzkq1+l92sSq29XdTCVjCJoK2sBQ==
13044 +
13026 weui@^1.1.2: 13045 weui@^1.1.2:
13027 version "1.1.3" 13046 version "1.1.3"
13028 resolved "https://mirrors.cloud.tencent.com/npm/weui/-/weui-1.1.3.tgz#0f0899bb61bb2ec603b2648367a8139298f81514" 13047 resolved "https://mirrors.cloud.tencent.com/npm/weui/-/weui-1.1.3.tgz#0f0899bb61bb2ec603b2648367a8139298f81514"
......