Compare commits

...

2 Commits

Author SHA1 Message Date
徐涛
6d97d437a2 feat(ui):增加产品伴随选择。 2024-04-07 17:33:45 +08:00
徐涛
2af30101cc enhance(server):更新产品数据。 2024-04-07 17:24:34 +08:00
3 changed files with 1294 additions and 4 deletions

File diff suppressed because one or more lines are too long

View File

@ -7,6 +7,7 @@ use tokio::{fs::File, io::AsyncReadExt};
pub struct Product { pub struct Product {
pub id: String, pub id: String,
pub name: String, pub name: String,
pub couple: Vec<String>,
} }
static PRODUCTS: OnceLock<Vec<Product>> = OnceLock::new(); static PRODUCTS: OnceLock<Vec<Product>> = OnceLock::new();

View File

@ -1,9 +1,10 @@
import { concat, pluck, uniq } from "ramda"; import { concat, find, pluck, propEq, uniq } from "ramda";
import { create } from "zustand"; import { create } from "zustand";
interface Product { interface Product {
id: string; id: string;
name: string; name: string;
couple: string[];
} }
interface ProductsStore { interface ProductsStore {
@ -18,8 +19,12 @@ interface ProductsStore {
export const useProductsStore = create<ProductsStore>((set, get) => ({ export const useProductsStore = create<ProductsStore>((set, get) => ({
products: [], products: [],
selectedProducts: [], selectedProducts: [],
append: (code: string) => append: (code: string) => {
set((state) => ({ selectedProducts: [...state.selectedProducts, code] })), const selectedProduct: Product | undefined = find(propEq(code, "id"), get().products);
set((state) => ({
selectedProducts: uniq([...state.selectedProducts, code, ...(selectedProduct.couple ?? [])]),
}));
},
remove: (code: string) => remove: (code: string) =>
set((state) => ({ selectedProducts: state.selectedProducts.filter((item) => item !== code) })), set((state) => ({ selectedProducts: state.selectedProducts.filter((item) => item !== code) })),
unselectAll: () => set({ selectedProducts: [] }), unselectAll: () => set({ selectedProducts: [] }),