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