App.vue
5.2 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
<script>
import Vue from 'vue';
import { mapMutations, mapActions, mapState } from 'vuex';
import Wechat from './common/wechat/wechat';
import store from '@/common/store';
export default {
post:function(url, data, method, codetype) {
// console.log(url)
let t = this;
var promise = new Promise((resolve, reject) => {
//init
let header = {
'content-Type': 'application/x-www-form-urlencoded',
// 记得改token
// be151a07-a60f-436c-a63a-fb7fea42e2c8
// uni.getStorageSync('token') || ''
token: 'be151a07-a60f-436c-a63a-fb7fea42e2c8'
};
// console.log(header)
// let method = '';
// console.log(url + url)
// console.log(token)
// uni.showLoading({
// title: '加载中',
// })
//网络请求
// console.log(data)
uni.getNetworkType({
success(r) {
if (r.networkType == 'none') {
uni.showToast({
title: '您还没有连接网络哦,请先连接网络吧~',
icon: 'none',
duration: 1300
});
} else {
uni.request({
url: t.globalData.baseUrl + url,
data: data,
method: method || 'POST',
header: header,
emulateJSON: true,
success: function(res) {
//返回取得的数据
// uni.hideLoading();
if (res.data.code == 1) {
resolve(res.data);
} else if (res.data.code == 401) {
uni.removeStorageSync('token');
} else {
resolve(res.data);
}
},
fail: function(e) {
// console.log('88888888888888888')
// uni.hideLoading();
reject('网络出错');
uni.hideNavigationBarLoading();
uni.showToast({
title: '网络要挤爆啦,请稍后重试吧~',
icon: 'none',
duration: 1300
});
},
complete: function(daa) {
// console.log(daa);
// console.log('99999999999999999999999999999999999')
}
});
}
}
});
});
return promise;
},
globalData: {
userInfo: null,
// baseUrl: 'http://sortmessage.t.brotop.cn/api/',
baseUrl: 'http://suquan.t.brotop.cn/',
switch:true,
// imgUrl: 'https://yuanli.qingdi.com.cn/'
},
methods: {
//应用初始化,获取模板,获取页面路由,获取用户信息,保存用户Token并返回初始进入页面
...mapActions(['getAppInit', 'getTemplate', 'getRoutes', 'getUserInfo', 'setTokenAndBack']),
// 获取系统栏高度
async setAppInfo() {
let that = this;
let platform = '';
return new Promise((resolve, reject) => {
uni.getSystemInfo({
success: function(e) {
Vue.prototype.StatusBar = e.statusBarHeight;
// #ifdef H5
Vue.prototype.CustomBar = e.statusBarHeight + 45;
if (that.$wxsdk.isWechat()) {
platform = 'wxOfficialAccount';
} else {
platform = 'H5';
}
// #endif
// #ifdef APP-PLUS
platform = 'App';
if (e.platform == 'android') {
uni.setStorageSync('isAndroid', true);
Vue.prototype.CustomBar = e.statusBarHeight + 50;
} else {
Vue.prototype.CustomBar = e.statusBarHeight + 45;
uni.setStorageSync('isAndroid', false);
}
// #endif
// #ifdef MP-WEIXIN
platform = 'wxMiniProgram';
new Wechat().getWxMiniProgramSessionKey();
let custom = wx.getMenuButtonBoundingClientRect();
Vue.prototype.Custom = custom;
Vue.prototype.CustomBar = custom.bottom + custom.top - e.statusBarHeight;
// #endif
uni.setStorageSync('platform', platform);
resolve(platform);
}
});
});
},
// 自动登录
async autoLogin(data) {
let initData = data;
var wechat = new Wechat();
if (initData.wechat.autologin && !uni.getStorageSync('token')) {
// #ifdef H5
uni.setStorageSync('appid', initData.wechat.appid);
let token = await wechat.login();
this.setTokenAndBack(token);
// #endif
// #ifdef MP-WEIXIN
wechat.login();
// #endif
}
}
},
onLaunch: async function(options) {
if (options.query.mode === 'save') {
//截图模式
uni.setStorageSync('screenShot', true);
uni.setStorageSync('shop_id', options.query.shop_id);
}
// #ifdef MP-WEIXIN
if(options.scene !== 1154) {
var wechat = new Wechat();
wechat.checkMiniProgramUpdate();
}
// #endif
await this.setAppInfo();
await this.getTemplate(options);
let init = await this.getAppInit(options);
await this.autoLogin(init.data);
await this.getRoutes();
},
onShow: function() {
this.$store.commit('CART_NUM');
},
onHide: function() {}
};
</script>
<style lang="scss">
@import 'static/colorui/main.css';
@import 'static/colorui/icon.css';
@import 'static/font/shopro-icon.css';
// 其他scss集成在uni.scss,(变量,class,minix)
uni-radio:not([disabled]) .uni-radio-input:hover,
uni-checkbox:not([disabled]) .uni-checkbox-input:hover {
border-color: #ccc !important;
}
page {
-webkit-overflow-scrolling: touch; //ios滑动不流畅
height: 100%;
background: #f6f6f6;
width: 100%;
font-size: 30upx;
font-family: NotoSansHans-Bold;
word-break: break-all; //英文文本不换行
color: #333;
}
::-webkit-scrollbar {
width: 0;
height: 0;
color: transparent;
display: none;
}
</style>