index.vue
3.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<template>
<view class="index">
<nut-row>
<nut-col :span="is_pc ? 22 : 24" :offset="is_pc ? 1 : 0">
<div style="background-color: red; color: white;">span:24</div>
</nut-col>
</nut-row>
</view>
</template>
<script setup>
import { computed, watchEffect, onMounted } from "vue";
import { useDidShow } from '@tarojs/taro'
import request from '@/utils/request';
import { storeToRefs } from 'pinia'
import { mainStore } from '@/stores'
import { wxInfo, getUrlParams } from "@/utils/tools";
// 初始化WX环境
import wx from 'weixin-js-sdk'
import { wxJsAPI } from '@/api/wx/config'
import { apiList } from '@/api/wx/jsApiList.js'
import { styleColor } from "@/constant.js";
import { getFormSettingAPI } from "@/api/form.js";
// web端判断
const is_pc = computed(() => process.env.TARO_ENV === 'h5' && wxInfo().isPC);
const store = mainStore();
const { formInfo } = storeToRefs(store);
console.warn(is_pc.value);
onMounted(async () => {
const code = getUrlParams(location.href) ? getUrlParams(location.href).code : '';
const model = getUrlParams(location.href) ? getUrlParams(location.href).model : '';
const raw_url = encodeURIComponent(location.pathname + location.hash);
// 数据收集设置
const { data } = await getFormSettingAPI({ form_code: code });
const form_setting = {};
if (data.length) {
Object.assign(form_setting, data[0]['property_list'], data[0]['extend']);
}
// 缓存表单设置
store.changeFormSetting(form_setting);
// 没有授权判断
const no_auth_info = form_setting.wxzq_enable && !form_setting.x_field_weixin_openid;
const no_preview_model = model !== 'preview';
// 需要网页授权-必须要域名相同,需要上传到线上测试
/**
* 微信公众号授权模式
* 空字符串=不授权,snsapi_base=静默授权,snsapi_userinfo=显式授权
*/
// 非测试环境,没有授权信息,需要授权
if (process.env.NODE_ENV !== 'development' && no_auth_info && form_setting.wxzq_scope) {
// 预览模式不开启
if (no_preview_model) {
$router.replace({
path: '/auth',
query: {
href: location.hash,
code
}
});
}
} else {
// 判断跳转页面
if (form_setting.sjsj_enable === 0 && !form_setting.sjsj_enable) {
// 表单已结束 -
$router.push("/stop?status=disable");
}
// 开启后有开始和结束时间,不在时间范围的显示表单还未开始或者已经结束
if (form_setting.sjsj_is_time_range && form_setting.sjsj_is_time_range) {
// 未开始
if (form_setting.server_time < form_setting.sjsj_begin_time) {
$router.push("/stop?status=apply");
}
// 已结束
if (form_setting.server_time > form_setting.sjsj_end_time) {
$router.push("/stop?status=finish");
}
}
// 启用分享功能,非预览模式
if (form_setting.wxzq_is_share && no_preview_model) {
const wxJs = await wxJsAPI({ form_code: code, url: raw_url });
wxJs.data.jsApiList = apiList;
wx.config(wxJs.data);
wx.ready(() => {
wx.showAllNonBaseMenuItem();
});
wx.error((err) => {
console.warn(err);
});
}
// 当数据量达到限额时,该表单将不能继续提交数据。
if (form_setting.is_reach_sjsj_max_count) {
showDialog({
title: '温馨提示',
message: '表单收集量已达到限额,无法再提交数据。',
theme: 'round-button',
confirmButtonColor: styleColor.baseColor
});
}
// 设定填写次数
if (form_setting.wxzq_scope && no_preview_model) {
}
}
});
</script>
<style lang="less">
</style>