From 6a33da2ac6cca708b14c254c6e1de416919cfda5 Mon Sep 17 00:00:00 2001 From: gaosp <gaosp> Date: 星期二, 16 一月 2024 23:23:14 +0800 Subject: [PATCH] update --- src/utils/ajax.js | 40 ++++++++++++++++++++++++++++++++-------- 1 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/utils/ajax.js b/src/utils/ajax.js index f17dcb3..afa9c1e 100644 --- a/src/utils/ajax.js +++ b/src/utils/ajax.js @@ -1,7 +1,7 @@ /* * @Date: 2022-11-09 12:37:25 * @LastEditors: Sneed - * @LastEditTime: 2024-01-05 23:41:48 + * @LastEditTime: 2024-01-16 23:18:23 * @FilePath: /belleson-frontend/Users/mache/Documents/demo/mdc/src/utils/ajax.js */ import axios from 'axios' @@ -17,17 +17,25 @@ // 鍒涘缓axios瀹炰緥 const service = axios.create({ // baseURL: process.env.BASE_API, // api鐨刡ase_url - timeout: 3000 // 璇锋眰瓒呮椂鏃堕棿 + timeout: 30000 // 璇锋眰瓒呮椂鏃堕棿 }) // 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 @@ -46,11 +54,11 @@ */ 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 || {} @@ -70,6 +78,13 @@ // } if (response.data.result === 'SUCCESS') { return response.data + } else { + Message({ + message: response.data.msg, + type: 'error', + duration: 3 * 1000 + }) + return Promise.reject('error') } } }, @@ -94,6 +109,15 @@ 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({ -- Gitblit v1.9.3