@sl-material/sl-import 1.0.0-beta16 → 1.0.0-beta18

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/sl-import.es.js CHANGED
@@ -41,203 +41,128 @@ const getImageRatioOptions = (t2) => [
41
41
  { label: t2("imageRatio1to1"), value: "1:1" },
42
42
  { label: t2("imageRatio16to9"), value: "16:9" }
43
43
  ];
44
- const getTranslatedTemplateConfigs = (t2) => ({
44
+ const BASE_TEMPLATE_CONFIG = {
45
+ type: ExportTypeEnum.excel,
46
+ tabs: [],
47
+ showBrand: false,
48
+ showImageRatio: false,
49
+ showMonth: false,
50
+ showDateRange: false,
51
+ uploadTitle: "",
52
+ uploadLinkText: "",
53
+ uploadHint: "",
54
+ acceptTypes: ".xls,.xlsx",
55
+ tips: [],
56
+ templateUrl: "/template/base_template.xlsx"
57
+ };
58
+ const TEMPLATE_OVERRIDES = {
45
59
  [TemplateTypeEnum.BASE]: {
46
- type: ExportTypeEnum.excel,
47
- tabs: [],
48
- showBrand: false,
49
- showImageRatio: false,
50
- showMonth: false,
51
- showDateRange: false,
52
- uploadTitle: t2("uploadTitleBase"),
53
- uploadLinkText: t2("uploadLinkTextDefault"),
54
- uploadHint: t2("uploadHintExcel"),
55
- acceptTypes: ".xls,.xlsx",
56
- tips: [],
57
- templateUrl: "/template/base_template.xlsx"
60
+ uploadTitleKey: "uploadTitleBase",
61
+ uploadLinkTextKey: "uploadLinkTextDefault",
62
+ uploadHintKey: "uploadHintExcel"
58
63
  },
59
64
  [TemplateTypeEnum.TEMPLATE1]: {
60
- type: ExportTypeEnum.excel,
61
- tabs: [],
62
65
  showBrand: true,
63
66
  showImageRatio: true,
64
- showMonth: false,
65
- showDateRange: false,
66
- uploadTitle: t2("uploadTitleTemplate1"),
67
- uploadLinkText: t2("uploadLinkTextDefault"),
68
- uploadHint: t2("uploadHintExcel"),
69
- acceptTypes: ".xls,.xlsx",
70
- tips: t2("tipsTemplate1").split("\n"),
67
+ uploadTitleKey: "uploadTitleTemplate1",
68
+ uploadLinkTextKey: "uploadLinkTextDefault",
69
+ uploadHintKey: "uploadHintExcel",
70
+ tipsKey: "tipsTemplate1",
71
71
  templateUrl: "/template/template1.xlsx"
72
72
  },
73
73
  [TemplateTypeEnum.TEMPLATE2]: {
74
- type: ExportTypeEnum.excel,
75
74
  tabs: [
76
- { label: t2("tabCoverImport"), key: "cover" },
77
- { label: t2("tabIncrementImport"), key: "increment" }
75
+ { labelKey: "tabCoverImport", key: "cover" },
76
+ { labelKey: "tabIncrementImport", key: "increment" }
78
77
  ],
79
- showBrand: false,
80
- showImageRatio: false,
81
- showMonth: false,
82
- showDateRange: false,
83
- uploadTitle: t2("uploadTitleTemplate2"),
84
- uploadLinkText: t2("uploadLinkTextImport"),
85
- uploadHint: t2("uploadHintImage"),
78
+ uploadTitleKey: "uploadTitleTemplate2",
79
+ uploadLinkTextKey: "uploadLinkTextImport",
80
+ uploadHintKey: "uploadHintImage",
86
81
  acceptTypes: ".rar,.zip,.jpg,.png,.jpeg",
87
- tips: t2("tipsTemplate2").split("\n"),
82
+ tipsKey: "tipsTemplate2",
88
83
  templateUrl: "/template/template2.xlsx"
89
84
  },
90
85
  [TemplateTypeEnum.TEMPLATE3]: {
91
- type: ExportTypeEnum.excel,
92
- tabs: [],
93
86
  showBrand: true,
94
- showImageRatio: false,
95
- showMonth: false,
96
- showDateRange: false,
97
- uploadTitle: t2("uploadTitleTemplate3"),
98
- uploadLinkText: t2("uploadLinkTextImport"),
99
- uploadHint: t2("uploadHintExcel"),
100
- acceptTypes: ".xls,.xlsx",
101
- tips: t2("tipsTemplate3").split("\n"),
87
+ uploadTitleKey: "uploadTitleTemplate3",
88
+ uploadLinkTextKey: "uploadLinkTextImport",
89
+ uploadHintKey: "uploadHintExcel",
90
+ tipsKey: "tipsTemplate3",
102
91
  templateUrl: "/template/template3.xlsx"
103
92
  },
104
93
  [TemplateTypeEnum.TEMPLATE4]: {
105
- type: ExportTypeEnum.excel,
106
- tabs: [],
107
94
  showBrand: true,
108
- showImageRatio: false,
109
- showMonth: false,
110
- showDateRange: false,
111
- uploadTitle: t2("uploadTitleTemplate4"),
112
- uploadLinkText: t2("uploadLinkTextImport"),
113
- uploadHint: t2("uploadHintExcel"),
114
- acceptTypes: ".xls,.xlsx",
115
- tips: t2("tipsTemplate4").split("\n"),
95
+ uploadTitleKey: "uploadTitleTemplate4",
96
+ uploadLinkTextKey: "uploadLinkTextImport",
97
+ uploadHintKey: "uploadHintExcel",
98
+ tipsKey: "tipsTemplate4",
116
99
  templateUrl: "/template/template4.xlsx"
117
100
  },
118
101
  [TemplateTypeEnum.TEMPLATE5]: {
119
- type: ExportTypeEnum.excel,
120
102
  tabs: [
121
- { label: t2("tabInPrice"), key: "inPrice" },
122
- { label: t2("tabOutPrice"), key: "outPrice" }
103
+ { labelKey: "tabInPrice", key: "inPrice" },
104
+ { labelKey: "tabOutPrice", key: "outPrice" }
123
105
  ],
124
- showBrand: false,
125
- showImageRatio: false,
126
- showMonth: false,
127
106
  showDateRange: true,
128
- uploadTitle: t2("uploadTitleTemplate5"),
129
- uploadLinkText: t2("uploadLinkTextImport"),
130
- uploadHint: t2("uploadHintExcel"),
131
- acceptTypes: ".xls,.xlsx",
132
- tips: t2("tipsTemplate5").split("\n"),
107
+ uploadTitleKey: "uploadTitleTemplate5",
108
+ uploadLinkTextKey: "uploadLinkTextImport",
109
+ uploadHintKey: "uploadHintExcel",
110
+ tipsKey: "tipsTemplate5",
133
111
  templateUrl: "/template/template5.xlsx"
134
112
  }
135
- });
136
- const DEFAULT_TEMPLATE_CONFIGS = {
137
- [TemplateTypeEnum.BASE]: {
138
- type: ExportTypeEnum.excel,
139
- tabs: [],
140
- showBrand: false,
141
- showImageRatio: false,
142
- showMonth: false,
143
- showDateRange: false,
144
- uploadTitle: "上传文件",
145
- uploadLinkText: "点击上传",
146
- uploadHint: "文件仅支持扩展名:.xls,.xlsx",
147
- acceptTypes: ".xls,.xlsx",
148
- tips: [],
149
- templateUrl: "/template/base_template.xlsx"
150
- },
151
- [TemplateTypeEnum.TEMPLATE1]: {
152
- type: ExportTypeEnum.excel,
153
- tabs: [],
154
- showBrand: true,
155
- showImageRatio: true,
156
- showMonth: false,
157
- showDateRange: false,
158
- uploadTitle: "上传编辑好的文件",
159
- uploadLinkText: "点击上传",
160
- uploadHint: "文件仅支持扩展名:.xls,.xlsx",
161
- acceptTypes: ".xls,.xlsx",
162
- tips: ["这里写一些提示信息"],
163
- templateUrl: "/template/template1.xlsx"
164
- },
165
- [TemplateTypeEnum.TEMPLATE2]: {
166
- type: ExportTypeEnum.excel,
167
- tabs: [
168
- { label: "覆盖导入数据", key: "cover" },
169
- { label: "增量导入数据", key: "increment" }
170
- ],
171
- showBrand: false,
172
- showImageRatio: false,
173
- showMonth: false,
174
- showDateRange: false,
175
- uploadTitle: "导入菜品图片文件",
176
- uploadLinkText: "点击导入",
177
- uploadHint: "文件仅支持扩展名:.rar .zip .jpg .png .jpeg",
178
- acceptTypes: ".rar,.zip,.jpg,.png,.jpeg",
179
- tips: [
180
- "图片名称需要与菜品名称一致",
181
- "上传文件仅支持ZIP、RAR压缩包文件(暂不支持win11自带工具压缩的文件),文件大小不超过100M",
182
- "图片支持jpg、png、jpeg格式,单张大小不超过2M"
183
- ],
184
- templateUrl: "/template/template2.xlsx"
185
- },
186
- [TemplateTypeEnum.TEMPLATE3]: {
187
- type: ExportTypeEnum.excel,
188
- tabs: [],
189
- showBrand: false,
190
- showImageRatio: false,
191
- showMonth: true,
192
- showDateRange: false,
193
- uploadTitle: "上传营业目标文件",
194
- uploadLinkText: "点击上传",
195
- uploadHint: "文件仅支持扩展名:.xls,.xlsx",
196
- acceptTypes: ".xls,.xlsx",
197
- tips: [
198
- "日目标金额最多支持两位小数,单位是元",
199
- "导入文件严格按照下载的模版格式进行数据填入",
200
- "导入采用直接覆盖的方式且直接保存成功,不可逆",
201
- "每次仅支持多个门店一个月的目标导入"
202
- ],
203
- templateUrl: "/template/template3.xlsx"
204
- },
205
- [TemplateTypeEnum.TEMPLATE4]: {
206
- type: ExportTypeEnum.excel,
207
- tabs: [],
208
- showBrand: true,
209
- showImageRatio: false,
210
- showMonth: false,
211
- showDateRange: false,
212
- uploadTitle: "导入菜谱方案文件",
213
- uploadLinkText: "点击导入",
214
- uploadHint: "文件仅支持扩展名:.xls,.xlsx",
215
- acceptTypes: ".xls,.xlsx",
216
- tips: [
217
- "最多支持导入五个菜谱方案",
218
- "菜品以代码为唯一标识进行集团菜品的匹配,请仔细核对菜品代码",
219
- "模版支持导入名称、线上可点分类、价格和自定义分类,其余菜品的属性获取集团菜品库"
220
- ],
221
- templateUrl: "/template/template4.xlsx"
222
- },
223
- [TemplateTypeEnum.TEMPLATE5]: {
224
- type: ExportTypeEnum.excel,
225
- tabs: [
226
- { label: "合批修改入库价格", key: "inPrice" },
227
- { label: "合批修改出库价格", key: "outPrice" }
228
- ],
229
- showBrand: false,
230
- showImageRatio: false,
231
- showMonth: false,
232
- showDateRange: true,
233
- uploadTitle: "导入菜谱方案文件",
234
- uploadLinkText: "点击导入",
235
- uploadHint: "文件仅支持扩展名:.xls,.xlsx",
236
- acceptTypes: ".xls,.xlsx",
237
- tips: [],
238
- templateUrl: "/template/template5.xlsx"
113
+ };
114
+ const getTranslatedTemplateConfigs = (t2) => {
115
+ const result = {};
116
+ for (const templateType of Object.values(TemplateTypeEnum)) {
117
+ const override = TEMPLATE_OVERRIDES[templateType];
118
+ const config = {
119
+ ...BASE_TEMPLATE_CONFIG,
120
+ type: override.type ?? BASE_TEMPLATE_CONFIG.type,
121
+ showBrand: override.showBrand ?? BASE_TEMPLATE_CONFIG.showBrand,
122
+ showImageRatio: override.showImageRatio ?? BASE_TEMPLATE_CONFIG.showImageRatio,
123
+ showMonth: override.showMonth ?? BASE_TEMPLATE_CONFIG.showMonth,
124
+ showDateRange: override.showDateRange ?? BASE_TEMPLATE_CONFIG.showDateRange,
125
+ acceptTypes: override.acceptTypes ?? BASE_TEMPLATE_CONFIG.acceptTypes,
126
+ templateUrl: override.templateUrl ?? BASE_TEMPLATE_CONFIG.templateUrl,
127
+ // 翻译字段
128
+ uploadTitle: override.uploadTitleKey ? t2(override.uploadTitleKey) : "",
129
+ uploadLinkText: override.uploadLinkTextKey ? t2(override.uploadLinkTextKey) : "",
130
+ uploadHint: override.uploadHintKey ? t2(override.uploadHintKey) : "",
131
+ tips: override.tipsKey ? t2(override.tipsKey).split("\n") : [],
132
+ // 翻译 tabs
133
+ tabs: override.tabs ? override.tabs.map((tab) => ({
134
+ label: t2(tab.labelKey),
135
+ key: tab.key
136
+ })) : []
137
+ };
138
+ result[templateType] = config;
239
139
  }
140
+ return result;
240
141
  };
142
+ const DEFAULT_TEMPLATE_CONFIGS = getTranslatedTemplateConfigs((key) => {
143
+ const defaultMessages = {
144
+ uploadTitleBase: "上传文件",
145
+ uploadTitleTemplate1: "上传编辑好的文件",
146
+ uploadTitleTemplate2: "导入菜品图片文件",
147
+ uploadTitleTemplate3: "上传营业目标文件",
148
+ uploadTitleTemplate4: "导入菜谱方案文件",
149
+ uploadTitleTemplate5: "导入菜谱方案文件",
150
+ uploadLinkTextDefault: "点击上传",
151
+ uploadLinkTextImport: "点击导入",
152
+ uploadHintExcel: "文件仅支持扩展名:.xls,.xlsx",
153
+ uploadHintImage: "文件仅支持扩展名:.rar .zip .jpg .png .jpeg",
154
+ tabCoverImport: "覆盖导入数据",
155
+ tabIncrementImport: "增量导入数据",
156
+ tabInPrice: "合批修改入库价格",
157
+ tabOutPrice: "合批修改出库价格",
158
+ tipsTemplate1: "这里写一些提示信息",
159
+ tipsTemplate2: "图片名称需要与菜品名称一致\n上传文件仅支持ZIP、RAR压缩包文件(暂不支持win11自带工具压缩的文件),文件大小不超过100M\n图片支持jpg、png、jpeg格式,单张大小不超过2M",
160
+ tipsTemplate3: "日目标金额最多支持两位小数,单位是元\n导入文件严格按照下载的模版格式进行数据填入\n导入采用直接覆盖的方式且直接保存成功,不可逆\n每次仅支持多个门店一个月的目标导入",
161
+ tipsTemplate4: "最多支持导入五个菜谱方案\n菜品以代码为唯一标识进行集团菜品的匹配,请仔细核对菜品代码\n模版支持导入名称、线上可点分类、价格和自定义分类,其余菜品的属性获取集团菜品库",
162
+ tipsTemplate5: ""
163
+ };
164
+ return defaultMessages[key] || "";
165
+ });
241
166
  const types = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
242
167
  __proto__: null,
243
168
  DEFAULT_IMAGE_RATIOS,
@@ -3168,7 +3093,7 @@ class ImportDialogUploader {
3168
3093
  * 获取并发限制数
3169
3094
  */
3170
3095
  get concurrentLimit() {
3171
- return this.config.concurrentLimit ?? 3;
3096
+ return this.config.concurrentLimit != null ? this.config.concurrentLimit : 3;
3172
3097
  }
3173
3098
  /**
3174
3099
  * 判断是否应该使用分片上传
@@ -3311,27 +3236,49 @@ class ImportDialogUploader {
3311
3236
  }
3312
3237
  /**
3313
3238
  * 删除文件
3239
+ * @param index 文件索引,不传则清空所有文件
3240
+ *
3241
+ * 删除权限:
3242
+ * - pending 状态:可删除(还没开始上传)
3243
+ * - uploading 状态:不可删除(正在上传/处理中)
3244
+ * - success/error 状态:可删除(已完成)
3314
3245
  */
3315
3246
  removeFile(index) {
3316
- var _a, _b, _c, _d, _e, _f;
3247
+ var _a, _b, _c, _d, _e, _f, _g, _h;
3317
3248
  if (index !== void 0 && index >= 0 && index < this.uploadFileList.length) {
3318
3249
  const fileItem = this.uploadFileList[index];
3319
3250
  if (fileItem.status === "uploading") {
3320
- (_b = (_a = this.callbacks).onMessage) == null ? void 0 : _b.call(_a, "正在上传中,无法删除", "warning");
3251
+ (_b = (_a = this.callbacks).onMessage) == null ? void 0 : _b.call(_a, "文件正在处理中,无法删除", "warning");
3321
3252
  return false;
3322
3253
  }
3254
+ const queueIndex = this.uploadQueue.findIndex(
3255
+ (q) => q.id === fileItem.id
3256
+ );
3257
+ if (queueIndex !== -1) {
3258
+ this.uploadQueue.splice(queueIndex, 1);
3259
+ }
3323
3260
  this.uploadFileList.splice(index, 1);
3324
3261
  this.fileList.splice(index, 1);
3325
3262
  } else {
3263
+ const hasUploading = this.uploadFileList.some(
3264
+ (f) => f.status === "uploading"
3265
+ );
3266
+ if (hasUploading) {
3267
+ (_d = (_c = this.callbacks).onMessage) == null ? void 0 : _d.call(_c, "有文件正在处理中,无法清空", "warning");
3268
+ return false;
3269
+ }
3270
+ this.uploadQueue = [];
3326
3271
  this.uploadFileList = [];
3327
3272
  this.fileList = [];
3328
3273
  }
3329
3274
  this.uploadProgress = 0;
3330
3275
  this.uploadMessage = "";
3331
3276
  this.uploadMessageType = "info";
3332
- this.isUploading = false;
3333
- (_d = (_c = this.callbacks).onFileChange) == null ? void 0 : _d.call(_c, this.uploadFileList);
3334
- (_f = (_e = this.callbacks).onUpdate) == null ? void 0 : _f.call(_e);
3277
+ this.isUploading = this.uploadFileList.some(
3278
+ (f) => f.status === "uploading"
3279
+ );
3280
+ (_f = (_e = this.callbacks).onFileChange) == null ? void 0 : _f.call(_e, this.uploadFileList);
3281
+ (_h = (_g = this.callbacks).onUpdate) == null ? void 0 : _h.call(_g);
3335
3282
  return true;
3336
3283
  }
3337
3284
  /**
@@ -3602,19 +3549,19 @@ const _ImportDialog = class _ImportDialog {
3602
3549
  onMessage: (msg, type) => this.showMessage(msg, type),
3603
3550
  onFileChange: (files) => {
3604
3551
  var _a, _b;
3605
- return (_b = (_a = this.modalOptions).onFileChange) == null ? void 0 : _b.call(_a, files);
3552
+ return (_b = (_a = this.modalOptions.uploadConfig) == null ? void 0 : _a.onFileChange) == null ? void 0 : _b.call(_a, files);
3606
3553
  },
3607
3554
  onUploadProgress: (file, progress) => {
3608
3555
  var _a, _b;
3609
- return (_b = (_a = this.modalOptions).onUploadProgress) == null ? void 0 : _b.call(_a, file, progress);
3556
+ return (_b = (_a = this.modalOptions.uploadConfig) == null ? void 0 : _a.onProgress) == null ? void 0 : _b.call(_a, file, progress);
3610
3557
  },
3611
3558
  onUploadSuccess: (file, response) => {
3612
3559
  var _a, _b;
3613
- return (_b = (_a = this.modalOptions).onUploadSuccess) == null ? void 0 : _b.call(_a, file, response);
3560
+ return (_b = (_a = this.modalOptions.uploadConfig) == null ? void 0 : _a.onSuccess) == null ? void 0 : _b.call(_a, file, response);
3614
3561
  },
3615
3562
  onUploadError: (file, error) => {
3616
3563
  var _a, _b;
3617
- return (_b = (_a = this.modalOptions).onUploadError) == null ? void 0 : _b.call(_a, file, error);
3564
+ return (_b = (_a = this.modalOptions.uploadConfig) == null ? void 0 : _a.onError) == null ? void 0 : _b.call(_a, file, error);
3618
3565
  }
3619
3566
  }
3620
3567
  );
@@ -4129,7 +4076,7 @@ const _ImportDialog = class _ImportDialog {
4129
4076
  return _ImportDialog.instance;
4130
4077
  }
4131
4078
  static open(options) {
4132
- return new Promise((resolve, reject) => {
4079
+ return new Promise((resolve) => {
4133
4080
  const dialog = _ImportDialog.getInstance();
4134
4081
  const wrappedOptions = {
4135
4082
  ...options,
@@ -4157,7 +4104,7 @@ const _ImportDialog = class _ImportDialog {
4157
4104
  if (options == null ? void 0 : options.onCancel) {
4158
4105
  options.onCancel();
4159
4106
  }
4160
- reject(new Error("用户取消"));
4107
+ resolve(null);
4161
4108
  }
4162
4109
  };
4163
4110
  dialog._openModalCore(wrappedOptions);