@pisell/pisellos 3.0.4 → 3.0.6

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.
Files changed (189) hide show
  1. package/dist/modules/Account/index.d.ts +2 -6
  2. package/dist/modules/Account/index.js +21 -103
  3. package/dist/modules/Account/types.d.ts +12 -1
  4. package/dist/modules/AccountList/index.d.ts +20 -1
  5. package/dist/modules/AccountList/index.js +243 -75
  6. package/dist/modules/AccountList/types.d.ts +33 -1
  7. package/dist/modules/AccountList/types.js +8 -0
  8. package/dist/modules/AccountList/utils.d.ts +9 -0
  9. package/dist/modules/AccountList/utils.js +25 -0
  10. package/dist/modules/BaseModule.d.ts +2 -2
  11. package/dist/modules/BaseModule.js +1 -1
  12. package/dist/modules/Cart/index.d.ts +8 -5
  13. package/dist/modules/Cart/index.js +101 -25
  14. package/dist/modules/Cart/types.d.ts +82 -5
  15. package/dist/modules/Cart/types.js +22 -0
  16. package/dist/modules/Cart/utils.d.ts +106 -13
  17. package/dist/modules/Cart/utils.js +289 -76
  18. package/dist/modules/Date/index.d.ts +6 -6
  19. package/dist/modules/Date/index.js +41 -58
  20. package/dist/modules/Date/types.d.ts +22 -6
  21. package/dist/modules/Date/utils.d.ts +4 -3
  22. package/dist/modules/Date/utils.js +81 -30
  23. package/dist/modules/Discount/index.d.ts +4 -4
  24. package/dist/modules/Discount/index.js +11 -11
  25. package/dist/modules/Order/index.d.ts +11 -5
  26. package/dist/modules/Order/index.js +47 -18
  27. package/dist/modules/Order/types.d.ts +10 -3
  28. package/dist/modules/Order/utils.d.ts +10 -0
  29. package/dist/modules/Order/utils.js +15 -0
  30. package/dist/modules/Product/index.d.ts +14 -1
  31. package/dist/modules/Product/index.js +35 -0
  32. package/dist/modules/Product/types.d.ts +27 -3
  33. package/dist/modules/ProductList/index.js +11 -5
  34. package/dist/modules/Resource/types.d.ts +1 -0
  35. package/dist/modules/Resource/utils.js +1 -1
  36. package/dist/modules/Rules/index.d.ts +3 -3
  37. package/dist/modules/Rules/index.js +121 -53
  38. package/dist/modules/Rules/types.d.ts +5 -1
  39. package/dist/modules/Schedule/index.d.ts +18 -0
  40. package/dist/modules/Schedule/index.js +111 -0
  41. package/dist/modules/Schedule/type.d.ts +157 -0
  42. package/dist/modules/Schedule/type.js +1 -0
  43. package/dist/modules/Schedule/types.d.ts +182 -0
  44. package/dist/modules/Schedule/types.js +1 -0
  45. package/dist/modules/Schedule/utils.d.ts +67 -0
  46. package/dist/modules/Schedule/utils.js +729 -0
  47. package/dist/modules/Step/index.d.ts +14 -3
  48. package/dist/modules/Step/index.js +54 -2
  49. package/dist/modules/Summary/index.d.ts +12 -5
  50. package/dist/modules/Summary/index.js +33 -7
  51. package/dist/modules/Summary/types.d.ts +23 -2
  52. package/dist/modules/Summary/utils.d.ts +14 -4
  53. package/dist/modules/Summary/utils.js +46 -4
  54. package/dist/modules/index.d.ts +10 -0
  55. package/dist/modules/index.js +11 -1
  56. package/dist/plugins/index.d.ts +3 -3
  57. package/dist/plugins/request.d.ts +3 -3
  58. package/dist/plugins/request.js +30 -30
  59. package/dist/plugins/shopStore.d.ts +1 -1
  60. package/dist/solution/BookingByStep/index.d.ts +97 -24
  61. package/dist/solution/BookingByStep/index.js +1024 -322
  62. package/dist/solution/BookingByStep/types.d.ts +3 -10
  63. package/dist/solution/BookingByStep/types.js +11 -15
  64. package/dist/solution/BookingByStep/utils/products.d.ts +1 -1
  65. package/dist/solution/BookingByStep/utils/products.js +3 -0
  66. package/dist/solution/BookingByStep/utils/resources.d.ts +60 -6
  67. package/dist/solution/BookingByStep/utils/resources.js +293 -52
  68. package/dist/solution/ShopDiscount/index.d.ts +4 -4
  69. package/dist/solution/ShopDiscount/index.js +16 -16
  70. package/dist/solution/ShopDiscount/types.d.ts +2 -2
  71. package/dist/solution/ShopDiscount/utils.js +1 -1
  72. package/lib/core/index.js +7 -2
  73. package/lib/modules/Account/index.d.ts +2 -6
  74. package/lib/modules/Account/index.js +15 -30
  75. package/lib/modules/Account/types.d.ts +12 -1
  76. package/lib/modules/AccountList/index.d.ts +20 -1
  77. package/lib/modules/AccountList/index.js +122 -13
  78. package/lib/modules/AccountList/types.d.ts +33 -1
  79. package/lib/modules/AccountList/utils.d.ts +9 -0
  80. package/lib/modules/AccountList/utils.js +39 -0
  81. package/lib/modules/BaseModule.d.ts +2 -2
  82. package/lib/modules/BaseModule.js +14 -3
  83. package/lib/modules/Cart/index.d.ts +8 -5
  84. package/lib/modules/Cart/index.js +81 -8
  85. package/lib/modules/Cart/types.d.ts +82 -5
  86. package/lib/modules/Cart/types.js +20 -2
  87. package/lib/modules/Cart/utils.d.ts +106 -13
  88. package/lib/modules/Cart/utils.js +188 -45
  89. package/lib/modules/Date/index.d.ts +6 -6
  90. package/lib/modules/Date/index.js +13 -28
  91. package/lib/modules/Date/types.d.ts +22 -6
  92. package/lib/modules/Date/utils.d.ts +4 -3
  93. package/lib/modules/Date/utils.js +47 -13
  94. package/lib/modules/Discount/index.d.ts +4 -4
  95. package/lib/modules/Discount/index.js +9 -2
  96. package/lib/modules/Guests/index.js +4 -1
  97. package/lib/modules/Order/index.d.ts +11 -5
  98. package/lib/modules/Order/index.js +24 -3
  99. package/lib/modules/Order/types.d.ts +10 -3
  100. package/lib/modules/Order/utils.d.ts +10 -0
  101. package/lib/modules/Order/utils.js +45 -0
  102. package/lib/modules/Payment/index.js +1 -6
  103. package/lib/modules/Product/index.d.ts +14 -1
  104. package/lib/modules/Product/index.js +19 -0
  105. package/lib/modules/Product/types.d.ts +27 -3
  106. package/lib/modules/ProductList/index.js +21 -7
  107. package/lib/modules/Resource/index.js +4 -1
  108. package/lib/modules/Resource/types.d.ts +1 -0
  109. package/lib/modules/Resource/utils.js +7 -4
  110. package/lib/modules/Rules/index.d.ts +3 -3
  111. package/lib/modules/Rules/index.js +118 -43
  112. package/lib/modules/Rules/types.d.ts +5 -1
  113. package/lib/modules/Schedule/index.d.ts +18 -0
  114. package/lib/modules/Schedule/index.js +81 -0
  115. package/lib/modules/Schedule/type.d.ts +157 -0
  116. package/lib/modules/Schedule/type.js +17 -0
  117. package/lib/modules/Schedule/types.d.ts +182 -0
  118. package/lib/modules/Schedule/types.js +17 -0
  119. package/lib/modules/Schedule/utils.d.ts +67 -0
  120. package/lib/modules/Schedule/utils.js +600 -0
  121. package/lib/modules/Step/index.d.ts +14 -3
  122. package/lib/modules/Step/index.js +38 -1
  123. package/lib/modules/Summary/index.d.ts +12 -5
  124. package/lib/modules/Summary/index.js +15 -1
  125. package/lib/modules/Summary/types.d.ts +23 -2
  126. package/lib/modules/Summary/utils.d.ts +14 -4
  127. package/lib/modules/Summary/utils.js +30 -1
  128. package/lib/modules/index.d.ts +10 -0
  129. package/lib/modules/index.js +21 -1
  130. package/lib/plugins/index.d.ts +3 -3
  131. package/lib/plugins/request.d.ts +3 -3
  132. package/lib/plugins/request.js +48 -11
  133. package/lib/plugins/shopStore.d.ts +1 -1
  134. package/lib/solution/BookingByStep/index.d.ts +97 -24
  135. package/lib/solution/BookingByStep/index.js +693 -145
  136. package/lib/solution/BookingByStep/types.d.ts +3 -10
  137. package/lib/solution/BookingByStep/types.js +37 -14
  138. package/lib/solution/BookingByStep/utils/products.d.ts +1 -1
  139. package/lib/solution/BookingByStep/utils/products.js +3 -0
  140. package/lib/solution/BookingByStep/utils/resources.d.ts +60 -6
  141. package/lib/solution/BookingByStep/utils/resources.js +286 -54
  142. package/lib/solution/BuyTickets/index.js +34 -20
  143. package/lib/solution/ShopDiscount/index.d.ts +4 -4
  144. package/lib/solution/ShopDiscount/index.js +10 -2
  145. package/lib/solution/ShopDiscount/types.d.ts +2 -2
  146. package/package.json +4 -2
  147. package/dist/core/index.d.ts.map +0 -1
  148. package/dist/effects/index.d.ts.map +0 -1
  149. package/dist/index.d.ts.map +0 -1
  150. package/dist/modules/Account/index.d.ts.map +0 -1
  151. package/dist/modules/Account/types.d.ts.map +0 -1
  152. package/dist/modules/AccountList/types.d.ts.map +0 -1
  153. package/dist/modules/Cart/index.d.ts.map +0 -1
  154. package/dist/modules/Cart/types.d.ts.map +0 -1
  155. package/dist/modules/Date/types.d.ts.map +0 -1
  156. package/dist/modules/Date/utils.d.ts.map +0 -1
  157. package/dist/modules/Guests/index.d.ts.map +0 -1
  158. package/dist/modules/Guests/types.d.ts.map +0 -1
  159. package/dist/modules/Order/index.d.ts.map +0 -1
  160. package/dist/modules/Order/types.d.ts.map +0 -1
  161. package/dist/modules/Payment/index.d.ts.map +0 -1
  162. package/dist/modules/Payment/types.d.ts.map +0 -1
  163. package/dist/modules/Product/index.d.ts.map +0 -1
  164. package/dist/modules/Product/types.d.ts.map +0 -1
  165. package/dist/modules/ProductList/types.d.ts.map +0 -1
  166. package/dist/modules/Resource/index.d.ts.map +0 -1
  167. package/dist/modules/Resource/types.d.ts.map +0 -1
  168. package/dist/modules/Resource/utils.d.ts.map +0 -1
  169. package/dist/modules/Rules/types.d.ts.map +0 -1
  170. package/dist/modules/Step/index.d.ts.map +0 -1
  171. package/dist/modules/Step/tyeps.d.ts.map +0 -1
  172. package/dist/modules/Summary/index.d.ts.map +0 -1
  173. package/dist/modules/Summary/types.d.ts.map +0 -1
  174. package/dist/modules/Summary/utils.d.ts.map +0 -1
  175. package/dist/modules/index.d.ts.map +0 -1
  176. package/dist/plugins/index.d.ts.map +0 -1
  177. package/dist/plugins/request.d.ts.map +0 -1
  178. package/dist/plugins/shopStore.d.ts.map +0 -1
  179. package/dist/plugins/window.d.ts.map +0 -1
  180. package/dist/solution/BookingByStep/types.d.ts.map +0 -1
  181. package/dist/solution/BookingByStep/utils/products.d.ts.map +0 -1
  182. package/dist/solution/BuyTickets/index.d.ts.map +0 -1
  183. package/dist/solution/BuyTickets/types.d.ts.map +0 -1
  184. package/dist/solution/PlaceOrder/index.d.ts.map +0 -1
  185. package/dist/solution/ShopDiscount/types.d.ts.map +0 -1
  186. package/dist/solution/ShopDiscount/utils.d.ts.map +0 -1
  187. package/dist/solution/index.d.ts.map +0 -1
  188. package/dist/store/createStore.d.ts.map +0 -1
  189. package/dist/types/index.d.ts.map +0 -1
@@ -1,8 +1,8 @@
1
1
  import { Module, PisellCore, ModuleOptions } from '../../types';
2
2
  import { BaseModule } from '../BaseModule';
3
- import { Account, AccountModuleAPI } from './types';
3
+ import { Account } from './types';
4
4
  export * from './types';
5
- export declare class AccountModule extends BaseModule implements Module, AccountModuleAPI {
5
+ export declare class AccountModule extends BaseModule implements Module {
6
6
  protected defaultName: string;
7
7
  protected defaultVersion: string;
8
8
  isGuest: boolean;
@@ -14,13 +14,9 @@ export declare class AccountModule extends BaseModule implements Module, Account
14
14
  username: string;
15
15
  password: string;
16
16
  }): Promise<void>;
17
- logout(): Promise<void>;
18
- register(account: Omit<Account, 'id'>): Promise<void>;
19
17
  getCurrentAccount(): Account | null;
20
18
  updateProfile(updates: Partial<Account>): Promise<void>;
21
19
  isLoggedIn(): boolean;
22
- resetPassword(email: string): Promise<void>;
23
- updatePassword(oldPassword: string, newPassword: string): Promise<void>;
24
20
  getLoginStatus(): boolean;
25
21
  getAccount(): Account | null;
26
22
  setAccountInfo(account: Account): void;
@@ -33,7 +33,7 @@ var AccountModule = class extends import_BaseModule.BaseModule {
33
33
  this.defaultVersion = "1.0.0";
34
34
  this.isGuest = false;
35
35
  this.store = {
36
- currentAccount: null,
36
+ accountInfo: null,
37
37
  isLoggedIn: false,
38
38
  active: false
39
39
  };
@@ -45,7 +45,7 @@ var AccountModule = class extends import_BaseModule.BaseModule {
45
45
  }
46
46
  getId() {
47
47
  var _a;
48
- return ((_a = this.store.currentAccount) == null ? void 0 : _a.id) || "";
48
+ return ((_a = this.store.accountInfo) == null ? void 0 : _a.id) || "";
49
49
  }
50
50
  async login(credentials) {
51
51
  const account = {
@@ -54,54 +54,39 @@ var AccountModule = class extends import_BaseModule.BaseModule {
54
54
  username: credentials.username,
55
55
  email: `${credentials.username}@example.com`,
56
56
  name: credentials.username,
57
- isGuest: false
57
+ isGuest: false,
58
+ type: "account"
58
59
  };
59
- this.store.currentAccount = account;
60
+ this.store.accountInfo = account;
60
61
  this.store.isLoggedIn = true;
61
62
  await this.core.effects.emit(import_types.AccountHooks.OnLogin, account);
62
63
  }
63
- async logout() {
64
- this.store.currentAccount = null;
65
- this.store.isLoggedIn = false;
66
- await this.core.effects.emit(import_types.AccountHooks.OnLogout, {});
67
- }
68
- async register(account) {
69
- const newAccount = {
70
- id: "1",
71
- // 实际应该从 API 返回
72
- ...account
73
- };
74
- this.store.currentAccount = newAccount;
75
- this.store.isLoggedIn = true;
76
- await this.core.effects.emit(import_types.AccountHooks.OnRegister, newAccount);
77
- }
78
64
  getCurrentAccount() {
79
- return this.store.currentAccount;
65
+ return this.store.accountInfo;
80
66
  }
81
67
  async updateProfile(updates) {
82
- if (!this.store.currentAccount)
68
+ if (!this.store.accountInfo)
83
69
  return;
84
- this.store.currentAccount = {
85
- ...this.store.currentAccount,
70
+ this.store.accountInfo = {
71
+ ...this.store.accountInfo,
86
72
  ...updates
87
73
  };
88
- await this.core.effects.emit(import_types.AccountHooks.OnProfileUpdate, this.store.currentAccount);
74
+ await this.core.effects.emit(
75
+ import_types.AccountHooks.OnProfileUpdate,
76
+ this.store.accountInfo
77
+ );
89
78
  }
90
79
  isLoggedIn() {
91
80
  return this.store.isLoggedIn;
92
81
  }
93
- async resetPassword(email) {
94
- }
95
- async updatePassword(oldPassword, newPassword) {
96
- }
97
82
  getLoginStatus() {
98
83
  return this.store.isLoggedIn;
99
84
  }
100
85
  getAccount() {
101
- return this.store.currentAccount;
86
+ return this.store.accountInfo;
102
87
  }
103
88
  setAccountInfo(account) {
104
- this.store.currentAccount = account;
89
+ this.store.accountInfo = account;
105
90
  if (account.isGuest) {
106
91
  this.isGuest = true;
107
92
  }
@@ -9,19 +9,30 @@ export declare enum AccountHooks {
9
9
  */
10
10
  export interface Account {
11
11
  id: string | number;
12
+ /** 用户名 */
12
13
  username: string;
14
+ /** 邮箱 */
13
15
  email?: string;
16
+ /** 手机号 */
14
17
  phone?: string;
18
+ /** 昵称 */
15
19
  name?: string;
20
+ /** 头像 */
16
21
  avatar?: string;
22
+ /** 元数据 */
17
23
  metadata?: Record<string, any>;
24
+ /** 是否为游客 */
18
25
  isGuest?: boolean;
26
+ /** 账户类型 */
27
+ type?: 'account' | 'holder';
28
+ /** 账户信息原始数据 */
29
+ _origin?: Record<string, any>;
19
30
  }
20
31
  /**
21
32
  * 账户模块状态
22
33
  */
23
34
  export interface AccountState {
24
- currentAccount: Account | null;
35
+ accountInfo: Account | null;
25
36
  isLoggedIn: boolean;
26
37
  active: boolean;
27
38
  }
@@ -1,16 +1,24 @@
1
1
  import { Module, PisellCore, ModuleOptions } from '../../types';
2
2
  import { AccountModule, Account } from '../Account';
3
3
  import { BaseModule } from '../BaseModule';
4
+ import { IFetchHolderAccountsParams, IHolder } from './types';
4
5
  export declare class AccountListModule extends BaseModule implements Module {
5
6
  protected defaultName: string;
6
7
  protected defaultVersion: string;
7
8
  private store;
9
+ private request;
8
10
  private cacheId;
9
11
  private openCache;
10
12
  private fatherModule;
11
13
  constructor(name?: string, version?: string);
12
14
  initialize(core: PisellCore, options?: ModuleOptions): Promise<void>;
13
- addAccount(account: Account): Promise<void>;
15
+ /**
16
+ * 创建账号并添加到列表中
17
+ * @param account 账号信息
18
+ * @param needEmit 是否需要触发事件
19
+ */
20
+ private createAccountAndAdd;
21
+ addAccount(account: Account): Promise<AccountModule>;
14
22
  updateAccount(id: string, updates: Account): Promise<void>;
15
23
  updateAccountListById(id: string | number, updates: Account): Promise<void>;
16
24
  removeAccount(id: string): Promise<void>;
@@ -20,4 +28,15 @@ export declare class AccountListModule extends BaseModule implements Module {
20
28
  setActiveAccount(id: string | number): void;
21
29
  getActiveAccount(): AccountModule | null;
22
30
  storeChange(): void;
31
+ /**
32
+ * 批量添加holder类型账号
33
+ * @param holders 账号信息列表
34
+ * @param customerId 账户id
35
+ */
36
+ addHolderAccounts(holders: IHolder[], customerId: number): Promise<AccountModule[]>;
37
+ /**
38
+ * 获取holder类型账户列表
39
+ * @param params
40
+ */
41
+ fetchHolderAccounts(params: IFetchHolderAccountsParams): Promise<void>;
23
42
  }
@@ -26,6 +26,7 @@ var import_lodash_es = require("lodash-es");
26
26
  var import_Account = require("../Account");
27
27
  var import_BaseModule = require("../BaseModule");
28
28
  var import_types = require("./types");
29
+ var import_utils = require("./utils");
29
30
  var AccountListModule = class extends import_BaseModule.BaseModule {
30
31
  constructor(name, version) {
31
32
  super(name, version);
@@ -45,6 +46,7 @@ var AccountListModule = class extends import_BaseModule.BaseModule {
45
46
  var _a, _b, _c;
46
47
  this.core = core;
47
48
  this.store = options == null ? void 0 : options.store;
49
+ this.request = this.core.getPlugin("request");
48
50
  if (Array.isArray((_a = options == null ? void 0 : options.initialState) == null ? void 0 : _a.accountList)) {
49
51
  const recordList = (0, import_lodash_es.cloneDeep)(options.initialState.accountList || []);
50
52
  this.store.accounts = [];
@@ -63,13 +65,41 @@ var AccountListModule = class extends import_BaseModule.BaseModule {
63
65
  this.fatherModule = options.otherParams.fatherModule;
64
66
  }
65
67
  }
68
+ /**
69
+ * 创建账号并添加到列表中
70
+ * @param account 账号信息
71
+ * @param needEmit 是否需要触发事件
72
+ */
73
+ async createAccountAndAdd(account, needEmit = true) {
74
+ const tempAccountModule = this.store.accounts.find(
75
+ (a) => a.getId() === account.id
76
+ );
77
+ if (tempAccountModule) {
78
+ return tempAccountModule;
79
+ }
80
+ this.store.accountList.push(account);
81
+ const accountModule = new import_Account.AccountModule(`account_${account.id}`);
82
+ this.core.registerModule(accountModule);
83
+ accountModule.setAccountInfo(account);
84
+ this.store.accounts = [...this.store.accounts || [], accountModule];
85
+ if (needEmit) {
86
+ await this.core.effects.emit(
87
+ import_types.AccountListHooks.OnAccountListUpdate,
88
+ this.store
89
+ );
90
+ }
91
+ return accountModule;
92
+ }
66
93
  async addAccount(account) {
94
+ let currentAccountModule;
67
95
  try {
68
96
  this.store.isLoading = true;
69
97
  this.store.error = null;
70
98
  if (this.store.accounts.some((a) => a.getId() === account.id)) {
99
+ currentAccountModule = this.store.accounts.find(
100
+ (n) => n.getId() === account.id
101
+ );
71
102
  throw new Error(`Account with id ${account.id} already exists`);
72
- return;
73
103
  }
74
104
  this.store.accountList.push(account);
75
105
  const accountModule = new import_Account.AccountModule(`account_${account.id}`);
@@ -79,13 +109,21 @@ var AccountListModule = class extends import_BaseModule.BaseModule {
79
109
  if (this.store.accounts.length === 1) {
80
110
  this.setActiveAccount(accountModule.getId());
81
111
  }
82
- await this.core.effects.emit(import_types.AccountListHooks.OnAccountListUpdate, this.store);
112
+ currentAccountModule = accountModule;
113
+ await this.core.effects.emit(
114
+ import_types.AccountListHooks.OnAccountListUpdate,
115
+ this.store
116
+ );
83
117
  } catch (error) {
84
118
  console.error(error);
85
119
  this.store.error = error instanceof Error ? error.message : "Failed to add account";
86
- await this.core.effects.emit(import_types.AccountListHooks.OnAccountListError, this.store.error);
120
+ await this.core.effects.emit(
121
+ import_types.AccountListHooks.OnAccountListError,
122
+ this.store.error
123
+ );
87
124
  } finally {
88
125
  this.store.isLoading = false;
126
+ return currentAccountModule;
89
127
  }
90
128
  }
91
129
  async updateAccount(id, updates) {
@@ -97,14 +135,22 @@ var AccountListModule = class extends import_BaseModule.BaseModule {
97
135
  throw new Error(`Account with id ${id} not found`);
98
136
  }
99
137
  account.setAccountInfo(updates);
100
- const index = this.store.accountList.findIndex((account2) => account2.id === id);
138
+ const index = this.store.accountList.findIndex(
139
+ (account2) => account2.id === id
140
+ );
101
141
  if (index !== -1) {
102
142
  this.store.accountList[index] = updates;
103
143
  }
104
- await this.core.effects.emit(import_types.AccountListHooks.OnAccountListUpdate, this.store);
144
+ await this.core.effects.emit(
145
+ import_types.AccountListHooks.OnAccountListUpdate,
146
+ this.store
147
+ );
105
148
  } catch (error) {
106
149
  this.store.error = error instanceof Error ? error.message : "Failed to update account";
107
- await this.core.effects.emit(import_types.AccountListHooks.OnAccountListError, this.store.error);
150
+ await this.core.effects.emit(
151
+ import_types.AccountListHooks.OnAccountListError,
152
+ this.store.error
153
+ );
108
154
  } finally {
109
155
  this.store.isLoading = false;
110
156
  }
@@ -116,7 +162,10 @@ var AccountListModule = class extends import_BaseModule.BaseModule {
116
162
  }
117
163
  return account;
118
164
  });
119
- this.core.effects.emit(`${this.name}:changed`, { path: "accounts", value: this.store.accountList });
165
+ this.core.effects.emit(`${this.name}:changed`, {
166
+ path: "accounts",
167
+ value: this.store.accountList
168
+ });
120
169
  }
121
170
  async removeAccount(id) {
122
171
  try {
@@ -131,11 +180,19 @@ var AccountListModule = class extends import_BaseModule.BaseModule {
131
180
  ...(this.store.accounts || []).slice(0, index),
132
181
  ...(this.store.accounts || []).slice(index + 1)
133
182
  ];
134
- this.store.accountList = this.store.accountList.filter((account) => account.id !== id);
135
- await this.core.effects.emit(import_types.AccountListHooks.OnAccountListUpdate, this.store);
183
+ this.store.accountList = this.store.accountList.filter(
184
+ (account) => account.id !== id
185
+ );
186
+ await this.core.effects.emit(
187
+ import_types.AccountListHooks.OnAccountListUpdate,
188
+ this.store
189
+ );
136
190
  } catch (error) {
137
191
  this.store.error = error instanceof Error ? error.message : "Failed to remove account";
138
- await this.core.effects.emit(import_types.AccountListHooks.OnAccountListError, this.store.error);
192
+ await this.core.effects.emit(
193
+ import_types.AccountListHooks.OnAccountListError,
194
+ this.store.error
195
+ );
139
196
  } finally {
140
197
  this.store.isLoading = false;
141
198
  }
@@ -151,10 +208,16 @@ var AccountListModule = class extends import_BaseModule.BaseModule {
151
208
  this.store.isLoading = true;
152
209
  this.store.error = null;
153
210
  this.store.accounts = [];
154
- await this.core.effects.emit(import_types.AccountListHooks.OnAccountListUpdate, this.store);
211
+ await this.core.effects.emit(
212
+ import_types.AccountListHooks.OnAccountListUpdate,
213
+ this.store
214
+ );
155
215
  } catch (error) {
156
216
  this.store.error = error instanceof Error ? error.message : "Failed to clear accounts";
157
- await this.core.effects.emit(import_types.AccountListHooks.OnAccountListError, this.store.error);
217
+ await this.core.effects.emit(
218
+ import_types.AccountListHooks.OnAccountListError,
219
+ this.store.error
220
+ );
158
221
  } finally {
159
222
  this.store.isLoading = false;
160
223
  }
@@ -177,7 +240,53 @@ var AccountListModule = class extends import_BaseModule.BaseModule {
177
240
  store.accountList = store.accountList.filter(
178
241
  (account, index, self) => index === self.findIndex((t) => t.id === account.id)
179
242
  );
180
- this.checkSaveCache({ cacheId: this.cacheId, fatherModule: this.fatherModule, store, cacheKey: ["accountList"] });
243
+ this.checkSaveCache({
244
+ cacheId: this.cacheId,
245
+ fatherModule: this.fatherModule,
246
+ store,
247
+ cacheKey: ["accountList"]
248
+ });
249
+ }
250
+ }
251
+ /**
252
+ * 批量添加holder类型账号
253
+ * @param holders 账号信息列表
254
+ * @param customerId 账户id
255
+ */
256
+ async addHolderAccounts(holders, customerId) {
257
+ const accountModules = [];
258
+ for (const holder of holders) {
259
+ const account = (0, import_utils.createHolderAccount)(holder, customerId);
260
+ const accountModule = await this.createAccountAndAdd(account, false);
261
+ accountModules.push(accountModule);
262
+ }
263
+ await this.core.effects.emit(
264
+ import_types.AccountListHooks.OnAccountListUpdate,
265
+ this.store
266
+ );
267
+ return accountModules;
268
+ }
269
+ /**
270
+ * 获取holder类型账户列表
271
+ * @param params
272
+ */
273
+ async fetchHolderAccounts(params) {
274
+ var _a, _b;
275
+ const url = params.url || "/account/holder";
276
+ const { form_id, shop_id, num, skip, customer_id } = (params == null ? void 0 : params.query) || {};
277
+ try {
278
+ const res = await this.request.get(url, {
279
+ customer_id,
280
+ form_id,
281
+ shop_id,
282
+ num: num || 100,
283
+ skip: skip || 1
284
+ });
285
+ if ((_b = (_a = res == null ? void 0 : res.data) == null ? void 0 : _a.list) == null ? void 0 : _b.length) {
286
+ await this.addHolderAccounts(res.data.list, customer_id);
287
+ }
288
+ } catch (error) {
289
+ console.error(error);
181
290
  }
182
291
  }
183
292
  };
@@ -1,4 +1,4 @@
1
- import { Account, AccountModule } from "../Account";
1
+ import { Account, AccountModule } from '../Account';
2
2
  export declare enum AccountListHooks {
3
3
  OnAccountListUpdate = "accountList:onUpdate",
4
4
  OnAccountListError = "accountList:onError"
@@ -27,11 +27,43 @@ export interface AccountListState {
27
27
  * 账户列表模块 API
28
28
  */
29
29
  export interface AccountListModuleAPI {
30
+ /** 添加账户 */
30
31
  addAccount: (account: Account) => Promise<void>;
32
+ /** 更新账户 */
31
33
  updateAccount: (id: string, updates: Partial<AccountModule>) => Promise<void>;
34
+ /** 删除账户 */
32
35
  removeAccount: (id: string) => Promise<void>;
36
+ /** 获取账户列表 */
33
37
  getAccounts: () => AccountModule[];
38
+ /** 获取单个账户 */
34
39
  getAccount: (id: string) => AccountModule | null;
40
+ /** 清空账户列表 */
35
41
  clearAccounts: () => Promise<void>;
42
+ /** 批量添加账户 */
36
43
  addAccounts: (accounts: AccountModule[]) => Promise<void>;
44
+ /** 获取holder类型账户列表 */
45
+ fetchHolderAccounts: (params: IFetchHolderAccountsParams) => Promise<void>;
46
+ }
47
+ /**
48
+ * 获取holder类型账户列表参数
49
+ */
50
+ export interface IFetchHolderAccountsParams {
51
+ url?: string;
52
+ query: {
53
+ customer_id: number;
54
+ form_id: string | number;
55
+ shop_id: string | number;
56
+ num?: number;
57
+ skip?: number;
58
+ };
59
+ }
60
+ /**
61
+ * holder类型数据
62
+ */
63
+ export interface IHolder {
64
+ created_at: string;
65
+ form_id: number;
66
+ form_record_id: number;
67
+ main_field: string;
68
+ customer_cover?: string;
37
69
  }
@@ -0,0 +1,9 @@
1
+ import { Account } from '../Account/types';
2
+ import { IHolder } from './types';
3
+ /**
4
+ * 创建holder类型账号
5
+ * @param holder
6
+ * @param customer_id 账户id
7
+ * @returns
8
+ */
9
+ export declare const createHolderAccount: (holder: IHolder, customerId: number) => Account;
@@ -0,0 +1,39 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/modules/AccountList/utils.ts
20
+ var utils_exports = {};
21
+ __export(utils_exports, {
22
+ createHolderAccount: () => createHolderAccount
23
+ });
24
+ module.exports = __toCommonJS(utils_exports);
25
+ var createHolderAccount = (holder, customerId) => {
26
+ const account = {
27
+ id: holder.form_record_id,
28
+ name: holder.main_field,
29
+ username: holder.main_field,
30
+ avatar: (holder == null ? void 0 : holder.customer_cover) || "",
31
+ type: "holder",
32
+ _origin: { ...holder, customer_id: customerId }
33
+ };
34
+ return account;
35
+ };
36
+ // Annotate the CommonJS export names for ESM import in node:
37
+ 0 && (module.exports = {
38
+ createHolderAccount
39
+ });
@@ -1,4 +1,4 @@
1
- import { PisellCore } from "../types";
1
+ import { PisellCore } from '../types';
2
2
  export declare class BaseModule {
3
3
  protected defaultName: string;
4
4
  protected defaultVersion: string;
@@ -8,7 +8,7 @@ export declare class BaseModule {
8
8
  protected core: PisellCore;
9
9
  constructor(name?: string, version?: string);
10
10
  destroy(): void;
11
- checkSaveCache({ cacheId, fatherModule, store, cacheKey }: {
11
+ checkSaveCache({ cacheId, fatherModule, store, cacheKey, }: {
12
12
  cacheId: string | undefined;
13
13
  fatherModule: string | undefined;
14
14
  store: any;
@@ -35,7 +35,12 @@ var BaseModule = class {
35
35
  this.core.unregisterModule(this);
36
36
  }
37
37
  // 提供统一的缓存 module 里的数据的方法
38
- checkSaveCache({ cacheId, fatherModule, store, cacheKey }) {
38
+ checkSaveCache({
39
+ cacheId,
40
+ fatherModule,
41
+ store,
42
+ cacheKey
43
+ }) {
39
44
  const window = this.core.getPlugin("window");
40
45
  if (cacheId) {
41
46
  if (fatherModule) {
@@ -54,7 +59,10 @@ var BaseModule = class {
54
59
  cacheKey.forEach((key) => {
55
60
  currentCacheDataObj[cacheId][this.name][key] = store == null ? void 0 : store[key];
56
61
  });
57
- window.sessionStorage.setItem(fatherModule, JSON.stringify(currentCacheDataObj));
62
+ window.sessionStorage.setItem(
63
+ fatherModule,
64
+ JSON.stringify(currentCacheDataObj)
65
+ );
58
66
  } else {
59
67
  let currentCacheData = window.sessionStorage.getItem(cacheId);
60
68
  let currentCacheDataObj = JSON.parse(currentCacheData || "{}");
@@ -67,7 +75,10 @@ var BaseModule = class {
67
75
  cacheKey.forEach((key) => {
68
76
  currentCacheDataObj[this.name][key] = store[key];
69
77
  });
70
- window.sessionStorage.setItem(cacheId, JSON.stringify(currentCacheDataObj));
78
+ window.sessionStorage.setItem(
79
+ cacheId,
80
+ JSON.stringify(currentCacheDataObj)
81
+ );
71
82
  }
72
83
  }
73
84
  }
@@ -1,7 +1,7 @@
1
- import { Module, PisellCore, ModuleOptions } from "../../types";
2
- import { BaseModule } from "../BaseModule";
3
- import { CartItem, CartModuleAPI, IAddItemParams, IUpdateItemParams } from "./types";
4
- export * from "./types";
1
+ import { Module, PisellCore, ModuleOptions } from '../../types';
2
+ import { BaseModule } from '../BaseModule';
3
+ import { CartItem, CartModuleAPI, ECartItemCheckType, ECartItemInfoType, IAddItemParams, IUpdateItemParams } from './types';
4
+ export * from './types';
5
5
  /**
6
6
  * 购物车模块实现
7
7
  */
@@ -57,11 +57,14 @@ export declare class CartModule extends BaseModule implements Module, CartModule
57
57
  clearCartByAccount(account_id: string): void;
58
58
  /**
59
59
  * 清除购物车商品中的信息
60
+ * @param type 清除购物车商品中的信息类型
61
+ * @param _id 购物车商品ID
60
62
  */
61
- deleteCartItemInfo(types: "resource" | "time"): void;
63
+ deleteCartItemInfo(type: ECartItemInfoType, _id?: string): void;
62
64
  /**
63
65
  * 清除购物车
64
66
  */
65
67
  clear(): void;
66
68
  storeChange(): void;
69
+ checkCartItemByType(cartItem: CartItem, type: ECartItemCheckType): boolean;
67
70
  }