1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- const install = (Vue, vm) => {
- Vue.prototype.$u.http.setConfig({
-
-
- baseUrl:'https://bcsyds.hactcm.edu.cn/api',
- originalData: true,
- dataType: 'json',
- showLoading: true,
- loadingText: '请求中...',
- loadingTime:100,
- loadingMask: true,
-
-
- header: {
- 'content-type': 'application/json',
- 'type': 'app'
- }
- });
-
- Vue.prototype.$u.http.interceptor.request = (config) => {
-
-
-
- config.header.Authorization = vm.vuex_token;
- if (config.method.toUpperCase() == 'PUT') {
- config.method = 'POST'
- config.header['X-HTTP-Method-Override'] = 'PUT'
- }
- if (config.method.toUpperCase() == 'DELETE') {
- config.method = 'POST'
- config.header['X-HTTP-Method-Override'] = 'DELETE'
- }
-
-
-
-
-
-
-
- return config;
- }
-
- Vue.prototype.$u.http.interceptor.response = (res) => {
-
-
- if (res.statusCode == 401) {
- console.log("重新登录")
- uni.reLaunch({
- url: "/pages/login/index"
- })
- 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 == 423) {
- 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 < 300 && res.statusCode >= 200) {
-
- return res.data;
- } else return false;
- }
- }
- export default {
- install
- }
|