fix: 调整网络错误的提示形式,出现网络超时不再踢出登录

fix: 修复当key为数字类型时,联想弹层第一次选择显示title失败的bug
This commit is contained in:
gaoyunqi
2024-03-20 15:02:42 +08:00
parent 8cb2bcc9ad
commit 756e92f00d
4 changed files with 434 additions and 416 deletions

View File

@ -121,6 +121,9 @@ export const basicComponents = [
typeName: t('计数组件'), typeName: t('计数组件'),
type: 'number', type: 'number',
options: { options: {
labelWidthMode: 'fix',
labelFixWidth: 120,
responsive: false,
width: '100%', width: '100%',
span: '', span: '',
defaultValue: 0, defaultValue: 0,
@ -1165,6 +1168,9 @@ export const infoComponents = [
typeName: t('人员选择'), typeName: t('人员选择'),
type: 'user', type: 'user',
options: { options: {
labelWidthMode: 'fix',
labelFixWidth: 120,
responsive: false,
span: '', span: '',
width: '100%', width: '100%',
defaultValue: '', defaultValue: '',

View File

@ -2,21 +2,21 @@
<div> <div>
<a-input <a-input
v-model:value="popupValue" v-model:value="popupValue"
:placeholder="placeholder"
:addonBefore="addonBefore"
:addonAfter="addonAfter" :addonAfter="addonAfter"
:disabled="disabled" :addonBefore="addonBefore"
:bordered="bordered" :bordered="bordered"
autoComplete="off" :disabled="disabled"
:placeholder="placeholder"
:size="size" :size="size"
allowClear allowClear
@click="showDialog" autoComplete="off"
@change="handleChange" @change="handleChange"
@click="showDialog"
> >
<template #prefix v-if="prefix"> <template v-if="prefix" #prefix>
<Icon :icon="prefix"/> <Icon :icon="prefix"/>
</template> </template>
<template #suffix v-if="suffix"> <template v-if="suffix" #suffix>
<Icon :icon="suffix"/> <Icon :icon="suffix"/>
</template> </template>
</a-input> </a-input>
@ -24,21 +24,21 @@
<MultipleSelect <MultipleSelect
ref="MultipleSelectRef" ref="MultipleSelectRef"
v-model:multipleDialog="multipleDialog" v-model:multipleDialog="multipleDialog"
:popupType="popupType"
:dataSourceOptions="dataSourceOptions"
:params="params"
v-model:value="defaultVal"
v-model:popupValue="popupValue" v-model:popupValue="popupValue"
:labelField="labelField" v-model:selectedDataSource="selectedDataSourceVal"
:valueField="valueField" v-model:value="defaultVal"
:apiConfig="apiConfig"
:dataSourceOptions="dataSourceOptions"
:datasourceType="datasourceType" :datasourceType="datasourceType"
:dicOptions="dicOptions" :dicOptions="dicOptions"
:apiConfig="apiConfig" :labelField="labelField"
v-model:selectedDataSource="selectedDataSourceVal"
:mainKey="mainKey" :mainKey="mainKey"
:params="params"
:popupType="popupType"
:subTableIndex="index" :subTableIndex="index"
@get-list="getList" :valueField="valueField"
@submit="handleSubmit" @submit="handleSubmit"
@get-list="getList"
/> />
</FormItemRest> </FormItemRest>
</div> </div>
@ -115,6 +115,7 @@
}; };
const getSubDatasourceList = async () => { const getSubDatasourceList = async () => {
debugger;
let showValueArr: string[] = []; let showValueArr: string[] = [];
await MultipleSelectRef.value?.getDatasourceList(); await MultipleSelectRef.value?.getDatasourceList();
@ -123,7 +124,12 @@
const selectedArr = props.value?.split(','); const selectedArr = props.value?.split(',');
dataSourceList.value?.map((item) => { dataSourceList.value?.map((item) => {
selectedArr?.map((selected) => { selectedArr?.map((selected) => {
if (item[props.valueField] === selected) { let itemVal = item[props.valueField];
if ((itemVal || itemVal === 0) && typeof selected === 'string') {
// 处理当key为数字类型时
itemVal += '';
}
if (itemVal === selected) {
selectedDataSourceVal.value?.push(item); selectedDataSourceVal.value?.push(item);
} }
}); });

View File

@ -310,11 +310,7 @@ export class VAxios {
}) })
.catch((e: Error | AxiosError) => { .catch((e: Error | AxiosError) => {
if (e.message.includes('timeout') || e.message.includes('Network Error')) { if (e.message.includes('timeout') || e.message.includes('Network Error')) {
const userStore = useUserStore(); // 太极端了,这里没必要给人踢回登录页面
userStore.setToken(undefined);
userStore.setSessionTimeout(false);
userStore.setUserInfo(null);
router.push(PageEnum.BASE_LOGIN);
} }
if (requestCatchHook && isFunction(requestCatchHook)) { if (requestCatchHook && isFunction(requestCatchHook)) {
reject(requestCatchHook(e, opt)); reject(requestCatchHook(e, opt));

View File

@ -20,11 +20,23 @@ import { useUserStoreWithOut } from '/@/store/modules/user';
import { AxiosRetry } from '/@/utils/http/axios/axiosRetry'; import { AxiosRetry } from '/@/utils/http/axios/axiosRetry';
import { useGo } from '/@/hooks/web/usePage'; import { useGo } from '/@/hooks/web/usePage';
import { validateScript } from '/@/utils/event/design'; import { validateScript } from '/@/utils/event/design';
import { notification } from 'ant-design-vue';
import { throttle } from 'lodash-es';
const globSetting = useGlobSetting(); const globSetting = useGlobSetting();
const urlPrefix = globSetting.urlPrefix; const urlPrefix = globSetting.urlPrefix;
const { createMessage, createErrorModal } = useMessage(); const { createMessage, createErrorModal } = useMessage();
const showNetworkError = function() {
notification.error({
message: '网络超时,请检查本地网络是否正常,或者稍后再试',
placement: 'topRight',
duration: 3
});
};
const trNetworkError = throttle(showNetworkError, 5000, { trailing: false });
/** /**
* @description: 数据处理,方便区分多种处理方式 * @description: 数据处理,方便区分多种处理方式
*/ */
@ -127,7 +139,7 @@ const transform: AxiosTransform = {
if (isBoolean(joinParamsToUrl) && joinParamsToUrl) { if (isBoolean(joinParamsToUrl) && joinParamsToUrl) {
config.url = setObjToUrlParams( config.url = setObjToUrlParams(
config.url as string, config.url as string,
Object.assign({}, config.params, config.data), Object.assign({}, config.params, config.data)
); );
} }
} else { } else {
@ -176,13 +188,10 @@ const transform: AxiosTransform = {
try { try {
if (code === 'ECONNABORTED' && message.indexOf('timeout') !== -1) { if (code === 'ECONNABORTED' && message.indexOf('timeout') !== -1) {
errMessage = t('接口请求超时,请刷新页面重试!'); trNetworkError();
} } else if (err?.includes('Network Error')) {
if (err?.includes('Network Error')) { trNetworkError();
errMessage = t('网络异常,请检查您的网络连接是否正常!'); } else if (errMessage) {
}
if (errMessage) {
if (errorMessageMode === 'modal') { if (errorMessageMode === 'modal') {
createErrorModal({ title: t('错误提示'), content: errMessage }); createErrorModal({ title: t('错误提示'), content: errMessage });
} else if (errorMessageMode === 'message') { } else if (errorMessageMode === 'message') {
@ -204,7 +213,7 @@ const transform: AxiosTransform = {
// @ts-ignore // @ts-ignore
retryRequest.retry(axiosInstance, error); retryRequest.retry(axiosInstance, error);
return Promise.reject(error); return Promise.reject(error);
}, }
}; };
function createAxios(opt?: Partial<CreateAxiosOptions>) { function createAxios(opt?: Partial<CreateAxiosOptions>) {
@ -251,14 +260,15 @@ function createAxios(opt?: Partial<CreateAxiosOptions>) {
retryRequest: { retryRequest: {
isOpenRetry: false, isOpenRetry: false,
count: 5, count: 5,
waitTime: 100, waitTime: 100
}
}
}, },
}, opt || {}
}, )
opt || {},
),
); );
} }
export const defHttp = createAxios(); export const defHttp = createAxios();
// other api url // other api url