diff --git a/src/api/audio.js b/src/api/audio.js index 1c06729..d270496 100644 --- a/src/api/audio.js +++ b/src/api/audio.js @@ -4,8 +4,8 @@ import request from '@/utils/request' export function getAudioList(params) { return request({ url: '/audioManagement/list', - method: 'get', - params: { + method: 'post', + data: { current: params.current || 1, size: params.size || 20, recordingName: params.recordingName, diff --git a/src/api/user.js b/src/api/user.js index dc8c9bf..8f86f9b 100644 --- a/src/api/user.js +++ b/src/api/user.js @@ -2,9 +2,12 @@ import request from '@/utils/request' import { AUTH_API } from './config' export function login(data) { - // 转换参数名称以匹配后端接口要求 + const account = (data.username || '').trim() + // 同时传常见字段名,兼容不同后端 DTO(userName / username / loginAccount) const loginData = { - userName: data.username, // 后端需要 userName 而不是 username + userName: account, + username: account, + loginAccount: account, password: data.password } return request({ diff --git a/src/utils/request.js b/src/utils/request.js index 3359609..3471c4a 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -107,9 +107,21 @@ service.interceptors.response.use( } }, error => { - console.log('err' + error) // for debug + console.error('请求失败:', error.response?.status, error.response?.data || error.message) + let msg = error.message || '请求失败' + if (error.response) { + const rd = error.response.data + if (typeof rd === 'string' && rd) { + msg = rd + } else if (rd && typeof rd === 'object') { + msg = rd.message || rd.msg || rd.error || msg + } + if (error.response.status === 500 && msg === error.message) { + msg = '服务器内部错误(500),请检查后端服务与数据库是否正常,或查看后端日志' + } + } Message({ - message: error.message, + message: msg, type: 'error', duration: 5 * 1000 }) diff --git a/vue.config.js b/vue.config.js index acef527..e246198 100644 --- a/vue.config.js +++ b/vue.config.js @@ -57,8 +57,8 @@ module.exports = { proxy: { '/api': { // 可以通过环境变量 VUE_APP_API_BASE_URL 来配置后端地址 - // 例如: VUE_APP_API_BASE_URL=http://localhost:8090 npm run dev - target: process.env.VUE_APP_API_BASE_URL || 'http://localhost:8090', // 本地后端服务器地址 + // 例如: VUE_APP_API_BASE_URL=http://localhost:8091 npm run dev + target: process.env.VUE_APP_API_BASE_URL || 'http://localhost:8091', // 本地后端服务器地址 // target: 'https://api.huayang-star.com/', // 生产环境后端地址 changeOrigin: true, pathRewrite: {