@sybz-components/utils 1.0.17 → 1.0.19

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/base.cjs CHANGED
@@ -3,7 +3,7 @@
3
3
  require('vue');
4
4
  require('consola');
5
5
  require('es-toolkit');
6
- const format = require('./shared/utils.CC08jxyG.cjs');
6
+ const format = require('./shared/utils.s3A3s_9I.cjs');
7
7
  require('./confirmSemantic.cjs');
8
8
  require('element-plus');
9
9
  require('axios');
package/dist/base.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as vue from 'vue';
2
- import { VNode, AppContext, Ref } from 'vue';
2
+ import { Component, StyleValue, VNode, AppContext, Ref } from 'vue';
3
3
  import { SybzComponentTheme } from './theme.cjs';
4
4
  import { ConfirmVariant, ConfirmTarget } from './confirmSemantic.cjs';
5
5
  import { MessageOptions, ElMessageBoxOptions, ElMessageBox } from 'element-plus';
@@ -38,7 +38,24 @@ interface SybzUtilsConfig {
38
38
  /** HTTP 客户端的全局配置,应用入口配置一次即可。 */
39
39
  http?: CreateHttpOptions;
40
40
  }
41
- interface ToastOptions extends Partial<MessageOptions> {
41
+ interface ToastOptions extends Omit<Partial<MessageOptions>, 'icon'> {
42
+ /** 是否解析 HTML 字符串,并将已全局注册的组件标签渲染为 Vue 组件;默认 false。仅传可信内容。 */
43
+ dangerouslyUseHTMLString?: boolean;
44
+ /** 图标组件,或由全局 SIcon 自动解析的图标名称。 */
45
+ icon?: string | Component;
46
+ /** 传给 s-icon 或自定义图标组件的属性。 */
47
+ iconAttrs?: {
48
+ size?: string | number;
49
+ color?: string;
50
+ source?: 'auto' | 'element-plus' | 'iconify' | 'css' | 'svg' | 'url';
51
+ type?: 'default' | 'primary' | 'success' | 'warning' | 'danger' | 'info';
52
+ variant?: 'plain' | 'light' | 'solid';
53
+ class?: string;
54
+ style?: StyleValue;
55
+ [key: string]: unknown;
56
+ };
57
+ /** 字符串组件标签中 @click="方法名" 等事件对应的处理函数。 */
58
+ handlers?: Record<string, (...args: any[]) => void>;
42
59
  /** 是否启用仅在悬停关闭区域时出现的关闭按钮,默认 `true`。 */
43
60
  showClose?: boolean;
44
61
  /**
@@ -59,7 +76,7 @@ interface ClearStorageExcludeOptions {
59
76
  type ClearStorageInput = string | string[] | ClearStorageExcludeOptions;
60
77
  interface ValidateFormOptions {
61
78
  /**
62
- * 校验失败时的提示文案。
79
+ * 校验失败时的自定义提示文案;不传时根据字段错误自动选择。
63
80
  */
64
81
  message?: string;
65
82
  /**
package/dist/base.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as vue from 'vue';
2
- import { VNode, AppContext, Ref } from 'vue';
2
+ import { Component, StyleValue, VNode, AppContext, Ref } from 'vue';
3
3
  import { SybzComponentTheme } from './theme.mjs';
4
4
  import { ConfirmVariant, ConfirmTarget } from './confirmSemantic.mjs';
5
5
  import { MessageOptions, ElMessageBoxOptions, ElMessageBox } from 'element-plus';
@@ -38,7 +38,24 @@ interface SybzUtilsConfig {
38
38
  /** HTTP 客户端的全局配置,应用入口配置一次即可。 */
39
39
  http?: CreateHttpOptions;
40
40
  }
41
- interface ToastOptions extends Partial<MessageOptions> {
41
+ interface ToastOptions extends Omit<Partial<MessageOptions>, 'icon'> {
42
+ /** 是否解析 HTML 字符串,并将已全局注册的组件标签渲染为 Vue 组件;默认 false。仅传可信内容。 */
43
+ dangerouslyUseHTMLString?: boolean;
44
+ /** 图标组件,或由全局 SIcon 自动解析的图标名称。 */
45
+ icon?: string | Component;
46
+ /** 传给 s-icon 或自定义图标组件的属性。 */
47
+ iconAttrs?: {
48
+ size?: string | number;
49
+ color?: string;
50
+ source?: 'auto' | 'element-plus' | 'iconify' | 'css' | 'svg' | 'url';
51
+ type?: 'default' | 'primary' | 'success' | 'warning' | 'danger' | 'info';
52
+ variant?: 'plain' | 'light' | 'solid';
53
+ class?: string;
54
+ style?: StyleValue;
55
+ [key: string]: unknown;
56
+ };
57
+ /** 字符串组件标签中 @click="方法名" 等事件对应的处理函数。 */
58
+ handlers?: Record<string, (...args: any[]) => void>;
42
59
  /** 是否启用仅在悬停关闭区域时出现的关闭按钮,默认 `true`。 */
43
60
  showClose?: boolean;
44
61
  /**
@@ -59,7 +76,7 @@ interface ClearStorageExcludeOptions {
59
76
  type ClearStorageInput = string | string[] | ClearStorageExcludeOptions;
60
77
  interface ValidateFormOptions {
61
78
  /**
62
- * 校验失败时的提示文案。
79
+ * 校验失败时的自定义提示文案;不传时根据字段错误自动选择。
63
80
  */
64
81
  message?: string;
65
82
  /**
package/dist/base.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as vue from 'vue';
2
- import { VNode, AppContext, Ref } from 'vue';
2
+ import { Component, StyleValue, VNode, AppContext, Ref } from 'vue';
3
3
  import { SybzComponentTheme } from './theme.js';
4
4
  import { ConfirmVariant, ConfirmTarget } from './confirmSemantic.js';
5
5
  import { MessageOptions, ElMessageBoxOptions, ElMessageBox } from 'element-plus';
@@ -38,7 +38,24 @@ interface SybzUtilsConfig {
38
38
  /** HTTP 客户端的全局配置,应用入口配置一次即可。 */
39
39
  http?: CreateHttpOptions;
40
40
  }
41
- interface ToastOptions extends Partial<MessageOptions> {
41
+ interface ToastOptions extends Omit<Partial<MessageOptions>, 'icon'> {
42
+ /** 是否解析 HTML 字符串,并将已全局注册的组件标签渲染为 Vue 组件;默认 false。仅传可信内容。 */
43
+ dangerouslyUseHTMLString?: boolean;
44
+ /** 图标组件,或由全局 SIcon 自动解析的图标名称。 */
45
+ icon?: string | Component;
46
+ /** 传给 s-icon 或自定义图标组件的属性。 */
47
+ iconAttrs?: {
48
+ size?: string | number;
49
+ color?: string;
50
+ source?: 'auto' | 'element-plus' | 'iconify' | 'css' | 'svg' | 'url';
51
+ type?: 'default' | 'primary' | 'success' | 'warning' | 'danger' | 'info';
52
+ variant?: 'plain' | 'light' | 'solid';
53
+ class?: string;
54
+ style?: StyleValue;
55
+ [key: string]: unknown;
56
+ };
57
+ /** 字符串组件标签中 @click="方法名" 等事件对应的处理函数。 */
58
+ handlers?: Record<string, (...args: any[]) => void>;
42
59
  /** 是否启用仅在悬停关闭区域时出现的关闭按钮,默认 `true`。 */
43
60
  showClose?: boolean;
44
61
  /**
@@ -59,7 +76,7 @@ interface ClearStorageExcludeOptions {
59
76
  type ClearStorageInput = string | string[] | ClearStorageExcludeOptions;
60
77
  interface ValidateFormOptions {
61
78
  /**
62
- * 校验失败时的提示文案。
79
+ * 校验失败时的自定义提示文案;不传时根据字段错误自动选择。
63
80
  */
64
81
  message?: string;
65
82
  /**
package/dist/base.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import 'vue';
2
2
  import 'consola';
3
3
  import 'es-toolkit';
4
- export { $ as $toast, c as clearStorage, a as clone, b as configureUtils, d as confirm, e as copy, f as debounce, g as delay, h as getStorage, i as getType, j as getUtilsBuildTime, k as getVariable, l as isEmpty, m as log, n as merge, o as mockValue, p as processWidth, r as random, s as setStorage, t as test, q as throttle, u as toLine, v as tryCatch, w as validate, x as validateForm, y as validateOnSubmit } from './shared/utils.E1TDYt7o.mjs';
4
+ export { $ as $toast, c as clearStorage, a as clone, b as configureUtils, d as confirm, e as copy, f as debounce, g as delay, h as getStorage, i as getType, j as getUtilsBuildTime, k as getVariable, l as isEmpty, m as log, n as merge, o as mockValue, p as processWidth, r as random, s as setStorage, t as test, q as throttle, u as toLine, v as tryCatch, w as validate, x as validateForm, y as validateOnSubmit } from './shared/utils.C6JV38T7.mjs';
5
5
  import './confirmSemantic.mjs';
6
6
  import 'element-plus';
7
7
  import 'axios';
package/dist/format.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const format = require('./shared/utils.CC08jxyG.cjs');
3
+ const format = require('./shared/utils.s3A3s_9I.cjs');
4
4
  require('./is.cjs');
5
5
  require('consola');
6
6
  require('vue');
package/dist/format.mjs CHANGED
@@ -1,4 +1,4 @@
1
- export { z as formatBytes, A as formatBytesConvert, B as formatDurationTime, C as formatTextToHtml, D as formatThousands, E as formatTime, F as formatToFixed } from './shared/utils.E1TDYt7o.mjs';
1
+ export { z as formatBytes, A as formatBytesConvert, B as formatDurationTime, C as formatTextToHtml, D as formatThousands, E as formatTime, F as formatToFixed } from './shared/utils.C6JV38T7.mjs';
2
2
  import './is.mjs';
3
3
  import 'consola';
4
4
  import 'vue';
package/dist/http.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  require('axios');
4
- const format = require('./shared/utils.CC08jxyG.cjs');
4
+ const format = require('./shared/utils.s3A3s_9I.cjs');
5
5
  require('vue');
6
6
  require('consola');
7
7
  require('es-toolkit');
package/dist/http.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import 'axios';
2
- export { H as HttpError, G as configureHttp, I as createHttp, J as http } from './shared/utils.E1TDYt7o.mjs';
2
+ export { H as HttpError, G as configureHttp, I as createHttp, J as http } from './shared/utils.C6JV38T7.mjs';
3
3
  import 'vue';
4
4
  import 'consola';
5
5
  import 'es-toolkit';
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const format = require('./shared/utils.CC08jxyG.cjs');
3
+ const format = require('./shared/utils.s3A3s_9I.cjs');
4
4
  const confirmSemantic = require('./confirmSemantic.cjs');
5
5
  const is = require('./is.cjs');
6
6
  const theme = require('./theme.cjs');
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- export { $ as $toast, H as HttpError, c as clearStorage, a as clone, G as configureHttp, b as configureUtils, d as confirm, e as copy, I as createHttp, f as debounce, g as delay, z as formatBytes, A as formatBytesConvert, B as formatDurationTime, C as formatTextToHtml, D as formatThousands, E as formatTime, F as formatToFixed, h as getStorage, i as getType, j as getUtilsBuildTime, k as getVariable, J as http, l as isEmpty, m as log, n as merge, o as mockValue, p as processWidth, r as random, s as setStorage, t as test, q as throttle, u as toLine, v as tryCatch, w as validate, x as validateForm, y as validateOnSubmit } from './shared/utils.E1TDYt7o.mjs';
1
+ export { $ as $toast, H as HttpError, c as clearStorage, a as clone, G as configureHttp, b as configureUtils, d as confirm, e as copy, I as createHttp, f as debounce, g as delay, z as formatBytes, A as formatBytesConvert, B as formatDurationTime, C as formatTextToHtml, D as formatThousands, E as formatTime, F as formatToFixed, h as getStorage, i as getType, j as getUtilsBuildTime, k as getVariable, J as http, l as isEmpty, m as log, n as merge, o as mockValue, p as processWidth, r as random, s as setStorage, t as test, q as throttle, u as toLine, v as tryCatch, w as validate, x as validateForm, y as validateOnSubmit } from './shared/utils.C6JV38T7.mjs';
2
2
  export { resolveConfirmSemantic } from './confirmSemantic.mjs';
3
3
  export { isArray, isBoolean, isComponent, isDate, isEmptyObject, isFunction, isIOS, isMap, isNumber, isObject, isPlainObject, isPromise, isRegExp, isSVGElement, isSet, isString, isStringNumber, isSymbol, isUrl, objectToString, toRawType, toTypeString } from './is.mjs';
4
4
  export { SYBZ_THEME_PREFIX, isSybzTheme, resolveSybzComponentTheme } from './theme.mjs';
@@ -1,4 +1,4 @@
1
- import { isRef, unref, isVNode, toRaw } from 'vue';
1
+ import { isVNode, h, Fragment, isRef, unref, toRaw } from 'vue';
2
2
  import { consola } from 'consola';
3
3
  import { cloneDeep } from 'es-toolkit';
4
4
  import { resolveConfirmSemantic } from '../confirmSemantic.mjs';
@@ -372,6 +372,37 @@ function _parseStorageValue(value) {
372
372
  }
373
373
  return value;
374
374
  }
375
+ function renderToastComponents(message, components, handlers) {
376
+ const template = document.createElement("template");
377
+ template.innerHTML = message;
378
+ const renderNode = (node) => {
379
+ if (node.nodeType === Node.TEXT_NODE) return node.textContent ?? "";
380
+ if (node.nodeType !== Node.ELEMENT_NODE) return null;
381
+ const element = node;
382
+ const tag = element.tagName.toLowerCase();
383
+ const pascalTag = tag.replace(/(^|-)([a-z])/g, (_, _separator, letter) => letter.toUpperCase());
384
+ const component = components[tag] ?? components[pascalTag];
385
+ const attrs = {};
386
+ for (const { name, value } of Array.from(element.attributes)) {
387
+ if (name.startsWith("@")) {
388
+ const handler = handlers?.[value];
389
+ if (handler) {
390
+ const eventName = name.slice(1).replace(/(^|-)([a-z])/g, (_, _separator, letter) => letter.toUpperCase());
391
+ attrs[`on${eventName}`] = handler;
392
+ }
393
+ } else {
394
+ attrs[name] = value === "" ? true : value;
395
+ }
396
+ }
397
+ const children = Array.from(element.childNodes, renderNode).filter((child) => child !== null);
398
+ return component ? h(component, attrs, { default: () => children }) : h(tag, attrs, children);
399
+ };
400
+ return h(
401
+ Fragment,
402
+ null,
403
+ Array.from(template.content.childNodes, renderNode).filter((child) => child !== null)
404
+ );
405
+ }
375
406
  function $toast(message, type = "success", otherParams = {}) {
376
407
  const typeMap = {
377
408
  s: "success",
@@ -383,10 +414,28 @@ function $toast(message, type = "success", otherParams = {}) {
383
414
  return ["s", "i", "e", "w"].includes(t);
384
415
  }
385
416
  function isToastOptions(obj) {
386
- return typeof obj === "object" && obj !== null;
417
+ return typeof obj === "object" && obj !== null && !isVNode(obj);
387
418
  }
388
419
  function showToast(options) {
389
- const { theme = utilsConfig.theme, customClass, ...messageOptions } = options;
420
+ const { theme = utilsConfig.theme, customClass, iconAttrs, handlers, ...messageOptions } = options;
421
+ const appComponents = _resolveAppContext(null)?.components;
422
+ if (typeof messageOptions.icon === "string") {
423
+ const icon = appComponents?.SIcon ?? appComponents?.["s-icon"];
424
+ if (icon) {
425
+ const iconName = messageOptions.icon;
426
+ messageOptions.icon = () => h(icon, { cursor: "default", ...iconAttrs, icon: iconName });
427
+ }
428
+ } else if (messageOptions.icon && iconAttrs) {
429
+ const icon = messageOptions.icon;
430
+ messageOptions.icon = () => h(icon, iconAttrs);
431
+ }
432
+ if (typeof messageOptions.message === "string" && messageOptions.dangerouslyUseHTMLString) {
433
+ const registeredComponents = appComponents ?? {};
434
+ if (Object.keys(registeredComponents).length > 0) {
435
+ messageOptions.message = renderToastComponents(messageOptions.message, registeredComponents, handlers);
436
+ messageOptions.dangerouslyUseHTMLString = false;
437
+ }
438
+ }
390
439
  if (options.closeAll) {
391
440
  ElMessage.closeAll();
392
441
  }
@@ -493,19 +542,28 @@ function clearStorage(str = "") {
493
542
  function _isObjectWithExclude(obj) {
494
543
  return typeof obj === "object" && obj !== null && "exclude" in obj && Array.isArray(obj.exclude);
495
544
  }
496
- function validateForm(ref, { message = "\u5B58\u5728\u5FC5\u586B\u9879\u672A\u586B\u5199\uFF0C\u8BF7\u8865\u5145\u5B8C\u6574", detail = false, showMessage = true } = {}) {
545
+ function validateForm(ref, { message, detail = false, showMessage = true } = {}) {
497
546
  return new Promise((resolve, reject) => {
498
547
  unref(ref).validate((valid, status) => {
499
548
  if (valid) {
500
549
  resolve(status);
501
550
  } else {
502
- if (message && showMessage) {
503
- let errorText = Object.keys(status);
504
- let toastMessage = message;
505
- if (detail) {
506
- toastMessage = message + errorText.join(",");
507
- }
508
- $toast(toastMessage, "e");
551
+ if (showMessage) {
552
+ const fieldNames = Object.keys(status ?? {});
553
+ const errors = fieldNames.flatMap((field) => {
554
+ const fieldErrors = status[field];
555
+ return Array.isArray(fieldErrors) ? fieldErrors : [fieldErrors];
556
+ });
557
+ const errorMessages = errors.map((error) => error?.message).filter((errorMessage) => typeof errorMessage === "string" && !!errorMessage.trim());
558
+ const nonRequiredMessage = errors.find((error) => {
559
+ const errorMessage = error?.message;
560
+ if (typeof errorMessage !== "string" || !errorMessage.trim()) return false;
561
+ if ("fieldValue" in Object(error) && !isEmpty(error.fieldValue)) return true;
562
+ return !/^(请输入|请选择|请填写|请上传|请勾选|不能为空)/.test(errorMessage) || /^请输入(?:正确|非负|正|整数|数字|\d|至少|最多|不超过)/.test(errorMessage);
563
+ })?.message;
564
+ const defaultMessage = nonRequiredMessage ?? (errorMessages.length ? "\u5B58\u5728\u5FC5\u586B\u9879\u672A\u586B\u5199\uFF0C\u8BF7\u8865\u5145\u5B8C\u6574" : "\u8868\u5355\u6821\u9A8C\u672A\u901A\u8FC7\uFF0C\u8BF7\u68C0\u67E5\u8F93\u5165");
565
+ const toastMessage = message === void 0 ? defaultMessage : message;
566
+ if (toastMessage) $toast(detail ? toastMessage + fieldNames.join(",") : toastMessage, "e");
509
567
  }
510
568
  reject(status);
511
569
  }
@@ -1195,7 +1253,7 @@ function getVariable(propertyName, fallback = "") {
1195
1253
  const DEFAULT_BUILD_TIME_FALLBACK = "\u672A\u6CE8\u5165";
1196
1254
  function getUtilsBuildTime(fallback = DEFAULT_BUILD_TIME_FALLBACK) {
1197
1255
  {
1198
- return "2026-11-10 13:51:09";
1256
+ return "2026-11-16 18:13:32";
1199
1257
  }
1200
1258
  }
1201
1259
  function test() {
@@ -378,6 +378,37 @@ function _parseStorageValue(value) {
378
378
  }
379
379
  return value;
380
380
  }
381
+ function renderToastComponents(message, components, handlers) {
382
+ const template = document.createElement("template");
383
+ template.innerHTML = message;
384
+ const renderNode = (node) => {
385
+ if (node.nodeType === Node.TEXT_NODE) return node.textContent ?? "";
386
+ if (node.nodeType !== Node.ELEMENT_NODE) return null;
387
+ const element = node;
388
+ const tag = element.tagName.toLowerCase();
389
+ const pascalTag = tag.replace(/(^|-)([a-z])/g, (_, _separator, letter) => letter.toUpperCase());
390
+ const component = components[tag] ?? components[pascalTag];
391
+ const attrs = {};
392
+ for (const { name, value } of Array.from(element.attributes)) {
393
+ if (name.startsWith("@")) {
394
+ const handler = handlers?.[value];
395
+ if (handler) {
396
+ const eventName = name.slice(1).replace(/(^|-)([a-z])/g, (_, _separator, letter) => letter.toUpperCase());
397
+ attrs[`on${eventName}`] = handler;
398
+ }
399
+ } else {
400
+ attrs[name] = value === "" ? true : value;
401
+ }
402
+ }
403
+ const children = Array.from(element.childNodes, renderNode).filter((child) => child !== null);
404
+ return component ? vue.h(component, attrs, { default: () => children }) : vue.h(tag, attrs, children);
405
+ };
406
+ return vue.h(
407
+ vue.Fragment,
408
+ null,
409
+ Array.from(template.content.childNodes, renderNode).filter((child) => child !== null)
410
+ );
411
+ }
381
412
  function $toast(message, type = "success", otherParams = {}) {
382
413
  const typeMap = {
383
414
  s: "success",
@@ -389,10 +420,28 @@ function $toast(message, type = "success", otherParams = {}) {
389
420
  return ["s", "i", "e", "w"].includes(t);
390
421
  }
391
422
  function isToastOptions(obj) {
392
- return typeof obj === "object" && obj !== null;
423
+ return typeof obj === "object" && obj !== null && !vue.isVNode(obj);
393
424
  }
394
425
  function showToast(options) {
395
- const { theme = utilsConfig.theme, customClass, ...messageOptions } = options;
426
+ const { theme = utilsConfig.theme, customClass, iconAttrs, handlers, ...messageOptions } = options;
427
+ const appComponents = _resolveAppContext(null)?.components;
428
+ if (typeof messageOptions.icon === "string") {
429
+ const icon = appComponents?.SIcon ?? appComponents?.["s-icon"];
430
+ if (icon) {
431
+ const iconName = messageOptions.icon;
432
+ messageOptions.icon = () => vue.h(icon, { cursor: "default", ...iconAttrs, icon: iconName });
433
+ }
434
+ } else if (messageOptions.icon && iconAttrs) {
435
+ const icon = messageOptions.icon;
436
+ messageOptions.icon = () => vue.h(icon, iconAttrs);
437
+ }
438
+ if (typeof messageOptions.message === "string" && messageOptions.dangerouslyUseHTMLString) {
439
+ const registeredComponents = appComponents ?? {};
440
+ if (Object.keys(registeredComponents).length > 0) {
441
+ messageOptions.message = renderToastComponents(messageOptions.message, registeredComponents, handlers);
442
+ messageOptions.dangerouslyUseHTMLString = false;
443
+ }
444
+ }
396
445
  if (options.closeAll) {
397
446
  elementPlus.ElMessage.closeAll();
398
447
  }
@@ -499,19 +548,28 @@ function clearStorage(str = "") {
499
548
  function _isObjectWithExclude(obj) {
500
549
  return typeof obj === "object" && obj !== null && "exclude" in obj && Array.isArray(obj.exclude);
501
550
  }
502
- function validateForm(ref, { message = "\u5B58\u5728\u5FC5\u586B\u9879\u672A\u586B\u5199\uFF0C\u8BF7\u8865\u5145\u5B8C\u6574", detail = false, showMessage = true } = {}) {
551
+ function validateForm(ref, { message, detail = false, showMessage = true } = {}) {
503
552
  return new Promise((resolve, reject) => {
504
553
  vue.unref(ref).validate((valid, status) => {
505
554
  if (valid) {
506
555
  resolve(status);
507
556
  } else {
508
- if (message && showMessage) {
509
- let errorText = Object.keys(status);
510
- let toastMessage = message;
511
- if (detail) {
512
- toastMessage = message + errorText.join(",");
513
- }
514
- $toast(toastMessage, "e");
557
+ if (showMessage) {
558
+ const fieldNames = Object.keys(status ?? {});
559
+ const errors = fieldNames.flatMap((field) => {
560
+ const fieldErrors = status[field];
561
+ return Array.isArray(fieldErrors) ? fieldErrors : [fieldErrors];
562
+ });
563
+ const errorMessages = errors.map((error) => error?.message).filter((errorMessage) => typeof errorMessage === "string" && !!errorMessage.trim());
564
+ const nonRequiredMessage = errors.find((error) => {
565
+ const errorMessage = error?.message;
566
+ if (typeof errorMessage !== "string" || !errorMessage.trim()) return false;
567
+ if ("fieldValue" in Object(error) && !isEmpty(error.fieldValue)) return true;
568
+ return !/^(请输入|请选择|请填写|请上传|请勾选|不能为空)/.test(errorMessage) || /^请输入(?:正确|非负|正|整数|数字|\d|至少|最多|不超过)/.test(errorMessage);
569
+ })?.message;
570
+ const defaultMessage = nonRequiredMessage ?? (errorMessages.length ? "\u5B58\u5728\u5FC5\u586B\u9879\u672A\u586B\u5199\uFF0C\u8BF7\u8865\u5145\u5B8C\u6574" : "\u8868\u5355\u6821\u9A8C\u672A\u901A\u8FC7\uFF0C\u8BF7\u68C0\u67E5\u8F93\u5165");
571
+ const toastMessage = message === void 0 ? defaultMessage : message;
572
+ if (toastMessage) $toast(detail ? toastMessage + fieldNames.join(",") : toastMessage, "e");
515
573
  }
516
574
  reject(status);
517
575
  }
@@ -1201,7 +1259,7 @@ function getVariable(propertyName, fallback = "") {
1201
1259
  const DEFAULT_BUILD_TIME_FALLBACK = "\u672A\u6CE8\u5165";
1202
1260
  function getUtilsBuildTime(fallback = DEFAULT_BUILD_TIME_FALLBACK) {
1203
1261
  {
1204
- return "2026-11-10 13:51:09";
1262
+ return "2026-11-16 18:13:32";
1205
1263
  }
1206
1264
  }
1207
1265
  function test() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sybz-components/utils",
3
- "version": "1.0.17",
3
+ "version": "1.0.19",
4
4
  "description": "utils of sybz-components",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",