forked from dingyong0214/ThorUI-uniapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
113 lines (110 loc) · 2.51 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
import Vue from 'vue'
import App from './App'
import store from './store'
Vue.config.productionTip = false
const tui = {
toast: function(text, duration, success) {
uni.showToast({
title: text,
icon: success ? 'success' : 'none',
duration: duration || 2000
})
},
constNum: function() {
const res = uni.getSystemInfoSync();
return res.platform.toLocaleLowerCase() == "android" ? 300 : 0;
},
px: function(num) {
return uni.upx2px(num) + 'px';
},
interfaceUrl: function() {
//接口地址
return "https://www.thorui.cn";
},
request: function(url, postData, method, type, hideLoading) {
//接口请求
if (!hideLoading) {
uni.showLoading({
mask: true,
title: '请稍候...'
})
}
return new Promise((resolve, reject) => {
uni.request({
url: this.interfaceUrl() + url,
data: postData,
header: {
'content-type': type ? 'application/x-www-form-urlencoded' : 'application/json',
'authorization': this.getToken(),
'security': 1
},
method: method, //'GET','POST'
dataType: 'json',
success: (res) => {
!hideLoading && uni.hideLoading()
resolve(res.data)
},
fail: (res) => {
if (!hideLoading) {
this.toast("网络不给力,请稍后再试~")
}
reject(res)
}
})
})
},
uploadFile: function(src) {
const that = this
uni.showLoading({
title: '请稍候...'
})
return new Promise((resolve, reject) => {
const uploadTask = uni.uploadFile({
url: 'https://abc.cc',
filePath: src,
name: 'file',
header: {
'content-type': 'multipart/form-data'
},
formData: {},
success: function(res) {
uni.hideLoading()
let d = JSON.parse(res.data)
if (d.code === 1) {
let fileObj = JSON.parse(d.data)[0];
//文件上传成功后把图片路径数据提交到服务器,数据提交成功后,再进行下张图片的上传
resolve(fileObj)
} else {
that.toast(res.message);
}
},
fail: function(res) {
reject(res)
uni.hideLoading();
that.toast(res.message);
}
})
})
},
setToken: function(token) {
uni.setStorageSync("token", token)
},
getToken() {
return uni.getStorageSync("token")
},
isLogin: function() {
return uni.getStorageSync("token") ? true : false
},
webURL:function(){
return "https://www.thorui.cn/wx"
}
}
Vue.prototype.tui = tui
Vue.prototype.$eventHub = Vue.prototype.$eventHub || new Vue()
Vue.prototype.$store = store
App.mpType = 'app'
const app = new Vue({
store,
...App
})
app.$mount()