app.js
2.66 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
//app.js
let fetchApi = require('./http/fetch-api.js');
let api = require('./http/api');
let config = require('./config');
let router = require('./router/index');
let store = require('./utils/stroage');
require('./http/mock-data');
App({
get: fetchApi.fetch,
post: (params) => {
params.method = 'post';
return fetchApi.fetch(params);
},
api: api,
config: config,
router: router,
store: store,
globalData: {
isTest: false, //是否测试状态 测试状态可触发点击摇一摇
indexInfo: null,
userInfo: null,
wxcode: store.getItem("wxcode"),
tlMemberCode: "",
curCoupon: null,
questionResult: null, //答题的结果 弹力值 elasticValue
posterWishList: [], //海报用
giftData: null, // 实物奖 userTabel prizeDetail用
coopOptions: null, // 协作页 onload入参
},
onLaunch: function (options) {
// console.log("app q:", decodeURIComponent(options.query.q));
console.log("onLaunch options:", options)
this.globalData.coopOptions = null;
this.share();
this.shake();
},
shake() {
wx.onAccelerometerChange(function (res) {
let pages = getCurrentPages();
let view = pages[pages.length - 1];
if (view) {
let data = view.data;
if (data.isShake) {
view.onShakeHandler(res);
}
}
});
},
//重写分享方法
share: function () {
//监听路由切换
//间接实现全局设置分享内容
wx.onAppRoute(function (res) {
//获取加载的页面
let pages = getCurrentPages();
//获取当前页面的对象
let view = pages[pages.length - 1];
let data;
if (view) {
data = view.data;
if (!data.isOverShare) {
data.isOverShare = true;
view.onShareAppMessage = function (res) {
//分享配置
return {
title: '弹弹弹 看你有多弹',
path: 'pages/index/index',
// imageUrl: './image/share.png',
imageUrl: 'https://kd.cdn.xyiyang.com/weapp/marubi/wish-list/share.png'
// imageUrl: 'https://kdcdn.oss-cn-shenzhen.aliyuncs.com/weapp/marubi/wish-list/share.png'
};
};
}
}
})
},
// 获取用户基本信息
queryIndex(query = {
auth: true,
// loading: true
}) {
return new Promise((resolve, reject) => {
this.post({
url: this.api.index,
data: {},
// loading: loading,
}).then((result) => {
this.globalData.indexInfo = result;
this.globalData.userInfo = result.userInfo;
resolve(result)
}).catch((err) => {
reject();
});
});
}
})