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