From ecb6732d4f70fec6960a174f67fb49c565ff69e8 Mon Sep 17 00:00:00 2001 From: zhangyao Date: Thu, 27 Jul 2023 17:20:50 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=A2=9E=E5=8A=A0=E9=A6=96=E9=A1=B5json?= =?UTF-8?q?=E8=AF=BB=E5=8F=96=E4=B8=8D=E5=88=B0=E5=88=99=E8=B0=83=E7=94=A8?= =?UTF-8?q?Android=E7=9A=84=E6=96=B9=E6=B3=95=E9=87=8D=E5=90=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/composables/useInitConfigAndMallInfo.ts | 2 + src/http/http.ts | 43 ++++++++++++++++++++- src/types/window.d.ts | 1 + 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/composables/useInitConfigAndMallInfo.ts b/src/composables/useInitConfigAndMallInfo.ts index 8233ca6..6e30517 100644 --- a/src/composables/useInitConfigAndMallInfo.ts +++ b/src/composables/useInitConfigAndMallInfo.ts @@ -53,7 +53,9 @@ export const useInitConfigAndMallInfo = async () => { store.SET_MENU_LIST(_menuList.data) store.SET_PICTURE_LIST(_pictureList.data) } catch (error) { + console.log('开机读取JSON报错 :>> ', JSON.stringify(error)) Message({ text: '初始化数据失败', type: 'success' }) + window.android.restartWebView() } } diff --git a/src/http/http.ts b/src/http/http.ts index d3cd159..afece98 100644 --- a/src/http/http.ts +++ b/src/http/http.ts @@ -54,19 +54,58 @@ class Request { if (config.interceptors?.requestInterceptors) { config = config.interceptors.requestInterceptors(config as any) } + const checkJsonList = [ + 'getDevCoordinateByIP', + 'getMapInfo', + 'getFacilityList', + 'GetWeather', + 'getBrandShopListByFloor', + 'getBrandShopListByIndustryId', + 'getBrandShopList', + 'getModuleList', + 'getArtList' + ] this.instance .request(config) .then(res => { - console.log('axios获取数据 :>> ', JSON.stringify(res)) + if ( + config.url && + config.url?.search('getMap.json') <= 0 && + config.url?.search('getMapInfo.json') <= 0 && + config.url?.search('getBrandShopListByFloor.json') <= 0 && + config.url?.search('getBrandShopListByIndustryId.json') <= 0 + ) { + console.log('axios获取数据 :>> ', JSON.stringify(res)) + } // 如果为单个响应设置拦截器,使用单个响应的拦截器 if (config.interceptors?.responseInterceptors) { res = config.interceptors.responseInterceptors(res) } - + if (config.url && Object(res).code !== 200) { + for (let t = 0; t < checkJsonList.length; t++) { + const element = checkJsonList[t] + if (config.url.search(element) > 0) { + console.log('开机读取JSON报错 :>> ') + window?.android?.restartWebView() + break + } + } + } resolve(res) }) .catch((err: any) => { console.log('axios获取数据失败 :==>> ', JSON.stringify(err)) + + if (config.url) { + for (let t = 0; t < checkJsonList.length; t++) { + const element = checkJsonList[t] + if (config.url.search(element) > 0) { + console.log('catch开机读取JSON报错 :>> ') + window.android.restartWebView() + break + } + } + } reject(err) }) }) diff --git a/src/types/window.d.ts b/src/types/window.d.ts index c65a27a..6389077 100644 --- a/src/types/window.d.ts +++ b/src/types/window.d.ts @@ -4,6 +4,7 @@ leaveScreenSave() 离开屏保需要调用我这里的方法 */ type Android = { goScreenSave: () => void + restartWebView: () => void } declare interface Window { android: Android