webview.js
3.83 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
import accountModel from '../../models/account/index';
import saleModel from '../../models/activity/sale/index';
import {parse, stringify} from '../../vendors/query-stringify';
import config from '../../common/config';
import udid from '../../common/udid';
import event from '../../common/event';
import { verify } from '../../common/api';
import { tapGoBind } from '../../common/login';
Page({
/**
* 页面的初始数据
*/
data: {
url: ''
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function(options) {
if (options.scene) {
accountModel.getMiniAppRealParam(decodeURIComponent(options.scene || ''))
.then(query => {
global.router.go('webView', query);
});
} else {
if (!options.limitId) {
this.setData({
activityExist: '2'
});
options.url = decodeURIComponent(options.url || '');
if (options.url) {
let uid = this.getUid();
const search = options.url.split('?')[1] || '';
const qs = parse(search);
if (Number(qs.needLogin) === 1 && uid === 0) {
event.on('user-login-success', () => {
this.generateUrl(options);
});
tapGoBind();
} else {
this.generateUrl(options);
}
}
} else { // 限定C类公众号文章
saleModel.queryLimitActivityDetail({id: options.limitId}).then(res => {
// 不存在的活动
if (!res.data || res.data.code === 400) {
return this.setData({
activityExist: '1'
});
} else {
options.url = decodeURIComponent(options.url || '');
if (options.url) {
let uid = this.getUid();
const search = options.url.split('?')[1] || '';
const qs = parse(search);
if (Number(qs.needLogin) === 1 && uid === 0) {
event.on('user-login-success', () => {
this.generateUrl(options);
});
tapGoBind();
} else {
this.generateUrl(options);
}
}
this.setData({
activityExist: '2'
});
}
});
}
}
},
/**
* 获取 UID
*/
getUid: function() {
const app = getApp();
return app && app.getUid() ? app.getUid() : 0;
},
/**
* 生成链接
*/
generateUrl: function(options) {
wx.showLoading({
title: '正在加载中...'
});
let app = getApp();
let param = {
app_version: config.apiParams.app_version,
session_key: app && app.getSessionKey() || '',
client_type: config.apiParams.client_type,
udid: udid.get()
};
let uid = this.getUid();
if (uid) {
param.uid = uid;
}
let url = options.url;
let params = verify.computeSecret(param);
const [uri, search] = url.split('?');
const qs = parse(search);
this.setData({
url: uri + '?' + stringify(Object.assign({}, params, qs))
}, wx.hideLoading);
},
checkOther: function() {
global.router.go('activityIndex');
}
});