@pisell/pisellos
Version:
一个可扩展的前端模块化SDK框架,支持插件系统
237 lines (236 loc) • 6.24 kB
TypeScript
import { ProductData } from '../Product/types';
import { Account } from '../Account/types';
import { Resource } from '../Resource/types';
export declare enum CartHooks {
OnAddItem = "card:onAddItem",
OnCartChange = "card:onCartChange",
OnCartUpdateItem = "card:onCartUpdateItem",
OnCartRemove = "card:onCartRemove"
}
/**
* 购物车商品信息类型
*/
export declare enum ECartItemInfoType {
/** 资源信息 */
Resource = "resource",
/** 时间信息 */
Time = "time",
/** 关联表单信息 */
RelationForms = "relationForms",
/** 账户信息 */
Holder = "holder"
}
/**
* 购物车商品检查类型
*/
export declare enum ECartItemCheckType {
/** 账户信息 */
Account = "account",
/** 资源信息 */
Resources = "resources",
/** 时间信息 */
Date = "date",
/** 关联表单信息 */
RelationForms = "relationForms"
}
export interface CartModuleAPI {
/** 添加商品到购物车 */
addItem: (item: IAddItemParams) => Promise<void>;
/** 获取购物车商品 */
getItems: () => CartItem[];
/** 更新购物车商品 */
updateItem: (params: IUpdateItemParams) => Promise<void>;
/** 格式化购物车商品 */
formatCartItem: (params: IUpdateItemParams) => CartItem;
/** 批量设置购物车商品 */
batchSetItems: (items: CartItem[]) => Promise<void>;
/** 移除购物车商品 */
removeItem: (id: string) => Promise<void>;
/** 根据账户ID清除购物车 */
clearCartByAccount: (account_id: string) => void;
/** 根据账户ID获取购物车 */
getCartByAccount: (account_id: string) => CartItem[];
/** 清除购物车 */
clear: () => void;
/** 清除购物车商品中的信息 */
deleteCartItemInfo: (type: ECartItemInfoType, _id?: string) => void;
/** 检查购物车商品 */
checkCartItemByType: (cartItem: CartItem, type: ECartItemCheckType) => boolean;
}
/**
* 购物车商品接口
*/
export interface CartItem {
/** 购物车ID */
_id: string;
/** 商品ID */
id?: number;
/** 商品名称 */
name?: string;
/** 商品价格 */
price?: number | string;
/** 单个商品包括商品本身价格+套餐价格+规格等价格得出来的 */
total?: number | string;
/** 基于 total 乘以 商品数量的价格 */
summaryTotal?: number | string;
/** 商品原价总价,排除原始价格为0的场景 */
origin_total?: number | string;
/** 基于 origin_total 乘以 商品数量的价格 */
summaryOriginTotal?: number | string;
/** 商品数量 */
num?: number;
/** 商品图片 */
image?: string;
/** 商品时长 */
duration?: {
type: string;
value: number;
};
/** 是否显示备注 */
isShowNote?: boolean;
/** 备注 */
note?: string;
/** 点赞状态 */
like_status?: 'like' | 'common';
/** 用户名称 */
holder_title?: string;
/** 用户ID */
holder_id?: number | string;
/** 符号 */
symbol?: string;
/** 开始日期 */
start_date?: string;
/** 开始时间 */
start_time?: string;
/** 结束日期 */
end_date?: string;
/** 结束时间 */
end_time?: string;
/** 是否收取税费 */
is_charge_tax?: number;
/** 商品套餐信息 */
bundle?: any[];
/** 商品规格信息 */
options?: any[];
/** 商品规格选项字符串 */
product_option_string?: string;
/** 是否为普通商品 */
isNormalProduct?: boolean;
/** 资源ID */
resource_id?: string | number;
/** 资源名称 */
relation_form_name?: string;
/** 定金 */
deposit?: {
/** 定金总价 */
total: number | string;
/** 定金协议 */
protocols: {
/** 定金协议ID */
id: number;
/** 定金协议标题 */
title: string;
}[];
} | null;
/** 接口原始数据 */
_origin: any;
/** 商品加入购物车时初始数据 */
_productInit?: ProductData;
/** 商品原始数据 */
_productOrigin?: ProductData;
/** 资源原始数据 */
_resourceOrigin?: Resource[];
/** 容量 */
capacity?: any;
/** 商品套餐原始数据 */
_bundleOrigin?: any[];
/** 商品规格原始数据 */
_optionsOrigin?: any[];
/** 操作系统提示 */
osWarnTips?: string[];
}
/**
* 购物车状态接口
*/
export interface CartState {
list: CartItem[];
}
/**
* 添加商品到购物车参数
*/
export interface IAddItemParams {
/** 账户 */
account: Account;
/** 商品 */
product: ProductData;
/** 数量 */
quantity?: number;
/** 商品套餐信息 */
bundle?: any[];
/** 商品规格信息 */
options?: any[];
/** 日期 */
date?: {
/** 开始时间 */
startTime: string;
/** 结束时间 */
endTime: string;
};
/** 商品组合规格ID */
product_variant_id?: number;
}
/**
* 更新购物车信息参数
*/
export interface IUpdateItemParams {
/** 购物车_id字段 */
_id: string;
/** 购物车商品 */
cartItem?: CartItem;
/** 账户 */
account?: Account;
/** 商品 */
product?: ProductData;
/** 商品套餐信息 */
bundle?: any[];
/** 商品规格信息 */
options?: any[];
/** 折扣列表 */
discounts?: IDiscount[];
/** 数量 */
quantity?: number;
/** 资源 */
resources?: Resource[];
/** 元数据 */
metadata?: any;
/** 备注 */
note?: string;
/** 日期 */
date?: {
/** 开始时间 */
startTime: string;
/** 结束时间 */
endTime: string;
};
/** 关联表单 */
relationForms?: {
/** 关联表单ID */
form_id: number;
/** 关联表单记录ID */
form_record_ids: number[];
}[];
/** 商品组合规格ID */
product_variant_id?: number;
/** 操作系统提示 */
osWarnTips?: string[];
}
/**
* 折扣
*/
export interface IDiscount {
amount?: number;
type?: string;
resource_id?: string;
title?: any;
original_amount?: number;
}