seeder-st2110-components 1.3.4 → 1.3.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/dist/index.esm.js +218 -739
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +214 -736
- package/dist/index.js.map +1 -1
- package/package.json +1 -4
package/dist/index.esm.js
CHANGED
|
@@ -1,10 +1,74 @@
|
|
|
1
|
-
import { useState, useCallback, useEffect, memo, useMemo, useRef
|
|
1
|
+
import { useState, useCallback, useEffect, memo, useMemo, useRef } from 'react';
|
|
2
2
|
import { useWebSocket, useInterval } from 'ahooks';
|
|
3
|
-
import { Tooltip, Space, Flex, Divider, App, Modal, Form, Input, Alert, message, Dropdown, Spin,
|
|
3
|
+
import { Tooltip, Space, Flex, Divider, App, Modal, Form, Input, Alert, message, Dropdown, Spin, InputNumber, ConfigProvider, Badge, Switch, Select, Typography, List, Empty, Button, Checkbox, Row, Col } from 'antd';
|
|
4
4
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
5
|
-
import { LoadingOutlined, ExclamationCircleFilled,
|
|
5
|
+
import { LoadingOutlined, ExclamationCircleFilled, PlusOutlined } from '@ant-design/icons';
|
|
6
6
|
import axios from 'axios';
|
|
7
7
|
|
|
8
|
+
function _defineProperty(e, r, t) {
|
|
9
|
+
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
10
|
+
value: t,
|
|
11
|
+
enumerable: !0,
|
|
12
|
+
configurable: !0,
|
|
13
|
+
writable: !0
|
|
14
|
+
}) : e[r] = t, e;
|
|
15
|
+
}
|
|
16
|
+
function ownKeys(e, r) {
|
|
17
|
+
var t = Object.keys(e);
|
|
18
|
+
if (Object.getOwnPropertySymbols) {
|
|
19
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
20
|
+
r && (o = o.filter(function (r) {
|
|
21
|
+
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
22
|
+
})), t.push.apply(t, o);
|
|
23
|
+
}
|
|
24
|
+
return t;
|
|
25
|
+
}
|
|
26
|
+
function _objectSpread2(e) {
|
|
27
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
28
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
29
|
+
r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
|
|
30
|
+
_defineProperty(e, r, t[r]);
|
|
31
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
|
|
32
|
+
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
return e;
|
|
36
|
+
}
|
|
37
|
+
function _objectWithoutProperties(e, t) {
|
|
38
|
+
if (null == e) return {};
|
|
39
|
+
var o,
|
|
40
|
+
r,
|
|
41
|
+
i = _objectWithoutPropertiesLoose(e, t);
|
|
42
|
+
if (Object.getOwnPropertySymbols) {
|
|
43
|
+
var n = Object.getOwnPropertySymbols(e);
|
|
44
|
+
for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
|
|
45
|
+
}
|
|
46
|
+
return i;
|
|
47
|
+
}
|
|
48
|
+
function _objectWithoutPropertiesLoose(r, e) {
|
|
49
|
+
if (null == r) return {};
|
|
50
|
+
var t = {};
|
|
51
|
+
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
|
52
|
+
if (-1 !== e.indexOf(n)) continue;
|
|
53
|
+
t[n] = r[n];
|
|
54
|
+
}
|
|
55
|
+
return t;
|
|
56
|
+
}
|
|
57
|
+
function _toPrimitive(t, r) {
|
|
58
|
+
if ("object" != typeof t || !t) return t;
|
|
59
|
+
var e = t[Symbol.toPrimitive];
|
|
60
|
+
if (void 0 !== e) {
|
|
61
|
+
var i = e.call(t, r || "default");
|
|
62
|
+
if ("object" != typeof i) return i;
|
|
63
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
64
|
+
}
|
|
65
|
+
return ("string" === r ? String : Number)(t);
|
|
66
|
+
}
|
|
67
|
+
function _toPropertyKey(t) {
|
|
68
|
+
var i = _toPrimitive(t, "string");
|
|
69
|
+
return "symbol" == typeof i ? i : i + "";
|
|
70
|
+
}
|
|
71
|
+
|
|
8
72
|
const useHardwareWebSocket = socketUrl => {
|
|
9
73
|
// cpu_percent cpu使用率
|
|
10
74
|
// cpu_freq.current cpu频率
|
|
@@ -22,9 +86,7 @@ const useHardwareWebSocket = socketUrl => {
|
|
|
22
86
|
const handleMessage = useCallback(message => {
|
|
23
87
|
try {
|
|
24
88
|
if (message) {
|
|
25
|
-
setSystemStatus(prev => ({
|
|
26
|
-
...prev,
|
|
27
|
-
...message,
|
|
89
|
+
setSystemStatus(prev => _objectSpread2(_objectSpread2(_objectSpread2({}, prev), message), {}, {
|
|
28
90
|
lastUpdated: Date.now() // 添加更新时间戳
|
|
29
91
|
}));
|
|
30
92
|
}
|
|
@@ -35,7 +97,7 @@ const useHardwareWebSocket = socketUrl => {
|
|
|
35
97
|
|
|
36
98
|
// 监听消息 如果latestMessage变化,说明有新消息
|
|
37
99
|
useEffect(() => {
|
|
38
|
-
if (!latestMessage
|
|
100
|
+
if (!(latestMessage !== null && latestMessage !== void 0 && latestMessage.data)) return;
|
|
39
101
|
try {
|
|
40
102
|
const parsedMessage = JSON.parse(latestMessage.data);
|
|
41
103
|
handleMessage(parsedMessage);
|
|
@@ -43,7 +105,7 @@ const useHardwareWebSocket = socketUrl => {
|
|
|
43
105
|
console.error('Message parsing error:', error);
|
|
44
106
|
console.debug('Raw message:', latestMessage.data);
|
|
45
107
|
}
|
|
46
|
-
}, [latestMessage
|
|
108
|
+
}, [latestMessage === null || latestMessage === void 0 ? void 0 : latestMessage.data, handleMessage]);
|
|
47
109
|
return {
|
|
48
110
|
ps_status: systemStatus
|
|
49
111
|
};
|
|
@@ -52,7 +114,7 @@ var useHardwareWebSocket$1 = useHardwareWebSocket;
|
|
|
52
114
|
|
|
53
115
|
const formatBytes = function (bytes) {
|
|
54
116
|
let decimals = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
55
|
-
if (bytes === 0 || !bytes) return '0 Bytes';
|
|
117
|
+
if (bytes === 0 || !bytes || bytes < 0) return '0 Bytes';
|
|
56
118
|
const k = 1024;
|
|
57
119
|
const dm = decimals < 0 ? 0 : decimals;
|
|
58
120
|
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
|
|
@@ -78,7 +140,7 @@ const UsageItem = /*#__PURE__*/memo(_ref => {
|
|
|
78
140
|
children: /*#__PURE__*/jsxs(Space, {
|
|
79
141
|
size: 4,
|
|
80
142
|
children: [/*#__PURE__*/jsx("i", {
|
|
81
|
-
className:
|
|
143
|
+
className: "iconfont ".concat(iconClass, " text-xl")
|
|
82
144
|
}), /*#__PURE__*/jsx("span", {
|
|
83
145
|
className: "inline-block w-10 text-center",
|
|
84
146
|
children: children
|
|
@@ -90,7 +152,10 @@ var UsageItem$1 = UsageItem;
|
|
|
90
152
|
|
|
91
153
|
const getMaxNicTemp = function (sensors) {
|
|
92
154
|
let priorityFields = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ["i350bb", "r8169_0_8300:00"];
|
|
93
|
-
const temps = priorityFields.flatMap(field =>
|
|
155
|
+
const temps = priorityFields.flatMap(field => {
|
|
156
|
+
var _sensors$field;
|
|
157
|
+
return (sensors === null || sensors === void 0 || (_sensors$field = sensors[field]) === null || _sensors$field === void 0 ? void 0 : _sensors$field.map(item => item.current)) || [];
|
|
158
|
+
}).filter(temp => typeof temp === 'number');
|
|
94
159
|
return temps.length ? Math.max(...temps) : null;
|
|
95
160
|
};
|
|
96
161
|
|
|
@@ -100,6 +165,7 @@ const getMaxSensorTemp = sensorData => {
|
|
|
100
165
|
return temps.length ? Math.max(...temps) : null;
|
|
101
166
|
};
|
|
102
167
|
const getDetail = function () {
|
|
168
|
+
var _sensors_temperatures, _sensors_temperatures2, _mem$total, _mem$percent, _getMaxNicTemp, _gpu_stats$0$utilizat, _gpu_stats$, _gpu_stats$0$temperat, _gpu_stats$2;
|
|
103
169
|
let status = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
104
170
|
const {
|
|
105
171
|
cpu_percent,
|
|
@@ -108,15 +174,15 @@ const getDetail = function () {
|
|
|
108
174
|
gpu_stats
|
|
109
175
|
} = status;
|
|
110
176
|
return {
|
|
111
|
-
cpu_usage: cpu_percent
|
|
112
|
-
cpu_temp: sensors_temperatures
|
|
113
|
-
mem_total: mem
|
|
114
|
-
mem_usage: mem
|
|
115
|
-
mem_temp: getMaxSensorTemp(sensors_temperatures
|
|
116
|
-
nic_temp: getMaxNicTemp(sensors_temperatures)
|
|
117
|
-
hd_temp: getMaxSensorTemp(sensors_temperatures
|
|
118
|
-
gpu_usage: gpu_stats
|
|
119
|
-
gpu_temp: gpu_stats
|
|
177
|
+
cpu_usage: cpu_percent !== null && cpu_percent !== void 0 ? cpu_percent : null,
|
|
178
|
+
cpu_temp: (_sensors_temperatures = sensors_temperatures === null || sensors_temperatures === void 0 || (_sensors_temperatures2 = sensors_temperatures.coretemp) === null || _sensors_temperatures2 === void 0 || (_sensors_temperatures2 = _sensors_temperatures2[0]) === null || _sensors_temperatures2 === void 0 ? void 0 : _sensors_temperatures2.current) !== null && _sensors_temperatures !== void 0 ? _sensors_temperatures : null,
|
|
179
|
+
mem_total: (_mem$total = mem === null || mem === void 0 ? void 0 : mem.total) !== null && _mem$total !== void 0 ? _mem$total : null,
|
|
180
|
+
mem_usage: (_mem$percent = mem === null || mem === void 0 ? void 0 : mem.percent) !== null && _mem$percent !== void 0 ? _mem$percent : null,
|
|
181
|
+
mem_temp: getMaxSensorTemp(sensors_temperatures === null || sensors_temperatures === void 0 ? void 0 : sensors_temperatures.spd5118),
|
|
182
|
+
nic_temp: (_getMaxNicTemp = getMaxNicTemp(sensors_temperatures)) !== null && _getMaxNicTemp !== void 0 ? _getMaxNicTemp : null,
|
|
183
|
+
hd_temp: getMaxSensorTemp(sensors_temperatures === null || sensors_temperatures === void 0 ? void 0 : sensors_temperatures.nvme),
|
|
184
|
+
gpu_usage: (_gpu_stats$0$utilizat = gpu_stats === null || gpu_stats === void 0 || (_gpu_stats$ = gpu_stats[0]) === null || _gpu_stats$ === void 0 ? void 0 : _gpu_stats$["utilization.gpu"]) !== null && _gpu_stats$0$utilizat !== void 0 ? _gpu_stats$0$utilizat : null,
|
|
185
|
+
gpu_temp: (_gpu_stats$0$temperat = gpu_stats === null || gpu_stats === void 0 || (_gpu_stats$2 = gpu_stats[0]) === null || _gpu_stats$2 === void 0 ? void 0 : _gpu_stats$2["temperature.gpu"]) !== null && _gpu_stats$0$temperat !== void 0 ? _gpu_stats$0$temperat : null
|
|
120
186
|
};
|
|
121
187
|
};
|
|
122
188
|
|
|
@@ -126,7 +192,7 @@ const createMetricItem = (title, iconClass, value, unit) => {
|
|
|
126
192
|
return {
|
|
127
193
|
title,
|
|
128
194
|
iconClass,
|
|
129
|
-
valueString:
|
|
195
|
+
valueString: "".concat(numValue).concat(unit),
|
|
130
196
|
value: numValue
|
|
131
197
|
};
|
|
132
198
|
};
|
|
@@ -139,10 +205,9 @@ const getItems = details => {
|
|
|
139
205
|
items.push(createMetricItem('CPU Temperature', 'icon-CPUwendu', details.cpu_temp, '℃'));
|
|
140
206
|
}
|
|
141
207
|
if (details.mem_usage !== null && details.mem_usage !== undefined) {
|
|
142
|
-
items.push({
|
|
143
|
-
...createMetricItem('Memory Usage', 'icon-shiyongshuai', details.mem_usage, '%'),
|
|
208
|
+
items.push(_objectSpread2(_objectSpread2({}, createMetricItem('Memory Usage', 'icon-shiyongshuai', details.mem_usage, '%')), {}, {
|
|
144
209
|
memTotal: details.mem_total
|
|
145
|
-
});
|
|
210
|
+
}));
|
|
146
211
|
}
|
|
147
212
|
if (details.mem_temp !== null && details.mem_temp !== undefined) {
|
|
148
213
|
items.push(createMetricItem('Memory Temperature', 'icon-wendu', details.mem_temp, '℃'));
|
|
@@ -212,7 +277,7 @@ const AuthorizationModal = _ref => {
|
|
|
212
277
|
onOk(trimmedCode);
|
|
213
278
|
};
|
|
214
279
|
const statusAlert = isActivated ? /*#__PURE__*/jsx(Alert, {
|
|
215
|
-
message:
|
|
280
|
+
message: "".concat(statusMessage, ", will expire on ").concat(expiresTime),
|
|
216
281
|
type: "success",
|
|
217
282
|
showIcon: true
|
|
218
283
|
}) : /*#__PURE__*/jsx(Alert, {
|
|
@@ -301,7 +366,7 @@ const useAuth = options => {
|
|
|
301
366
|
try {
|
|
302
367
|
setLoading(true);
|
|
303
368
|
const result = await fetchAuthInfo();
|
|
304
|
-
if (result
|
|
369
|
+
if (result !== null && result !== void 0 && result.commands) {
|
|
305
370
|
const commands = result.commands;
|
|
306
371
|
setAuthData(commands);
|
|
307
372
|
setIsRegistered(commands.accredit_status);
|
|
@@ -327,10 +392,10 @@ const useAuth = options => {
|
|
|
327
392
|
license_data: code
|
|
328
393
|
}
|
|
329
394
|
});
|
|
330
|
-
if (result
|
|
395
|
+
if (result !== null && result !== void 0 && result.commands) {
|
|
331
396
|
const commands = result.commands;
|
|
332
397
|
// type accredit_message
|
|
333
|
-
if (commands
|
|
398
|
+
if (commands !== null && commands !== void 0 && commands.accredit_status) {
|
|
334
399
|
setIsRegistered(true);
|
|
335
400
|
setAuthData(commands);
|
|
336
401
|
closeModal();
|
|
@@ -457,7 +522,7 @@ const useUpgrade = _ref => {
|
|
|
457
522
|
if (onMenuClick) {
|
|
458
523
|
onMenuClick(key);
|
|
459
524
|
} else {
|
|
460
|
-
console.warn(
|
|
525
|
+
console.warn("Unknown menu key: ".concat(key, " and no onMenuClick provided"));
|
|
461
526
|
}
|
|
462
527
|
}
|
|
463
528
|
};
|
|
@@ -470,7 +535,7 @@ const useUpgrade = _ref => {
|
|
|
470
535
|
try {
|
|
471
536
|
const res = await downloadFiles();
|
|
472
537
|
if (res.status !== 200) {
|
|
473
|
-
throw new Error(
|
|
538
|
+
throw new Error("Unexpected status code: ".concat(res.status));
|
|
474
539
|
}
|
|
475
540
|
|
|
476
541
|
// 默认值,兼容接口响应头没有定义文件名
|
|
@@ -480,7 +545,7 @@ const useUpgrade = _ref => {
|
|
|
480
545
|
// 获取接口响应的content-disposition字段值,以便获取到文件名
|
|
481
546
|
if (contentDisposition) {
|
|
482
547
|
const filenameMatch = contentDisposition.match(/filename\s*=\s*"?([^";]+)"?/i);
|
|
483
|
-
if (filenameMatch
|
|
548
|
+
if (filenameMatch !== null && filenameMatch !== void 0 && filenameMatch[1]) {
|
|
484
549
|
fileName = decodeURIComponent(filenameMatch[1]); // 处理编码后的文件名(如 %20 转空格)
|
|
485
550
|
}
|
|
486
551
|
}
|
|
@@ -509,7 +574,7 @@ const useUpgrade = _ref => {
|
|
|
509
574
|
}
|
|
510
575
|
};
|
|
511
576
|
const onUpload = () => {
|
|
512
|
-
if (inputRef
|
|
577
|
+
if (inputRef !== null && inputRef !== void 0 && inputRef.current) {
|
|
513
578
|
inputRef.current.click();
|
|
514
579
|
}
|
|
515
580
|
};
|
|
@@ -520,7 +585,8 @@ const useUpgrade = _ref => {
|
|
|
520
585
|
return;
|
|
521
586
|
}
|
|
522
587
|
try {
|
|
523
|
-
|
|
588
|
+
var _event$target$files;
|
|
589
|
+
const file = (_event$target$files = event.target.files) === null || _event$target$files === void 0 ? void 0 : _event$target$files[0];
|
|
524
590
|
if (!file) return;
|
|
525
591
|
showLoader();
|
|
526
592
|
setCurrentStatus('Uploading...');
|
|
@@ -568,7 +634,7 @@ const useUpgrade = _ref => {
|
|
|
568
634
|
const response = await upgradeStatus({
|
|
569
635
|
cancelToken: statusCancelToken.current.token
|
|
570
636
|
});
|
|
571
|
-
if (response
|
|
637
|
+
if ((response === null || response === void 0 ? void 0 : response.status) === 200) {
|
|
572
638
|
const {
|
|
573
639
|
code,
|
|
574
640
|
message: statusMessage
|
|
@@ -656,7 +722,7 @@ const useUpgrade = _ref => {
|
|
|
656
722
|
},
|
|
657
723
|
spin: true
|
|
658
724
|
}),
|
|
659
|
-
tip: currentStatus === "Uploading..." ?
|
|
725
|
+
tip: currentStatus === "Uploading..." ? "".concat(currentStatus, " ").concat(uploadProgress, "%") : currentStatus,
|
|
660
726
|
size: "large",
|
|
661
727
|
fullscreen: true
|
|
662
728
|
})]
|
|
@@ -681,7 +747,7 @@ const useSystemOperations = function () {
|
|
|
681
747
|
try {
|
|
682
748
|
AntdModal.confirm({
|
|
683
749
|
icon: /*#__PURE__*/jsx(ExclamationCircleFilled, {}),
|
|
684
|
-
title:
|
|
750
|
+
title: "".concat(confirmTitle, " ").concat(action, "?"),
|
|
685
751
|
cancelText,
|
|
686
752
|
okText,
|
|
687
753
|
onOk: () => {
|
|
@@ -698,7 +764,7 @@ const useSystemOperations = function () {
|
|
|
698
764
|
}
|
|
699
765
|
});
|
|
700
766
|
} catch (error) {
|
|
701
|
-
console.error(
|
|
767
|
+
console.error("".concat(action.toUpperCase(), " ERROR: "), error);
|
|
702
768
|
}
|
|
703
769
|
}, [AntdModal, confirmTitle, cancelText, okText, onPowerOff, onRestart]);
|
|
704
770
|
const getMenuItems = useCallback(() => [{
|
|
@@ -721,585 +787,20 @@ const useSystemOperations = function () {
|
|
|
721
787
|
};
|
|
722
788
|
var useSystemOperations$1 = useSystemOperations;
|
|
723
789
|
|
|
724
|
-
const
|
|
725
|
-
let {
|
|
726
|
-
onClose,
|
|
727
|
-
onConfirm
|
|
728
|
-
} = _ref;
|
|
729
|
-
const [value, setValue] = useState('');
|
|
730
|
-
const handleConfirm = useCallback(() => {
|
|
731
|
-
onConfirm(value, () => setValue(''));
|
|
732
|
-
}, [confirm, value]);
|
|
733
|
-
const handleKeyDown = useCallback(e => {
|
|
734
|
-
if (e.key === 'Enter') {
|
|
735
|
-
handleConfirm();
|
|
736
|
-
}
|
|
737
|
-
}, [handleConfirm]);
|
|
738
|
-
return /*#__PURE__*/jsxs(Fragment, {
|
|
739
|
-
children: [/*#__PURE__*/jsx(Form.Item, {
|
|
740
|
-
label: "Folder Name",
|
|
741
|
-
style: {
|
|
742
|
-
marginBottom: 8
|
|
743
|
-
},
|
|
744
|
-
children: /*#__PURE__*/jsx(Input, {
|
|
745
|
-
ref: ref,
|
|
746
|
-
value: value,
|
|
747
|
-
onChange: e => setValue(e.target.value),
|
|
748
|
-
onKeyDown: handleKeyDown,
|
|
749
|
-
size: "small",
|
|
750
|
-
style: {
|
|
751
|
-
width: 120
|
|
752
|
-
},
|
|
753
|
-
autoFocus: true
|
|
754
|
-
})
|
|
755
|
-
}), /*#__PURE__*/jsxs(Flex, {
|
|
756
|
-
justify: "flex-end",
|
|
757
|
-
gap: "small",
|
|
758
|
-
children: [/*#__PURE__*/jsx(Button, {
|
|
759
|
-
type: "default",
|
|
760
|
-
size: "small",
|
|
761
|
-
onClick: onClose,
|
|
762
|
-
children: "Close"
|
|
763
|
-
}), /*#__PURE__*/jsx(Button, {
|
|
764
|
-
type: "primary",
|
|
765
|
-
size: "small",
|
|
766
|
-
onClick: handleConfirm,
|
|
767
|
-
children: "OK"
|
|
768
|
-
})]
|
|
769
|
-
})]
|
|
770
|
-
});
|
|
771
|
-
});
|
|
772
|
-
const EditablePopover = _ref2 => {
|
|
773
|
-
let {
|
|
774
|
-
children,
|
|
775
|
-
add
|
|
776
|
-
} = _ref2;
|
|
777
|
-
const inputRef = useRef(null);
|
|
778
|
-
const [open, setOpen] = useState(false);
|
|
779
|
-
useEffect(() => {
|
|
780
|
-
if (open && inputRef.current) {
|
|
781
|
-
const timer = setTimeout(() => {
|
|
782
|
-
inputRef.current?.focus();
|
|
783
|
-
}, 100);
|
|
784
|
-
return () => clearTimeout(timer);
|
|
785
|
-
}
|
|
786
|
-
}, [open]);
|
|
787
|
-
|
|
788
|
-
// 使用 open 属性控制浮层显示
|
|
789
|
-
const hide = useCallback(() => {
|
|
790
|
-
setOpen(false);
|
|
791
|
-
}, []);
|
|
792
|
-
const handleConfirm = useCallback((newTitle, callback) => {
|
|
793
|
-
add(newTitle);
|
|
794
|
-
callback?.();
|
|
795
|
-
hide();
|
|
796
|
-
}, [add, hide]);
|
|
797
|
-
const handleOpenChange = useCallback(newOpen => {
|
|
798
|
-
setOpen(newOpen);
|
|
799
|
-
}, []);
|
|
800
|
-
return /*#__PURE__*/jsx(Popover, {
|
|
801
|
-
content: /*#__PURE__*/jsx(PopoverContent, {
|
|
802
|
-
ref: inputRef,
|
|
803
|
-
onClose: hide,
|
|
804
|
-
onConfirm: handleConfirm
|
|
805
|
-
}),
|
|
806
|
-
trigger: "click",
|
|
807
|
-
open: open,
|
|
808
|
-
onOpenChange: handleOpenChange,
|
|
809
|
-
destroyOnHidden: true,
|
|
810
|
-
children: children
|
|
811
|
-
});
|
|
812
|
-
};
|
|
813
|
-
var EditablePopover$1 = /*#__PURE__*/memo(EditablePopover);
|
|
814
|
-
|
|
815
|
-
const EditableContext = /*#__PURE__*/createContext(null);
|
|
816
|
-
const TreeTitle = _ref => {
|
|
817
|
-
let {
|
|
818
|
-
...props
|
|
819
|
-
} = _ref;
|
|
820
|
-
const [form] = Form.useForm();
|
|
821
|
-
return /*#__PURE__*/jsx(Form, {
|
|
822
|
-
form: form,
|
|
823
|
-
component: false,
|
|
824
|
-
children: /*#__PURE__*/jsx(EditableContext.Provider, {
|
|
825
|
-
value: form,
|
|
826
|
-
children: /*#__PURE__*/jsx(TreeTitleNode, {
|
|
827
|
-
...props
|
|
828
|
-
})
|
|
829
|
-
})
|
|
830
|
-
});
|
|
831
|
-
};
|
|
832
|
-
const TreeTitleNode = _ref2 => {
|
|
833
|
-
let {
|
|
834
|
-
title,
|
|
835
|
-
nodeData,
|
|
836
|
-
handleSave,
|
|
837
|
-
handleDel,
|
|
838
|
-
handleAdd
|
|
839
|
-
} = _ref2;
|
|
840
|
-
const [editing, setEditing] = useState(false);
|
|
841
|
-
const inputRef = useRef(null);
|
|
842
|
-
const form = useContext(EditableContext);
|
|
843
|
-
useEffect(() => {
|
|
844
|
-
if (editing) {
|
|
845
|
-
inputRef.current?.focus();
|
|
846
|
-
}
|
|
847
|
-
}, [editing]);
|
|
848
|
-
const toggleEdit = useCallback(() => {
|
|
849
|
-
setEditing(prev => !prev);
|
|
850
|
-
form.setFieldsValue({
|
|
851
|
-
[nodeData.title]: nodeData.title
|
|
852
|
-
});
|
|
853
|
-
}, [form, nodeData.title]);
|
|
854
|
-
const save = useCallback(async () => {
|
|
855
|
-
try {
|
|
856
|
-
const values = await form.validateFields();
|
|
857
|
-
toggleEdit();
|
|
858
|
-
handleSave({
|
|
859
|
-
...nodeData,
|
|
860
|
-
title: values[nodeData.title]
|
|
861
|
-
});
|
|
862
|
-
} catch (errInfo) {
|
|
863
|
-
console.error('Save failed:', errInfo);
|
|
864
|
-
}
|
|
865
|
-
}, [form, toggleEdit, handleSave, nodeData]);
|
|
866
|
-
|
|
867
|
-
// 新建文件夹
|
|
868
|
-
// 修改文件/文件夹
|
|
869
|
-
// 删除文件/文件夹
|
|
870
|
-
const renderIconNode = useCallback(() => {
|
|
871
|
-
return /*#__PURE__*/jsxs("span", {
|
|
872
|
-
className: "flex",
|
|
873
|
-
onClick: e => e.stopPropagation(),
|
|
874
|
-
children: [/*#__PURE__*/jsx(EditablePopover$1, {
|
|
875
|
-
add: newTitle => handleAdd(nodeData, newTitle),
|
|
876
|
-
children: /*#__PURE__*/jsx("div", {
|
|
877
|
-
className: "px-1",
|
|
878
|
-
title: "create",
|
|
879
|
-
children: /*#__PURE__*/jsx("i", {
|
|
880
|
-
className: "iconfont icon-jia"
|
|
881
|
-
})
|
|
882
|
-
})
|
|
883
|
-
}), !nodeData.isRoot && /*#__PURE__*/jsxs(Fragment, {
|
|
884
|
-
children: [/*#__PURE__*/jsx("div", {
|
|
885
|
-
className: "px-1",
|
|
886
|
-
onClick: toggleEdit,
|
|
887
|
-
title: "edit",
|
|
888
|
-
children: /*#__PURE__*/jsx("i", {
|
|
889
|
-
className: "iconfont icon-bianji"
|
|
890
|
-
})
|
|
891
|
-
}), /*#__PURE__*/jsx(Popconfirm, {
|
|
892
|
-
title: "Confirm deletion?",
|
|
893
|
-
onConfirm: () => handleDel(nodeData),
|
|
894
|
-
okText: "Yes",
|
|
895
|
-
cancelText: "No",
|
|
896
|
-
children: /*#__PURE__*/jsx("div", {
|
|
897
|
-
className: "px-1",
|
|
898
|
-
title: "delete",
|
|
899
|
-
children: /*#__PURE__*/jsx("i", {
|
|
900
|
-
className: "iconfont icon-jian"
|
|
901
|
-
})
|
|
902
|
-
})
|
|
903
|
-
})]
|
|
904
|
-
})]
|
|
905
|
-
});
|
|
906
|
-
}, [handleAdd, nodeData, title, toggleEdit, handleDel]);
|
|
907
|
-
const renderChildNode = useCallback(() => {
|
|
908
|
-
return editing ? /*#__PURE__*/jsx(Form.Item, {
|
|
909
|
-
style: {
|
|
910
|
-
margin: 0,
|
|
911
|
-
width: "100%"
|
|
912
|
-
},
|
|
913
|
-
name: nodeData.title,
|
|
914
|
-
children: /*#__PURE__*/jsx(Input, {
|
|
915
|
-
ref: inputRef,
|
|
916
|
-
onPressEnter: save,
|
|
917
|
-
onBlur: save,
|
|
918
|
-
autoComplete: "off",
|
|
919
|
-
size: "small"
|
|
920
|
-
})
|
|
921
|
-
}) : /*#__PURE__*/jsxs(Fragment, {
|
|
922
|
-
children: [/*#__PURE__*/jsx(Typography.Text, {
|
|
923
|
-
ellipsis: true,
|
|
924
|
-
style: {
|
|
925
|
-
width: "75%"
|
|
926
|
-
},
|
|
927
|
-
children: title
|
|
928
|
-
}), renderIconNode()]
|
|
929
|
-
});
|
|
930
|
-
}, [editing, nodeData.title, save, title, renderIconNode]);
|
|
931
|
-
return /*#__PURE__*/jsx("div", {
|
|
932
|
-
className: "tree-title",
|
|
933
|
-
children: renderChildNode()
|
|
934
|
-
});
|
|
935
|
-
};
|
|
936
|
-
var TreeTitle$1 = /*#__PURE__*/memo(TreeTitle);
|
|
937
|
-
|
|
938
|
-
const replaceRootPath = path => {
|
|
939
|
-
if (typeof path !== 'string') return '';
|
|
940
|
-
return path.startsWith('root/') ? path.slice(5) : path;
|
|
941
|
-
};
|
|
942
|
-
|
|
943
|
-
/**
|
|
944
|
-
* 递归转换目录结构为树形结构
|
|
945
|
-
* @param {Array} data - 原始数据
|
|
946
|
-
* @param {string} [basePath='0'] - 基础路径
|
|
947
|
-
* @param {string} [parentRoute] - 父级路由路径
|
|
948
|
-
* @returns {Array} 转换后的树形结构
|
|
949
|
-
*/
|
|
950
|
-
const buildDirectoryTree = function (data) {
|
|
951
|
-
let basePath = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '0';
|
|
952
|
-
let parentRoute = arguments.length > 2 ? arguments[2] : undefined;
|
|
953
|
-
if (!Array.isArray(data)) return [];
|
|
954
|
-
return data.reduce((acc, item, index) => {
|
|
955
|
-
// 跳过文件类型,只处理目录
|
|
956
|
-
if (item.type === 'file') return acc;
|
|
957
|
-
const title = parentRoute ? item.name : item.sd_index || item.name;
|
|
958
|
-
const key = `${basePath}-${index}`;
|
|
959
|
-
const currentPath = parentRoute ? `${parentRoute}/${title}` : item.path || title;
|
|
960
|
-
const treeNode = {
|
|
961
|
-
title,
|
|
962
|
-
// 文件/文件夹名称
|
|
963
|
-
key,
|
|
964
|
-
icon: _ref => {
|
|
965
|
-
let {
|
|
966
|
-
expanded
|
|
967
|
-
} = _ref;
|
|
968
|
-
return expanded ? /*#__PURE__*/jsx(FolderOpenOutlined, {}) : /*#__PURE__*/jsx(FolderOutlined, {});
|
|
969
|
-
},
|
|
970
|
-
children: [],
|
|
971
|
-
isLeaf: false,
|
|
972
|
-
isRoot: Boolean(item.sd_index),
|
|
973
|
-
path: currentPath,
|
|
974
|
-
contents: (item.contents || []).filter(content => content.type === 'file'),
|
|
975
|
-
rawData: item // 保留原始数据
|
|
976
|
-
};
|
|
977
|
-
|
|
978
|
-
// 递归处理子目录
|
|
979
|
-
if (Array.isArray(item.contents) && item.contents.length > 0) {
|
|
980
|
-
treeNode.children = buildDirectoryTree(item.contents.filter(content => content.type !== 'file'), key, currentPath);
|
|
981
|
-
}
|
|
982
|
-
acc.push(treeNode);
|
|
983
|
-
return acc;
|
|
984
|
-
}, []);
|
|
985
|
-
};
|
|
986
|
-
|
|
987
|
-
/**
|
|
988
|
-
* 查找树中指定key的节点
|
|
989
|
-
* @param {Array} treeData - 树数据
|
|
990
|
-
* @param {string} targetKey - 要查找的key
|
|
991
|
-
* @returns {Array} 包含匹配节点的数组
|
|
992
|
-
*/
|
|
993
|
-
const findTreeNode = (treeData, targetKey) => {
|
|
994
|
-
if (!Array.isArray(treeData) || typeof targetKey !== 'string') return [];
|
|
995
|
-
const result = [];
|
|
996
|
-
const stack = [...treeData];
|
|
997
|
-
while (stack.length) {
|
|
998
|
-
const node = stack.pop();
|
|
999
|
-
if (node.key === targetKey) {
|
|
1000
|
-
result.push(node);
|
|
1001
|
-
// 如果只需要第一个匹配项,可以在这里break
|
|
1002
|
-
}
|
|
1003
|
-
if (Array.isArray(node.children)) {
|
|
1004
|
-
stack.push(...node.children);
|
|
1005
|
-
}
|
|
1006
|
-
}
|
|
1007
|
-
return result;
|
|
1008
|
-
};
|
|
1009
|
-
|
|
1010
|
-
/**
|
|
1011
|
-
* 获取树中所有节点的keys
|
|
1012
|
-
* @param {Array} treeData - 树数据
|
|
1013
|
-
* @returns {Array} 包含所有节点keys的数组
|
|
1014
|
-
*/
|
|
1015
|
-
const getAllNodeKeys = treeData => {
|
|
1016
|
-
if (!Array.isArray(treeData)) return [];
|
|
1017
|
-
const keys = [];
|
|
1018
|
-
const stack = [...treeData];
|
|
1019
|
-
while (stack.length) {
|
|
1020
|
-
const node = stack.pop();
|
|
1021
|
-
if (node.key != null) {
|
|
1022
|
-
keys.push(node.key);
|
|
1023
|
-
}
|
|
1024
|
-
if (Array.isArray(node.children)) {
|
|
1025
|
-
stack.push(...node.children);
|
|
1026
|
-
}
|
|
1027
|
-
}
|
|
1028
|
-
return keys;
|
|
1029
|
-
};
|
|
1030
|
-
|
|
1031
|
-
const useDirectoryTree = _ref => {
|
|
1032
|
-
let {
|
|
1033
|
-
getFolderData,
|
|
1034
|
-
createFolder,
|
|
1035
|
-
removeFolderFile,
|
|
1036
|
-
renameFolderFile,
|
|
1037
|
-
height = 760,
|
|
1038
|
-
theme = {
|
|
1039
|
-
components: {
|
|
1040
|
-
Tree: {
|
|
1041
|
-
titleHeight: 30
|
|
1042
|
-
}
|
|
1043
|
-
}
|
|
1044
|
-
}
|
|
1045
|
-
} = _ref;
|
|
1046
|
-
const [treeState, setTreeState] = useState({
|
|
1047
|
-
data: [],
|
|
1048
|
-
selectedKeys: [],
|
|
1049
|
-
expandedKeys: [],
|
|
1050
|
-
currentPath: "",
|
|
1051
|
-
contents: [],
|
|
1052
|
-
loading: false
|
|
1053
|
-
});
|
|
1054
|
-
const [originTreeData, setOriginTreeData] = useState([]);
|
|
1055
|
-
const updateTreeState = partialState => {
|
|
1056
|
-
setTreeState(prev => ({
|
|
1057
|
-
...prev,
|
|
1058
|
-
...partialState
|
|
1059
|
-
}));
|
|
1060
|
-
};
|
|
1061
|
-
|
|
1062
|
-
// 错误处理
|
|
1063
|
-
const handleError = (error, operation) => {
|
|
1064
|
-
console.error(`${operation} ERROR`, error);
|
|
1065
|
-
// 可以添加通知等统一错误处理
|
|
1066
|
-
};
|
|
1067
|
-
|
|
1068
|
-
// 路径处理工具
|
|
1069
|
-
const pathUtils = {
|
|
1070
|
-
replaceRoot: path => replaceRootPath(path),
|
|
1071
|
-
getNewPath: (node, newTitle) => {
|
|
1072
|
-
const arr = node.path.split('/');
|
|
1073
|
-
arr[arr.length - 1] = newTitle;
|
|
1074
|
-
return arr.join('/');
|
|
1075
|
-
},
|
|
1076
|
-
isSamePath: (path1, path2) => {
|
|
1077
|
-
return pathUtils.replaceRoot(path1) === pathUtils.replaceRoot(path2);
|
|
1078
|
-
}
|
|
1079
|
-
};
|
|
1080
|
-
|
|
1081
|
-
// 节点查找工具
|
|
1082
|
-
const nodeUtils = {
|
|
1083
|
-
findNode: (treeData, key) => {
|
|
1084
|
-
return findTreeNode(treeData, key);
|
|
1085
|
-
}
|
|
1086
|
-
};
|
|
1087
|
-
|
|
1088
|
-
// 获取文件夹数据 文件夹名称为空时返回根目录数据
|
|
1089
|
-
const fetchFolderData = useCallback(async function () {
|
|
1090
|
-
let initialization = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
1091
|
-
try {
|
|
1092
|
-
const data = await getFolderData({
|
|
1093
|
-
folder: ""
|
|
1094
|
-
});
|
|
1095
|
-
if (!data?.directoryTree) {
|
|
1096
|
-
return null;
|
|
1097
|
-
}
|
|
1098
|
-
setOriginTreeData(data.directoryTree);
|
|
1099
|
-
|
|
1100
|
-
// 构建根节点并生成树结构
|
|
1101
|
-
const rootNode = {
|
|
1102
|
-
name: 'root',
|
|
1103
|
-
type: 'directory',
|
|
1104
|
-
contents: data.directoryTree
|
|
1105
|
-
};
|
|
1106
|
-
// 递归生成treenodes
|
|
1107
|
-
const treeNodes = buildDirectoryTree([rootNode]);
|
|
1108
|
-
const rootChildren = treeNodes[0]?.children || [];
|
|
1109
|
-
if (!rootChildren.length) {
|
|
1110
|
-
return null;
|
|
1111
|
-
}
|
|
1112
|
-
const firstChild = rootChildren[0];
|
|
1113
|
-
const newState = {
|
|
1114
|
-
data: rootChildren,
|
|
1115
|
-
...(initialization && {
|
|
1116
|
-
selectedKeys: [firstChild?.key],
|
|
1117
|
-
expandedKeys: getAllNodeKeys(rootChildren),
|
|
1118
|
-
currentPath: firstChild?.path,
|
|
1119
|
-
contents: firstChild?.contents || []
|
|
1120
|
-
})
|
|
1121
|
-
};
|
|
1122
|
-
updateTreeState(newState);
|
|
1123
|
-
return rootChildren;
|
|
1124
|
-
} catch (error) {
|
|
1125
|
-
handleError(error, 'GET FOLDER DATA');
|
|
1126
|
-
}
|
|
1127
|
-
}, []);
|
|
1128
|
-
|
|
1129
|
-
// 初始化数据
|
|
1130
|
-
useEffect(() => {
|
|
1131
|
-
fetchFolderData(true);
|
|
1132
|
-
}, [fetchFolderData]);
|
|
1133
|
-
|
|
1134
|
-
// 创建文件夹
|
|
1135
|
-
const handleCreate = useCallback(async (node, newTitle) => {
|
|
1136
|
-
if (!newTitle?.trim()) return false;
|
|
1137
|
-
try {
|
|
1138
|
-
const path = pathUtils.replaceRoot(`${node.path}/${newTitle}`);
|
|
1139
|
-
await createFolder({
|
|
1140
|
-
path
|
|
1141
|
-
});
|
|
1142
|
-
const newTreeData = await fetchFolderData();
|
|
1143
|
-
|
|
1144
|
-
// 找到新增节点的父节点
|
|
1145
|
-
const parentNode = nodeUtils.findNode(newTreeData, node.key);
|
|
1146
|
-
if (parentNode?.[0]?.children) {
|
|
1147
|
-
// 通过 path 找到新增节点,得到新增节点的key
|
|
1148
|
-
const addedNode = parentNode[0].children.find(ch => pathUtils.isSamePath(ch.path, `root/${newTitle}`));
|
|
1149
|
-
if (addedNode) {
|
|
1150
|
-
updateTreeState({
|
|
1151
|
-
expandedKeys: [...treeState.expandedKeys, addedNode.key, parentNode[0].key]
|
|
1152
|
-
});
|
|
1153
|
-
}
|
|
1154
|
-
}
|
|
1155
|
-
} catch (error) {
|
|
1156
|
-
handleError(error, 'CREATE FOLDER');
|
|
1157
|
-
}
|
|
1158
|
-
}, [fetchFolderData, treeState.expandedKeys]);
|
|
1159
|
-
|
|
1160
|
-
// 删除文件/文件夹
|
|
1161
|
-
const handleRemove = useCallback(async node => {
|
|
1162
|
-
if (!node.path) return;
|
|
1163
|
-
try {
|
|
1164
|
-
await removeFolderFile({
|
|
1165
|
-
paths: [{
|
|
1166
|
-
path: pathUtils.replaceRoot(node.path)
|
|
1167
|
-
}]
|
|
1168
|
-
});
|
|
1169
|
-
// 如果删除的是当前选中节点,则重新初始化
|
|
1170
|
-
const shouldReinitialize = treeState.selectedKeys[0] === node.key;
|
|
1171
|
-
await fetchFolderData(shouldReinitialize);
|
|
1172
|
-
} catch (error) {
|
|
1173
|
-
handleError(error, 'REMOVE FOLDER/FILE');
|
|
1174
|
-
}
|
|
1175
|
-
}, [fetchFolderData, treeState.selectedKeys]);
|
|
1176
|
-
|
|
1177
|
-
// 修改文件/文件夹
|
|
1178
|
-
const handleRename = useCallback(async node => {
|
|
1179
|
-
const newPath = pathUtils.getNewPath(node, node.title);
|
|
1180
|
-
if (pathUtils.isSamePath(node.path, newPath)) return false;
|
|
1181
|
-
try {
|
|
1182
|
-
await renameFolderFile({
|
|
1183
|
-
old_path: pathUtils.replaceRoot(node.path),
|
|
1184
|
-
new_path: pathUtils.replaceRoot(newPath)
|
|
1185
|
-
});
|
|
1186
|
-
await fetchFolderData();
|
|
1187
|
-
} catch (error) {
|
|
1188
|
-
handleError(error, 'RENAME FOLDER/FILE');
|
|
1189
|
-
}
|
|
1190
|
-
}, [fetchFolderData]);
|
|
1191
|
-
|
|
1192
|
-
// 选择节点
|
|
1193
|
-
const onSelect = useCallback(async (keys, info) => {
|
|
1194
|
-
if (!keys.length || keys[0] === treeState.selectedKeys[0] && pathUtils.isSamePath(info.node.path, treeState.currentPath)) return;
|
|
1195
|
-
updateTreeState({
|
|
1196
|
-
selectedKeys: keys,
|
|
1197
|
-
currentPath: info.node.path,
|
|
1198
|
-
loading: true
|
|
1199
|
-
});
|
|
1200
|
-
try {
|
|
1201
|
-
// 模拟延迟加载
|
|
1202
|
-
// eslint-disable-next-line no-promise-executor-return
|
|
1203
|
-
await new Promise(resolve => setTimeout(resolve, 300));
|
|
1204
|
-
updateTreeState({
|
|
1205
|
-
contents: info.node.contents,
|
|
1206
|
-
loading: false
|
|
1207
|
-
});
|
|
1208
|
-
} catch (error) {
|
|
1209
|
-
handleError(error, 'SELECT NODE');
|
|
1210
|
-
updateTreeState({
|
|
1211
|
-
loading: false
|
|
1212
|
-
});
|
|
1213
|
-
}
|
|
1214
|
-
}, [treeState.selectedKeys, treeState.currentPath]);
|
|
1215
|
-
|
|
1216
|
-
// 展开节点
|
|
1217
|
-
const onExpand = useCallback(keys => {
|
|
1218
|
-
updateTreeState({
|
|
1219
|
-
expandedKeys: keys
|
|
1220
|
-
});
|
|
1221
|
-
}, []);
|
|
1222
|
-
|
|
1223
|
-
// 上传右侧文件或删除右侧文件 成功后的回调函数
|
|
1224
|
-
const updateFileContents = useCallback(async () => {
|
|
1225
|
-
// 找到当前选中的节点,更新当前节点的 contents
|
|
1226
|
-
const newTreeData = await fetchFolderData();
|
|
1227
|
-
const selectedNode = nodeUtils.findNode(newTreeData, treeState.selectedKeys[0]);
|
|
1228
|
-
if (selectedNode?.[0]) {
|
|
1229
|
-
updateTreeState({
|
|
1230
|
-
contents: selectedNode[0].contents
|
|
1231
|
-
});
|
|
1232
|
-
}
|
|
1233
|
-
}, [fetchFolderData, treeState.selectedKeys]);
|
|
1234
|
-
|
|
1235
|
-
// 删除文件
|
|
1236
|
-
const removeFile = useCallback(async url => {
|
|
1237
|
-
try {
|
|
1238
|
-
await removeFolderFile({
|
|
1239
|
-
path: url
|
|
1240
|
-
});
|
|
1241
|
-
await updateFileContents();
|
|
1242
|
-
} catch (error) {
|
|
1243
|
-
handleError(error, 'REMOVE FILE');
|
|
1244
|
-
}
|
|
1245
|
-
}, [updateFileContents]);
|
|
1246
|
-
const MemoizedTree = useMemo(() => {
|
|
1247
|
-
if (!treeState.data?.length) {
|
|
1248
|
-
return /*#__PURE__*/jsx(Empty, {
|
|
1249
|
-
image: Empty.PRESENTED_IMAGE_SIMPLE
|
|
1250
|
-
});
|
|
1251
|
-
}
|
|
1252
|
-
return /*#__PURE__*/jsx("div", {
|
|
1253
|
-
style: {
|
|
1254
|
-
paddingTop: 16
|
|
1255
|
-
},
|
|
1256
|
-
children: /*#__PURE__*/jsx(ConfigProvider, {
|
|
1257
|
-
theme: theme,
|
|
1258
|
-
children: /*#__PURE__*/jsx(Tree, {
|
|
1259
|
-
blockNode: true,
|
|
1260
|
-
showIcon: true,
|
|
1261
|
-
selectedKeys: treeState.selectedKeys,
|
|
1262
|
-
expandedKeys: treeState.expandedKeys,
|
|
1263
|
-
onSelect: onSelect,
|
|
1264
|
-
onExpand: onExpand,
|
|
1265
|
-
treeData: treeState.data,
|
|
1266
|
-
titleRender: nodeData => /*#__PURE__*/jsx(TreeTitle$1, {
|
|
1267
|
-
title: nodeData.title,
|
|
1268
|
-
nodeData: nodeData,
|
|
1269
|
-
handleSave: handleRename,
|
|
1270
|
-
handleDel: handleRemove,
|
|
1271
|
-
handleAdd: handleCreate
|
|
1272
|
-
}),
|
|
1273
|
-
height: height
|
|
1274
|
-
})
|
|
1275
|
-
})
|
|
1276
|
-
}, "folder-directory");
|
|
1277
|
-
}, [treeState.data, treeState.selectedKeys, treeState.expandedKeys]);
|
|
1278
|
-
return {
|
|
1279
|
-
directoryTree: MemoizedTree,
|
|
1280
|
-
contents: treeState.contents,
|
|
1281
|
-
currentPath: treeState.currentPath,
|
|
1282
|
-
loading: treeState.loading,
|
|
1283
|
-
originTreeData,
|
|
1284
|
-
updateFileContents,
|
|
1285
|
-
removeFile
|
|
1286
|
-
};
|
|
1287
|
-
};
|
|
1288
|
-
var useDirectoryTree$1 = useDirectoryTree;
|
|
1289
|
-
|
|
790
|
+
const _excluded = ["menuItems", "onMenuClick", "downloadFiles", "upgradeExecute", "upgradeStatus", "acceptFileTypes", "uploadCompleteDelay", "statusPollingInterval", "children"];
|
|
1290
791
|
const UpgradeManager = _ref => {
|
|
1291
792
|
let {
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
793
|
+
menuItems = [],
|
|
794
|
+
onMenuClick,
|
|
795
|
+
downloadFiles,
|
|
796
|
+
upgradeExecute,
|
|
797
|
+
upgradeStatus,
|
|
798
|
+
acceptFileTypes = "application/octet-stream",
|
|
799
|
+
uploadCompleteDelay = 3000,
|
|
800
|
+
statusPollingInterval = 1000,
|
|
801
|
+
children
|
|
802
|
+
} = _ref,
|
|
803
|
+
dropdownProps = _objectWithoutProperties(_ref, _excluded);
|
|
1303
804
|
const [upgradeElement] = useUpgrade$1({
|
|
1304
805
|
menuItems,
|
|
1305
806
|
onMenuClick,
|
|
@@ -1315,11 +816,9 @@ const UpgradeManager = _ref => {
|
|
|
1315
816
|
const dropdownElement = upgradeElement.props.children[0];
|
|
1316
817
|
const otherElements = upgradeElement.props.children.slice(1);
|
|
1317
818
|
return /*#__PURE__*/jsxs(Fragment, {
|
|
1318
|
-
children: [/*#__PURE__*/jsx(Dropdown, {
|
|
1319
|
-
...dropdownProps,
|
|
1320
|
-
...dropdownElement.props,
|
|
819
|
+
children: [/*#__PURE__*/jsx(Dropdown, _objectSpread2(_objectSpread2(_objectSpread2({}, dropdownProps), dropdownElement.props), {}, {
|
|
1321
820
|
children: children
|
|
1322
|
-
}), otherElements]
|
|
821
|
+
})), otherElements]
|
|
1323
822
|
});
|
|
1324
823
|
}
|
|
1325
824
|
|
|
@@ -2557,7 +2056,7 @@ const SystemOperations = _ref => {
|
|
|
2557
2056
|
try {
|
|
2558
2057
|
AntdModal.confirm({
|
|
2559
2058
|
icon: /*#__PURE__*/jsx(ExclamationCircleFilled, {}),
|
|
2560
|
-
title:
|
|
2059
|
+
title: "".concat(confirmTitle, " ").concat(action, "?"),
|
|
2561
2060
|
cancelText,
|
|
2562
2061
|
okText,
|
|
2563
2062
|
onOk: () => {
|
|
@@ -2574,7 +2073,7 @@ const SystemOperations = _ref => {
|
|
|
2574
2073
|
}
|
|
2575
2074
|
});
|
|
2576
2075
|
} catch (error) {
|
|
2577
|
-
console.error(
|
|
2076
|
+
console.error("".concat(action.toUpperCase(), " ERROR: "), error);
|
|
2578
2077
|
}
|
|
2579
2078
|
};
|
|
2580
2079
|
const handleMenuClick = _ref2 => {
|
|
@@ -2715,12 +2214,12 @@ function convertPtpStatusToArray(ptpStatus, fieldConfigs, fieldOrder) {
|
|
|
2715
2214
|
formType: 'text'
|
|
2716
2215
|
};
|
|
2717
2216
|
const value = ptpStatus[key];
|
|
2718
|
-
return {
|
|
2217
|
+
return _objectSpread2(_objectSpread2({
|
|
2719
2218
|
key,
|
|
2720
|
-
value
|
|
2721
|
-
|
|
2219
|
+
value
|
|
2220
|
+
}, config), {}, {
|
|
2722
2221
|
rawData: ptpStatus
|
|
2723
|
-
};
|
|
2222
|
+
});
|
|
2724
2223
|
});
|
|
2725
2224
|
}
|
|
2726
2225
|
const PtpModal = _ref => {
|
|
@@ -2742,7 +2241,7 @@ const PtpModal = _ref => {
|
|
|
2742
2241
|
useEffect(() => {
|
|
2743
2242
|
if (open) {
|
|
2744
2243
|
getPtpInfo().then(data => {
|
|
2745
|
-
if (data
|
|
2244
|
+
if (data !== null && data !== void 0 && data[0]) {
|
|
2746
2245
|
setPtpStatus(data[0]);
|
|
2747
2246
|
form.setFieldsValue(data[0]);
|
|
2748
2247
|
}
|
|
@@ -2755,8 +2254,7 @@ const PtpModal = _ref => {
|
|
|
2755
2254
|
}, [ptpStatus]);
|
|
2756
2255
|
const handleValueChange = changedValues => {
|
|
2757
2256
|
if ('t1_domain_number' in changedValues) {
|
|
2758
|
-
setPtpStatus(prev => ({
|
|
2759
|
-
...prev,
|
|
2257
|
+
setPtpStatus(prev => _objectSpread2(_objectSpread2({}, prev), {}, {
|
|
2760
2258
|
t1_domain_number: changedValues.t1_domain_number
|
|
2761
2259
|
}));
|
|
2762
2260
|
}
|
|
@@ -2776,6 +2274,7 @@ const PtpModal = _ref => {
|
|
|
2776
2274
|
}
|
|
2777
2275
|
};
|
|
2778
2276
|
const renderFormItem = item => {
|
|
2277
|
+
var _item$statusMap, _item$min, _item$max;
|
|
2779
2278
|
switch (item.formType) {
|
|
2780
2279
|
case 'select':
|
|
2781
2280
|
return /*#__PURE__*/jsx(Select, {
|
|
@@ -2786,7 +2285,7 @@ const PtpModal = _ref => {
|
|
|
2786
2285
|
return /*#__PURE__*/jsx(Switch, {});
|
|
2787
2286
|
case 'badge':
|
|
2788
2287
|
const normalizedValue = typeof item.value === 'boolean' ? item.value ? 1 : 0 : item.value;
|
|
2789
|
-
const status = item.statusMap
|
|
2288
|
+
const status = ((_item$statusMap = item.statusMap) === null || _item$statusMap === void 0 ? void 0 : _item$statusMap[normalizedValue]) || {
|
|
2790
2289
|
text: 'Unknown',
|
|
2791
2290
|
color: 'gray'
|
|
2792
2291
|
};
|
|
@@ -2808,8 +2307,8 @@ const PtpModal = _ref => {
|
|
|
2808
2307
|
disabled: item.readOnly,
|
|
2809
2308
|
controls: false,
|
|
2810
2309
|
keyboard: false,
|
|
2811
|
-
min: item.min
|
|
2812
|
-
max: item.max
|
|
2310
|
+
min: (_item$min = item.min) !== null && _item$min !== void 0 ? _item$min : Number.MIN_SAFE_INTEGER,
|
|
2311
|
+
max: (_item$max = item.max) !== null && _item$max !== void 0 ? _item$max : Number.MAX_SAFE_INTEGER
|
|
2813
2312
|
});
|
|
2814
2313
|
default:
|
|
2815
2314
|
return /*#__PURE__*/jsx(Input, {
|
|
@@ -2820,19 +2319,18 @@ const PtpModal = _ref => {
|
|
|
2820
2319
|
if (!open || !ptpStatus) return null;
|
|
2821
2320
|
|
|
2822
2321
|
// 合并默认模态框属性和传入的属性
|
|
2823
|
-
const mergedModalProps = {
|
|
2322
|
+
const mergedModalProps = _objectSpread2({
|
|
2824
2323
|
title: "PTP",
|
|
2825
2324
|
width: 650,
|
|
2826
2325
|
open,
|
|
2827
2326
|
okText: "Apply",
|
|
2828
2327
|
cancelText: "Close",
|
|
2829
2328
|
onCancel: onClose,
|
|
2830
|
-
onOk: handleSubmit
|
|
2831
|
-
|
|
2832
|
-
};
|
|
2329
|
+
onOk: handleSubmit
|
|
2330
|
+
}, modalProps);
|
|
2833
2331
|
|
|
2834
2332
|
// 合并默认表单属性和传入的属性
|
|
2835
|
-
const mergedFormProps = {
|
|
2333
|
+
const mergedFormProps = _objectSpread2({
|
|
2836
2334
|
form: form,
|
|
2837
2335
|
name: "ptpForm",
|
|
2838
2336
|
labelCol: {
|
|
@@ -2842,25 +2340,23 @@ const PtpModal = _ref => {
|
|
|
2842
2340
|
span: 16
|
|
2843
2341
|
},
|
|
2844
2342
|
autoComplete: "off",
|
|
2845
|
-
onValuesChange: handleValueChange
|
|
2846
|
-
|
|
2847
|
-
}
|
|
2848
|
-
|
|
2849
|
-
...mergedModalProps,
|
|
2850
|
-
children: /*#__PURE__*/jsx(Form, {
|
|
2851
|
-
...mergedFormProps,
|
|
2343
|
+
onValuesChange: handleValueChange
|
|
2344
|
+
}, formProps);
|
|
2345
|
+
return /*#__PURE__*/jsx(Modal, _objectSpread2(_objectSpread2({}, mergedModalProps), {}, {
|
|
2346
|
+
children: /*#__PURE__*/jsx(Form, _objectSpread2(_objectSpread2({}, mergedFormProps), {}, {
|
|
2852
2347
|
children: ptpStatusArray.map(item => /*#__PURE__*/jsx(Form.Item, {
|
|
2853
2348
|
label: item.label,
|
|
2854
2349
|
name: item.key,
|
|
2855
2350
|
initialValue: item.value,
|
|
2856
2351
|
children: renderFormItem(item)
|
|
2857
2352
|
}, item.key))
|
|
2858
|
-
})
|
|
2859
|
-
});
|
|
2353
|
+
}))
|
|
2354
|
+
}));
|
|
2860
2355
|
};
|
|
2861
2356
|
var PtpModal$1 = /*#__PURE__*/memo(PtpModal);
|
|
2862
2357
|
|
|
2863
2358
|
const NetworkFieldGroup = _ref => {
|
|
2359
|
+
var _fieldConfig$netmask$, _fieldConfig$netmask;
|
|
2864
2360
|
let {
|
|
2865
2361
|
prefix,
|
|
2866
2362
|
interfaces,
|
|
@@ -2881,14 +2377,12 @@ const NetworkFieldGroup = _ref => {
|
|
|
2881
2377
|
enabled: true
|
|
2882
2378
|
}
|
|
2883
2379
|
};
|
|
2884
|
-
const mergedFieldConfig = {
|
|
2885
|
-
...defaultFieldConfig,
|
|
2886
|
-
...fieldConfig,
|
|
2380
|
+
const mergedFieldConfig = _objectSpread2(_objectSpread2(_objectSpread2({}, defaultFieldConfig), fieldConfig), {}, {
|
|
2887
2381
|
netmask: {
|
|
2888
2382
|
label: "Netmask",
|
|
2889
|
-
enabled: fieldConfig.netmask
|
|
2383
|
+
enabled: (_fieldConfig$netmask$ = (_fieldConfig$netmask = fieldConfig.netmask) === null || _fieldConfig$netmask === void 0 ? void 0 : _fieldConfig$netmask.enabled) !== null && _fieldConfig$netmask$ !== void 0 ? _fieldConfig$netmask$ : defaultFieldConfig.netmask.enabled // 合并 enabled
|
|
2890
2384
|
}
|
|
2891
|
-
};
|
|
2385
|
+
});
|
|
2892
2386
|
return /*#__PURE__*/jsxs(Fragment, {
|
|
2893
2387
|
children: [/*#__PURE__*/jsx(Typography.Title, {
|
|
2894
2388
|
level: 5,
|
|
@@ -2959,24 +2453,20 @@ const NetworkSettingsModal = _ref2 => {
|
|
|
2959
2453
|
hasInitialized: false
|
|
2960
2454
|
});
|
|
2961
2455
|
const preparedFieldConfig = useMemo(() => {
|
|
2962
|
-
const config = {
|
|
2963
|
-
...fieldConfig
|
|
2964
|
-
};
|
|
2456
|
+
const config = _objectSpread2({}, fieldConfig);
|
|
2965
2457
|
|
|
2966
2458
|
// 确保LAN和QSFP的配置存在
|
|
2967
2459
|
config.LAN = config.LAN || {};
|
|
2968
2460
|
config.QSFP = config.QSFP || {};
|
|
2969
2461
|
if (sections.includes('LAN')) {
|
|
2970
|
-
config.LAN.netmask = {
|
|
2971
|
-
...(config.LAN.netmask || {}),
|
|
2462
|
+
config.LAN.netmask = _objectSpread2(_objectSpread2({}, config.LAN.netmask || {}), {}, {
|
|
2972
2463
|
enabled: showNetmask.LAN
|
|
2973
|
-
};
|
|
2464
|
+
});
|
|
2974
2465
|
}
|
|
2975
2466
|
if (sections.includes('QSFP')) {
|
|
2976
|
-
config.QSFP.netmask = {
|
|
2977
|
-
...(config.QSFP.netmask || {}),
|
|
2467
|
+
config.QSFP.netmask = _objectSpread2(_objectSpread2({}, config.QSFP.netmask || {}), {}, {
|
|
2978
2468
|
enabled: showNetmask.QSFP
|
|
2979
|
-
};
|
|
2469
|
+
});
|
|
2980
2470
|
}
|
|
2981
2471
|
return config;
|
|
2982
2472
|
}, [fieldConfig, showNetmask, sections]);
|
|
@@ -3044,28 +2534,23 @@ const NetworkSettingsModal = _ref2 => {
|
|
|
3044
2534
|
const initialValues = useMemo(() => {
|
|
3045
2535
|
const values = {};
|
|
3046
2536
|
if (sections.includes('LAN') && lanConfigs.length > 0) {
|
|
3047
|
-
values.LAN = lanConfigs.map(config => ({
|
|
2537
|
+
values.LAN = lanConfigs.map(config => _objectSpread2({
|
|
3048
2538
|
connection_id: config.connection_id,
|
|
3049
2539
|
display_name: config.display_name,
|
|
3050
|
-
ip_address: config.ip_address
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
}));
|
|
2540
|
+
ip_address: config.ip_address
|
|
2541
|
+
}, showNetmask.LAN ? {
|
|
2542
|
+
netmask: config.netmask
|
|
2543
|
+
} : {}));
|
|
3055
2544
|
}
|
|
3056
2545
|
if (sections.includes('QSFP') && st2110Interfaces.length > 0) {
|
|
3057
|
-
values.QSFP = st2110Interfaces.map(iface => ({
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
id: iface.id
|
|
3061
|
-
}),
|
|
2546
|
+
values.QSFP = st2110Interfaces.map(iface => _objectSpread2(_objectSpread2({}, iface.id !== undefined && {
|
|
2547
|
+
id: iface.id
|
|
2548
|
+
}), {}, {
|
|
3062
2549
|
display_name: iface.display_name,
|
|
3063
|
-
ip_address: iface.ip_address || iface.ip
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
} : {})
|
|
3068
|
-
}));
|
|
2550
|
+
ip_address: iface.ip_address || iface.ip
|
|
2551
|
+
}, showNetmask.QSFP ? {
|
|
2552
|
+
netmask: iface.netmask
|
|
2553
|
+
} : {}));
|
|
3069
2554
|
}
|
|
3070
2555
|
return values;
|
|
3071
2556
|
}, [lanConfigs, st2110Interfaces, sections, showNetmask]);
|
|
@@ -3127,32 +2612,32 @@ const NetworkSettingsModal = _ref2 => {
|
|
|
3127
2612
|
|
|
3128
2613
|
// 更新LAN配置
|
|
3129
2614
|
if (sections.includes('LAN') && values.LAN) {
|
|
3130
|
-
const lanData = values.LAN.map((item, index) =>
|
|
3131
|
-
|
|
3132
|
-
|
|
3133
|
-
|
|
2615
|
+
const lanData = values.LAN.map((item, index) => {
|
|
2616
|
+
var _lanConfigs$index;
|
|
2617
|
+
return _objectSpread2({
|
|
2618
|
+
connection_id: (_lanConfigs$index = lanConfigs[index]) === null || _lanConfigs$index === void 0 ? void 0 : _lanConfigs$index.connection_id,
|
|
2619
|
+
ip_address: item.ip_address
|
|
2620
|
+
}, showNetmask.LAN ? {
|
|
3134
2621
|
netmask: item.netmask
|
|
3135
|
-
} : {})
|
|
3136
|
-
})
|
|
2622
|
+
} : {});
|
|
2623
|
+
});
|
|
3137
2624
|
updatePromises.push(updateLanConfig(lanData));
|
|
3138
2625
|
}
|
|
3139
2626
|
|
|
3140
2627
|
// 更新QSFP配置
|
|
3141
2628
|
if (sections.includes('QSFP') && values.QSFP) {
|
|
3142
|
-
const interfacesData = values.QSFP.map((item, index) =>
|
|
3143
|
-
|
|
3144
|
-
|
|
3145
|
-
id: st2110Interfaces
|
|
3146
|
-
}),
|
|
3147
|
-
...(st2110Interfaces?.[index]?.ip !== undefined ? {
|
|
2629
|
+
const interfacesData = values.QSFP.map((item, index) => {
|
|
2630
|
+
var _st2110Interfaces$ind, _st2110Interfaces$ind2, _st2110Interfaces$ind3;
|
|
2631
|
+
return _objectSpread2(_objectSpread2(_objectSpread2({}, (st2110Interfaces === null || st2110Interfaces === void 0 || (_st2110Interfaces$ind = st2110Interfaces[index]) === null || _st2110Interfaces$ind === void 0 ? void 0 : _st2110Interfaces$ind.id) !== undefined && {
|
|
2632
|
+
id: st2110Interfaces === null || st2110Interfaces === void 0 || (_st2110Interfaces$ind2 = st2110Interfaces[index]) === null || _st2110Interfaces$ind2 === void 0 ? void 0 : _st2110Interfaces$ind2.id
|
|
2633
|
+
}), (st2110Interfaces === null || st2110Interfaces === void 0 || (_st2110Interfaces$ind3 = st2110Interfaces[index]) === null || _st2110Interfaces$ind3 === void 0 ? void 0 : _st2110Interfaces$ind3.ip) !== undefined ? {
|
|
3148
2634
|
ip: item.ip_address
|
|
3149
2635
|
} : {
|
|
3150
2636
|
ip_address: item.ip_address
|
|
3151
|
-
}),
|
|
3152
|
-
...(showNetmask.QSFP ? {
|
|
2637
|
+
}), showNetmask.QSFP ? {
|
|
3153
2638
|
netmask: item.netmask
|
|
3154
|
-
} : {})
|
|
3155
|
-
})
|
|
2639
|
+
} : {});
|
|
2640
|
+
});
|
|
3156
2641
|
const st2110Data = st2110Interfaces.some(iface => 'id' in iface) ? {
|
|
3157
2642
|
st2110_interfaces: interfacesData
|
|
3158
2643
|
} : {
|
|
@@ -3178,7 +2663,7 @@ const NetworkSettingsModal = _ref2 => {
|
|
|
3178
2663
|
}, [form, sections, lanConfigs, st2110Interfaces, updateLanConfig, updateSysConfig, handleSuccess, message]);
|
|
3179
2664
|
|
|
3180
2665
|
// 合并默认模态框属性和传入的属性
|
|
3181
|
-
const mergedModalProps = {
|
|
2666
|
+
const mergedModalProps = _objectSpread2({
|
|
3182
2667
|
title: "Network Settings",
|
|
3183
2668
|
width: 650,
|
|
3184
2669
|
open,
|
|
@@ -3188,21 +2673,19 @@ const NetworkSettingsModal = _ref2 => {
|
|
|
3188
2673
|
okText: "Apply",
|
|
3189
2674
|
cancelText: "Close",
|
|
3190
2675
|
centered: true,
|
|
3191
|
-
styles: {
|
|
2676
|
+
styles: _objectSpread2({
|
|
3192
2677
|
body: {
|
|
3193
2678
|
padding: "16px 24px 8px 24px"
|
|
3194
|
-
}
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
...modalProps
|
|
3202
|
-
};
|
|
2679
|
+
}
|
|
2680
|
+
}, restartRemark !== null && {
|
|
2681
|
+
footer: {
|
|
2682
|
+
paddingBottom: 28
|
|
2683
|
+
}
|
|
2684
|
+
})
|
|
2685
|
+
}, modalProps);
|
|
3203
2686
|
|
|
3204
2687
|
// 合并默认表单属性和传入的属性
|
|
3205
|
-
const mergedFormProps = {
|
|
2688
|
+
const mergedFormProps = _objectSpread2({
|
|
3206
2689
|
form: form,
|
|
3207
2690
|
labelCol: {
|
|
3208
2691
|
span: 6
|
|
@@ -3210,13 +2693,10 @@ const NetworkSettingsModal = _ref2 => {
|
|
|
3210
2693
|
wrapperCol: {
|
|
3211
2694
|
span: 18
|
|
3212
2695
|
},
|
|
3213
|
-
autoComplete: "off"
|
|
3214
|
-
|
|
3215
|
-
}
|
|
3216
|
-
|
|
3217
|
-
...mergedModalProps,
|
|
3218
|
-
children: [/*#__PURE__*/jsxs(Form, {
|
|
3219
|
-
...mergedFormProps,
|
|
2696
|
+
autoComplete: "off"
|
|
2697
|
+
}, formProps);
|
|
2698
|
+
return /*#__PURE__*/jsxs(Modal, _objectSpread2(_objectSpread2({}, mergedModalProps), {}, {
|
|
2699
|
+
children: [/*#__PURE__*/jsxs(Form, _objectSpread2(_objectSpread2({}, mergedFormProps), {}, {
|
|
3220
2700
|
children: [sections.includes('LAN') && lanConfigs.length > 0 && /*#__PURE__*/jsxs(Fragment, {
|
|
3221
2701
|
children: [/*#__PURE__*/jsx(NetworkFieldGroup, {
|
|
3222
2702
|
prefix: "LAN",
|
|
@@ -3228,8 +2708,8 @@ const NetworkSettingsModal = _ref2 => {
|
|
|
3228
2708
|
interfaces: st2110Interfaces,
|
|
3229
2709
|
fieldConfig: preparedFieldConfig.QSFP
|
|
3230
2710
|
})]
|
|
3231
|
-
}), restartRemark]
|
|
3232
|
-
});
|
|
2711
|
+
})), restartRemark]
|
|
2712
|
+
}));
|
|
3233
2713
|
};
|
|
3234
2714
|
var NetworkSettingsModal$1 = /*#__PURE__*/memo(NetworkSettingsModal);
|
|
3235
2715
|
|
|
@@ -3255,7 +2735,7 @@ const LeftList = /*#__PURE__*/memo(_ref => {
|
|
|
3255
2735
|
className: "list-container",
|
|
3256
2736
|
children: /*#__PURE__*/jsx(List, {
|
|
3257
2737
|
header: /*#__PURE__*/jsxs("div", {
|
|
3258
|
-
className:
|
|
2738
|
+
className: "grid ".concat(gridColumns, " w-full list-header"),
|
|
3259
2739
|
children: [/*#__PURE__*/jsx("div", {
|
|
3260
2740
|
children: "Name"
|
|
3261
2741
|
}), /*#__PURE__*/jsx("div", {
|
|
@@ -3267,13 +2747,13 @@ const LeftList = /*#__PURE__*/memo(_ref => {
|
|
|
3267
2747
|
dataSource: dataSource,
|
|
3268
2748
|
rowKey: "id",
|
|
3269
2749
|
renderItem: item => /*#__PURE__*/jsx(List.Item, {
|
|
3270
|
-
className:
|
|
2750
|
+
className: "list-item ".concat(selectedPresetId === item.id ? 'selected' : ''),
|
|
3271
2751
|
style: {
|
|
3272
2752
|
padding: "9px 24px"
|
|
3273
2753
|
},
|
|
3274
2754
|
onClick: () => onSelectPreset(item),
|
|
3275
2755
|
children: /*#__PURE__*/jsxs("div", {
|
|
3276
|
-
className:
|
|
2756
|
+
className: "grid ".concat(gridColumns, " w-full text-text-normal"),
|
|
3277
2757
|
children: [/*#__PURE__*/jsx("div", {
|
|
3278
2758
|
title: item.name,
|
|
3279
2759
|
children: item.name || "Untitled Preset"
|
|
@@ -3390,10 +2870,9 @@ const RightDetailForm = /*#__PURE__*/memo(_ref3 => {
|
|
|
3390
2870
|
return fields.category_list.options.map(category => {
|
|
3391
2871
|
const isInitiallySelected = initialSelected.includes(category.name);
|
|
3392
2872
|
const shouldDisable = isEditing ? !isInitiallySelected : false;
|
|
3393
|
-
return {
|
|
3394
|
-
...category,
|
|
2873
|
+
return _objectSpread2(_objectSpread2({}, category), {}, {
|
|
3395
2874
|
disabled: shouldDisable
|
|
3396
|
-
};
|
|
2875
|
+
});
|
|
3397
2876
|
});
|
|
3398
2877
|
}, [initialSelected, isEditing, hasCategoryList, fields.category_list]);
|
|
3399
2878
|
return /*#__PURE__*/jsxs(Flex, {
|
|
@@ -3452,13 +2931,13 @@ const RightDetailForm = /*#__PURE__*/memo(_ref3 => {
|
|
|
3452
2931
|
disabled: isEditing
|
|
3453
2932
|
})
|
|
3454
2933
|
})]
|
|
3455
|
-
}), isEditing ? /*#__PURE__*/jsx(SubmitButton, {
|
|
3456
|
-
action: onLoad
|
|
3457
|
-
|
|
3458
|
-
|
|
3459
|
-
|
|
2934
|
+
}), isEditing ? /*#__PURE__*/jsx(SubmitButton, _objectSpread2(_objectSpread2({
|
|
2935
|
+
action: onLoad
|
|
2936
|
+
}, hasCategoryList && {
|
|
2937
|
+
disabled: !currentSelected.length
|
|
2938
|
+
}), {}, {
|
|
3460
2939
|
children: texts.loadButton
|
|
3461
|
-
}) : /*#__PURE__*/jsx(SubmitButton, {
|
|
2940
|
+
})) : /*#__PURE__*/jsx(SubmitButton, {
|
|
3462
2941
|
action: onSave,
|
|
3463
2942
|
loading: isLoading,
|
|
3464
2943
|
children: texts.saveButton
|
|
@@ -3516,7 +2995,7 @@ const Preset = _ref => {
|
|
|
3516
2995
|
const fetchPresetList = useCallback(async () => {
|
|
3517
2996
|
try {
|
|
3518
2997
|
const data = await getPresetList();
|
|
3519
|
-
const presets = data
|
|
2998
|
+
const presets = (data === null || data === void 0 ? void 0 : data.preset_list) || data || [];
|
|
3520
2999
|
setPresetList(presets);
|
|
3521
3000
|
} catch (error) {
|
|
3522
3001
|
console.error('Failed to fetch preset list:', error);
|
|
@@ -3528,6 +3007,7 @@ const Preset = _ref => {
|
|
|
3528
3007
|
// setPresetChanged(prev => prev + 1); // 触发更新
|
|
3529
3008
|
}, [form]);
|
|
3530
3009
|
const handleAddNew = useCallback(() => {
|
|
3010
|
+
var _fields$category_list;
|
|
3531
3011
|
const unsavedPreset = presetList.find(item => !item.id);
|
|
3532
3012
|
if (unsavedPreset) {
|
|
3533
3013
|
AntdMessage.warning('Existing unsaved preset detected.');
|
|
@@ -3541,7 +3021,7 @@ const Preset = _ref => {
|
|
|
3541
3021
|
}, {});
|
|
3542
3022
|
|
|
3543
3023
|
// 特殊处理 category_list
|
|
3544
|
-
if (fields.category_list
|
|
3024
|
+
if ((_fields$category_list = fields.category_list) !== null && _fields$category_list !== void 0 && _fields$category_list.options) {
|
|
3545
3025
|
newPreset.category_list = fields.category_list.options.map(item => item.name);
|
|
3546
3026
|
}
|
|
3547
3027
|
setPresetList([...presetList, newPreset]);
|
|
@@ -3557,7 +3037,7 @@ const Preset = _ref => {
|
|
|
3557
3037
|
try {
|
|
3558
3038
|
AntdModal.confirm({
|
|
3559
3039
|
icon: /*#__PURE__*/jsx(ExclamationCircleFilled, {}),
|
|
3560
|
-
title:
|
|
3040
|
+
title: "".concat(texts.deleteConfirm, " \"").concat(presetName, "\"?"),
|
|
3561
3041
|
cancelText: 'No',
|
|
3562
3042
|
okText: 'Yes',
|
|
3563
3043
|
onOk: async () => {
|
|
@@ -3582,7 +3062,7 @@ const Preset = _ref => {
|
|
|
3582
3062
|
}
|
|
3583
3063
|
}, [selectedPreset, form, AntdModal, AntdMessage, fetchPresetList, texts]);
|
|
3584
3064
|
const handleLoadPreset = useCallback(async () => {
|
|
3585
|
-
if (!selectedPreset
|
|
3065
|
+
if (!(selectedPreset !== null && selectedPreset !== void 0 && selectedPreset.id)) return;
|
|
3586
3066
|
|
|
3587
3067
|
// 显示加载模态框
|
|
3588
3068
|
const modalInstance = Modal.info({
|
|
@@ -3599,12 +3079,11 @@ const Preset = _ref => {
|
|
|
3599
3079
|
}
|
|
3600
3080
|
});
|
|
3601
3081
|
try {
|
|
3602
|
-
await loadPreset({
|
|
3603
|
-
id: selectedPreset.id
|
|
3604
|
-
|
|
3605
|
-
|
|
3606
|
-
|
|
3607
|
-
});
|
|
3082
|
+
await loadPreset(_objectSpread2({
|
|
3083
|
+
id: selectedPreset.id
|
|
3084
|
+
}, selectedPreset.category_list && {
|
|
3085
|
+
category_list: selectedPreset.category_list
|
|
3086
|
+
}));
|
|
3608
3087
|
// 成功时延迟关闭
|
|
3609
3088
|
setTimeout(() => {
|
|
3610
3089
|
modalInstance.destroy();
|
|
@@ -3643,13 +3122,13 @@ const Preset = _ref => {
|
|
|
3643
3122
|
title: texts.title,
|
|
3644
3123
|
width: width,
|
|
3645
3124
|
open: open,
|
|
3646
|
-
wrapClassName:
|
|
3125
|
+
wrapClassName: "preset-management ".concat(className),
|
|
3647
3126
|
footer: null,
|
|
3648
3127
|
onCancel: onClose,
|
|
3649
3128
|
centered: true,
|
|
3650
3129
|
styles: {
|
|
3651
3130
|
body: {
|
|
3652
|
-
height:
|
|
3131
|
+
height: "".concat(height, "px")
|
|
3653
3132
|
}
|
|
3654
3133
|
},
|
|
3655
3134
|
children: /*#__PURE__*/jsxs(Row, {
|
|
@@ -3660,7 +3139,7 @@ const Preset = _ref => {
|
|
|
3660
3139
|
className: "h-full",
|
|
3661
3140
|
children: /*#__PURE__*/jsx(LeftList, {
|
|
3662
3141
|
dataSource: presetList,
|
|
3663
|
-
selectedPresetId: selectedPreset
|
|
3142
|
+
selectedPresetId: selectedPreset === null || selectedPreset === void 0 ? void 0 : selectedPreset.id,
|
|
3664
3143
|
onSelectPreset: handleSelectPreset,
|
|
3665
3144
|
onAddNew: handleAddNew,
|
|
3666
3145
|
onRemove: handleRemove,
|
|
@@ -3679,7 +3158,7 @@ const Preset = _ref => {
|
|
|
3679
3158
|
onSave: handleSave,
|
|
3680
3159
|
onLoad: handleLoadPreset,
|
|
3681
3160
|
isLoading: loading,
|
|
3682
|
-
isEditing: !!selectedPreset
|
|
3161
|
+
isEditing: !!(selectedPreset !== null && selectedPreset !== void 0 && selectedPreset.id),
|
|
3683
3162
|
fields: fields,
|
|
3684
3163
|
texts: {
|
|
3685
3164
|
loadButton: texts.loadButton,
|
|
@@ -3702,5 +3181,5 @@ const Preset = _ref => {
|
|
|
3702
3181
|
};
|
|
3703
3182
|
var PresetModal = /*#__PURE__*/memo(Preset);
|
|
3704
3183
|
|
|
3705
|
-
export { AuthorizationModal$1 as AuthorizationModal, NetworkSettingsModal$1 as NetworkSettingsModal, PresetModal, PtpModal$1 as PtpModal, SystemOperations$1 as SystemOperations, UpgradeManager$1 as UpgradeManager, useAuth,
|
|
3184
|
+
export { AuthorizationModal$1 as AuthorizationModal, NetworkSettingsModal$1 as NetworkSettingsModal, PresetModal, PtpModal$1 as PtpModal, SystemOperations$1 as SystemOperations, UpgradeManager$1 as UpgradeManager, useAuth, useHardwareUsage$1 as useHardwareUsage, useHardwareWebSocket$1 as useHardwareWebSocket, useSystemOperations$1 as useSystemOperations, useUpgrade$1 as useUpgrade };
|
|
3706
3185
|
//# sourceMappingURL=index.esm.js.map
|