@pisell/pisellos 0.0.335 → 0.0.337

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.
@@ -0,0 +1,2488 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
5
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
6
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
7
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
8
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
9
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
10
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
11
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
12
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
13
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
14
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
15
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
16
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
17
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
18
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
19
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
20
+ import { BaseModule } from "../../modules/BaseModule";
21
+ import { RegisterAndLoginHooks, VerificationCodeType, VerificationPurpose } from "./types";
22
+ import { createApiCaller } from "./config";
23
+ export * from "./types";
24
+ export * from "./config";
25
+
26
+ /**
27
+ * 注册登录解决方案实现
28
+ */
29
+ export var RegisterAndLoginImpl = /*#__PURE__*/function (_BaseModule) {
30
+ _inherits(RegisterAndLoginImpl, _BaseModule);
31
+ var _super = _createSuper(RegisterAndLoginImpl);
32
+ function RegisterAndLoginImpl(name, version) {
33
+ var _this;
34
+ _classCallCheck(this, RegisterAndLoginImpl);
35
+ _this = _super.call(this, name, version);
36
+ // 提供给 baseModule 用的默认名称和默认版本
37
+ _defineProperty(_assertThisInitialized(_this), "defaultName", 'registerAndLogin');
38
+ _defineProperty(_assertThisInitialized(_this), "defaultVersion", '1.0.0');
39
+ _defineProperty(_assertThisInitialized(_this), "isSolution", true);
40
+ _defineProperty(_assertThisInitialized(_this), "request", void 0);
41
+ _defineProperty(_assertThisInitialized(_this), "window", void 0);
42
+ _defineProperty(_assertThisInitialized(_this), "store", void 0);
43
+ _defineProperty(_assertThisInitialized(_this), "apiCaller", void 0);
44
+ _defineProperty(_assertThisInitialized(_this), "otherParams", {});
45
+ _defineProperty(_assertThisInitialized(_this), "channel", 'default');
46
+ return _this;
47
+ }
48
+
49
+ /**
50
+ * 重新发送邮箱注册链接
51
+ */
52
+ _createClass(RegisterAndLoginImpl, [{
53
+ key: "resendEmailRegisterLink",
54
+ value: (function () {
55
+ var _resendEmailRegisterLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
56
+ var error, response;
57
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
58
+ while (1) switch (_context.prev = _context.next) {
59
+ case 0:
60
+ _context.prev = 0;
61
+ if (this.store.emailRegisterLinkCode) {
62
+ _context.next = 5;
63
+ break;
64
+ }
65
+ error = '没有找到邮箱注册链接的 code,请先调用 sendEmailRegisterLink';
66
+ this.store.error = error;
67
+ return _context.abrupt("return", {
68
+ status: false,
69
+ message: error
70
+ });
71
+ case 5:
72
+ this.store.isLoading = true;
73
+ this.store.error = null;
74
+ _context.next = 9;
75
+ return this.apiCaller.call('resendEmailRegisterLink', {
76
+ code: this.store.emailRegisterLinkCode
77
+ });
78
+ case 9:
79
+ response = _context.sent;
80
+ if (!response.status) {
81
+ _context.next = 15;
82
+ break;
83
+ }
84
+ _context.next = 13;
85
+ return this.core.effects.emit(RegisterAndLoginHooks.onEmailVerificationSent, {
86
+ target: 'resend',
87
+ purpose: VerificationPurpose.REGISTER
88
+ });
89
+ case 13:
90
+ _context.next = 18;
91
+ break;
92
+ case 15:
93
+ this.store.error = response.message || '重新发送注册邀请链接失败';
94
+ _context.next = 18;
95
+ return this.core.effects.emit(RegisterAndLoginHooks.onEmailVerificationFailed, {
96
+ target: 'resend',
97
+ error: this.store.error
98
+ });
99
+ case 18:
100
+ return _context.abrupt("return", response);
101
+ case 21:
102
+ _context.prev = 21;
103
+ _context.t0 = _context["catch"](0);
104
+ this.store.error = '重新发送注册邀请链接失败';
105
+ _context.next = 26;
106
+ return this.core.effects.emit(RegisterAndLoginHooks.onEmailVerificationFailed, {
107
+ target: 'resend',
108
+ error: this.store.error
109
+ });
110
+ case 26:
111
+ return _context.abrupt("return", _context.t0);
112
+ case 27:
113
+ _context.prev = 27;
114
+ this.store.isLoading = false;
115
+ return _context.finish(27);
116
+ case 30:
117
+ case "end":
118
+ return _context.stop();
119
+ }
120
+ }, _callee, this, [[0, 21, 27, 30]]);
121
+ }));
122
+ function resendEmailRegisterLink() {
123
+ return _resendEmailRegisterLink.apply(this, arguments);
124
+ }
125
+ return resendEmailRegisterLink;
126
+ }()
127
+ /**
128
+ * 邮箱验证码注册
129
+ * @param params 注册参数
130
+ * @returns 注册结果
131
+ */
132
+ )
133
+ }, {
134
+ key: "emailCodeRegister",
135
+ value: (function () {
136
+ var _emailCodeRegister = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(params) {
137
+ var response, _response$data, user, token, refreshToken, expiresAt;
138
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
139
+ while (1) switch (_context2.prev = _context2.next) {
140
+ case 0:
141
+ _context2.prev = 0;
142
+ this.store.isLoading = true;
143
+ this.store.error = null;
144
+ _context2.next = 5;
145
+ return this.core.effects.emit(RegisterAndLoginHooks.onRegisterStarted, params);
146
+ case 5:
147
+ _context2.next = 7;
148
+ return this.apiCaller.call('emailCodeRegister', params);
149
+ case 7:
150
+ response = _context2.sent;
151
+ if (!(response.status && response.data)) {
152
+ _context2.next = 15;
153
+ break;
154
+ }
155
+ _response$data = response.data, user = _response$data.user, token = _response$data.token, refreshToken = _response$data.refreshToken, expiresAt = _response$data.expiresAt; // 如果注册成功并返回了 token,说明可以直接登录
156
+ if (token) {
157
+ this.store.currentUser = user;
158
+ this.store.isLoggedIn = true;
159
+
160
+ // 保存到本地存储
161
+ // this.window.localStorage.setItem('auth_token', token);
162
+ // this.window.localStorage.setItem('user_info', JSON.stringify(user));
163
+ // if (refreshToken) {
164
+ // this.window.localStorage.setItem('refresh_token', refreshToken);
165
+ // }
166
+ }
167
+ _context2.next = 13;
168
+ return this.core.effects.emit(RegisterAndLoginHooks.onRegisterSuccess, response.data);
169
+ case 13:
170
+ _context2.next = 18;
171
+ break;
172
+ case 15:
173
+ this.store.error = response.message || '邮箱验证码注册失败';
174
+ _context2.next = 18;
175
+ return this.core.effects.emit(RegisterAndLoginHooks.onRegisterFailed, {
176
+ error: this.store.error,
177
+ params: params
178
+ });
179
+ case 18:
180
+ return _context2.abrupt("return", response);
181
+ case 21:
182
+ _context2.prev = 21;
183
+ _context2.t0 = _context2["catch"](0);
184
+ this.store.error = '邮箱验证码注册失败';
185
+ _context2.next = 26;
186
+ return this.core.effects.emit(RegisterAndLoginHooks.onRegisterFailed, {
187
+ error: this.store.error,
188
+ params: params
189
+ });
190
+ case 26:
191
+ throw _context2.t0;
192
+ case 27:
193
+ _context2.prev = 27;
194
+ this.store.isLoading = false;
195
+ return _context2.finish(27);
196
+ case 30:
197
+ case "end":
198
+ return _context2.stop();
199
+ }
200
+ }, _callee2, this, [[0, 21, 27, 30]]);
201
+ }));
202
+ function emailCodeRegister(_x) {
203
+ return _emailCodeRegister.apply(this, arguments);
204
+ }
205
+ return emailCodeRegister;
206
+ }()
207
+ /**
208
+ * 手机验证码注册
209
+ */
210
+ )
211
+ }, {
212
+ key: "phoneCodeRegister",
213
+ value: (function () {
214
+ var _phoneCodeRegister = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(params) {
215
+ var response, _response$data2, user, token, refreshToken, expiresAt;
216
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
217
+ while (1) switch (_context3.prev = _context3.next) {
218
+ case 0:
219
+ _context3.prev = 0;
220
+ this.store.isLoading = true;
221
+ this.store.error = null;
222
+ _context3.next = 5;
223
+ return this.core.effects.emit(RegisterAndLoginHooks.onRegisterStarted, params);
224
+ case 5:
225
+ _context3.next = 7;
226
+ return this.apiCaller.call('phoneCodeRegister', params);
227
+ case 7:
228
+ response = _context3.sent;
229
+ if (!(response.status && response.data)) {
230
+ _context3.next = 15;
231
+ break;
232
+ }
233
+ _response$data2 = response.data, user = _response$data2.user, token = _response$data2.token, refreshToken = _response$data2.refreshToken, expiresAt = _response$data2.expiresAt; // 如果注册成功并返回了 token,说明可以直接登录
234
+ if (token) {
235
+ this.store.currentUser = user;
236
+ this.store.isLoggedIn = true;
237
+
238
+ // 保存到本地存储
239
+ // this.window.localStorage.setItem('auth_token', token);
240
+ // this.window.localStorage.setItem('user_info', JSON.stringify(user));
241
+ // if (refreshToken) {
242
+ // this.window.localStorage.setItem('refresh_token', refreshToken);
243
+ // }
244
+ }
245
+ _context3.next = 13;
246
+ return this.core.effects.emit(RegisterAndLoginHooks.onRegisterSuccess, response.data);
247
+ case 13:
248
+ _context3.next = 18;
249
+ break;
250
+ case 15:
251
+ this.store.error = response.message || '注册失败';
252
+ _context3.next = 18;
253
+ return this.core.effects.emit(RegisterAndLoginHooks.onRegisterFailed, {
254
+ error: this.store.error,
255
+ params: params
256
+ });
257
+ case 18:
258
+ return _context3.abrupt("return", response);
259
+ case 21:
260
+ _context3.prev = 21;
261
+ _context3.t0 = _context3["catch"](0);
262
+ this.store.error = _context3.t0.message || '注册失败';
263
+ _context3.next = 26;
264
+ return this.core.effects.emit(RegisterAndLoginHooks.onRegisterFailed, {
265
+ error: this.store.error,
266
+ params: params
267
+ });
268
+ case 26:
269
+ throw _context3.t0;
270
+ case 27:
271
+ _context3.prev = 27;
272
+ this.store.isLoading = false;
273
+ return _context3.finish(27);
274
+ case 30:
275
+ case "end":
276
+ return _context3.stop();
277
+ }
278
+ }, _callee3, this, [[0, 21, 27, 30]]);
279
+ }));
280
+ function phoneCodeRegister(_x2) {
281
+ return _phoneCodeRegister.apply(this, arguments);
282
+ }
283
+ return phoneCodeRegister;
284
+ }())
285
+ }, {
286
+ key: "initialize",
287
+ value: function () {
288
+ var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(core, options) {
289
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
290
+ while (1) switch (_context4.prev = _context4.next) {
291
+ case 0:
292
+ this.core = core;
293
+
294
+ // 初始化状态
295
+ this.store = _objectSpread({
296
+ currentUser: null,
297
+ isLoggedIn: false,
298
+ isLoading: false,
299
+ verificationCodeSent: {},
300
+ oauthConfig: options.oauthConfig || {},
301
+ error: null
302
+ }, options.store);
303
+ this.otherParams = options.otherParams || {};
304
+
305
+ // 获取渠道信息
306
+ this.channel = this.otherParams.channel || 'default';
307
+
308
+ // 获取依赖的插件
309
+ this.request = core.getPlugin('request');
310
+ this.window = core.getPlugin('window');
311
+ if (this.request) {
312
+ _context4.next = 8;
313
+ break;
314
+ }
315
+ throw new Error('RegisterAndLogin 模块需要 request 插件支持');
316
+ case 8:
317
+ if (this.window) {
318
+ _context4.next = 10;
319
+ break;
320
+ }
321
+ throw new Error('RegisterAndLogin 模块需要 window 插件支持');
322
+ case 10:
323
+ // 创建 API 调用器
324
+ this.apiCaller = createApiCaller(this.request, this.channel);
325
+
326
+ // 尝试从本地存储恢复登录状态
327
+ _context4.next = 13;
328
+ return this.restoreLoginState();
329
+ case 13:
330
+ console.log('[RegisterAndLogin] 初始化完成');
331
+ _context4.next = 16;
332
+ return this.core.effects.emit(RegisterAndLoginHooks.onInited, {});
333
+ case 16:
334
+ case "end":
335
+ return _context4.stop();
336
+ }
337
+ }, _callee4, this);
338
+ }));
339
+ function initialize(_x3, _x4) {
340
+ return _initialize.apply(this, arguments);
341
+ }
342
+ return initialize;
343
+ }()
344
+ /**
345
+ * 从本地存储恢复登录状态
346
+ */
347
+ }, {
348
+ key: "restoreLoginState",
349
+ value: (function () {
350
+ var _restoreLoginState = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
351
+ var token, userInfo, user;
352
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
353
+ while (1) switch (_context5.prev = _context5.next) {
354
+ case 0:
355
+ _context5.prev = 0;
356
+ token = this.window.localStorage.getItem('auth_token');
357
+ userInfo = this.window.localStorage.getItem('user_info');
358
+ if (!(token && userInfo)) {
359
+ _context5.next = 9;
360
+ break;
361
+ }
362
+ user = JSON.parse(userInfo);
363
+ this.store.currentUser = user;
364
+ this.store.isLoggedIn = true;
365
+
366
+ // 验证 token 是否仍然有效
367
+ _context5.next = 9;
368
+ return this.validateToken(token);
369
+ case 9:
370
+ _context5.next = 15;
371
+ break;
372
+ case 11:
373
+ _context5.prev = 11;
374
+ _context5.t0 = _context5["catch"](0);
375
+ console.warn('[RegisterAndLogin] 恢复登录状态失败:', _context5.t0);
376
+ this.clearLoginState();
377
+ case 15:
378
+ case "end":
379
+ return _context5.stop();
380
+ }
381
+ }, _callee5, this, [[0, 11]]);
382
+ }));
383
+ function restoreLoginState() {
384
+ return _restoreLoginState.apply(this, arguments);
385
+ }
386
+ return restoreLoginState;
387
+ }()
388
+ /**
389
+ * 验证 token 有效性
390
+ */
391
+ )
392
+ }, {
393
+ key: "validateToken",
394
+ value: (function () {
395
+ var _validateToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(token) {
396
+ var response;
397
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
398
+ while (1) switch (_context6.prev = _context6.next) {
399
+ case 0:
400
+ _context6.prev = 0;
401
+ _context6.next = 3;
402
+ return this.apiCaller.call('validateToken', token);
403
+ case 3:
404
+ response = _context6.sent;
405
+ if (!(response.status && response.data)) {
406
+ _context6.next = 9;
407
+ break;
408
+ }
409
+ this.store.currentUser = response.data;
410
+ return _context6.abrupt("return", true);
411
+ case 9:
412
+ this.clearLoginState();
413
+ return _context6.abrupt("return", false);
414
+ case 11:
415
+ _context6.next = 18;
416
+ break;
417
+ case 13:
418
+ _context6.prev = 13;
419
+ _context6.t0 = _context6["catch"](0);
420
+ console.warn('[RegisterAndLogin] Token 验证失败:', _context6.t0);
421
+ this.clearLoginState();
422
+ return _context6.abrupt("return", false);
423
+ case 18:
424
+ case "end":
425
+ return _context6.stop();
426
+ }
427
+ }, _callee6, this, [[0, 13]]);
428
+ }));
429
+ function validateToken(_x5) {
430
+ return _validateToken.apply(this, arguments);
431
+ }
432
+ return validateToken;
433
+ }()
434
+ /**
435
+ * 清除登录状态
436
+ */
437
+ )
438
+ }, {
439
+ key: "clearLoginState",
440
+ value: function clearLoginState() {
441
+ this.store.currentUser = null;
442
+ this.store.isLoggedIn = false;
443
+ this.window.localStorage.removeItem('auth_token');
444
+ this.window.localStorage.removeItem('user_info');
445
+ this.window.localStorage.removeItem('refresh_token');
446
+ }
447
+
448
+ /**
449
+ * 发送邮箱验证码
450
+ */
451
+ }, {
452
+ key: "sendEmailVerificationCode",
453
+ value: (function () {
454
+ var _sendEmailVerificationCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(params) {
455
+ var response, now;
456
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
457
+ while (1) switch (_context7.prev = _context7.next) {
458
+ case 0:
459
+ _context7.prev = 0;
460
+ this.store.isLoading = true;
461
+ this.store.error = null;
462
+ _context7.next = 5;
463
+ return this.apiCaller.call('sendEmailVerificationCode', params);
464
+ case 5:
465
+ response = _context7.sent;
466
+ if (!response.status) {
467
+ _context7.next = 13;
468
+ break;
469
+ }
470
+ // 记录验证码发送状态
471
+ now = Date.now();
472
+ this.store.verificationCodeSent[params.target] = {
473
+ sent: true,
474
+ sentAt: now,
475
+ expiresAt: now + 5 * 60 * 1000 // 5分钟过期
476
+ };
477
+ _context7.next = 11;
478
+ return this.core.effects.emit(RegisterAndLoginHooks.onEmailVerificationSent, {
479
+ target: params.target,
480
+ purpose: params.purpose
481
+ });
482
+ case 11:
483
+ _context7.next = 16;
484
+ break;
485
+ case 13:
486
+ this.store.error = response.message || '发送验证码失败';
487
+ _context7.next = 16;
488
+ return this.core.effects.emit(RegisterAndLoginHooks.onEmailVerificationFailed, {
489
+ target: params.target,
490
+ error: this.store.error
491
+ });
492
+ case 16:
493
+ return _context7.abrupt("return", response);
494
+ case 19:
495
+ _context7.prev = 19;
496
+ _context7.t0 = _context7["catch"](0);
497
+ this.store.error = '发送验证码失败';
498
+ _context7.next = 24;
499
+ return this.core.effects.emit(RegisterAndLoginHooks.onEmailVerificationFailed, {
500
+ target: params.target,
501
+ error: this.store.error
502
+ });
503
+ case 24:
504
+ return _context7.abrupt("return", _context7.t0);
505
+ case 25:
506
+ _context7.prev = 25;
507
+ this.store.isLoading = false;
508
+ return _context7.finish(25);
509
+ case 28:
510
+ case "end":
511
+ return _context7.stop();
512
+ }
513
+ }, _callee7, this, [[0, 19, 25, 28]]);
514
+ }));
515
+ function sendEmailVerificationCode(_x6) {
516
+ return _sendEmailVerificationCode.apply(this, arguments);
517
+ }
518
+ return sendEmailVerificationCode;
519
+ }()
520
+ /**
521
+ * 发送邮箱登录验证码
522
+ */
523
+ )
524
+ }, {
525
+ key: "sendEmailLoginCode",
526
+ value: (function () {
527
+ var _sendEmailLoginCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(params) {
528
+ var response, now;
529
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
530
+ while (1) switch (_context8.prev = _context8.next) {
531
+ case 0:
532
+ _context8.prev = 0;
533
+ this.store.isLoading = true;
534
+ this.store.error = null;
535
+ _context8.next = 5;
536
+ return this.apiCaller.call('sendEmailLoginCode', params);
537
+ case 5:
538
+ response = _context8.sent;
539
+ if (!response.status) {
540
+ _context8.next = 13;
541
+ break;
542
+ }
543
+ // 记录验证码发送状态
544
+ now = Date.now();
545
+ this.store.verificationCodeSent[params.target] = {
546
+ sent: true,
547
+ sentAt: now,
548
+ expiresAt: now + 5 * 60 * 1000 // 5分钟过期
549
+ };
550
+ _context8.next = 11;
551
+ return this.core.effects.emit(RegisterAndLoginHooks.onEmailVerificationSent, {
552
+ target: params.target,
553
+ purpose: params.purpose
554
+ });
555
+ case 11:
556
+ _context8.next = 16;
557
+ break;
558
+ case 13:
559
+ this.store.error = response.message || '发送验证码失败';
560
+ _context8.next = 16;
561
+ return this.core.effects.emit(RegisterAndLoginHooks.onEmailVerificationFailed, {
562
+ target: params.target,
563
+ error: this.store.error
564
+ });
565
+ case 16:
566
+ return _context8.abrupt("return", response);
567
+ case 19:
568
+ _context8.prev = 19;
569
+ _context8.t0 = _context8["catch"](0);
570
+ this.store.error = '发送验证码失败';
571
+ _context8.next = 24;
572
+ return this.core.effects.emit(RegisterAndLoginHooks.onEmailVerificationFailed, {
573
+ target: params.target,
574
+ error: this.store.error
575
+ });
576
+ case 24:
577
+ return _context8.abrupt("return", _context8.t0);
578
+ case 25:
579
+ _context8.prev = 25;
580
+ this.store.isLoading = false;
581
+ return _context8.finish(25);
582
+ case 28:
583
+ case "end":
584
+ return _context8.stop();
585
+ }
586
+ }, _callee8, this, [[0, 19, 25, 28]]);
587
+ }));
588
+ function sendEmailLoginCode(_x7) {
589
+ return _sendEmailLoginCode.apply(this, arguments);
590
+ }
591
+ return sendEmailLoginCode;
592
+ }()
593
+ /**
594
+ * 发送手机号注册验证码
595
+ */
596
+ )
597
+ }, {
598
+ key: "sendSmsRegisterCode",
599
+ value: (function () {
600
+ var _sendSmsRegisterCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(params) {
601
+ var response, now;
602
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
603
+ while (1) switch (_context9.prev = _context9.next) {
604
+ case 0:
605
+ _context9.prev = 0;
606
+ this.store.isLoading = true;
607
+ this.store.error = null;
608
+ _context9.next = 5;
609
+ return this.apiCaller.call('sendSmsRegisterCode', params);
610
+ case 5:
611
+ response = _context9.sent;
612
+ if (!response.status) {
613
+ _context9.next = 13;
614
+ break;
615
+ }
616
+ // 记录验证码发送状态
617
+ now = Date.now();
618
+ this.store.verificationCodeSent[params.phone] = {
619
+ sent: true,
620
+ sentAt: now,
621
+ expiresAt: now + 5 * 60 * 1000 // 5分钟过期
622
+ };
623
+ _context9.next = 11;
624
+ return this.core.effects.emit(RegisterAndLoginHooks.onSmsVerificationSent, {
625
+ target: params.phone,
626
+ purpose: VerificationPurpose.REGISTER
627
+ });
628
+ case 11:
629
+ _context9.next = 16;
630
+ break;
631
+ case 13:
632
+ this.store.error = response.message || '发送注册验证码失败';
633
+ _context9.next = 16;
634
+ return this.core.effects.emit(RegisterAndLoginHooks.onSmsVerificationFailed, {
635
+ target: params.phone,
636
+ error: this.store.error
637
+ });
638
+ case 16:
639
+ return _context9.abrupt("return", response);
640
+ case 19:
641
+ _context9.prev = 19;
642
+ _context9.t0 = _context9["catch"](0);
643
+ this.store.error = '发送注册验证码失败';
644
+ _context9.next = 24;
645
+ return this.core.effects.emit(RegisterAndLoginHooks.onSmsVerificationFailed, {
646
+ target: params.phone,
647
+ error: this.store.error
648
+ });
649
+ case 24:
650
+ return _context9.abrupt("return", _context9.t0);
651
+ case 25:
652
+ _context9.prev = 25;
653
+ this.store.isLoading = false;
654
+ return _context9.finish(25);
655
+ case 28:
656
+ case "end":
657
+ return _context9.stop();
658
+ }
659
+ }, _callee9, this, [[0, 19, 25, 28]]);
660
+ }));
661
+ function sendSmsRegisterCode(_x8) {
662
+ return _sendSmsRegisterCode.apply(this, arguments);
663
+ }
664
+ return sendSmsRegisterCode;
665
+ }()
666
+ /**
667
+ * 发送邮箱注册邀请链接
668
+ */
669
+ )
670
+ }, {
671
+ key: "sendEmailRegisterLink",
672
+ value: (function () {
673
+ var _sendEmailRegisterLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(email) {
674
+ var response, _response$data3, now;
675
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
676
+ while (1) switch (_context10.prev = _context10.next) {
677
+ case 0:
678
+ _context10.prev = 0;
679
+ this.store.isLoading = true;
680
+ this.store.error = null;
681
+ _context10.next = 5;
682
+ return this.apiCaller.call('sendEmailRegisterLink', email);
683
+ case 5:
684
+ response = _context10.sent;
685
+ if (!response.status) {
686
+ _context10.next = 14;
687
+ break;
688
+ }
689
+ // 保存返回的 code
690
+ if ((_response$data3 = response.data) !== null && _response$data3 !== void 0 && _response$data3.code) {
691
+ this.store.emailRegisterLinkCode = response.data.code;
692
+ }
693
+
694
+ // 记录邀请链接发送状态
695
+ now = Date.now();
696
+ this.store.verificationCodeSent[email] = {
697
+ sent: true,
698
+ sentAt: now,
699
+ expiresAt: now + 24 * 60 * 60 * 1000 // 24小时过期
700
+ };
701
+ _context10.next = 12;
702
+ return this.core.effects.emit(RegisterAndLoginHooks.onEmailVerificationSent, {
703
+ target: email,
704
+ purpose: VerificationPurpose.REGISTER
705
+ });
706
+ case 12:
707
+ _context10.next = 17;
708
+ break;
709
+ case 14:
710
+ this.store.error = response.message || '发送注册邀请链接失败';
711
+ _context10.next = 17;
712
+ return this.core.effects.emit(RegisterAndLoginHooks.onEmailVerificationFailed, {
713
+ target: email,
714
+ error: this.store.error
715
+ });
716
+ case 17:
717
+ return _context10.abrupt("return", response);
718
+ case 20:
719
+ _context10.prev = 20;
720
+ _context10.t0 = _context10["catch"](0);
721
+ this.store.error = '发送注册邀请链接失败';
722
+ _context10.next = 25;
723
+ return this.core.effects.emit(RegisterAndLoginHooks.onEmailVerificationFailed, {
724
+ target: email,
725
+ error: this.store.error
726
+ });
727
+ case 25:
728
+ return _context10.abrupt("return", _context10.t0);
729
+ case 26:
730
+ _context10.prev = 26;
731
+ this.store.isLoading = false;
732
+ return _context10.finish(26);
733
+ case 29:
734
+ case "end":
735
+ return _context10.stop();
736
+ }
737
+ }, _callee10, this, [[0, 20, 26, 29]]);
738
+ }));
739
+ function sendEmailRegisterLink(_x9) {
740
+ return _sendEmailRegisterLink.apply(this, arguments);
741
+ }
742
+ return sendEmailRegisterLink;
743
+ }()
744
+ /**
745
+ * 验证邮箱注册链接
746
+ */
747
+ )
748
+ }, {
749
+ key: "verifyEmailRegistrationLink",
750
+ value: (function () {
751
+ var _verifyEmailRegistrationLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(params) {
752
+ var response;
753
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
754
+ while (1) switch (_context11.prev = _context11.next) {
755
+ case 0:
756
+ _context11.prev = 0;
757
+ this.store.isLoading = true;
758
+ this.store.error = null;
759
+ _context11.next = 5;
760
+ return this.apiCaller.call('verifyEmailRegistrationLink', params);
761
+ case 5:
762
+ response = _context11.sent;
763
+ if (!response.status) {
764
+ _context11.next = 11;
765
+ break;
766
+ }
767
+ _context11.next = 9;
768
+ return this.core.effects.emit(RegisterAndLoginHooks.onEmailVerificationVerified, {
769
+ target: 'email-registration-link',
770
+ purpose: VerificationPurpose.REGISTER
771
+ });
772
+ case 9:
773
+ _context11.next = 14;
774
+ break;
775
+ case 11:
776
+ this.store.error = response.message || '邮箱注册链接验证失败';
777
+ _context11.next = 14;
778
+ return this.core.effects.emit(RegisterAndLoginHooks.onEmailVerificationFailed, {
779
+ target: 'email-registration-link',
780
+ error: this.store.error
781
+ });
782
+ case 14:
783
+ return _context11.abrupt("return", response);
784
+ case 17:
785
+ _context11.prev = 17;
786
+ _context11.t0 = _context11["catch"](0);
787
+ this.store.error = '邮箱注册链接验证失败';
788
+ _context11.next = 22;
789
+ return this.core.effects.emit(RegisterAndLoginHooks.onEmailVerificationFailed, {
790
+ target: 'email-registration-link',
791
+ error: this.store.error
792
+ });
793
+ case 22:
794
+ return _context11.abrupt("return", _context11.t0);
795
+ case 23:
796
+ _context11.prev = 23;
797
+ this.store.isLoading = false;
798
+ return _context11.finish(23);
799
+ case 26:
800
+ case "end":
801
+ return _context11.stop();
802
+ }
803
+ }, _callee11, this, [[0, 17, 23, 26]]);
804
+ }));
805
+ function verifyEmailRegistrationLink(_x10) {
806
+ return _verifyEmailRegistrationLink.apply(this, arguments);
807
+ }
808
+ return verifyEmailRegistrationLink;
809
+ }()
810
+ /**
811
+ * 邮箱密码登录
812
+ */
813
+ )
814
+ }, {
815
+ key: "emailPasswordLogin",
816
+ value: (function () {
817
+ var _emailPasswordLogin = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(params) {
818
+ var response;
819
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
820
+ while (1) switch (_context12.prev = _context12.next) {
821
+ case 0:
822
+ _context12.prev = 0;
823
+ this.store.isLoading = true;
824
+ this.store.error = null;
825
+ _context12.next = 5;
826
+ return this.core.effects.emit(RegisterAndLoginHooks.onLoginStarted, {
827
+ type: 'email-password',
828
+ email: params.email
829
+ });
830
+ case 5:
831
+ _context12.next = 7;
832
+ return this.apiCaller.call('emailPasswordLogin', params);
833
+ case 7:
834
+ response = _context12.sent;
835
+ if (!(response.status && response.data)) {
836
+ _context12.next = 17;
837
+ break;
838
+ }
839
+ // 保存用户信息和 token
840
+ this.store.isLoggedIn = true;
841
+ this.store.userInfo = response.data.user;
842
+ this.store.token = response.data.token;
843
+
844
+ // 如果有 refreshToken,也保存
845
+ if (response.data.refreshToken) {
846
+ this.store.refreshToken = response.data.refreshToken;
847
+ }
848
+ _context12.next = 15;
849
+ return this.core.effects.emit(RegisterAndLoginHooks.onLoginSuccess, {
850
+ user: response.data.user,
851
+ token: response.data.token,
852
+ loginType: 'email-password'
853
+ });
854
+ case 15:
855
+ _context12.next = 20;
856
+ break;
857
+ case 17:
858
+ this.store.error = response.message || '邮箱密码登录失败';
859
+ _context12.next = 20;
860
+ return this.core.effects.emit(RegisterAndLoginHooks.onLoginFailed, {
861
+ error: this.store.error,
862
+ loginType: 'email-password'
863
+ });
864
+ case 20:
865
+ return _context12.abrupt("return", response);
866
+ case 23:
867
+ _context12.prev = 23;
868
+ _context12.t0 = _context12["catch"](0);
869
+ this.store.error = '邮箱密码登录失败';
870
+ _context12.next = 28;
871
+ return this.core.effects.emit(RegisterAndLoginHooks.onLoginFailed, {
872
+ error: this.store.error,
873
+ loginType: 'email-password'
874
+ });
875
+ case 28:
876
+ return _context12.abrupt("return", _context12.t0);
877
+ case 29:
878
+ _context12.prev = 29;
879
+ this.store.isLoading = false;
880
+ return _context12.finish(29);
881
+ case 32:
882
+ case "end":
883
+ return _context12.stop();
884
+ }
885
+ }, _callee12, this, [[0, 23, 29, 32]]);
886
+ }));
887
+ function emailPasswordLogin(_x11) {
888
+ return _emailPasswordLogin.apply(this, arguments);
889
+ }
890
+ return emailPasswordLogin;
891
+ }()
892
+ /**
893
+ * 验证验证码
894
+ */
895
+ )
896
+ }, {
897
+ key: "verifyCode",
898
+ value: (function () {
899
+ var _verifyCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(params) {
900
+ var response, hookName, _hookName;
901
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
902
+ while (1) switch (_context13.prev = _context13.next) {
903
+ case 0:
904
+ _context13.prev = 0;
905
+ this.store.isLoading = true;
906
+ this.store.error = null;
907
+ _context13.next = 5;
908
+ return this.apiCaller.call('verifyCode', params);
909
+ case 5:
910
+ response = _context13.sent;
911
+ if (!response.status) {
912
+ _context13.next = 12;
913
+ break;
914
+ }
915
+ hookName = params.type === VerificationCodeType.EMAIL ? RegisterAndLoginHooks.onEmailVerificationVerified : RegisterAndLoginHooks.onSmsVerificationVerified;
916
+ _context13.next = 10;
917
+ return this.core.effects.emit(hookName, {
918
+ target: params.target,
919
+ purpose: params.purpose
920
+ });
921
+ case 10:
922
+ _context13.next = 16;
923
+ break;
924
+ case 12:
925
+ this.store.error = response.message || '验证码验证失败';
926
+ _hookName = params.type === VerificationCodeType.EMAIL ? RegisterAndLoginHooks.onEmailVerificationFailed : RegisterAndLoginHooks.onSmsVerificationFailed;
927
+ _context13.next = 16;
928
+ return this.core.effects.emit(_hookName, {
929
+ target: params.target,
930
+ error: this.store.error
931
+ });
932
+ case 16:
933
+ return _context13.abrupt("return", response);
934
+ case 19:
935
+ _context13.prev = 19;
936
+ _context13.t0 = _context13["catch"](0);
937
+ this.store.error = '验证码验证失败';
938
+ return _context13.abrupt("return", _context13.t0);
939
+ case 23:
940
+ _context13.prev = 23;
941
+ this.store.isLoading = false;
942
+ return _context13.finish(23);
943
+ case 26:
944
+ case "end":
945
+ return _context13.stop();
946
+ }
947
+ }, _callee13, this, [[0, 19, 23, 26]]);
948
+ }));
949
+ function verifyCode(_x12) {
950
+ return _verifyCode.apply(this, arguments);
951
+ }
952
+ return verifyCode;
953
+ }()
954
+ /**
955
+ * 用户注册
956
+ */
957
+ )
958
+ }, {
959
+ key: "register",
960
+ value: (function () {
961
+ var _register = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(params) {
962
+ var response, _response$data4, user, token, refreshToken, expiresAt;
963
+ return _regeneratorRuntime().wrap(function _callee14$(_context14) {
964
+ while (1) switch (_context14.prev = _context14.next) {
965
+ case 0:
966
+ _context14.prev = 0;
967
+ this.store.isLoading = true;
968
+ this.store.error = null;
969
+ _context14.next = 5;
970
+ return this.core.effects.emit(RegisterAndLoginHooks.onRegisterStarted, params);
971
+ case 5:
972
+ _context14.next = 7;
973
+ return this.apiCaller.call('register', params);
974
+ case 7:
975
+ response = _context14.sent;
976
+ if (!(response.status && response.data)) {
977
+ _context14.next = 15;
978
+ break;
979
+ }
980
+ _response$data4 = response.data, user = _response$data4.user, token = _response$data4.token, refreshToken = _response$data4.refreshToken, expiresAt = _response$data4.expiresAt; // 如果注册成功并返回了 token,说明可以直接登录
981
+ if (token) {
982
+ this.store.currentUser = user;
983
+ this.store.isLoggedIn = true;
984
+
985
+ // 保存到本地存储
986
+ this.window.localStorage.setItem('auth_token', token);
987
+ this.window.localStorage.setItem('user_info', JSON.stringify(user));
988
+ if (refreshToken) {
989
+ this.window.localStorage.setItem('refresh_token', refreshToken);
990
+ }
991
+ }
992
+ _context14.next = 13;
993
+ return this.core.effects.emit(RegisterAndLoginHooks.onRegisterSuccess, response.data);
994
+ case 13:
995
+ _context14.next = 18;
996
+ break;
997
+ case 15:
998
+ this.store.error = response.message || '注册失败';
999
+ _context14.next = 18;
1000
+ return this.core.effects.emit(RegisterAndLoginHooks.onRegisterFailed, {
1001
+ error: this.store.error,
1002
+ params: params
1003
+ });
1004
+ case 18:
1005
+ return _context14.abrupt("return", response);
1006
+ case 21:
1007
+ _context14.prev = 21;
1008
+ _context14.t0 = _context14["catch"](0);
1009
+ this.store.error = '注册失败';
1010
+ _context14.next = 26;
1011
+ return this.core.effects.emit(RegisterAndLoginHooks.onRegisterFailed, {
1012
+ error: this.store.error,
1013
+ params: params
1014
+ });
1015
+ case 26:
1016
+ throw _context14.t0;
1017
+ case 27:
1018
+ _context14.prev = 27;
1019
+ this.store.isLoading = false;
1020
+ return _context14.finish(27);
1021
+ case 30:
1022
+ case "end":
1023
+ return _context14.stop();
1024
+ }
1025
+ }, _callee14, this, [[0, 21, 27, 30]]);
1026
+ }));
1027
+ function register(_x13) {
1028
+ return _register.apply(this, arguments);
1029
+ }
1030
+ return register;
1031
+ }()
1032
+ /**
1033
+ * 用户登录
1034
+ */
1035
+ )
1036
+ }, {
1037
+ key: "login",
1038
+ value: (function () {
1039
+ var _login = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(params) {
1040
+ var response, _response$data5, user, token, refreshToken;
1041
+ return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1042
+ while (1) switch (_context15.prev = _context15.next) {
1043
+ case 0:
1044
+ _context15.prev = 0;
1045
+ this.store.isLoading = true;
1046
+ this.store.error = null;
1047
+ _context15.next = 5;
1048
+ return this.core.effects.emit(RegisterAndLoginHooks.onLoginStarted, params);
1049
+ case 5:
1050
+ _context15.next = 7;
1051
+ return this.apiCaller.call('login', params);
1052
+ case 7:
1053
+ response = _context15.sent;
1054
+ if (!(response.status && response.data)) {
1055
+ _context15.next = 19;
1056
+ break;
1057
+ }
1058
+ _response$data5 = response.data, user = _response$data5.user, token = _response$data5.token, refreshToken = _response$data5.refreshToken;
1059
+ this.store.currentUser = user;
1060
+ this.store.isLoggedIn = true;
1061
+
1062
+ // 保存到本地存储
1063
+ this.window.localStorage.setItem('auth_token', token);
1064
+ this.window.localStorage.setItem('user_info', JSON.stringify(user));
1065
+ if (refreshToken) {
1066
+ this.window.localStorage.setItem('refresh_token', refreshToken);
1067
+ }
1068
+ _context15.next = 17;
1069
+ return this.core.effects.emit(RegisterAndLoginHooks.onLoginSuccess, response.data);
1070
+ case 17:
1071
+ _context15.next = 22;
1072
+ break;
1073
+ case 19:
1074
+ this.store.error = response.message || '登录失败';
1075
+ _context15.next = 22;
1076
+ return this.core.effects.emit(RegisterAndLoginHooks.onLoginFailed, {
1077
+ error: this.store.error,
1078
+ params: params
1079
+ });
1080
+ case 22:
1081
+ return _context15.abrupt("return", response);
1082
+ case 25:
1083
+ _context15.prev = 25;
1084
+ _context15.t0 = _context15["catch"](0);
1085
+ this.store.error = '登录失败';
1086
+ _context15.next = 30;
1087
+ return this.core.effects.emit(RegisterAndLoginHooks.onLoginFailed, {
1088
+ error: this.store.error,
1089
+ params: params
1090
+ });
1091
+ case 30:
1092
+ throw _context15.t0;
1093
+ case 31:
1094
+ _context15.prev = 31;
1095
+ this.store.isLoading = false;
1096
+ return _context15.finish(31);
1097
+ case 34:
1098
+ case "end":
1099
+ return _context15.stop();
1100
+ }
1101
+ }, _callee15, this, [[0, 25, 31, 34]]);
1102
+ }));
1103
+ function login(_x14) {
1104
+ return _login.apply(this, arguments);
1105
+ }
1106
+ return login;
1107
+ }()
1108
+ /**
1109
+ * OAuth 登录
1110
+ */
1111
+ )
1112
+ }, {
1113
+ key: "oauthLogin",
1114
+ value: (function () {
1115
+ var _oauthLogin = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(params) {
1116
+ var response, _response$data6, user, token, refreshToken;
1117
+ return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1118
+ while (1) switch (_context16.prev = _context16.next) {
1119
+ case 0:
1120
+ _context16.prev = 0;
1121
+ this.store.isLoading = true;
1122
+ this.store.error = null;
1123
+ _context16.next = 5;
1124
+ return this.core.effects.emit(RegisterAndLoginHooks.onOAuthLoginStarted, params);
1125
+ case 5:
1126
+ _context16.next = 7;
1127
+ return this.apiCaller.call('oauthLogin', params);
1128
+ case 7:
1129
+ response = _context16.sent;
1130
+ if (!(response.status && response.data)) {
1131
+ _context16.next = 19;
1132
+ break;
1133
+ }
1134
+ _response$data6 = response.data, user = _response$data6.user, token = _response$data6.token, refreshToken = _response$data6.refreshToken;
1135
+ this.store.currentUser = user;
1136
+ this.store.isLoggedIn = true;
1137
+
1138
+ // 保存到本地存储
1139
+ this.window.localStorage.setItem('auth_token', token);
1140
+ this.window.localStorage.setItem('user_info', JSON.stringify(user));
1141
+ if (refreshToken) {
1142
+ this.window.localStorage.setItem('refresh_token', refreshToken);
1143
+ }
1144
+ _context16.next = 17;
1145
+ return this.core.effects.emit(RegisterAndLoginHooks.onOAuthLoginSuccess, response.data);
1146
+ case 17:
1147
+ _context16.next = 22;
1148
+ break;
1149
+ case 19:
1150
+ this.store.error = response.message || 'OAuth 登录失败';
1151
+ _context16.next = 22;
1152
+ return this.core.effects.emit(RegisterAndLoginHooks.onOAuthLoginFailed, {
1153
+ error: this.store.error,
1154
+ params: params
1155
+ });
1156
+ case 22:
1157
+ return _context16.abrupt("return", response);
1158
+ case 25:
1159
+ _context16.prev = 25;
1160
+ _context16.t0 = _context16["catch"](0);
1161
+ this.store.error = 'OAuth 登录失败';
1162
+ _context16.next = 30;
1163
+ return this.core.effects.emit(RegisterAndLoginHooks.onOAuthLoginFailed, {
1164
+ error: this.store.error,
1165
+ params: params
1166
+ });
1167
+ case 30:
1168
+ throw _context16.t0;
1169
+ case 31:
1170
+ _context16.prev = 31;
1171
+ this.store.isLoading = false;
1172
+ return _context16.finish(31);
1173
+ case 34:
1174
+ case "end":
1175
+ return _context16.stop();
1176
+ }
1177
+ }, _callee16, this, [[0, 25, 31, 34]]);
1178
+ }));
1179
+ function oauthLogin(_x15) {
1180
+ return _oauthLogin.apply(this, arguments);
1181
+ }
1182
+ return oauthLogin;
1183
+ }()
1184
+ /**
1185
+ * 用户登出
1186
+ */
1187
+ )
1188
+ }, {
1189
+ key: "logout",
1190
+ value: (function () {
1191
+ var _logout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
1192
+ return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1193
+ while (1) switch (_context17.prev = _context17.next) {
1194
+ case 0:
1195
+ _context17.prev = 0;
1196
+ _context17.next = 3;
1197
+ return this.apiCaller.call('logout');
1198
+ case 3:
1199
+ _context17.next = 8;
1200
+ break;
1201
+ case 5:
1202
+ _context17.prev = 5;
1203
+ _context17.t0 = _context17["catch"](0);
1204
+ console.warn('[RegisterAndLogin] 登出接口调用失败:', _context17.t0);
1205
+ case 8:
1206
+ _context17.prev = 8;
1207
+ // 无论后端接口是否成功,都清除本地状态
1208
+ this.clearLoginState();
1209
+ return _context17.finish(8);
1210
+ case 11:
1211
+ case "end":
1212
+ return _context17.stop();
1213
+ }
1214
+ }, _callee17, this, [[0, 5, 8, 11]]);
1215
+ }));
1216
+ function logout() {
1217
+ return _logout.apply(this, arguments);
1218
+ }
1219
+ return logout;
1220
+ }() /** 发送重置密码邮箱链接 */)
1221
+ }, {
1222
+ key: "sendResetPasswordLink",
1223
+ value: (function () {
1224
+ var _sendResetPasswordLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(params) {
1225
+ var response;
1226
+ return _regeneratorRuntime().wrap(function _callee18$(_context18) {
1227
+ while (1) switch (_context18.prev = _context18.next) {
1228
+ case 0:
1229
+ _context18.prev = 0;
1230
+ this.store.isLoading = true;
1231
+ this.store.error = null;
1232
+ _context18.next = 5;
1233
+ return this.apiCaller.call('sendResetPasswordLink', params);
1234
+ case 5:
1235
+ response = _context18.sent;
1236
+ if (response.status) {
1237
+ this.store.verificationCodeSent[params.email] = {
1238
+ sent: true,
1239
+ sentAt: Date.now(),
1240
+ expiresAt: Date.now() + 5 * 60 * 1000 // 5分钟后过期
1241
+ };
1242
+ this.core.effects.emit(RegisterAndLoginHooks.onEmailVerificationSent, {
1243
+ email: params.email,
1244
+ purpose: 'reset-password-link'
1245
+ });
1246
+ } else {
1247
+ this.store.error = response.message || '发送重置密码链接失败';
1248
+ }
1249
+ return _context18.abrupt("return", response);
1250
+ case 10:
1251
+ _context18.prev = 10;
1252
+ _context18.t0 = _context18["catch"](0);
1253
+ this.store.error = '发送重置密码链接失败';
1254
+ return _context18.abrupt("return", _context18.t0);
1255
+ case 14:
1256
+ _context18.prev = 14;
1257
+ this.store.isLoading = false;
1258
+ return _context18.finish(14);
1259
+ case 17:
1260
+ case "end":
1261
+ return _context18.stop();
1262
+ }
1263
+ }, _callee18, this, [[0, 10, 14, 17]]);
1264
+ }));
1265
+ function sendResetPasswordLink(_x16) {
1266
+ return _sendResetPasswordLink.apply(this, arguments);
1267
+ }
1268
+ return sendResetPasswordLink;
1269
+ }() /** 检测重置密码链接code有效性 */)
1270
+ }, {
1271
+ key: "checkResetPasswordCode",
1272
+ value: (function () {
1273
+ var _checkResetPasswordCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(params) {
1274
+ var response;
1275
+ return _regeneratorRuntime().wrap(function _callee19$(_context19) {
1276
+ while (1) switch (_context19.prev = _context19.next) {
1277
+ case 0:
1278
+ _context19.prev = 0;
1279
+ this.store.isLoading = true;
1280
+ this.store.error = null;
1281
+ _context19.next = 5;
1282
+ return this.apiCaller.call('checkResetPasswordCode', params);
1283
+ case 5:
1284
+ response = _context19.sent;
1285
+ if (!response.status) {
1286
+ this.store.error = response.message || '验证码无效';
1287
+ }
1288
+ return _context19.abrupt("return", response);
1289
+ case 10:
1290
+ _context19.prev = 10;
1291
+ _context19.t0 = _context19["catch"](0);
1292
+ this.store.error = '验证码验证失败';
1293
+ return _context19.abrupt("return", _context19.t0);
1294
+ case 14:
1295
+ _context19.prev = 14;
1296
+ this.store.isLoading = false;
1297
+ return _context19.finish(14);
1298
+ case 17:
1299
+ case "end":
1300
+ return _context19.stop();
1301
+ }
1302
+ }, _callee19, this, [[0, 10, 14, 17]]);
1303
+ }));
1304
+ function checkResetPasswordCode(_x17) {
1305
+ return _checkResetPasswordCode.apply(this, arguments);
1306
+ }
1307
+ return checkResetPasswordCode;
1308
+ }() /** 校验邮件链接 code 有效性 */)
1309
+ }, {
1310
+ key: "checkEmailLinkCode",
1311
+ value: (function () {
1312
+ var _checkEmailLinkCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(params) {
1313
+ var response;
1314
+ return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1315
+ while (1) switch (_context20.prev = _context20.next) {
1316
+ case 0:
1317
+ _context20.prev = 0;
1318
+ this.store.isLoading = true;
1319
+ this.store.error = null;
1320
+ _context20.next = 5;
1321
+ return this.apiCaller.call('checkEmailLinkCode', params);
1322
+ case 5:
1323
+ response = _context20.sent;
1324
+ if (!response.status) {
1325
+ this.store.error = response.message || '邮件链接验证码无效';
1326
+ }
1327
+ return _context20.abrupt("return", response);
1328
+ case 10:
1329
+ _context20.prev = 10;
1330
+ _context20.t0 = _context20["catch"](0);
1331
+ this.store.error = '邮件链接验证码验证失败';
1332
+ return _context20.abrupt("return", _context20.t0);
1333
+ case 14:
1334
+ _context20.prev = 14;
1335
+ this.store.isLoading = false;
1336
+ return _context20.finish(14);
1337
+ case 17:
1338
+ case "end":
1339
+ return _context20.stop();
1340
+ }
1341
+ }, _callee20, this, [[0, 10, 14, 17]]);
1342
+ }));
1343
+ function checkEmailLinkCode(_x18) {
1344
+ return _checkEmailLinkCode.apply(this, arguments);
1345
+ }
1346
+ return checkEmailLinkCode;
1347
+ }() /** 通过code重置密码 */)
1348
+ }, {
1349
+ key: "resetPasswordByCode",
1350
+ value: (function () {
1351
+ var _resetPasswordByCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(params) {
1352
+ var response;
1353
+ return _regeneratorRuntime().wrap(function _callee21$(_context21) {
1354
+ while (1) switch (_context21.prev = _context21.next) {
1355
+ case 0:
1356
+ _context21.prev = 0;
1357
+ this.store.isLoading = true;
1358
+ this.store.error = null;
1359
+ this.core.effects.emit(RegisterAndLoginHooks.onPasswordResetStarted, {
1360
+ code: params.code
1361
+ });
1362
+ _context21.next = 6;
1363
+ return this.apiCaller.call('resetPasswordByCode', params);
1364
+ case 6:
1365
+ response = _context21.sent;
1366
+ if (response.status) {
1367
+ this.core.effects.emit(RegisterAndLoginHooks.onPasswordResetSuccess, {
1368
+ code: params.code
1369
+ });
1370
+ } else {
1371
+ this.store.error = response.message || '密码重置失败';
1372
+ this.core.effects.emit(RegisterAndLoginHooks.onPasswordResetFailed, {
1373
+ code: params.code,
1374
+ error: this.store.error
1375
+ });
1376
+ }
1377
+ return _context21.abrupt("return", response);
1378
+ case 11:
1379
+ _context21.prev = 11;
1380
+ _context21.t0 = _context21["catch"](0);
1381
+ this.store.error = '密码重置失败';
1382
+ this.core.effects.emit(RegisterAndLoginHooks.onPasswordResetFailed, {
1383
+ code: params.code,
1384
+ error: this.store.error
1385
+ });
1386
+ return _context21.abrupt("return", _context21.t0);
1387
+ case 16:
1388
+ _context21.prev = 16;
1389
+ this.store.isLoading = false;
1390
+ return _context21.finish(16);
1391
+ case 19:
1392
+ case "end":
1393
+ return _context21.stop();
1394
+ }
1395
+ }, _callee21, this, [[0, 11, 16, 19]]);
1396
+ }));
1397
+ function resetPasswordByCode(_x19) {
1398
+ return _resetPasswordByCode.apply(this, arguments);
1399
+ }
1400
+ return resetPasswordByCode;
1401
+ }()
1402
+ /**
1403
+ * 重置密码
1404
+ */
1405
+ )
1406
+ }, {
1407
+ key: "resetPassword",
1408
+ value: (function () {
1409
+ var _resetPassword = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(params) {
1410
+ var response, key;
1411
+ return _regeneratorRuntime().wrap(function _callee22$(_context22) {
1412
+ while (1) switch (_context22.prev = _context22.next) {
1413
+ case 0:
1414
+ _context22.prev = 0;
1415
+ this.store.isLoading = true;
1416
+ this.store.error = null;
1417
+
1418
+ // 根据类型触发不同的事件
1419
+ if (params.type === 'email') {
1420
+ this.core.effects.emit(RegisterAndLoginHooks.onPasswordResetStarted, {
1421
+ email: params.target.email
1422
+ });
1423
+ } else {
1424
+ this.core.effects.emit(RegisterAndLoginHooks.onPasswordResetStarted, {
1425
+ phone: params.target.phone
1426
+ });
1427
+ }
1428
+ if (!(params.type === 'email')) {
1429
+ _context22.next = 12;
1430
+ break;
1431
+ }
1432
+ if (params.target.email) {
1433
+ _context22.next = 7;
1434
+ break;
1435
+ }
1436
+ throw new Error('邮箱地址不能为空');
1437
+ case 7:
1438
+ _context22.next = 9;
1439
+ return this.apiCaller.call('resetPasswordByEmail', {
1440
+ email: params.target.email,
1441
+ password: params.password,
1442
+ code: params.code
1443
+ });
1444
+ case 9:
1445
+ response = _context22.sent;
1446
+ _context22.next = 17;
1447
+ break;
1448
+ case 12:
1449
+ if (!(!params.target.phone || !params.target.country_calling_code)) {
1450
+ _context22.next = 14;
1451
+ break;
1452
+ }
1453
+ throw new Error('手机号和国家区号不能为空');
1454
+ case 14:
1455
+ _context22.next = 16;
1456
+ return this.apiCaller.call('resetPasswordByPhone', {
1457
+ phone: params.target.phone,
1458
+ password: params.password,
1459
+ code: params.code,
1460
+ country_calling_code: params.target.country_calling_code
1461
+ });
1462
+ case 16:
1463
+ response = _context22.sent;
1464
+ case 17:
1465
+ if (response.status) {
1466
+ // 清除验证码发送状态
1467
+ key = params.type === 'email' ? params.target.email : params.target.phone;
1468
+ if (this.store.verificationCodeSent[key]) {
1469
+ delete this.store.verificationCodeSent[key];
1470
+ }
1471
+ if (params.type === 'email') {
1472
+ this.core.effects.emit(RegisterAndLoginHooks.onPasswordResetSuccess, {
1473
+ email: params.target.email
1474
+ });
1475
+ } else {
1476
+ this.core.effects.emit(RegisterAndLoginHooks.onPasswordResetSuccess, {
1477
+ phone: params.target.phone
1478
+ });
1479
+ }
1480
+ } else {
1481
+ this.store.error = response.message || '密码重置失败';
1482
+ if (params.type === 'email') {
1483
+ this.core.effects.emit(RegisterAndLoginHooks.onPasswordResetFailed, {
1484
+ email: params.target.email,
1485
+ error: this.store.error
1486
+ });
1487
+ } else {
1488
+ this.core.effects.emit(RegisterAndLoginHooks.onPasswordResetFailed, {
1489
+ phone: params.target.phone,
1490
+ error: this.store.error
1491
+ });
1492
+ }
1493
+ }
1494
+ return _context22.abrupt("return", response);
1495
+ case 21:
1496
+ _context22.prev = 21;
1497
+ _context22.t0 = _context22["catch"](0);
1498
+ this.store.error = '密码重置失败';
1499
+ if (params.type === 'email') {
1500
+ this.core.effects.emit(RegisterAndLoginHooks.onPasswordResetFailed, {
1501
+ email: params.target.email,
1502
+ error: this.store.error
1503
+ });
1504
+ } else {
1505
+ this.core.effects.emit(RegisterAndLoginHooks.onPasswordResetFailed, {
1506
+ phone: params.target.phone,
1507
+ error: this.store.error
1508
+ });
1509
+ }
1510
+ return _context22.abrupt("return", _context22.t0);
1511
+ case 26:
1512
+ _context22.prev = 26;
1513
+ this.store.isLoading = false;
1514
+ return _context22.finish(26);
1515
+ case 29:
1516
+ case "end":
1517
+ return _context22.stop();
1518
+ }
1519
+ }, _callee22, this, [[0, 21, 26, 29]]);
1520
+ }));
1521
+ function resetPassword(_x20) {
1522
+ return _resetPassword.apply(this, arguments);
1523
+ }
1524
+ return resetPassword;
1525
+ }() /** 发送手机登录验证码 */)
1526
+ }, {
1527
+ key: "sendSmsLoginCode",
1528
+ value: (function () {
1529
+ var _sendSmsLoginCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(params) {
1530
+ var response, now;
1531
+ return _regeneratorRuntime().wrap(function _callee23$(_context23) {
1532
+ while (1) switch (_context23.prev = _context23.next) {
1533
+ case 0:
1534
+ _context23.prev = 0;
1535
+ this.store.isLoading = true;
1536
+ this.store.error = null;
1537
+ _context23.next = 5;
1538
+ return this.apiCaller.call('sendSmsLoginCode', params);
1539
+ case 5:
1540
+ response = _context23.sent;
1541
+ if (!response.status) {
1542
+ _context23.next = 13;
1543
+ break;
1544
+ }
1545
+ // 记录验证码发送状态
1546
+ now = Date.now();
1547
+ this.store.verificationCodeSent[params.phone] = {
1548
+ sent: true,
1549
+ sentAt: now,
1550
+ expiresAt: now + 5 * 60 * 1000 // 5分钟过期
1551
+ };
1552
+ _context23.next = 11;
1553
+ return this.core.effects.emit(RegisterAndLoginHooks.onSmsVerificationSent, {
1554
+ target: params.phone,
1555
+ purpose: VerificationPurpose.LOGIN
1556
+ });
1557
+ case 11:
1558
+ _context23.next = 16;
1559
+ break;
1560
+ case 13:
1561
+ this.store.error = response.message || '发送登录验证码失败';
1562
+ _context23.next = 16;
1563
+ return this.core.effects.emit(RegisterAndLoginHooks.onSmsVerificationFailed, {
1564
+ target: params.phone,
1565
+ error: this.store.error
1566
+ });
1567
+ case 16:
1568
+ return _context23.abrupt("return", response);
1569
+ case 19:
1570
+ _context23.prev = 19;
1571
+ _context23.t0 = _context23["catch"](0);
1572
+ this.store.error = '发送登录验证码失败';
1573
+ _context23.next = 24;
1574
+ return this.core.effects.emit(RegisterAndLoginHooks.onSmsVerificationFailed, {
1575
+ target: params.phone,
1576
+ error: this.store.error
1577
+ });
1578
+ case 24:
1579
+ return _context23.abrupt("return", _context23.t0);
1580
+ case 25:
1581
+ _context23.prev = 25;
1582
+ this.store.isLoading = false;
1583
+ return _context23.finish(25);
1584
+ case 28:
1585
+ case "end":
1586
+ return _context23.stop();
1587
+ }
1588
+ }, _callee23, this, [[0, 19, 25, 28]]);
1589
+ }));
1590
+ function sendSmsLoginCode(_x21) {
1591
+ return _sendSmsLoginCode.apply(this, arguments);
1592
+ }
1593
+ return sendSmsLoginCode;
1594
+ }() /** 手机号+短信验证码登录 */)
1595
+ }, {
1596
+ key: "phoneCodeLogin",
1597
+ value: (function () {
1598
+ var _phoneCodeLogin = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(params) {
1599
+ var response;
1600
+ return _regeneratorRuntime().wrap(function _callee24$(_context24) {
1601
+ while (1) switch (_context24.prev = _context24.next) {
1602
+ case 0:
1603
+ _context24.prev = 0;
1604
+ this.store.isLoading = true;
1605
+ this.store.error = null;
1606
+ _context24.next = 5;
1607
+ return this.core.effects.emit(RegisterAndLoginHooks.onLoginStarted, {
1608
+ type: 'phone-code',
1609
+ phone: params.phone
1610
+ });
1611
+ case 5:
1612
+ _context24.next = 7;
1613
+ return this.apiCaller.call('phoneCodeLogin', params);
1614
+ case 7:
1615
+ response = _context24.sent;
1616
+ if (!(response.status && response.data)) {
1617
+ _context24.next = 17;
1618
+ break;
1619
+ }
1620
+ // 保存用户信息和 token
1621
+ this.store.isLoggedIn = true;
1622
+ this.store.userInfo = response.data.user;
1623
+ this.store.token = response.data.token;
1624
+
1625
+ // 如果有 refreshToken,也保存
1626
+ if (response.data.refreshToken) {
1627
+ this.store.refreshToken = response.data.refreshToken;
1628
+ }
1629
+ _context24.next = 15;
1630
+ return this.core.effects.emit(RegisterAndLoginHooks.onLoginSuccess, {
1631
+ user: response.data.user,
1632
+ token: response.data.token,
1633
+ loginType: 'phone-code'
1634
+ });
1635
+ case 15:
1636
+ _context24.next = 20;
1637
+ break;
1638
+ case 17:
1639
+ this.store.error = response.message || '手机号验证码登录失败';
1640
+ _context24.next = 20;
1641
+ return this.core.effects.emit(RegisterAndLoginHooks.onLoginFailed, {
1642
+ error: this.store.error,
1643
+ loginType: 'phone-code'
1644
+ });
1645
+ case 20:
1646
+ return _context24.abrupt("return", response);
1647
+ case 23:
1648
+ _context24.prev = 23;
1649
+ _context24.t0 = _context24["catch"](0);
1650
+ this.store.error = '手机号验证码登录失败';
1651
+ _context24.next = 28;
1652
+ return this.core.effects.emit(RegisterAndLoginHooks.onLoginFailed, {
1653
+ error: this.store.error,
1654
+ loginType: 'phone-code'
1655
+ });
1656
+ case 28:
1657
+ return _context24.abrupt("return", _context24.t0);
1658
+ case 29:
1659
+ _context24.prev = 29;
1660
+ this.store.isLoading = false;
1661
+ return _context24.finish(29);
1662
+ case 32:
1663
+ case "end":
1664
+ return _context24.stop();
1665
+ }
1666
+ }, _callee24, this, [[0, 23, 29, 32]]);
1667
+ }));
1668
+ function phoneCodeLogin(_x22) {
1669
+ return _phoneCodeLogin.apply(this, arguments);
1670
+ }
1671
+ return phoneCodeLogin;
1672
+ }() /** Guest 登录 */)
1673
+ }, {
1674
+ key: "guestLogin",
1675
+ value: (function () {
1676
+ var _guestLogin = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
1677
+ var response;
1678
+ return _regeneratorRuntime().wrap(function _callee25$(_context25) {
1679
+ while (1) switch (_context25.prev = _context25.next) {
1680
+ case 0:
1681
+ _context25.prev = 0;
1682
+ this.store.isLoading = true;
1683
+ this.store.error = null;
1684
+ this.core.effects.emit(RegisterAndLoginHooks.onLoginStarted, {
1685
+ type: 'guest'
1686
+ });
1687
+ _context25.next = 6;
1688
+ return this.apiCaller.call('guestLogin', this.channel);
1689
+ case 6:
1690
+ response = _context25.sent;
1691
+ if (response.status && response.data) {
1692
+ // 保存用户信息和 token
1693
+ this.store.isLoggedIn = true;
1694
+ this.store.userInfo = response.data.user;
1695
+ this.store.token = response.data.token;
1696
+
1697
+ // 如果有 refreshToken,也保存
1698
+ if (response.data.refreshToken) {
1699
+ this.store.refreshToken = response.data.refreshToken;
1700
+ }
1701
+ this.core.effects.emit(RegisterAndLoginHooks.onLoginSuccess, {
1702
+ user: response.data.user,
1703
+ token: response.data.token,
1704
+ loginType: 'guest'
1705
+ });
1706
+ } else {
1707
+ this.store.error = response.message || 'Guest 登录失败';
1708
+ this.core.effects.emit(RegisterAndLoginHooks.onLoginFailed, {
1709
+ error: this.store.error,
1710
+ loginType: 'guest'
1711
+ });
1712
+ }
1713
+ return _context25.abrupt("return", response);
1714
+ case 11:
1715
+ _context25.prev = 11;
1716
+ _context25.t0 = _context25["catch"](0);
1717
+ this.store.error = 'Guest 登录失败';
1718
+ this.core.effects.emit(RegisterAndLoginHooks.onLoginFailed, {
1719
+ error: this.store.error,
1720
+ loginType: 'guest'
1721
+ });
1722
+ return _context25.abrupt("return", _context25.t0);
1723
+ case 16:
1724
+ _context25.prev = 16;
1725
+ this.store.isLoading = false;
1726
+ return _context25.finish(16);
1727
+ case 19:
1728
+ case "end":
1729
+ return _context25.stop();
1730
+ }
1731
+ }, _callee25, this, [[0, 11, 16, 19]]);
1732
+ }));
1733
+ function guestLogin() {
1734
+ return _guestLogin.apply(this, arguments);
1735
+ }
1736
+ return guestLogin;
1737
+ }() /** 检查邮箱是否已注册 */)
1738
+ }, {
1739
+ key: "checkEmailExists",
1740
+ value: (function () {
1741
+ var _checkEmailExists = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(params) {
1742
+ var response;
1743
+ return _regeneratorRuntime().wrap(function _callee26$(_context26) {
1744
+ while (1) switch (_context26.prev = _context26.next) {
1745
+ case 0:
1746
+ _context26.prev = 0;
1747
+ this.store.isLoading = true;
1748
+ this.store.error = null;
1749
+ _context26.next = 5;
1750
+ return this.apiCaller.call('checkEmailExists', params);
1751
+ case 5:
1752
+ response = _context26.sent;
1753
+ if (!response.status) {
1754
+ this.store.error = response.message || '检查邮箱失败';
1755
+ }
1756
+ return _context26.abrupt("return", response);
1757
+ case 10:
1758
+ _context26.prev = 10;
1759
+ _context26.t0 = _context26["catch"](0);
1760
+ this.store.error = '检查邮箱失败';
1761
+ return _context26.abrupt("return", _context26.t0);
1762
+ case 14:
1763
+ _context26.prev = 14;
1764
+ this.store.isLoading = false;
1765
+ return _context26.finish(14);
1766
+ case 17:
1767
+ case "end":
1768
+ return _context26.stop();
1769
+ }
1770
+ }, _callee26, this, [[0, 10, 14, 17]]);
1771
+ }));
1772
+ function checkEmailExists(_x23) {
1773
+ return _checkEmailExists.apply(this, arguments);
1774
+ }
1775
+ return checkEmailExists;
1776
+ }() /** 检查邮箱验证码是否有效 */)
1777
+ }, {
1778
+ key: "checkEmailCode",
1779
+ value: (function () {
1780
+ var _checkEmailCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(params) {
1781
+ var response;
1782
+ return _regeneratorRuntime().wrap(function _callee27$(_context27) {
1783
+ while (1) switch (_context27.prev = _context27.next) {
1784
+ case 0:
1785
+ _context27.prev = 0;
1786
+ this.store.isLoading = true;
1787
+ this.store.error = null;
1788
+ _context27.next = 5;
1789
+ return this.apiCaller.call('checkEmailCode', params);
1790
+ case 5:
1791
+ response = _context27.sent;
1792
+ if (!response.status) {
1793
+ this.store.error = response.message || '检查邮箱验证码失败';
1794
+ }
1795
+ return _context27.abrupt("return", response);
1796
+ case 10:
1797
+ _context27.prev = 10;
1798
+ _context27.t0 = _context27["catch"](0);
1799
+ this.store.error = '检查邮箱验证码失败';
1800
+ return _context27.abrupt("return", _context27.t0);
1801
+ case 14:
1802
+ _context27.prev = 14;
1803
+ this.store.isLoading = false;
1804
+ return _context27.finish(14);
1805
+ case 17:
1806
+ case "end":
1807
+ return _context27.stop();
1808
+ }
1809
+ }, _callee27, this, [[0, 10, 14, 17]]);
1810
+ }));
1811
+ function checkEmailCode(_x24) {
1812
+ return _checkEmailCode.apply(this, arguments);
1813
+ }
1814
+ return checkEmailCode;
1815
+ }() /** 检查手机验证码是否有效 */)
1816
+ }, {
1817
+ key: "checkMobileCode",
1818
+ value: (function () {
1819
+ var _checkMobileCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(params) {
1820
+ var response;
1821
+ return _regeneratorRuntime().wrap(function _callee28$(_context28) {
1822
+ while (1) switch (_context28.prev = _context28.next) {
1823
+ case 0:
1824
+ _context28.prev = 0;
1825
+ this.store.isLoading = true;
1826
+ this.store.error = null;
1827
+ _context28.next = 5;
1828
+ return this.apiCaller.call('checkMobileCode', params);
1829
+ case 5:
1830
+ response = _context28.sent;
1831
+ if (!response.status) {
1832
+ this.store.error = response.message || '检查手机验证码失败';
1833
+ }
1834
+ return _context28.abrupt("return", response);
1835
+ case 10:
1836
+ _context28.prev = 10;
1837
+ _context28.t0 = _context28["catch"](0);
1838
+ this.store.error = '检查手机验证码失败';
1839
+ return _context28.abrupt("return", _context28.t0);
1840
+ case 14:
1841
+ _context28.prev = 14;
1842
+ this.store.isLoading = false;
1843
+ return _context28.finish(14);
1844
+ case 17:
1845
+ case "end":
1846
+ return _context28.stop();
1847
+ }
1848
+ }, _callee28, this, [[0, 10, 14, 17]]);
1849
+ }));
1850
+ function checkMobileCode(_x25) {
1851
+ return _checkMobileCode.apply(this, arguments);
1852
+ }
1853
+ return checkMobileCode;
1854
+ }() /** 手机号密码登录 */)
1855
+ }, {
1856
+ key: "phonePasswordLogin",
1857
+ value: (function () {
1858
+ var _phonePasswordLogin = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(params) {
1859
+ var response;
1860
+ return _regeneratorRuntime().wrap(function _callee29$(_context29) {
1861
+ while (1) switch (_context29.prev = _context29.next) {
1862
+ case 0:
1863
+ _context29.prev = 0;
1864
+ this.store.isLoading = true;
1865
+ this.store.error = null;
1866
+ this.core.effects.emit(RegisterAndLoginHooks.onLoginStarted, {
1867
+ type: 'phone-password',
1868
+ phone: params.phone
1869
+ });
1870
+ _context29.next = 6;
1871
+ return this.apiCaller.call('phonePasswordLogin', params);
1872
+ case 6:
1873
+ response = _context29.sent;
1874
+ if (response.status && response.data) {
1875
+ // 保存用户信息和 token
1876
+ this.store.isLoggedIn = true;
1877
+ this.store.userInfo = response.data.user;
1878
+ this.store.token = response.data.token;
1879
+
1880
+ // 如果有 refreshToken,也保存
1881
+ if (response.data.refreshToken) {
1882
+ this.store.refreshToken = response.data.refreshToken;
1883
+ }
1884
+ this.core.effects.emit(RegisterAndLoginHooks.onLoginSuccess, {
1885
+ user: response.data.user,
1886
+ token: response.data.token,
1887
+ loginType: 'phone-password'
1888
+ });
1889
+ } else {
1890
+ this.store.error = response.message || '手机号密码登录失败';
1891
+ this.core.effects.emit(RegisterAndLoginHooks.onLoginFailed, {
1892
+ error: this.store.error,
1893
+ loginType: 'phone-password'
1894
+ });
1895
+ }
1896
+ return _context29.abrupt("return", response);
1897
+ case 11:
1898
+ _context29.prev = 11;
1899
+ _context29.t0 = _context29["catch"](0);
1900
+ this.store.error = '手机号密码登录失败';
1901
+ this.core.effects.emit(RegisterAndLoginHooks.onLoginFailed, {
1902
+ error: this.store.error,
1903
+ loginType: 'phone-password'
1904
+ });
1905
+ return _context29.abrupt("return", _context29.t0);
1906
+ case 16:
1907
+ _context29.prev = 16;
1908
+ this.store.isLoading = false;
1909
+ return _context29.finish(16);
1910
+ case 19:
1911
+ case "end":
1912
+ return _context29.stop();
1913
+ }
1914
+ }, _callee29, this, [[0, 11, 16, 19]]);
1915
+ }));
1916
+ function phonePasswordLogin(_x26) {
1917
+ return _phonePasswordLogin.apply(this, arguments);
1918
+ }
1919
+ return phonePasswordLogin;
1920
+ }() /** 发送密码重置邮箱验证码 */)
1921
+ }, {
1922
+ key: "sendPasswordResetEmail",
1923
+ value: (function () {
1924
+ var _sendPasswordResetEmail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30(params) {
1925
+ var response, now;
1926
+ return _regeneratorRuntime().wrap(function _callee30$(_context30) {
1927
+ while (1) switch (_context30.prev = _context30.next) {
1928
+ case 0:
1929
+ _context30.prev = 0;
1930
+ this.store.isLoading = true;
1931
+ this.store.error = null;
1932
+ _context30.next = 5;
1933
+ return this.apiCaller.call('sendPasswordResetEmail', params);
1934
+ case 5:
1935
+ response = _context30.sent;
1936
+ if (response.status) {
1937
+ // 记录验证码发送状态
1938
+ now = Date.now();
1939
+ this.store.verificationCodeSent[params.email] = {
1940
+ sent: true,
1941
+ sentAt: now,
1942
+ expiresAt: now + 10 * 60 * 1000 // 10分钟过期
1943
+ };
1944
+ this.core.effects.emit(RegisterAndLoginHooks.onEmailVerificationSent, {
1945
+ target: params.email,
1946
+ purpose: VerificationPurpose.PASSWORD_RESET
1947
+ });
1948
+ } else {
1949
+ this.store.error = response.message || '发送密码重置验证码失败';
1950
+ this.core.effects.emit(RegisterAndLoginHooks.onEmailVerificationFailed, {
1951
+ target: params.email,
1952
+ error: this.store.error
1953
+ });
1954
+ }
1955
+ return _context30.abrupt("return", response);
1956
+ case 10:
1957
+ _context30.prev = 10;
1958
+ _context30.t0 = _context30["catch"](0);
1959
+ this.store.error = '发送密码重置验证码失败';
1960
+ this.core.effects.emit(RegisterAndLoginHooks.onEmailVerificationFailed, {
1961
+ target: params.email,
1962
+ error: this.store.error
1963
+ });
1964
+ return _context30.abrupt("return", _context30.t0);
1965
+ case 15:
1966
+ _context30.prev = 15;
1967
+ this.store.isLoading = false;
1968
+ return _context30.finish(15);
1969
+ case 18:
1970
+ case "end":
1971
+ return _context30.stop();
1972
+ }
1973
+ }, _callee30, this, [[0, 10, 15, 18]]);
1974
+ }));
1975
+ function sendPasswordResetEmail(_x27) {
1976
+ return _sendPasswordResetEmail.apply(this, arguments);
1977
+ }
1978
+ return sendPasswordResetEmail;
1979
+ }() /** 发送手机号验证码重置密码 */)
1980
+ }, {
1981
+ key: "sendPasswordResetSms",
1982
+ value: (function () {
1983
+ var _sendPasswordResetSms = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(params) {
1984
+ var response;
1985
+ return _regeneratorRuntime().wrap(function _callee31$(_context31) {
1986
+ while (1) switch (_context31.prev = _context31.next) {
1987
+ case 0:
1988
+ _context31.prev = 0;
1989
+ this.store.isLoading = true;
1990
+ this.store.error = null;
1991
+ _context31.next = 5;
1992
+ return this.apiCaller.call('sendPasswordResetSms', params);
1993
+ case 5:
1994
+ response = _context31.sent;
1995
+ if (!response.status) {
1996
+ _context31.next = 10;
1997
+ break;
1998
+ }
1999
+ return _context31.abrupt("return", response);
2000
+ case 10:
2001
+ this.store.error = response.message || '发送手机号验证码重置密码失败';
2002
+ case 11:
2003
+ return _context31.abrupt("return", response);
2004
+ case 14:
2005
+ _context31.prev = 14;
2006
+ _context31.t0 = _context31["catch"](0);
2007
+ this.store.error = '发送手机号验证码重置密码失败';
2008
+ return _context31.abrupt("return", _context31.t0);
2009
+ case 18:
2010
+ _context31.prev = 18;
2011
+ this.store.isLoading = false;
2012
+ return _context31.finish(18);
2013
+ case 21:
2014
+ case "end":
2015
+ return _context31.stop();
2016
+ }
2017
+ }, _callee31, this, [[0, 14, 18, 21]]);
2018
+ }));
2019
+ function sendPasswordResetSms(_x28) {
2020
+ return _sendPasswordResetSms.apply(this, arguments);
2021
+ }
2022
+ return sendPasswordResetSms;
2023
+ }()
2024
+ /**
2025
+ * 获取当前用户信息
2026
+ */
2027
+ )
2028
+ }, {
2029
+ key: "getCurrentUser",
2030
+ value: function getCurrentUser() {
2031
+ return this.store.currentUser;
2032
+ }
2033
+
2034
+ /**
2035
+ * 检查是否已登录
2036
+ */
2037
+ }, {
2038
+ key: "isLoggedIn",
2039
+ value: function isLoggedIn() {
2040
+ return this.store.isLoggedIn;
2041
+ }
2042
+
2043
+ /**
2044
+ * 获取加载状态
2045
+ */
2046
+ }, {
2047
+ key: "isLoading",
2048
+ value: function isLoading() {
2049
+ return this.store.isLoading;
2050
+ }
2051
+
2052
+ /**
2053
+ * 获取错误信息
2054
+ */
2055
+ }, {
2056
+ key: "getError",
2057
+ value: function getError() {
2058
+ return this.store.error;
2059
+ }
2060
+
2061
+ /**
2062
+ * 清除错误信息
2063
+ */
2064
+ }, {
2065
+ key: "clearError",
2066
+ value: function clearError() {
2067
+ this.store.error = null;
2068
+ }
2069
+
2070
+ /**
2071
+ * 检查验证码是否已发送且未过期
2072
+ */
2073
+ }, {
2074
+ key: "isVerificationCodeSent",
2075
+ value: function isVerificationCodeSent(target) {
2076
+ var codeInfo = this.store.verificationCodeSent[target];
2077
+ if (!codeInfo || !codeInfo.sent) {
2078
+ return false;
2079
+ }
2080
+ return Date.now() < codeInfo.expiresAt;
2081
+ }
2082
+
2083
+ /**
2084
+ * 获取验证码剩余时间(秒)
2085
+ */
2086
+ }, {
2087
+ key: "getVerificationCodeRemainingTime",
2088
+ value: function getVerificationCodeRemainingTime(target) {
2089
+ var codeInfo = this.store.verificationCodeSent[target];
2090
+ if (!codeInfo || !codeInfo.sent) {
2091
+ return 0;
2092
+ }
2093
+ var remaining = Math.max(0, codeInfo.expiresAt - Date.now());
2094
+ return Math.ceil(remaining / 1000);
2095
+ }
2096
+
2097
+ /**
2098
+ * 初始化 Facebook SDK
2099
+ */
2100
+ }, {
2101
+ key: "initFacebookSDK",
2102
+ value: (function () {
2103
+ var _initFacebookSDK = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32(token) {
2104
+ return _regeneratorRuntime().wrap(function _callee32$(_context32) {
2105
+ while (1) switch (_context32.prev = _context32.next) {
2106
+ case 0:
2107
+ return _context32.abrupt("return", new Promise(function (resolve, reject) {
2108
+ if (typeof window === 'undefined') {
2109
+ reject(new Error('Facebook SDK 只能在浏览器环境中使用'));
2110
+ return;
2111
+ }
2112
+
2113
+ // 检查是否已经加载
2114
+ if (window.FB) {
2115
+ resolve();
2116
+ return;
2117
+ }
2118
+
2119
+ // 动态加载 Facebook SDK
2120
+ var script = document.createElement('script');
2121
+ script.src = 'https://connect.facebook.net/en_US/sdk.js';
2122
+ script.async = true;
2123
+ script.defer = true;
2124
+ script.crossOrigin = 'anonymous';
2125
+ script.onload = function () {
2126
+ window.FB.init({
2127
+ appId: token,
2128
+ cookie: true,
2129
+ xfbml: true,
2130
+ version: 'v18.0'
2131
+ });
2132
+ resolve();
2133
+ };
2134
+ script.onerror = function () {
2135
+ reject(new Error('Facebook SDK 加载失败'));
2136
+ };
2137
+ document.head.appendChild(script);
2138
+ }));
2139
+ case 1:
2140
+ case "end":
2141
+ return _context32.stop();
2142
+ }
2143
+ }, _callee32);
2144
+ }));
2145
+ function initFacebookSDK(_x29) {
2146
+ return _initFacebookSDK.apply(this, arguments);
2147
+ }
2148
+ return initFacebookSDK;
2149
+ }()
2150
+ /**
2151
+ * 初始化 Apple SDK
2152
+ */
2153
+ )
2154
+ }, {
2155
+ key: "initAppleSDK",
2156
+ value: (function () {
2157
+ var _initAppleSDK = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33() {
2158
+ return _regeneratorRuntime().wrap(function _callee33$(_context33) {
2159
+ while (1) switch (_context33.prev = _context33.next) {
2160
+ case 0:
2161
+ return _context33.abrupt("return", new Promise(function (resolve, reject) {
2162
+ if (typeof window === 'undefined') {
2163
+ reject(new Error('Apple SDK 只能在浏览器环境中使用'));
2164
+ return;
2165
+ }
2166
+
2167
+ // 检查是否已经加载
2168
+ if (window.AppleID) {
2169
+ resolve();
2170
+ return;
2171
+ }
2172
+
2173
+ // 动态加载 Apple SDK
2174
+ var script = document.createElement('script');
2175
+ script.src = 'https://file.mypisell-dev.com/static/apple.js';
2176
+ script.async = true;
2177
+ script.defer = true;
2178
+ script.crossOrigin = 'anonymous';
2179
+ script.onload = function () {
2180
+ // Apple SDK 加载完成后,需要等待一下确保 AppleID 对象可用
2181
+ setTimeout(function () {
2182
+ if (window.AppleID) {
2183
+ resolve();
2184
+ } else {
2185
+ reject(new Error('Apple SDK 加载失败:AppleID 对象不可用'));
2186
+ }
2187
+ }, 100);
2188
+ };
2189
+ script.onerror = function () {
2190
+ reject(new Error('Apple SDK 加载失败'));
2191
+ };
2192
+ document.head.appendChild(script);
2193
+ }));
2194
+ case 1:
2195
+ case "end":
2196
+ return _context33.stop();
2197
+ }
2198
+ }, _callee33);
2199
+ }));
2200
+ function initAppleSDK() {
2201
+ return _initAppleSDK.apply(this, arguments);
2202
+ }
2203
+ return initAppleSDK;
2204
+ }()
2205
+ /**
2206
+ * Facebook 登录
2207
+ */
2208
+ )
2209
+ }, {
2210
+ key: "loginWithFacebook",
2211
+ value: (function () {
2212
+ var _loginWithFacebook = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(token) {
2213
+ var _this2 = this;
2214
+ return _regeneratorRuntime().wrap(function _callee35$(_context35) {
2215
+ while (1) switch (_context35.prev = _context35.next) {
2216
+ case 0:
2217
+ _context35.next = 2;
2218
+ return this.initFacebookSDK(token);
2219
+ case 2:
2220
+ return _context35.abrupt("return", new Promise(function (resolve, reject) {
2221
+ window.FB.login( /*#__PURE__*/function () {
2222
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(response) {
2223
+ var result;
2224
+ return _regeneratorRuntime().wrap(function _callee34$(_context34) {
2225
+ while (1) switch (_context34.prev = _context34.next) {
2226
+ case 0:
2227
+ if (!response.authResponse) {
2228
+ _context34.next = 13;
2229
+ break;
2230
+ }
2231
+ _context34.prev = 1;
2232
+ _context34.next = 4;
2233
+ return _this2.apiCaller.call('facebookLogin', {
2234
+ token: response.authResponse.accessToken
2235
+ });
2236
+ case 4:
2237
+ result = _context34.sent;
2238
+ resolve(result);
2239
+ _context34.next = 11;
2240
+ break;
2241
+ case 8:
2242
+ _context34.prev = 8;
2243
+ _context34.t0 = _context34["catch"](1);
2244
+ reject(_context34.t0);
2245
+ case 11:
2246
+ _context34.next = 14;
2247
+ break;
2248
+ case 13:
2249
+ reject(new Error('facebook_login_cancel'));
2250
+ case 14:
2251
+ case "end":
2252
+ return _context34.stop();
2253
+ }
2254
+ }, _callee34, null, [[1, 8]]);
2255
+ }));
2256
+ return function (_x31) {
2257
+ return _ref.apply(this, arguments);
2258
+ };
2259
+ }(), {
2260
+ scope: 'email,public_profile'
2261
+ });
2262
+ }));
2263
+ case 3:
2264
+ case "end":
2265
+ return _context35.stop();
2266
+ }
2267
+ }, _callee35, this);
2268
+ }));
2269
+ function loginWithFacebook(_x30) {
2270
+ return _loginWithFacebook.apply(this, arguments);
2271
+ }
2272
+ return loginWithFacebook;
2273
+ }()
2274
+ /**
2275
+ * Apple 登录(需要在支持的环境中使用)
2276
+ */
2277
+ )
2278
+ }, {
2279
+ key: "loginWithApple",
2280
+ value: (function () {
2281
+ var _loginWithApple = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(token) {
2282
+ var _this3 = this;
2283
+ return _regeneratorRuntime().wrap(function _callee37$(_context37) {
2284
+ while (1) switch (_context37.prev = _context37.next) {
2285
+ case 0:
2286
+ _context37.next = 2;
2287
+ return this.initAppleSDK();
2288
+ case 2:
2289
+ return _context37.abrupt("return", new Promise(function (resolve, reject) {
2290
+ try {
2291
+ var _AppleID, _AppleID2;
2292
+ // 动态创建 Apple 登录按钮元素
2293
+ var appleSignInDiv = document.createElement('div');
2294
+ appleSignInDiv.id = 'appleid-signin-temp';
2295
+ appleSignInDiv.setAttribute('data-color', 'black');
2296
+ appleSignInDiv.setAttribute('data-border', 'false');
2297
+ appleSignInDiv.setAttribute('data-type', 'sign-in');
2298
+ appleSignInDiv.setAttribute('data-mode', 'logo-only');
2299
+ appleSignInDiv.setAttribute('data-logo-size', 'small');
2300
+ appleSignInDiv.style.opacity = '0';
2301
+ appleSignInDiv.style.position = 'absolute';
2302
+ appleSignInDiv.style.left = '-9999px';
2303
+ appleSignInDiv.style.top = '-9999px';
2304
+ appleSignInDiv.style.width = '1px';
2305
+ appleSignInDiv.style.height = '1px';
2306
+
2307
+ // 将元素添加到 body 中
2308
+ document.body.appendChild(appleSignInDiv);
2309
+
2310
+ // 初始化 Apple ID 按钮
2311
+ if ((_AppleID = window.AppleID) !== null && _AppleID !== void 0 && (_AppleID = _AppleID.auth) !== null && _AppleID !== void 0 && _AppleID.init) {
2312
+ window.AppleID.auth.init({
2313
+ clientId: token,
2314
+ // 使用传入的 token 作为 clientId
2315
+ scope: 'name email',
2316
+ redirectURI: window.location.origin,
2317
+ state: 'signin',
2318
+ usePopup: true
2319
+ });
2320
+ }
2321
+
2322
+ // 直接调用 Apple ID 登录,并处理 Promise
2323
+ if ((_AppleID2 = window.AppleID) !== null && _AppleID2 !== void 0 && (_AppleID2 = _AppleID2.auth) !== null && _AppleID2 !== void 0 && _AppleID2.signIn) {
2324
+ window.AppleID.auth.signIn().then( /*#__PURE__*/function () {
2325
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(authResult) {
2326
+ var _authResult$authoriza, _authResult$authoriza2, authorizationCode, identityToken, result;
2327
+ return _regeneratorRuntime().wrap(function _callee36$(_context36) {
2328
+ while (1) switch (_context36.prev = _context36.next) {
2329
+ case 0:
2330
+ _context36.prev = 0;
2331
+ // 清理临时元素
2332
+ if (document.body.contains(appleSignInDiv)) {
2333
+ document.body.removeChild(appleSignInDiv);
2334
+ }
2335
+
2336
+ // 获取授权码或令牌
2337
+ authorizationCode = (_authResult$authoriza = authResult.authorization) === null || _authResult$authoriza === void 0 ? void 0 : _authResult$authoriza.code;
2338
+ identityToken = (_authResult$authoriza2 = authResult.authorization) === null || _authResult$authoriza2 === void 0 ? void 0 : _authResult$authoriza2.id_token; // 使用授权码或身份令牌调用后端接口
2339
+ _context36.next = 6;
2340
+ return _this3.apiCaller.call('appleLogin', {
2341
+ token: authorizationCode || identityToken
2342
+ });
2343
+ case 6:
2344
+ result = _context36.sent;
2345
+ resolve(result);
2346
+ _context36.next = 13;
2347
+ break;
2348
+ case 10:
2349
+ _context36.prev = 10;
2350
+ _context36.t0 = _context36["catch"](0);
2351
+ reject(_context36.t0);
2352
+ case 13:
2353
+ case "end":
2354
+ return _context36.stop();
2355
+ }
2356
+ }, _callee36, null, [[0, 10]]);
2357
+ }));
2358
+ return function (_x33) {
2359
+ return _ref2.apply(this, arguments);
2360
+ };
2361
+ }()).catch(function (error) {
2362
+ // 清理临时元素
2363
+ if (document.body.contains(appleSignInDiv)) {
2364
+ document.body.removeChild(appleSignInDiv);
2365
+ }
2366
+ reject(new Error('Apple 登录失败: ' + ((error === null || error === void 0 ? void 0 : error.error) || (error === null || error === void 0 ? void 0 : error.message) || '未知错误')));
2367
+ });
2368
+ } else {
2369
+ reject(new Error('Apple SDK 未正确加载'));
2370
+ }
2371
+ } catch (error) {
2372
+ reject(error);
2373
+ }
2374
+ }));
2375
+ case 3:
2376
+ case "end":
2377
+ return _context37.stop();
2378
+ }
2379
+ }, _callee37, this);
2380
+ }));
2381
+ function loginWithApple(_x32) {
2382
+ return _loginWithApple.apply(this, arguments);
2383
+ }
2384
+ return loginWithApple;
2385
+ }()
2386
+ /**
2387
+ * 更新 OAuth 配置
2388
+ */
2389
+ )
2390
+ }, {
2391
+ key: "updateOAuthConfig",
2392
+ value: function updateOAuthConfig(config) {
2393
+ this.store.oauthConfig = _objectSpread(_objectSpread({}, this.store.oauthConfig), config);
2394
+ }
2395
+
2396
+ /**
2397
+ * 获取当前渠道
2398
+ */
2399
+ }, {
2400
+ key: "getCurrentChannel",
2401
+ value: function getCurrentChannel() {
2402
+ return this.channel;
2403
+ }
2404
+
2405
+ /**
2406
+ * 获取 API 调用器(用于高级用法)
2407
+ */
2408
+ }, {
2409
+ key: "getApiCaller",
2410
+ value: function getApiCaller() {
2411
+ return this.apiCaller;
2412
+ }
2413
+
2414
+ /**
2415
+ * 获取国家区号列表
2416
+ */
2417
+ }, {
2418
+ key: "getCountries",
2419
+ value: (function () {
2420
+ var _getCountries = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38() {
2421
+ var response;
2422
+ return _regeneratorRuntime().wrap(function _callee38$(_context38) {
2423
+ while (1) switch (_context38.prev = _context38.next) {
2424
+ case 0:
2425
+ _context38.prev = 0;
2426
+ this.store.isLoading = true;
2427
+ this.store.error = null;
2428
+ _context38.next = 5;
2429
+ return this.apiCaller.call('getCountries');
2430
+ case 5:
2431
+ response = _context38.sent;
2432
+ if (!(response.status && response.data)) {
2433
+ _context38.next = 10;
2434
+ break;
2435
+ }
2436
+ return _context38.abrupt("return", response.data);
2437
+ case 10:
2438
+ this.store.error = response.message || '获取国家区号失败';
2439
+ throw new Error(this.store.error);
2440
+ case 12:
2441
+ _context38.next = 19;
2442
+ break;
2443
+ case 14:
2444
+ _context38.prev = 14;
2445
+ _context38.t0 = _context38["catch"](0);
2446
+ this.store.error = '获取国家区号失败';
2447
+ console.error('[RegisterAndLogin] 获取国家区号失败:', _context38.t0);
2448
+ throw _context38.t0;
2449
+ case 19:
2450
+ _context38.prev = 19;
2451
+ this.store.isLoading = false;
2452
+ return _context38.finish(19);
2453
+ case 22:
2454
+ case "end":
2455
+ return _context38.stop();
2456
+ }
2457
+ }, _callee38, this, [[0, 14, 19, 22]]);
2458
+ }));
2459
+ function getCountries() {
2460
+ return _getCountries.apply(this, arguments);
2461
+ }
2462
+ return getCountries;
2463
+ }())
2464
+ }, {
2465
+ key: "destroy",
2466
+ value: function () {
2467
+ var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39() {
2468
+ return _regeneratorRuntime().wrap(function _callee39$(_context39) {
2469
+ while (1) switch (_context39.prev = _context39.next) {
2470
+ case 0:
2471
+ _context39.next = 2;
2472
+ return this.core.effects.emit(RegisterAndLoginHooks.onDestroy, {});
2473
+ case 2:
2474
+ console.log('[RegisterAndLogin] 已销毁');
2475
+ case 3:
2476
+ case "end":
2477
+ return _context39.stop();
2478
+ }
2479
+ }, _callee39, this);
2480
+ }));
2481
+ function destroy() {
2482
+ return _destroy.apply(this, arguments);
2483
+ }
2484
+ return destroy;
2485
+ }()
2486
+ }]);
2487
+ return RegisterAndLoginImpl;
2488
+ }(BaseModule);