xctc-utils 1.3.9 → 1.4.1

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.
@@ -9,6 +9,7 @@ interface configOption {
9
9
  isPassLogin?: boolean;
10
10
  }
11
11
  export declare function weixinUrlCode(config: configOption): void;
12
+ export declare function weixinCode(appId?: string, scope?: string): void;
12
13
  interface ShareConfig {
13
14
  http?: any;
14
15
  cb?: any;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.weixinPay = exports.weixinShareInit = exports.weixinShareConfig = exports.weixinUrlCode = void 0;
3
+ exports.weixinPay = exports.weixinShareInit = exports.weixinShareConfig = exports.weixinCode = exports.weixinUrlCode = void 0;
4
4
  // import * as weixin from 'weixin-js-sdk' // 引入微信SDK
5
5
  var weixin = require("weixin-js-sdk");
6
6
  var utils_1 = require("../utils");
@@ -132,6 +132,7 @@ function weixinLogin(code) {
132
132
  item = JSON.stringify(item);
133
133
  }
134
134
  (0, index_1.useSessionStorage)(key, item);
135
+ (0, index_1.useLocalStorage)(key, item);
135
136
  }
136
137
  var url = loc.origin;
137
138
  var hashVal = loc.hash;
@@ -190,17 +191,30 @@ function weixinInit() {
190
191
  }
191
192
  return wx;
192
193
  }
193
- function weixinCode() {
194
+ // 前往微信授权登录页面
195
+ function weixinCode(appId, scope) {
194
196
  if ((0, utils_1.weixinBrowser)()) {
195
- if (!weixinConfig['appId'])
197
+ var id = "";
198
+ if (weixinConfig['appId']) {
199
+ id = weixinConfig['appId'];
200
+ }
201
+ else if (appId) {
202
+ id = appId;
203
+ }
204
+ if (!id) {
205
+ console.log("调用跳转微信授权方法时weixinCode,请传入参数:appId");
196
206
  return;
197
- var scope = "snsapi_userinfo";
207
+ }
208
+ var scopeVal = "snsapi_userinfo";
198
209
  if (weixinConfig['scope']) {
199
- scope = weixinConfig.scope;
210
+ scopeVal = weixinConfig.scope;
211
+ }
212
+ else if (scope) {
213
+ scopeVal = scope;
200
214
  }
201
215
  var base = "https://open.weixin.qq.com/connect/oauth2/authorize?";
202
216
  var uri = encodeURIComponent(loc.href.split("?")[0]);
203
- var config = "appid=".concat(weixinConfig.appId, "&redirect_uri=").concat(uri, "&response_type=code&scope=").concat(scope, "&state=state#wechat_redirect");
217
+ var config = "appid=".concat(weixinConfig.appId, "&redirect_uri=").concat(uri, "&response_type=code&scope=").concat(scopeVal, "&state=state#wechat_redirect");
204
218
  var wxJumpURL = base + config;
205
219
  loc.replace(wxJumpURL);
206
220
  }
@@ -209,6 +223,7 @@ function weixinCode() {
209
223
  console.log("非微信内核浏览器执行其他业务");
210
224
  }
211
225
  }
226
+ exports.weixinCode = weixinCode;
212
227
  var defaultJsApiList = [
213
228
  'updateAppMessageShareData', 'updateTimelineShareData', "onMenuShareWeibo", "onMenuShareQZone", "startRecord", "stopRecord", "closeWindow", "scanQRCode", "chooseWXPay", "chooseCard", "openCard",
214
229
  "onVoiceRecordEnd", "playVoice", "pauseVoice", "stopVoice", "onVoicePlayEnd", "uploadVoice", "downloadVoice", "chooseImage", "previewImage", "uploadImage", "openProductSpecificView", "addCard",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xctc-utils",
3
- "version": "1.3.9",
3
+ "version": "1.4.1",
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",