main.js
2.1 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
import Vue from 'vue'
import App from './App'
import store from "./store/index.js"
import check from './check/index.js'
import TIM from 'tim-js-sdk'
import tim from './commen/tim/tim.js'
import commen from './commen/commen.js'
// 引入全局uView
import uView from 'uview-ui';
Vue.use(uView);
Vue.config.productionTip = false
Vue.prototype.check=check;
Vue.prototype.apiUrl="http://app.zhaodizhu.cn/api"
// Vue.prototype.apiUrl="http://landlord.t.brotop.cn/api"
Vue.prototype.imgUrl="http://qiniu.zhaodizhu.cn"
Vue.prototype.tim = tim.tim //tim sdk 引入后生成的tim服务
Vue.prototype.$TIM = TIM //tim 的状态/事件 常量
Vue.prototype.$commen = commen
Vue.prototype.$request=function(url,data='',type = 1){
// var that=this
return new Promise((reslove,reject)=>{
if(type == 1){
uni.showLoading({
title:'加载中...'
})
}
if(type == 3){
uni.showLoading({
title:'发布中'
})
}
if(type == 2){
uni.showLoading({
title:'保存中...'
})
}
uni.request({
url:this.apiUrl+url,
method:"POST",
header: {
'token': uni.getStorageSync('token')
},
data:data,
success:(res)=>{
// console.log('接口返回数据',res);
if(res.data.code == 401){
uni.setStorageSync("token",'')
uni.reLaunch({
url:"/pages/index/login"
})
}
if(res.data.code == 0 || res.data.code==1){
reslove(res.data)
}
uni.hideLoading()
},
fail: (err) => {
console.log('请求失败',err)
}
})
})
}
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
})
}
if(type==3){
uni.redirectTo({
url:data
})
}
}else{
uni.reLaunch({
url:"/pages/index/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.reLaunch({
url:"/pages/login/login?backurl=1"
})
}
}
App.mpType = 'app'
const app = new Vue({
store,
...App
})
app.$mount()