app.js
2.29 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
//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({
api: api,
get: fetchApi.fetch,
post: (params) => {
params.method = 'post';
return fetchApi.fetch(params);
},
stat: (data) => {
let params = {}
params.mode = 'log';
params.mode = 'log';
params.sid = false;
params.url = api.stat;
params.data = data;
params.method = "POST";
return fetchApi.fetch(params);
},
config: config,
router: router,
store: store,
onLaunch(options) {
let scene = options.scene;
// 根据场景值判断分享入口
// https://developers.weixin.qq.com/miniprogram/dev/reference/scene-list.html
// 小程序由分享进入
// if (scene == 1007 || scene == 1008 || scene == 1011 || scene == 1012 || scene == 1013) {
// this.globalData.share = true
// } else {
// this.globalData.share = false
// };
const MenuRect = wx.getMenuButtonBoundingClientRect();
const statusBarHeight = wx.getSystemInfoSync().statusBarHeight;
const height = (MenuRect.top - statusBarHeight) * 2 + MenuRect.height + MenuRect.top;
this.globalData.statusBarHeight = wx.getSystemInfoSync().statusBarHeight;
this.globalData.barHeight = height;
this.share();
this.stat({
classify: "minipro",
action: "detail_page",
primaryCode: "",
})
},
globalData: {
share: false,
indexInfo: null,
userInfo: null,
wxcode: store.getItem("wxcode"),
tlMemberCode: "",
},
//重写分享方法
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: ''
};
};
}
}
})
},
})