Commit bd1772aa by 李伟康

```

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

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