@pisell/pisellos 2.3.74 → 2.3.76

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 (283) hide show
  1. package/dist/core/index.js +6 -10
  2. package/dist/model/strategy/adapter/promotion/index.js +9 -0
  3. package/dist/model/strategy/adapter/walletPass/example.js +3 -26
  4. package/dist/model/strategy/strategy-example.js +5 -19
  5. package/dist/modules/Cart/index.js +0 -3
  6. package/dist/modules/Cart/utils/cartProduct.js +0 -1
  7. package/dist/modules/Date/index.js +1 -5
  8. package/dist/modules/Discount/index.js +2 -4
  9. package/dist/modules/OpenData/index.js +0 -2
  10. package/dist/modules/Order/index.d.ts +1 -1
  11. package/dist/modules/Order/index.js +75 -91
  12. package/dist/modules/Order/types.d.ts +3 -1
  13. package/dist/modules/Payment/index.js +97 -162
  14. package/dist/modules/Rules/index.js +1 -4
  15. package/dist/modules/Schedule/index.js +0 -1
  16. package/dist/modules/Schedule/utils.js +0 -1
  17. package/dist/modules/Step/index.js +0 -1
  18. package/dist/plugins/request.js +1 -4
  19. package/dist/plugins/window.js +2 -6
  20. package/dist/server/index.js +97 -129
  21. package/dist/server/modules/menu/index.js +32 -41
  22. package/dist/server/modules/order/index.js +2 -4
  23. package/dist/server/modules/products/index.js +24 -42
  24. package/dist/server/modules/quotation/index.js +29 -38
  25. package/dist/server/modules/resource/index.js +3 -4
  26. package/dist/server/modules/schedule/index.js +27 -35
  27. package/dist/server/utils/product.js +0 -1
  28. package/dist/solution/BaseSales/index.js +100 -72
  29. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +5 -0
  30. package/dist/solution/BaseSales/utils/cartPromotion.js +15 -6
  31. package/dist/solution/BookingByStep/index.js +7 -59
  32. package/dist/solution/BookingByStep/utils/capacity.js +1 -11
  33. package/dist/solution/BookingByStep/utils/resources.js +1 -3
  34. package/dist/solution/BookingByStep/utils/timeslots.js +2 -43
  35. package/dist/solution/BookingTicket/index.js +0 -2
  36. package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +6 -7
  37. package/dist/solution/BookingTicket/utils/scan/handleScan.js +25 -31
  38. package/dist/solution/BookingTicket/utils/scan/index.js +6 -10
  39. package/dist/solution/BuyTickets/index.js +9 -12
  40. package/dist/solution/Checkout/index.js +177 -252
  41. package/dist/solution/Checkout/utils/index.js +4 -16
  42. package/dist/solution/RegisterAndLogin/index.js +30 -76
  43. package/dist/solution/ScanOrder/index.js +50 -60
  44. package/dist/solution/ShopDiscount/index.js +2 -7
  45. package/dist/solution/VenueBooking/index.js +45 -55
  46. package/dist/utils/task.js +15 -18
  47. package/dist/utils/watch.js +0 -1
  48. package/lib/apis/picoding.js +2 -0
  49. package/lib/core/index.js +134 -134
  50. package/lib/effects/index.js +46 -57
  51. package/lib/index.js +82 -49
  52. package/lib/model/index.js +14 -21
  53. package/lib/model/strategy/adapter/dataVariant/adapter.js +38 -50
  54. package/lib/model/strategy/adapter/dataVariant/evaluator.js +162 -236
  55. package/lib/model/strategy/adapter/dataVariant/examples.js +229 -237
  56. package/lib/model/strategy/adapter/dataVariant/index.js +39 -34
  57. package/lib/model/strategy/adapter/dataVariant/type.js +57 -28
  58. package/lib/model/strategy/adapter/index.js +100 -64
  59. package/lib/model/strategy/adapter/itemRule/adapter.js +156 -144
  60. package/lib/model/strategy/adapter/itemRule/evaluator.js +36 -48
  61. package/lib/model/strategy/adapter/itemRule/examples.js +295 -225
  62. package/lib/model/strategy/adapter/itemRule/index.js +83 -57
  63. package/lib/model/strategy/adapter/itemRule/type.js +97 -36
  64. package/lib/model/strategy/adapter/promotion/adapter.js +91 -69
  65. package/lib/model/strategy/adapter/promotion/evaluator.js +444 -310
  66. package/lib/model/strategy/adapter/promotion/examples.js +222 -234
  67. package/lib/model/strategy/adapter/promotion/index.js +1 -0
  68. package/lib/model/strategy/adapter/promotion/type.js +243 -36
  69. package/lib/model/strategy/adapter/type.js +4 -16
  70. package/lib/model/strategy/adapter/walletPass/evaluator.js +180 -150
  71. package/lib/model/strategy/adapter/walletPass/example.js +217 -190
  72. package/lib/model/strategy/adapter/walletPass/index.js +75 -51
  73. package/lib/model/strategy/adapter/walletPass/locales.js +36 -58
  74. package/lib/model/strategy/adapter/walletPass/type.js +4 -16
  75. package/lib/model/strategy/adapter/walletPass/utils.js +588 -378
  76. package/lib/model/strategy/engine.js +270 -168
  77. package/lib/model/strategy/index.js +49 -34
  78. package/lib/model/strategy/strategy-example.js +243 -239
  79. package/lib/model/strategy/type.js +100 -40
  80. package/lib/modules/Account/index.js +39 -53
  81. package/lib/modules/Account/types.js +20 -33
  82. package/lib/modules/AccountList/index.js +116 -154
  83. package/lib/modules/AccountList/types.js +30 -31
  84. package/lib/modules/AccountList/utils.js +18 -30
  85. package/lib/modules/BaseModule.js +23 -42
  86. package/lib/modules/BookingContext/index.js +158 -136
  87. package/lib/modules/BookingContext/types.js +46 -32
  88. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +138 -146
  89. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +78 -83
  90. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +170 -150
  91. package/lib/modules/BookingContext/utils/flexible.js +38 -55
  92. package/lib/modules/BookingContext/utils/formatResourceList.js +19 -34
  93. package/lib/modules/BookingContext/utils/index.js +124 -41
  94. package/lib/modules/BookingContext/utils/noResource.js +58 -70
  95. package/lib/modules/BookingContext/utils/orderLineDisplay.js +14 -41
  96. package/lib/modules/BookingContext/utils/productExtend.js +202 -155
  97. package/lib/modules/BookingContext/utils/resourceErrors.js +53 -53
  98. package/lib/modules/BookingContext/utils/resourceSelection.js +19 -41
  99. package/lib/modules/BookingContext/utils/resources.js +209 -167
  100. package/lib/modules/BookingContext/utils/serviceTimes.js +115 -116
  101. package/lib/modules/BookingContext/utils/timeSlices.js +76 -86
  102. package/lib/modules/Cart/index.js +170 -124
  103. package/lib/modules/Cart/types.js +46 -51
  104. package/lib/modules/Cart/utils/cartAccount.js +40 -39
  105. package/lib/modules/Cart/utils/cartDate.js +56 -61
  106. package/lib/modules/Cart/utils/cartDiscount.js +28 -33
  107. package/lib/modules/Cart/utils/cartNote.js +27 -32
  108. package/lib/modules/Cart/utils/cartProduct.js +321 -251
  109. package/lib/modules/Cart/utils/cartRelationForms.js +29 -35
  110. package/lib/modules/Cart/utils/cartResource.js +70 -78
  111. package/lib/modules/Cart/utils/changePrice.js +22 -50
  112. package/lib/modules/Cart/utils/index.js +106 -48
  113. package/lib/modules/Customer/constants.js +13 -34
  114. package/lib/modules/Customer/index.js +235 -172
  115. package/lib/modules/Customer/types.js +38 -35
  116. package/lib/modules/Date/index.js +116 -115
  117. package/lib/modules/Date/types.js +16 -28
  118. package/lib/modules/Date/utils.js +174 -123
  119. package/lib/modules/Discount/index.js +122 -127
  120. package/lib/modules/Discount/types.js +9 -31
  121. package/lib/modules/Guests/index.js +30 -56
  122. package/lib/modules/Guests/types.js +23 -33
  123. package/lib/modules/Holder/index.js +209 -189
  124. package/lib/modules/Holder/types.js +4 -16
  125. package/lib/modules/Holder/utils.js +20 -49
  126. package/lib/modules/OpenData/index.js +70 -76
  127. package/lib/modules/OpenData/types.js +4 -16
  128. package/lib/modules/OpenData/utils.js +44 -78
  129. package/lib/modules/Order/index.d.ts +1 -1
  130. package/lib/modules/Order/index.js +1733 -2121
  131. package/lib/modules/Order/payment-utils.js +77 -120
  132. package/lib/modules/Order/types.d.ts +3 -1
  133. package/lib/modules/Order/types.js +88 -35
  134. package/lib/modules/Order/utils/bundleDiscountHydration.js +41 -74
  135. package/lib/modules/Order/utils/discountProductLineIdentity.js +142 -100
  136. package/lib/modules/Order/utils/manualProductDiscount.js +124 -123
  137. package/lib/modules/Order/utils/orderCollectionIdentity.js +184 -244
  138. package/lib/modules/Order/utils.js +814 -647
  139. package/lib/modules/Payment/cash.js +20 -33
  140. package/lib/modules/Payment/cashRecommendationAlgorithm.js +145 -76
  141. package/lib/modules/Payment/eftpos.js +16 -30
  142. package/lib/modules/Payment/index.js +532 -399
  143. package/lib/modules/Payment/mx51.js +1 -0
  144. package/lib/modules/Payment/types.js +230 -108
  145. package/lib/modules/Payment/utils.js +52 -51
  146. package/lib/modules/Payment/walletpass.js +485 -660
  147. package/lib/modules/Product/index.js +51 -46
  148. package/lib/modules/Product/types.js +4 -16
  149. package/lib/modules/Product/utils.js +32 -33
  150. package/lib/modules/ProductList/index.js +113 -123
  151. package/lib/modules/ProductList/types.js +9 -31
  152. package/lib/modules/Quotation/index.js +81 -118
  153. package/lib/modules/Quotation/types.js +4 -16
  154. package/lib/modules/Resource/index.js +27 -59
  155. package/lib/modules/Resource/types.js +22 -32
  156. package/lib/modules/Resource/utils.js +30 -38
  157. package/lib/modules/ResourcePlanner/index.js +25 -23
  158. package/lib/modules/ResourcePlanner/localClock.js +54 -119
  159. package/lib/modules/ResourcePlanner/planner.js +589 -770
  160. package/lib/modules/ResourcePlanner/types.js +10 -29
  161. package/lib/modules/Rules/index.js +1218 -959
  162. package/lib/modules/Rules/types.js +17 -40
  163. package/lib/modules/SalesSummary/index.js +85 -90
  164. package/lib/modules/SalesSummary/types.js +4 -16
  165. package/lib/modules/SalesSummary/utils.js +355 -430
  166. package/lib/modules/ScanOrderLogger/index.js +59 -79
  167. package/lib/modules/ScanOrderLogger/providers/feishu.js +54 -78
  168. package/lib/modules/ScanOrderLogger/providers/grafana.js +13 -36
  169. package/lib/modules/ScanOrderLogger/types.js +4 -16
  170. package/lib/modules/Schedule/getDateIsInSchedule.js +334 -163
  171. package/lib/modules/Schedule/index.js +100 -114
  172. package/lib/modules/Schedule/type.js +4 -16
  173. package/lib/modules/Schedule/types.js +4 -16
  174. package/lib/modules/Schedule/utils.js +433 -291
  175. package/lib/modules/Step/index.js +40 -52
  176. package/lib/modules/Step/tyeps.js +4 -16
  177. package/lib/modules/Summary/index.js +66 -71
  178. package/lib/modules/Summary/types.js +4 -16
  179. package/lib/modules/Summary/utils.js +773 -418
  180. package/lib/modules/SurchargeList/index.js +46 -60
  181. package/lib/modules/SurchargeList/types.js +4 -16
  182. package/lib/modules/index.js +245 -63
  183. package/lib/plugins/app.js +4 -16
  184. package/lib/plugins/index.js +36 -25
  185. package/lib/plugins/request.js +137 -126
  186. package/lib/plugins/shopStore.js +4 -16
  187. package/lib/plugins/user.js +4 -16
  188. package/lib/plugins/window.js +171 -179
  189. package/lib/server/index.js +3050 -2665
  190. package/lib/server/modules/floor-plan/index.js +118 -134
  191. package/lib/server/modules/floor-plan/types.js +15 -30
  192. package/lib/server/modules/index.js +106 -68
  193. package/lib/server/modules/menu/index.js +142 -122
  194. package/lib/server/modules/menu/types.js +18 -31
  195. package/lib/server/modules/order/index.js +784 -1002
  196. package/lib/server/modules/order/types.js +122 -33
  197. package/lib/server/modules/order/utils/filterBookings.js +219 -194
  198. package/lib/server/modules/order/utils/filterOrders.js +118 -92
  199. package/lib/server/modules/payment/index.js +59 -83
  200. package/lib/server/modules/payment/types.js +4 -16
  201. package/lib/server/modules/products/index.js +583 -471
  202. package/lib/server/modules/products/types.js +44 -34
  203. package/lib/server/modules/quotation/index.js +137 -172
  204. package/lib/server/modules/quotation/types.js +21 -31
  205. package/lib/server/modules/resource/index.js +220 -186
  206. package/lib/server/modules/resource/types.js +42 -33
  207. package/lib/server/modules/schedule/index.js +135 -123
  208. package/lib/server/modules/schedule/types.js +14 -21
  209. package/lib/server/modules/schedule/utils.js +334 -163
  210. package/lib/server/types.js +4 -16
  211. package/lib/server/utils/index.js +25 -23
  212. package/lib/server/utils/product.js +196 -139
  213. package/lib/server/utils/schedule.js +34 -41
  214. package/lib/server/utils/small-ticket.js +479 -456
  215. package/lib/server/utils/time.js +40 -49
  216. package/lib/solution/BaseSales/index.js +1220 -1412
  217. package/lib/solution/BaseSales/types.js +42 -38
  218. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +5 -0
  219. package/lib/solution/BaseSales/utils/cartPromotion.js +652 -498
  220. package/lib/solution/BaseSales/utils/parseSalesResponse.js +85 -105
  221. package/lib/solution/BaseSales/utils/quotationPrice.js +56 -114
  222. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +108 -145
  223. package/lib/solution/BaseSales/utils.js +158 -143
  224. package/lib/solution/BookingByStep/index.js +1527 -1340
  225. package/lib/solution/BookingByStep/types.js +40 -99
  226. package/lib/solution/BookingByStep/utils/capacity.js +192 -160
  227. package/lib/solution/BookingByStep/utils/products.js +42 -52
  228. package/lib/solution/BookingByStep/utils/resources.js +527 -330
  229. package/lib/solution/BookingByStep/utils/stock.js +65 -44
  230. package/lib/solution/BookingByStep/utils/timeslots.js +129 -131
  231. package/lib/solution/BookingTicket/index.js +607 -522
  232. package/lib/solution/BookingTicket/types.js +99 -77
  233. package/lib/solution/BookingTicket/utils/addProductDecision.js +226 -189
  234. package/lib/solution/BookingTicket/utils/addTimeAvailability.js +58 -89
  235. package/lib/solution/BookingTicket/utils/bookingStatus.js +107 -78
  236. package/lib/solution/BookingTicket/utils/cartView.js +114 -99
  237. package/lib/solution/BookingTicket/utils/exampleData.js +185 -0
  238. package/lib/solution/BookingTicket/utils/orderCustomer.js +18 -41
  239. package/lib/solution/BookingTicket/utils/resolveBestAddTimePlan.js +219 -86
  240. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +168 -116
  241. package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +79 -91
  242. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +54 -41
  243. package/lib/solution/BookingTicket/utils/scan/handleScan.js +84 -81
  244. package/lib/solution/BookingTicket/utils/scan/index.js +98 -104
  245. package/lib/solution/BookingTicket/utils/scan/scanCache.js +90 -43
  246. package/lib/solution/BookingTicket/utils/scan/scanProductValues.js +52 -64
  247. package/lib/solution/BookingTicket/utils/sessionCatalogStale.js +56 -58
  248. package/lib/solution/BookingTicket/utils/weighingProductSku.js +34 -48
  249. package/lib/solution/BuyTickets/index.js +67 -70
  250. package/lib/solution/BuyTickets/types.js +22 -38
  251. package/lib/solution/Checkout/index.js +1451 -1158
  252. package/lib/solution/Checkout/types.js +91 -61
  253. package/lib/solution/Checkout/utils/index.js +228 -156
  254. package/lib/solution/PlaceOrder/index.js +55 -0
  255. package/lib/solution/RegisterAndLogin/config.js +493 -460
  256. package/lib/solution/RegisterAndLogin/index.js +633 -630
  257. package/lib/solution/RegisterAndLogin/types.js +189 -76
  258. package/lib/solution/RegisterAndLogin/utils.js +183 -125
  259. package/lib/solution/Sales/index.js +328 -324
  260. package/lib/solution/Sales/types.js +27 -33
  261. package/lib/solution/ScanOrder/index.js +832 -864
  262. package/lib/solution/ScanOrder/types.js +33 -34
  263. package/lib/solution/ScanOrder/utils.js +409 -374
  264. package/lib/solution/ShopDiscount/index.js +226 -232
  265. package/lib/solution/ShopDiscount/types.js +15 -37
  266. package/lib/solution/ShopDiscount/utils.js +300 -172
  267. package/lib/solution/UnifiedBookingSales/index.js +1035 -1201
  268. package/lib/solution/UnifiedBookingSales/remoteOccupancyCache.js +99 -159
  269. package/lib/solution/UnifiedBookingSales/types.js +10 -32
  270. package/lib/solution/VenueBooking/index.js +811 -879
  271. package/lib/solution/VenueBooking/types.js +19 -39
  272. package/lib/solution/VenueBooking/utils/dateSummary.js +27 -56
  273. package/lib/solution/VenueBooking/utils/resource.js +31 -54
  274. package/lib/solution/VenueBooking/utils/slotMerge.js +94 -107
  275. package/lib/solution/VenueBooking/utils/timeSlot.js +132 -132
  276. package/lib/solution/VenueBooking/utils.js +130 -67
  277. package/lib/solution/index.js +124 -41
  278. package/lib/store/createStore.js +32 -29
  279. package/lib/types/index.js +4 -16
  280. package/lib/utils/payment-number.js +26 -46
  281. package/lib/utils/task.js +36 -36
  282. package/lib/utils/watch.js +81 -47
  283. package/package.json +2 -1
@@ -1,52 +1,66 @@
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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ "use strict";
19
2
 
20
- // src/solution/RegisterAndLogin/index.ts
21
- var RegisterAndLogin_exports = {};
22
- __export(RegisterAndLogin_exports, {
23
- RegisterAndLoginImpl: () => RegisterAndLoginImpl
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _exportNames = {
7
+ RegisterAndLoginImpl: true
8
+ };
9
+ exports.RegisterAndLoginImpl = void 0;
10
+ var _BaseModule = require("../../modules/BaseModule");
11
+ var _types = require("./types");
12
+ Object.keys(_types).forEach(function (key) {
13
+ if (key === "default" || key === "__esModule") return;
14
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
15
+ if (key in exports && exports[key] === _types[key]) return;
16
+ Object.defineProperty(exports, key, {
17
+ enumerable: true,
18
+ get: function () {
19
+ return _types[key];
20
+ }
21
+ });
22
+ });
23
+ var _config = require("./config");
24
+ Object.keys(_config).forEach(function (key) {
25
+ if (key === "default" || key === "__esModule") return;
26
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
27
+ if (key in exports && exports[key] === _config[key]) return;
28
+ Object.defineProperty(exports, key, {
29
+ enumerable: true,
30
+ get: function () {
31
+ return _config[key];
32
+ }
33
+ });
24
34
  });
25
- module.exports = __toCommonJS(RegisterAndLogin_exports);
26
- var import_BaseModule = require("../../modules/BaseModule");
27
- var import_types = require("./types");
28
- var import_config = require("./config");
29
- __reExport(RegisterAndLogin_exports, require("./types"), module.exports);
30
- __reExport(RegisterAndLogin_exports, require("./config"), module.exports);
31
- var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
35
+ /**
36
+ * 注册登录解决方案实现
37
+ */
38
+ class RegisterAndLoginImpl extends _BaseModule.BaseModule {
39
+ // 提供给 baseModule 用的默认名称和默认版本
40
+ defaultName = 'registerAndLogin';
41
+ defaultVersion = '1.0.0';
42
+ isSolution = true;
43
+ request;
44
+ window;
45
+ store;
46
+ apiCaller;
47
+ otherParams = {};
48
+ channel = 'default';
49
+
50
+ // 内存缓存
51
+ countriesCache = null;
32
52
  constructor(name, version) {
33
53
  super(name, version);
34
- // 提供给 baseModule 用的默认名称和默认版本
35
- this.defaultName = "registerAndLogin";
36
- this.defaultVersion = "1.0.0";
37
- this.isSolution = true;
38
- this.otherParams = {};
39
- this.channel = "default";
40
- // 内存缓存
41
- this.countriesCache = null;
42
54
  }
55
+
43
56
  /**
44
57
  * 重新发送邮箱注册链接
45
58
  */
46
59
  async resendEmailRegisterLink() {
47
60
  try {
61
+ // 检查是否有保存的 code
48
62
  if (!this.store.emailRegisterLinkCode) {
49
- const error = "没有找到邮箱注册链接的 code,请先调用 sendEmailRegisterLink";
63
+ const error = '没有找到邮箱注册链接的 code,请先调用 sendEmailRegisterLink';
50
64
  this.store.error = error;
51
65
  return {
52
66
  status: false,
@@ -55,43 +69,34 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
55
69
  }
56
70
  this.store.isLoading = true;
57
71
  this.store.error = null;
58
- const response = await this.apiCaller.call(
59
- "resendEmailRegisterLink",
60
- { code: this.store.emailRegisterLinkCode }
61
- );
72
+ const response = await this.apiCaller.call('resendEmailRegisterLink', {
73
+ code: this.store.emailRegisterLinkCode
74
+ });
62
75
  if (response.status) {
63
- await this.core.effects.emit(
64
- import_types.RegisterAndLoginHooks.onEmailVerificationSent,
65
- {
66
- target: "resend",
67
- purpose: import_types.VerificationPurpose.REGISTER
68
- }
69
- );
76
+ await this.core.effects.emit(_types.RegisterAndLoginHooks.onEmailVerificationSent, {
77
+ target: 'resend',
78
+ purpose: _types.VerificationPurpose.REGISTER
79
+ });
70
80
  } else {
71
- this.store.error = response.message || "重新发送注册邀请链接失败";
72
- await this.core.effects.emit(
73
- import_types.RegisterAndLoginHooks.onEmailVerificationFailed,
74
- {
75
- target: "resend",
76
- error: this.store.error
77
- }
78
- );
81
+ this.store.error = response.message || '重新发送注册邀请链接失败';
82
+ await this.core.effects.emit(_types.RegisterAndLoginHooks.onEmailVerificationFailed, {
83
+ target: 'resend',
84
+ error: this.store.error
85
+ });
79
86
  }
80
87
  return response;
81
88
  } catch (error) {
82
- this.store.error = "重新发送注册邀请链接失败";
83
- await this.core.effects.emit(
84
- import_types.RegisterAndLoginHooks.onEmailVerificationFailed,
85
- {
86
- target: "resend",
87
- error: this.store.error
88
- }
89
- );
89
+ this.store.error = '重新发送注册邀请链接失败';
90
+ await this.core.effects.emit(_types.RegisterAndLoginHooks.onEmailVerificationFailed, {
91
+ target: 'resend',
92
+ error: this.store.error
93
+ });
90
94
  return error;
91
95
  } finally {
92
96
  this.store.isLoading = false;
93
97
  }
94
98
  }
99
+
95
100
  /**
96
101
  * 邮箱验证码注册
97
102
  * @param params 注册参数
@@ -101,35 +106,40 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
101
106
  try {
102
107
  this.store.isLoading = true;
103
108
  this.store.error = null;
104
- await this.core.effects.emit(
105
- import_types.RegisterAndLoginHooks.onRegisterStarted,
106
- params
107
- );
108
- const response = await this.apiCaller.call(
109
- "emailCodeRegister",
110
- params
111
- );
109
+ await this.core.effects.emit(_types.RegisterAndLoginHooks.onRegisterStarted, params);
110
+ const response = await this.apiCaller.call('emailCodeRegister', params);
112
111
  if (response.status && response.data) {
113
- const { user, token, refreshToken, expiresAt } = response.data;
112
+ const {
113
+ user,
114
+ token,
115
+ refreshToken,
116
+ expiresAt
117
+ } = response.data;
118
+
119
+ // 如果注册成功并返回了 token,说明可以直接登录
114
120
  if (token) {
115
121
  this.store.currentUser = user;
116
122
  this.store.isLoggedIn = true;
123
+
124
+ // 保存到本地存储
125
+ // this.window.localStorage.setItem('auth_token', token);
126
+ // this.window.localStorage.setItem('user_info', JSON.stringify(user));
127
+ // if (refreshToken) {
128
+ // this.window.localStorage.setItem('refresh_token', refreshToken);
129
+ // }
117
130
  }
118
- await this.core.effects.emit(
119
- import_types.RegisterAndLoginHooks.onRegisterSuccess,
120
- response.data
121
- );
131
+ await this.core.effects.emit(_types.RegisterAndLoginHooks.onRegisterSuccess, response.data);
122
132
  } else {
123
- this.store.error = response.message || "邮箱验证码注册失败";
124
- await this.core.effects.emit(import_types.RegisterAndLoginHooks.onRegisterFailed, {
133
+ this.store.error = response.message || '邮箱验证码注册失败';
134
+ await this.core.effects.emit(_types.RegisterAndLoginHooks.onRegisterFailed, {
125
135
  error: this.store.error,
126
136
  params
127
137
  });
128
138
  }
129
139
  return response;
130
140
  } catch (error) {
131
- this.store.error = "邮箱验证码注册失败";
132
- await this.core.effects.emit(import_types.RegisterAndLoginHooks.onRegisterFailed, {
141
+ this.store.error = '邮箱验证码注册失败';
142
+ await this.core.effects.emit(_types.RegisterAndLoginHooks.onRegisterFailed, {
133
143
  error: this.store.error,
134
144
  params
135
145
  });
@@ -138,6 +148,7 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
138
148
  this.store.isLoading = false;
139
149
  }
140
150
  }
151
+
141
152
  /**
142
153
  * 手机验证码注册
143
154
  */
@@ -145,35 +156,40 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
145
156
  try {
146
157
  this.store.isLoading = true;
147
158
  this.store.error = null;
148
- await this.core.effects.emit(
149
- import_types.RegisterAndLoginHooks.onRegisterStarted,
150
- params
151
- );
152
- const response = await this.apiCaller.call(
153
- "phoneCodeRegister",
154
- params
155
- );
159
+ await this.core.effects.emit(_types.RegisterAndLoginHooks.onRegisterStarted, params);
160
+ const response = await this.apiCaller.call('phoneCodeRegister', params);
156
161
  if (response.status && response.data) {
157
- const { user, token, refreshToken, expiresAt } = response.data;
162
+ const {
163
+ user,
164
+ token,
165
+ refreshToken,
166
+ expiresAt
167
+ } = response.data;
168
+
169
+ // 如果注册成功并返回了 token,说明可以直接登录
158
170
  if (token) {
159
171
  this.store.currentUser = user;
160
172
  this.store.isLoggedIn = true;
173
+
174
+ // 保存到本地存储
175
+ // this.window.localStorage.setItem('auth_token', token);
176
+ // this.window.localStorage.setItem('user_info', JSON.stringify(user));
177
+ // if (refreshToken) {
178
+ // this.window.localStorage.setItem('refresh_token', refreshToken);
179
+ // }
161
180
  }
162
- await this.core.effects.emit(
163
- import_types.RegisterAndLoginHooks.onRegisterSuccess,
164
- response.data
165
- );
181
+ await this.core.effects.emit(_types.RegisterAndLoginHooks.onRegisterSuccess, response.data);
166
182
  } else {
167
- this.store.error = response.message || "注册失败";
168
- await this.core.effects.emit(import_types.RegisterAndLoginHooks.onRegisterFailed, {
183
+ this.store.error = response.message || '注册失败';
184
+ await this.core.effects.emit(_types.RegisterAndLoginHooks.onRegisterFailed, {
169
185
  error: this.store.error,
170
186
  params
171
187
  });
172
188
  }
173
189
  return response;
174
190
  } catch (error) {
175
- this.store.error = error.message || "注册失败";
176
- await this.core.effects.emit(import_types.RegisterAndLoginHooks.onRegisterFailed, {
191
+ this.store.error = error.message || '注册失败';
192
+ await this.core.effects.emit(_types.RegisterAndLoginHooks.onRegisterFailed, {
177
193
  error: this.store.error,
178
194
  params
179
195
  });
@@ -184,6 +200,8 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
184
200
  }
185
201
  async initialize(core, options) {
186
202
  this.core = core;
203
+
204
+ // 初始化状态
187
205
  this.store = {
188
206
  currentUser: null,
189
207
  isLoggedIn: false,
@@ -194,48 +212,58 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
194
212
  ...options.store
195
213
  };
196
214
  this.otherParams = options.otherParams || {};
197
- this.channel = this.otherParams.channel || "default";
198
- this.request = core.getPlugin("request");
199
- this.window = core.getPlugin("window");
215
+
216
+ // 获取渠道信息
217
+ this.channel = this.otherParams.channel || 'default';
218
+
219
+ // 获取依赖的插件
220
+ this.request = core.getPlugin('request');
221
+ this.window = core.getPlugin('window');
200
222
  if (!this.request) {
201
- throw new Error("RegisterAndLogin 模块需要 request 插件支持");
223
+ throw new Error('RegisterAndLogin 模块需要 request 插件支持');
202
224
  }
203
225
  if (!this.window) {
204
- throw new Error("RegisterAndLogin 模块需要 window 插件支持");
226
+ throw new Error('RegisterAndLogin 模块需要 window 插件支持');
205
227
  }
206
- this.apiCaller = (0, import_config.createApiCaller)(this.request, this.channel);
228
+
229
+ // 创建 API 调用器
230
+ this.apiCaller = (0, _config.createApiCaller)(this.request, this.channel);
231
+
232
+ // 尝试从本地存储恢复登录状态
207
233
  await this.restoreLoginState();
234
+
235
+ // 预先调用获取区号的方法,初始内存缓存
208
236
  this.getCountries();
209
- console.log("[RegisterAndLogin] 初始化完成");
210
- await this.core.effects.emit(import_types.RegisterAndLoginHooks.onInited, {});
237
+ await this.core.effects.emit(_types.RegisterAndLoginHooks.onInited, {});
211
238
  }
239
+
212
240
  /**
213
241
  * 从本地存储恢复登录状态
214
242
  */
215
243
  async restoreLoginState() {
216
244
  try {
217
- const token = this.window.localStorage.getItem("auth_token");
218
- const userInfo = this.window.localStorage.getItem("user_info");
245
+ const token = this.window.localStorage.getItem('auth_token');
246
+ const userInfo = this.window.localStorage.getItem('user_info');
219
247
  if (token && userInfo) {
220
248
  const user = JSON.parse(userInfo);
221
249
  this.store.currentUser = user;
222
250
  this.store.isLoggedIn = true;
251
+
252
+ // 验证 token 是否仍然有效
223
253
  await this.validateToken(token);
224
254
  }
225
255
  } catch (error) {
226
- console.warn("[RegisterAndLogin] 恢复登录状态失败:", error);
256
+ console.warn('[RegisterAndLogin] 恢复登录状态失败:', error);
227
257
  this.clearLoginState();
228
258
  }
229
259
  }
260
+
230
261
  /**
231
262
  * 验证 token 有效性
232
263
  */
233
264
  async validateToken(token) {
234
265
  try {
235
- const response = await this.apiCaller.call(
236
- "validateToken",
237
- token
238
- );
266
+ const response = await this.apiCaller.call('validateToken', token);
239
267
  if (response.status && response.data) {
240
268
  this.store.currentUser = response.data;
241
269
  return true;
@@ -244,21 +272,23 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
244
272
  return false;
245
273
  }
246
274
  } catch (error) {
247
- console.warn("[RegisterAndLogin] Token 验证失败:", error);
275
+ console.warn('[RegisterAndLogin] Token 验证失败:', error);
248
276
  this.clearLoginState();
249
277
  return false;
250
278
  }
251
279
  }
280
+
252
281
  /**
253
282
  * 清除登录状态
254
283
  */
255
284
  clearLoginState() {
256
285
  this.store.currentUser = null;
257
286
  this.store.isLoggedIn = false;
258
- this.window.localStorage.removeItem("auth_token");
259
- this.window.localStorage.removeItem("user_info");
260
- this.window.localStorage.removeItem("refresh_token");
287
+ this.window.localStorage.removeItem('auth_token');
288
+ this.window.localStorage.removeItem('user_info');
289
+ this.window.localStorage.removeItem('refresh_token');
261
290
  }
291
+
262
292
  /**
263
293
  * 发送邮箱验证码
264
294
  */
@@ -266,50 +296,39 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
266
296
  try {
267
297
  this.store.isLoading = true;
268
298
  this.store.error = null;
269
- const response = await this.apiCaller.call(
270
- "sendEmailVerificationCode",
271
- params
272
- );
299
+ const response = await this.apiCaller.call('sendEmailVerificationCode', params);
273
300
  if (response.status) {
301
+ // 记录验证码发送状态
274
302
  const now = Date.now();
275
303
  this.store.verificationCodeSent[params.target] = {
276
304
  sent: true,
277
305
  sentAt: now,
278
- expiresAt: now + 5 * 60 * 1e3
279
- // 5分钟过期
306
+ expiresAt: now + 5 * 60 * 1000 // 5分钟过期
280
307
  };
281
- await this.core.effects.emit(
282
- import_types.RegisterAndLoginHooks.onEmailVerificationSent,
283
- {
284
- target: params.target,
285
- purpose: params.purpose
286
- }
287
- );
308
+ await this.core.effects.emit(_types.RegisterAndLoginHooks.onEmailVerificationSent, {
309
+ target: params.target,
310
+ purpose: params.purpose
311
+ });
288
312
  } else {
289
- this.store.error = response.message || "发送验证码失败";
290
- await this.core.effects.emit(
291
- import_types.RegisterAndLoginHooks.onEmailVerificationFailed,
292
- {
293
- target: params.target,
294
- error: this.store.error
295
- }
296
- );
313
+ this.store.error = response.message || '发送验证码失败';
314
+ await this.core.effects.emit(_types.RegisterAndLoginHooks.onEmailVerificationFailed, {
315
+ target: params.target,
316
+ error: this.store.error
317
+ });
297
318
  }
298
319
  return response;
299
320
  } catch (error) {
300
- this.store.error = "发送验证码失败";
301
- await this.core.effects.emit(
302
- import_types.RegisterAndLoginHooks.onEmailVerificationFailed,
303
- {
304
- target: params.target,
305
- error: this.store.error
306
- }
307
- );
321
+ this.store.error = '发送验证码失败';
322
+ await this.core.effects.emit(_types.RegisterAndLoginHooks.onEmailVerificationFailed, {
323
+ target: params.target,
324
+ error: this.store.error
325
+ });
308
326
  return error;
309
327
  } finally {
310
328
  this.store.isLoading = false;
311
329
  }
312
330
  }
331
+
313
332
  /**
314
333
  * 发送邮箱登录验证码
315
334
  */
@@ -317,50 +336,39 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
317
336
  try {
318
337
  this.store.isLoading = true;
319
338
  this.store.error = null;
320
- const response = await this.apiCaller.call(
321
- "sendEmailLoginCode",
322
- params
323
- );
339
+ const response = await this.apiCaller.call('sendEmailLoginCode', params);
324
340
  if (response.status) {
341
+ // 记录验证码发送状态
325
342
  const now = Date.now();
326
343
  this.store.verificationCodeSent[params.target] = {
327
344
  sent: true,
328
345
  sentAt: now,
329
- expiresAt: now + 5 * 60 * 1e3
330
- // 5分钟过期
346
+ expiresAt: now + 5 * 60 * 1000 // 5分钟过期
331
347
  };
332
- await this.core.effects.emit(
333
- import_types.RegisterAndLoginHooks.onEmailVerificationSent,
334
- {
335
- target: params.target,
336
- purpose: params.purpose
337
- }
338
- );
348
+ await this.core.effects.emit(_types.RegisterAndLoginHooks.onEmailVerificationSent, {
349
+ target: params.target,
350
+ purpose: params.purpose
351
+ });
339
352
  } else {
340
- this.store.error = response.message || "发送验证码失败";
341
- await this.core.effects.emit(
342
- import_types.RegisterAndLoginHooks.onEmailVerificationFailed,
343
- {
344
- target: params.target,
345
- error: this.store.error
346
- }
347
- );
353
+ this.store.error = response.message || '发送验证码失败';
354
+ await this.core.effects.emit(_types.RegisterAndLoginHooks.onEmailVerificationFailed, {
355
+ target: params.target,
356
+ error: this.store.error
357
+ });
348
358
  }
349
359
  return response;
350
360
  } catch (error) {
351
- this.store.error = "发送验证码失败";
352
- await this.core.effects.emit(
353
- import_types.RegisterAndLoginHooks.onEmailVerificationFailed,
354
- {
355
- target: params.target,
356
- error: this.store.error
357
- }
358
- );
361
+ this.store.error = '发送验证码失败';
362
+ await this.core.effects.emit(_types.RegisterAndLoginHooks.onEmailVerificationFailed, {
363
+ target: params.target,
364
+ error: this.store.error
365
+ });
359
366
  return error;
360
367
  } finally {
361
368
  this.store.isLoading = false;
362
369
  }
363
370
  }
371
+
364
372
  /**
365
373
  * 发送手机号注册验证码
366
374
  */
@@ -368,105 +376,84 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
368
376
  try {
369
377
  this.store.isLoading = true;
370
378
  this.store.error = null;
371
- const response = await this.apiCaller.call(
372
- "sendSmsRegisterCode",
373
- params
374
- );
379
+ const response = await this.apiCaller.call('sendSmsRegisterCode', params);
375
380
  if (response.status) {
381
+ // 记录验证码发送状态
376
382
  const now = Date.now();
377
383
  this.store.verificationCodeSent[params.phone] = {
378
384
  sent: true,
379
385
  sentAt: now,
380
- expiresAt: now + 5 * 60 * 1e3
381
- // 5分钟过期
386
+ expiresAt: now + 5 * 60 * 1000 // 5分钟过期
382
387
  };
383
- await this.core.effects.emit(
384
- import_types.RegisterAndLoginHooks.onSmsVerificationSent,
385
- {
386
- target: params.phone,
387
- purpose: import_types.VerificationPurpose.REGISTER
388
- }
389
- );
388
+ await this.core.effects.emit(_types.RegisterAndLoginHooks.onSmsVerificationSent, {
389
+ target: params.phone,
390
+ purpose: _types.VerificationPurpose.REGISTER
391
+ });
390
392
  } else {
391
- this.store.error = response.message || "发送注册验证码失败";
392
- await this.core.effects.emit(
393
- import_types.RegisterAndLoginHooks.onSmsVerificationFailed,
394
- {
395
- target: params.phone,
396
- error: this.store.error
397
- }
398
- );
393
+ this.store.error = response.message || '发送注册验证码失败';
394
+ await this.core.effects.emit(_types.RegisterAndLoginHooks.onSmsVerificationFailed, {
395
+ target: params.phone,
396
+ error: this.store.error
397
+ });
399
398
  }
400
399
  return response;
401
400
  } catch (error) {
402
- this.store.error = "发送注册验证码失败";
403
- await this.core.effects.emit(
404
- import_types.RegisterAndLoginHooks.onSmsVerificationFailed,
405
- {
406
- target: params.phone,
407
- error: this.store.error
408
- }
409
- );
401
+ this.store.error = '发送注册验证码失败';
402
+ await this.core.effects.emit(_types.RegisterAndLoginHooks.onSmsVerificationFailed, {
403
+ target: params.phone,
404
+ error: this.store.error
405
+ });
410
406
  return error;
411
407
  } finally {
412
408
  this.store.isLoading = false;
413
409
  }
414
410
  }
411
+
415
412
  /**
416
413
  * 发送邮箱注册邀请链接
417
414
  */
418
415
  async sendEmailRegisterLink(email) {
419
- var _a;
420
416
  try {
421
417
  this.store.isLoading = true;
422
418
  this.store.error = null;
423
- const response = await this.apiCaller.call(
424
- "sendEmailRegisterLink",
425
- email
426
- );
419
+ const response = await this.apiCaller.call('sendEmailRegisterLink', email);
427
420
  if (response.status) {
428
- if ((_a = response.data) == null ? void 0 : _a.code) {
421
+ // 保存返回的 code
422
+ if (response.data?.code) {
429
423
  this.store.emailRegisterLinkCode = response.data.code;
430
424
  }
425
+
426
+ // 记录邀请链接发送状态
431
427
  const now = Date.now();
432
428
  this.store.verificationCodeSent[email] = {
433
429
  sent: true,
434
430
  sentAt: now,
435
- expiresAt: now + 24 * 60 * 60 * 1e3
436
- // 24小时过期
431
+ expiresAt: now + 24 * 60 * 60 * 1000 // 24小时过期
437
432
  };
438
- await this.core.effects.emit(
439
- import_types.RegisterAndLoginHooks.onEmailVerificationSent,
440
- {
441
- target: email,
442
- purpose: import_types.VerificationPurpose.REGISTER
443
- }
444
- );
433
+ await this.core.effects.emit(_types.RegisterAndLoginHooks.onEmailVerificationSent, {
434
+ target: email,
435
+ purpose: _types.VerificationPurpose.REGISTER
436
+ });
445
437
  } else {
446
- this.store.error = response.message || "发送注册邀请链接失败";
447
- await this.core.effects.emit(
448
- import_types.RegisterAndLoginHooks.onEmailVerificationFailed,
449
- {
450
- target: email,
451
- error: this.store.error
452
- }
453
- );
438
+ this.store.error = response.message || '发送注册邀请链接失败';
439
+ await this.core.effects.emit(_types.RegisterAndLoginHooks.onEmailVerificationFailed, {
440
+ target: email,
441
+ error: this.store.error
442
+ });
454
443
  }
455
444
  return response;
456
445
  } catch (error) {
457
- this.store.error = "发送注册邀请链接失败";
458
- await this.core.effects.emit(
459
- import_types.RegisterAndLoginHooks.onEmailVerificationFailed,
460
- {
461
- target: email,
462
- error: this.store.error
463
- }
464
- );
446
+ this.store.error = '发送注册邀请链接失败';
447
+ await this.core.effects.emit(_types.RegisterAndLoginHooks.onEmailVerificationFailed, {
448
+ target: email,
449
+ error: this.store.error
450
+ });
465
451
  return error;
466
452
  } finally {
467
453
  this.store.isLoading = false;
468
454
  }
469
455
  }
456
+
470
457
  /**
471
458
  * 验证邮箱注册链接
472
459
  */
@@ -474,43 +461,32 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
474
461
  try {
475
462
  this.store.isLoading = true;
476
463
  this.store.error = null;
477
- const response = await this.apiCaller.call(
478
- "verifyEmailRegistrationLink",
479
- params
480
- );
464
+ const response = await this.apiCaller.call('verifyEmailRegistrationLink', params);
481
465
  if (response.status) {
482
- await this.core.effects.emit(
483
- import_types.RegisterAndLoginHooks.onEmailVerificationVerified,
484
- {
485
- target: "email-registration-link",
486
- purpose: import_types.VerificationPurpose.REGISTER
487
- }
488
- );
466
+ await this.core.effects.emit(_types.RegisterAndLoginHooks.onEmailVerificationVerified, {
467
+ target: 'email-registration-link',
468
+ purpose: _types.VerificationPurpose.REGISTER
469
+ });
489
470
  } else {
490
- this.store.error = response.message || "邮箱注册链接验证失败";
491
- await this.core.effects.emit(
492
- import_types.RegisterAndLoginHooks.onEmailVerificationFailed,
493
- {
494
- target: "email-registration-link",
495
- error: this.store.error
496
- }
497
- );
471
+ this.store.error = response.message || '邮箱注册链接验证失败';
472
+ await this.core.effects.emit(_types.RegisterAndLoginHooks.onEmailVerificationFailed, {
473
+ target: 'email-registration-link',
474
+ error: this.store.error
475
+ });
498
476
  }
499
477
  return response;
500
478
  } catch (error) {
501
- this.store.error = "邮箱注册链接验证失败";
502
- await this.core.effects.emit(
503
- import_types.RegisterAndLoginHooks.onEmailVerificationFailed,
504
- {
505
- target: "email-registration-link",
506
- error: this.store.error
507
- }
508
- );
479
+ this.store.error = '邮箱注册链接验证失败';
480
+ await this.core.effects.emit(_types.RegisterAndLoginHooks.onEmailVerificationFailed, {
481
+ target: 'email-registration-link',
482
+ error: this.store.error
483
+ });
509
484
  return error;
510
485
  } finally {
511
486
  this.store.isLoading = false;
512
487
  }
513
488
  }
489
+
514
490
  /**
515
491
  * 邮箱密码登录
516
492
  */
@@ -518,45 +494,46 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
518
494
  try {
519
495
  this.store.isLoading = true;
520
496
  this.store.error = null;
521
- await this.core.effects.emit(import_types.RegisterAndLoginHooks.onLoginStarted, {
522
- type: "email-password",
497
+ await this.core.effects.emit(_types.RegisterAndLoginHooks.onLoginStarted, {
498
+ type: 'email-password',
523
499
  email: params.email
524
500
  });
525
- const response = await this.apiCaller.call(
526
- "emailPasswordLogin",
527
- params
528
- );
501
+ const response = await this.apiCaller.call('emailPasswordLogin', params);
529
502
  if (response.status && response.data) {
503
+ // 保存用户信息和 token
530
504
  this.store.isLoggedIn = true;
531
505
  this.store.userInfo = response.data.user;
532
506
  this.store.token = response.data.token;
507
+
508
+ // 如果有 refreshToken,也保存
533
509
  if (response.data.refreshToken) {
534
510
  this.store.refreshToken = response.data.refreshToken;
535
511
  }
536
- await this.core.effects.emit(import_types.RegisterAndLoginHooks.onLoginSuccess, {
512
+ await this.core.effects.emit(_types.RegisterAndLoginHooks.onLoginSuccess, {
537
513
  user: response.data.user,
538
514
  token: response.data.token,
539
- loginType: "email-password"
515
+ loginType: 'email-password'
540
516
  });
541
517
  } else {
542
- this.store.error = response.message || "邮箱密码登录失败";
543
- await this.core.effects.emit(import_types.RegisterAndLoginHooks.onLoginFailed, {
518
+ this.store.error = response.message || '邮箱密码登录失败';
519
+ await this.core.effects.emit(_types.RegisterAndLoginHooks.onLoginFailed, {
544
520
  error: this.store.error,
545
- loginType: "email-password"
521
+ loginType: 'email-password'
546
522
  });
547
523
  }
548
524
  return response;
549
525
  } catch (error) {
550
- this.store.error = "邮箱密码登录失败";
551
- await this.core.effects.emit(import_types.RegisterAndLoginHooks.onLoginFailed, {
526
+ this.store.error = '邮箱密码登录失败';
527
+ await this.core.effects.emit(_types.RegisterAndLoginHooks.onLoginFailed, {
552
528
  error: this.store.error,
553
- loginType: "email-password"
529
+ loginType: 'email-password'
554
530
  });
555
531
  return error;
556
532
  } finally {
557
533
  this.store.isLoading = false;
558
534
  }
559
535
  }
536
+
560
537
  /**
561
538
  * 验证验证码
562
539
  */
@@ -564,19 +541,16 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
564
541
  try {
565
542
  this.store.isLoading = true;
566
543
  this.store.error = null;
567
- const response = await this.apiCaller.call(
568
- "verifyCode",
569
- params
570
- );
544
+ const response = await this.apiCaller.call('verifyCode', params);
571
545
  if (response.status) {
572
- const hookName = params.type === import_types.VerificationCodeType.EMAIL ? import_types.RegisterAndLoginHooks.onEmailVerificationVerified : import_types.RegisterAndLoginHooks.onSmsVerificationVerified;
546
+ const hookName = params.type === _types.VerificationCodeType.EMAIL ? _types.RegisterAndLoginHooks.onEmailVerificationVerified : _types.RegisterAndLoginHooks.onSmsVerificationVerified;
573
547
  await this.core.effects.emit(hookName, {
574
548
  target: params.target,
575
549
  purpose: params.purpose
576
550
  });
577
551
  } else {
578
- this.store.error = response.message || "验证码验证失败";
579
- const hookName = params.type === import_types.VerificationCodeType.EMAIL ? import_types.RegisterAndLoginHooks.onEmailVerificationFailed : import_types.RegisterAndLoginHooks.onSmsVerificationFailed;
552
+ this.store.error = response.message || '验证码验证失败';
553
+ const hookName = params.type === _types.VerificationCodeType.EMAIL ? _types.RegisterAndLoginHooks.onEmailVerificationFailed : _types.RegisterAndLoginHooks.onSmsVerificationFailed;
580
554
  await this.core.effects.emit(hookName, {
581
555
  target: params.target,
582
556
  error: this.store.error
@@ -584,12 +558,13 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
584
558
  }
585
559
  return response;
586
560
  } catch (error) {
587
- this.store.error = "验证码验证失败";
561
+ this.store.error = '验证码验证失败';
588
562
  return error;
589
563
  } finally {
590
564
  this.store.isLoading = false;
591
565
  }
592
566
  }
567
+
593
568
  /**
594
569
  * 用户注册
595
570
  */
@@ -597,35 +572,40 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
597
572
  try {
598
573
  this.store.isLoading = true;
599
574
  this.store.error = null;
600
- await this.core.effects.emit(
601
- import_types.RegisterAndLoginHooks.onRegisterStarted,
602
- params
603
- );
604
- const response = await this.apiCaller.call(
605
- "register",
606
- params
607
- );
575
+ await this.core.effects.emit(_types.RegisterAndLoginHooks.onRegisterStarted, params);
576
+ const response = await this.apiCaller.call('register', params);
608
577
  if (response.status && response.data) {
609
- const { user, token, refreshToken, expiresAt } = response.data;
578
+ const {
579
+ user,
580
+ token,
581
+ refreshToken,
582
+ expiresAt
583
+ } = response.data;
584
+
585
+ // 如果注册成功并返回了 token,说明可以直接登录
610
586
  if (token) {
611
587
  this.store.currentUser = user;
612
588
  this.store.isLoggedIn = true;
589
+
590
+ // 保存到本地存储
591
+ // this.window.localStorage.setItem('auth_token', token);
592
+ // this.window.localStorage.setItem('user_info', JSON.stringify(user));
593
+ // if (refreshToken) {
594
+ // this.window.localStorage.setItem('refresh_token', refreshToken);
595
+ // }
613
596
  }
614
- await this.core.effects.emit(
615
- import_types.RegisterAndLoginHooks.onRegisterSuccess,
616
- response.data
617
- );
597
+ await this.core.effects.emit(_types.RegisterAndLoginHooks.onRegisterSuccess, response.data);
618
598
  } else {
619
- this.store.error = response.message || "注册失败";
620
- await this.core.effects.emit(import_types.RegisterAndLoginHooks.onRegisterFailed, {
599
+ this.store.error = response.message || '注册失败';
600
+ await this.core.effects.emit(_types.RegisterAndLoginHooks.onRegisterFailed, {
621
601
  error: this.store.error,
622
602
  params
623
603
  });
624
604
  }
625
605
  return response;
626
606
  } catch (error) {
627
- this.store.error = "注册失败";
628
- await this.core.effects.emit(import_types.RegisterAndLoginHooks.onRegisterFailed, {
607
+ this.store.error = '注册失败';
608
+ await this.core.effects.emit(_types.RegisterAndLoginHooks.onRegisterFailed, {
629
609
  error: this.store.error,
630
610
  params
631
611
  });
@@ -634,6 +614,7 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
634
614
  this.store.isLoading = false;
635
615
  }
636
616
  }
617
+
637
618
  /**
638
619
  * 用户登录
639
620
  */
@@ -641,33 +622,36 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
641
622
  try {
642
623
  this.store.isLoading = true;
643
624
  this.store.error = null;
644
- await this.core.effects.emit(
645
- import_types.RegisterAndLoginHooks.onLoginStarted,
646
- params
647
- );
648
- const response = await this.apiCaller.call(
649
- "login",
650
- params
651
- );
625
+ await this.core.effects.emit(_types.RegisterAndLoginHooks.onLoginStarted, params);
626
+ const response = await this.apiCaller.call('login', params);
652
627
  if (response.status && response.data) {
653
- const { user, token, refreshToken } = response.data;
628
+ const {
629
+ user,
630
+ token,
631
+ refreshToken
632
+ } = response.data;
654
633
  this.store.currentUser = user;
655
634
  this.store.isLoggedIn = true;
656
- await this.core.effects.emit(
657
- import_types.RegisterAndLoginHooks.onLoginSuccess,
658
- response.data
659
- );
635
+
636
+ // 保存到本地存储
637
+ // this.window.localStorage.setItem('auth_token', token);
638
+ // this.window.localStorage.setItem('user_info', JSON.stringify(user));
639
+ // if (refreshToken) {
640
+ // this.window.localStorage.setItem('refresh_token', refreshToken);
641
+ // }
642
+
643
+ await this.core.effects.emit(_types.RegisterAndLoginHooks.onLoginSuccess, response.data);
660
644
  } else {
661
- this.store.error = response.message || "登录失败";
662
- await this.core.effects.emit(import_types.RegisterAndLoginHooks.onLoginFailed, {
645
+ this.store.error = response.message || '登录失败';
646
+ await this.core.effects.emit(_types.RegisterAndLoginHooks.onLoginFailed, {
663
647
  error: this.store.error,
664
648
  params
665
649
  });
666
650
  }
667
651
  return response;
668
652
  } catch (error) {
669
- this.store.error = "登录失败";
670
- await this.core.effects.emit(import_types.RegisterAndLoginHooks.onLoginFailed, {
653
+ this.store.error = '登录失败';
654
+ await this.core.effects.emit(_types.RegisterAndLoginHooks.onLoginFailed, {
671
655
  error: this.store.error,
672
656
  params
673
657
  });
@@ -676,6 +660,7 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
676
660
  this.store.isLoading = false;
677
661
  }
678
662
  }
663
+
679
664
  /**
680
665
  * OAuth 登录
681
666
  */
@@ -683,30 +668,36 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
683
668
  try {
684
669
  this.store.isLoading = true;
685
670
  this.store.error = null;
686
- await this.core.effects.emit(
687
- import_types.RegisterAndLoginHooks.onOAuthLoginStarted,
688
- params
689
- );
690
- const response = await this.apiCaller.call("oauthLogin", params);
671
+ await this.core.effects.emit(_types.RegisterAndLoginHooks.onOAuthLoginStarted, params);
672
+ const response = await this.apiCaller.call('oauthLogin', params);
691
673
  if (response.status && response.data) {
692
- const { user, token, refreshToken } = response.data;
674
+ const {
675
+ user,
676
+ token,
677
+ refreshToken
678
+ } = response.data;
693
679
  this.store.currentUser = user;
694
680
  this.store.isLoggedIn = true;
695
- await this.core.effects.emit(
696
- import_types.RegisterAndLoginHooks.onOAuthLoginSuccess,
697
- response.data
698
- );
681
+
682
+ // 保存到本地存储
683
+ // this.window.localStorage.setItem('auth_token', token);
684
+ // this.window.localStorage.setItem('user_info', JSON.stringify(user));
685
+ // if (refreshToken) {
686
+ // this.window.localStorage.setItem('refresh_token', refreshToken);
687
+ // }
688
+
689
+ await this.core.effects.emit(_types.RegisterAndLoginHooks.onOAuthLoginSuccess, response.data);
699
690
  } else {
700
- this.store.error = response.message || "OAuth 登录失败";
701
- await this.core.effects.emit(import_types.RegisterAndLoginHooks.onOAuthLoginFailed, {
691
+ this.store.error = response.message || 'OAuth 登录失败';
692
+ await this.core.effects.emit(_types.RegisterAndLoginHooks.onOAuthLoginFailed, {
702
693
  error: this.store.error,
703
694
  params
704
695
  });
705
696
  }
706
697
  return response;
707
698
  } catch (error) {
708
- this.store.error = "OAuth 登录失败";
709
- await this.core.effects.emit(import_types.RegisterAndLoginHooks.onOAuthLoginFailed, {
699
+ this.store.error = 'OAuth 登录失败';
700
+ await this.core.effects.emit(_types.RegisterAndLoginHooks.onOAuthLoginFailed, {
710
701
  error: this.store.error,
711
702
  params
712
703
  });
@@ -715,116 +706,110 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
715
706
  this.store.isLoading = false;
716
707
  }
717
708
  }
709
+
718
710
  /**
719
711
  * 用户登出
720
712
  */
721
713
  async logout() {
722
714
  try {
723
- await this.apiCaller.call("logout");
715
+ // 调用后端登出接口
716
+ await this.apiCaller.call('logout');
724
717
  } catch (error) {
725
- console.warn("[RegisterAndLogin] 登出接口调用失败:", error);
718
+ console.warn('[RegisterAndLogin] 登出接口调用失败:', error);
726
719
  } finally {
720
+ // 无论后端接口是否成功,都清除本地状态
727
721
  this.clearLoginState();
728
722
  }
729
723
  }
724
+
730
725
  /** 发送重置密码邮箱链接 */
731
726
  async sendResetPasswordLink(params) {
732
727
  try {
733
728
  this.store.isLoading = true;
734
729
  this.store.error = null;
735
- const response = await this.apiCaller.call(
736
- "sendResetPasswordLink",
737
- params
738
- );
730
+ const response = await this.apiCaller.call('sendResetPasswordLink', params);
739
731
  if (response.status) {
740
732
  this.store.verificationCodeSent[params.email] = {
741
733
  sent: true,
742
734
  sentAt: Date.now(),
743
- expiresAt: Date.now() + 5 * 60 * 1e3
744
- // 5分钟后过期
735
+ expiresAt: Date.now() + 5 * 60 * 1000 // 5分钟后过期
745
736
  };
746
- this.core.effects.emit(import_types.RegisterAndLoginHooks.onEmailVerificationSent, {
737
+ this.core.effects.emit(_types.RegisterAndLoginHooks.onEmailVerificationSent, {
747
738
  email: params.email,
748
- purpose: "reset-password-link"
739
+ purpose: 'reset-password-link'
749
740
  });
750
741
  } else {
751
- this.store.error = response.message || "发送重置密码链接失败";
742
+ this.store.error = response.message || '发送重置密码链接失败';
752
743
  }
753
744
  return response;
754
745
  } catch (error) {
755
- this.store.error = "发送重置密码链接失败";
746
+ this.store.error = '发送重置密码链接失败';
756
747
  return error;
757
748
  } finally {
758
749
  this.store.isLoading = false;
759
750
  }
760
751
  }
752
+
761
753
  /** 检测重置密码链接code有效性 */
762
754
  async checkResetPasswordCode(params) {
763
755
  try {
764
756
  this.store.isLoading = true;
765
757
  this.store.error = null;
766
- const response = await this.apiCaller.call(
767
- "checkResetPasswordCode",
768
- params
769
- );
758
+ const response = await this.apiCaller.call('checkResetPasswordCode', params);
770
759
  if (!response.status) {
771
- this.store.error = response.message || "验证码无效";
760
+ this.store.error = response.message || '验证码无效';
772
761
  }
773
762
  return response;
774
763
  } catch (error) {
775
- this.store.error = "验证码验证失败";
764
+ this.store.error = '验证码验证失败';
776
765
  return error;
777
766
  } finally {
778
767
  this.store.isLoading = false;
779
768
  }
780
769
  }
770
+
781
771
  /** 校验邮件链接 code 有效性 */
782
772
  async checkEmailLinkCode(params) {
783
773
  try {
784
774
  this.store.isLoading = true;
785
775
  this.store.error = null;
786
- const response = await this.apiCaller.call(
787
- "checkEmailLinkCode",
788
- params
789
- );
776
+ const response = await this.apiCaller.call('checkEmailLinkCode', params);
790
777
  if (!response.status) {
791
- this.store.error = response.message || "邮件链接验证码无效";
778
+ this.store.error = response.message || '邮件链接验证码无效';
792
779
  }
793
780
  return response;
794
781
  } catch (error) {
795
- this.store.error = "邮件链接验证码验证失败";
782
+ this.store.error = '邮件链接验证码验证失败';
796
783
  return error;
797
784
  } finally {
798
785
  this.store.isLoading = false;
799
786
  }
800
787
  }
788
+
801
789
  /** 通过code重置密码 */
802
790
  async resetPasswordByCode(params) {
803
791
  try {
804
792
  this.store.isLoading = true;
805
793
  this.store.error = null;
806
- this.core.effects.emit(import_types.RegisterAndLoginHooks.onPasswordResetStarted, {
794
+ this.core.effects.emit(_types.RegisterAndLoginHooks.onPasswordResetStarted, {
807
795
  code: params.code
808
796
  });
809
- const response = await this.apiCaller.call(
810
- "resetPasswordByCode",
811
- params
812
- );
797
+ const response = await this.apiCaller.call('resetPasswordByCode', params);
813
798
  if (response.status) {
814
- this.core.effects.emit(import_types.RegisterAndLoginHooks.onPasswordResetSuccess, {
799
+ this.core.effects.emit(_types.RegisterAndLoginHooks.onPasswordResetSuccess, {
815
800
  code: params.code
816
801
  });
817
802
  } else {
818
- this.store.error = response.message || "密码重置失败";
819
- this.core.effects.emit(import_types.RegisterAndLoginHooks.onPasswordResetFailed, {
803
+ this.store.error = response.message || '密码重置失败';
804
+ this.core.effects.emit(_types.RegisterAndLoginHooks.onPasswordResetFailed, {
820
805
  code: params.code,
821
806
  error: this.store.error
822
807
  });
823
808
  }
824
809
  return response;
825
810
  } catch (error) {
826
- this.store.error = "密码重置失败";
827
- this.core.effects.emit(import_types.RegisterAndLoginHooks.onPasswordResetFailed, {
811
+ this.store.error = '密码重置失败';
812
+ this.core.effects.emit(_types.RegisterAndLoginHooks.onPasswordResetFailed, {
828
813
  code: params.code,
829
814
  error: this.store.error
830
815
  });
@@ -833,6 +818,7 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
833
818
  this.store.isLoading = false;
834
819
  }
835
820
  }
821
+
836
822
  /**
837
823
  * 重置密码
838
824
  */
@@ -840,65 +826,64 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
840
826
  try {
841
827
  this.store.isLoading = true;
842
828
  this.store.error = null;
843
- if (params.type === "email") {
844
- this.core.effects.emit(import_types.RegisterAndLoginHooks.onPasswordResetStarted, {
829
+
830
+ // 根据类型触发不同的事件
831
+ if (params.type === 'email') {
832
+ this.core.effects.emit(_types.RegisterAndLoginHooks.onPasswordResetStarted, {
845
833
  email: params.target.email
846
834
  });
847
835
  } else {
848
- this.core.effects.emit(import_types.RegisterAndLoginHooks.onPasswordResetStarted, {
836
+ this.core.effects.emit(_types.RegisterAndLoginHooks.onPasswordResetStarted, {
849
837
  phone: params.target.phone
850
838
  });
851
839
  }
852
840
  let response;
853
- if (params.type === "email") {
841
+ if (params.type === 'email') {
842
+ // 邮箱重置密码
854
843
  if (!params.target.email) {
855
- throw new Error("邮箱地址不能为空");
844
+ throw new Error('邮箱地址不能为空');
856
845
  }
857
- response = await this.apiCaller.call(
858
- "resetPasswordByEmail",
859
- {
860
- email: params.target.email,
861
- password: params.password,
862
- code: params.code
863
- }
864
- );
846
+ response = await this.apiCaller.call('resetPasswordByEmail', {
847
+ email: params.target.email,
848
+ password: params.password,
849
+ code: params.code
850
+ });
865
851
  } else {
852
+ // 手机号重置密码
866
853
  if (!params.target.phone || !params.target.country_calling_code) {
867
- throw new Error("手机号和国家区号不能为空");
854
+ throw new Error('手机号和国家区号不能为空');
868
855
  }
869
- response = await this.apiCaller.call(
870
- "resetPasswordByPhone",
871
- {
872
- phone: params.target.phone,
873
- password: params.password,
874
- code: params.code,
875
- country_calling_code: params.target.country_calling_code
876
- }
877
- );
856
+ response = await this.apiCaller.call('resetPasswordByPhone', {
857
+ phone: params.target.phone,
858
+ password: params.password,
859
+ code: params.code,
860
+ country_calling_code: params.target.country_calling_code
861
+ });
878
862
  }
879
863
  if (response.status) {
880
- const key = params.type === "email" ? params.target.email : params.target.phone;
864
+ // 清除验证码发送状态
865
+ const key = params.type === 'email' ? params.target.email : params.target.phone;
881
866
  if (this.store.verificationCodeSent[key]) {
882
867
  delete this.store.verificationCodeSent[key];
883
868
  }
884
- if (params.type === "email") {
885
- this.core.effects.emit(import_types.RegisterAndLoginHooks.onPasswordResetSuccess, {
869
+ if (params.type === 'email') {
870
+ this.core.effects.emit(_types.RegisterAndLoginHooks.onPasswordResetSuccess, {
886
871
  email: params.target.email
887
872
  });
888
873
  } else {
889
- this.core.effects.emit(import_types.RegisterAndLoginHooks.onPasswordResetSuccess, {
874
+ this.core.effects.emit(_types.RegisterAndLoginHooks.onPasswordResetSuccess, {
890
875
  phone: params.target.phone
891
876
  });
892
877
  }
893
878
  } else {
894
- this.store.error = response.message || "密码重置失败";
895
- if (params.type === "email") {
896
- this.core.effects.emit(import_types.RegisterAndLoginHooks.onPasswordResetFailed, {
879
+ this.store.error = response.message || '密码重置失败';
880
+ if (params.type === 'email') {
881
+ this.core.effects.emit(_types.RegisterAndLoginHooks.onPasswordResetFailed, {
897
882
  email: params.target.email,
898
883
  error: this.store.error
899
884
  });
900
885
  } else {
901
- this.core.effects.emit(import_types.RegisterAndLoginHooks.onPasswordResetFailed, {
886
+ this.core.effects.emit(_types.RegisterAndLoginHooks.onPasswordResetFailed, {
902
887
  phone: params.target.phone,
903
888
  error: this.store.error
904
889
  });
@@ -906,14 +891,14 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
906
891
  }
907
892
  return response;
908
893
  } catch (error) {
909
- this.store.error = "密码重置失败";
910
- if (params.type === "email") {
911
- this.core.effects.emit(import_types.RegisterAndLoginHooks.onPasswordResetFailed, {
894
+ this.store.error = '密码重置失败';
895
+ if (params.type === 'email') {
896
+ this.core.effects.emit(_types.RegisterAndLoginHooks.onPasswordResetFailed, {
912
897
  email: params.target.email,
913
898
  error: this.store.error
914
899
  });
915
900
  } else {
916
- this.core.effects.emit(import_types.RegisterAndLoginHooks.onPasswordResetFailed, {
901
+ this.core.effects.emit(_types.RegisterAndLoginHooks.onPasswordResetFailed, {
917
902
  phone: params.target.phone,
918
903
  error: this.store.error
919
904
  });
@@ -923,93 +908,83 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
923
908
  this.store.isLoading = false;
924
909
  }
925
910
  }
911
+
926
912
  /** 发送手机登录验证码 */
927
913
  async sendSmsLoginCode(params) {
928
914
  try {
929
915
  this.store.isLoading = true;
930
916
  this.store.error = null;
931
- const response = await this.apiCaller.call(
932
- "sendSmsLoginCode",
933
- params
934
- );
917
+ const response = await this.apiCaller.call('sendSmsLoginCode', params);
935
918
  if (response.status) {
919
+ // 记录验证码发送状态
936
920
  const now = Date.now();
937
921
  this.store.verificationCodeSent[params.phone] = {
938
922
  sent: true,
939
923
  sentAt: now,
940
- expiresAt: now + 5 * 60 * 1e3
941
- // 5分钟过期
924
+ expiresAt: now + 5 * 60 * 1000 // 5分钟过期
942
925
  };
943
- await this.core.effects.emit(
944
- import_types.RegisterAndLoginHooks.onSmsVerificationSent,
945
- {
946
- target: params.phone,
947
- purpose: import_types.VerificationPurpose.LOGIN
948
- }
949
- );
926
+ await this.core.effects.emit(_types.RegisterAndLoginHooks.onSmsVerificationSent, {
927
+ target: params.phone,
928
+ purpose: _types.VerificationPurpose.LOGIN
929
+ });
950
930
  } else {
951
- this.store.error = response.message || "发送登录验证码失败";
952
- await this.core.effects.emit(
953
- import_types.RegisterAndLoginHooks.onSmsVerificationFailed,
954
- {
955
- target: params.phone,
956
- error: this.store.error
957
- }
958
- );
931
+ this.store.error = response.message || '发送登录验证码失败';
932
+ await this.core.effects.emit(_types.RegisterAndLoginHooks.onSmsVerificationFailed, {
933
+ target: params.phone,
934
+ error: this.store.error
935
+ });
959
936
  }
960
937
  return response;
961
938
  } catch (error) {
962
- this.store.error = "发送登录验证码失败";
963
- await this.core.effects.emit(
964
- import_types.RegisterAndLoginHooks.onSmsVerificationFailed,
965
- {
966
- target: params.phone,
967
- error: this.store.error
968
- }
969
- );
939
+ this.store.error = '发送登录验证码失败';
940
+ await this.core.effects.emit(_types.RegisterAndLoginHooks.onSmsVerificationFailed, {
941
+ target: params.phone,
942
+ error: this.store.error
943
+ });
970
944
  return error;
971
945
  } finally {
972
946
  this.store.isLoading = false;
973
947
  }
974
948
  }
949
+
975
950
  /** 手机号+短信验证码登录 */
976
951
  async phoneCodeLogin(params) {
977
952
  try {
978
953
  this.store.isLoading = true;
979
954
  this.store.error = null;
980
- await this.core.effects.emit(import_types.RegisterAndLoginHooks.onLoginStarted, {
981
- type: "phone-code",
955
+ await this.core.effects.emit(_types.RegisterAndLoginHooks.onLoginStarted, {
956
+ type: 'phone-code',
982
957
  phone: params.phone
983
958
  });
984
- const response = await this.apiCaller.call(
985
- "phoneCodeLogin",
986
- params
987
- );
959
+ const response = await this.apiCaller.call('phoneCodeLogin', params);
988
960
  if (response.status && response.data) {
961
+ // 保存用户信息和 token
989
962
  this.store.isLoggedIn = true;
990
963
  this.store.userInfo = response.data.user;
991
964
  this.store.token = response.data.token;
965
+
966
+ // 如果有 refreshToken,也保存
992
967
  if (response.data.refreshToken) {
993
968
  this.store.refreshToken = response.data.refreshToken;
994
969
  }
995
- await this.core.effects.emit(import_types.RegisterAndLoginHooks.onLoginSuccess, {
970
+ await this.core.effects.emit(_types.RegisterAndLoginHooks.onLoginSuccess, {
996
971
  user: response.data.user,
997
972
  token: response.data.token,
998
- loginType: "phone-code"
973
+ loginType: 'phone-code'
999
974
  });
1000
975
  } else {
1001
- this.store.error = response.message || "手机号验证码登录失败";
1002
- await this.core.effects.emit(import_types.RegisterAndLoginHooks.onLoginFailed, {
976
+ this.store.error = response.message || '手机号验证码登录失败';
977
+ await this.core.effects.emit(_types.RegisterAndLoginHooks.onLoginFailed, {
1003
978
  error: this.store.error,
1004
- loginType: "phone-code"
979
+ loginType: 'phone-code'
1005
980
  });
1006
981
  }
1007
982
  return response;
1008
983
  } catch (error) {
1009
- this.store.error = "手机号验证码登录失败";
1010
- await this.core.effects.emit(import_types.RegisterAndLoginHooks.onLoginFailed, {
984
+ this.store.error = '手机号验证码登录失败';
985
+ await this.core.effects.emit(_types.RegisterAndLoginHooks.onLoginFailed, {
1011
986
  error: this.store.error,
1012
- loginType: "phone-code"
987
+ loginType: 'phone-code'
1013
988
  });
1014
989
  return error;
1015
990
  } finally {
@@ -1017,196 +992,206 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
1017
992
  }
1018
993
  }
1019
994
  formatLoginParams(params) {
995
+ // 获取当前浏览器窗口的 URL
1020
996
  const currentUrl = this.window.location.href;
1021
- let urlObj = new URL(currentUrl || "");
1022
- let source_customer_id = urlObj.searchParams.get("customer");
997
+ // 使用 URL 对象解析 URL
998
+ let urlObj = new URL(currentUrl || '');
999
+ // 获取 customer 参数的值
1000
+ let source_customer_id = urlObj.searchParams.get('customer');
1023
1001
  if (source_customer_id) {
1024
1002
  params.source_customer_id = parseInt(source_customer_id);
1025
1003
  }
1026
1004
  return params;
1027
1005
  }
1006
+
1028
1007
  /** Guest 登录 */
1029
1008
  async guestLogin() {
1030
- var _a, _b;
1031
1009
  try {
1032
1010
  this.store.isLoading = true;
1033
1011
  this.store.error = null;
1034
- this.core.effects.emit(import_types.RegisterAndLoginHooks.onLoginStarted, {
1035
- type: "guest"
1012
+ this.core.effects.emit(_types.RegisterAndLoginHooks.onLoginStarted, {
1013
+ type: 'guest'
1036
1014
  });
1037
- let guestCode = this.window.localStorage.getItem("guest_code") || "";
1015
+ // 匿名登录 code
1016
+ let guestCode = this.window.localStorage.getItem('guest_code') || '';
1038
1017
  let param = {
1039
1018
  login_channel: this.channel
1040
1019
  };
1041
1020
  if (guestCode) {
1042
1021
  param.guest_code = guestCode;
1043
1022
  }
1023
+
1024
+ // 获取邀请id
1044
1025
  param = this.formatLoginParams(param);
1045
- const response = await this.apiCaller.call("guestLogin", param);
1026
+ const response = await this.apiCaller.call('guestLogin', param);
1046
1027
  if (response.status && response.data) {
1028
+ // 保存用户信息和 token
1047
1029
  this.store.isLoggedIn = true;
1048
1030
  this.store.userInfo = response.data.user;
1049
1031
  this.store.token = response.data.token;
1032
+
1033
+ // 如果有 refreshToken,也保存
1050
1034
  if (response.data.refreshToken) {
1051
1035
  this.store.refreshToken = response.data.refreshToken;
1052
1036
  }
1053
- if ((_b = (_a = response.data) == null ? void 0 : _a.customer) == null ? void 0 : _b.guest_code) {
1054
- this.window.localStorage.setItem("guest_code", response.data.customer.guest_code);
1037
+
1038
+ // 设置匿名登录code
1039
+ if (response.data?.customer?.guest_code) {
1040
+ this.window.localStorage.setItem('guest_code', response.data.customer.guest_code);
1055
1041
  }
1056
- this.core.effects.emit(import_types.RegisterAndLoginHooks.onLoginSuccess, {
1042
+ this.core.effects.emit(_types.RegisterAndLoginHooks.onLoginSuccess, {
1057
1043
  user: response.data.user,
1058
1044
  token: response.data.token,
1059
- loginType: "guest"
1045
+ loginType: 'guest'
1060
1046
  });
1061
1047
  } else {
1062
- this.store.error = response.message || "Guest 登录失败";
1063
- this.core.effects.emit(import_types.RegisterAndLoginHooks.onLoginFailed, {
1048
+ this.store.error = response.message || 'Guest 登录失败';
1049
+ this.core.effects.emit(_types.RegisterAndLoginHooks.onLoginFailed, {
1064
1050
  error: this.store.error,
1065
- loginType: "guest"
1051
+ loginType: 'guest'
1066
1052
  });
1067
1053
  }
1068
1054
  return response;
1069
1055
  } catch (error) {
1070
- this.store.error = "Guest 登录失败";
1071
- this.core.effects.emit(import_types.RegisterAndLoginHooks.onLoginFailed, {
1056
+ this.store.error = 'Guest 登录失败';
1057
+ this.core.effects.emit(_types.RegisterAndLoginHooks.onLoginFailed, {
1072
1058
  error: this.store.error,
1073
- loginType: "guest"
1059
+ loginType: 'guest'
1074
1060
  });
1075
1061
  return error;
1076
1062
  } finally {
1077
1063
  this.store.isLoading = false;
1078
1064
  }
1079
1065
  }
1066
+
1080
1067
  /** 检查邮箱是否已注册 */
1081
1068
  async checkEmailExists(params) {
1082
1069
  try {
1083
1070
  this.store.isLoading = true;
1084
1071
  this.store.error = null;
1085
- const response = await this.apiCaller.call("checkEmailExists", params);
1072
+ const response = await this.apiCaller.call('checkEmailExists', params);
1086
1073
  if (!response.status) {
1087
- this.store.error = response.message || "检查邮箱失败";
1074
+ this.store.error = response.message || '检查邮箱失败';
1088
1075
  }
1089
1076
  return response;
1090
1077
  } catch (error) {
1091
- this.store.error = "检查邮箱失败";
1078
+ this.store.error = '检查邮箱失败';
1092
1079
  return error;
1093
1080
  } finally {
1094
1081
  this.store.isLoading = false;
1095
1082
  }
1096
1083
  }
1084
+
1097
1085
  /** 检查邮箱验证码是否有效 */
1098
1086
  async checkEmailCode(params) {
1099
1087
  try {
1100
1088
  this.store.isLoading = true;
1101
1089
  this.store.error = null;
1102
- const response = await this.apiCaller.call("checkEmailCode", params);
1090
+ const response = await this.apiCaller.call('checkEmailCode', params);
1103
1091
  if (!response.status) {
1104
- this.store.error = response.message || "检查邮箱验证码失败";
1092
+ this.store.error = response.message || '检查邮箱验证码失败';
1105
1093
  }
1106
1094
  return response;
1107
1095
  } catch (error) {
1108
- this.store.error = "检查邮箱验证码失败";
1096
+ this.store.error = '检查邮箱验证码失败';
1109
1097
  return error;
1110
1098
  } finally {
1111
1099
  this.store.isLoading = false;
1112
1100
  }
1113
1101
  }
1102
+
1114
1103
  /** 检查手机验证码是否有效 */
1115
1104
  async checkMobileCode(params) {
1116
1105
  try {
1117
1106
  this.store.isLoading = true;
1118
1107
  this.store.error = null;
1119
- const response = await this.apiCaller.call("checkMobileCode", params);
1108
+ const response = await this.apiCaller.call('checkMobileCode', params);
1120
1109
  if (!response.status) {
1121
- this.store.error = response.message || "检查手机验证码失败";
1110
+ this.store.error = response.message || '检查手机验证码失败';
1122
1111
  }
1123
1112
  return response;
1124
1113
  } catch (error) {
1125
- this.store.error = "检查手机验证码失败";
1114
+ this.store.error = '检查手机验证码失败';
1126
1115
  return error;
1127
1116
  } finally {
1128
1117
  this.store.isLoading = false;
1129
1118
  }
1130
1119
  }
1120
+
1131
1121
  /** 手机号密码登录 */
1132
1122
  async phonePasswordLogin(params) {
1133
1123
  try {
1134
1124
  this.store.isLoading = true;
1135
1125
  this.store.error = null;
1136
- this.core.effects.emit(import_types.RegisterAndLoginHooks.onLoginStarted, {
1137
- type: "phone-password",
1126
+ this.core.effects.emit(_types.RegisterAndLoginHooks.onLoginStarted, {
1127
+ type: 'phone-password',
1138
1128
  phone: params.phone
1139
1129
  });
1140
- const response = await this.apiCaller.call(
1141
- "phonePasswordLogin",
1142
- params
1143
- );
1130
+ const response = await this.apiCaller.call('phonePasswordLogin', params);
1144
1131
  if (response.status && response.data) {
1132
+ // 保存用户信息和 token
1145
1133
  this.store.isLoggedIn = true;
1146
1134
  this.store.userInfo = response.data.user;
1147
1135
  this.store.token = response.data.token;
1136
+
1137
+ // 如果有 refreshToken,也保存
1148
1138
  if (response.data.refreshToken) {
1149
1139
  this.store.refreshToken = response.data.refreshToken;
1150
1140
  }
1151
- this.core.effects.emit(import_types.RegisterAndLoginHooks.onLoginSuccess, {
1141
+ this.core.effects.emit(_types.RegisterAndLoginHooks.onLoginSuccess, {
1152
1142
  user: response.data.user,
1153
1143
  token: response.data.token,
1154
- loginType: "phone-password"
1144
+ loginType: 'phone-password'
1155
1145
  });
1156
1146
  } else {
1157
- this.store.error = response.message || "手机号密码登录失败";
1158
- this.core.effects.emit(import_types.RegisterAndLoginHooks.onLoginFailed, {
1147
+ this.store.error = response.message || '手机号密码登录失败';
1148
+ this.core.effects.emit(_types.RegisterAndLoginHooks.onLoginFailed, {
1159
1149
  error: this.store.error,
1160
- loginType: "phone-password"
1150
+ loginType: 'phone-password'
1161
1151
  });
1162
1152
  }
1163
1153
  return response;
1164
1154
  } catch (error) {
1165
- this.store.error = "手机号密码登录失败";
1166
- this.core.effects.emit(import_types.RegisterAndLoginHooks.onLoginFailed, {
1155
+ this.store.error = '手机号密码登录失败';
1156
+ this.core.effects.emit(_types.RegisterAndLoginHooks.onLoginFailed, {
1167
1157
  error: this.store.error,
1168
- loginType: "phone-password"
1158
+ loginType: 'phone-password'
1169
1159
  });
1170
1160
  return error;
1171
1161
  } finally {
1172
1162
  this.store.isLoading = false;
1173
1163
  }
1174
1164
  }
1165
+
1175
1166
  /** 发送密码重置邮箱验证码 */
1176
1167
  async sendPasswordResetEmail(params) {
1177
1168
  try {
1178
1169
  this.store.isLoading = true;
1179
1170
  this.store.error = null;
1180
- const response = await this.apiCaller.call(
1181
- "sendPasswordResetEmail",
1182
- params
1183
- );
1171
+ const response = await this.apiCaller.call('sendPasswordResetEmail', params);
1184
1172
  if (response.status) {
1173
+ // 记录验证码发送状态
1185
1174
  const now = Date.now();
1186
1175
  this.store.verificationCodeSent[params.email] = {
1187
1176
  sent: true,
1188
1177
  sentAt: now,
1189
- expiresAt: now + 10 * 60 * 1e3
1190
- // 10分钟过期
1178
+ expiresAt: now + 10 * 60 * 1000 // 10分钟过期
1191
1179
  };
1192
- this.core.effects.emit(import_types.RegisterAndLoginHooks.onEmailVerificationSent, {
1180
+ this.core.effects.emit(_types.RegisterAndLoginHooks.onEmailVerificationSent, {
1193
1181
  target: params.email,
1194
- purpose: import_types.VerificationPurpose.PASSWORD_RESET
1182
+ purpose: _types.VerificationPurpose.PASSWORD_RESET
1195
1183
  });
1196
1184
  } else {
1197
- this.store.error = response.message || "发送密码重置验证码失败";
1198
- this.core.effects.emit(
1199
- import_types.RegisterAndLoginHooks.onEmailVerificationFailed,
1200
- {
1201
- target: params.email,
1202
- error: this.store.error
1203
- }
1204
- );
1185
+ this.store.error = response.message || '发送密码重置验证码失败';
1186
+ this.core.effects.emit(_types.RegisterAndLoginHooks.onEmailVerificationFailed, {
1187
+ target: params.email,
1188
+ error: this.store.error
1189
+ });
1205
1190
  }
1206
1191
  return response;
1207
1192
  } catch (error) {
1208
- this.store.error = "发送密码重置验证码失败";
1209
- this.core.effects.emit(import_types.RegisterAndLoginHooks.onEmailVerificationFailed, {
1193
+ this.store.error = '发送密码重置验证码失败';
1194
+ this.core.effects.emit(_types.RegisterAndLoginHooks.onEmailVerificationFailed, {
1210
1195
  target: params.email,
1211
1196
  error: this.store.error
1212
1197
  });
@@ -1215,58 +1200,62 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
1215
1200
  this.store.isLoading = false;
1216
1201
  }
1217
1202
  }
1203
+
1218
1204
  /** 发送手机号验证码重置密码 */
1219
1205
  async sendPasswordResetSms(params) {
1220
1206
  try {
1221
1207
  this.store.isLoading = true;
1222
1208
  this.store.error = null;
1223
- const response = await this.apiCaller.call(
1224
- "sendPasswordResetSms",
1225
- params
1226
- );
1209
+ const response = await this.apiCaller.call('sendPasswordResetSms', params);
1227
1210
  if (response.status) {
1228
1211
  return response;
1229
1212
  } else {
1230
- this.store.error = response.message || "发送手机号验证码重置密码失败";
1213
+ this.store.error = response.message || '发送手机号验证码重置密码失败';
1231
1214
  }
1232
1215
  return response;
1233
1216
  } catch (error) {
1234
- this.store.error = "发送手机号验证码重置密码失败";
1217
+ this.store.error = '发送手机号验证码重置密码失败';
1235
1218
  return error;
1236
1219
  } finally {
1237
1220
  this.store.isLoading = false;
1238
1221
  }
1239
1222
  }
1223
+
1240
1224
  /**
1241
1225
  * 获取当前用户信息
1242
1226
  */
1243
1227
  getCurrentUser() {
1244
1228
  return this.store.currentUser;
1245
1229
  }
1230
+
1246
1231
  /**
1247
1232
  * 检查是否已登录
1248
1233
  */
1249
1234
  isLoggedIn() {
1250
1235
  return this.store.isLoggedIn;
1251
1236
  }
1237
+
1252
1238
  /**
1253
1239
  * 获取加载状态
1254
1240
  */
1255
1241
  isLoading() {
1256
1242
  return this.store.isLoading;
1257
1243
  }
1244
+
1258
1245
  /**
1259
1246
  * 获取错误信息
1260
1247
  */
1261
1248
  getError() {
1262
1249
  return this.store.error;
1263
1250
  }
1251
+
1264
1252
  /**
1265
1253
  * 清除错误信息
1266
1254
  */
1267
1255
  clearError() {
1268
1256
  this.store.error = null;
1269
1257
  }
1258
+
1270
1259
  /**
1271
1260
  * 检查验证码是否已发送且未过期
1272
1261
  */
@@ -1277,6 +1266,7 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
1277
1266
  }
1278
1267
  return Date.now() < codeInfo.expiresAt;
1279
1268
  }
1269
+
1280
1270
  /**
1281
1271
  * 获取验证码剩余时间(秒)
1282
1272
  */
@@ -1286,207 +1276,203 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
1286
1276
  return 0;
1287
1277
  }
1288
1278
  const remaining = Math.max(0, codeInfo.expiresAt - Date.now());
1289
- return Math.ceil(remaining / 1e3);
1279
+ return Math.ceil(remaining / 1000);
1290
1280
  }
1281
+
1291
1282
  /**
1292
1283
  * 初始化 Facebook SDK
1293
1284
  */
1294
1285
  async initFacebookSDK(token) {
1286
+ // const config = this.store.oauthConfig[OAuthProvider.FACEBOOK];
1287
+ // if (!config) {
1288
+ // throw new Error('Facebook OAuth 配置未找到');
1289
+ // }
1290
+
1295
1291
  return new Promise((resolve, reject) => {
1296
- if (typeof window === "undefined") {
1297
- reject(new Error("Facebook SDK 只能在浏览器环境中使用"));
1292
+ if (typeof window === 'undefined') {
1293
+ reject(new Error('Facebook SDK 只能在浏览器环境中使用'));
1298
1294
  return;
1299
1295
  }
1296
+
1297
+ // 检查是否已经加载
1300
1298
  if (window.FB) {
1301
1299
  resolve();
1302
1300
  return;
1303
1301
  }
1304
- const script = document.createElement("script");
1305
- script.src = "https://connect.facebook.net/en_US/sdk.js";
1302
+
1303
+ // 动态加载 Facebook SDK
1304
+ const script = document.createElement('script');
1305
+ script.src = 'https://connect.facebook.net/en_US/sdk.js';
1306
1306
  script.async = true;
1307
1307
  script.defer = true;
1308
- script.crossOrigin = "anonymous";
1308
+ script.crossOrigin = 'anonymous';
1309
1309
  script.onload = () => {
1310
1310
  window.FB.init({
1311
1311
  appId: token,
1312
1312
  cookie: true,
1313
1313
  xfbml: true,
1314
- version: "v18.0"
1314
+ version: 'v18.0'
1315
1315
  });
1316
1316
  resolve();
1317
1317
  };
1318
1318
  script.onerror = () => {
1319
- reject(new Error("Facebook SDK 加载失败"));
1319
+ reject(new Error('Facebook SDK 加载失败'));
1320
1320
  };
1321
1321
  document.head.appendChild(script);
1322
1322
  });
1323
1323
  }
1324
+
1324
1325
  /**
1325
1326
  * 初始化 Apple SDK
1326
1327
  */
1327
1328
  async initAppleSDK() {
1328
1329
  return new Promise((resolve, reject) => {
1329
- if (typeof window === "undefined") {
1330
- reject(new Error("Apple SDK 只能在浏览器环境中使用"));
1330
+ if (typeof window === 'undefined') {
1331
+ reject(new Error('Apple SDK 只能在浏览器环境中使用'));
1331
1332
  return;
1332
1333
  }
1334
+
1335
+ // 检查是否已经加载
1333
1336
  if (window.AppleID) {
1334
1337
  resolve();
1335
1338
  return;
1336
1339
  }
1337
- const script = document.createElement("script");
1338
- script.src = "https://file.mypisell-dev.com/static/apple.js";
1340
+
1341
+ // 动态加载 Apple SDK
1342
+ const script = document.createElement('script');
1343
+ script.src = 'https://file.mypisell-dev.com/static/apple.js';
1339
1344
  script.async = true;
1340
1345
  script.defer = true;
1341
- script.crossOrigin = "anonymous";
1346
+ script.crossOrigin = 'anonymous';
1342
1347
  script.onload = () => {
1348
+ // Apple SDK 加载完成后,需要等待一下确保 AppleID 对象可用
1343
1349
  setTimeout(() => {
1344
1350
  if (window.AppleID) {
1345
1351
  resolve();
1346
1352
  } else {
1347
- reject(new Error("Apple SDK 加载失败:AppleID 对象不可用"));
1353
+ reject(new Error('Apple SDK 加载失败:AppleID 对象不可用'));
1348
1354
  }
1349
1355
  }, 100);
1350
1356
  };
1351
1357
  script.onerror = () => {
1352
- reject(new Error("Apple SDK 加载失败"));
1358
+ reject(new Error('Apple SDK 加载失败'));
1353
1359
  };
1354
1360
  document.head.appendChild(script);
1355
1361
  });
1356
1362
  }
1363
+
1357
1364
  /**
1358
1365
  * Facebook 登录
1359
1366
  */
1360
1367
  async loginWithFacebook(token) {
1361
- console.log("[RegisterAndLogin] Facebook 登录开始", {
1362
- tokenLength: (token == null ? void 0 : token.length) || 0,
1363
- timestamp: Date.now()
1364
- });
1365
1368
  await this.initFacebookSDK(token);
1366
- console.log("[RegisterAndLogin] Facebook SDK 初始化完成,准备调用 FB.login");
1367
1369
  return new Promise((resolve, reject) => {
1368
- console.log("[RegisterAndLogin] 调用 FB.login", {
1369
- scope: "email,public_profile"
1370
- });
1371
- window.FB.login(
1372
- async (response) => {
1373
- console.log("[RegisterAndLogin] FB.login 回调触发", {
1374
- hasAuthResponse: Boolean(response == null ? void 0 : response.authResponse),
1375
- status: response == null ? void 0 : response.status
1376
- });
1377
- if (response.authResponse) {
1378
- try {
1379
- console.log("[RegisterAndLogin] 调用后端 facebookLogin 接口");
1380
- const result = await this.apiCaller.call("facebookLogin", {
1381
- token: response.authResponse.accessToken
1382
- });
1383
- console.log("[RegisterAndLogin] facebookLogin 接口返回成功", {
1384
- hasResult: Boolean(result)
1385
- });
1386
- resolve(result);
1387
- } catch (error) {
1388
- console.error("[RegisterAndLogin] facebookLogin 接口调用失败", error);
1389
- reject(error);
1390
- }
1391
- } else {
1392
- console.warn("[RegisterAndLogin] FB.login 用户取消授权或无 authResponse", response);
1393
- reject(new Error("facebook_login_cancel"));
1370
+ window.FB.login(async response => {
1371
+ if (response.authResponse) {
1372
+ try {
1373
+ // 直接调用 /auth/facebook/login 接口
1374
+
1375
+ const result = await this.apiCaller.call('facebookLogin', {
1376
+ token: response.authResponse.accessToken
1377
+ });
1378
+ resolve(result);
1379
+ } catch (error) {
1380
+ console.error('[RegisterAndLogin] facebookLogin 接口调用失败', error);
1381
+ reject(error);
1394
1382
  }
1395
- },
1396
- { scope: "email,public_profile" }
1397
- );
1383
+ } else {
1384
+ console.warn('[RegisterAndLogin] FB.login 用户取消授权或无 authResponse', response);
1385
+ reject(new Error('facebook_login_cancel'));
1386
+ }
1387
+ }, {
1388
+ scope: 'email,public_profile'
1389
+ });
1398
1390
  });
1399
1391
  }
1392
+
1400
1393
  /**
1401
1394
  * Apple 登录(需要在支持的环境中使用)
1402
1395
  */
1403
1396
  async loginWithApple(token) {
1404
- console.log("[RegisterAndLogin] Apple 登录开始", {
1405
- tokenLength: (token == null ? void 0 : token.length) || 0,
1406
- timestamp: Date.now()
1407
- });
1397
+ // 先加载 Apple SDK
1398
+
1408
1399
  await this.initAppleSDK();
1409
- console.log("[RegisterAndLogin] Apple SDK 初始化完成");
1410
1400
  return new Promise((resolve, reject) => {
1411
- var _a, _b, _c, _d;
1412
1401
  try {
1413
- console.log("[RegisterAndLogin] 创建临时 Apple SignIn 按钮节点");
1414
- const appleSignInDiv = document.createElement("div");
1415
- appleSignInDiv.id = "appleid-signin-temp";
1416
- appleSignInDiv.setAttribute("data-color", "black");
1417
- appleSignInDiv.setAttribute("data-border", "false");
1418
- appleSignInDiv.setAttribute("data-type", "sign-in");
1419
- appleSignInDiv.setAttribute("data-mode", "logo-only");
1420
- appleSignInDiv.setAttribute("data-logo-size", "small");
1421
- appleSignInDiv.style.opacity = "0";
1422
- appleSignInDiv.style.position = "absolute";
1423
- appleSignInDiv.style.left = "-9999px";
1424
- appleSignInDiv.style.top = "-9999px";
1425
- appleSignInDiv.style.width = "1px";
1426
- appleSignInDiv.style.height = "1px";
1402
+ // 动态创建 Apple 登录按钮元素
1403
+
1404
+ const appleSignInDiv = document.createElement('div');
1405
+ appleSignInDiv.id = 'appleid-signin-temp';
1406
+ appleSignInDiv.setAttribute('data-color', 'black');
1407
+ appleSignInDiv.setAttribute('data-border', 'false');
1408
+ appleSignInDiv.setAttribute('data-type', 'sign-in');
1409
+ appleSignInDiv.setAttribute('data-mode', 'logo-only');
1410
+ appleSignInDiv.setAttribute('data-logo-size', 'small');
1411
+ appleSignInDiv.style.opacity = '0';
1412
+ appleSignInDiv.style.position = 'absolute';
1413
+ appleSignInDiv.style.left = '-9999px';
1414
+ appleSignInDiv.style.top = '-9999px';
1415
+ appleSignInDiv.style.width = '1px';
1416
+ appleSignInDiv.style.height = '1px';
1417
+
1418
+ // 将元素添加到 body 中
1427
1419
  document.body.appendChild(appleSignInDiv);
1428
- console.log("[RegisterAndLogin] Apple SignIn 按钮已添加到文档");
1429
- if ((_b = (_a = window.AppleID) == null ? void 0 : _a.auth) == null ? void 0 : _b.init) {
1430
- console.log("[RegisterAndLogin] 调用 AppleID.auth.init");
1420
+ // 初始化 Apple ID 按钮
1421
+ if (window.AppleID?.auth?.init) {
1431
1422
  window.AppleID.auth.init({
1432
1423
  clientId: token,
1433
1424
  // 使用传入的 token 作为 clientId
1434
- scope: "name email",
1425
+ scope: 'name email',
1435
1426
  redirectURI: window.location.origin,
1436
- state: "signin",
1427
+ state: 'signin',
1437
1428
  usePopup: true
1438
1429
  });
1439
1430
  } else {
1440
- console.warn("[RegisterAndLogin] AppleID.auth.init 方法不可用");
1431
+ console.warn('[RegisterAndLogin] AppleID.auth.init 方法不可用');
1441
1432
  }
1442
- if ((_d = (_c = window.AppleID) == null ? void 0 : _c.auth) == null ? void 0 : _d.signIn) {
1443
- console.log("[RegisterAndLogin] 调用 AppleID.auth.signIn");
1444
- window.AppleID.auth.signIn().then(async (authResult) => {
1445
- var _a2, _b2;
1433
+
1434
+ // 直接调用 Apple ID 登录,并处理 Promise
1435
+ if (window.AppleID?.auth?.signIn) {
1436
+ window.AppleID.auth.signIn().then(async authResult => {
1446
1437
  try {
1438
+ // 清理临时元素
1447
1439
  if (document.body.contains(appleSignInDiv)) {
1448
1440
  document.body.removeChild(appleSignInDiv);
1449
1441
  }
1450
- console.log("[RegisterAndLogin] Apple SignIn 成功,临时节点已移除", {
1451
- hasAuthorization: Boolean(authResult == null ? void 0 : authResult.authorization),
1452
- hasUser: Boolean(authResult == null ? void 0 : authResult.user)
1453
- });
1454
- const authorizationCode = (_a2 = authResult.authorization) == null ? void 0 : _a2.code;
1455
- const identityToken = (_b2 = authResult.authorization) == null ? void 0 : _b2.id_token;
1456
- console.log("[RegisterAndLogin] Apple 授权结果解析", {
1457
- hasAuthorizationCode: Boolean(authorizationCode),
1458
- hasIdentityToken: Boolean(identityToken)
1459
- });
1460
- console.log("[RegisterAndLogin] 调用后端 appleLogin 接口");
1461
- const result = await this.apiCaller.call("appleLogin", {
1442
+ // 获取授权码或令牌
1443
+ const authorizationCode = authResult.authorization?.code;
1444
+ const identityToken = authResult.authorization?.id_token;
1445
+
1446
+ // 使用授权码或身份令牌调用后端接口
1447
+
1448
+ const result = await this.apiCaller.call('appleLogin', {
1462
1449
  code: identityToken || authorizationCode,
1463
1450
  login_channel: this.channel
1464
1451
  });
1465
- console.log("[RegisterAndLogin] appleLogin 接口返回成功", {
1466
- hasResult: Boolean(result)
1467
- });
1468
1452
  resolve(result);
1469
1453
  } catch (error) {
1470
- console.error("[RegisterAndLogin] 处理 Apple 登录结果失败", error);
1454
+ console.error('[RegisterAndLogin] 处理 Apple 登录结果失败', error);
1471
1455
  reject(error);
1472
1456
  }
1473
- }).catch((error) => {
1457
+ }).catch(error => {
1458
+ // 清理临时元素
1474
1459
  if (document.body.contains(appleSignInDiv)) {
1475
1460
  document.body.removeChild(appleSignInDiv);
1476
1461
  }
1477
- console.error("[RegisterAndLogin] Apple SignIn Promise 拒绝", error);
1478
- reject(new Error("Apple 登录失败: " + ((error == null ? void 0 : error.error) || (error == null ? void 0 : error.message) || "未知错误")));
1462
+ console.error('[RegisterAndLogin] Apple SignIn Promise 拒绝', error);
1463
+ reject(new Error('Apple 登录失败: ' + (error?.error || error?.message || '未知错误')));
1479
1464
  });
1480
1465
  } else {
1481
- console.error("[RegisterAndLogin] AppleID.auth.signIn 方法不可用");
1482
- reject(new Error("Apple SDK 未正确加载"));
1466
+ console.error('[RegisterAndLogin] AppleID.auth.signIn 方法不可用');
1467
+ reject(new Error('Apple SDK 未正确加载'));
1483
1468
  }
1484
1469
  } catch (error) {
1485
- console.error("[RegisterAndLogin] Apple 登录流程异常", error);
1470
+ console.error('[RegisterAndLogin] Apple 登录流程异常', error);
1486
1471
  reject(error);
1487
1472
  }
1488
1473
  });
1489
1474
  }
1475
+
1490
1476
  /**
1491
1477
  * 更新 OAuth 配置
1492
1478
  */
@@ -1496,30 +1482,37 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
1496
1482
  ...config
1497
1483
  };
1498
1484
  }
1485
+
1499
1486
  /**
1500
1487
  * 获取当前渠道
1501
1488
  */
1502
1489
  getCurrentChannel() {
1503
1490
  return this.channel;
1504
1491
  }
1492
+
1505
1493
  /**
1506
1494
  * 获取 API 调用器(用于高级用法)
1507
1495
  */
1508
1496
  getApiCaller() {
1509
1497
  return this.apiCaller;
1510
1498
  }
1499
+
1511
1500
  /**
1512
1501
  * 获取国家区号列表
1513
1502
  */
1514
1503
  async getCountries() {
1515
- const CACHE_KEY = "pisell_countries_cache";
1504
+ const CACHE_KEY = 'pisell_countries_cache';
1516
1505
  try {
1517
1506
  this.store.isLoading = true;
1518
1507
  this.store.error = null;
1508
+
1509
+ // 1. 检查内存缓存
1519
1510
  if (this.countriesCache) {
1520
1511
  this.store.isLoading = false;
1521
1512
  return this.countriesCache;
1522
1513
  }
1514
+
1515
+ // 2. 检查 localStorage 缓存
1523
1516
  let cachedData = null;
1524
1517
  try {
1525
1518
  const cached = this.window.localStorage.getItem(CACHE_KEY);
@@ -1527,67 +1520,77 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
1527
1520
  cachedData = JSON.parse(cached);
1528
1521
  }
1529
1522
  } catch (error) {
1530
- console.warn("[RegisterAndLogin] localStorage 缓存解析失败:", error);
1523
+ console.warn('[RegisterAndLogin] localStorage 缓存解析失败:', error);
1531
1524
  }
1525
+
1526
+ // 3. 如果有 localStorage 缓存,先返回缓存数据
1532
1527
  if (cachedData && Array.isArray(cachedData) && cachedData.length > 0) {
1528
+ // 设置内存缓存
1533
1529
  this.countriesCache = cachedData;
1530
+
1531
+ // 异步请求后端数据进行对比和更新
1534
1532
  this.updateCountriesCache(CACHE_KEY, cachedData);
1535
1533
  this.store.isLoading = false;
1536
1534
  return cachedData;
1537
1535
  }
1538
- const response = await this.apiCaller.call("getCountries");
1536
+
1537
+ // 4. 没有缓存,直接请求后端
1538
+ const response = await this.apiCaller.call('getCountries');
1539
1539
  if (response.status && response.data) {
1540
1540
  const countries = response.data;
1541
+
1542
+ // 更新内存缓存
1541
1543
  this.countriesCache = countries;
1544
+
1545
+ // 更新 localStorage 缓存
1542
1546
  try {
1543
1547
  localStorage.setItem(CACHE_KEY, JSON.stringify(countries));
1544
1548
  } catch (error) {
1545
- console.warn("[RegisterAndLogin] localStorage 存储失败:", error);
1549
+ console.warn('[RegisterAndLogin] localStorage 存储失败:', error);
1546
1550
  }
1547
1551
  return countries;
1548
1552
  } else {
1549
- this.store.error = response.message || "获取国家区号失败";
1553
+ this.store.error = response.message || '获取国家区号失败';
1550
1554
  throw new Error(this.store.error);
1551
1555
  }
1552
1556
  } catch (error) {
1553
- this.store.error = "获取国家区号失败";
1554
- console.error("[RegisterAndLogin] 获取国家区号失败:", error);
1557
+ this.store.error = '获取国家区号失败';
1558
+ console.error('[RegisterAndLogin] 获取国家区号失败:', error);
1555
1559
  throw error;
1556
1560
  } finally {
1557
1561
  this.store.isLoading = false;
1558
1562
  }
1559
1563
  }
1564
+
1560
1565
  /**
1561
1566
  * 异步更新国家缓存数据
1562
1567
  */
1563
1568
  async updateCountriesCache(cacheKey, cachedData) {
1564
1569
  try {
1565
- const response = await this.apiCaller.call("getCountries");
1570
+ const response = await this.apiCaller.call('getCountries');
1566
1571
  if (response.status && response.data) {
1567
1572
  const newData = response.data;
1573
+
1574
+ // 比较数据是否有变化(简单的长度和内容对比)
1568
1575
  const hasChanged = newData.length !== cachedData.length || JSON.stringify(newData) !== JSON.stringify(cachedData);
1569
1576
  if (hasChanged) {
1577
+ // 更新内存缓存
1570
1578
  this.countriesCache = newData;
1579
+
1580
+ // 更新 localStorage 缓存
1571
1581
  try {
1572
1582
  localStorage.setItem(cacheKey, JSON.stringify(newData));
1573
1583
  } catch (error) {
1574
- console.warn("[RegisterAndLogin] localStorage 更新失败:", error);
1584
+ console.warn('[RegisterAndLogin] localStorage 更新失败:', error);
1575
1585
  }
1576
- console.log("[RegisterAndLogin] 国家数据已更新");
1577
1586
  }
1578
1587
  }
1579
1588
  } catch (error) {
1580
- console.warn("[RegisterAndLogin] 后台更新国家数据失败:", error);
1589
+ console.warn('[RegisterAndLogin] 后台更新国家数据失败:', error);
1581
1590
  }
1582
1591
  }
1583
1592
  async destroy() {
1584
- await this.core.effects.emit(import_types.RegisterAndLoginHooks.onDestroy, {});
1585
- console.log("[RegisterAndLogin] 已销毁");
1593
+ await this.core.effects.emit(_types.RegisterAndLoginHooks.onDestroy, {});
1586
1594
  }
1587
- };
1588
- // Annotate the CommonJS export names for ESM import in node:
1589
- 0 && (module.exports = {
1590
- RegisterAndLoginImpl,
1591
- ...require("./types"),
1592
- ...require("./config")
1593
- });
1595
+ }
1596
+ exports.RegisterAndLoginImpl = RegisterAndLoginImpl;