xctc-utils 1.3.8 → 1.4.0

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,11 +9,13 @@ 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;
15
16
  appId: string;
16
17
  jsApiList?: string[];
18
+ openTagList?: string[];
17
19
  }
18
20
  export declare function weixinShareConfig(config: ShareConfig): void;
19
21
  interface ShareOptions {
@@ -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,11 +223,16 @@ 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",
215
230
  "downloadImage", "translateVoice", "getNetworkType", "openLocation", "getLocation", "hideOptionMenu", "showOptionMenu", "hideMenuItems", "showMenuItems", "hideAllNonBaseMenuItem", "showAllNonBaseMenuItem",
216
231
  ];
232
+ var defaultOpenTagList = [
233
+ "wx-open-subscribe", "wx-open-launch-app", "wx-open-launch-weapp",
234
+ "wx-open-audio"
235
+ ];
217
236
  function weixinShareConfig(config) {
218
237
  if (!config['http'])
219
238
  return;
@@ -223,9 +242,13 @@ function weixinShareConfig(config) {
223
242
  appId: config.appId,
224
243
  };
225
244
  var jsApiList = defaultJsApiList;
226
- if (config && config.jsApiList && config.jsApiList.length) {
245
+ var openTagList = defaultOpenTagList;
246
+ if (config && config['jsApiList'] && config.jsApiList.length) {
227
247
  jsApiList = config.jsApiList;
228
248
  }
249
+ if (config && config['openTagList'] && config.openTagList.length) {
250
+ openTagList = config.openTagList;
251
+ }
229
252
  config.http(param).then(function (res) {
230
253
  if (res.code == 0) {
231
254
  var data = res['data'] || {};
@@ -236,7 +259,8 @@ function weixinShareConfig(config) {
236
259
  timestamp: data.timestamp,
237
260
  nonceStr: data.noncestr,
238
261
  signature: data.signature,
239
- jsApiList: jsApiList //必填,允许分享好友,分享朋友圈
262
+ jsApiList: jsApiList,
263
+ openTagList: openTagList,
240
264
  });
241
265
  wx.ready(function (res) {
242
266
  console.log("加载微信分享配置完成:", res);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xctc-utils",
3
- "version": "1.3.8",
3
+ "version": "1.4.0",
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",