feat: 更新 ESLint 和 Prettier 配置,增强代码质量管理
- 在 .gitignore 中添加 public/audio/* 以忽略音频文件。 - 更新 bun.lock,添加 eslint-config-prettier 和 eslint-plugin-prettier 依赖,确保 ESLint 与 Prettier 的兼容性。 - 修改 eslint.config.ts,整合 Prettier 规则,优化代码风格一致性。 - 在 package.json 中添加 lint:fix 和 format 脚本,简化代码格式化和修复流程。 - 更新 tailwind.config.ts 和其他组件文件,统一代码风格,提升可读性。
This commit is contained in:
1 parent
5d00adc1a5
commit
76c67b492e
216 files changed
+12454
-13976
No files matched your search
+36
-41
@@ -1,56 +1,56 @@
|
||||
import { create } from "zustand";
|
||||
import { persist } from "zustand/middleware";
|
||||
import { STORE_NAMES } from "./storeNames";
|
||||
import { create } from 'zustand'
|
||||
import { persist } from 'zustand/middleware'
|
||||
import { STORE_NAMES } from './storeNames'
|
||||
|
||||
interface LuxunStore {
|
||||
// 存储每个场景(place)的已访问展品ID集合
|
||||
// 格式:{ place1: Set<1, 2>, place2: Set<1, 2>, ... }
|
||||
visitedExhibits: Record<string, Set<number>>;
|
||||
visitedExhibits: Record<string, Set<number>>
|
||||
|
||||
// 标记展品为已访问
|
||||
markExhibitVisited: (place: string, exhibitId: number) => void;
|
||||
markExhibitVisited: (place: string, exhibitId: number) => void
|
||||
|
||||
// 检查展品是否已访问
|
||||
isExhibitVisited: (place: string, exhibitId: number) => boolean;
|
||||
isExhibitVisited: (place: string, exhibitId: number) => boolean
|
||||
|
||||
// 获取某个场景已访问的展品ID数组
|
||||
getVisitedExhibits: (place: string) => number[];
|
||||
getVisitedExhibits: (place: string) => number[]
|
||||
|
||||
// 重置某个场景的访问记录
|
||||
resetPlace: (place: string) => void;
|
||||
resetPlace: (place: string) => void
|
||||
|
||||
// 重置所有访问记录
|
||||
resetAll: () => void;
|
||||
resetAll: () => void
|
||||
}
|
||||
|
||||
// 将 Set 转换为数组以便序列化
|
||||
const serializeVisitedExhibits = (
|
||||
visitedExhibits: Record<string, Set<number>>
|
||||
): Record<string, number[]> => {
|
||||
const serialized: Record<string, number[]> = {};
|
||||
const serialized: Record<string, number[]> = {}
|
||||
for (const [place, exhibits] of Object.entries(visitedExhibits)) {
|
||||
serialized[place] = Array.from(exhibits);
|
||||
serialized[place] = Array.from(exhibits)
|
||||
}
|
||||
return serialized;
|
||||
};
|
||||
return serialized
|
||||
}
|
||||
|
||||
// 将数组转换回 Set
|
||||
const deserializeVisitedExhibits = (
|
||||
serialized: Record<string, number[]> | undefined
|
||||
): Record<string, Set<number>> => {
|
||||
if (!serialized || typeof serialized !== "object") {
|
||||
return {};
|
||||
if (!serialized || typeof serialized !== 'object') {
|
||||
return {}
|
||||
}
|
||||
const visitedExhibits: Record<string, Set<number>> = {};
|
||||
const visitedExhibits: Record<string, Set<number>> = {}
|
||||
for (const [place, exhibits] of Object.entries(serialized)) {
|
||||
if (Array.isArray(exhibits)) {
|
||||
visitedExhibits[place] = new Set(exhibits);
|
||||
visitedExhibits[place] = new Set(exhibits)
|
||||
} else {
|
||||
visitedExhibits[place] = new Set();
|
||||
visitedExhibits[place] = new Set()
|
||||
}
|
||||
}
|
||||
return visitedExhibits;
|
||||
};
|
||||
return visitedExhibits
|
||||
}
|
||||
|
||||
export const useLuxunStore = create<LuxunStore>()(
|
||||
persist(
|
||||
@@ -59,39 +59,38 @@ export const useLuxunStore = create<LuxunStore>()(
|
||||
|
||||
markExhibitVisited: (place: string, exhibitId: number) => {
|
||||
set((state) => {
|
||||
const currentExhibits =
|
||||
state.visitedExhibits[place] || new Set<number>();
|
||||
const currentExhibits = state.visitedExhibits[place] || new Set<number>()
|
||||
if (!currentExhibits.has(exhibitId)) {
|
||||
const newExhibits = {
|
||||
...state.visitedExhibits,
|
||||
[place]: new Set([...currentExhibits, exhibitId]),
|
||||
};
|
||||
return { visitedExhibits: newExhibits };
|
||||
}
|
||||
return { visitedExhibits: newExhibits }
|
||||
}
|
||||
return state;
|
||||
});
|
||||
return state
|
||||
})
|
||||
},
|
||||
|
||||
isExhibitVisited: (place: string, exhibitId: number) => {
|
||||
const { visitedExhibits } = get();
|
||||
return visitedExhibits[place]?.has(exhibitId) || false;
|
||||
const { visitedExhibits } = get()
|
||||
return visitedExhibits[place]?.has(exhibitId) || false
|
||||
},
|
||||
|
||||
getVisitedExhibits: (place: string) => {
|
||||
const { visitedExhibits } = get();
|
||||
return Array.from(visitedExhibits[place] || []);
|
||||
const { visitedExhibits } = get()
|
||||
return Array.from(visitedExhibits[place] || [])
|
||||
},
|
||||
|
||||
resetPlace: (place: string) => {
|
||||
set((state) => {
|
||||
const newExhibits = { ...state.visitedExhibits };
|
||||
delete newExhibits[place];
|
||||
return { visitedExhibits: newExhibits };
|
||||
});
|
||||
const newExhibits = { ...state.visitedExhibits }
|
||||
delete newExhibits[place]
|
||||
return { visitedExhibits: newExhibits }
|
||||
})
|
||||
},
|
||||
|
||||
resetAll: () => {
|
||||
set({ visitedExhibits: {} });
|
||||
set({ visitedExhibits: {} })
|
||||
},
|
||||
}),
|
||||
{
|
||||
@@ -101,13 +100,9 @@ export const useLuxunStore = create<LuxunStore>()(
|
||||
}),
|
||||
onRehydrateStorage: () => (state) => {
|
||||
if (state) {
|
||||
state.visitedExhibits = deserializeVisitedExhibits(
|
||||
state.visitedExhibits as any
|
||||
);
|
||||
state.visitedExhibits = deserializeVisitedExhibits(state.visitedExhibits as any)
|
||||
}
|
||||
},
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
)
|
||||
Reference in new issue
Block a user