| | |
| | | /*
|
| | | * @Date: 2022-11-09 12:37:25
|
| | | * @LastEditors: Sneed
|
| | | * @LastEditTime: 2024-01-05 23:41:48
|
| | | * @LastEditTime: 2024-01-12 22:39:31
|
| | | * @FilePath: /belleson-frontend/Users/mache/Documents/demo/mdc/src/utils/ajax.js
|
| | | */
|
| | | import axios from 'axios'
|
| | |
| | |
|
| | | // request拦截器
|
| | | service.interceptors.request.use(config => {
|
| | | console.log(config.url,'config')
|
| | | config.url = `${URL_CFG.BASE_URL}${config.url}`
|
| | | if (store.getters.token) {
|
| | | config.headers['mdc-token'] = getToken().value // 让每个请求携带自定义token 请根据实际情况自行修改
|
| | | }
|
| | | if (config.mytype == 'json') {
|
| | | config.headers = {
|
| | | 'Content-Type':'application/json; charset=UTF-8'
|
| | | }
|
| | | }
|
| | | config.transformRequest = [function(data) {
|
| | | // debugger
|
| | | if (config.mytype == 'json') {
|
| | | return JSON.stringify(data)
|
| | | }
|
| | | return qs.stringify(data)
|
| | | }]
|
| | | return config
|
| | |
| | | */
|
| | | const status = response.status
|
| | | if (status !== 200) {
|
| | | Message({
|
| | | message: '服务连接异常,请稍后重试或联系管理员',
|
| | | type: 'error',
|
| | | duration: 5 * 1000
|
| | | })
|
| | | // Message({
|
| | | // message: '服务连接异常,请稍后重试或联系管理员',
|
| | | // type: 'error',
|
| | | // duration: 5 * 1000
|
| | | // })
|
| | | return Promise.reject('error')
|
| | | } else {
|
| | | // const data = response.data || {}
|
| | |
| | | // }
|
| | | if (response.data.result === 'SUCCESS') {
|
| | | return response.data
|
| | | } else {
|
| | | Message({
|
| | | message: response.data.msg,
|
| | | type: 'error',
|
| | | duration: 3 * 1000
|
| | | })
|
| | | return Promise.reject('error')
|
| | | }
|
| | | }
|
| | | },
|
| | |
| | | data: params
|
| | | })
|
| | | },
|
| | | postJson: function(url, params) {
|
| | | console.log(url,'url')
|
| | | return service({
|
| | | mytype: 'json',
|
| | | url: url,
|
| | | method: 'post',
|
| | | data: params
|
| | | })
|
| | | },
|
| | | // get请求
|
| | | get: function(url, params) {
|
| | | return service({
|