20260703173210

This commit is contained in:
oneao committed 2026-07-03 17:32:11 +08:00
1 parent d0f7f0d3d8
commit 3556d5e8c1
15 files changed
+853 -143

No files matched your search

+41 -48
View File
@@ -8,7 +8,6 @@ import {
ClothingSaveChanges,
ClothingStatus,
ClothingTag,
ClothingTagGroup,
ClothingTagRelation,
ClothingTargetType,
} from "@/types/clothing";
@@ -18,19 +17,25 @@ const TABLES = {
outfit: "b_clothing_outfit",
outfitClothes: "b_clothing_outfit_clothes",
category: "b_clothing_category",
tagGroup: "b_clothing_tag_group",
tag: "b_clothing_tag",
tagRelation: "b_clothing_tag_relation",
familyMember: "b_family_member",
} as const;
export interface ClothingFamilyMember {
user_id: number;
nickname: string;
avatar?: string;
}
interface ClothingState {
clothes: ClothingClothes[];
outfits: ClothingOutfit[];
outfitClothes: ClothingOutfitClothes[];
categories: ClothingCategory[];
tagGroups: ClothingTagGroup[];
tags: ClothingTag[];
tagRelations: ClothingTagRelation[];
members: ClothingFamilyMember[];
clear: () => void;
@@ -39,13 +44,14 @@ interface ClothingState {
fetchOutfits: (familyId: number) => Promise<void>;
fetchOutfitClothes: (familyId: number, outfitId?: number) => Promise<void>;
fetchCategories: (familyId: number, type?: ClothingTargetType) => Promise<void>;
fetchTagGroups: (familyId: number, type?: ClothingTargetType) => Promise<void>;
fetchTags: (familyId: number, type?: ClothingTargetType, tagGroupId?: number) => Promise<void>;
fetchTags: (familyId: number, type?: ClothingTargetType, parentId?: number) => Promise<void>;
fetchTagRelations: (
familyId: number,
targetType?: ClothingTargetType,
targetId?: number,
) => Promise<void>;
fetchMembers: (familyId: number) => Promise<void>;
getOwnerName: (ownerId?: number | null) => string;
saveClothesChanges: (changes: ClothingSaveChanges<ClothingClothes>) => Promise<boolean>;
saveOutfitChanges: (changes: ClothingSaveChanges<ClothingOutfit>) => Promise<boolean>;
@@ -53,16 +59,12 @@ interface ClothingState {
changes: ClothingSaveChanges<ClothingOutfitClothes>,
) => Promise<boolean>;
saveCategoryChanges: (changes: ClothingSaveChanges<ClothingCategory>) => Promise<boolean>;
saveTagGroupChanges: (changes: ClothingSaveChanges<ClothingTagGroup>) => Promise<boolean>;
saveTagChanges: (changes: ClothingSaveChanges<ClothingTag>) => Promise<boolean>;
saveTagRelationChanges: (changes: ClothingSaveChanges<ClothingTagRelation>) => Promise<boolean>;
saveMetadataBundle: (payload: {
categoryInserts?: Partial<ClothingCategory>[];
categoryUpdates?: Partial<ClothingCategory>[];
categoryDeletes?: Partial<ClothingCategory>[];
tagGroupInserts?: Partial<ClothingTagGroup>[];
tagGroupUpdates?: Partial<ClothingTagGroup>[];
tagGroupDeletes?: Partial<ClothingTagGroup>[];
tagInserts?: Partial<ClothingTag>[];
tagUpdates?: Partial<ClothingTag>[];
tagDeletes?: Partial<ClothingTag>[];
@@ -121,9 +123,9 @@ export const useClothingStore = create<ClothingState>((set, get) => ({
outfits: [],
outfitClothes: [],
categories: [],
tagGroups: [],
tags: [],
tagRelations: [],
members: [],
clear: () =>
set({
@@ -131,9 +133,9 @@ export const useClothingStore = create<ClothingState>((set, get) => ({
outfits: [],
outfitClothes: [],
categories: [],
tagGroups: [],
tags: [],
tagRelations: [],
members: [],
}),
fetchAll: async (familyId: number) => {
@@ -141,9 +143,9 @@ export const useClothingStore = create<ClothingState>((set, get) => ({
get().fetchClothes(familyId),
get().fetchOutfits(familyId),
get().fetchCategories(familyId),
get().fetchTagGroups(familyId),
get().fetchTags(familyId),
get().fetchTagRelations(familyId),
get().fetchMembers(familyId),
]);
},
@@ -213,24 +215,7 @@ export const useClothingStore = create<ClothingState>((set, get) => ({
}
},
fetchTagGroups: async (familyId: number, type?: ClothingTargetType) => {
if (!familyId) return;
const { condition, args } = typeCondition(type);
const res = await loadDataApi({
view_name: TABLES.tagGroup,
search_condition: condition,
search_columns: [],
order_by: "type asc, sort_number asc, id asc",
args: [familyId, ClothingStatus.Enabled, ...args],
});
if (res.isSuccess) {
set({ tagGroups: res.data as ClothingTagGroup[] });
}
},
fetchTags: async (familyId: number, type?: ClothingTargetType, tagGroupId?: number) => {
fetchTags: async (familyId: number, type?: ClothingTargetType, parentId?: number) => {
if (!familyId) return;
const conditions = ["family_id = ?", "status = ?"];
@@ -241,16 +226,16 @@ export const useClothingStore = create<ClothingState>((set, get) => ({
args.push(type);
}
if (tagGroupId !== undefined) {
conditions.push("tag_group_id = ?");
args.push(tagGroupId);
if (parentId !== undefined) {
conditions.push("parent_id = ?");
args.push(parentId);
}
const res = await loadDataApi({
view_name: TABLES.tag,
search_condition: conditions.join(" and "),
search_columns: [],
order_by: "type asc, tag_group_id asc, sort_number asc, id asc",
order_by: "type asc, parent_id asc, sort_number asc, id asc",
args,
});
@@ -292,6 +277,28 @@ export const useClothingStore = create<ClothingState>((set, get) => ({
}
},
fetchMembers: async (familyId: number) => {
if (!familyId) return;
const res = await loadDataApi({
view_name: TABLES.familyMember,
search_condition: "family_id = ?",
search_columns: ["user_id", "nickname"],
order_by: "id asc",
args: [familyId],
});
if (res.isSuccess) {
set({ members: (res.data as ClothingFamilyMember[]) ?? [] });
}
},
getOwnerName: (ownerId?: number | null) => {
if (!ownerId) return "";
const m = get().members.find((row) => row.user_id === ownerId);
return m?.nickname || `用户${ownerId}`;
},
saveClothesChanges: async (changes: ClothingSaveChanges<ClothingClothes>) => {
const res = await saveDataApi([
{ table_name: TABLES.clothes, key_field: "id", ...normalizeChanges(changes) },
@@ -320,13 +327,6 @@ export const useClothingStore = create<ClothingState>((set, get) => ({
return res.isSuccess;
},
saveTagGroupChanges: async (changes: ClothingSaveChanges<ClothingTagGroup>) => {
const res = await saveDataApi([
{ table_name: TABLES.tagGroup, key_field: "id", ...normalizeChanges(changes) },
]);
return res.isSuccess;
},
saveTagChanges: async (changes: ClothingSaveChanges<ClothingTag>) => {
const res = await saveDataApi([
{ table_name: TABLES.tag, key_field: "id", ...normalizeChanges(changes) },
@@ -350,13 +350,6 @@ export const useClothingStore = create<ClothingState>((set, get) => ({
updates: payload.categoryUpdates ?? [],
deletes: payload.categoryDeletes ?? [],
},
{
table_name: TABLES.tagGroup,
key_field: "id",
inserts: payload.tagGroupInserts ?? [],
updates: payload.tagGroupUpdates ?? [],
deletes: payload.tagGroupDeletes ?? [],
},
{
table_name: TABLES.tag,
key_field: "id",