@pisell/pisellos 0.0.337 → 0.0.339

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -50,8 +50,9 @@ export interface RulesParamsHooks {
50
50
  origin_total?: number;
51
51
  price?: string | number;
52
52
  variant?: any[];
53
- original_price?: number;
53
+ original_price?: number | string;
54
54
  quantity?: number;
55
+ bundle?: any[];
55
56
  }) => Record<string, any>;
56
57
  }
57
58
  export {};
@@ -122,12 +122,6 @@ var BookingTicketImpl = class extends import_BaseModule.BaseModule {
122
122
  throw error;
123
123
  }
124
124
  }
125
- /**
126
- * 初始化外设扫码结果监听
127
- */
128
- initPeripheralsListener() {
129
- this.scan.initPeripheralsListener();
130
- }
131
125
  /**
132
126
  * 获取商品列表(不加载到模块中)
133
127
  * @returns 商品列表
@@ -17,6 +17,7 @@ export declare class RegisterAndLoginImpl extends BaseModule implements Module {
17
17
  private apiCaller;
18
18
  private otherParams;
19
19
  private channel;
20
+ private countriesCache;
20
21
  constructor(name?: string, version?: string);
21
22
  /**
22
23
  * 重新发送邮箱注册链接
@@ -179,5 +180,9 @@ export declare class RegisterAndLoginImpl extends BaseModule implements Module {
179
180
  * 获取国家区号列表
180
181
  */
181
182
  getCountries(): Promise<CountryInfo[]>;
183
+ /**
184
+ * 异步更新国家缓存数据
185
+ */
186
+ private updateCountriesCache;
182
187
  destroy(): Promise<void>;
183
188
  }
@@ -37,6 +37,8 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
37
37
  this.isSolution = true;
38
38
  this.otherParams = {};
39
39
  this.channel = "default";
40
+ // 内存缓存
41
+ this.countriesCache = null;
40
42
  }
41
43
  /**
42
44
  * 重新发送邮箱注册链接
@@ -607,11 +609,6 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
607
609
  if (token) {
608
610
  this.store.currentUser = user;
609
611
  this.store.isLoggedIn = true;
610
- this.window.localStorage.setItem("auth_token", token);
611
- this.window.localStorage.setItem("user_info", JSON.stringify(user));
612
- if (refreshToken) {
613
- this.window.localStorage.setItem("refresh_token", refreshToken);
614
- }
615
612
  }
616
613
  await this.core.effects.emit(
617
614
  import_types.RegisterAndLoginHooks.onRegisterSuccess,
@@ -655,11 +652,6 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
655
652
  const { user, token, refreshToken } = response.data;
656
653
  this.store.currentUser = user;
657
654
  this.store.isLoggedIn = true;
658
- this.window.localStorage.setItem("auth_token", token);
659
- this.window.localStorage.setItem("user_info", JSON.stringify(user));
660
- if (refreshToken) {
661
- this.window.localStorage.setItem("refresh_token", refreshToken);
662
- }
663
655
  await this.core.effects.emit(
664
656
  import_types.RegisterAndLoginHooks.onLoginSuccess,
665
657
  response.data
@@ -699,11 +691,6 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
699
691
  const { user, token, refreshToken } = response.data;
700
692
  this.store.currentUser = user;
701
693
  this.store.isLoggedIn = true;
702
- this.window.localStorage.setItem("auth_token", token);
703
- this.window.localStorage.setItem("user_info", JSON.stringify(user));
704
- if (refreshToken) {
705
- this.window.localStorage.setItem("refresh_token", refreshToken);
706
- }
707
694
  await this.core.effects.emit(
708
695
  import_types.RegisterAndLoginHooks.onOAuthLoginSuccess,
709
696
  response.data
@@ -1457,12 +1444,39 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
1457
1444
  * 获取国家区号列表
1458
1445
  */
1459
1446
  async getCountries() {
1447
+ const CACHE_KEY = "pisell_countries_cache";
1460
1448
  try {
1461
1449
  this.store.isLoading = true;
1462
1450
  this.store.error = null;
1451
+ if (this.countriesCache) {
1452
+ this.store.isLoading = false;
1453
+ return this.countriesCache;
1454
+ }
1455
+ let cachedData = null;
1456
+ try {
1457
+ const cached = this.window.localStorage.getItem(CACHE_KEY);
1458
+ if (cached) {
1459
+ cachedData = JSON.parse(cached);
1460
+ }
1461
+ } catch (error) {
1462
+ console.warn("[RegisterAndLogin] localStorage 缓存解析失败:", error);
1463
+ }
1464
+ if (cachedData && Array.isArray(cachedData) && cachedData.length > 0) {
1465
+ this.countriesCache = cachedData;
1466
+ this.updateCountriesCache(CACHE_KEY, cachedData);
1467
+ this.store.isLoading = false;
1468
+ return cachedData;
1469
+ }
1463
1470
  const response = await this.apiCaller.call("getCountries");
1464
1471
  if (response.status && response.data) {
1465
- return response.data;
1472
+ const countries = response.data;
1473
+ this.countriesCache = countries;
1474
+ try {
1475
+ localStorage.setItem(CACHE_KEY, JSON.stringify(countries));
1476
+ } catch (error) {
1477
+ console.warn("[RegisterAndLogin] localStorage 存储失败:", error);
1478
+ }
1479
+ return countries;
1466
1480
  } else {
1467
1481
  this.store.error = response.message || "获取国家区号失败";
1468
1482
  throw new Error(this.store.error);
@@ -1475,6 +1489,29 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
1475
1489
  this.store.isLoading = false;
1476
1490
  }
1477
1491
  }
1492
+ /**
1493
+ * 异步更新国家缓存数据
1494
+ */
1495
+ async updateCountriesCache(cacheKey, cachedData) {
1496
+ try {
1497
+ const response = await this.apiCaller.call("getCountries");
1498
+ if (response.status && response.data) {
1499
+ const newData = response.data;
1500
+ const hasChanged = newData.length !== cachedData.length || JSON.stringify(newData) !== JSON.stringify(cachedData);
1501
+ if (hasChanged) {
1502
+ this.countriesCache = newData;
1503
+ try {
1504
+ localStorage.setItem(cacheKey, JSON.stringify(newData));
1505
+ } catch (error) {
1506
+ console.warn("[RegisterAndLogin] localStorage 更新失败:", error);
1507
+ }
1508
+ console.log("[RegisterAndLogin] 国家数据已更新");
1509
+ }
1510
+ }
1511
+ } catch (error) {
1512
+ console.warn("[RegisterAndLogin] 后台更新国家数据失败:", error);
1513
+ }
1514
+ }
1478
1515
  async destroy() {
1479
1516
  await this.core.effects.emit(import_types.RegisterAndLoginHooks.onDestroy, {});
1480
1517
  console.log("[RegisterAndLogin] 已销毁");
@@ -342,7 +342,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
342
342
  if (item.booking_id) {
343
343
  const product = (_a2 = this.hooks) == null ? void 0 : _a2.getProduct(item);
344
344
  (item.discount_list || []).forEach((discount) => {
345
- var _a3, _b, _c;
345
+ var _a3, _b, _c, _d, _e;
346
346
  if (discount.id && ["good_pass", "discount_card"].includes(discount.type)) {
347
347
  const index = editModeDiscountList.findIndex((n) => {
348
348
  var _a4;
@@ -352,7 +352,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
352
352
  editModeDiscountList[index] = {
353
353
  ...editModeDiscountList[index],
354
354
  amount: new import_decimal.default(discount.amount || 0).plus(new import_decimal.default(editModeDiscountList[index].amount || 0)).toNumber(),
355
- savedAmount: new import_decimal.default(discount.amount || 0).times((product == null ? void 0 : product.num) || 1).plus(new import_decimal.default(editModeDiscountList[index].savedAmount || 0)).toNumber()
355
+ savedAmount: new import_decimal.default(discount.amount || 0).times(((_a3 = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a3.num) || (product == null ? void 0 : product.num) || 1).plus(new import_decimal.default(editModeDiscountList[index].savedAmount || 0)).toNumber()
356
356
  };
357
357
  } else {
358
358
  if (discount.type && !discount.tag) {
@@ -363,13 +363,13 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
363
363
  name: discount.name || discount.discount.title.auto,
364
364
  isEditMode: true,
365
365
  limited_relation_product_data: {},
366
- savedAmount: discount.amount * ((product == null ? void 0 : product.num) || 1),
366
+ savedAmount: discount.amount * (((_b = discount == null ? void 0 : discount.metadata) == null ? void 0 : _b.num) || (product == null ? void 0 : product.num) || 1),
367
367
  isAvailable: true,
368
- id: ((_a3 = discount.discount) == null ? void 0 : _a3.resource_id) || discount.id,
369
- format_title: ((_b = discount.discount) == null ? void 0 : _b.title) || discount.format_title,
368
+ id: ((_c = discount.discount) == null ? void 0 : _c.resource_id) || discount.id,
369
+ format_title: ((_d = discount.discount) == null ? void 0 : _d.title) || discount.format_title,
370
370
  isDisabled: true,
371
371
  isSelected: true,
372
- product_id: ((_c = discount.discount) == null ? void 0 : _c.product_id) || discount.product_id
372
+ product_id: ((_e = discount.discount) == null ? void 0 : _e.product_id) || discount.product_id
373
373
  });
374
374
  }
375
375
  }
@@ -383,15 +383,17 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
383
383
  const isProductFree = (id) => {
384
384
  var _a2;
385
385
  const targetProduct = productList.find((n) => n.id === id);
386
+ if (!targetProduct)
387
+ return false;
386
388
  const product = (_a2 = this.hooks) == null ? void 0 : _a2.getProduct(targetProduct);
387
389
  return Number(product == null ? void 0 : product.total) <= 0 && (Number(product == null ? void 0 : product.origin_total) <= 0 || !(product == null ? void 0 : product.origin_total)) || (0, import_lodash_es.isBoolean)(product == null ? void 0 : product.vouchersApplicable) && !(product == null ? void 0 : product.vouchersApplicable);
388
390
  };
389
391
  const allUsedProductIds = newDiscountList.map((n) => {
390
392
  var _a2;
391
- return n.isSelected ? (_a2 = n.appliedProductDetails) == null ? void 0 : _a2.map((n2) => {
393
+ return n.isSelected ? ((_a2 = n.appliedProductDetails) == null ? void 0 : _a2.map((n2) => {
392
394
  var _a3;
393
395
  return (_a3 = n2.discount) == null ? void 0 : _a3.product_id;
394
- }) : [];
396
+ })) || n.product_id : [];
395
397
  }).flat();
396
398
  newDiscountList.forEach((item) => {
397
399
  var _a2;
@@ -12,6 +12,13 @@ export declare const isAllNormalProduct: (items: any[]) => boolean;
12
12
  * @returns
13
13
  */
14
14
  export declare const getDiscountAmount: (discount: Discount, total: number, price: number) => number;
15
+ export declare const getDiscountListAmountTotal: (discount: Discount[]) => any;
16
+ /**
17
+ * 获取折扣金额 计算每个折扣的金额
18
+ * @param discount
19
+ * @returns
20
+ */
21
+ export declare const getDiscountListAmount: (discount: Discount[]) => any;
15
22
  export interface ScheduleItem {
16
23
  id: number;
17
24
  name: string | {
@@ -32,6 +32,8 @@ __export(utils_exports, {
32
32
  filterDiscountListByBookingTime: () => filterDiscountListByBookingTime,
33
33
  getDateIsInSchedule: () => getDateIsInSchedule,
34
34
  getDiscountAmount: () => getDiscountAmount,
35
+ getDiscountListAmount: () => getDiscountListAmount,
36
+ getDiscountListAmountTotal: () => getDiscountListAmountTotal,
35
37
  isAllNormalProduct: () => isAllNormalProduct,
36
38
  isNormalProductByDurationSchedule: () => isNormalProductByDurationSchedule,
37
39
  uniqueById: () => uniqueById
@@ -53,13 +55,23 @@ var isAllNormalProduct = (items) => {
53
55
  var getDiscountAmount = (discount, total, price) => {
54
56
  var _a;
55
57
  if (discount.tag === "good_pass") {
56
- return new import_decimal.default(total).minus(new import_decimal.default(price || 0)).toNumber();
58
+ return new import_decimal.default(price).minus(new import_decimal.default(price || 0)).toNumber();
57
59
  }
58
60
  const isFixedAmount = ((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.discount_card_type) === "fixed_amount";
59
61
  if (isFixedAmount) {
60
- return Math.max(new import_decimal.default(total).minus(new import_decimal.default(discount.par_value || 0)).toNumber(), 0);
62
+ return Math.max(new import_decimal.default(price).minus(new import_decimal.default(discount.par_value || 0)).toNumber(), 0);
61
63
  }
62
- return new import_decimal.default(100).minus(discount.par_value || 0).div(100).mul(new import_decimal.default(total)).toNumber();
64
+ return new import_decimal.default(100).minus(discount.par_value || 0).div(100).mul(new import_decimal.default(price)).toNumber();
65
+ };
66
+ var getDiscountListAmountTotal = (discount) => {
67
+ return discount.reduce((acc, cur) => {
68
+ return new import_decimal.default(acc).plus(new import_decimal.default(cur.num || 1).mul(new import_decimal.default(cur.amount || 0))).toNumber();
69
+ }, new import_decimal.default(0));
70
+ };
71
+ var getDiscountListAmount = (discount) => {
72
+ return discount.reduce((acc, cur) => {
73
+ return new import_decimal.default(acc).plus(new import_decimal.default(cur.amount || 0)).toNumber();
74
+ }, new import_decimal.default(0));
63
75
  };
64
76
  var getDateIsInSchedule = (dateTime, scheduleList) => {
65
77
  if (!dateTime || !scheduleList || scheduleList.length === 0) {
@@ -222,6 +234,8 @@ var filterDiscountListByBookingTime = (discountList, bookingTime) => {
222
234
  filterDiscountListByBookingTime,
223
235
  getDateIsInSchedule,
224
236
  getDiscountAmount,
237
+ getDiscountListAmount,
238
+ getDiscountListAmountTotal,
225
239
  isAllNormalProduct,
226
240
  isNormalProductByDurationSchedule,
227
241
  uniqueById
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.337",
4
+ "version": "0.0.339",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",