| | |
| | | import axios from 'axios' |
| | | import * as $CONST from '@/utils/constant' |
| | | import * as $T from '@/utils/tools' |
| | | import $store from '@/store' |
| | | // import $store from '@/store' |
| | | |
| | | /** |
| | | * 定义传入参数数据格式 |
| | |
| | | } |
| | | } |
| | | return config |
| | | }*/ |
| | | } */ |
| | | |
| | | // request拦截器 |
| | | Service.interceptors.request.use( |
| | | config => { |
| | | // 临时追加 |
| | | if ($store.state.user.account) { |
| | | config.headers.account = $store.state.user.account |
| | | } |
| | | let copyConfig = Object.assign({}, config) |
| | | // 临时追加 |
| | | // if ($store.state.user.account) { |
| | | // config.headers.account = $store.state.user.account |
| | | // } |
| | | const copyConfig = Object.assign({}, config) |
| | | // copyConfig = filterOauthData(copyConfig) |
| | | // showDebugInfo(copyConfig) |
| | | copyConfig.cancelToken = new CancelToken((c) => { |
| | |
| | | const res = response.data |
| | | if (Number(res.code) !== 200 && Number(res.code) !== 0) { |
| | | $T.warning(res.message) |
| | | return res |
| | | return Promise.reject(res.message) |
| | | } else { |
| | | return res |
| | | } |
| | |
| | | const $http = {} |
| | | $http.$service = Service |
| | | $http.$axios = axios |
| | | $http.get = function(url, params = {}) { |
| | | $http.get = function (url, params = {}) { |
| | | if ($T.isInlineParams(url)) { |
| | | // 严格遵循restful标准的url的场景 |
| | | url = $T.replaceUrlParams(url, params) |
| | |
| | | params: $T.filterParams(params) |
| | | }) |
| | | } |
| | | $http.post = function(url, data = {}) { |
| | | $http.post = function (url, data = {}) { |
| | | return Service({ |
| | | url: url, |
| | | method: 'post', |
| | | data: data |
| | | }) |
| | | } |
| | | $http.put = function(url, data = {}) { |
| | | $http.put = function (url, data = {}) { |
| | | return Service({ |
| | | url: url, |
| | | method: 'put', |
| | | data: data |
| | | }) |
| | | } |
| | | $http.delete = function(url, data = {}) { |
| | | $http.delete = function (url, data = {}) { |
| | | return Service({ |
| | | url: url, |
| | | method: 'delete', |