1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- const install = (Vue, vm) => {
- Vue.prototype.$u.http.setConfig({
-
- baseUrl:'https://zbs.xueyousuohuo.cn/api',
-
- fileUrl:'http://api.dwbszbs.dev.xmnk.cn',
- originalData: true,
- dataType: 'json',
- showLoading: true,
- loadingText: '请求中...',
- loadingTime: 100,
- loadingMask: true,
-
- header: {
- 'content-type': 'application/json',
- 'Accept': 'application/json'
- }
- });
-
- Vue.prototype.$u.http.interceptor.request = (config) => {
-
-
-
- config.header.Authorization = vm.vuex_token;
-
-
-
-
-
-
-
- return config;
- }
-
- Vue.prototype.$u.http.interceptor.response = (res) => {
-
-
- if (res.statusCode == 401) {
- Vue.prototype.$u.toast('登录过期请重新登录')
- Vue.prototype.$u.vuex('vuex_token', '');
- Vue.prototype.$u.vuex('vuex_user', '');
- Vue.prototype.$u.vuex('vuex_id', '');
- uni.reLaunch({
- url: "/pages/login/skip"
- })
- return
- }
- if (res.statusCode == 422) {
- Vue.prototype.$u.toast(res.data.message)
- return false
- }
- if (res.statusCode == 400) {
- Vue.prototype.$u.toast(res.data.message)
- return false
- }
- if (res.statusCode == 500) {
- Vue.prototype.$u.toast(res.data.message)
- return false
- }
- if (res.statusCode == 423) {
- Vue.prototype.$u.toast(res.data.message)
- return false
- }
-
-
-
- if (res.statusCode < 300 && res.statusCode >= 200) {
-
- return res.data;
- } else {
- Vue.prototype.$u.toast(res.data.message)
- return false
- };
- }
- }
- export default {
- install
- }
|