hookehuyr

refactor(utils): 提取请求默认参数到config文件

将分散在多个文件中的请求默认参数提取到config.js中统一管理
修改BASE_URL为测试服务器地址
修复授权页面跳转逻辑
import Taro from '@tarojs/taro'
import { routerStore } from '@/stores/router'
import BASE_URL from './config'
import BASE_URL, { REQUEST_DEFAULT_PARAMS } from './config'
/**
* 授权与回跳相关工具
......@@ -112,7 +112,7 @@ export const refreshSession = async (options) => {
// 换取后端会话(服务端通过 Set-Cookie 返回会话信息)
const response = await Taro.request({
url: `${BASE_URL}/srv/?a=openid&f=reserve&client_name=${encodeURIComponent('智慧西园寺')}`,
url: `${BASE_URL}/srv/?a=openid&f=${encodeURIComponent(REQUEST_DEFAULT_PARAMS.f)}&client_name=${encodeURIComponent(REQUEST_DEFAULT_PARAMS.client_name)}`,
method: 'POST',
data: request_data,
})
......@@ -211,7 +211,7 @@ export const navigateToAuth = (return_path) => {
return
}
// navigateTo 失败时(例如页面栈满),降级为 redirectTo
// TAG: navigateTo 失败时(例如页面栈满),降级为 redirectTo
Taro.navigateTo({ url: '/pages/auth/index' }).catch(() => {
return Taro.redirectTo({ url: '/pages/auth/index' })
})
......@@ -294,12 +294,12 @@ export const handleSharePageAuth = async (options, callback) => {
if (typeof callback === 'function') callback()
},
() => {
// Taro.navigateTo({ url: '/pages/auth/index' })
Taro.navigateTo({ url: '/pages/auth/index' })
}
)
return true
} catch (error) {
// Taro.navigateTo({ url: '/pages/auth/index' })
Taro.navigateTo({ url: '/pages/auth/index' })
return false
}
}
......
/*
* @Date: 2022-09-19 14:11:06
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2024-01-15 17:07:14
* @FilePath: /meihuaApp/src/utils/config.js
* @LastEditTime: 2026-01-08 16:42:38
* @FilePath: /xyxBooking-weapp/src/utils/config.js
* @Description: 文件描述
*/
// TAG:服务器环境配置
// const BASE_URL = "https://oa-dev.onwall.cn"; // 测试服务器
const BASE_URL = "https://oa.onwall.cn"; // 正式服务器
const BASE_URL = "https://oa-dev.onwall.cn"; // 测试服务器
// const BASE_URL = "https://oa.onwall.cn"; // 正式服务器
/**
* 接口默认公共参数(避免在多个文件里硬编码)
* - f:业务模块标识
* - client_name:客户端标识(后端用于识别来源)
*/
export const REQUEST_DEFAULT_PARAMS = {
f: 'reserve',
client_name: '智慧西园寺',
}
export default BASE_URL
......
......@@ -15,7 +15,7 @@ import { refreshSession, saveCurrentPagePath, navigateToAuth } from './authRedir
// import { ProgressStart, ProgressEnd } from '@/components/axios-progress/progress';
// import store from '@/store'
// import { getToken } from '@/utils/auth'
import BASE_URL from './config';
import BASE_URL, { REQUEST_DEFAULT_PARAMS } from './config';
/**
* 获取sessionid的工具函数
......@@ -43,8 +43,7 @@ const service = axios.create({
})
service.defaults.params = {
f: 'reserve',
client_name: '智慧西园寺',
...REQUEST_DEFAULT_PARAMS,
};
// request interceptor
......