add listDataEvents.ts
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import { Events as EventsClass } from "timi-web";
|
||||
import { getCurrentStoreId } from "@/utils/store";
|
||||
|
||||
export const listDataEventKeys = {
|
||||
productChanged: "gao:list:product-changed",
|
||||
productStockChanged: "gao:list:product-stock-changed",
|
||||
salesOrderChanged: "gao:list:sales-order-changed"
|
||||
} as const;
|
||||
|
||||
export type ListDataEventKey = typeof listDataEventKeys[keyof typeof listDataEventKeys];
|
||||
|
||||
export interface ListDataChangedPayload {
|
||||
storeId?: string;
|
||||
entityId?: string;
|
||||
}
|
||||
|
||||
interface ListDataEventMap {
|
||||
[listDataEventKeys.productChanged]: [payload: ListDataChangedPayload];
|
||||
[listDataEventKeys.productStockChanged]: [payload: ListDataChangedPayload];
|
||||
[listDataEventKeys.salesOrderChanged]: [payload: ListDataChangedPayload];
|
||||
}
|
||||
|
||||
export const events = new EventsClass<ListDataEventMap>();
|
||||
|
||||
export function emitListDataChanged(key: ListDataEventKey, entityId?: string): void {
|
||||
events.emit(key, {
|
||||
storeId: getCurrentStoreId(),
|
||||
entityId
|
||||
});
|
||||
}
|
||||
|
||||
export function isCurrentStoreEvent(payload?: ListDataChangedPayload): boolean {
|
||||
return !payload?.storeId || payload.storeId === getCurrentStoreId();
|
||||
}
|
||||
@@ -14,4 +14,4 @@ export { default as Cooker } from "../../../timi-web/src/utils/Cooker";
|
||||
export { default as Storage } from "../../../timi-web/src/utils/Storage";
|
||||
export { default as WebToolkit } from "../../../timi-web/src/utils/WebToolkit";
|
||||
|
||||
export { Text, Time, Toolkit } from "../../../timi-ts/src/index";
|
||||
export { Events, Text, Time, Toolkit } from "../../../timi-ts/src/index";
|
||||
|
||||
Reference in New Issue
Block a user