@lambo-design/shared 1.0.0-beta.1

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.
@@ -0,0 +1,79 @@
1
+ // deepCopy
2
+
3
+ export function deepCopy(data) {
4
+ let i;
5
+ const t = typeOf(data);
6
+ let o;
7
+
8
+ if (t === 'array') {
9
+ o = [];
10
+ } else if (t === 'object') {
11
+ o = {};
12
+ } else {
13
+ return data;
14
+ }
15
+
16
+ if (t === 'array') {
17
+ for (i = 0; i < data.length; i++) {
18
+ o.push(deepCopy(data[i]));
19
+ }
20
+ } else if (t === 'object') {
21
+ for (i in data) {
22
+ o[i] = deepCopy(data[i]);
23
+ }
24
+ }
25
+ return o;
26
+ }
27
+
28
+ export function typeOf(obj) {
29
+ const toString = Object.prototype.toString;
30
+ const map = {
31
+ '[object Boolean]': 'boolean',
32
+ '[object Number]': 'number',
33
+ '[object String]': 'string',
34
+ '[object Function]': 'function',
35
+ '[object Array]': 'array',
36
+ '[object Date]': 'date',
37
+ '[object RegExp]': 'regExp',
38
+ '[object Undefined]': 'undefined',
39
+ '[object Null]': 'null',
40
+ '[object Object]': 'object'
41
+ };
42
+ return map[toString.call(obj)];
43
+ }
44
+
45
+ export function operateBtn(vm, h, currentRow, operationName, operation, type, permission) {
46
+ return h('Button', {
47
+ props: {
48
+ type: type,
49
+ size: "small",
50
+ ghost: true,
51
+ },
52
+ directives: [{
53
+ name: "permission",
54
+ value: permission
55
+ }],
56
+ style: {
57
+ margin: '0 2px'
58
+ },
59
+ on: {
60
+ 'click': () => {
61
+ operation(vm, currentRow);
62
+ }
63
+ }
64
+ }, operationName);
65
+ }
66
+
67
+ export function operateHref(vm, h, currentRow, operationName, operation) {
68
+ return h('a', {
69
+ on: {
70
+ 'click': () => {
71
+ operation(vm, currentRow);
72
+ }
73
+ }
74
+ }, operationName);
75
+ }
76
+
77
+ export function isJson(arg) {
78
+ return typeof (arg) == "object" && Object.prototype.toString.call(arg).toLowerCase() == "[object object]" && !arg.length
79
+ };
package/utils/bus.js ADDED
@@ -0,0 +1,3 @@
1
+ import Vue from 'vue'
2
+ const Bus = new Vue();
3
+ export default Bus;
@@ -0,0 +1,38 @@
1
+ import sm3 from "./sm3";
2
+ import md5 from "./md5";
3
+
4
+ let crypto = {}
5
+ crypto.sm3 = function (s) {
6
+ return sm3(s);
7
+ }
8
+ crypto.genSalt = function (s) {
9
+ return s + "{1#2$3%4(5)6@7!poeeww$3%4(5)djjkkldss}";
10
+ }
11
+
12
+ crypto.encrypt = function (s, method, add) {
13
+ let result;
14
+ if (!method) {
15
+ method = 'md5';
16
+ }
17
+ if (method === 'md5') {
18
+ result = crypto.md5(s, add);
19
+ } else {
20
+ result = crypto.sm3(s, add);
21
+ }
22
+ return result;
23
+ };
24
+
25
+ crypto.sm3 = function (s, add) {
26
+ if (add) {
27
+ return sm3(crypto.genSalt(s));
28
+ }
29
+ return sm3(s);
30
+ };
31
+ crypto.md5 = function (s, add) {
32
+ if (add) {
33
+ return md5.MD5(crypto.genSalt(s));
34
+ }
35
+ return md5.MD5(s);
36
+ };
37
+
38
+ export default crypto;
@@ -0,0 +1,152 @@
1
+ const md5 = {};
2
+ md5.ByteMD5 = function (arr, Type) {
3
+ return binl2hex(coreMD5(arr2binl(arr)))
4
+
5
+ function safe_add(x, y) {
6
+ var lsw = (x & 0xFFFF) + (y & 0xFFFF)
7
+ var msw = (x >> 16) + (y >> 16) + (lsw >> 16)
8
+ return (msw << 16) | (lsw & 0xFFFF)
9
+ }
10
+
11
+ function rol(num, cnt) {
12
+ return (num << cnt) | (num >>> (32 - cnt))
13
+ }
14
+
15
+ function cmn(q, a, b, x, s, t) {
16
+ return safe_add(rol(safe_add(safe_add(a, q), safe_add(x, t)), s), b)
17
+ }
18
+
19
+ function ff(a, b, c, d, x, s, t) {
20
+ return cmn((b & c) | ((~b) & d), a, b, x, s, t)
21
+ }
22
+
23
+ function gg(a, b, c, d, x, s, t) {
24
+ return cmn((b & d) | (c & (~d)), a, b, x, s, t)
25
+ }
26
+
27
+ function hh(a, b, c, d, x, s, t) {
28
+ return cmn(b ^ c ^ d, a, b, x, s, t)
29
+ }
30
+
31
+ function ii(a, b, c, d, x, s, t) {
32
+ return cmn(c ^ (b | (~d)), a, b, x, s, t)
33
+ }
34
+
35
+ function coreMD5(x) {
36
+ var a = 1732584193
37
+ var b = -271733879
38
+ var c = -1732584194
39
+ var d = 271733878
40
+ for (var i = 0; i < x.length; i += 16) {
41
+ var olda = a
42
+ var oldb = b
43
+ var oldc = c
44
+ var oldd = d
45
+ a = ff(a, b, c, d, x[i + 0], 7, -680876936)
46
+ d = ff(d, a, b, c, x[i + 1], 12, -389564586)
47
+ c = ff(c, d, a, b, x[i + 2], 17, 606105819)
48
+ b = ff(b, c, d, a, x[i + 3], 22, -1044525330)
49
+ a = ff(a, b, c, d, x[i + 4], 7, -176418897)
50
+ d = ff(d, a, b, c, x[i + 5], 12, 1200080426)
51
+ c = ff(c, d, a, b, x[i + 6], 17, -1473231341)
52
+ b = ff(b, c, d, a, x[i + 7], 22, -45705983)
53
+ a = ff(a, b, c, d, x[i + 8], 7, 1770035416)
54
+ d = ff(d, a, b, c, x[i + 9], 12, -1958414417)
55
+ c = ff(c, d, a, b, x[i + 10], 17, -42063)
56
+ b = ff(b, c, d, a, x[i + 11], 22, -1990404162)
57
+ a = ff(a, b, c, d, x[i + 12], 7, 1804603682)
58
+ d = ff(d, a, b, c, x[i + 13], 12, -40341101)
59
+ c = ff(c, d, a, b, x[i + 14], 17, -1502002290)
60
+ b = ff(b, c, d, a, x[i + 15], 22, 1236535329)
61
+ a = gg(a, b, c, d, x[i + 1], 5, -165796510)
62
+ d = gg(d, a, b, c, x[i + 6], 9, -1069501632)
63
+ c = gg(c, d, a, b, x[i + 11], 14, 643717713)
64
+ b = gg(b, c, d, a, x[i + 0], 20, -373897302)
65
+ a = gg(a, b, c, d, x[i + 5], 5, -701558691)
66
+ d = gg(d, a, b, c, x[i + 10], 9, 38016083)
67
+ c = gg(c, d, a, b, x[i + 15], 14, -660478335)
68
+ b = gg(b, c, d, a, x[i + 4], 20, -405537848)
69
+ a = gg(a, b, c, d, x[i + 9], 5, 568446438)
70
+ d = gg(d, a, b, c, x[i + 14], 9, -1019803690)
71
+ c = gg(c, d, a, b, x[i + 3], 14, -187363961)
72
+ b = gg(b, c, d, a, x[i + 8], 20, 1163531501)
73
+ a = gg(a, b, c, d, x[i + 13], 5, -1444681467)
74
+ d = gg(d, a, b, c, x[i + 2], 9, -51403784)
75
+ c = gg(c, d, a, b, x[i + 7], 14, 1735328473)
76
+ b = gg(b, c, d, a, x[i + 12], 20, -1926607734)
77
+ a = hh(a, b, c, d, x[i + 5], 4, -378558)
78
+ d = hh(d, a, b, c, x[i + 8], 11, -2022574463)
79
+ c = hh(c, d, a, b, x[i + 11], 16, 1839030562)
80
+ b = hh(b, c, d, a, x[i + 14], 23, -35309556)
81
+ a = hh(a, b, c, d, x[i + 1], 4, -1530992060)
82
+ d = hh(d, a, b, c, x[i + 4], 11, 1272893353)
83
+ c = hh(c, d, a, b, x[i + 7], 16, -155497632)
84
+ b = hh(b, c, d, a, x[i + 10], 23, -1094730640)
85
+ a = hh(a, b, c, d, x[i + 13], 4, 681279174)
86
+ d = hh(d, a, b, c, x[i + 0], 11, -358537222)
87
+ c = hh(c, d, a, b, x[i + 3], 16, -722521979)
88
+ b = hh(b, c, d, a, x[i + 6], 23, 76029189)
89
+ a = hh(a, b, c, d, x[i + 9], 4, -640364487)
90
+ d = hh(d, a, b, c, x[i + 12], 11, -421815835)
91
+ c = hh(c, d, a, b, x[i + 15], 16, 530742520)
92
+ b = hh(b, c, d, a, x[i + 2], 23, -995338651)
93
+ a = ii(a, b, c, d, x[i + 0], 6, -198630844)
94
+ d = ii(d, a, b, c, x[i + 7], 10, 1126891415)
95
+ c = ii(c, d, a, b, x[i + 14], 15, -1416354905)
96
+ b = ii(b, c, d, a, x[i + 5], 21, -57434055)
97
+ a = ii(a, b, c, d, x[i + 12], 6, 1700485571)
98
+ d = ii(d, a, b, c, x[i + 3], 10, -1894986606)
99
+ c = ii(c, d, a, b, x[i + 10], 15, -1051523)
100
+ b = ii(b, c, d, a, x[i + 1], 21, -2054922799)
101
+ a = ii(a, b, c, d, x[i + 8], 6, 1873313359)
102
+ d = ii(d, a, b, c, x[i + 15], 10, -30611744)
103
+ c = ii(c, d, a, b, x[i + 6], 15, -1560198380)
104
+ b = ii(b, c, d, a, x[i + 13], 21, 1309151649)
105
+ a = ii(a, b, c, d, x[i + 4], 6, -145523070)
106
+ d = ii(d, a, b, c, x[i + 11], 10, -1120210379)
107
+ c = ii(c, d, a, b, x[i + 2], 15, 718787259)
108
+ b = ii(b, c, d, a, x[i + 9], 21, -343485551)
109
+ a = safe_add(a, olda)
110
+ b = safe_add(b, oldb)
111
+ c = safe_add(c, oldc)
112
+ d = safe_add(d, oldd)
113
+ }
114
+ if (Type == 32) {
115
+ return [a, b, c, d];
116
+ } else {
117
+ return [b, c];
118
+ }
119
+ }
120
+
121
+ function binl2hex(binarray) {
122
+ var hex_tab = "0123456789abcdef"
123
+ var str = ""
124
+ for (var i = 0; i < binarray.length * 4; i++) {
125
+ str += hex_tab.charAt((binarray[i >> 2] >> ((i % 4) * 8 + 4)) & 0xF) +
126
+ hex_tab.charAt((binarray[i >> 2] >> ((i % 4) * 8)) & 0xF)
127
+ }
128
+ return str
129
+ }
130
+
131
+ function arr2binl(arr) {
132
+ var nblk = ((arr.length + 8) >> 6) + 1
133
+ var blks = new Array(nblk * 16)
134
+ for (var i = 0; i < nblk * 16; i++) blks[i] = 0
135
+ for (var i = 0; i < arr.length; i++)
136
+ blks[i >> 2] |= (arr[i] & 0xFF) << ((i % 4) * 8)
137
+ blks[i >> 2] |= 0x80 << ((i % 4) * 8)
138
+ blks[nblk * 16 - 2] = arr.length * 8
139
+ return blks
140
+ }
141
+ }
142
+
143
+ md5.MD5 = function (s) {
144
+ var len = s.length;
145
+ var arr = new Array(len);
146
+ for (var i = 0; i < len; i++) {
147
+ var cc = s.charCodeAt(i);
148
+ arr[i] = cc & 0xFF;
149
+ }
150
+ return md5.ByteMD5(arr, 32);
151
+ }
152
+ export default md5;
@@ -0,0 +1,235 @@
1
+ /**
2
+ * 左补0到指定长度
3
+ */
4
+ function leftPad(input, num) {
5
+ if (input.length >= num) return input;
6
+
7
+ return (new Array(num - input.length + 1)).join('0') + input
8
+ }
9
+
10
+ /**
11
+ * 二进制转化为十六进制
12
+ */
13
+ function binary2hex(binary) {
14
+ const binaryLength = 8;
15
+ let hex = '';
16
+ for (let i = 0; i < binary.length / binaryLength; i++) {
17
+ hex += leftPad(parseInt(binary.substr(i * binaryLength, binaryLength), 2).toString(16), 2);
18
+ }
19
+ return hex;
20
+ }
21
+
22
+ /**
23
+ * 十六进制转化为二进制
24
+ */
25
+ function hex2binary(hex) {
26
+ const hexLength = 2;
27
+ let binary = '';
28
+ for (let i = 0; i < hex.length / hexLength; i++) {
29
+ binary += leftPad(parseInt(hex.substr(i * hexLength, hexLength), 16).toString(2), 8);
30
+ }
31
+ return binary;
32
+ }
33
+
34
+ /**
35
+ * 普通字符串转化为二进制
36
+ */
37
+ function str2binary(str) {
38
+ let binary = '';
39
+ for (const ch of str) {
40
+ binary += leftPad(ch.codePointAt(0).toString(2), 8);
41
+ }
42
+ return binary;
43
+ }
44
+
45
+ /**
46
+ * 循环左移
47
+ */
48
+ function rol(str, n) {
49
+ return str.substring(n % str.length) + str.substr(0, n % str.length);
50
+ }
51
+
52
+ /**
53
+ * 二进制运算
54
+ */
55
+ function binaryCal(x, y, method) {
56
+ const a = x || '';
57
+ const b = y || '';
58
+ const result = [];
59
+ let prevResult;
60
+
61
+ for (let i = a.length - 1; i >= 0; i--) { // 大端
62
+ prevResult = method(a[i], b[i], prevResult);
63
+ result[i] = prevResult[0];
64
+ }
65
+ return result.join('');
66
+ }
67
+
68
+ /**
69
+ * 二进制异或运算
70
+ */
71
+ function xor(x, y) {
72
+ return binaryCal(x, y, (a, b) => [(a === b ? '0' : '1')]);
73
+ }
74
+
75
+ /**
76
+ * 二进制与运算
77
+ */
78
+ function and(x, y) {
79
+ return binaryCal(x, y, (a, b) => [(a === '1' && b === '1' ? '1' : '0')]);
80
+ }
81
+
82
+ /**
83
+ * 二进制或运算
84
+ */
85
+ function or(x, y) {
86
+ return binaryCal(x, y, (a, b) => [(a === '1' || b === '1' ? '1' : '0')]); // a === '0' && b === '0' ? '0' : '1'
87
+ }
88
+
89
+ /**
90
+ * 二进制与运算
91
+ */
92
+ function add(x, y) {
93
+ const result = binaryCal(x, y, (a, b, prevResult) => {
94
+ const carry = prevResult ? prevResult[1] : '0' || '0';
95
+
96
+ // a,b不等时,carry不变,结果与carry相反
97
+ // a,b相等时,结果等于原carry,新carry等于a
98
+ if (a !== b) return [carry === '0' ? '1' : '0', carry];
99
+
100
+ return [carry, a];
101
+ });
102
+
103
+ return result;
104
+ }
105
+
106
+ /**
107
+ * 二进制非运算
108
+ */
109
+ function not(x) {
110
+ return binaryCal(x, undefined, a => [a === '1' ? '0' : '1']);
111
+ }
112
+
113
+ function calMulti(method) {
114
+ return (...arr) => arr.reduce((prev, curr) => method(prev, curr));
115
+ }
116
+
117
+ /**
118
+ * 压缩函数中的置换函数 P1(X) = X xor (X <<< 9) xor (X <<< 17)
119
+ */
120
+ function P0(X) {
121
+ return calMulti(xor)(X, rol(X, 9), rol(X, 17));
122
+ }
123
+
124
+ /**
125
+ * 消息扩展中的置换函数 P1(X) = X xor (X <<< 15) xor (X <<< 23)
126
+ */
127
+ function P1(X) {
128
+ return calMulti(xor)(X, rol(X, 15), rol(X, 23));
129
+ }
130
+
131
+ function FF(X, Y, Z, j) {
132
+ return j >= 0 && j <= 15 ? calMulti(xor)(X, Y, Z) : calMulti(or)(and(X, Y), and(X, Z), and(Y, Z));
133
+ }
134
+
135
+ function GG(X, Y, Z, j) {
136
+ return j >= 0 && j <= 15 ? calMulti(xor)(X, Y, Z) : or(and(X, Y), and(not(X), Z));
137
+ }
138
+
139
+ function T(j) {
140
+ return j >= 0 && j <= 15 ? hex2binary('79cc4519') : hex2binary('7a879d8a');
141
+ }
142
+
143
+ /**
144
+ * 压缩函数
145
+ */
146
+ function CF(V, Bi) {
147
+ // 消息扩展
148
+ const wordLength = 32;
149
+ const W = [];
150
+ const M = []; // W'
151
+
152
+ // 将消息分组B划分为16个字W0, W1,…… ,W15 (字为长度为32的比特串)
153
+ for (let i = 0; i < 16; i++) {
154
+ W.push(Bi.substr(i * wordLength, wordLength));
155
+ }
156
+
157
+ // W[j] <- P1(W[j−16] xor W[j−9] xor (W[j−3] <<< 15)) xor (W[j−13] <<< 7) xor W[j−6]
158
+ for (let j = 16; j < 68; j++) {
159
+ W.push(calMulti(xor)(
160
+ P1(calMulti(xor)(W[j - 16], W[j - 9], rol(W[j - 3], 15))),
161
+ rol(W[j - 13], 7),
162
+ W[j - 6]
163
+ ));
164
+ }
165
+
166
+ // W′[j] = W[j] xor W[j+4]
167
+ for (let j = 0; j < 64; j++) {
168
+ M.push(xor(W[j], W[j + 4]));
169
+ }
170
+
171
+ // 压缩
172
+ const wordRegister = []; // 字寄存器
173
+ for (let j = 0; j < 8; j++) {
174
+ wordRegister.push(V.substr(j * wordLength, wordLength));
175
+ }
176
+
177
+ let A = wordRegister[0];
178
+ let B = wordRegister[1];
179
+ let C = wordRegister[2];
180
+ let D = wordRegister[3];
181
+ let E = wordRegister[4];
182
+ let F = wordRegister[5];
183
+ let G = wordRegister[6];
184
+ let H = wordRegister[7];
185
+
186
+ // 中间变量
187
+ let SS1;
188
+ let SS2;
189
+ let TT1;
190
+ let TT2;
191
+ for (let j = 0; j < 64; j++) {
192
+ SS1 = rol(calMulti(add)(rol(A, 12), E, rol(T(j), j)), 7);
193
+ SS2 = xor(SS1, rol(A, 12));
194
+
195
+ TT1 = calMulti(add)(FF(A, B, C, j), D, SS2, M[j]);
196
+ TT2 = calMulti(add)(GG(E, F, G, j), H, SS1, W[j]);
197
+
198
+ D = C;
199
+ C = rol(B, 9);
200
+ B = A;
201
+ A = TT1;
202
+ H = G;
203
+ G = rol(F, 19);
204
+ F = E;
205
+ E = P0(TT2);
206
+ }
207
+
208
+ return xor([A, B, C, D, E, F, G, H].join(''), V);
209
+ }
210
+
211
+ function sm3(str) {
212
+ const binary = str2binary(str);
213
+
214
+ // 填充
215
+ const len = binary.length;
216
+
217
+ // k是满足len + 1 + k = 448mod512的最小的非负整数
218
+ let k = len % 512;
219
+
220
+ // 如果 448 <= (512 % len) < 512,需要多补充 (len % 448) 比特'0'以满足总比特长度为512的倍数
221
+ k = k >= 448 ? 512 - (k % 448) - 1 : 448 - k - 1;
222
+
223
+ const m = `${binary}1${leftPad('', k)}${leftPad(len.toString(2), 64)}`.toString(); // k个0
224
+
225
+ // 迭代压缩
226
+ const n = (len + k + 65) / 512;
227
+
228
+ let V = hex2binary('7380166f4914b2b9172442d7da8a0600a96f30bc163138aae38dee4db0fb0e4e');
229
+ for (let i = 0; i <= n - 1; i++) {
230
+ const B = m.substr(512 * i, 512);
231
+ V = CF(V, B);
232
+ }
233
+ return binary2hex(V);
234
+ };
235
+ export default sm3;