index.vue
4.26 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<template>
<view class="index-page">
<nut-config-provider :theme-vars="themeVars">
<nut-dialog no-cancel-btn title="温馨提示" content="表单收集量已达到限额,无法再提交数据。" v-model:visible="show_reach_sjsj_max_count" @ok="onOk" />
</nut-config-provider>
</view>
</template>
<script setup>
import { ref, computed, watchEffect, onMounted } from "vue";
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 { mainStore } from '@/stores'
import { getFormSettingAPI } from '@/api/form.js'
import Taro from '@tarojs/taro'
// TAG: 自定义主题颜色
const themeVars = {
primaryColor: styleColor.baseColor,
};
const code = getUrlParams(location.href) ? getUrlParams(location.href).code : '';
const model = getUrlParams(location.href) ? getUrlParams(location.href).model : '';
const show_reach_sjsj_max_count = ref(false);
const onOk = () => {
show_reach_sjsj_max_count.value = false;
Taro.redirectTo({
url: `../table/index?code=${code}&model=${model}`
})
}
onMounted(async () => {
const store = mainStore();
// 数据收集设置
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 raw_url = encodeURIComponent(location.pathname + location.hash);
// 没有授权判断
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) {
Taro.redirectTo({
url: `../auth/index?href=${location.hash}&code=${code}`
})
}
} else {
// 判断跳转页面
if (form_setting.sjsj_enable === 0 && !form_setting.sjsj_enable) {
// 表单已结束
Taro.navigateTo({
url: '../stop/index?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) {
Taro.navigateTo({
url: '../stop/index?status=apply'
})
}
// 已结束
if (form_setting.server_time > form_setting.sjsj_end_time) {
Taro.navigateTo({
url: '../stop/index?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) {
show_reach_sjsj_max_count.value = true;
return false;
}
// 设定填写次数
if (form_setting.wxzq_scope && no_preview_model) {
}
}
// 获取信息后重定向到表单页
Taro.redirectTo({
url: `../table/index?code=${code}&model=${model}`
})
});
</script>
<style lang="less">
@prefix: ~"@{namespace}-x";
html,
body {
width: 100%;
// height: 100%;
color: @base-font-color;
// background-color: #f7f8fa;
// background-color: #fff9ef;
padding: 0;
margin: 0;
}
body {
position: relative;
p {
margin: 0;
padding: 0;
}
}
#app {
min-height: calc(100vh);
position: relative;
}
.@{prefix} {
color: red;
}
.global-center {
position: relative;
top: 50%;
transform: translateY(-50%);
}
.zIndex {
z-index: 4500 !important;
}
</style>