|
|
|
@ -39,12 +39,21 @@ const transform: AxiosTransform = {
@@ -39,12 +39,21 @@ const transform: AxiosTransform = {
|
|
|
|
|
return res; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 检查是否有code,并且等于200,直接返回结果
|
|
|
|
|
const { data } = res; |
|
|
|
|
const hasSuccess = data && Reflect.has(data, 'code') && data.code === ResultEnum.SUCCESS; |
|
|
|
|
if (hasSuccess) { |
|
|
|
|
// 检查是否有code,并且code等于200,直接返回结果
|
|
|
|
|
const { data } = res; |
|
|
|
|
const hasCode = data && Reflect.has(data, 'code'); |
|
|
|
|
if (hasCode && data.code === ResultEnum.SUCCESS) { |
|
|
|
|
return data.data; |
|
|
|
|
// 检查是否有code,如果code不等于200,说明返回的结果集有错误,直接抛错
|
|
|
|
|
} else if (hasCode && data.code !== ResultEnum.SUCCESS) { |
|
|
|
|
if (options.errorMessageMode === 'modal') { |
|
|
|
|
createErrorModal({ title: t('sys.api.errorTip'), content: data?.msg }); |
|
|
|
|
} else if (options.errorMessageMode === 'message') { |
|
|
|
|
createMessage.error(data?.msg); |
|
|
|
|
} |
|
|
|
|
throw new Error(data?.msg || t('sys.api.errMsgDefault')); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return data; |
|
|
|
|
|
|
|
|
|
}, |
|
|
|
|