12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- const install = (Vue, vm) => {
- Vue.prototype.$u.http.setConfig({
- baseUrl: Vue.prototype.$url,
- loadingText: '加载中...',
- loadingTime: 800,
- showLoading: true,
- loadingMask: true,
- originalData: true,
-
- header: {},
- });
-
- Vue.prototype.$u.http.interceptor.request = (config) => {
-
-
-
-
-
-
-
-
-
-
- const token = uni.getStorageSync('token');
- config.header.token = token;
-
-
-
- return config;
-
-
- }
-
- Vue.prototype.$u.http.interceptor.response = (res) => {
- if (res.statusCode == 200) {
-
-
-
- return res.data;
- } else {
-
- if (res.statusCode == 500) {
- var title = ''
- var title1 = ''
-
- var html = res.data
- var start = html.indexOf('<h1>')
- var end = html.indexOf('</h1>')
- title = html.substring(start + 4, end)
- var start1 = html.indexOf('</abbr> in <a class="toggle" title=')
- var end1 = html.indexOf('</a></h2>')
- title1 = html.substring(start1 + 35, end1)
- if (title1 && title) {
- uni.showModal({
- title: `网络错误:${res.statusCode}`,
- content: `位置:${title1}\r\n 标题:${title}`
- })
- } else {
- uni.showModal({
- title: `网络错误:${res.statusCode}`,
- })
- }
- } else {
-
-
-
- }
- return false;
- }
- }
- }
- export default {
- install
- }
|