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