seeder-st2110-components 1.2.6 → 1.2.8
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.css +1 -0
- package/dist/index.esm.js +490 -11
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +496 -16
- package/dist/index.js.map +1 -1
- package/package.json +12 -2
- package/src/styles/index.less +113 -0
package/dist/index.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.preset-management .w-full{width:100%}.preset-management .h-full{height:100%}.preset-management .h-auto{height:auto}.preset-management .p-0{padding:0}.preset-management .p-4{padding:16px}.preset-management .p-6{padding:24px}.preset-management .p-8{padding:32px}.preset-management .block{display:block}.preset-management .mx-auto{margin-left:auto;margin-right:auto}.preset-management .text-gray-400{color:#9ca3af}.preset-management .text-text-normal{color:#bfbfbf}.preset-management .grid{display:grid}.preset-management .grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.preset-management .grid-cols-3{grid-template-columns:repeat(3,minmax(0,1fr))}.preset-management .ant-modal .ant-modal-content{padding:0}.preset-management .ant-modal-header{padding-block-start:24px;padding-inline:24px}.preset-management .ant-spin-nested-loading{margin-block-start:0}.preset-management .left-list-wrapper{display:flex;flex-direction:column;position:relative}.preset-management .left-list-wrapper:after{background-color:rgba(0,0,0,.3);bottom:0;content:"";display:block;position:absolute;right:0;top:0;width:1px}.preset-management .left-list-wrapper .list-container{flex:1;overflow-y:auto}.preset-management .left-list-wrapper .list-container::-webkit-scrollbar-track-piece{background:#282828;box-shadow:0 1px 1px 0 #282828}.preset-management .left-list-wrapper .list-container::-webkit-scrollbar{width:5px}.preset-management .left-list-wrapper .list-container::-webkit-scrollbar-thumb{background:#141414;border-radius:2em;box-shadow:0 1px 1px 0 #282828}.preset-management .left-list-wrapper .list-header{color:hsla(0,0%,100%,.75);font-weight:500;padding-block:4px;padding-inline:24px}.preset-management .left-list-wrapper .list-item{background-color:transparent;cursor:pointer;transition-duration:.15s;transition-property:background-color;transition-timing-function:cubic-bezier(.4,0,.2,1)}.preset-management .left-list-wrapper .list-item.selected{background-color:hsla(0,0%,100%,.12)}.preset-management .submit-btn-wrapper{bottom:0;left:0;margin-block-start:0;padding:16px 24px;position:absolute;right:0;text-align:right}
|
package/dist/index.esm.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { useState, useCallback, useEffect, memo, useMemo, useRef, forwardRef, useContext, createContext } from 'react';
|
|
2
2
|
import { useWebSocket, useInterval } from 'ahooks';
|
|
3
|
-
import { Tooltip, Space, Flex, Divider, App, Modal, Form, Input, Alert, message, Dropdown, Spin, Popover, Button, Popconfirm, Typography, Empty, ConfigProvider, Tree, InputNumber, Badge, Switch, Select } from 'antd';
|
|
3
|
+
import { Tooltip, Space, Flex, Divider, App, Modal, Form, Input, Alert, message, Dropdown, Spin, Popover, Button, Popconfirm, Typography, Empty, ConfigProvider, Tree, InputNumber, Badge, Switch, Select, List, Checkbox, Row, Col } from 'antd';
|
|
4
4
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
5
|
-
import { LoadingOutlined, ExclamationCircleFilled, FolderOpenOutlined, FolderOutlined } from '@ant-design/icons';
|
|
5
|
+
import { LoadingOutlined, ExclamationCircleFilled, FolderOpenOutlined, FolderOutlined, PlusOutlined } from '@ant-design/icons';
|
|
6
6
|
import axios from 'axios';
|
|
7
7
|
|
|
8
8
|
const useHardwareWebSocket = socketUrl => {
|
|
@@ -48,6 +48,7 @@ const useHardwareWebSocket = socketUrl => {
|
|
|
48
48
|
ps_status: systemStatus
|
|
49
49
|
};
|
|
50
50
|
};
|
|
51
|
+
var useHardwareWebSocket$1 = useHardwareWebSocket;
|
|
51
52
|
|
|
52
53
|
const UsageItem = /*#__PURE__*/memo(_ref => {
|
|
53
54
|
let {
|
|
@@ -83,6 +84,7 @@ const UsageItem = /*#__PURE__*/memo(_ref => {
|
|
|
83
84
|
})]
|
|
84
85
|
});
|
|
85
86
|
});
|
|
87
|
+
var UsageItem$1 = UsageItem;
|
|
86
88
|
|
|
87
89
|
const getTemperature = (supermicro, sensors) => {
|
|
88
90
|
return supermicro?.cpu_temperature ?? sensors?.temperatures?.coretemp?.[0]?.current;
|
|
@@ -100,29 +102,29 @@ const useHardwareUsage = function (ps_status) {
|
|
|
100
102
|
} = ps_status;
|
|
101
103
|
return /*#__PURE__*/jsxs("div", {
|
|
102
104
|
className: "flex",
|
|
103
|
-
children: [/*#__PURE__*/jsxs(UsageItem, {
|
|
105
|
+
children: [/*#__PURE__*/jsxs(UsageItem$1, {
|
|
104
106
|
text: "CPU Usage",
|
|
105
107
|
iconClass: "icon-CPU",
|
|
106
108
|
children: [cpu_percent, "%"]
|
|
107
|
-
}), /*#__PURE__*/jsxs(UsageItem, {
|
|
109
|
+
}), /*#__PURE__*/jsxs(UsageItem$1, {
|
|
108
110
|
text: "CPU Temperature",
|
|
109
111
|
iconClass: "icon-wendu",
|
|
110
112
|
children: [getTemperature(supermicro, sensors_temperatures), "\u2103"]
|
|
111
|
-
}), mem && /*#__PURE__*/jsxs(UsageItem, {
|
|
113
|
+
}), mem && /*#__PURE__*/jsxs(UsageItem$1, {
|
|
112
114
|
text: "Memory Usage",
|
|
113
115
|
iconClass: "icon-shiyongshuai",
|
|
114
116
|
showRam: showRam,
|
|
115
117
|
ramValue: (mem.total / (1024 * 1024 * 1024)).toFixed(1),
|
|
116
118
|
children: [mem.percent, "%"]
|
|
117
|
-
}), supermicro?.nic_temperature && /*#__PURE__*/jsxs(UsageItem, {
|
|
119
|
+
}), supermicro?.nic_temperature && /*#__PURE__*/jsxs(UsageItem$1, {
|
|
118
120
|
text: "NIC Temperature",
|
|
119
121
|
iconClass: "icon-wuliwangka",
|
|
120
122
|
children: [supermicro.nic_temperature, "\u2103"]
|
|
121
|
-
}), gpu_stats?.length > 0 && /*#__PURE__*/jsx(UsageItem, {
|
|
123
|
+
}), gpu_stats?.length > 0 && /*#__PURE__*/jsx(UsageItem$1, {
|
|
122
124
|
text: "GPU Usage",
|
|
123
125
|
iconClass: "icon-gpufuwu",
|
|
124
126
|
children: gpu_stats[0]["utilization.gpu"]
|
|
125
|
-
}), supermicro?.gpu_temperature && /*#__PURE__*/jsxs(UsageItem, {
|
|
127
|
+
}), supermicro?.gpu_temperature && /*#__PURE__*/jsxs(UsageItem$1, {
|
|
126
128
|
text: "GPU Temperature",
|
|
127
129
|
iconClass: "icon-wendu",
|
|
128
130
|
children: [supermicro.gpu_temperature, "\u2103"]
|
|
@@ -130,6 +132,7 @@ const useHardwareUsage = function (ps_status) {
|
|
|
130
132
|
});
|
|
131
133
|
}, [ps_status]);
|
|
132
134
|
};
|
|
135
|
+
var useHardwareUsage$1 = useHardwareUsage;
|
|
133
136
|
|
|
134
137
|
const AuthorizationModal = _ref => {
|
|
135
138
|
let {
|
|
@@ -219,6 +222,7 @@ const AuthorizationModal = _ref => {
|
|
|
219
222
|
})
|
|
220
223
|
});
|
|
221
224
|
};
|
|
225
|
+
var AuthorizationModal$1 = AuthorizationModal;
|
|
222
226
|
|
|
223
227
|
const DEFAULT_AUTH = {
|
|
224
228
|
accredit_status: false,
|
|
@@ -292,7 +296,7 @@ const useAuth = options => {
|
|
|
292
296
|
}
|
|
293
297
|
};
|
|
294
298
|
const modal = showModal && /*#__PURE__*/jsxs(Fragment, {
|
|
295
|
-
children: [/*#__PURE__*/jsx(AuthorizationModal, {
|
|
299
|
+
children: [/*#__PURE__*/jsx(AuthorizationModal$1, {
|
|
296
300
|
onOk: auth,
|
|
297
301
|
onCancel: closeModal,
|
|
298
302
|
authData: authData
|
|
@@ -610,6 +614,7 @@ const useUpgrade = _ref => {
|
|
|
610
614
|
});
|
|
611
615
|
return [upgradeElement];
|
|
612
616
|
};
|
|
617
|
+
var useUpgrade$1 = useUpgrade;
|
|
613
618
|
|
|
614
619
|
const useSystemOperations = function () {
|
|
615
620
|
let {
|
|
@@ -665,6 +670,7 @@ const useSystemOperations = function () {
|
|
|
665
670
|
handleMenuClick
|
|
666
671
|
};
|
|
667
672
|
};
|
|
673
|
+
var useSystemOperations$1 = useSystemOperations;
|
|
668
674
|
|
|
669
675
|
const PopoverContent = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
670
676
|
let {
|
|
@@ -1230,6 +1236,7 @@ const useDirectoryTree = _ref => {
|
|
|
1230
1236
|
removeFile
|
|
1231
1237
|
};
|
|
1232
1238
|
};
|
|
1239
|
+
var useDirectoryTree$1 = useDirectoryTree;
|
|
1233
1240
|
|
|
1234
1241
|
const UpgradeManager = _ref => {
|
|
1235
1242
|
let {
|
|
@@ -1244,7 +1251,7 @@ const UpgradeManager = _ref => {
|
|
|
1244
1251
|
children,
|
|
1245
1252
|
...dropdownProps
|
|
1246
1253
|
} = _ref;
|
|
1247
|
-
const [upgradeElement] = useUpgrade({
|
|
1254
|
+
const [upgradeElement] = useUpgrade$1({
|
|
1248
1255
|
menuItems,
|
|
1249
1256
|
onMenuClick,
|
|
1250
1257
|
downloadFiles,
|
|
@@ -1274,6 +1281,7 @@ UpgradeManager.defaultProps = {
|
|
|
1274
1281
|
trigger: ["hover"],
|
|
1275
1282
|
placement: "bottomRight"
|
|
1276
1283
|
};
|
|
1284
|
+
var UpgradeManager$1 = UpgradeManager;
|
|
1277
1285
|
|
|
1278
1286
|
function getDefaultExportFromCjs (x) {
|
|
1279
1287
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
@@ -2551,6 +2559,7 @@ SystemOperations.propTypes = {
|
|
|
2551
2559
|
okText: PropTypes.string,
|
|
2552
2560
|
run: PropTypes.func
|
|
2553
2561
|
};
|
|
2562
|
+
var SystemOperations$1 = SystemOperations;
|
|
2554
2563
|
|
|
2555
2564
|
const defaultFieldConfigs = {
|
|
2556
2565
|
clock_class: {
|
|
@@ -3175,5 +3184,475 @@ const NetworkSettingsModal = _ref2 => {
|
|
|
3175
3184
|
};
|
|
3176
3185
|
var NetworkSettingsModal$1 = /*#__PURE__*/memo(NetworkSettingsModal);
|
|
3177
3186
|
|
|
3178
|
-
|
|
3187
|
+
const LeftList = /*#__PURE__*/memo(_ref => {
|
|
3188
|
+
let {
|
|
3189
|
+
dataSource,
|
|
3190
|
+
selectedPresetId,
|
|
3191
|
+
onSelectPreset,
|
|
3192
|
+
onAddNew,
|
|
3193
|
+
onRemove,
|
|
3194
|
+
hasPresets = dataSource.length > 0,
|
|
3195
|
+
showDescription = false,
|
|
3196
|
+
texts = {
|
|
3197
|
+
newButton: "New Preset",
|
|
3198
|
+
removeButton: "Remove"
|
|
3199
|
+
}
|
|
3200
|
+
} = _ref;
|
|
3201
|
+
// 动态计算列布局
|
|
3202
|
+
const gridColumns = showDescription ? "grid-cols-3" : "grid-cols-2";
|
|
3203
|
+
return /*#__PURE__*/jsxs("div", {
|
|
3204
|
+
className: "h-full left-list-wrapper",
|
|
3205
|
+
children: [/*#__PURE__*/jsx("div", {
|
|
3206
|
+
className: "list-container",
|
|
3207
|
+
children: /*#__PURE__*/jsx(List, {
|
|
3208
|
+
header: /*#__PURE__*/jsxs("div", {
|
|
3209
|
+
className: `grid ${gridColumns} w-full list-header`,
|
|
3210
|
+
children: [/*#__PURE__*/jsx("div", {
|
|
3211
|
+
children: "Name"
|
|
3212
|
+
}), /*#__PURE__*/jsx("div", {
|
|
3213
|
+
children: "Create Time"
|
|
3214
|
+
}), showDescription && /*#__PURE__*/jsx("div", {
|
|
3215
|
+
children: "Description"
|
|
3216
|
+
})]
|
|
3217
|
+
}),
|
|
3218
|
+
dataSource: dataSource,
|
|
3219
|
+
rowKey: "id",
|
|
3220
|
+
renderItem: item => /*#__PURE__*/jsx(List.Item, {
|
|
3221
|
+
className: `list-item ${selectedPresetId === item.id ? 'selected' : ''}`,
|
|
3222
|
+
style: {
|
|
3223
|
+
padding: "9px 24px"
|
|
3224
|
+
},
|
|
3225
|
+
onClick: () => onSelectPreset(item),
|
|
3226
|
+
children: /*#__PURE__*/jsxs("div", {
|
|
3227
|
+
className: `grid ${gridColumns} w-full text-text-normal`,
|
|
3228
|
+
children: [/*#__PURE__*/jsx("div", {
|
|
3229
|
+
title: item.name,
|
|
3230
|
+
children: item.name || "Untitled Preset"
|
|
3231
|
+
}), /*#__PURE__*/jsx("div", {
|
|
3232
|
+
children: item.create_time
|
|
3233
|
+
}), showDescription && /*#__PURE__*/jsx("div", {
|
|
3234
|
+
children: item.description
|
|
3235
|
+
})]
|
|
3236
|
+
})
|
|
3237
|
+
}),
|
|
3238
|
+
locale: {
|
|
3239
|
+
emptyText: /*#__PURE__*/jsx("div", {
|
|
3240
|
+
className: "p-8",
|
|
3241
|
+
children: /*#__PURE__*/jsx(Empty, {
|
|
3242
|
+
image: Empty.PRESENTED_IMAGE_SIMPLE,
|
|
3243
|
+
description: /*#__PURE__*/jsx("span", {
|
|
3244
|
+
className: "text-gray-400",
|
|
3245
|
+
children: /*#__PURE__*/jsx(Button, {
|
|
3246
|
+
type: "link",
|
|
3247
|
+
onClick: onAddNew,
|
|
3248
|
+
className: "p-0 h-auto",
|
|
3249
|
+
icon: /*#__PURE__*/jsx(PlusOutlined, {}),
|
|
3250
|
+
children: "Create new preset"
|
|
3251
|
+
})
|
|
3252
|
+
})
|
|
3253
|
+
})
|
|
3254
|
+
})
|
|
3255
|
+
}
|
|
3256
|
+
})
|
|
3257
|
+
}), hasPresets && /*#__PURE__*/jsx("div", {
|
|
3258
|
+
className: "p-4",
|
|
3259
|
+
style: {
|
|
3260
|
+
paddingInline: 24
|
|
3261
|
+
},
|
|
3262
|
+
children: /*#__PURE__*/jsxs(Space, {
|
|
3263
|
+
size: "middle",
|
|
3264
|
+
children: [/*#__PURE__*/jsx(Button, {
|
|
3265
|
+
type: "default",
|
|
3266
|
+
icon: /*#__PURE__*/jsx(PlusOutlined, {}),
|
|
3267
|
+
style: {
|
|
3268
|
+
padding: "20px 12px"
|
|
3269
|
+
},
|
|
3270
|
+
className: "btn-gray",
|
|
3271
|
+
onClick: onAddNew,
|
|
3272
|
+
children: texts.newButton
|
|
3273
|
+
}), /*#__PURE__*/jsx(Button, {
|
|
3274
|
+
type: "default",
|
|
3275
|
+
style: {
|
|
3276
|
+
padding: "20px 12px"
|
|
3277
|
+
},
|
|
3278
|
+
className: "btn-gray",
|
|
3279
|
+
onClick: onRemove,
|
|
3280
|
+
children: texts.removeButton
|
|
3281
|
+
})]
|
|
3282
|
+
})
|
|
3283
|
+
})]
|
|
3284
|
+
});
|
|
3285
|
+
});
|
|
3286
|
+
const SubmitButton = _ref2 => {
|
|
3287
|
+
let {
|
|
3288
|
+
loading,
|
|
3289
|
+
action,
|
|
3290
|
+
children,
|
|
3291
|
+
disabled = false
|
|
3292
|
+
} = _ref2;
|
|
3293
|
+
return /*#__PURE__*/jsx("div", {
|
|
3294
|
+
className: "submit-btn-wrapper",
|
|
3295
|
+
children: /*#__PURE__*/jsx(Button, {
|
|
3296
|
+
className: "btn-gray",
|
|
3297
|
+
loading: loading,
|
|
3298
|
+
onClick: action,
|
|
3299
|
+
disabled: disabled,
|
|
3300
|
+
children: children
|
|
3301
|
+
})
|
|
3302
|
+
});
|
|
3303
|
+
};
|
|
3304
|
+
const RightDetailForm = /*#__PURE__*/memo(_ref3 => {
|
|
3305
|
+
let {
|
|
3306
|
+
form,
|
|
3307
|
+
onSave,
|
|
3308
|
+
onLoad,
|
|
3309
|
+
isLoading,
|
|
3310
|
+
isEditing,
|
|
3311
|
+
fields = {
|
|
3312
|
+
name: {
|
|
3313
|
+
label: "Preset Name",
|
|
3314
|
+
placeholder: "Enter preset name",
|
|
3315
|
+
required: true
|
|
3316
|
+
}
|
|
3317
|
+
},
|
|
3318
|
+
texts = {
|
|
3319
|
+
loadButton: "Load",
|
|
3320
|
+
saveButton: "Save"
|
|
3321
|
+
},
|
|
3322
|
+
presetChanged
|
|
3323
|
+
} = _ref3;
|
|
3324
|
+
const [initialSelected, setInitialSelected] = useState([]);
|
|
3325
|
+
const currentSelected = Form.useWatch('category_list', form) || [];
|
|
3326
|
+
|
|
3327
|
+
// 检查是否包含category_list字段
|
|
3328
|
+
const hasCategoryList = fields.category_list !== null && fields.category_list !== undefined;
|
|
3329
|
+
|
|
3330
|
+
// 初始化 category_list 的选择状态
|
|
3331
|
+
useEffect(() => {
|
|
3332
|
+
if (hasCategoryList) {
|
|
3333
|
+
const currentValue = form.getFieldValue('category_list') || [];
|
|
3334
|
+
setInitialSelected(currentValue);
|
|
3335
|
+
}
|
|
3336
|
+
}, [presetChanged, form, hasCategoryList]); // 当presetChanged变化时更新
|
|
3337
|
+
|
|
3338
|
+
// 动态生成 checkbox 选项
|
|
3339
|
+
const checkboxOptions = useMemo(() => {
|
|
3340
|
+
if (!hasCategoryList) return [];
|
|
3341
|
+
return fields.category_list.options.map(category => {
|
|
3342
|
+
const isInitiallySelected = initialSelected.includes(category.name);
|
|
3343
|
+
const shouldDisable = isEditing ? !isInitiallySelected : false;
|
|
3344
|
+
return {
|
|
3345
|
+
...category,
|
|
3346
|
+
disabled: shouldDisable
|
|
3347
|
+
};
|
|
3348
|
+
});
|
|
3349
|
+
}, [initialSelected, isEditing, hasCategoryList, fields.category_list]);
|
|
3350
|
+
return /*#__PURE__*/jsxs(Flex, {
|
|
3351
|
+
vertical: true,
|
|
3352
|
+
className: "h-full",
|
|
3353
|
+
children: [/*#__PURE__*/jsxs(Form, {
|
|
3354
|
+
form: form,
|
|
3355
|
+
layout: "vertical",
|
|
3356
|
+
autoComplete: "off",
|
|
3357
|
+
style: {
|
|
3358
|
+
flex: 1,
|
|
3359
|
+
overflowY: 'auto'
|
|
3360
|
+
},
|
|
3361
|
+
children: [/*#__PURE__*/jsx(Form.Item, {
|
|
3362
|
+
name: "name",
|
|
3363
|
+
label: fields.name.label,
|
|
3364
|
+
rules: [{
|
|
3365
|
+
required: fields.name.required,
|
|
3366
|
+
validator: async (_, value) => {
|
|
3367
|
+
if (!value || value.trim() === '') {
|
|
3368
|
+
return Promise.reject(new Error('Preset name cannot be empty or spaces only'));
|
|
3369
|
+
}
|
|
3370
|
+
}
|
|
3371
|
+
}],
|
|
3372
|
+
children: /*#__PURE__*/jsx(Input, {
|
|
3373
|
+
placeholder: fields.name.placeholder,
|
|
3374
|
+
disabled: isEditing
|
|
3375
|
+
})
|
|
3376
|
+
}), hasCategoryList && /*#__PURE__*/jsx(Form.Item, {
|
|
3377
|
+
name: "category_list",
|
|
3378
|
+
label: fields.category_list.label,
|
|
3379
|
+
rules: [{
|
|
3380
|
+
required: fields.category_list.required,
|
|
3381
|
+
message: 'Please select at least one category',
|
|
3382
|
+
validator: (_, value) => {
|
|
3383
|
+
if (value && value.length > 0) {
|
|
3384
|
+
return Promise.resolve();
|
|
3385
|
+
}
|
|
3386
|
+
return Promise.reject(new Error('Please select at least one category'));
|
|
3387
|
+
}
|
|
3388
|
+
}],
|
|
3389
|
+
children: /*#__PURE__*/jsx(Checkbox.Group, {
|
|
3390
|
+
className: "grid grid-cols-2 gap-2",
|
|
3391
|
+
children: checkboxOptions.map(category => /*#__PURE__*/jsx(Checkbox, {
|
|
3392
|
+
value: category.name,
|
|
3393
|
+
disabled: category.disabled,
|
|
3394
|
+
children: category.label
|
|
3395
|
+
}, category.name))
|
|
3396
|
+
})
|
|
3397
|
+
}), fields.description && /*#__PURE__*/jsx(Form.Item, {
|
|
3398
|
+
name: "description",
|
|
3399
|
+
label: fields.description.label,
|
|
3400
|
+
children: /*#__PURE__*/jsx(Input.TextArea, {
|
|
3401
|
+
rows: 4,
|
|
3402
|
+
placeholder: fields.description.placeholder,
|
|
3403
|
+
disabled: isEditing
|
|
3404
|
+
})
|
|
3405
|
+
})]
|
|
3406
|
+
}), isEditing ? /*#__PURE__*/jsx(SubmitButton, {
|
|
3407
|
+
action: onLoad,
|
|
3408
|
+
...(hasCategoryList && {
|
|
3409
|
+
disabled: !currentSelected.length
|
|
3410
|
+
}),
|
|
3411
|
+
children: texts.loadButton
|
|
3412
|
+
}) : /*#__PURE__*/jsx(SubmitButton, {
|
|
3413
|
+
action: onSave,
|
|
3414
|
+
loading: isLoading,
|
|
3415
|
+
children: texts.saveButton
|
|
3416
|
+
})]
|
|
3417
|
+
});
|
|
3418
|
+
});
|
|
3419
|
+
|
|
3420
|
+
const Preset = _ref => {
|
|
3421
|
+
let {
|
|
3422
|
+
open,
|
|
3423
|
+
onClose,
|
|
3424
|
+
// API 方法通过 props 传入
|
|
3425
|
+
getPresetList,
|
|
3426
|
+
savePreset,
|
|
3427
|
+
removePreset,
|
|
3428
|
+
loadPreset,
|
|
3429
|
+
// 字段配置
|
|
3430
|
+
fields = {
|
|
3431
|
+
name: {
|
|
3432
|
+
label: "Preset Name",
|
|
3433
|
+
placeholder: "Enter preset name",
|
|
3434
|
+
required: true
|
|
3435
|
+
}
|
|
3436
|
+
},
|
|
3437
|
+
texts = {
|
|
3438
|
+
title: "Preset Management",
|
|
3439
|
+
emptyText: "Select a preset from the list to view details",
|
|
3440
|
+
deleteConfirm: "Are you sure to delete preset",
|
|
3441
|
+
loadText: "Loading...",
|
|
3442
|
+
successText: "Success",
|
|
3443
|
+
newButton: "New Preset",
|
|
3444
|
+
removeButton: "Remove",
|
|
3445
|
+
loadButton: "Load",
|
|
3446
|
+
saveButton: "Save"
|
|
3447
|
+
},
|
|
3448
|
+
// 样式定制
|
|
3449
|
+
width = 1000,
|
|
3450
|
+
height = 680,
|
|
3451
|
+
className = ""
|
|
3452
|
+
} = _ref;
|
|
3453
|
+
const {
|
|
3454
|
+
message: AntdMessage,
|
|
3455
|
+
modal: AntdModal
|
|
3456
|
+
} = App.useApp();
|
|
3457
|
+
const [presetList, setPresetList] = useState([]);
|
|
3458
|
+
const [selectedPreset, setSelectedPreset] = useState(null);
|
|
3459
|
+
const [loading, setLoading] = useState(false);
|
|
3460
|
+
const [presetChanged, setPresetChanged] = useState(0);
|
|
3461
|
+
const [form] = Form.useForm();
|
|
3462
|
+
|
|
3463
|
+
// 获取预设列表
|
|
3464
|
+
useEffect(() => {
|
|
3465
|
+
fetchPresetList();
|
|
3466
|
+
}, []);
|
|
3467
|
+
const fetchPresetList = useCallback(async () => {
|
|
3468
|
+
try {
|
|
3469
|
+
const data = await getPresetList();
|
|
3470
|
+
if (data?.preset_list) {
|
|
3471
|
+
setPresetList(data.preset_list);
|
|
3472
|
+
}
|
|
3473
|
+
} catch (error) {
|
|
3474
|
+
console.error('Failed to fetch preset list:', error);
|
|
3475
|
+
}
|
|
3476
|
+
}, [getPresetList]);
|
|
3477
|
+
const handleSelectPreset = useCallback(preset => {
|
|
3478
|
+
setSelectedPreset(preset);
|
|
3479
|
+
form.setFieldsValue(preset);
|
|
3480
|
+
// setPresetChanged(prev => prev + 1); // 触发更新
|
|
3481
|
+
}, [form]);
|
|
3482
|
+
const handleAddNew = useCallback(() => {
|
|
3483
|
+
const unsavedPreset = presetList.find(item => !item.id);
|
|
3484
|
+
if (unsavedPreset) {
|
|
3485
|
+
AntdMessage.warning('Existing unsaved preset detected.');
|
|
3486
|
+
return;
|
|
3487
|
+
}
|
|
3488
|
+
|
|
3489
|
+
// 创建新的数据,包含所有配置的字段
|
|
3490
|
+
const newPreset = Object.keys(fields).reduce((acc, fieldName) => {
|
|
3491
|
+
acc[fieldName] = '';
|
|
3492
|
+
return acc;
|
|
3493
|
+
}, {});
|
|
3494
|
+
|
|
3495
|
+
// 特殊处理 category_list
|
|
3496
|
+
if (fields.category_list?.options) {
|
|
3497
|
+
newPreset.category_list = fields.category_list.options.map(item => item.name);
|
|
3498
|
+
}
|
|
3499
|
+
setPresetList([...presetList, newPreset]);
|
|
3500
|
+
setSelectedPreset(newPreset);
|
|
3501
|
+
form.setFieldsValue(newPreset);
|
|
3502
|
+
}, [form, presetList, AntdMessage]);
|
|
3503
|
+
const handleRemove = useCallback(async () => {
|
|
3504
|
+
if (!selectedPreset) return;
|
|
3505
|
+
|
|
3506
|
+
// 检查是否为新建的未保存数据(无id)
|
|
3507
|
+
const isUnsavedPreset = !selectedPreset.id;
|
|
3508
|
+
const presetName = selectedPreset.name || 'Untitled Preset';
|
|
3509
|
+
try {
|
|
3510
|
+
AntdModal.confirm({
|
|
3511
|
+
icon: /*#__PURE__*/jsx(ExclamationCircleFilled, {}),
|
|
3512
|
+
title: `${texts.deleteConfirm} "${presetName}"?`,
|
|
3513
|
+
cancelText: 'No',
|
|
3514
|
+
okText: 'Yes',
|
|
3515
|
+
onOk: async () => {
|
|
3516
|
+
if (!isUnsavedPreset) {
|
|
3517
|
+
await removePreset({
|
|
3518
|
+
id: selectedPreset.id
|
|
3519
|
+
});
|
|
3520
|
+
AntdMessage.success(texts.successText);
|
|
3521
|
+
// 刷新列表
|
|
3522
|
+
await fetchPresetList();
|
|
3523
|
+
} else {
|
|
3524
|
+
setPresetList(prev => prev.filter(item => !!item.id));
|
|
3525
|
+
}
|
|
3526
|
+
|
|
3527
|
+
// 重置表单和选择状态
|
|
3528
|
+
setSelectedPreset(null);
|
|
3529
|
+
form.resetFields();
|
|
3530
|
+
}
|
|
3531
|
+
});
|
|
3532
|
+
} catch (error) {
|
|
3533
|
+
console.error('Failed to delete preset:', error);
|
|
3534
|
+
}
|
|
3535
|
+
}, [selectedPreset, form, AntdModal, AntdMessage, fetchPresetList, texts]);
|
|
3536
|
+
const handleLoadPreset = useCallback(async () => {
|
|
3537
|
+
if (!selectedPreset?.id) return;
|
|
3538
|
+
|
|
3539
|
+
// 显示加载模态框
|
|
3540
|
+
const modalInstance = Modal.info({
|
|
3541
|
+
title: texts.loadText,
|
|
3542
|
+
content: /*#__PURE__*/jsx(Spin, {
|
|
3543
|
+
size: "large",
|
|
3544
|
+
className: "block mx-auto"
|
|
3545
|
+
}),
|
|
3546
|
+
maskClosable: false,
|
|
3547
|
+
okButtonProps: {
|
|
3548
|
+
style: {
|
|
3549
|
+
display: 'none'
|
|
3550
|
+
}
|
|
3551
|
+
}
|
|
3552
|
+
});
|
|
3553
|
+
try {
|
|
3554
|
+
await loadPreset({
|
|
3555
|
+
id: selectedPreset.id,
|
|
3556
|
+
...(selectedPreset.category_list && {
|
|
3557
|
+
category_list: selectedPreset.category_list
|
|
3558
|
+
})
|
|
3559
|
+
});
|
|
3560
|
+
// 成功时延迟关闭
|
|
3561
|
+
setTimeout(() => {
|
|
3562
|
+
modalInstance.destroy();
|
|
3563
|
+
AntdMessage.success(texts.successText);
|
|
3564
|
+
}, 1000);
|
|
3565
|
+
} catch (error) {
|
|
3566
|
+
console.error('Failed to load preset:', error);
|
|
3567
|
+
modalInstance.destroy();
|
|
3568
|
+
}
|
|
3569
|
+
}, [selectedPreset, loadPreset, texts, AntdMessage]);
|
|
3570
|
+
const handleSave = useCallback(async () => {
|
|
3571
|
+
setLoading(true);
|
|
3572
|
+
try {
|
|
3573
|
+
const values = await form.validateFields();
|
|
3574
|
+
console.log('Form values:', values);
|
|
3575
|
+
await savePreset(values);
|
|
3576
|
+
AntdMessage.success(texts.successText);
|
|
3577
|
+
// 刷新列表
|
|
3578
|
+
await fetchPresetList();
|
|
3579
|
+
|
|
3580
|
+
// 重置表单和选择状态
|
|
3581
|
+
setSelectedPreset(null);
|
|
3582
|
+
form.resetFields();
|
|
3583
|
+
} catch (error) {
|
|
3584
|
+
if (error.errorFields) {
|
|
3585
|
+
// 表单验证错误
|
|
3586
|
+
console.error('Form validation failed:', error.errorFields);
|
|
3587
|
+
} else {
|
|
3588
|
+
console.error('Failed to save preset:', error);
|
|
3589
|
+
}
|
|
3590
|
+
} finally {
|
|
3591
|
+
setLoading(false);
|
|
3592
|
+
}
|
|
3593
|
+
}, [form, AntdMessage, fetchPresetList, savePreset, texts]);
|
|
3594
|
+
return /*#__PURE__*/jsx(Modal, {
|
|
3595
|
+
title: texts.title,
|
|
3596
|
+
width: width,
|
|
3597
|
+
open: open,
|
|
3598
|
+
wrapClassName: `preset-management ${className}`,
|
|
3599
|
+
footer: null,
|
|
3600
|
+
onCancel: onClose,
|
|
3601
|
+
centered: true,
|
|
3602
|
+
styles: {
|
|
3603
|
+
body: {
|
|
3604
|
+
height: `${height}px`
|
|
3605
|
+
}
|
|
3606
|
+
},
|
|
3607
|
+
children: /*#__PURE__*/jsxs(Row, {
|
|
3608
|
+
gutter: 0,
|
|
3609
|
+
className: "h-full w-full",
|
|
3610
|
+
children: [/*#__PURE__*/jsx(Col, {
|
|
3611
|
+
span: 14,
|
|
3612
|
+
className: "h-full",
|
|
3613
|
+
children: /*#__PURE__*/jsx(LeftList, {
|
|
3614
|
+
dataSource: presetList,
|
|
3615
|
+
selectedPresetId: selectedPreset?.id,
|
|
3616
|
+
onSelectPreset: handleSelectPreset,
|
|
3617
|
+
onAddNew: handleAddNew,
|
|
3618
|
+
onRemove: handleRemove,
|
|
3619
|
+
showDescription: !!fields.description // 根据 fields 判断是否显示 description
|
|
3620
|
+
,
|
|
3621
|
+
texts: {
|
|
3622
|
+
newButton: texts.newButton,
|
|
3623
|
+
removeButton: texts.removeButton
|
|
3624
|
+
}
|
|
3625
|
+
})
|
|
3626
|
+
}), /*#__PURE__*/jsx(Col, {
|
|
3627
|
+
span: 10,
|
|
3628
|
+
className: "h-full p-6",
|
|
3629
|
+
children: selectedPreset ? /*#__PURE__*/jsx(RightDetailForm, {
|
|
3630
|
+
form: form,
|
|
3631
|
+
onSave: handleSave,
|
|
3632
|
+
onLoad: handleLoadPreset,
|
|
3633
|
+
isLoading: loading,
|
|
3634
|
+
isEditing: !!selectedPreset?.id,
|
|
3635
|
+
fields: fields,
|
|
3636
|
+
texts: {
|
|
3637
|
+
loadButton: texts.loadButton,
|
|
3638
|
+
saveButton: texts.saveButton
|
|
3639
|
+
},
|
|
3640
|
+
presetChanged: presetChanged
|
|
3641
|
+
}) : /*#__PURE__*/jsx(Flex, {
|
|
3642
|
+
vertical: true,
|
|
3643
|
+
justify: "center",
|
|
3644
|
+
align: "center",
|
|
3645
|
+
className: "h-full text-gray-400",
|
|
3646
|
+
children: /*#__PURE__*/jsx(Empty, {
|
|
3647
|
+
image: Empty.PRESENTED_IMAGE_SIMPLE,
|
|
3648
|
+
description: texts.emptyText
|
|
3649
|
+
})
|
|
3650
|
+
})
|
|
3651
|
+
})]
|
|
3652
|
+
})
|
|
3653
|
+
});
|
|
3654
|
+
};
|
|
3655
|
+
var PresetModal = /*#__PURE__*/memo(Preset);
|
|
3656
|
+
|
|
3657
|
+
export { AuthorizationModal$1 as AuthorizationModal, NetworkSettingsModal$1 as NetworkSettingsModal, PresetModal, PtpModal$1 as PtpModal, SystemOperations$1 as SystemOperations, UpgradeManager$1 as UpgradeManager, useAuth, useDirectoryTree$1 as useDirectoryTree, useHardwareUsage$1 as useHardwareUsage, useHardwareWebSocket$1 as useHardwareWebSocket, useSystemOperations$1 as useSystemOperations, useUpgrade$1 as useUpgrade };
|
|
3179
3658
|
//# sourceMappingURL=index.esm.js.map
|