forked from gooking/uni-app-mall
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.vue
More file actions
263 lines (253 loc) · 6.76 KB
/
Copy pathApp.vue
File metadata and controls
263 lines (253 loc) · 6.76 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
<script>
const WXAUTH = require('@/common/wxauth.js')
const TTAUTH = require('@/common/ttauth.js')
const QQAUTH = require('@/common/qqauth.js')
export default {
globalData: {
h5Domain: 'https://flpt.jxsupplier.com',
goLogin: false,
subDomain: 'tz', // jdjf0115
merchantId: 951, // 42151
version: '2.0.0',
sysconfigkeys: 'mallName,shopMod,share_profile,recharge_amount_min,open_growth,shopping_cart_vop_open,needIdCheck',
wxpayOpenAppId: 'wx9b04553fd8c7b9c3', // 微信开放平台的移动端应用appID
openAlipayProvider: false, // 是否开通支付宝支付
addressLevel: 3, // 省市区到3级还是4级,可选 3 或者 4
},
onLaunch: function() {
// https://www.yuque.com/apifm/nu0f75/cdqz1n
this.$wxapi.setMerchantId(this.globalData.merchantId)
this.$wxapi.init(this.globalData.subDomain)
const _this = this
// 1.1.0版本之前关于http拦截器代码,已平滑移动到/common/http.interceptor.js中
// 注意,需要在/main.js中实例化Vue之后引入如下(详见文档说明):
// import httpInterceptor from '@/common/http.interceptor.js'
// Vue.use(httpInterceptor, app)
// process.env.VUE_APP_PLATFORM 为通过js判断平台名称的方法,结果分别如下:
/**
* h5,app-plus(nvue下也为app-plus),mp-weixin,mp-alipay......
*/
this.checkForUpdate(); // 检查新版本
this.queryConfigBatch();
},
onShow(e) {
if (e && e.query && e.query.inviter_id) {
this.$u.vuex('referrer', e.query.inviter_id)
}
if (e && e.query && e.query.kjJoinUid) {
this.$u.vuex('kjJoinUid', e.query.kjJoinUid)
}
if (e && e.query && e.query.code) {
// 微信登陆
this.wxmpLogin(e.query.code)
return
} else {
this.autoLogin()
}
},
onHide: function() {
// console.log('App Hide,app不再展现在前台')
},
onPageNotFound(e) {
// 页面不存在 {path: '/1212', query: {a: '123'}, isEntryPage: true}
console.error(e)
},
methods: {
async queryConfigBatch() {
const sysconfigkeys = this.globalData.sysconfigkeys
if (!sysconfigkeys) {
return
}
// https://www.yuque.com/apifm/nu0f75/dis5tl
const res = await this.$wxapi.queryConfigBatch(sysconfigkeys)
if (res.code == 0) {
const sysconfigMap = {}
res.data.forEach(config => {
sysconfigMap[config.key] = config.value
})
this.$u.vuex('sysconfigMap', sysconfigMap)
}
},
checkForUpdate() {
// #ifdef MP
const updateManager = uni.getUpdateManager();
updateManager.onCheckForUpdate(function(res) {
// 请求完新版本信息的回调
console.log(res.hasUpdate);
});
updateManager.onUpdateReady(function(res) {
uni.showModal({
title: '更新提示',
content: '新版本已经准备好,是否重启应用?',
success(res) {
if (res.confirm) {
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
updateManager.applyUpdate();
}
}
});
});
updateManager.onUpdateFailed(function(res) {
// 新的版本下载失败
});
// #endif
// #ifdef APP-PLUS
// APP 自动更新
// #endif
},
async autoLogin(force) {
// 自动登陆
// #ifdef MP-WEIXIN
const isLogined = await WXAUTH.checkHasLogined()
if (!isLogined) {
await WXAUTH.authorize()
await WXAUTH.bindSeller()
}
setTimeout(() => {
uni.$emit('loginOK', {})
}, 500)
// #endif
// #ifdef MP-QQ
const isLogined = await QQAUTH.checkHasLogined()
if (!isLogined) {
await QQAUTH.authorize()
await QQAUTH.bindSeller()
}
setTimeout(() => {
uni.$emit('loginOK', {})
}, 500)
// #endif
// #ifdef MP-TOUTIAO
const isLogined = await TTAUTH.checkHasLogined()
if (!isLogined) {
await TTAUTH.authorize()
await TTAUTH.bindSeller()
}
setTimeout(() => {
uni.$emit('loginOK', {})
}, 500)
// #endif
if (!force) {
return
}
// #ifdef H5
const isLogined = await this.checkHasLoginedH5()
if (!isLogined) {
// 判断是普通浏览器还是微信浏览器
const ua = window.navigator.userAgent.toLowerCase();
if (ua.match(/MicroMessenger/i) == 'micromessenger') {
// 微信内置浏览器打开的
// https://www.yuque.com/apifm/nu0f75/fpvc3m
const res = await this.$wxapi.siteStatistics()
const wxMpAppid = res.data.wxMpAppid
let _domian = this.globalData.h5Domain + '/pages/index/index'
_domian = encodeURIComponent(_domian)
console.log(_domian);
if (!this.globalData.goLogin) {
this.globalData.goLogin = true
window.parent.location.href = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' +
wxMpAppid + '&redirect_uri=' + _domian +
'&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect'
}
} else {
// 其他浏览器打开的, 按需登陆,不能直接跳转到登陆界面
uni.navigateTo({
url: "/pages/login/login"
})
}
}
// #endif
},
async checkHasLoginedH5() {
const _this = this.$vm ? this.$vm : this
if (!_this.token) {
return false
}
// https://www.yuque.com/apifm/nu0f75/mp9f59
const res = await _this.$wxapi.checkToken(_this.token)
if (res.code != 0) {
_this.$u.vuex('token', '')
return false
}
return true
},
async wxmpLogin(code) {
// https://www.yuque.com/apifm/nu0f75/lh6cd3
const res = await this.$wxapi.wxmpAuth({
code
})
if (res.code == 0) {
this.$u.vuex('token', res.data.token)
this.$u.vuex('uid', res.data.uid)
this.$u.vuex('openid', res.data.openid)
setTimeout(() => {
uni.$emit('loginOK', {})
}, 500)
}
}
}
}
</script>
<style lang="scss">
/*每个页面公共css */
@import "@/uni_modules/uview-ui/index.scss";
.price-score {
position: relative;
display: flex;
color: #e64340;
font-size: 38rpx;
text {
padding: 0 6rpx;
font-size: 28rpx;
}
.item {
padding: 0 8rpx;
display: flex;
align-items: center;
}
.original {
margin-left: 32rpx;
color: #aaa;
text-decoration: line-through
}
.score-icon {
width: 28rpx;
height: 28rpx;
padding: 0 6rpx;
}
}
.goods-title-tag {
display: inline-flex !important;
margin-right: 24rpx;
}
.goods-title {
color: #333;
font-size: 28rpx;
}
.pt16 {
padding-top: 16rpx !important;
}
.submit-btn {
padding: 32rpx;
}
.form-box {
padding: 32rpx;
}
.mt32 {
margin-top: 32rpx;
}
.label-title{
font-size:28rpx;
font-weight: bold;
color:#000000;
padding: 30rpx;
display: flex;
align-items: center;
.icon {
width: 6rpx;
height: 30rpx;
background: linear-gradient(360deg, #FFAD56 0%, #FF8A46 100%);
margin-right: 8rpx;
}
}
</style>