main.js
2.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
import Vue from 'vue'
import App from './App'
import store from "./store/index.js"
import check from './check/index.js'
// import myImage from './components/myImage.vue'
Vue.config.productionTip = false
Vue.prototype.$imgUrl="http://api.intewl.cn/uploads/"
Vue.prototype.apiUrl="http://api.intewl.cn/api"
// Vue.prototype.$imgUrl="http://www.mall.com/uploads/"
// Vue.prototype.apiUrl="http://www.mall.com/api"
Vue.prototype.check=check;
// Vue.component('my-image',myImage)
Vue.prototype.$request=function(url,data=''){
// var that=this
return new Promise((reslove,reject)=>{
uni.request({
url:this.apiUrl+url,
method:"POST",
header: {
'token': uni.getStorageSync('token')
},
data:data,
success:(res)=>{
console.log(res)
//token错误和返回结果都是用code
if(res.data.tcode==0){
reslove({"tcode":0,"msg":"未登录"})
// this.code=0
}
if(res.data.tcode==1){
reslove(res.data)
}
if(res.data.tcode==2){
uni.setStorageSync('token',res.data.token)
uni.request({
url:this.apiUrl+url,
method:"POST",
header: {
'token': uni.getStorageSync('token')
},
data:data,
success:(res)=>{
reslove(res.data)
}
})
}
if(res.data.tcode==3){
reslove({"tcode":0,"msg":"token失效"})
uni.setStorageSync("token",'')
}
if(res.data.tcode==4){
reslove({"tcode":0,"msg":"没有相关数据"})
uni.setStorageSync("token",'')
}
if(res.data.code==0||res.data.code){
reslove(res.data)
}
}
})
})
}
Vue.prototype.$href=function(data,type=1){
// if(uni.getStorageSync("token")){
if(type==1){
uni.navigateTo({
url:data
})
}
if(type==2){
uni.switchTab({
url:data
})
}
/* }else{
uni.navigateTo({
url:"/pages/login/login?backurl="+data
})
} */
}
Vue.prototype.$back=function(data,type=1){
if(uni.getStorageSync("token")){
if(type==1){
uni.navigateTo({
url:data
})
}else{
uni.switchTab({
url:data
})
}
}else{
uni.navigateTo({
url:"/pages/login/login?backurl=1"
})
}
}
// Vue.prototype.apiUrl="http://192.168.1.101/mall/public/api"
App.mpType = 'app'
const app = new Vue({
store,
...App
})
app.$mount()