修改当页面未登录时自动跳转登录页
This commit is contained in:
parent
4b8653a11b
commit
6a865ff750
12
pages.json
12
pages.json
|
|
@ -1,11 +1,5 @@
|
|||
{
|
||||
"pages": [
|
||||
{
|
||||
"path": "pages/login/login",
|
||||
"style": {
|
||||
"navigationStyle": "custom"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/index/index",
|
||||
"style": {
|
||||
|
|
@ -13,6 +7,12 @@
|
|||
"navigationStyle": "custom"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/login/login",
|
||||
"style": {
|
||||
"navigationStyle": "custom"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/lease/lease",
|
||||
"style": {
|
||||
|
|
|
|||
|
|
@ -20,17 +20,17 @@ const ENV_CONFIG = {
|
|||
// 开发环境
|
||||
// baseUrl: 'http://192.168.2.174:4501',
|
||||
baseUrl: 'https://chu.chuangtewl.com/prod-api',
|
||||
appId: 1, // TODO: 根据实际后端配置调整
|
||||
appId: 1,
|
||||
},
|
||||
trial: {
|
||||
// 体验版
|
||||
baseUrl: 'https://chu.chuangtewl.com/prod-api',
|
||||
appId: 1, // TODO: 根据实际后端配置调整
|
||||
appId: 1,
|
||||
},
|
||||
release: {
|
||||
// 正式版
|
||||
baseUrl: 'https://chu.chuangtewl.com/prod-api',
|
||||
appId: 1, // TODO: 根据实际后端配置调整
|
||||
appId: 1,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -126,6 +126,16 @@ function handleResponseError(res, reject, options = {}) {
|
|||
hideLoading()
|
||||
}
|
||||
|
||||
// 添加调试日志
|
||||
console.log('处理响应错误:', {
|
||||
res: res,
|
||||
resType: typeof res,
|
||||
hasCode: 'code' in res,
|
||||
hasMsg: 'msg' in res,
|
||||
code: res.code,
|
||||
msg: res.msg,
|
||||
})
|
||||
|
||||
const errorMap = {
|
||||
401: {
|
||||
title: '登录已过期,请重新登录',
|
||||
|
|
@ -151,11 +161,22 @@ function handleResponseError(res, reject, options = {}) {
|
|||
},
|
||||
}
|
||||
|
||||
const error = errorMap[res.statusCode] || {
|
||||
title: res.data?.msg || '请求失败',
|
||||
// 确保res.code存在且为数字
|
||||
const errorCode = parseInt(res.code) || res.code
|
||||
|
||||
// 优先使用errorMap中的错误信息,如果没有则使用服务器返回的msg
|
||||
const error = errorMap[errorCode] || {
|
||||
title: res.msg || res.message || '请求失败',
|
||||
action: () => {},
|
||||
}
|
||||
|
||||
console.log('最终错误信息:', {
|
||||
errorCode: errorCode,
|
||||
errorTitle: error.title,
|
||||
serverMsg: res.msg,
|
||||
serverMessage: res.message,
|
||||
})
|
||||
|
||||
// 显示错误提示
|
||||
uni.showToast({
|
||||
title: error.title,
|
||||
|
|
@ -169,8 +190,6 @@ function handleResponseError(res, reject, options = {}) {
|
|||
reject(new Error(error.title))
|
||||
}
|
||||
|
||||
// Loading相关函数已从loading-manager.js导入
|
||||
|
||||
/**
|
||||
* 统一请求方法
|
||||
* @param {Object} options - 请求配置
|
||||
|
|
@ -213,17 +232,18 @@ export function request(options = {}) {
|
|||
header: getRequestHeaders(options.header),
|
||||
timeout: options.timeout || 60000, // 默认60秒超时
|
||||
success: res => {
|
||||
console.log('成功发送请求:', res)
|
||||
// 隐藏加载状态
|
||||
if (options.showLoading !== false) {
|
||||
hideLoading()
|
||||
}
|
||||
|
||||
// 请求成功处理
|
||||
if (res.statusCode === 200) {
|
||||
if (res.data.code === 200) {
|
||||
resolve(res.data)
|
||||
} else {
|
||||
// 处理错误响应
|
||||
handleResponseError(res, reject, options)
|
||||
handleResponseError(res.data, reject, options)
|
||||
}
|
||||
},
|
||||
fail: err => {
|
||||
|
|
@ -527,7 +547,7 @@ export function uploadFile(url, filePath, name = 'file', formData = {}, options
|
|||
timeout: options.timeout || 60000,
|
||||
success: res => {
|
||||
console.log('文件上传响应:', {
|
||||
statusCode: res.statusCode,
|
||||
code: res.code,
|
||||
data: res.data,
|
||||
header: res.header,
|
||||
})
|
||||
|
|
@ -537,15 +557,14 @@ export function uploadFile(url, filePath, name = 'file', formData = {}, options
|
|||
const data = JSON.parse(res.data)
|
||||
console.log('解析后的响应数据:', data)
|
||||
|
||||
if (res.statusCode === 200 && data.code === 200) {
|
||||
if (res.code === 200 && data.code === 200) {
|
||||
console.log('文件上传成功:', data)
|
||||
resolve(data)
|
||||
} else {
|
||||
// 服务器返回错误
|
||||
const errorMsg = data.msg || data.message || '上传失败'
|
||||
console.error('文件上传失败 - 服务器错误:', {
|
||||
statusCode: res.statusCode,
|
||||
code: data.code,
|
||||
code: res.code,
|
||||
message: errorMsg,
|
||||
data: data,
|
||||
})
|
||||
|
|
@ -566,7 +585,7 @@ export function uploadFile(url, filePath, name = 'file', formData = {}, options
|
|||
console.error('文件上传失败:', err)
|
||||
|
||||
uni.showToast({
|
||||
title: errorMessage,
|
||||
title: '上传失败',
|
||||
icon: 'none',
|
||||
duration: 3000,
|
||||
})
|
||||
|
|
@ -577,7 +596,5 @@ export function uploadFile(url, filePath, name = 'file', formData = {}, options
|
|||
})
|
||||
}
|
||||
|
||||
// Loading管理相关函数已从loading-manager.js导入
|
||||
|
||||
// 默认导出request函数,方便API文件导入
|
||||
export default request
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user