chore: 更新素材和组件优化
- 更新展品图片(鲁迅/毛泽东/孙中山/黄炎培/聂耳/张乐平故居) - 新增点击查看图标、报纸素材 - 优化视频组件、拼图组件、展品组件 - 更新陈云音频资源 - 新增输入验证文档和工具函数 - 组件布局和动画优化 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
73d02eb62d
commit
73f6df92ce
130 files changed
+2345
-759
No files matched your search
+65
-2
@@ -1,7 +1,11 @@
|
||||
import { create } from 'zustand'
|
||||
import { persist } from 'zustand/middleware'
|
||||
import { STORE_NAMES } from './storeNames'
|
||||
import { setUserDefine } from '@/lib/utils/api-common'
|
||||
import {
|
||||
setUserDefine,
|
||||
getUserDefineResult,
|
||||
type UserDefineFetchStatus,
|
||||
} from '@/lib/utils/api-common'
|
||||
|
||||
interface LuxunStore {
|
||||
// 存储每个场景(place)的已访问展品ID集合
|
||||
@@ -30,6 +34,9 @@ interface LuxunStore {
|
||||
|
||||
// 重置所有访问记录
|
||||
resetAll: () => void
|
||||
|
||||
completedVideos: Record<string, boolean>
|
||||
markVideoCompleted: (videoKey: string) => void
|
||||
}
|
||||
|
||||
// 将 Set 转换为数组以便序列化
|
||||
@@ -61,12 +68,31 @@ const deserializeVisitedExhibits = (
|
||||
return visitedExhibits
|
||||
}
|
||||
|
||||
const resolveReflectionRoute = (route: unknown): string =>
|
||||
typeof route === 'string' && ['reflection', 'reflection2', 'reflection3'].includes(route)
|
||||
? route
|
||||
: 'reflection'
|
||||
|
||||
interface LuxunPersistedState {
|
||||
visitedExhibits?: Record<string, number[]>
|
||||
lastVisitedPlace?: string | null
|
||||
reflectionRoute?: string
|
||||
completedVideos?: Record<string, boolean>
|
||||
}
|
||||
|
||||
export const useLuxunStore = create<LuxunStore>()(
|
||||
persist(
|
||||
(set, get) => ({
|
||||
visitedExhibits: {},
|
||||
reflectionRoute: 'reflection',
|
||||
lastVisitedPlace: null,
|
||||
completedVideos: {},
|
||||
|
||||
markVideoCompleted: (videoKey: string) => {
|
||||
set((state) => ({
|
||||
completedVideos: { ...state.completedVideos, [videoKey]: true },
|
||||
}))
|
||||
},
|
||||
|
||||
markExhibitVisited: (place: string, exhibitId: number) => {
|
||||
set((state) => {
|
||||
@@ -101,7 +127,12 @@ export const useLuxunStore = create<LuxunStore>()(
|
||||
},
|
||||
|
||||
resetAll: () => {
|
||||
set({ visitedExhibits: {} })
|
||||
set({
|
||||
visitedExhibits: {},
|
||||
lastVisitedPlace: null,
|
||||
reflectionRoute: 'reflection',
|
||||
completedVideos: {},
|
||||
})
|
||||
},
|
||||
|
||||
setLastVisitedPlace: (place: string) => set({ lastVisitedPlace: place }),
|
||||
@@ -113,6 +144,7 @@ export const useLuxunStore = create<LuxunStore>()(
|
||||
visitedExhibits: serializeVisitedExhibits(state.visitedExhibits),
|
||||
lastVisitedPlace: state.lastVisitedPlace,
|
||||
reflectionRoute: state.reflectionRoute,
|
||||
completedVideos: state.completedVideos,
|
||||
}),
|
||||
onRehydrateStorage: () => (state) => {
|
||||
if (state) {
|
||||
@@ -123,6 +155,9 @@ export const useLuxunStore = create<LuxunStore>()(
|
||||
if ((state as any).reflectionRoute === undefined) {
|
||||
;(state as any).reflectionRoute = 'reflection'
|
||||
}
|
||||
if (!state.completedVideos || typeof state.completedVideos !== 'object') {
|
||||
state.completedVideos = {}
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
@@ -140,6 +175,7 @@ export const saveLuxunStore = (): void => {
|
||||
visitedExhibits: serializeVisitedExhibits(state.visitedExhibits),
|
||||
lastVisitedPlace: state.lastVisitedPlace,
|
||||
reflectionRoute: state.reflectionRoute,
|
||||
completedVideos: state.completedVideos,
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -148,3 +184,30 @@ export const saveLuxunStore = (): void => {
|
||||
console.error('Failed to save Luxun store', error)
|
||||
}
|
||||
}
|
||||
|
||||
export const applyLuxunPersistedState = (payload: LuxunPersistedState): void => {
|
||||
useLuxunStore.setState({
|
||||
visitedExhibits: deserializeVisitedExhibits(payload.visitedExhibits),
|
||||
lastVisitedPlace: payload.lastVisitedPlace ?? null,
|
||||
reflectionRoute: resolveReflectionRoute(payload.reflectionRoute),
|
||||
completedVideos: payload.completedVideos ?? {},
|
||||
})
|
||||
}
|
||||
|
||||
export const loadLuxunStore = async (): Promise<UserDefineFetchStatus> => {
|
||||
try {
|
||||
const result = await getUserDefineResult(LUXUN_LESSON_ID, LUXUN_KEY)
|
||||
if (result.status !== 'success') {
|
||||
if (result.status === 'empty') {
|
||||
useLuxunStore.getState().resetAll()
|
||||
}
|
||||
return result.status
|
||||
}
|
||||
|
||||
applyLuxunPersistedState(JSON.parse(result.content) as LuxunPersistedState)
|
||||
return result.status
|
||||
} catch (error) {
|
||||
console.error('Failed to load Luxun store', error)
|
||||
return 'error'
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user