seeder-st2110-components 2.0.1 → 2.0.2

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.js CHANGED
@@ -1743,6 +1743,8 @@ var zhCN = {
1743
1743
  'preset.button.save': '保存',
1744
1744
  'preset.button.edit': '编辑',
1745
1745
  'preset.button.cancel': '取消',
1746
+ 'preset.button.import': '导入',
1747
+ 'preset.button.export': '导出',
1746
1748
  'preset.empty.noData': '从列表中选择一个预设查看详情',
1747
1749
  'preset.unsaved.detected': '检测到未保存的预设',
1748
1750
  'preset.empty.create': '创建新预设',
@@ -1756,6 +1758,7 @@ var zhCN = {
1756
1758
  'preset.validation.nameRequired': '名称是必填项',
1757
1759
  'preset.validation.categoryRequired': '请选择分类',
1758
1760
  'preset.error.noSelectionOrIdMissing': '未选择预设或预设 ID 缺失',
1761
+ 'preset.import.invalidFile': '请选择 .preset 格式的文件',
1759
1762
  // License/Auth Modal
1760
1763
  'license.title': '注册许可证',
1761
1764
  'license.machineCode': '机器码',
@@ -1893,6 +1896,8 @@ var enUS = {
1893
1896
  'preset.button.save': 'Save',
1894
1897
  'preset.button.edit': 'Edit',
1895
1898
  'preset.button.cancel': 'Cancel',
1899
+ 'preset.button.import': 'Import',
1900
+ 'preset.button.export': 'Export',
1896
1901
  'preset.empty.noData': 'Select a preset from the list to view details',
1897
1902
  'preset.unsaved.detected': 'Existing unsaved preset detected',
1898
1903
  'preset.empty.create': 'Create New Preset',
@@ -1906,6 +1911,7 @@ var enUS = {
1906
1911
  'preset.validation.nameRequired': 'Name is required',
1907
1912
  'preset.validation.categoryRequired': 'No category selected',
1908
1913
  'preset.error.noSelectionOrIdMissing': 'No preset selected or preset ID is missing',
1914
+ 'preset.import.invalidFile': 'Please select a file with the .preset extension.',
1909
1915
  // License/Auth Modal
1910
1916
  'license.title': 'Register License',
1911
1917
  'license.machineCode': 'Machine Code',
@@ -2679,10 +2685,15 @@ const LeftList = /*#__PURE__*/React.memo(_ref => {
2679
2685
  onSelectPreset,
2680
2686
  onAddNew,
2681
2687
  onRemove,
2688
+ onImport,
2689
+ onExport,
2682
2690
  hasPresets = dataSource.length > 0,
2691
+ enableImportAndExport,
2683
2692
  texts = {
2684
2693
  newButton: "preset.button.new",
2685
- removeButton: "preset.button.delete"
2694
+ removeButton: "preset.button.delete",
2695
+ importButton: "preset.button.import",
2696
+ exportButton: "preset.button.export"
2686
2697
  }
2687
2698
  } = _ref;
2688
2699
  const intl = useIntl();
@@ -2784,6 +2795,19 @@ const LeftList = /*#__PURE__*/React.memo(_ref => {
2784
2795
  className: "btn-gray",
2785
2796
  onClick: onRemove,
2786
2797
  children: texts.removeButton
2798
+ }), enableImportAndExport && /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
2799
+ children: [/*#__PURE__*/jsxRuntime.jsx(antd.Button, {
2800
+ type: "default",
2801
+ className: "btn-gray",
2802
+ onClick: onImport,
2803
+ children: texts.importButton
2804
+ }), /*#__PURE__*/jsxRuntime.jsx(antd.Button, {
2805
+ type: "default",
2806
+ className: "btn-gray",
2807
+ onClick: onExport,
2808
+ disabled: !selectedPresetId,
2809
+ children: texts.exportButton
2810
+ })]
2787
2811
  })]
2788
2812
  })
2789
2813
  })]
@@ -3040,6 +3064,8 @@ const Preset = _ref => {
3040
3064
  removePreset,
3041
3065
  loadPreset,
3042
3066
  updatePreset,
3067
+ uploadPreset,
3068
+ downloadPreset,
3043
3069
  onLoadSuccess,
3044
3070
  // 加载成功后的回调
3045
3071
  onLoadError,
@@ -3065,14 +3091,17 @@ const Preset = _ref => {
3065
3091
  loadButton: "preset.button.load",
3066
3092
  saveButton: "preset.button.save",
3067
3093
  editButton: "preset.button.edit",
3068
- cancelButton: "preset.button.cancel"
3094
+ cancelButton: "preset.button.cancel",
3095
+ importButton: "preset.button.import",
3096
+ exportButton: "preset.button.export"
3069
3097
  },
3070
3098
  // 样式定制
3071
3099
  width = 1000,
3072
3100
  height = 680,
3073
3101
  className = "",
3074
3102
  // 功能配置
3075
- enableEdit = true
3103
+ enableEdit = true,
3104
+ enableImportAndExport = false
3076
3105
  } = _ref;
3077
3106
  const intl = useIntl();
3078
3107
  const {
@@ -3082,6 +3111,7 @@ const Preset = _ref => {
3082
3111
  const [presetList, setPresetList] = React.useState([]);
3083
3112
  const [selectedPreset, setSelectedPreset] = React.useState(null);
3084
3113
  const [loading, setLoading] = React.useState(false);
3114
+ const [uploading, setUploading] = React.useState(false);
3085
3115
  const [presetChanged, setPresetChanged] = React.useState(0);
3086
3116
  const [form] = antd.Form.useForm();
3087
3117
 
@@ -3200,6 +3230,68 @@ const Preset = _ref => {
3200
3230
  console.error('Failed to delete preset:', error);
3201
3231
  }
3202
3232
  }, [selectedPreset, form, modal, message, removePreset, getPresetList, fmt]);
3233
+ const handleImport = React.useCallback(async () => {
3234
+ // 创建一个临时的 input 元素
3235
+ const input = document.createElement('input');
3236
+ input.type = 'file';
3237
+ input.accept = '.preset'; // 限制只能选择 .preset 文件
3238
+
3239
+ input.onchange = async e => {
3240
+ var _e$target$files;
3241
+ const file = (_e$target$files = e.target.files) === null || _e$target$files === void 0 ? void 0 : _e$target$files[0];
3242
+ if (!file) {
3243
+ return; // 用户取消选择
3244
+ }
3245
+
3246
+ // 确保文件扩展名是 .preset(防止 accept 被绕过)
3247
+ if (!file.name.toLowerCase().endsWith('.preset')) {
3248
+ message.error(intl.formatMessage({
3249
+ id: 'preset.import.invalidFile'
3250
+ }));
3251
+ return;
3252
+ }
3253
+ try {
3254
+ setUploading(true);
3255
+ await uploadPreset(file);
3256
+ message.success(intl.formatMessage({
3257
+ id: 'preset.success'
3258
+ }));
3259
+
3260
+ // 上传成功后刷新列表
3261
+ fetchPresetList();
3262
+ } catch (error) {
3263
+ console.error('Failed to import preset file:', error);
3264
+ } finally {
3265
+ setUploading(false);
3266
+ }
3267
+
3268
+ // 清理:移除 input
3269
+ input.remove();
3270
+ };
3271
+
3272
+ // 触发文件选择框
3273
+ input.click();
3274
+ }, [uploadPreset, message, intl, fetchPresetList]);
3275
+ const handleExport = React.useCallback(() => {
3276
+ if (!(selectedPreset !== null && selectedPreset !== void 0 && selectedPreset.id)) {
3277
+ message.warning(intl.formatMessage({
3278
+ id: 'preset.error.noSelectionOrIdMissing'
3279
+ }));
3280
+ return;
3281
+ }
3282
+
3283
+ // 构造下载 URL
3284
+ const downloadUrl = "".concat(downloadPreset, "/").concat(selectedPreset.id);
3285
+
3286
+ // 创建临时 a 标签
3287
+ const link = document.createElement('a');
3288
+ link.href = downloadUrl;
3289
+ link.download = "".concat(selectedPreset.name || 'preset', ".preset"); // 指定文件名
3290
+
3291
+ document.body.appendChild(link);
3292
+ link.click();
3293
+ document.body.removeChild(link);
3294
+ }, [selectedPreset, message, intl]);
3203
3295
  const handleLoadPreset = React.useCallback(async loadData => {
3204
3296
  if (!loadData) return;
3205
3297
  let modalInstance = null;
@@ -3387,9 +3479,14 @@ const Preset = _ref => {
3387
3479
  onSelectPreset: handleSelectPreset,
3388
3480
  onAddNew: handleAddNew,
3389
3481
  onRemove: handleRemove,
3482
+ onImport: handleImport,
3483
+ onExport: handleExport,
3484
+ enableImportAndExport: enableImportAndExport,
3390
3485
  texts: {
3391
3486
  newButton: fmt(texts.newButton),
3392
- removeButton: fmt(texts.removeButton)
3487
+ removeButton: fmt(texts.removeButton),
3488
+ importButton: fmt(texts.importButton),
3489
+ exportButton: fmt(texts.exportButton)
3393
3490
  }
3394
3491
  })
3395
3492
  }), /*#__PURE__*/jsxRuntime.jsx(antd.Col, {