xctc-utils 1.0.5 → 1.0.6

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.
package/README.md CHANGED
@@ -9,6 +9,12 @@
9
9
  取值: utils.getLocalStorage(key)
10
10
  ```
11
11
 
12
+ #### sessionStorage使用,存取值时数据已经过处理
13
+ ```
14
+ 存储: utils.useSessionStorage(key,value)
15
+ 取值: utils.getSessionStorage(key)
16
+ ```
17
+
12
18
  #### 获取当前设备环境
13
19
  设备环境:
14
20
  ```
File without changes
@@ -1,7 +1,30 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
26
  exports.decrypt = exports.encrypt = void 0;
4
- var CryptoJS = require("crypto-js");
27
+ var CryptoJS = __importStar(require("crypto-js"));
5
28
  var utils_1 = require("../utils");
6
29
  function formatVal(val) {
7
30
  var key = "";
package/dist/index.d.ts CHANGED
@@ -1 +1,2 @@
1
- declare function app(): void;
1
+ declare const obj: any;
2
+ export default obj;
package/dist/index.js CHANGED
@@ -1,7 +1,42 @@
1
1
  "use strict";
2
- // npm run build
3
- // npm publish
4
- function app() {
5
- console.log("xxxx");
6
- }
7
- app();
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ var desc = Object.getOwnPropertyDescriptor(m, k);
16
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
+ desc = { enumerable: true, get: function() { return m[k]; } };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
20
+ }) : (function(o, m, k, k2) {
21
+ if (k2 === undefined) k2 = k;
22
+ o[k2] = m[k];
23
+ }));
24
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
25
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
26
+ }) : function(o, v) {
27
+ o["default"] = v;
28
+ });
29
+ var __importStar = (this && this.__importStar) || function (mod) {
30
+ if (mod && mod.__esModule) return mod;
31
+ var result = {};
32
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
33
+ __setModuleDefault(result, mod);
34
+ return result;
35
+ };
36
+ Object.defineProperty(exports, "__esModule", { value: true });
37
+ var storage = __importStar(require("./storage"));
38
+ var utils = __importStar(require("./utils"));
39
+ var crypto = __importStar(require("./crypto"));
40
+ var weixin = __importStar(require("./weixin"));
41
+ var obj = __assign(__assign(__assign(__assign({}, storage), utils), weixin), crypto);
42
+ exports.default = obj;
@@ -1,18 +1,28 @@
1
1
  interface configOption {
2
2
  appId?: string;
3
3
  http?: any;
4
+ scope?: string;
4
5
  codeKey?: string;
5
6
  stateKey?: string;
6
7
  cryptoiv?: string;
7
8
  cryptokey?: string;
8
9
  }
9
10
  export declare function weixinUrlCode(config: configOption): void;
10
- /**
11
- *
12
- * 获取地址栏中的 search 参数,将参数转换为数组,最终返回地址栏参数数组
13
- * keys 需要截取字符串开始字符
14
- */
15
- export declare function formatSearch(search: string | undefined, keys: string): false | any[];
16
- export declare function weixinInit(): any;
17
- export declare function weixinCode(): void;
11
+ interface ShareConfig {
12
+ http: any;
13
+ cb?: any;
14
+ appId: string;
15
+ jsApiList?: string[];
16
+ }
17
+ export declare function weixinShareConfig(config: ShareConfig): void;
18
+ interface ShareOptions {
19
+ title?: string;
20
+ desc?: string;
21
+ link: '';
22
+ imgUrl: '';
23
+ data?: any;
24
+ iv?: string;
25
+ key?: string;
26
+ }
27
+ export declare function weixinShareInit(options: ShareOptions): void;
18
28
  export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.weixinCode = exports.weixinInit = exports.formatSearch = exports.weixinUrlCode = void 0;
3
+ exports.weixinShareInit = exports.weixinShareConfig = 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");
@@ -134,7 +134,7 @@ function formatSearch(search, keys) {
134
134
  var urlArr = search.split("&");
135
135
  return urlArr;
136
136
  }
137
- exports.formatSearch = formatSearch;
137
+ // 加载当前微信sdk环境
138
138
  function weixinInit() {
139
139
  var wx = null;
140
140
  if (w.wx && w.wx.ready) {
@@ -145,14 +145,16 @@ function weixinInit() {
145
145
  }
146
146
  return wx;
147
147
  }
148
- exports.weixinInit = weixinInit;
149
148
  function weixinCode() {
150
149
  if ((0, utils_1.weixinBrowser)()) {
151
150
  if (!weixinConfig['appId'])
152
151
  return;
152
+ var scope = "snsapi_userinfo";
153
+ if (weixinConfig['scope'])
154
+ scope = weixinConfig['scope'];
153
155
  var base = "https://open.weixin.qq.com/connect/oauth2/authorize?";
154
156
  var uri = encodeURIComponent(loc.href.split("?")[0]);
155
- var config = "appid=".concat(weixinConfig.appId, "&redirect_uri=").concat(uri, "&response_type=code&scope=snsapi_userinfo&state=state#wechat_redirect");
157
+ var config = "appid=".concat(weixinConfig.appId, "&redirect_uri=").concat(uri, "&response_type=code&scope=").concat(scope, "&state=state#wechat_redirect");
156
158
  var wxJumpURL = base + config;
157
159
  loc.replace(wxJumpURL);
158
160
  }
@@ -161,4 +163,101 @@ function weixinCode() {
161
163
  console.log("非微信内核浏览器执行其他业务");
162
164
  }
163
165
  }
164
- exports.weixinCode = weixinCode;
166
+ function weixinShareConfig(config) {
167
+ var _a;
168
+ if (!config['http'])
169
+ return;
170
+ var url = loc.href.split("#")[0];
171
+ var param = {
172
+ url: url,
173
+ appId: config.appId,
174
+ };
175
+ var jsApiList = defaultJsApiList;
176
+ if ((_a = config.jsApiList) === null || _a === void 0 ? void 0 : _a.length)
177
+ jsApiList = config.jsApiList;
178
+ config.http(param).then(function (res) {
179
+ if (res.code == 0) {
180
+ var data = res.data;
181
+ var wx = weixinInit();
182
+ wx.config({
183
+ debug: false,
184
+ appId: data.appId,
185
+ timestamp: data.timestamp,
186
+ nonceStr: data.noncestr,
187
+ signature: data.signature,
188
+ jsApiList: jsApiList //必填,允许分享好友,分享朋友圈
189
+ });
190
+ wx.ready(function (res) {
191
+ console.log("加载微信分享配置完成:", res);
192
+ if ((config === null || config === void 0 ? void 0 : config.cb) && typeof config.cb === "function")
193
+ config.cb();
194
+ });
195
+ wx.error(function (err) {
196
+ console.log("加载微信分享配置错误:", err);
197
+ });
198
+ }
199
+ });
200
+ }
201
+ exports.weixinShareConfig = weixinShareConfig;
202
+ var defaultJsApiList = [
203
+ 'updateAppMessageShareData', 'updateTimelineShareData', "onMenuShareWeibo", "onMenuShareQZone", "startRecord", "stopRecord", "closeWindow", "scanQRCode", "chooseWXPay", "chooseCard", "openCard",
204
+ "onVoiceRecordEnd", "playVoice", "pauseVoice", "stopVoice", "onVoicePlayEnd", "uploadVoice", "downloadVoice", "chooseImage", "previewImage", "uploadImage", "openProductSpecificView", "addCard",
205
+ "downloadImage", "translateVoice", "getNetworkType", "openLocation", "getLocation", "hideOptionMenu", "showOptionMenu", "hideMenuItems", "showMenuItems", "hideAllNonBaseMenuItem", "showAllNonBaseMenuItem",
206
+ ];
207
+ function weixinShareInit(options) {
208
+ var title = "微信分享";
209
+ if (options === null || options === void 0 ? void 0 : options.title)
210
+ title = options.title;
211
+ var desc = "微信分享描述";
212
+ if (options === null || options === void 0 ? void 0 : options.desc)
213
+ desc = options.desc;
214
+ var link = loc.href.split("#")[0];
215
+ if (options === null || options === void 0 ? void 0 : options.link)
216
+ link = options.link;
217
+ var imgUrl = "";
218
+ if (options === null || options === void 0 ? void 0 : options.imgUrl)
219
+ imgUrl = options.imgUrl;
220
+ if (options && typeof options == "object") {
221
+ var state = "";
222
+ if (options === null || options === void 0 ? void 0 : options.data) {
223
+ var data = options.data;
224
+ state = (0, crypto_1.encrypt)(data, options['key'], options['iv']);
225
+ link = "".concat(link, "?state=").concat(state);
226
+ }
227
+ }
228
+ var wx = weixinInit();
229
+ // console.log("shareUrl===",link)
230
+ w.sessionStorage.setItem("shareUrl", link);
231
+ wx.ready(function () {
232
+ //需在用户可能点击分享按钮前就先调用
233
+ wx.updateAppMessageShareData({
234
+ title: title,
235
+ desc: desc,
236
+ link: link,
237
+ imgUrl: imgUrl,
238
+ success: function () {
239
+ // 设置成功
240
+ console.log("成功分享到朋友");
241
+ },
242
+ cancel: function () {
243
+ console.log("分享到朋友失败");
244
+ }
245
+ });
246
+ wx.updateTimelineShareData({
247
+ title: title,
248
+ link: link,
249
+ imgUrl: imgUrl,
250
+ success: function () {
251
+ // 设置成功
252
+ console.log("成功分享到朋友圈");
253
+ },
254
+ cancel: function () {
255
+ console.log("分享到朋友圈失败");
256
+ }
257
+ });
258
+ });
259
+ wx.error(function (res) {
260
+ console.log("配置进入错误:", res);
261
+ });
262
+ }
263
+ exports.weixinShareInit = weixinShareInit;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xctc-utils",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "localStorage存储\r ```\r sessionStorage存储\r ```\r crypto-js加密、解密\r ```\r 微信授权登录、微信分享\r ```\r 设备环境获取\r ```\r 是否是微信浏览器\r ```",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
package/tsconfig.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "node_modules"
12
12
  ],
13
13
  "include": [
14
- "index.ts",
14
+ // "app.ts",
15
15
  "src/*"
16
16
  ]
17
17
  }