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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
/* eslint-disable indent */
/* eslint-disable guard-for-in */
/* eslint-disable no-restricted-syntax */
import React, { useEffect, useState } from 'react';
import { Button, Space, notification, Modal, Popconfirm, Empty, Spin, Tooltip } from 'antd';
import {
BarcodeOutlined,
UserOutlined,
CalendarOutlined,
PlusOutlined,
CheckOutlined,
} from '@ant-design/icons';
import CryptoJS from 'crypto-js';
import styles from './DatabaseInitialization.less';
import { GetLicenseDifference, InitEditDataBase, GetProductList } from '@/services/database/api';
import New from '../../../assets/images/icons/new.png';
const AppendModal = props => {
const { callBackSubmit = () => {}, visible, onCancel, value, keepHistroy, appendType } = props;
const [data, setData] = useState([]);
const [allLength, setAllLength] = useState('');
const [flag, setFlag] = useState();
const [loading, setLoading] = useState(false);
const [code, setCode] = useState('');
const [project, setProject] = useState('');
const [name, setName] = useState('');
const [number, setNumber] = useState('');
const [much, setMuch] = useState([]);
const [code1, setCode1] = useState('');
const [project1, setProject1] = useState('');
const [name1, setName1] = useState('');
const [number1, setNumber1] = useState('');
const [allValue, setAllValue] = useState([]);
const [keepData, setKeepData] = useState([]);
const key = CryptoJS.enc.Utf8.parse('1p2a3n4d5a6o7m8s9a10n1e2t3c4o5re'); // 十六位十六进制数作为密钥
const iv = CryptoJS.enc.Utf8.parse('1234567890000000');
useEffect(() => {
if (visible) {
getProduct();
let aa = [];
keepHistroy.map((i, j) => {
if (i.license !== '已使用' && j !== keepHistroy.length - 1) {
aa.push(i);
}
});
if (aa.length > 0) {
let a = [];
let b = [];
let c = [];
aa.map(k => {
a.push(k.license);
b.push(k.projectName);
c.push(`${k.applicantName}(${k.jobNumber})`);
});
setCode1(a.toString());
setProject1(b.toString());
setName1(c.toString());
}
setMuch(aa);
setCode(keepHistroy[keepHistroy.length - 1].license);
setProject(keepHistroy[keepHistroy.length - 1].projectName);
setName(keepHistroy[keepHistroy.length - 1].applicantName);
setNumber(keepHistroy[keepHistroy.length - 1].jobNumber);
} else {
setData([]);
setFlag();
setAllLength('');
}
}, [visible]);
// 解密
const Decrypt = word => {
let encryptedHexStr = CryptoJS.enc.Hex.parse(word);
let srcs = CryptoJS.enc.Base64.stringify(encryptedHexStr);
let decrypt = CryptoJS.AES.decrypt(srcs, key, {
iv,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7,
});
let decryptedStr = decrypt.toString(CryptoJS.enc.Utf8);
return decryptedStr.toString();
};
// 加密
const Encrypt = word => {
let srcs = CryptoJS.enc.Utf8.parse(word);
let encrypted = CryptoJS.AES.encrypt(srcs, key, {
iv,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7,
});
return encrypted.ciphertext.toString().toUpperCase();
};
const getProduct = () => {
setLoading(true);
let pwd =
Decrypt(value.password) === '' || Decrypt(value.password).indexOf('\u0004') !== -1
? Encrypt(value.password)
: value.password;
GetLicenseDifference({ ...value, password: pwd }).then(res => {
setLoading(false);
if (res.code === 0) {
setKeepData(res.data);
let aab = [];
res.data.map(k => {
if (k.status == 0) {
aab.push(k.name);
}
});
setAllValue(aab);
let arr = formateArrDataA(res.data, 'productName');
let aa = Object.keys(arr);
aa.map(i => {
let list = [];
arr[i].map(j => {
list.push(j.name);
});
arr[i] = list;
});
setData(arr);
if (res.data.length == 0) {
setFlag(1);
} else {
setFlag(0);
}
setAllLength(res.data.length);
} else {
notification.error({
message: '提示',
duration: 3,
description: res.msg,
});
}
});
};
const formateArrDataA = (initialArr, name) => {
// 判定传参是否符合规则
if (!(initialArr instanceof Array)) {
return '请传入正确格式的数组';
}
if (!name) {
return '请传入对象属性';
}
// 先获取一下这个数组中有多少个"name"
let nameArr = [];
for (let i in initialArr) {
if (nameArr.indexOf(initialArr[i][`${name}`]) === -1) {
nameArr.push(initialArr[i][`${name}`]);
}
}
// 新建一个包含多个list的结果对象
let tempObj = {};
// 根据不同的"name"生成多个数组
for (let k in nameArr) {
for (let j in initialArr) {
if (initialArr[j][`${name}`] == nameArr[k]) {
// 每次外循环时新建一个对应"name"的数组, 内循环时当前数组不变
tempObj[nameArr[k]] = tempObj[nameArr[k]] || [];
tempObj[nameArr[k]].push(initialArr[j]);
}
}
}
for (let keys in tempObj) {
let arr = [];
tempObj[keys].map((item, index) => {
tempObj[keys] = arr;
item.key = index;
arr.push(item);
});
}
return tempObj;
};
const Submit = () => {
if (allValue.length > 0) {
callBackSubmit();
}
};
const title = e => {
let aa = [];
data[e].map(i => {
if (allValue.indexOf(i) != -1) {
aa.push(i);
}
});
return aa.length;
};
const title1 = () => {
if (allValue.length == 0) {
return <span style={{ color: 'red' }}>license下产品已全被初始化,无需再次追加!!!</span>;
}
return (
<span style={{ color: 'rgb(24 144 255)' }}>
{appendType === 'yes' ? (
<div style={{ width: '150px' }}>
当前数据库为非授权初始化数据库,是否使用授权码升级到授权码模式?
</div>
) : (
'是否确认追加!'
)}
</span>
);
};
return (
<Modal
title="产品追加"
width="1000px"
visible={visible}
onCancel={onCancel}
destroyOnClose
maskClosable={false}
bodyStyle={{
height: '500px',
overflowY: 'scroll',
}}
footer={
<Space>
<Button onClick={onCancel}>取消</Button>
<Popconfirm
placement="topLeft"
title={title1}
okText="确认"
cancelText="取消"
onConfirm={() => {
Submit();
}}
>
<Button type="primary">追加</Button>
</Popconfirm>
</Space>
}
>
<Spin spinning={loading}>
{flag === 1 ? (
<Empty
image={Empty.PRESENTED_IMAGE_SIMPLE}
description={<span>当前授权码下产品已全部初始化,无需再次追加</span>}
/>
) : (
<>
{allLength > 0 && (
<div
style={{
height: '50px',
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
marginBottom: '15px',
}}
>
{much.length > 0 ? (
<Tooltip title={code1}>
<div style={{ display: 'inline-block', backgroundColor: 'aliceblue' }}>
<BarcodeOutlined style={{ color: 'rgb(227 168 96)', marginRight: '5px' }} />
授权码:
{code ? <>{code}</> : <span>--</span>}
<span>...</span>
</div>
</Tooltip>
) : (
<div style={{ display: 'inline-block', backgroundColor: 'aliceblue' }}>
<BarcodeOutlined style={{ color: 'rgb(227 168 96)', marginRight: '5px' }} />
授权码:
{code ? <>{code}</> : <span>--</span>}
</div>
)}
{much.length > 0 ? (
<Tooltip title={project1}>
<div style={{ display: 'inline-block', backgroundColor: 'aliceblue' }}>
<CalendarOutlined style={{ color: '#8466cb', marginRight: '5px' }} />
项目名:{project ? <>{project}</> : '--'}
<span>...</span>
</div>
</Tooltip>
) : (
<div style={{ display: 'inline-block', backgroundColor: 'aliceblue' }}>
<CalendarOutlined style={{ color: '#8466cb', marginRight: '5px' }} />
项目名:{project ? <>{project}</> : '--'}
</div>
)}
{much.length > 0 ? (
<Tooltip title={name1}>
<div style={{ display: 'inline-block', backgroundColor: 'aliceblue' }}>
<UserOutlined style={{ color: 'green', marginRight: '5px' }} />
授权人:{name ? <>{name}</> : '-'}
{number ? <>({number})</> : '-'}
{much.length > 0 ? <span>...</span> : <></>}
</div>
</Tooltip>
) : (
<div style={{ display: 'inline-block', backgroundColor: 'aliceblue' }}>
<UserOutlined style={{ color: 'green', marginRight: '5px' }} />
授权人:{name ? <>{name}</> : '-'}
{number ? <>({number})</> : '-'}
</div>
)}
<div style={{ display: 'inline-block', backgroundColor: 'aliceblue' }}>
<div style={{ float: 'right' }}>
<strong>
追加产品列表(共
<span style={{ color: 'rgb(24 144 255)' }}>
{allValue && allValue.length > 0 ? allValue.length : 0}
</span>
<span>/</span>
<span style={{ color: 'rgb(24 144 255)' }}>{allLength}</span>
个)
</strong>
</div>
</div>
</div>
)}
{data &&
Object.keys(data).map((i, j) => (
<div
style={{
border: '2px solid #c2cdfd',
borderRadius: '5px',
marginBottom: '20px',
position: 'relative',
paddingTop: '30px',
}}
>
<div
style={{
position: 'absolute',
left: '13px',
top: '-12px',
backgroundColor: 'white',
paddingLeft: '10px',
paddingRight: '10px',
}}
>
<>
<span>{i}</span>
<span>
(共
<span style={{ color: 'rgb(24, 144, 255)' }}>{title(i)}</span>
<span>/</span>
<span style={{ color: 'rgb(24, 144, 255)' }}>{data[i].length}</span>个)
</span>
</>
</div>
{data[i].map(j => (
<span
style={{
width: '150px',
marginLeft: '24px',
display: 'inline-block',
marginBottom: '20px',
}}
>
{allValue.indexOf(j) !== -1 ? (
<span>
{keepData.length > 0 &&
keepData.find(item => item.name === j).version !== 2022 && (
<img
src={New}
style={{
height: '24px',
marginTop: '-12px',
marginRight: '3px',
}}
alt=""
/>
)}
<PlusOutlined
style={{ color: 'rgb(24, 144, 255)', marginRight: '5px' }}
/>
{j}
</span>
) : (
<span>
{keepData.length > 0 &&
keepData.find(item => item.name === j).version !== 2022 && (
<img
src={New}
style={{
height: '24px',
marginTop: '-12px',
marginRight: '3px',
}}
alt=""
/>
)}
<CheckOutlined style={{ color: 'green', marginRight: '5px' }} />
{j}
</span>
)}
</span>
))}
</div>
))}
</>
)}
</Spin>
</Modal>
);
};
export default AppendModal;