xctc-utils 1.6.5 → 1.6.7
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 +6 -6
- package/dist/weixin/index.d.ts +4 -0
- package/dist/weixin/index.js +27 -23
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -25,15 +25,15 @@ all:boolean 为true时删除调用方法的所有缓存,否则只删除当前
|
|
|
25
25
|
删除永久缓存: useUtils.removeLocalStorage(key,all)
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
-
### 地址栏参数处理
|
|
28
|
+
### 地址栏参数处理
|
|
29
29
|
#### 设置参数
|
|
30
30
|
```
|
|
31
31
|
interface SetOptions {
|
|
32
32
|
url:string, // 完整的 url 地址
|
|
33
33
|
data:string, // 具体需要拼接在地址参数
|
|
34
34
|
keyword:string, // 地址栏参数 key 值
|
|
35
|
-
key
|
|
36
|
-
iv
|
|
35
|
+
key?:string, // 参数加密 key
|
|
36
|
+
iv?:string // 参数加密 iv
|
|
37
37
|
}
|
|
38
38
|
useUtils.params.set( options:SetOptions )
|
|
39
39
|
```
|
|
@@ -43,8 +43,8 @@ interface GetOptions {
|
|
|
43
43
|
keys:string[],
|
|
44
44
|
cache?:string, // 是否需要缓存地址栏数据: 不传或传空,则不做处理,session 临时缓存 local永久缓存
|
|
45
45
|
cacheKey?:string, // 缓存数据的键 默认值 urlParamsData
|
|
46
|
-
key
|
|
47
|
-
iv
|
|
46
|
+
key?:string, // 参数解密 key 必须与设置参数 key 一致
|
|
47
|
+
iv?:string // 参数解密 iv 必须与设置参数 iv 一致
|
|
48
48
|
}
|
|
49
49
|
useUtils.params.get( options:GetOptions )
|
|
50
50
|
```
|
|
@@ -175,7 +175,7 @@ useUtils.date.formatStrTime(str) // 返回时间戳 秒
|
|
|
175
175
|
#### 计算当前富文本内容高度
|
|
176
176
|
```
|
|
177
177
|
var option = {
|
|
178
|
-
id:"ueditor" , // 富文本DOM容器 id
|
|
178
|
+
id:"ueditor" , // 富文本DOM容器 id 默认不传
|
|
179
179
|
content:"" , // ueditor 富文本内容
|
|
180
180
|
}
|
|
181
181
|
// 返回的富文本内容包含input dom元素,input元素的content-data-height属性计算富文本高度
|
package/dist/weixin/index.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ interface configOption {
|
|
|
8
8
|
cryptokey?: string;
|
|
9
9
|
isPassLogin?: boolean;
|
|
10
10
|
redirectUri?: string;
|
|
11
|
+
appIdKey?: string;
|
|
12
|
+
jsCodeKey?: string;
|
|
11
13
|
}
|
|
12
14
|
export declare function getUrlCode(config: configOption): void;
|
|
13
15
|
export declare function envSDK(): any;
|
|
@@ -19,6 +21,8 @@ interface ShareConfig {
|
|
|
19
21
|
jsApiList?: string[];
|
|
20
22
|
openTagList?: string[];
|
|
21
23
|
url?: string;
|
|
24
|
+
urlKey?: string;
|
|
25
|
+
appIdKey?: string;
|
|
22
26
|
}
|
|
23
27
|
export declare function configReady(config: ShareConfig): void;
|
|
24
28
|
interface ShareOptions {
|
package/dist/weixin/index.js
CHANGED
|
@@ -103,7 +103,8 @@ function cryptoConfig(key, iv) {
|
|
|
103
103
|
}
|
|
104
104
|
// 执行微信登录
|
|
105
105
|
function login(code) {
|
|
106
|
-
var
|
|
106
|
+
var _a;
|
|
107
|
+
var appId = weixinConfig.appId, http = weixinConfig.http, redirectUri = weixinConfig.redirectUri, _b = weixinConfig.appIdKey, appIdKey = _b === void 0 ? "app_id" : _b, _c = weixinConfig.jsCodeKey, jsCodeKey = _c === void 0 ? "js_code" : _c;
|
|
107
108
|
if (!appId) {
|
|
108
109
|
console.error("未正常传入微信公众号appId");
|
|
109
110
|
return;
|
|
@@ -112,10 +113,10 @@ function login(code) {
|
|
|
112
113
|
console.error("未获取到微信授权的code参数");
|
|
113
114
|
return;
|
|
114
115
|
}
|
|
115
|
-
var obj = {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
116
|
+
var obj = (_a = {},
|
|
117
|
+
_a[appIdKey] = appId,
|
|
118
|
+
_a[jsCodeKey] = code,
|
|
119
|
+
_a);
|
|
119
120
|
if (!http) {
|
|
120
121
|
console.error("未正常传入微信授权登录http函数");
|
|
121
122
|
return;
|
|
@@ -123,7 +124,7 @@ function login(code) {
|
|
|
123
124
|
(0, index_1.useSessionStorage)("loginParams", JSON.stringify(obj));
|
|
124
125
|
// 调试字段 isPassLogin ,为true 时不继续执行微信登录,前端可拿到 code 给后端测试
|
|
125
126
|
// if(weixinConfig['isPassLogin']) return
|
|
126
|
-
weixinConfig.http(obj).then(function (res) {
|
|
127
|
+
weixinConfig === null || weixinConfig === void 0 ? void 0 : weixinConfig.http(obj).then(function (res) {
|
|
127
128
|
var _a;
|
|
128
129
|
(0, index_1.useSessionStorage)("loginRes", res);
|
|
129
130
|
if (res.code == 40163) {
|
|
@@ -229,7 +230,8 @@ function envSDK() {
|
|
|
229
230
|
exports.envSDK = envSDK;
|
|
230
231
|
// 前往微信授权登录页面
|
|
231
232
|
function getCode(appId, scope) {
|
|
232
|
-
|
|
233
|
+
var _a = weixinConfig.cryptoiv, cryptoiv = _a === void 0 ? defaultIv : _a, _b = weixinConfig.cryptokey, cryptokey = _b === void 0 ? defaultKey : _b;
|
|
234
|
+
params.get({ keys: ['code', 'state'], cache: "session", key: cryptokey, iv: cryptoiv });
|
|
233
235
|
if ((0, utils_1.weixinBrowser)()) {
|
|
234
236
|
var id = "";
|
|
235
237
|
if (weixinConfig['appId']) {
|
|
@@ -274,23 +276,25 @@ var defaultOpenTagList = [
|
|
|
274
276
|
"wx-open-audio"
|
|
275
277
|
];
|
|
276
278
|
function configReady(config) {
|
|
277
|
-
|
|
279
|
+
var _a;
|
|
280
|
+
var _b = config || {}, appId = _b.appId, url = _b.url, _c = _b.urlKey, urlKey = _c === void 0 ? "url" : _c, _d = _b.appIdKey, appIdKey = _d === void 0 ? "appId" : _d, cb = _b.cb, _e = _b.jsApiList, jsApiList = _e === void 0 ? [] : _e, _f = _b.openTagList, openTagList = _f === void 0 ? [] : _f, _g = _b.http, http = _g === void 0 ? "" : _g;
|
|
281
|
+
if (!http)
|
|
278
282
|
return;
|
|
279
|
-
var
|
|
280
|
-
if (
|
|
281
|
-
|
|
283
|
+
var currentUrl = loc.origin;
|
|
284
|
+
if (url) {
|
|
285
|
+
currentUrl = url;
|
|
282
286
|
}
|
|
283
|
-
var param = {
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
var
|
|
288
|
-
var
|
|
289
|
-
if (
|
|
290
|
-
|
|
287
|
+
var param = (_a = {},
|
|
288
|
+
_a[urlKey] = currentUrl,
|
|
289
|
+
_a[appIdKey] = appId,
|
|
290
|
+
_a);
|
|
291
|
+
var jsApiListData = defaultJsApiList;
|
|
292
|
+
var openTagListData = defaultOpenTagList;
|
|
293
|
+
if (jsApiList === null || jsApiList === void 0 ? void 0 : jsApiList.length) {
|
|
294
|
+
jsApiListData = jsApiListData;
|
|
291
295
|
}
|
|
292
|
-
if (
|
|
293
|
-
|
|
296
|
+
if (openTagList === null || openTagList === void 0 ? void 0 : openTagList.length) {
|
|
297
|
+
openTagListData = openTagList;
|
|
294
298
|
}
|
|
295
299
|
config.http(param).then(function (res) {
|
|
296
300
|
if (res.code == 0) {
|
|
@@ -302,8 +306,8 @@ function configReady(config) {
|
|
|
302
306
|
timestamp: data.timestamp,
|
|
303
307
|
nonceStr: data.noncestr,
|
|
304
308
|
signature: data.signature,
|
|
305
|
-
jsApiList:
|
|
306
|
-
openTagList:
|
|
309
|
+
jsApiList: jsApiListData,
|
|
310
|
+
openTagList: openTagListData,
|
|
307
311
|
});
|
|
308
312
|
wx.ready(function (res) {
|
|
309
313
|
console.log("加载微信分享配置完成:", res);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xctc-utils",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.7",
|
|
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",
|