Browse Source

fix: 增加首页json读取不到则调用Android的方法重启

pull/34/head
张耀 3 years ago
parent
commit
ecb6732d4f
  1. 2
      src/composables/useInitConfigAndMallInfo.ts
  2. 43
      src/http/http.ts
  3. 1
      src/types/window.d.ts

2
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()
}
}

43
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<any, T>(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)
})
})

1
src/types/window.d.ts

@ -4,6 +4,7 @@ leaveScreenSave() 离开屏保需要调用我这里的方法
*/
type Android = {
goScreenSave: () => void
restartWebView: () => void
}
declare interface Window {
android: Android

Loading…
Cancel
Save