@skyfox2000/webui 1.3.9 → 1.3.11

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.
@@ -451,32 +451,31 @@ const performDataValidation = async (buffer: ArrayBuffer): Promise<void> => {
451
451
 
452
452
  // 统一验证(格式验证和重复验证)
453
453
  const {
454
- hasError,
455
454
  errBlob,
456
455
  validationMsg: valMsg,
457
456
  duplicateMsg: dupMsg,
457
+ hasFormatError,
458
+ hasDuplicateError
458
459
  } = await validateExcelUnified(buffer, excelCtrl.formRules.value, duplicateRules.value, duplicateUrl.value);
459
460
 
460
461
  // 更新验证状态
461
462
  validationMsg.value = valMsg;
462
463
  duplicateMsg.value = dupMsg;
463
464
 
464
- if (hasError) {
465
- // 有验证错误
466
- if (errBlob) {
467
- excelError.value = true;
468
- duplicateError.value = true;
469
- validationType.value = 'error';
470
- duplicateType.value = 'error';
471
- const blobUrl = URL.createObjectURL(errBlob);
472
- excelUrl.value = blobUrl;
473
- }
465
+ // 根据验证结果设置正确的状态类型
466
+ validationType.value = hasFormatError ? 'error' : (excelCtrl.formRules.value && Object.keys(excelCtrl.formRules.value).length > 0 ? 'success' : 'warning');
467
+ duplicateType.value = hasDuplicateError ? 'error' : (duplicateRules.value && duplicateRules.value.length > 0 ? 'success' : 'warning');
468
+
469
+ // 有验证错误
470
+ if (errBlob) {
471
+ excelError.value = hasFormatError ?? false;
472
+ duplicateError.value = hasDuplicateError ?? false;
473
+ const blobUrl = URL.createObjectURL(errBlob);
474
+ excelUrl.value = blobUrl;
474
475
  } else {
475
476
  // 验证成功
476
477
  excelError.value = false;
477
478
  duplicateError.value = false;
478
- validationType.value = 'success';
479
- duplicateType.value = 'success';
480
479
  // 验证成功时,excelUrl会在beforeUpload中设置
481
480
  }
482
481
  } catch (error) {
@@ -316,22 +316,23 @@ export const validateExcelUnified = async (
316
316
  duplicateRules?: string[],
317
317
  duplicateUrl?: IUrlInfo,
318
318
  ): Promise<{
319
- hasError: boolean;
320
319
  errBlob?: Blob;
321
320
  validationMsg: string;
322
321
  duplicateMsg: string;
322
+ hasFormatError?: boolean;
323
+ hasDuplicateError?: boolean;
323
324
  }> => {
324
325
  const allMarkCells: Array<{ row: number; col: number; color: string }> = [];
325
326
  const allMarkHeaders: string[] = [];
326
- let hasValidationError = false;
327
+ let hasFormatError = false;
327
328
  let hasDuplicateError = false;
328
329
  let validationMsg = '数据验证成功';
329
- let duplicateMsg = '数据验证通过';
330
+ let duplicateMsg = '待验证重复数据';
330
331
 
331
332
  // 1. 格式验证
332
333
  const validationResult = await validateExcel(excelBuffer, rules);
333
334
  if (validationResult.hasError) {
334
- hasValidationError = true;
335
+ hasFormatError = true;
335
336
  validationMsg = '数据验证失败';
336
337
  if (validationResult.markCells) {
337
338
  allMarkCells.push(...validationResult.markCells);
@@ -339,6 +340,8 @@ export const validateExcelUnified = async (
339
340
  if (validationResult.markHeaders) {
340
341
  allMarkHeaders.push(...validationResult.markHeaders);
341
342
  }
343
+ } else if (rules && Object.keys(rules).length > 0) {
344
+ validationMsg = '数据验证通过';
342
345
  }
343
346
 
344
347
  // 2. 重复验证
@@ -363,11 +366,15 @@ export const validateExcelUnified = async (
363
366
  if (duplicateResult.markHeaders) {
364
367
  allMarkHeaders.push(...duplicateResult.markHeaders);
365
368
  }
369
+ } else {
370
+ duplicateMsg = '重复性检验通过';
366
371
  }
367
372
  }
368
373
 
374
+ const hasError = hasFormatError || hasDuplicateError;
375
+
369
376
  // 3. 如果有任何错误,创建统一的标记Excel
370
- if (hasValidationError || hasDuplicateError) {
377
+ if (hasError) {
371
378
  const markResult = await createMarkedExcelView(
372
379
  excelBuffer,
373
380
  {
@@ -381,24 +388,27 @@ export const validateExcelUnified = async (
381
388
  const response = await fetch(markResult.blobUrl);
382
389
  const errBlob = await response.blob();
383
390
  return {
384
- hasError: true,
385
391
  errBlob,
386
392
  validationMsg,
387
393
  duplicateMsg,
394
+ hasFormatError,
395
+ hasDuplicateError
388
396
  };
389
397
  } else {
390
398
  return {
391
- hasError: true,
392
399
  validationMsg,
393
400
  duplicateMsg,
401
+ hasFormatError,
402
+ hasDuplicateError
394
403
  };
395
404
  }
396
405
  }
397
406
 
398
407
  return {
399
- hasError: false,
400
408
  validationMsg,
401
409
  duplicateMsg,
410
+ hasFormatError: false,
411
+ hasDuplicateError: false
402
412
  };
403
413
  };
404
414
 
package/src/utils/page.ts CHANGED
@@ -85,6 +85,17 @@ export const initPageFactory = (options: {
85
85
  };
86
86
  };
87
87
 
88
+ const initUrls = (apiUrls: ApiUrls) => {
89
+ for (let urlKey in apiUrls.urls) {
90
+ if (!apiUrls.urls[urlKey]!.api) {
91
+ apiUrls.urls[urlKey]!.api = apiUrls.api;
92
+ }
93
+ if (!apiUrls.urls[urlKey]!.authorize) {
94
+ apiUrls.urls[urlKey]!.authorize = apiUrls.authorize;
95
+ }
96
+ }
97
+ };
98
+
88
99
  /**
89
100
  * 编辑器工厂处理
90
101
  *
@@ -100,6 +111,7 @@ export const useEditorFactory = <T, E>(
100
111
  defaultData?: Partial<E>,
101
112
  formRules?: Record<string, ValidateRule>,
102
113
  ) => {
114
+ initUrls(urls);
103
115
  /**
104
116
  * 表单数据交互控制
105
117
  */
@@ -133,6 +145,7 @@ export const useEditorFactory = <T, E>(
133
145
  * @returns
134
146
  */
135
147
  export const useGridFactory = <T, G>(urls: ApiUrls, pageCtrl: PageControl<T>, columns?: Record<string, any>[]) => {
148
+ initUrls(urls);
136
149
  /**
137
150
  * 表格数据交互控制
138
151
  */
@@ -194,6 +207,7 @@ export const useGridFactory = <T, G>(urls: ApiUrls, pageCtrl: PageControl<T>, co
194
207
  * @returns
195
208
  */
196
209
  export const useTreeFactory = <T>(urls: ApiUrls, pageCtrl: PageControl<T>) => {
210
+ initUrls(urls);
197
211
  /**
198
212
  * 树数据交互控制
199
213
  */
@@ -306,15 +320,7 @@ export const usePageFactory = <T>(
306
320
  defaultData?: Partial<T>,
307
321
  formRules?: Record<string, ValidateRule>,
308
322
  ) => {
309
- // urls 参数处理
310
- // api 默认
311
- // authorize 默认
312
- for (const key in urls.urls) {
313
- if (urls.urls[key]) {
314
- if (!urls.urls[key].api) urls.urls[key].api = urls.api;
315
- if (urls.urls[key].authorize === undefined) urls.urls[key].authorize = urls.authorize;
316
- }
317
- }
323
+ initUrls(urls);
318
324
 
319
325
  /**
320
326
  * 页面交互主数据