|
|
@@ -17,11 +17,18 @@ import {
|
|
|
reqGetRoutes,
|
|
|
reqLogin,
|
|
|
reqLogout,
|
|
|
- reqRegister
|
|
|
+ reqRegister, reqUpdateFavoInfo
|
|
|
} from "@features/api";
|
|
|
import {toast} from 'react-toastify';
|
|
|
import {getHttpMsg, localStorageGet, localStorageSet} from "@utils/helpers";
|
|
|
-import {LOCAL_CUSTOM_LOCK, LOCAL_IS_LOGIN, LOCAL_SIGN, LOCAL_USER_INFO, LOCAL_VISTOR_ID} from "@constants/localkey";
|
|
|
+import {
|
|
|
+ LOCAL_CUSTOM_LOCK,
|
|
|
+ LOCAL_FAVO_IDS,
|
|
|
+ LOCAL_IS_LOGIN,
|
|
|
+ LOCAL_SIGN,
|
|
|
+ LOCAL_USER_INFO,
|
|
|
+ LOCAL_VISTOR_ID
|
|
|
+} from "@constants/localkey";
|
|
|
import {reqPayConfig} from "@features/paySlice";
|
|
|
import FingerprintJS from '@fingerprintjs/fingerprintjs'
|
|
|
const i18n=global.i18n;
|
|
|
@@ -130,6 +137,24 @@ const parseBlocks=(data)=>{
|
|
|
}
|
|
|
return blocks;
|
|
|
}
|
|
|
+const getFavorites=(data)=>{
|
|
|
+ let favorites=[];
|
|
|
+ if (data!=null){
|
|
|
+ let arr=data.split(",");
|
|
|
+ if (arr){
|
|
|
+ for (let i = 0; i < arr.length; i++) {
|
|
|
+ favorites.push(parseInt(arr[i]));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ localStorageSet(LOCAL_FAVO_IDS,JSON.stringify(favorites));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ let localFavorites=localStorageGet(LOCAL_FAVO_IDS,"");
|
|
|
+ if (localFavorites!=="")favorites=JSON.parse(localFavorites)
|
|
|
+ }
|
|
|
+ return favorites;
|
|
|
+}
|
|
|
const reducerRoutes=(state,action)=>{
|
|
|
let json=action.payload;
|
|
|
if (json&&json.code==0){
|
|
|
@@ -161,7 +186,9 @@ const reducerRoutes=(state,action)=>{
|
|
|
initTrackAll(type,id)
|
|
|
}
|
|
|
}
|
|
|
- Object.assign(state, {routes:state.routes,asyncRoutes:data,styles:styles,blocks:blocks,...generData,isLogin:isLogin,userInfo:userInfo,hallServerUrl:hallServerUrl});
|
|
|
+ //favorites
|
|
|
+ let favorites=getFavorites(json.favorites);
|
|
|
+ Object.assign(state, {routes:state.routes,asyncRoutes:data,styles:styles,blocks:blocks,...generData,isLogin:isLogin,userInfo:userInfo,hallServerUrl:hallServerUrl,favorites:favorites});
|
|
|
}
|
|
|
}
|
|
|
const routesStatus=(state,status,arg)=>{
|
|
|
@@ -328,6 +355,21 @@ const reducerCustomLeaveMsg=(state,action,arg)=>{
|
|
|
const customLeaveMsgStatus=(state,status,arg)=>{
|
|
|
state.customLeaveMsgStatus=status;
|
|
|
}
|
|
|
+const reducerUpdateFavoInfo=(state,action,arg)=>{
|
|
|
+ let payload=action.payload;
|
|
|
+ let msg=getHttpMsg(payload);
|
|
|
+ if (payload&&payload.code===200){
|
|
|
+ if (msg!=null&&msg!==""){
|
|
|
+ toast.success(msg)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (msg!=null&&msg!==""){
|
|
|
+ toast.error(msg)
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
//custom
|
|
|
export const Main=createSlice({
|
|
|
name: 'main',
|
|
|
@@ -399,6 +441,7 @@ export const Main=createSlice({
|
|
|
state.favorites=favorites;
|
|
|
}
|
|
|
}
|
|
|
+ localStorageSet(LOCAL_FAVO_IDS,JSON.stringify(favorites));
|
|
|
}
|
|
|
},
|
|
|
extraReducers: (builder) => {
|
|
|
@@ -415,6 +458,7 @@ export const Main=createSlice({
|
|
|
buildReqReducer(builder,reqGameInfo,reducerGameInfo,gameInfoStatus);
|
|
|
buildReqReducer(builder,reqCustomService,reducerCustom,customStatus);
|
|
|
buildReqReducer(builder,reqCustomLeaveMsg,reducerCustomLeaveMsg,customLeaveMsgStatus);
|
|
|
+ buildReqReducer(builder,reqUpdateFavoInfo,reducerUpdateFavoInfo,null);
|
|
|
},
|
|
|
})
|
|
|
export const {logout,updateUserInfo,updateUserScore,updateAddScore,updateGameLike} = Main.actions;
|