fix: 修复

This commit is contained in:
2025-11-12 19:31:46 +08:00
parent 1468002fe2
commit 967317367c
17 changed files with 1002 additions and 560 deletions

View File

@@ -4,7 +4,7 @@
* @Date: 2023-07-27 15:55:08
* @LastEditors: lip
*/
const TokenKey = 'App-Token'
const TokenKey = 'token' // 与微信登录时存储的 key 保持一致
export function getToken() {
return uni.getStorageSync(TokenKey)

View File

@@ -5,8 +5,12 @@
* @LastEditors: shirlwang
*/
// 应用全局配置
import config from '@/config.js'
let exports = {
// 引用根目录config.js的baseUrl避免重复配置
baseUrl: config.baseUrl,
// baseUrl: 'http://127.0.0.1:8903', // 本地开发
@@ -19,8 +23,8 @@ let exports = {
// baseUrl: 'http://10.160.0.5:8903', // 演示环境外网
// baseUrl: 'http://111.34.80.140:8081/prod-api', // 正式环境(不要轻易连接)
baseUrl: 'http://ks.zhaopinzao8dian.com/api/ks',
zytpBaseUrl: 'http://ks.zhaopinzao8dian.com/api/ks',
// baseUrl: 'http://ks.zhaopinzao8dian.com/api/ks', // 已从根目录config.js引用不再重复配置
zytpBaseUrl: 'http://ks.zhaopinzao8dian.com/api/ks_zytp/admin-api/zytp',

View File

@@ -18,10 +18,11 @@ const request = config => {
// 是否需要设置 token
const isToken = (config.headers || {}).isToken === false
config.header = config.header || {}
if (getToken() && !isToken) {
config.header['Authorization'] = 'Bearer ' + getToken()
// 从存储中获取微信登录的 token
const token = getToken()
if (token && !isToken) {
config.header['Authorization'] = 'Bearer ' + token
}
config.header['Authorization'] = 'Bearer ' + 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJsb2dpblR5cGUiOiJsb2dpbiIsImxvZ2luSWQiOiJzeXNfdXNlcjoxIiwicm5TdHIiOiJVMDRocERSZjdZMXJUbUxXb05uOUpzYUdDZzBNazJJQSIsInVzZXJJZCI6MX0.LZ29vvA4tK3b9Hki4nU9Jb1himXZM2AEOue3CMRY95w'
// get请求映射params参数
const baseType = config.baseUrlType
const requestBaseUrl = baseType === 'zytp' && zytpBaseUrl ? zytpBaseUrl : baseUrl
@@ -34,6 +35,26 @@ const request = config => {
requestUrl += (requestUrl.includes('?') ? '&' : '?') + url
}
}
// 如果是 getJobPathById 接口,打印完整 URL
if (config.url && config.url.includes('getJobPathById')) {
console.log('[请求URL] getJobPathById 完整请求URL:', requestUrl);
console.log('[请求URL] baseUrl:', requestBaseUrl);
console.log('[请求URL] 接口路径:', config.url);
console.log('[请求URL] 请求参数:', config.params);
}
// 如果是 recommendJob 接口,打印详细信息
if (config.url && config.url.includes('recommendJob')) {
console.log('[请求URL] recommendJob 完整请求URL:', requestUrl);
console.log('[请求URL] baseUrl:', requestBaseUrl);
console.log('[请求URL] 接口路径:', config.url);
console.log('[请求URL] 请求方法:', config.method);
console.log('[请求URL] 请求参数 (params):', config.params);
console.log('[请求URL] 请求数据 (data):', config.data);
console.log('[请求URL] Content-Type:', config.header?.['content-type']);
}
return new Promise((resolve, reject) => {
uni.request({
method: config.method || 'get',
@@ -52,11 +73,12 @@ const request = config => {
reject('网络出小差,请稍后再试')
return
}
const code = res.code || 200
// 处理 code0 和 200 都表示成功
const code = res.code !== undefined && res.code !== null ? res.code : 200
console.log(code, 'const code = res.code || 200')
const msg = errorCode[code] || res.msg || errorCode['default']
const isShowModel = getApp().globalData.isShowModel
if (code === 200) {
if (code === 200 || code === 0) {
resolve(res)
}else if (code === 401) {
if(isShowModel === false) {
@@ -89,12 +111,15 @@ const request = config => {
else if (code === 500) {
toast(msg)
reject('500')
} else if (code !== 200 && code !== 9999) {
} else if (code !== 200 && code !== 0 && code !== 9999) {
// 9999是正常的业务状态码不应该被当作错误处理
// 0 和 200 都表示成功
toast(msg)
reject(code)
}
resolve(res.data)
// 如果 code 是 0 或 200返回完整响应对象而不是 res.data
// 因为有些接口的 data 在 res.data 中,有些在 res 中
resolve(res)
})
.catch(error => {
console.log(error, 'error')