@sybz-components/utils 1.0.16 → 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.KWmfSH7h.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
@@ -39,6 +39,8 @@ interface SybzUtilsConfig {
39
39
  http?: CreateHttpOptions;
40
40
  }
41
41
  interface ToastOptions extends Partial<MessageOptions> {
42
+ /** 是否启用仅在悬停关闭区域时出现的关闭按钮,默认 `true`。 */
43
+ showClose?: boolean;
42
44
  /**
43
45
  * 调用前是否先关闭全部消息提示。
44
46
  */
@@ -57,7 +59,7 @@ interface ClearStorageExcludeOptions {
57
59
  type ClearStorageInput = string | string[] | ClearStorageExcludeOptions;
58
60
  interface ValidateFormOptions {
59
61
  /**
60
- * 校验失败时的提示文案。
62
+ * 校验失败时的自定义提示文案;不传时根据字段错误自动选择。
61
63
  */
62
64
  message?: string;
63
65
  /**
@@ -130,7 +132,7 @@ interface CopyOptions extends ToastOptions {
130
132
  */
131
133
  hideToast?: boolean;
132
134
  }
133
- type WidthInput = string | number | Ref<string | number>;
135
+ type WidthInput = string | number | boolean | Ref<string | number | boolean>;
134
136
  type ConfirmMessage = string | VNode | (() => VNode);
135
137
  type ConfirmTheme = UtilsTheme;
136
138
  interface ConfirmCustomOptions {
package/dist/base.d.mts CHANGED
@@ -39,6 +39,8 @@ interface SybzUtilsConfig {
39
39
  http?: CreateHttpOptions;
40
40
  }
41
41
  interface ToastOptions extends Partial<MessageOptions> {
42
+ /** 是否启用仅在悬停关闭区域时出现的关闭按钮,默认 `true`。 */
43
+ showClose?: boolean;
42
44
  /**
43
45
  * 调用前是否先关闭全部消息提示。
44
46
  */
@@ -57,7 +59,7 @@ interface ClearStorageExcludeOptions {
57
59
  type ClearStorageInput = string | string[] | ClearStorageExcludeOptions;
58
60
  interface ValidateFormOptions {
59
61
  /**
60
- * 校验失败时的提示文案。
62
+ * 校验失败时的自定义提示文案;不传时根据字段错误自动选择。
61
63
  */
62
64
  message?: string;
63
65
  /**
@@ -130,7 +132,7 @@ interface CopyOptions extends ToastOptions {
130
132
  */
131
133
  hideToast?: boolean;
132
134
  }
133
- type WidthInput = string | number | Ref<string | number>;
135
+ type WidthInput = string | number | boolean | Ref<string | number | boolean>;
134
136
  type ConfirmMessage = string | VNode | (() => VNode);
135
137
  type ConfirmTheme = UtilsTheme;
136
138
  interface ConfirmCustomOptions {
package/dist/base.d.ts CHANGED
@@ -39,6 +39,8 @@ interface SybzUtilsConfig {
39
39
  http?: CreateHttpOptions;
40
40
  }
41
41
  interface ToastOptions extends Partial<MessageOptions> {
42
+ /** 是否启用仅在悬停关闭区域时出现的关闭按钮,默认 `true`。 */
43
+ showClose?: boolean;
42
44
  /**
43
45
  * 调用前是否先关闭全部消息提示。
44
46
  */
@@ -57,7 +59,7 @@ interface ClearStorageExcludeOptions {
57
59
  type ClearStorageInput = string | string[] | ClearStorageExcludeOptions;
58
60
  interface ValidateFormOptions {
59
61
  /**
60
- * 校验失败时的提示文案。
62
+ * 校验失败时的自定义提示文案;不传时根据字段错误自动选择。
61
63
  */
62
64
  message?: string;
63
65
  /**
@@ -130,7 +132,7 @@ interface CopyOptions extends ToastOptions {
130
132
  */
131
133
  hideToast?: boolean;
132
134
  }
133
- type WidthInput = string | number | Ref<string | number>;
135
+ type WidthInput = string | number | boolean | Ref<string | number | boolean>;
134
136
  type ConfirmMessage = string | VNode | (() => VNode);
135
137
  type ConfirmTheme = UtilsTheme;
136
138
  interface ConfirmCustomOptions {
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.BVs9MJTE.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.KWmfSH7h.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.BVs9MJTE.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.KWmfSH7h.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.d.cts CHANGED
@@ -42,7 +42,6 @@ interface CreateHttpOptions<D = unknown> extends CreateAxiosDefaults<D> {
42
42
  }
43
43
  type HttpClient = Omit<AxiosInstance, 'get' | 'post' | 'put' | 'patch' | 'delete'> & {
44
44
  <T = unknown, D = unknown>(url: string, config?: HttpRequestConfig<D>): Promise<T>;
45
- <T = unknown, D = unknown>(url: string, params?: unknown, config?: HttpRequestConfig<D>): Promise<T>;
46
45
  send<T = unknown, D = unknown>(config: HttpRequestConfig<D> & {
47
46
  rawResponse: true;
48
47
  }): Promise<AxiosResponse<T>>;
@@ -50,12 +49,11 @@ type HttpClient = Omit<AxiosInstance, 'get' | 'post' | 'put' | 'patch' | 'delete
50
49
  rawResponse?: false;
51
50
  }): Promise<T>;
52
51
  get<T = unknown>(url: string, config?: HttpRequestConfig): Promise<T>;
53
- get<T = unknown>(url: string, params?: unknown, config?: HttpRequestConfig): Promise<T>;
54
- post<T = unknown, D = unknown>(url: string, data?: D, config?: HttpRequestConfig<D>): Promise<T>;
55
- put<T = unknown, D = unknown>(url: string, data?: D, config?: HttpRequestConfig<D>): Promise<T>;
56
- patch<T = unknown, D = unknown>(url: string, data?: D, config?: HttpRequestConfig<D>): Promise<T>;
52
+ post<T = unknown, D = unknown>(url: string, config?: HttpRequestConfig<D>): Promise<T>;
53
+ put<T = unknown, D = unknown>(url: string, config?: HttpRequestConfig<D>): Promise<T>;
54
+ patch<T = unknown, D = unknown>(url: string, config?: HttpRequestConfig<D>): Promise<T>;
57
55
  delete<T = unknown>(url: string, config?: HttpRequestConfig): Promise<T>;
58
- download(url: string, params?: unknown, config?: HttpRequestConfig): Promise<Blob>;
56
+ download(url: string, config?: HttpRequestConfig): Promise<Blob>;
59
57
  };
60
58
  declare function createHttp<D = unknown>(options?: CreateHttpOptions<D>): HttpClient;
61
59
  /** 全局 HTTP 客户端;通过 configureUtils({ http: ... }) 配置一次。 */
package/dist/http.d.mts CHANGED
@@ -42,7 +42,6 @@ interface CreateHttpOptions<D = unknown> extends CreateAxiosDefaults<D> {
42
42
  }
43
43
  type HttpClient = Omit<AxiosInstance, 'get' | 'post' | 'put' | 'patch' | 'delete'> & {
44
44
  <T = unknown, D = unknown>(url: string, config?: HttpRequestConfig<D>): Promise<T>;
45
- <T = unknown, D = unknown>(url: string, params?: unknown, config?: HttpRequestConfig<D>): Promise<T>;
46
45
  send<T = unknown, D = unknown>(config: HttpRequestConfig<D> & {
47
46
  rawResponse: true;
48
47
  }): Promise<AxiosResponse<T>>;
@@ -50,12 +49,11 @@ type HttpClient = Omit<AxiosInstance, 'get' | 'post' | 'put' | 'patch' | 'delete
50
49
  rawResponse?: false;
51
50
  }): Promise<T>;
52
51
  get<T = unknown>(url: string, config?: HttpRequestConfig): Promise<T>;
53
- get<T = unknown>(url: string, params?: unknown, config?: HttpRequestConfig): Promise<T>;
54
- post<T = unknown, D = unknown>(url: string, data?: D, config?: HttpRequestConfig<D>): Promise<T>;
55
- put<T = unknown, D = unknown>(url: string, data?: D, config?: HttpRequestConfig<D>): Promise<T>;
56
- patch<T = unknown, D = unknown>(url: string, data?: D, config?: HttpRequestConfig<D>): Promise<T>;
52
+ post<T = unknown, D = unknown>(url: string, config?: HttpRequestConfig<D>): Promise<T>;
53
+ put<T = unknown, D = unknown>(url: string, config?: HttpRequestConfig<D>): Promise<T>;
54
+ patch<T = unknown, D = unknown>(url: string, config?: HttpRequestConfig<D>): Promise<T>;
57
55
  delete<T = unknown>(url: string, config?: HttpRequestConfig): Promise<T>;
58
- download(url: string, params?: unknown, config?: HttpRequestConfig): Promise<Blob>;
56
+ download(url: string, config?: HttpRequestConfig): Promise<Blob>;
59
57
  };
60
58
  declare function createHttp<D = unknown>(options?: CreateHttpOptions<D>): HttpClient;
61
59
  /** 全局 HTTP 客户端;通过 configureUtils({ http: ... }) 配置一次。 */
package/dist/http.d.ts CHANGED
@@ -42,7 +42,6 @@ interface CreateHttpOptions<D = unknown> extends CreateAxiosDefaults<D> {
42
42
  }
43
43
  type HttpClient = Omit<AxiosInstance, 'get' | 'post' | 'put' | 'patch' | 'delete'> & {
44
44
  <T = unknown, D = unknown>(url: string, config?: HttpRequestConfig<D>): Promise<T>;
45
- <T = unknown, D = unknown>(url: string, params?: unknown, config?: HttpRequestConfig<D>): Promise<T>;
46
45
  send<T = unknown, D = unknown>(config: HttpRequestConfig<D> & {
47
46
  rawResponse: true;
48
47
  }): Promise<AxiosResponse<T>>;
@@ -50,12 +49,11 @@ type HttpClient = Omit<AxiosInstance, 'get' | 'post' | 'put' | 'patch' | 'delete
50
49
  rawResponse?: false;
51
50
  }): Promise<T>;
52
51
  get<T = unknown>(url: string, config?: HttpRequestConfig): Promise<T>;
53
- get<T = unknown>(url: string, params?: unknown, config?: HttpRequestConfig): Promise<T>;
54
- post<T = unknown, D = unknown>(url: string, data?: D, config?: HttpRequestConfig<D>): Promise<T>;
55
- put<T = unknown, D = unknown>(url: string, data?: D, config?: HttpRequestConfig<D>): Promise<T>;
56
- patch<T = unknown, D = unknown>(url: string, data?: D, config?: HttpRequestConfig<D>): Promise<T>;
52
+ post<T = unknown, D = unknown>(url: string, config?: HttpRequestConfig<D>): Promise<T>;
53
+ put<T = unknown, D = unknown>(url: string, config?: HttpRequestConfig<D>): Promise<T>;
54
+ patch<T = unknown, D = unknown>(url: string, config?: HttpRequestConfig<D>): Promise<T>;
57
55
  delete<T = unknown>(url: string, config?: HttpRequestConfig): Promise<T>;
58
- download(url: string, params?: unknown, config?: HttpRequestConfig): Promise<Blob>;
56
+ download(url: string, config?: HttpRequestConfig): Promise<Blob>;
59
57
  };
60
58
  declare function createHttp<D = unknown>(options?: CreateHttpOptions<D>): HttpClient;
61
59
  /** 全局 HTTP 客户端;通过 configureUtils({ http: ... }) 配置一次。 */
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.BVs9MJTE.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.KWmfSH7h.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.BVs9MJTE.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';
@@ -306,22 +306,15 @@ function createHttp(options = {}) {
306
306
  const response = await instance.request(config);
307
307
  return config.rawResponse ? response : response.data;
308
308
  };
309
- const isRequestConfig = (value) => record(value) && ["url", "method", "headers", "timeout", "rawResponse", "skipAuth", "showErrorToast", "message"].some(
310
- (key) => key in value
311
- );
312
- const request = (url, paramsOrConfig, config = {}) => {
313
- const params = isRequestConfig(paramsOrConfig) ? void 0 : paramsOrConfig;
314
- const requestConfig = isRequestConfig(paramsOrConfig) ? paramsOrConfig : config;
315
- return send({ ...requestConfig, method: "GET", url, params, rawResponse: false });
316
- };
309
+ const request = (url, config = {}) => send({ ...config, method: "GET", url, rawResponse: false });
317
310
  const client = Object.assign(request, instance, {
318
311
  send,
319
- get: (url, paramsOrConfig, config) => request(url, paramsOrConfig, config),
320
- post: (url, data, config) => send({ ...config, method: "POST", url, data, rawResponse: false }),
321
- put: (url, data, config) => send({ ...config, method: "PUT", url, data, rawResponse: false }),
322
- patch: (url, data, config) => send({ ...config, method: "PATCH", url, data, rawResponse: false }),
312
+ get: (url, config) => request(url, config),
313
+ post: (url, config) => send({ ...config, method: "POST", url, rawResponse: false }),
314
+ put: (url, config) => send({ ...config, method: "PUT", url, rawResponse: false }),
315
+ patch: (url, config) => send({ ...config, method: "PATCH", url, rawResponse: false }),
323
316
  delete: (url, config) => send({ ...config, method: "DELETE", url, rawResponse: false }),
324
- download: (url, params, config) => send({ ...config, method: "GET", url, params, responseType: "blob", rawResponse: false })
317
+ download: (url, config) => send({ ...config, method: "GET", url, responseType: "blob", rawResponse: false })
325
318
  });
326
319
  return client;
327
320
  }
@@ -397,9 +390,15 @@ function $toast(message, type = "success", otherParams = {}) {
397
390
  if (options.closeAll) {
398
391
  ElMessage.closeAll();
399
392
  }
400
- const resolvedCustomClass = customClass === "el" ? "" : _mergeClassNames("s-antd-message", theme !== "default" && `s-antd-message--${theme}`, customClass);
393
+ const resolvedCustomClass = _mergeClassNames(
394
+ "s-toast",
395
+ customClass !== "el" && "s-antd-message",
396
+ customClass !== "el" && theme !== "default" && `s-antd-message--${theme}`,
397
+ customClass !== "el" && customClass
398
+ );
401
399
  ElMessage({
402
400
  ...messageOptions,
401
+ showClose: options.showClose ?? true,
403
402
  customClass: resolvedCustomClass
404
403
  });
405
404
  }
@@ -494,19 +493,28 @@ function clearStorage(str = "") {
494
493
  function _isObjectWithExclude(obj) {
495
494
  return typeof obj === "object" && obj !== null && "exclude" in obj && Array.isArray(obj.exclude);
496
495
  }
497
- 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 } = {}) {
498
497
  return new Promise((resolve, reject) => {
499
498
  unref(ref).validate((valid, status) => {
500
499
  if (valid) {
501
500
  resolve(status);
502
501
  } else {
503
- if (message && showMessage) {
504
- let errorText = Object.keys(status);
505
- let toastMessage = message;
506
- if (detail) {
507
- toastMessage = message + errorText.join(",");
508
- }
509
- $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");
510
518
  }
511
519
  reject(status);
512
520
  }
@@ -922,10 +930,10 @@ const _CSS_UNIT_RE = /^[0-9]+(\.[0-9]+)?(px|%|em|rem|vw|vh|ch)$/;
922
930
  const _CSS_LENGTH_FUNCTION_RE = /^(?:calc|min|max|clamp|var)\(.+\)$/;
923
931
  function processWidth(initValue, isBase = false) {
924
932
  const raw = unref(initValue);
925
- if (raw === void 0 || raw === null || raw === "") {
933
+ if (raw === void 0 || raw === null || raw === "" || raw === false) {
926
934
  return isBase ? "" : {};
927
935
  }
928
- const str = typeof raw === "number" ? `${raw}` : raw;
936
+ const str = raw === true ? "100%" : typeof raw === "number" ? `${raw}` : raw;
929
937
  let res;
930
938
  if (!isNaN(Number(str))) {
931
939
  res = str + "px";
@@ -1196,7 +1204,7 @@ function getVariable(propertyName, fallback = "") {
1196
1204
  const DEFAULT_BUILD_TIME_FALLBACK = "\u672A\u6CE8\u5165";
1197
1205
  function getUtilsBuildTime(fallback = DEFAULT_BUILD_TIME_FALLBACK) {
1198
1206
  {
1199
- return "2026-10-22 09:49:58";
1207
+ return "2026-11-12 14:28:53";
1200
1208
  }
1201
1209
  }
1202
1210
  function test() {
@@ -312,22 +312,15 @@ function createHttp(options = {}) {
312
312
  const response = await instance.request(config);
313
313
  return config.rawResponse ? response : response.data;
314
314
  };
315
- const isRequestConfig = (value) => record(value) && ["url", "method", "headers", "timeout", "rawResponse", "skipAuth", "showErrorToast", "message"].some(
316
- (key) => key in value
317
- );
318
- const request = (url, paramsOrConfig, config = {}) => {
319
- const params = isRequestConfig(paramsOrConfig) ? void 0 : paramsOrConfig;
320
- const requestConfig = isRequestConfig(paramsOrConfig) ? paramsOrConfig : config;
321
- return send({ ...requestConfig, method: "GET", url, params, rawResponse: false });
322
- };
315
+ const request = (url, config = {}) => send({ ...config, method: "GET", url, rawResponse: false });
323
316
  const client = Object.assign(request, instance, {
324
317
  send,
325
- get: (url, paramsOrConfig, config) => request(url, paramsOrConfig, config),
326
- post: (url, data, config) => send({ ...config, method: "POST", url, data, rawResponse: false }),
327
- put: (url, data, config) => send({ ...config, method: "PUT", url, data, rawResponse: false }),
328
- patch: (url, data, config) => send({ ...config, method: "PATCH", url, data, rawResponse: false }),
318
+ get: (url, config) => request(url, config),
319
+ post: (url, config) => send({ ...config, method: "POST", url, rawResponse: false }),
320
+ put: (url, config) => send({ ...config, method: "PUT", url, rawResponse: false }),
321
+ patch: (url, config) => send({ ...config, method: "PATCH", url, rawResponse: false }),
329
322
  delete: (url, config) => send({ ...config, method: "DELETE", url, rawResponse: false }),
330
- download: (url, params, config) => send({ ...config, method: "GET", url, params, responseType: "blob", rawResponse: false })
323
+ download: (url, config) => send({ ...config, method: "GET", url, responseType: "blob", rawResponse: false })
331
324
  });
332
325
  return client;
333
326
  }
@@ -403,9 +396,15 @@ function $toast(message, type = "success", otherParams = {}) {
403
396
  if (options.closeAll) {
404
397
  elementPlus.ElMessage.closeAll();
405
398
  }
406
- const resolvedCustomClass = customClass === "el" ? "" : _mergeClassNames("s-antd-message", theme !== "default" && `s-antd-message--${theme}`, customClass);
399
+ const resolvedCustomClass = _mergeClassNames(
400
+ "s-toast",
401
+ customClass !== "el" && "s-antd-message",
402
+ customClass !== "el" && theme !== "default" && `s-antd-message--${theme}`,
403
+ customClass !== "el" && customClass
404
+ );
407
405
  elementPlus.ElMessage({
408
406
  ...messageOptions,
407
+ showClose: options.showClose ?? true,
409
408
  customClass: resolvedCustomClass
410
409
  });
411
410
  }
@@ -500,19 +499,28 @@ function clearStorage(str = "") {
500
499
  function _isObjectWithExclude(obj) {
501
500
  return typeof obj === "object" && obj !== null && "exclude" in obj && Array.isArray(obj.exclude);
502
501
  }
503
- 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 } = {}) {
504
503
  return new Promise((resolve, reject) => {
505
504
  vue.unref(ref).validate((valid, status) => {
506
505
  if (valid) {
507
506
  resolve(status);
508
507
  } else {
509
- if (message && showMessage) {
510
- let errorText = Object.keys(status);
511
- let toastMessage = message;
512
- if (detail) {
513
- toastMessage = message + errorText.join(",");
514
- }
515
- $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");
516
524
  }
517
525
  reject(status);
518
526
  }
@@ -928,10 +936,10 @@ const _CSS_UNIT_RE = /^[0-9]+(\.[0-9]+)?(px|%|em|rem|vw|vh|ch)$/;
928
936
  const _CSS_LENGTH_FUNCTION_RE = /^(?:calc|min|max|clamp|var)\(.+\)$/;
929
937
  function processWidth(initValue, isBase = false) {
930
938
  const raw = vue.unref(initValue);
931
- if (raw === void 0 || raw === null || raw === "") {
939
+ if (raw === void 0 || raw === null || raw === "" || raw === false) {
932
940
  return isBase ? "" : {};
933
941
  }
934
- const str = typeof raw === "number" ? `${raw}` : raw;
942
+ const str = raw === true ? "100%" : typeof raw === "number" ? `${raw}` : raw;
935
943
  let res;
936
944
  if (!isNaN(Number(str))) {
937
945
  res = str + "px";
@@ -1202,7 +1210,7 @@ function getVariable(propertyName, fallback = "") {
1202
1210
  const DEFAULT_BUILD_TIME_FALLBACK = "\u672A\u6CE8\u5165";
1203
1211
  function getUtilsBuildTime(fallback = DEFAULT_BUILD_TIME_FALLBACK) {
1204
1212
  {
1205
- return "2026-10-22 09:49:58";
1213
+ return "2026-11-12 14:28:53";
1206
1214
  }
1207
1215
  }
1208
1216
  function test() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sybz-components/utils",
3
- "version": "1.0.16",
3
+ "version": "1.0.18",
4
4
  "description": "utils of sybz-components",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",