xctc-utils 1.5.4 → 1.5.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 +33 -27
- package/dist/index.js +2 -1
- package/dist/modal/index.d.ts +4 -0
- package/dist/modal/index.js +95 -0
- package/dist/time/index.d.ts +27 -0
- package/dist/time/index.js +133 -23
- package/dist/utils.d.ts +19 -0
- package/dist/utils.js +51 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,29 +1,35 @@
|
|
|
1
1
|
### 项目中常用的方法集合
|
|
2
2
|
#### email: dybself@163.com
|
|
3
3
|
#### 安装 npm i xctc-utils
|
|
4
|
-
####
|
|
4
|
+
#### 更新到最新版本 npm install xctc-utils@latest
|
|
5
|
+
#### 项目中引入 import useUtils from "xctc-utils"
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
#### LocalStorage使用,存取值时数据已经过处理
|
|
8
9
|
```
|
|
9
|
-
存储:
|
|
10
|
-
取值:
|
|
10
|
+
存储: useUtils.useLocalStorage(key,value)
|
|
11
|
+
取值: useUtils.getLocalStorage(key)
|
|
11
12
|
```
|
|
12
13
|
|
|
13
14
|
#### sessionStorage使用,存取值时数据已经过处理
|
|
14
15
|
```
|
|
15
16
|
|
|
16
|
-
存储:
|
|
17
|
-
取值:
|
|
17
|
+
存储: useUtils.useSessionStorage(key,value)
|
|
18
|
+
取值: useUtils.getSessionStorage(key)
|
|
18
19
|
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
#### 将数据复制到剪贴板函数
|
|
23
|
+
```
|
|
24
|
+
useUtils.handleCopyValue(val)
|
|
19
25
|
```
|
|
20
26
|
#### 删除缓存
|
|
21
27
|
```
|
|
22
28
|
key:string 需要删除的缓存键
|
|
23
29
|
isAll:boolean 为true时删除调用方法的所有缓存,否则只删除当前传入的 key 值
|
|
24
30
|
如果 isAll 为 true 时,方法会优先执行缓存的clear函数, key 传任意值,
|
|
25
|
-
删除临时缓存:
|
|
26
|
-
删除永久缓存:
|
|
31
|
+
删除临时缓存: useUtils.removeSessionStorage(key,isAll)
|
|
32
|
+
删除永久缓存: useUtils.removeLocalStorage(key,isAll)
|
|
27
33
|
|
|
28
34
|
```
|
|
29
35
|
#### AES 加密、解密,同一个数据的加密和解密传入的key 和 iv保持一致。
|
|
@@ -32,27 +38,27 @@ work: 需要加密的对象,如传入的是对象,该方法默认进行JSO
|
|
|
32
38
|
key:16位或者32位字符串作为密钥
|
|
33
39
|
iv:16位或者32位字符串作为密钥偏移量
|
|
34
40
|
data: encrypt方法加密后返回的数据
|
|
35
|
-
加密:
|
|
36
|
-
解密:
|
|
41
|
+
加密:useUtils.encrypt( work:any , key:string , iv:string )
|
|
42
|
+
解密:useUtils.decrypt( data:string , key:string , iv:string )
|
|
37
43
|
```
|
|
38
44
|
#### 类型判断
|
|
39
45
|
```
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
46
|
+
useUtils.type.isFunction(val) // 是否是函数
|
|
47
|
+
useUtils.type.isObject(val) // 是否是对象 null 类型为对象,该方法已对null进行过滤
|
|
48
|
+
useUtils.type.isDate(val) // 是否是时间对象
|
|
49
|
+
useUtils.type.isNumber(val) // 是否是number类型
|
|
50
|
+
useUtils.type.isString(val) // 是否是字符串类型
|
|
51
|
+
useUtils.type.isBoolean(val) // 是否是boolean类型
|
|
52
|
+
useUtils.type.isWindow(val) // 是否在浏览器环境下运行
|
|
47
53
|
|
|
48
54
|
```
|
|
49
55
|
#### 获取当前设备环境
|
|
50
56
|
设备环境:
|
|
51
57
|
```
|
|
52
58
|
|
|
53
|
-
当前使用设备类型:
|
|
54
|
-
是否在微信浏览器环境中:
|
|
55
|
-
是否是手持设备:
|
|
59
|
+
当前使用设备类型: useUtils.deviceEnvironment() // android ios
|
|
60
|
+
是否在微信浏览器环境中: useUtils.weixinBrowser() // true false
|
|
61
|
+
是否是手持设备: useUtils.isMobile() // true 移动设备 false PC设备
|
|
56
62
|
|
|
57
63
|
```
|
|
58
64
|
|
|
@@ -67,9 +73,9 @@ data:encrypt方法加密后返回的数据
|
|
|
67
73
|
对word进行CryptoJS.enc.Utf8.parse转义
|
|
68
74
|
CryptoJS.AES.encrypt加密,加密模式:CBC ; padding: CryptoJS.pad.Pkcs7
|
|
69
75
|
对数据进行加密
|
|
70
|
-
|
|
76
|
+
useUtils.encrypt(word:any,key:string,iv:string)
|
|
71
77
|
// 对数据进行解密
|
|
72
|
-
|
|
78
|
+
useUtils.decrypt(data:string,key:string,iv:string)
|
|
73
79
|
|
|
74
80
|
```
|
|
75
81
|
#### 微信H5使用方法集合
|
|
@@ -85,7 +91,7 @@ interface configOption {
|
|
|
85
91
|
cryptokey?:string, // 将地址栏携带参数加密key, 必须与 weixinShareInit 方法中的 key 参数一致
|
|
86
92
|
}
|
|
87
93
|
进入系统时,默认调用该方法,自动执行微信跳转授权,回调地址中code处理、state处理,
|
|
88
|
-
|
|
94
|
+
useUtils.weixinUrlCode(config)
|
|
89
95
|
|
|
90
96
|
```
|
|
91
97
|
#### 微信config接口权限注入
|
|
@@ -97,7 +103,7 @@ interface ShareConfig{
|
|
|
97
103
|
jsApiList?:string[],
|
|
98
104
|
}
|
|
99
105
|
|
|
100
|
-
|
|
106
|
+
useUtils.weixinShareConfig(config:ShareConfig)
|
|
101
107
|
```
|
|
102
108
|
|
|
103
109
|
#### 微信分享接口加载
|
|
@@ -111,14 +117,14 @@ interface Share{
|
|
|
111
117
|
iv?:string, // 分享链接中对 state 数据加密的iv 必须与 weixinUrlCode 方法中的 cryptoiv 参数一致
|
|
112
118
|
key?:string, // 分享链接中对 state 数据加密的 key 必须与 weixinUrlCode 方法中的 cryptokey 参数一致
|
|
113
119
|
}
|
|
114
|
-
|
|
120
|
+
useUtils.weixinShareInit(config:Share)
|
|
115
121
|
```
|
|
116
122
|
|
|
117
123
|
### 时间相关方法
|
|
118
124
|
#### 获取当前时间的时间戳
|
|
119
125
|
```
|
|
120
126
|
|
|
121
|
-
|
|
127
|
+
useUtils.getTime() // 返回秒
|
|
122
128
|
|
|
123
129
|
```
|
|
124
130
|
#### 时间戳转任意格式时间字符串
|
|
@@ -129,7 +135,7 @@ utils.getTime() // 返回秒
|
|
|
129
135
|
* @param format 解析后展示时间字符串格式,默认 "YYYY-MM-DD HH:mm:ss" 格式, 可传格式如: YYYY年MM月DD日 HH时 YYYY/MM/DD HH
|
|
130
136
|
* @returns
|
|
131
137
|
*/
|
|
132
|
-
|
|
138
|
+
useUtils.formatTimeStamp(num,format) // 返回 format 格式时间戳
|
|
133
139
|
|
|
134
140
|
```
|
|
135
141
|
#### 时间字符串转时间戳
|
|
@@ -139,6 +145,6 @@ utils.formatTimeStamp(num,format) // 返回 format 格式时间戳
|
|
|
139
145
|
* @param str 字符串格式必须为: 2017/03/03 12:23:55 格式,避免兼容性,不能传 “-” 分割的时间字符串 2017-03-03
|
|
140
146
|
* @returns
|
|
141
147
|
*/
|
|
142
|
-
|
|
148
|
+
useUtils.formatStrTime(str) // 返回时间戳 秒
|
|
143
149
|
|
|
144
150
|
```
|
package/dist/index.js
CHANGED
|
@@ -42,5 +42,6 @@ var time = __importStar(require("./time"));
|
|
|
42
42
|
var mobile = __importStar(require("./mobile"));
|
|
43
43
|
var format = __importStar(require("./format"));
|
|
44
44
|
var isType = __importStar(require("./is"));
|
|
45
|
-
var
|
|
45
|
+
var modal = __importStar(require("./modal"));
|
|
46
|
+
var obj = __assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign({}, storage), utils), weixin), crypto), time), mobile), format), { type: __assign({}, isType) }), modal);
|
|
46
47
|
exports.default = obj;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.destroyMessageModule = exports.createMessageModule = exports.destroySpinModule = exports.createSpinModule = void 0;
|
|
4
|
+
// 通过ID获取DOM元素
|
|
5
|
+
function $id(id) {
|
|
6
|
+
if (!id)
|
|
7
|
+
return false;
|
|
8
|
+
var dom = document.getElementById(id);
|
|
9
|
+
if (id && dom instanceof HTMLElement) {
|
|
10
|
+
return dom;
|
|
11
|
+
}
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
var createSpinModule = function () {
|
|
15
|
+
var parentBox = toggleDomModule("serveSpinModule", "block");
|
|
16
|
+
var containerBox = "";
|
|
17
|
+
var canvasBox = "";
|
|
18
|
+
var spinnerFourBox = "";
|
|
19
|
+
if (!parentBox) {
|
|
20
|
+
styleModule();
|
|
21
|
+
parentBox = createDom("div");
|
|
22
|
+
containerBox = createDom("div");
|
|
23
|
+
canvasBox = createDom("div");
|
|
24
|
+
spinnerFourBox = createDom("div");
|
|
25
|
+
var parentBoxStyle = "width:100vw!important; height:100vh!important;background-color:rgba(0,0,0,0.5);z-index:100000000;position: fixed;top:0;left:0;text-align:center;";
|
|
26
|
+
parentBox.setAttribute("style", parentBoxStyle);
|
|
27
|
+
parentBox.id = 'serveSpinModule';
|
|
28
|
+
var containerBoxStyle = "display: inline-block;padding-top:23%;";
|
|
29
|
+
containerBox.setAttribute("style", containerBoxStyle);
|
|
30
|
+
var canvasBoxStyle = "align-items: center;background: #eeeeee;border-radius: 50%;display: flex;justify-content: center;margin: 1em;width: 3em;height: 3em;";
|
|
31
|
+
canvasBox.setAttribute("style", canvasBoxStyle);
|
|
32
|
+
var spinnerFourBoxStyle = "animation: spinnerFour 1s linear infinite;border: solid 7px transparent;border-top: solid 7px #4db6ac;border-radius: 100%;width: 3em;height: 3em;";
|
|
33
|
+
spinnerFourBox.setAttribute("style", spinnerFourBoxStyle);
|
|
34
|
+
parentBox.appendChild(containerBox);
|
|
35
|
+
containerBox.appendChild(canvasBox);
|
|
36
|
+
canvasBox.appendChild(spinnerFourBox);
|
|
37
|
+
document.body.appendChild(parentBox);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
exports.createSpinModule = createSpinModule;
|
|
41
|
+
var styleModule = function () {
|
|
42
|
+
// 创建一个新的style元素
|
|
43
|
+
var styleElement = document.createElement('style');
|
|
44
|
+
// 将css字符串作为文本内容添加到style元素中
|
|
45
|
+
styleElement.textContent = "\n @keyframes spinnerFour {\n 0% {\n transform: rotate(0deg);\n }\n 100% {\n transform: rotate(360deg);\n }\n }\n ";
|
|
46
|
+
// 将style元素添加到head部分,使得样式生效
|
|
47
|
+
document.head.appendChild(styleElement);
|
|
48
|
+
};
|
|
49
|
+
var destroySpinModule = function () {
|
|
50
|
+
toggleDomModule("serveSpinModule", "none");
|
|
51
|
+
removeDom("serveSpinModule");
|
|
52
|
+
};
|
|
53
|
+
exports.destroySpinModule = destroySpinModule;
|
|
54
|
+
var toggleDomModule = function (id, val) {
|
|
55
|
+
if (!id)
|
|
56
|
+
return;
|
|
57
|
+
var div = $id(id) || "";
|
|
58
|
+
if (div) {
|
|
59
|
+
div.style.display = val;
|
|
60
|
+
}
|
|
61
|
+
return div;
|
|
62
|
+
};
|
|
63
|
+
var createDom = function (dom) {
|
|
64
|
+
if (!dom)
|
|
65
|
+
return;
|
|
66
|
+
return document.createElement(dom);
|
|
67
|
+
};
|
|
68
|
+
var createMessageModule = function (title, duration, type) {
|
|
69
|
+
var box = toggleDomModule("serveMessageModule", "block");
|
|
70
|
+
if (!type)
|
|
71
|
+
type = "success";
|
|
72
|
+
var containerBoxStyle = "display:inline-block;margin:auto;z-index:100000000;position: fixed;top:10px;left:50%;text-align:center;padding:6px 12px;box-shadow: 0 6px 16px 0 rgba(0, 0, 0, 0.08), 0 3px 6px -4px rgba(0, 0, 0, 0.12), 0 9px 28px 8px rgba(0, 0, 0, 0.05);box-sizing: border-box;border-radius:4px;color:".concat(type == "success" ? "#52c41a" : "#f50", " ");
|
|
73
|
+
box = createDom("div");
|
|
74
|
+
box.id = "serveMessageModule";
|
|
75
|
+
box.setAttribute("style", containerBoxStyle);
|
|
76
|
+
document.body.appendChild(box);
|
|
77
|
+
box.innerText = title;
|
|
78
|
+
if (!(typeof duration === "number")) {
|
|
79
|
+
duration = 1500;
|
|
80
|
+
}
|
|
81
|
+
setTimeout(function () {
|
|
82
|
+
(0, exports.destroyMessageModule)();
|
|
83
|
+
}, duration);
|
|
84
|
+
};
|
|
85
|
+
exports.createMessageModule = createMessageModule;
|
|
86
|
+
var destroyMessageModule = function () {
|
|
87
|
+
toggleDomModule("serveMessageModule", "none");
|
|
88
|
+
removeDom("serveMessageModule");
|
|
89
|
+
};
|
|
90
|
+
exports.destroyMessageModule = destroyMessageModule;
|
|
91
|
+
var removeDom = function (id) {
|
|
92
|
+
var div = $id(id);
|
|
93
|
+
if (div)
|
|
94
|
+
div.remove();
|
|
95
|
+
};
|
package/dist/time/index.d.ts
CHANGED
|
@@ -12,3 +12,30 @@ export declare function formatTimeStamp(num?: number, format?: string): string;
|
|
|
12
12
|
* @returns
|
|
13
13
|
*/
|
|
14
14
|
export declare function formatStrTime(str: string): any;
|
|
15
|
+
/**
|
|
16
|
+
* 2018-12-28 15:00:00
|
|
17
|
+
* 2018/12/28 15:00:00
|
|
18
|
+
* 2018年12月28日 15点00分00秒
|
|
19
|
+
* @param value
|
|
20
|
+
* 如果传入时间字符串格式,请传入具体时间格式,默认 "YYYY-MM-DD HH:mm:ss" 格式, 可传格式如: YYYY年MM月DD日 HH时 YYYY/MM/DD HH
|
|
21
|
+
* @param format 解析后展示时间字符串格式,默认 "YYYY-MM-DD HH:mm:ss" 格式, 可传格式如: YYYY年MM月DD日 HH时 YYYY/MM/DD HH
|
|
22
|
+
* @returns
|
|
23
|
+
*/
|
|
24
|
+
export declare function getDateData(value: string | number, format?: string): {
|
|
25
|
+
year: number;
|
|
26
|
+
month: string | number;
|
|
27
|
+
day: string | number;
|
|
28
|
+
hour: string | number;
|
|
29
|
+
minute: string | number;
|
|
30
|
+
second: string | number;
|
|
31
|
+
num: any;
|
|
32
|
+
};
|
|
33
|
+
export declare function findIdcardAge(idcard: string): {
|
|
34
|
+
year: number;
|
|
35
|
+
month: string | number;
|
|
36
|
+
day: string | number;
|
|
37
|
+
hour: string | number;
|
|
38
|
+
minute: string | number;
|
|
39
|
+
second: string | number;
|
|
40
|
+
num: any;
|
|
41
|
+
} | undefined;
|
package/dist/time/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.formatStrTime = exports.formatTimeStamp = exports.getTime = void 0;
|
|
3
|
+
exports.findIdcardAge = exports.getDateData = exports.formatStrTime = exports.formatTimeStamp = exports.getTime = void 0;
|
|
4
4
|
//获取当前时间戳
|
|
5
5
|
function getTime() {
|
|
6
6
|
var now = new Date().getTime() / 1000;
|
|
@@ -22,34 +22,36 @@ function formatTimeStamp(num, format) {
|
|
|
22
22
|
num = Number(num); // 先将数据转换为数据类型
|
|
23
23
|
if (!num)
|
|
24
24
|
return "";
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
25
|
+
var dateObj = getDateData(num, format) || {};
|
|
26
|
+
// // 传入秒 时间戳
|
|
27
|
+
// let date:any=""
|
|
28
|
+
// if ( typeof num == 'number') {
|
|
29
|
+
// date = new Date( num * 1000)
|
|
30
|
+
// }
|
|
31
|
+
// if( !date ) return ;
|
|
32
|
+
// const year:string = date.getFullYear()
|
|
33
|
+
// let month:any = date.getMonth() + 1
|
|
34
|
+
// month = month < 10 ? "0"+month : month
|
|
35
|
+
// let day:any = date.getDate()
|
|
36
|
+
// day = day < 10 ? "0"+day : day
|
|
37
|
+
// let hour:any = date.getHours()
|
|
38
|
+
// hour = hour < 10 ? "0"+hour : hour
|
|
39
|
+
// let minute:any = date.getMinutes()
|
|
40
|
+
// minute = minute < 10 ? "0"+minute : minute
|
|
41
|
+
// let second:any = date.getSeconds()
|
|
42
|
+
// second = second < 10 ? "0"+second : second
|
|
41
43
|
if (isExist(format, "YYYY"))
|
|
42
|
-
format = format.replace("YYYY", year);
|
|
44
|
+
format = format.replace("YYYY", dateObj === null || dateObj === void 0 ? void 0 : dateObj.year);
|
|
43
45
|
if (isExist(format, "MM"))
|
|
44
|
-
format = format.replace("MM", month);
|
|
46
|
+
format = format.replace("MM", dateObj === null || dateObj === void 0 ? void 0 : dateObj.month);
|
|
45
47
|
if (isExist(format, "DD"))
|
|
46
|
-
format = format.replace("DD", day);
|
|
48
|
+
format = format.replace("DD", dateObj === null || dateObj === void 0 ? void 0 : dateObj.day);
|
|
47
49
|
if (isExist(format, "HH"))
|
|
48
|
-
format = format.replace("HH", hour);
|
|
50
|
+
format = format.replace("HH", dateObj === null || dateObj === void 0 ? void 0 : dateObj.hour);
|
|
49
51
|
if (isExist(format, "mm"))
|
|
50
|
-
format = format.replace("mm", minute);
|
|
52
|
+
format = format.replace("mm", dateObj === null || dateObj === void 0 ? void 0 : dateObj.minute);
|
|
51
53
|
if (isExist(format, "ss"))
|
|
52
|
-
format = format.replace("ss", second);
|
|
54
|
+
format = format.replace("ss", dateObj === null || dateObj === void 0 ? void 0 : dateObj.second);
|
|
53
55
|
return format;
|
|
54
56
|
}
|
|
55
57
|
exports.formatTimeStamp = formatTimeStamp;
|
|
@@ -81,3 +83,111 @@ function formatStrTime(str) {
|
|
|
81
83
|
return "";
|
|
82
84
|
}
|
|
83
85
|
exports.formatStrTime = formatStrTime;
|
|
86
|
+
// 获取当前时间的 年月日时分秒对象
|
|
87
|
+
/**
|
|
88
|
+
* 2018-12-28 15:00:00
|
|
89
|
+
* 2018/12/28 15:00:00
|
|
90
|
+
* 2018年12月28日 15点00分00秒
|
|
91
|
+
* @param value
|
|
92
|
+
* 如果传入时间字符串格式,请传入具体时间格式,默认 "YYYY-MM-DD HH:mm:ss" 格式, 可传格式如: YYYY年MM月DD日 HH时 YYYY/MM/DD HH
|
|
93
|
+
* @param format 解析后展示时间字符串格式,默认 "YYYY-MM-DD HH:mm:ss" 格式, 可传格式如: YYYY年MM月DD日 HH时 YYYY/MM/DD HH
|
|
94
|
+
* @returns
|
|
95
|
+
*/
|
|
96
|
+
function getDateData(value, format) {
|
|
97
|
+
var now = new Date();
|
|
98
|
+
if (typeof value == 'number') {
|
|
99
|
+
now = new Date(value * 1000);
|
|
100
|
+
}
|
|
101
|
+
if (typeof value == "string") {
|
|
102
|
+
if (!format)
|
|
103
|
+
format = "YYYY-MM-DD HH:mm:ss";
|
|
104
|
+
var year_1 = value.substring(0, 4);
|
|
105
|
+
var str = "".concat(year_1);
|
|
106
|
+
var monthIndex = format.indexOf("MM");
|
|
107
|
+
var month_1 = "";
|
|
108
|
+
if (monthIndex != -1) {
|
|
109
|
+
month_1 = value.substring(monthIndex, monthIndex + 3);
|
|
110
|
+
str = "".concat(str, "/").concat(month_1);
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
str = "".concat(str, "/01");
|
|
114
|
+
}
|
|
115
|
+
var dayIndex = format.indexOf("DD");
|
|
116
|
+
var day_1 = "";
|
|
117
|
+
if (dayIndex != -1) {
|
|
118
|
+
day_1 = value.substring(dayIndex, dayIndex + 3);
|
|
119
|
+
str = "".concat(str, "/").concat(day_1);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
str = "".concat(str, "/01");
|
|
123
|
+
}
|
|
124
|
+
var hourIndex = format.indexOf("HH");
|
|
125
|
+
var hour_1 = "";
|
|
126
|
+
if (hourIndex != -1) {
|
|
127
|
+
hour_1 = value.substring(hourIndex, hourIndex + 3);
|
|
128
|
+
str = "".concat(str, " ").concat(hour_1);
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
str = "".concat(str, " 00");
|
|
132
|
+
}
|
|
133
|
+
var minuteIndex = format.indexOf("mm");
|
|
134
|
+
var minute_1 = "";
|
|
135
|
+
if (hourIndex != -1) {
|
|
136
|
+
minute_1 = value.substring(minuteIndex, minuteIndex + 3);
|
|
137
|
+
str = "".concat(str, ":").concat(minute_1);
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
str = "".concat(str, ":00");
|
|
141
|
+
}
|
|
142
|
+
var secondIndex = format.indexOf("ss");
|
|
143
|
+
var second_1 = "";
|
|
144
|
+
if (hourIndex != -1) {
|
|
145
|
+
second_1 = value.substring(secondIndex, secondIndex + 3);
|
|
146
|
+
str = "".concat(str, ":").concat(second_1);
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
str = "".concat(str, ":00");
|
|
150
|
+
}
|
|
151
|
+
now = new Date(str);
|
|
152
|
+
}
|
|
153
|
+
var year = now.getFullYear();
|
|
154
|
+
var month = now.getMonth() + 1;
|
|
155
|
+
month = month < 10 ? "0" + month : month;
|
|
156
|
+
var day = now.getDate();
|
|
157
|
+
day = day < 10 ? "0" + day : day;
|
|
158
|
+
var hour = now.getHours();
|
|
159
|
+
hour = hour < 10 ? "0" + hour : hour;
|
|
160
|
+
var minute = now.getMinutes();
|
|
161
|
+
minute = minute < 10 ? "0" + minute : minute;
|
|
162
|
+
var second = now.getSeconds();
|
|
163
|
+
second = second < 10 ? "0" + second : second;
|
|
164
|
+
var nowNumber = new Date().getTime() / 1000;
|
|
165
|
+
nowNumber = parseInt(nowNumber);
|
|
166
|
+
return {
|
|
167
|
+
year: year,
|
|
168
|
+
month: month,
|
|
169
|
+
day: day,
|
|
170
|
+
hour: hour,
|
|
171
|
+
minute: minute,
|
|
172
|
+
second: second,
|
|
173
|
+
num: nowNumber
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
exports.getDateData = getDateData;
|
|
177
|
+
function findIdcardAge(idcard) {
|
|
178
|
+
if (!idcard) {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
// 提取身份证号中的出生日期部分
|
|
182
|
+
var birthday = idcard.substring(6, 14);
|
|
183
|
+
if (birthday) {
|
|
184
|
+
// 解析出生日期
|
|
185
|
+
var year = birthday.substring(0, 4);
|
|
186
|
+
var month = birthday.substring(4, 6);
|
|
187
|
+
var day = birthday.substring(6, 8);
|
|
188
|
+
var str = "".concat(year, "-").concat(month, "-").concat(day);
|
|
189
|
+
return getDateData(str, "YYYY-MM-DD HH:mm:ss");
|
|
190
|
+
}
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
exports.findIdcardAge = findIdcardAge;
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,7 +1,26 @@
|
|
|
1
1
|
import { UeditorHeightOption } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* 判断当前传入的字符串是否为 json格式 字符串
|
|
4
|
+
* @param str
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
2
7
|
export declare function isJson(str: string): any;
|
|
3
8
|
export declare function $id(id: string): false | HTMLElement;
|
|
4
9
|
export declare function checkIframeContentHeight(option: UeditorHeightOption): string;
|
|
5
10
|
export declare function getIframeContentHeight(id: string): any;
|
|
11
|
+
/**
|
|
12
|
+
* 判断当前手机端环境
|
|
13
|
+
* @returns
|
|
14
|
+
*/
|
|
6
15
|
export declare function deviceEnvironment(): string;
|
|
16
|
+
/**
|
|
17
|
+
* 判断是否是微信内置浏览器
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
7
20
|
export declare function weixinBrowser(): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* 将传入的数据复制到粘贴板
|
|
23
|
+
* @param text
|
|
24
|
+
* @returns
|
|
25
|
+
*/
|
|
26
|
+
export declare function handleCopyValue(text: string): any;
|
package/dist/utils.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.weixinBrowser = exports.deviceEnvironment = exports.getIframeContentHeight = exports.checkIframeContentHeight = exports.$id = exports.isJson = void 0;
|
|
3
|
+
exports.handleCopyValue = exports.weixinBrowser = exports.deviceEnvironment = exports.getIframeContentHeight = exports.checkIframeContentHeight = exports.$id = exports.isJson = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* 判断当前传入的字符串是否为 json格式 字符串
|
|
6
|
+
* @param str
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
4
9
|
function isJson(str) {
|
|
5
10
|
if (!str)
|
|
6
11
|
return false;
|
|
@@ -67,6 +72,10 @@ function getIframeContentHeight(id) {
|
|
|
67
72
|
return 0;
|
|
68
73
|
}
|
|
69
74
|
exports.getIframeContentHeight = getIframeContentHeight;
|
|
75
|
+
/**
|
|
76
|
+
* 判断当前手机端环境
|
|
77
|
+
* @returns
|
|
78
|
+
*/
|
|
70
79
|
function deviceEnvironment() {
|
|
71
80
|
var u = navigator.userAgent;
|
|
72
81
|
if (u.indexOf('Android') > -1 || u.indexOf('Adr') > -1)
|
|
@@ -76,6 +85,10 @@ function deviceEnvironment() {
|
|
|
76
85
|
return "other";
|
|
77
86
|
}
|
|
78
87
|
exports.deviceEnvironment = deviceEnvironment;
|
|
88
|
+
/**
|
|
89
|
+
* 判断是否是微信内置浏览器
|
|
90
|
+
* @returns
|
|
91
|
+
*/
|
|
79
92
|
function weixinBrowser() {
|
|
80
93
|
var ua = navigator.userAgent.toLowerCase();
|
|
81
94
|
var isWeixin = ua.indexOf("micromessenger") != -1;
|
|
@@ -87,3 +100,40 @@ function weixinBrowser() {
|
|
|
87
100
|
}
|
|
88
101
|
}
|
|
89
102
|
exports.weixinBrowser = weixinBrowser;
|
|
103
|
+
// 复制功能
|
|
104
|
+
/**
|
|
105
|
+
* 将传入的数据复制到粘贴板
|
|
106
|
+
* @param text
|
|
107
|
+
* @returns
|
|
108
|
+
*/
|
|
109
|
+
function handleCopyValue(text) {
|
|
110
|
+
if (!text)
|
|
111
|
+
return console.error("请传入需要复制到粘贴板的数据");
|
|
112
|
+
//浏览器禁用了非安全域的 navigator.clipboard 对象
|
|
113
|
+
//在线上环境会报错 TypeError: Cannot read properties of undefined (reading 'writeText')
|
|
114
|
+
var clipboard = (navigator === null || navigator === void 0 ? void 0 : navigator.clipboard) || "";
|
|
115
|
+
if (!clipboard && window.isSecureContext) {
|
|
116
|
+
return clipboard === null || clipboard === void 0 ? void 0 : clipboard.writeText(text);
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
// 判断是否支持拷贝
|
|
120
|
+
if (!document.execCommand('copy'))
|
|
121
|
+
return Promise.reject();
|
|
122
|
+
// 创建标签,并隐藏
|
|
123
|
+
var textArea_1 = document.createElement('textarea');
|
|
124
|
+
textArea_1.style.position = 'fixed';
|
|
125
|
+
textArea_1.style.top = textArea_1.style.left = '-100vh';
|
|
126
|
+
textArea_1.style.opacity = '0';
|
|
127
|
+
textArea_1.value = text;
|
|
128
|
+
document.body.appendChild(textArea_1);
|
|
129
|
+
// 聚焦、复制
|
|
130
|
+
textArea_1.focus();
|
|
131
|
+
textArea_1.select();
|
|
132
|
+
return new Promise(function (resolve, reject) {
|
|
133
|
+
// 不知为何,必须写这个三目,不然copy不上
|
|
134
|
+
document.execCommand('copy') ? resolve() : reject();
|
|
135
|
+
textArea_1.remove();
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
exports.handleCopyValue = handleCopyValue;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xctc-utils",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.6",
|
|
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",
|