@sybz-components/utils 1.0.17 → 1.0.18

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.DqukLavi.cjs');
7
7
  require('./confirmSemantic.cjs');
8
8
  require('element-plus');
9
9
  require('axios');
package/dist/base.d.cts CHANGED
@@ -59,7 +59,7 @@ interface ClearStorageExcludeOptions {
59
59
  type ClearStorageInput = string | string[] | ClearStorageExcludeOptions;
60
60
  interface ValidateFormOptions {
61
61
  /**
62
- * 校验失败时的提示文案。
62
+ * 校验失败时的自定义提示文案;不传时根据字段错误自动选择。
63
63
  */
64
64
  message?: string;
65
65
  /**
package/dist/base.d.mts CHANGED
@@ -59,7 +59,7 @@ interface ClearStorageExcludeOptions {
59
59
  type ClearStorageInput = string | string[] | ClearStorageExcludeOptions;
60
60
  interface ValidateFormOptions {
61
61
  /**
62
- * 校验失败时的提示文案。
62
+ * 校验失败时的自定义提示文案;不传时根据字段错误自动选择。
63
63
  */
64
64
  message?: string;
65
65
  /**
package/dist/base.d.ts CHANGED
@@ -59,7 +59,7 @@ interface ClearStorageExcludeOptions {
59
59
  type ClearStorageInput = string | string[] | ClearStorageExcludeOptions;
60
60
  interface ValidateFormOptions {
61
61
  /**
62
- * 校验失败时的提示文案。
62
+ * 校验失败时的自定义提示文案;不传时根据字段错误自动选择。
63
63
  */
64
64
  message?: string;
65
65
  /**
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.D3fsXXCj.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.DqukLavi.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.D3fsXXCj.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.DqukLavi.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.D3fsXXCj.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.DqukLavi.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.D3fsXXCj.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';
@@ -493,19 +493,28 @@ function clearStorage(str = "") {
493
493
  function _isObjectWithExclude(obj) {
494
494
  return typeof obj === "object" && obj !== null && "exclude" in obj && Array.isArray(obj.exclude);
495
495
  }
496
- function validateForm(ref, { message = "\u5B58\u5728\u5FC5\u586B\u9879\u672A\u586B\u5199\uFF0C\u8BF7\u8865\u5145\u5B8C\u6574", detail = false, showMessage = true } = {}) {
496
+ function validateForm(ref, { message, detail = false, showMessage = true } = {}) {
497
497
  return new Promise((resolve, reject) => {
498
498
  unref(ref).validate((valid, status) => {
499
499
  if (valid) {
500
500
  resolve(status);
501
501
  } 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");
502
+ if (showMessage) {
503
+ const fieldNames = Object.keys(status ?? {});
504
+ const errors = fieldNames.flatMap((field) => {
505
+ const fieldErrors = status[field];
506
+ return Array.isArray(fieldErrors) ? fieldErrors : [fieldErrors];
507
+ });
508
+ const errorMessages = errors.map((error) => error?.message).filter((errorMessage) => typeof errorMessage === "string" && !!errorMessage.trim());
509
+ const nonRequiredMessage = errors.find((error) => {
510
+ const errorMessage = error?.message;
511
+ if (typeof errorMessage !== "string" || !errorMessage.trim()) return false;
512
+ if ("fieldValue" in Object(error) && !isEmpty(error.fieldValue)) return true;
513
+ return !/^(请输入|请选择|请填写|请上传|请勾选|不能为空)/.test(errorMessage) || /^请输入(?:正确|非负|正|整数|数字|\d|至少|最多|不超过)/.test(errorMessage);
514
+ })?.message;
515
+ 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");
516
+ const toastMessage = message === void 0 ? defaultMessage : message;
517
+ if (toastMessage) $toast(detail ? toastMessage + fieldNames.join(",") : toastMessage, "e");
509
518
  }
510
519
  reject(status);
511
520
  }
@@ -1195,7 +1204,7 @@ function getVariable(propertyName, fallback = "") {
1195
1204
  const DEFAULT_BUILD_TIME_FALLBACK = "\u672A\u6CE8\u5165";
1196
1205
  function getUtilsBuildTime(fallback = DEFAULT_BUILD_TIME_FALLBACK) {
1197
1206
  {
1198
- return "2026-11-10 13:51:09";
1207
+ return "2026-11-12 14:28:53";
1199
1208
  }
1200
1209
  }
1201
1210
  function test() {
@@ -499,19 +499,28 @@ function clearStorage(str = "") {
499
499
  function _isObjectWithExclude(obj) {
500
500
  return typeof obj === "object" && obj !== null && "exclude" in obj && Array.isArray(obj.exclude);
501
501
  }
502
- function validateForm(ref, { message = "\u5B58\u5728\u5FC5\u586B\u9879\u672A\u586B\u5199\uFF0C\u8BF7\u8865\u5145\u5B8C\u6574", detail = false, showMessage = true } = {}) {
502
+ function validateForm(ref, { message, detail = false, showMessage = true } = {}) {
503
503
  return new Promise((resolve, reject) => {
504
504
  vue.unref(ref).validate((valid, status) => {
505
505
  if (valid) {
506
506
  resolve(status);
507
507
  } 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");
508
+ if (showMessage) {
509
+ const fieldNames = Object.keys(status ?? {});
510
+ const errors = fieldNames.flatMap((field) => {
511
+ const fieldErrors = status[field];
512
+ return Array.isArray(fieldErrors) ? fieldErrors : [fieldErrors];
513
+ });
514
+ const errorMessages = errors.map((error) => error?.message).filter((errorMessage) => typeof errorMessage === "string" && !!errorMessage.trim());
515
+ const nonRequiredMessage = errors.find((error) => {
516
+ const errorMessage = error?.message;
517
+ if (typeof errorMessage !== "string" || !errorMessage.trim()) return false;
518
+ if ("fieldValue" in Object(error) && !isEmpty(error.fieldValue)) return true;
519
+ return !/^(请输入|请选择|请填写|请上传|请勾选|不能为空)/.test(errorMessage) || /^请输入(?:正确|非负|正|整数|数字|\d|至少|最多|不超过)/.test(errorMessage);
520
+ })?.message;
521
+ 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");
522
+ const toastMessage = message === void 0 ? defaultMessage : message;
523
+ if (toastMessage) $toast(detail ? toastMessage + fieldNames.join(",") : toastMessage, "e");
515
524
  }
516
525
  reject(status);
517
526
  }
@@ -1201,7 +1210,7 @@ function getVariable(propertyName, fallback = "") {
1201
1210
  const DEFAULT_BUILD_TIME_FALLBACK = "\u672A\u6CE8\u5165";
1202
1211
  function getUtilsBuildTime(fallback = DEFAULT_BUILD_TIME_FALLBACK) {
1203
1212
  {
1204
- return "2026-11-10 13:51:09";
1213
+ return "2026-11-12 14:28:53";
1205
1214
  }
1206
1215
  }
1207
1216
  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.18",
4
4
  "description": "utils of sybz-components",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",