2d21111e
wangming
项目初始化
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
// import { pathToBase64, base64ToPath } from '../js_sdk/image-tools/index.js'
const CryptoJS = require('crypto-js'); //引用AES源码js
const key = CryptoJS.enc.Utf8.parse("1234123412ABCDEF"); //十六位十六进制数作为密钥
const iv = CryptoJS.enc.Utf8.parse('ABCDEF1234123412'); //十六位十六进制数作为密钥偏移量
const utils = {
//加密方法
Encrypt(word) {
let srcs = CryptoJS.enc.Utf8.parse(word);
let encrypted = CryptoJS.AES.encrypt(srcs, key, {
iv: iv,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7
});
return encrypted.ciphertext.toString().toUpperCase();
},
//解密方法
Decrypt(word) {
let encryptedHexStr = CryptoJS.enc.Hex.parse(word);
let srcs = CryptoJS.enc.Base64.stringify(encryptedHexStr);
let decrypt = CryptoJS.AES.decrypt(srcs, key, {
iv: iv,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7
});
let decryptedStr = decrypt.toString(CryptoJS.enc.Utf8);
return decryptedStr.toString();
},
addDate(date, days) {
var d = new Date(date)
d.setDate(d.getDate() + days)
var month = d.getMonth() + 1
var day = d.getDate()
if (month < 10) {
month = '0' + month
}
if (day < 10) {
day = '0' + day
}
var val = d.getFullYear() + '-' + month + '-' + day
return val
},
ObjectToQureyParams(obj) {
let arr = []
for (let key in obj) {
arr.push(`${key}=${obj[key]}`);
}
return arr.join('&');
},
formatTime(date, formatStr) {
formatStr = formatStr || 'yyyy-MM-dd HH:mm:ss';
date = new Date(date) || new Date();
formatStr = formatStr.replace('yyyy', date.getFullYear());
formatStr = formatStr.replace('MM', (date.getMonth() + 1).toString().padStart(2, '0'));
formatStr = formatStr.replace('dd', (date.getDate()).toString().padStart(2, '0'));
formatStr = formatStr.replace('HH', (date.getHours()).toString().padStart(2, '0'));
formatStr = formatStr.replace('mm', (date.getMinutes()).toString().padStart(2, '0'));
formatStr = formatStr.replace('ss', (date.getSeconds()).toString().padStart(2, '0'));
formatStr = formatStr.replace('M', (date.getMonth() + 1));
formatStr = formatStr.replace('d', date.getDate());
formatStr = formatStr.replace('H', date.getHours());
formatStr = formatStr.replace('m', date.getMinutes());
formatStr = formatStr.replace('s', date.getSeconds());
return formatStr;
},
parseTime(str) {
return new Date(str);
},
// imagePathToBase64(path){
// return new Promise((resolve,reject)=>{
// pathToBase64(path)
// .then(base64 => {
// resolve(base64)
// })
// .catch(error => {
// reject(error)
// })
// });
// },
getUrlQueryParam(url, key) {
try {
let query = url.split('?')[1];
query = query.split('&');
return query.map(t => {
return {
key: t.split('=')[0],
val: t.split('=')[1]
}
}).find(t => t.key == key).val;
} catch (e) {
return '';
}
}
};
export default utils;
|