@pisell/pisellos 0.0.341 → 0.0.342

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.
@@ -154,10 +154,8 @@ var onlineStoreConfig = {
154
154
  guestLogin: {
155
155
  url: '/auth/guest/login',
156
156
  method: 'POST',
157
- transformParams: function transformParams(channel) {
158
- return {
159
- login_channel: channel
160
- };
157
+ transformParams: function transformParams(params) {
158
+ return params;
161
159
  }
162
160
  },
163
161
  checkEmailExists: {
@@ -106,6 +106,7 @@ export declare class RegisterAndLoginImpl extends BaseModule implements Module {
106
106
  sendSmsLoginCode(params: SendSmsLoginCodeParams): Promise<ApiResponse>;
107
107
  /** 手机号+短信验证码登录 */
108
108
  phoneCodeLogin(params: PhoneCodeLoginParams): Promise<ApiResponse<LoginResponse>>;
109
+ private formatLoginParams;
109
110
  /** Guest 登录 */
110
111
  guestLogin(): Promise<ApiResponse<GuestLoginResponse>>;
111
112
  /** 检查邮箱是否已注册 */
@@ -1671,12 +1671,28 @@ export var RegisterAndLoginImpl = /*#__PURE__*/function (_BaseModule) {
1671
1671
  return _phoneCodeLogin.apply(this, arguments);
1672
1672
  }
1673
1673
  return phoneCodeLogin;
1674
- }() /** Guest 登录 */)
1674
+ }())
1675
+ }, {
1676
+ key: "formatLoginParams",
1677
+ value: function formatLoginParams(params) {
1678
+ // 获取当前浏览器窗口的 URL
1679
+ var currentUrl = this.window.location.href;
1680
+ // 使用 URL 对象解析 URL
1681
+ var urlObj = new URL(currentUrl || '');
1682
+ // 获取 customer 参数的值
1683
+ var source_customer_id = urlObj.searchParams.get('customer');
1684
+ if (source_customer_id) {
1685
+ params.source_customer_id = parseInt(source_customer_id);
1686
+ }
1687
+ return params;
1688
+ }
1689
+
1690
+ /** Guest 登录 */
1675
1691
  }, {
1676
1692
  key: "guestLogin",
1677
1693
  value: (function () {
1678
1694
  var _guestLogin = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
1679
- var response;
1695
+ var guestCode, param, response;
1680
1696
  return _regeneratorRuntime().wrap(function _callee25$(_context25) {
1681
1697
  while (1) switch (_context25.prev = _context25.next) {
1682
1698
  case 0:
@@ -1686,9 +1702,20 @@ export var RegisterAndLoginImpl = /*#__PURE__*/function (_BaseModule) {
1686
1702
  this.core.effects.emit(RegisterAndLoginHooks.onLoginStarted, {
1687
1703
  type: 'guest'
1688
1704
  });
1689
- _context25.next = 6;
1690
- return this.apiCaller.call('guestLogin', this.channel);
1691
- case 6:
1705
+ // 匿名登录 code
1706
+ guestCode = this.window.localStorage.getItem('guest_code') || '';
1707
+ param = {
1708
+ login_channel: this.channel
1709
+ };
1710
+ if (guestCode) {
1711
+ param.guest_code = guestCode;
1712
+ }
1713
+
1714
+ // 获取邀请id
1715
+ param = this.formatLoginParams(param);
1716
+ _context25.next = 10;
1717
+ return this.apiCaller.call('guestLogin', param);
1718
+ case 10:
1692
1719
  response = _context25.sent;
1693
1720
  if (response.status && response.data) {
1694
1721
  // 保存用户信息和 token
@@ -1713,8 +1740,8 @@ export var RegisterAndLoginImpl = /*#__PURE__*/function (_BaseModule) {
1713
1740
  });
1714
1741
  }
1715
1742
  return _context25.abrupt("return", response);
1716
- case 11:
1717
- _context25.prev = 11;
1743
+ case 15:
1744
+ _context25.prev = 15;
1718
1745
  _context25.t0 = _context25["catch"](0);
1719
1746
  this.store.error = 'Guest 登录失败';
1720
1747
  this.core.effects.emit(RegisterAndLoginHooks.onLoginFailed, {
@@ -1722,15 +1749,15 @@ export var RegisterAndLoginImpl = /*#__PURE__*/function (_BaseModule) {
1722
1749
  loginType: 'guest'
1723
1750
  });
1724
1751
  return _context25.abrupt("return", _context25.t0);
1725
- case 16:
1726
- _context25.prev = 16;
1752
+ case 20:
1753
+ _context25.prev = 20;
1727
1754
  this.store.isLoading = false;
1728
- return _context25.finish(16);
1729
- case 19:
1755
+ return _context25.finish(20);
1756
+ case 23:
1730
1757
  case "end":
1731
1758
  return _context25.stop();
1732
1759
  }
1733
- }, _callee25, this, [[0, 11, 16, 19]]);
1760
+ }, _callee25, this, [[0, 15, 20, 23]]);
1734
1761
  }));
1735
1762
  function guestLogin() {
1736
1763
  return _guestLogin.apply(this, arguments);
@@ -129,9 +129,7 @@ var onlineStoreConfig = {
129
129
  guestLogin: {
130
130
  url: "/auth/guest/login",
131
131
  method: "POST",
132
- transformParams: (channel) => ({
133
- login_channel: channel
134
- })
132
+ transformParams: (params) => params
135
133
  },
136
134
  checkEmailExists: {
137
135
  url: "/auth/email/check-email",
@@ -106,6 +106,7 @@ export declare class RegisterAndLoginImpl extends BaseModule implements Module {
106
106
  sendSmsLoginCode(params: SendSmsLoginCodeParams): Promise<ApiResponse>;
107
107
  /** 手机号+短信验证码登录 */
108
108
  phoneCodeLogin(params: PhoneCodeLoginParams): Promise<ApiResponse<LoginResponse>>;
109
+ private formatLoginParams;
109
110
  /** Guest 登录 */
110
111
  guestLogin(): Promise<ApiResponse<GuestLoginResponse>>;
111
112
  /** 检查邮箱是否已注册 */
@@ -1015,6 +1015,15 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
1015
1015
  this.store.isLoading = false;
1016
1016
  }
1017
1017
  }
1018
+ formatLoginParams(params) {
1019
+ const currentUrl = this.window.location.href;
1020
+ let urlObj = new URL(currentUrl || "");
1021
+ let source_customer_id = urlObj.searchParams.get("customer");
1022
+ if (source_customer_id) {
1023
+ params.source_customer_id = parseInt(source_customer_id);
1024
+ }
1025
+ return params;
1026
+ }
1018
1027
  /** Guest 登录 */
1019
1028
  async guestLogin() {
1020
1029
  try {
@@ -1023,7 +1032,15 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
1023
1032
  this.core.effects.emit(import_types.RegisterAndLoginHooks.onLoginStarted, {
1024
1033
  type: "guest"
1025
1034
  });
1026
- const response = await this.apiCaller.call("guestLogin", this.channel);
1035
+ let guestCode = this.window.localStorage.getItem("guest_code") || "";
1036
+ let param = {
1037
+ login_channel: this.channel
1038
+ };
1039
+ if (guestCode) {
1040
+ param.guest_code = guestCode;
1041
+ }
1042
+ param = this.formatLoginParams(param);
1043
+ const response = await this.apiCaller.call("guestLogin", param);
1027
1044
  if (response.status && response.data) {
1028
1045
  this.store.isLoggedIn = true;
1029
1046
  this.store.userInfo = response.data.user;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.341",
4
+ "version": "0.0.342",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",