-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
64 lines (56 loc) · 1.14 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
import App from './App'
// #ifndef VUE3
import Vue from 'vue'
Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
...App
})
app.$mount()
// #endif
// #ifdef VUE3
import {
createSSRApp
} from 'vue'
export function createApp() {
const app = createSSRApp(App)
return {
app
}
}
// #endif
let baseUrl = "http://192.168.3.7:8080/emos-wx-api"
Vue.prototype.url = {
register: baseUrl + "/user/register",
login: baseUrl + "/user/login",
}
Vue.prototype.ajax = function(url, method, data, fun) {
uni.request({
"url": url,
"method": method,
"header": {
token: uni.getStorageSync('token')
},
"data": data,
success: function(resp) {
if (resp.statusCode == 401) {
uni.redirectTo({
url: '../login/login'
});
} else if (resp.statusCode == 200 && resp.data.code == 200) {
let data = resp.data
if (data.hasOwnProperty("token")) {
console.log(resp.data)
let token = data.token
uni.setStorageSync("token", token)
}
fun(resp)
} else {
uni.showToast({
icon: 'none',
title: resp.data
});
}
}
});
}