Commit bd1772aa by 李伟康

```

feat(api): 优化请求参数处理与取消请求功能

- 为 `request` 函数中的 `options` 参数设置默认值为空对象,提升兼容性
- 调整 POST 请求的数据结构拼接逻辑,确保配置项正确合并
- 统一通过 `headers` 传递 `returnAll` 配置,增强跨模块一致性
- 修复取消请求执行器函数名拼写问题,提高代码可读性
- 在 Vue 组件中移除无效调试日志,避免开发干扰
- 增加对 `$refs` 的安全访问判断,防止组件未挂载时报错
```
1 parent 72c551a6
...@@ -16,7 +16,7 @@ const request = ( ...@@ -16,7 +16,7 @@ const request = (
params = {}, params = {},
method = RequestMethods.GET, method = RequestMethods.GET,
noSignAttr = [], noSignAttr = [],
options options = {}
) => { ) => {
// 兼容线上dj和scrm appkey和secret不一样的情况 // 兼容线上dj和scrm appkey和secret不一样的情况
let apiName = "" let apiName = ""
...@@ -93,10 +93,11 @@ const request = ( ...@@ -93,10 +93,11 @@ const request = (
var reqData = var reqData =
method === RequestMethods.POST method === RequestMethods.POST
? { ? {
baseURL: "/", baseURL: "/",
data: sign(params, noSignAttr, secret, signWay[apiName]) data: sign(params, noSignAttr, secret, signWay[apiName])
} }
: { params: sign(params, noSignAttr, secret, signWay[apiName]) } : { params: sign(params, noSignAttr, secret, signWay[apiName]) }
reqData = Object.assign(reqData, options, {}) reqData = Object.assign(reqData, options, {})
// 请求进度 // 请求进度
if (params?.onProcess) { if (params?.onProcess) {
...@@ -104,7 +105,7 @@ const request = ( ...@@ -104,7 +105,7 @@ const request = (
} }
// 取消请求 // 取消请求
if (params?.cancelFun) { if (params?.cancelFun) {
reqData.cancelToken = new CancelToken(function excutor(c) { reqData.cancelToken = new CancelToken(function excutor (c) {
params.cancelFun.cancel = c params.cancelFun.cancel = c
}) })
} }
...@@ -115,8 +116,8 @@ const request = ( ...@@ -115,8 +116,8 @@ const request = (
return axios({ return axios({
url, url,
method, method,
...reqData, headers:{'return-all':options.returnAll},
...options ...reqData
}) })
/** /**
......
...@@ -8,13 +8,13 @@ import Qs from "qs" ...@@ -8,13 +8,13 @@ import Qs from "qs"
axios.defaults.withCredentials = true axios.defaults.withCredentials = true
// const expiresMinute = 60 // 过期时间(分钟) // const expiresMinute = 60 // 过期时间(分钟)
// 创建一个错误 // 创建一个错误
export function errorCreate(msg) { export function errorCreate (msg) {
const error = new Error(msg) const error = new Error(msg)
errorLog(error) errorLog(error)
throw error throw error
} }
// 记录和显示错误 // 记录和显示错误
function errorLog(error) { function errorLog (error) {
// 添加到日志 // 添加到日志
store.dispatch("d2admin/log/push", { store.dispatch("d2admin/log/push", {
message: "数据请求异常", message: "数据请求异常",
...@@ -47,7 +47,6 @@ const service = axios.create({ ...@@ -47,7 +47,6 @@ const service = axios.create({
} }
] ]
}) })
// 请求拦截器 // 请求拦截器
service.interceptors.request.use( service.interceptors.request.use(
(config) => { (config) => {
...@@ -121,7 +120,8 @@ service.interceptors.response.use( ...@@ -121,7 +120,8 @@ service.interceptors.response.use(
const ruleResult = baseConfig.axios.result const ruleResult = baseConfig.axios.result
const errCodeMsg = baseConfig.errCode const errCodeMsg = baseConfig.errCode
const errCodes = Object.keys(errCodeMsg) const errCodes = Object.keys(errCodeMsg)
const returnAll = response.config.returnAll const returnAll = response.config.headers['return-all']
// console.log("baseConfig", baseConfig) // console.log("baseConfig", baseConfig)
// console.log("response", response) // console.log("response", response)
// console.log("errCodes", errCodes) // console.log("errCodes", errCodes)
...@@ -138,7 +138,7 @@ service.interceptors.response.use( ...@@ -138,7 +138,7 @@ service.interceptors.response.use(
return errorCreate("登录超时,请重新登录") return errorCreate("登录超时,请重新登录")
// return Promise.reject(new Error(response.message || 'Error')) // return Promise.reject(new Error(response.message || 'Error'))
} }
if(returnAll) return dataAxios if (returnAll) return dataAxios
const codeValue = dataAxios[ruleResult.code_key] || dataAxios.returnCode const codeValue = dataAxios[ruleResult.code_key] || dataAxios.returnCode
switch (+codeValue) { switch (+codeValue) {
case ruleResult.code_success_value: case ruleResult.code_success_value:
......
...@@ -80,7 +80,6 @@ export default { ...@@ -80,7 +80,6 @@ export default {
visible: { visible: {
handler (val) { handler (val) {
if (val) { if (val) {
console.log(123)
this.phoneError = '' this.phoneError = ''
this.smsError = '' this.smsError = ''
} }
......
...@@ -95,7 +95,7 @@ export default { ...@@ -95,7 +95,7 @@ export default {
handler (val) { handler (val) {
if (val) { if (val) {
this.infoForm = this.$options.data.call(this).infoForm this.infoForm = this.$options.data.call(this).infoForm
this.$refs.editRef.resetFields() this.$refs?.editRef?.resetFields()
} }
}, },
immediate: true, immediate: true,
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!