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 | 46 +++++++++++++++++++++++++++++++++++++--------- 1 files changed, 37 insertions(+), 9 deletions(-) diff --git a/src/utils/ajax.js b/src/utils/ajax.js index 4d675cb..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:08:20 + * @LastEditTime: 2024-01-16 23:18:23 * @FilePath: /belleson-frontend/Users/mache/Documents/demo/mdc/src/utils/ajax.js */ import axios from 'axios' @@ -10,14 +10,14 @@ import { getToken, setToken } from '@/utils/auth' import qs from 'qs' const URL_CFG = { - BASE_URL: '', + BASE_URL: '/mdc', WEB_SOCKET_URL: '' } // 鍒涘缓axios瀹炰緥 const service = axios.create({ // baseURL: process.env.BASE_API, // api鐨刡ase_url - timeout: 3000 // 璇锋眰瓒呮椂鏃堕棿 + timeout: 30000 // 璇锋眰瓒呮椂鏃堕棿 }) // request鎷︽埅鍣� @@ -26,7 +26,16 @@ 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 @@ -45,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 || {} @@ -67,7 +76,16 @@ // } else { // return response.data // } - return 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') + } } }, error => { @@ -84,12 +102,22 @@ URL_CFG, // post璇锋眰 post: function(url, params) { + console.log(url,'url') return service({ url: url, method: 'post', 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