Browse Source

fix: 站点切换后重载记录状态

周玉环 4 days ago
parent
commit
93b0cd6b72
2 changed files with 9 additions and 5 deletions
  1. 6 3
      xinkeaboard-admin/src/models/global.js
  2. 3 2
      xinkeaboard-seller/src/models/global.js

+ 6 - 3
xinkeaboard-admin/src/models/global.js

@@ -80,11 +80,13 @@ export default {
       const response = siteList.length ? {data: siteList, state: 200} : yield call(sldCommonService, payload, 'get', 'v3/system/seller/setting/getSiteSettingList');
       if (callback) callback(response);
       yield put({ type: 'saveSiteList', payload: response.data });
+      const cacheSiteId = localStorage.getItem('currentSite');
+      const cacheSiteName = localStorage.getItem('currentSiteName');
       const currentSite = yield select(state => state.global.currentSite);
       if (!currentSite) {
-        yield put({type: 'setCurrentSite', payload: response.data[0]?.value})
-        yield put({type: 'setCurrentSiteName', payload: response.data[0]?.title})
-        yield put({type: 'setCurrentContactType', payload: webSiteContactRelation[response.data[0]?.value]})
+        yield put({type: 'setCurrentSite', payload: cacheSiteId || response.data[0]?.value})
+        yield put({type: 'setCurrentSiteName', payload: cacheSiteName || response.data[0]?.title})
+        yield put({type: 'setCurrentContactType', payload: webSiteContactRelation[cacheSiteId || response.data[0]?.value]})
       }
     },
   },
@@ -110,6 +112,7 @@ export default {
       };
     },
     setCurrentSiteName(state, { payload }) {
+      localStorage.setItem('currentSiteName', payload)
       return {
         ...state,
         currentSiteName: payload,

+ 3 - 2
xinkeaboard-seller/src/models/global.js

@@ -80,10 +80,11 @@ export default {
       const response = siteList.length ? {data: siteList, state: 200} : yield call(sldCommonService, payload, 'get', 'v3/system/seller/setting/getSiteSettingList');
       if (callback) callback(response);
       yield put({ type: 'saveSiteList', payload: response.data });
+      const cacheSiteId = localStorage.getItem('currentSite');
       const currentSite = yield select(state => state.global.currentSite);
       if (!currentSite) {
-        yield put({type: 'setCurrentSite', payload: response.data[0]?.value})
-        yield put({type: 'setCurrentContactType', payload: webSiteContactRelation[response.data[0]?.value]})
+        yield put({type: 'setCurrentSite', payload: cacheSiteId || response.data[0]?.value})
+        yield put({type: 'setCurrentContactType', payload: webSiteContactRelation[cacheSiteId || response.data[0]?.value]})
       }
     },
   },