feat: first commit

This commit is contained in:
eleanor.mao
2025-03-31 22:34:22 +08:00
commit d25187c9c8
390 changed files with 57031 additions and 0 deletions

44
src/store/reducers/app.ts Normal file
View File

@ -0,0 +1,44 @@
import Taro from '@tarojs/taro';
import { Action } from 'redux';
import { RoleType, PageType } from '@/constants/app';
import { CacheKey } from '@/constants/cache-key';
import { LocationInfo } from '@/types/location';
import { AppState } from '@/types/store';
import { CHANGE_ROLE_TYPE, CHANGE_HOME_PAGE, SET_LOCATION_INFO } from '../constants';
const DEFAULT_LOCATION: LocationInfo = {
provinceCode: '440000',
provinceDesc: '广东省',
cityCode: '440100',
cityDesc: '广州市',
latitude: 23.125178,
longitude: 113.280637,
};
const defaultAppMode = Taro.getStorageSync<RoleType>(CacheKey.APP_MODE_NEW) || RoleType.Anchor;
const INIT_STATE: AppState = {
roleType: defaultAppMode,
homePageType: defaultAppMode === RoleType.Anchor ? PageType.JOB : PageType.Anchor,
location: Taro.getStorageSync<LocationInfo>(CacheKey.CACHE_LOCATION_INFO) || DEFAULT_LOCATION,
};
const appState = (state: AppState = INIT_STATE, action: Action): AppState => {
const { type, value } = action as BL.Anything;
switch (type) {
case CHANGE_ROLE_TYPE:
Taro.setStorageSync(CacheKey.APP_MODE_NEW, value);
return { ...state, roleType: value };
case CHANGE_HOME_PAGE:
return { ...state, homePageType: value };
case SET_LOCATION_INFO:
Taro.setStorageSync(CacheKey.CACHE_LOCATION_INFO, value);
return { ...state, location: value };
default:
return state;
}
};
export default appState;

View File

@ -0,0 +1,11 @@
import { combineReducers } from 'redux';
import appState from './app';
import message from './message';
import userInfo from './user';
export default combineReducers({
appState,
userInfo,
message,
});

View File

@ -0,0 +1,22 @@
import { Action } from 'redux';
import { SET_USER_MESSAGE } from '@/store/constants';
import { UserMessage } from '@/types/message';
const INIT_STATE: Partial<UserMessage> = {
count: 0,
};
const message = (state: Partial<UserMessage> = INIT_STATE, action: Action): Partial<UserMessage> => {
const { type, value } = action as BL.Anything;
switch (type) {
case SET_USER_MESSAGE: {
const newValue: Partial<UserMessage> = { ...state, ...value };
return newValue;
}
default:
return state;
}
};
export default message;

View File

@ -0,0 +1,25 @@
import { Action } from 'redux';
import { UserInfo } from '@/types/user';
import { SET_USER_INFO, SET_BIND_PHONE } from '../constants';
const INIT_STATE: Partial<UserInfo> = {};
const userInfo = (state: Partial<UserInfo> = INIT_STATE, action: Action): Partial<UserInfo> => {
const { type, value } = action as BL.Anything;
switch (type) {
case SET_USER_INFO: {
const newUserInfo: Partial<UserInfo> = { ...state, ...value };
return newUserInfo;
}
case SET_BIND_PHONE: {
const newUserInfo: Partial<UserInfo> = { ...state, isBindPhone: value };
return newUserInfo;
}
default:
return state;
}
};
export default userInfo;