forked from gs-wenbing/uni-mall
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
135 lines (119 loc) · 2.94 KB
/
main.js
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
import Vue from 'vue'
import store from './store'
import App from './App'
// 管理账号信息
const USERS_KEY = 'USERS_KEY';
const STATE_KEY = 'STATE_KEY';
const MAP_KEY = 'T2okmwOeQg5GvbXOpqiiG3PmDBpmTCG3';
const API_URL = "https://mockapi.eolinker.com/p6QCAEw5a26610182ff15ddc6f4f212776fdfbb3ce18328/";
const callApi = function(params, resolve) {
if(!params.notLoading)uni.showNavigationBarLoading();
let resultData = {};
let url = API_URL + params.action;
console.log(url)
const requestTask = uni.request({
url: url,
data: params.param,
timeout: 10000, //超时时间设置为10秒;
method: "GET",
header: {
'Content-Type': 'application/json'
},
success: (result) => {
if(!params.notLoading)uni.hideNavigationBarLoading();
if (result.statusCode == 200) {
if (result.data.result == 0) {
resultData.IsSuccess = true;
resultData.data = result.data.data;
resolve(resultData);
} else {
resultData.IsSuccess = false;
resultData.msg = result.data.data;
resolve(resultData);
}
} else {
resultData.IsSuccess = false;
resultData.msg = result.statusCode;
resolve(resultData);
}
},
fail: (data, code) => {
if(!params.notLoading)uni.hideNavigationBarLoading();
resultData.IsSuccess = false;
resultData.msg = JSON.stringify(data);
resolve(resultData);
}
});
}
const getNowFormatDate = function() {
var date = new Date();
var seperator1 = "-";
var seperator2 = ":";
var month = date.getMonth() + 1;
var strDate = date.getDate();
if (month >= 1 && month <= 9) {
month = "0" + month;
}
if (strDate >= 0 && strDate <= 9) {
strDate = "0" + strDate;
}
var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate +
" " + date.getHours() + seperator2 + date.getMinutes() +
seperator2 + date.getSeconds();
return currentdate;
}
const msg = (title, duration = 1500, mask = false, icon = 'none') => {
//统一提示方便全局修改
if (Boolean(title) === false) {
return;
}
uni.showToast({
title,
duration,
mask,
icon
});
}
const putExtra = obj =>{
return encodeURIComponent(JSON.stringify(obj));
}
const getExtra = obj =>{
return JSON.parse(decodeURIComponent(obj));
}
const callApix = params => {
//模拟异步请求数据
return new Promise(resolve => {
callApi(params,resolve)
})
}
//获取上一页实例,可直接调用上页所有数据和方法
const prePage = () => {
let pages = getCurrentPages();
let prePage = pages[pages.length - 2];
// #ifdef H5
return prePage;
// #endif
return prePage.$vm;
}
const prePageWebview = () => {
let pages = getCurrentPages();
let prePage = pages[pages.length - 2];
var currentWebview = prePage.$getAppWebview();
return currentWebview;
}
Vue.config.productionTip = false
Vue.prototype.$fire = new Vue();
Vue.prototype.$store = store;
Vue.prototype.$api = {
msg,
prePage,
callApix,
putExtra,
getExtra,
MAP_KEY
};
App.mpType = 'app'
const app = new Vue({
...App
})
app.$mount()