UNPKG

@pisell/pisellos

Version:

一个可扩展的前端模块化SDK框架,支持插件系统

84 lines (82 loc) 2.84 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/modules/Summary/index.ts var Summary_exports = {}; __export(Summary_exports, { SummaryModule: () => SummaryModule }); module.exports = __toCommonJS(Summary_exports); var import_BaseModule = require("../BaseModule"); var import_utils = require("./utils"); var SummaryModule = class extends import_BaseModule.BaseModule { constructor(name, version) { super(name, version); this.defaultName = "summary"; this.defaultVersion = "1.0.0"; this.openCache = false; } async initialize(core, options) { var _a, _b; this.core = core; this.store = options.store; this.shopStore = this.core.getPlugin("shopStore"); this.request = this.core.getPlugin("request"); if (options.initialState) { this.store.summary = options.initialState.summary; } if ((_a = options.otherParams) == null ? void 0 : _a.cacheId) { this.openCache = options.otherParams.openCache; this.cacheId = options.otherParams.cacheId; } if ((_b = options.otherParams) == null ? void 0 : _b.fatherModule) { this.fatherModule = options.otherParams.fatherModule; } if (!this.shopStore) { throw new Error("SummaryModule 需要 shopStore 插件支持"); } } async getSummary(cartItems) { var _a, _b; const shopInfo = ((_b = (_a = this.shopStore.get("core")) == null ? void 0 : _a.core) == null ? void 0 : _b.shop) || {}; const summary = (0, import_utils.calculatePriceDetails)(shopInfo, cartItems); this.store.summary = summary; return this.store.summary; } /** * 获取协议 * @param protocolId 协议ID * @returns 协议 */ async getProtocol(protocolId) { return this.request.get(`/shop-policy/${protocolId}`); } storeChange() { if (this.openCache) { this.checkSaveCache({ cacheId: this.cacheId, fatherModule: this.fatherModule, store: this.store, cacheKey: ["summary"] }); } } }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { SummaryModule });