xctc-utils 1.3.1 → 1.3.2

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.
@@ -12,16 +12,22 @@ var defaultKey = "5uMz4R8rop26DkC8";
12
12
  var defaultIv = "5uMz4Rsd0926DkC8";
13
13
  var weixinConfig = {};
14
14
  function weixinUrlCode(config) {
15
+ var _a, _b, _c, _d;
16
+ var appId = (_a = config === null || config === void 0 ? void 0 : config.appId) !== null && _a !== void 0 ? _a : "";
17
+ if (!appId)
18
+ return;
15
19
  weixinConfig = config || {};
20
+ var scope = (_b = config === null || config === void 0 ? void 0 : config.scope) !== null && _b !== void 0 ? _b : "snsapi_userinfo";
21
+ var codeKey = (_c = config === null || config === void 0 ? void 0 : config.codeKey) !== null && _c !== void 0 ? _c : "weixinCode";
22
+ var stateKey = (_d = config === null || config === void 0 ? void 0 : config.stateKey) !== null && _d !== void 0 ? _d : "weixinState";
23
+ weixinConfig['scope'] = scope;
24
+ weixinConfig['codeKey'] = codeKey;
25
+ weixinConfig['stateKey'] = stateKey;
26
+ weixinConfig['scope'] = scope;
16
27
  (0, index_1.useSessionStorage)("weixinConfig", weixinConfig);
17
28
  var cryptoiv = weixinConfig.cryptoiv, cryptokey = weixinConfig.cryptokey;
18
29
  var search = loc.search; // ?code=0916SzFa1KH9TA0Ke7Ha1AQx6446SzFr&state=123
19
30
  // 获取地址栏返回 code 参数
20
- var codeKey = weixinConfig['codeKey'];
21
- if (!codeKey) {
22
- codeKey = "weixinCode";
23
- weixinConfig['codeKey'] = codeKey;
24
- }
25
31
  var localCode = "";
26
32
  if (codeKey)
27
33
  localCode = (0, index_1.getSessionStorage)(codeKey);
@@ -66,17 +72,17 @@ function weixinUrlCode(config) {
66
72
  var item = urlArr[k];
67
73
  if (item.indexOf("state=") != -1) {
68
74
  hrefState = item.substr(6);
69
- var stateKey = weixinConfig['stateKey'];
70
- if (!stateKey) {
71
- stateKey = "weixinState";
72
- weixinConfig['stateKey'] = stateKey;
75
+ var stateKey_1 = weixinConfig['stateKey'];
76
+ if (!stateKey_1) {
77
+ stateKey_1 = "weixinState";
78
+ weixinConfig['stateKey'] = stateKey_1;
73
79
  }
74
- (0, index_1.useSessionStorage)(stateKey, hrefState);
80
+ (0, index_1.useSessionStorage)(stateKey_1, hrefState);
75
81
  var cryptoObj = cryptoConfig(cryptokey, cryptoiv);
76
82
  var stateObj = (0, crypto_1.decrypt)(hrefState, cryptoObj.key, cryptoObj.iv);
77
83
  if (stateObj instanceof Object)
78
84
  stateObj = JSON.stringify(stateObj);
79
- (0, index_1.useSessionStorage)("".concat(stateKey, "Obj"), stateObj);
85
+ (0, index_1.useSessionStorage)("".concat(stateKey_1, "Obj"), stateObj);
80
86
  }
81
87
  }
82
88
  // 将 state进行本地存储,存储完成后跳转到微信授权页面
@@ -130,15 +136,10 @@ function weixinLogin(code) {
130
136
  }
131
137
  var url = loc.origin;
132
138
  var hashVal = loc.hash;
133
- (0, index_1.useSessionStorage)("stateKey===", stateKey);
134
- var state = (0, index_1.getSessionStorage)(stateKey) || "";
139
+ var state = (0, index_1.getSessionStorage)(stateKey);
135
140
  var str = "";
136
- (0, index_1.useSessionStorage)("getstatedata===", state);
137
141
  if (state) {
138
- (0, index_1.useSessionStorage)("stateKey===", "".concat(stateKey, "Obj"));
139
142
  var stateObj = (0, index_1.getSessionStorage)("".concat(stateKey, "Obj"));
140
- (0, index_1.useSessionStorage)("getstateObj===", stateObj);
141
- (0, index_1.useSessionStorage)("url11111===", url);
142
143
  for (var key in stateObj) {
143
144
  if (key == "path") {
144
145
  if (stateObj[key][0] == "/") {
@@ -147,7 +148,6 @@ function weixinLogin(code) {
147
148
  else {
148
149
  url = "".concat(url, "/#/").concat(stateObj.path);
149
150
  }
150
- (0, index_1.useSessionStorage)("url22222===", url);
151
151
  }
152
152
  else {
153
153
  str += "".concat(key, "=").concat(stateObj[key], "&");
@@ -158,7 +158,6 @@ function weixinLogin(code) {
158
158
  url = "".concat(url, "?").concat(str);
159
159
  }
160
160
  }
161
- (0, index_1.useSessionStorage)("url333333===", url);
162
161
  loc.replace(url);
163
162
  }
164
163
  else {
@@ -200,9 +199,6 @@ function weixinCode() {
200
199
  if (weixinConfig['scope']) {
201
200
  scope = weixinConfig['scope'];
202
201
  }
203
- else {
204
- weixinConfig['scope'] = scope;
205
- }
206
202
  var base = "https://open.weixin.qq.com/connect/oauth2/authorize?";
207
203
  var uri = encodeURIComponent(loc.href.split("?")[0]);
208
204
  var config = "appid=".concat(weixinConfig.appId, "&redirect_uri=").concat(uri, "&response_type=code&scope=").concat(scope, "&state=state#wechat_redirect");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xctc-utils",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
4
4
  "description": "localStorage存储\r ```\r sessionStorage存储\r ```\r crypto-js加密、解密\r ```\r 微信授权登录、微信分享\r ```\r 设备环境获取\r ```\r 是否是微信浏览器\r ```\r 时间戳转时间,字符串转时间戳",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",