@sybz-components/utils 1.0.11 → 1.0.13
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 +2 -1
- package/dist/base.d.cts +11 -2
- package/dist/base.d.mts +11 -2
- package/dist/base.d.ts +11 -2
- package/dist/base.mjs +2 -1
- package/dist/confirmSemantic.d.cts +3 -1
- package/dist/confirmSemantic.d.mts +3 -1
- package/dist/confirmSemantic.d.ts +3 -1
- package/dist/format.cjs +2 -1
- package/dist/format.mjs +2 -1
- package/dist/http.cjs +20 -0
- package/dist/http.d.cts +66 -0
- package/dist/http.d.mts +66 -0
- package/dist/http.d.ts +66 -0
- package/dist/http.mjs +8 -0
- package/dist/index.cjs +13 -1
- package/dist/index.d.cts +3 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.mjs +3 -1
- package/dist/shared/{utils.DfuweQgy.cjs → utils.1vSv2Q9r.cjs} +136 -3
- package/dist/shared/{utils.CJdEsMHi.mjs → utils.B9RT8TZf.mjs} +131 -5
- package/dist/sybz-code-standard.cjs +31 -12
- package/dist/sybz-code-standard.mjs +32 -13
- package/dist/theme.cjs +17 -0
- package/dist/theme.d.cts +16 -0
- package/dist/theme.d.mts +16 -0
- package/dist/theme.d.ts +16 -0
- package/dist/theme.mjs +13 -0
- package/package.json +2 -1
package/dist/base.cjs
CHANGED
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
require('vue');
|
|
4
4
|
require('consola');
|
|
5
5
|
require('es-toolkit');
|
|
6
|
-
const format = require('./shared/utils.
|
|
6
|
+
const format = require('./shared/utils.1vSv2Q9r.cjs');
|
|
7
7
|
require('./confirmSemantic.cjs');
|
|
8
8
|
require('element-plus');
|
|
9
|
+
require('axios');
|
|
9
10
|
require('./is.cjs');
|
|
10
11
|
|
|
11
12
|
|
package/dist/base.d.cts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import * as vue from 'vue';
|
|
2
2
|
import { VNode, AppContext, Ref } from 'vue';
|
|
3
|
+
import { SybzComponentTheme } from './theme.cjs';
|
|
3
4
|
import { ConfirmVariant, ConfirmTarget } from './confirmSemantic.cjs';
|
|
4
5
|
import { MessageOptions, ElMessageBoxOptions, ElMessageBox } from 'element-plus';
|
|
6
|
+
import { CreateHttpOptions } from './http.cjs';
|
|
7
|
+
import 'axios';
|
|
5
8
|
|
|
6
9
|
type Func<Args extends any[] = any[], Return = any> = (...args: Args) => Return;
|
|
7
10
|
type StorageValue = unknown;
|
|
@@ -26,12 +29,14 @@ type MockValueOptionItem<T = any> = {
|
|
|
26
29
|
label: string;
|
|
27
30
|
value: T;
|
|
28
31
|
};
|
|
29
|
-
type UtilsTheme =
|
|
32
|
+
type UtilsTheme = SybzComponentTheme;
|
|
30
33
|
interface SybzUtilsConfig {
|
|
31
34
|
/**
|
|
32
35
|
* 工具函数的默认主题。
|
|
33
36
|
*/
|
|
34
37
|
theme?: UtilsTheme;
|
|
38
|
+
/** HTTP 客户端的全局配置,应用入口配置一次即可。 */
|
|
39
|
+
http?: CreateHttpOptions;
|
|
35
40
|
}
|
|
36
41
|
interface ToastOptions extends Partial<MessageOptions> {
|
|
37
42
|
/**
|
|
@@ -476,7 +481,7 @@ declare function toLine(text: string, connect?: string): string;
|
|
|
476
481
|
/**
|
|
477
482
|
* 将宽度值规范化为可直接用于样式的结果。
|
|
478
483
|
*
|
|
479
|
-
* @param initValue 宽度值,支持数字、数字字符串、CSS
|
|
484
|
+
* @param initValue 宽度值,支持数字、数字字符串、CSS 长度、CSS 计算函数和 `ref`。
|
|
480
485
|
* @param isBase 为 `true` 时直接返回宽度字符串;否则返回 `{ width }` 对象。
|
|
481
486
|
* @returns 宽度字符串或宽度样式对象;无效值返回空字符串或空对象。
|
|
482
487
|
*
|
|
@@ -487,6 +492,10 @@ declare function toLine(text: string, connect?: string): string;
|
|
|
487
492
|
* @example
|
|
488
493
|
* processWidth('50%', true)
|
|
489
494
|
* // => '50%'
|
|
495
|
+
*
|
|
496
|
+
* @example
|
|
497
|
+
* processWidth('calc(100% - 24px)', true)
|
|
498
|
+
* // => 'calc(100% - 24px)'
|
|
490
499
|
*/
|
|
491
500
|
declare function processWidth(initValue: WidthInput, isBase: true): string;
|
|
492
501
|
declare function processWidth(initValue: WidthInput, isBase?: false): WidthStyleResult | {};
|
package/dist/base.d.mts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import * as vue from 'vue';
|
|
2
2
|
import { VNode, AppContext, Ref } from 'vue';
|
|
3
|
+
import { SybzComponentTheme } from './theme.mjs';
|
|
3
4
|
import { ConfirmVariant, ConfirmTarget } from './confirmSemantic.mjs';
|
|
4
5
|
import { MessageOptions, ElMessageBoxOptions, ElMessageBox } from 'element-plus';
|
|
6
|
+
import { CreateHttpOptions } from './http.mjs';
|
|
7
|
+
import 'axios';
|
|
5
8
|
|
|
6
9
|
type Func<Args extends any[] = any[], Return = any> = (...args: Args) => Return;
|
|
7
10
|
type StorageValue = unknown;
|
|
@@ -26,12 +29,14 @@ type MockValueOptionItem<T = any> = {
|
|
|
26
29
|
label: string;
|
|
27
30
|
value: T;
|
|
28
31
|
};
|
|
29
|
-
type UtilsTheme =
|
|
32
|
+
type UtilsTheme = SybzComponentTheme;
|
|
30
33
|
interface SybzUtilsConfig {
|
|
31
34
|
/**
|
|
32
35
|
* 工具函数的默认主题。
|
|
33
36
|
*/
|
|
34
37
|
theme?: UtilsTheme;
|
|
38
|
+
/** HTTP 客户端的全局配置,应用入口配置一次即可。 */
|
|
39
|
+
http?: CreateHttpOptions;
|
|
35
40
|
}
|
|
36
41
|
interface ToastOptions extends Partial<MessageOptions> {
|
|
37
42
|
/**
|
|
@@ -476,7 +481,7 @@ declare function toLine(text: string, connect?: string): string;
|
|
|
476
481
|
/**
|
|
477
482
|
* 将宽度值规范化为可直接用于样式的结果。
|
|
478
483
|
*
|
|
479
|
-
* @param initValue 宽度值,支持数字、数字字符串、CSS
|
|
484
|
+
* @param initValue 宽度值,支持数字、数字字符串、CSS 长度、CSS 计算函数和 `ref`。
|
|
480
485
|
* @param isBase 为 `true` 时直接返回宽度字符串;否则返回 `{ width }` 对象。
|
|
481
486
|
* @returns 宽度字符串或宽度样式对象;无效值返回空字符串或空对象。
|
|
482
487
|
*
|
|
@@ -487,6 +492,10 @@ declare function toLine(text: string, connect?: string): string;
|
|
|
487
492
|
* @example
|
|
488
493
|
* processWidth('50%', true)
|
|
489
494
|
* // => '50%'
|
|
495
|
+
*
|
|
496
|
+
* @example
|
|
497
|
+
* processWidth('calc(100% - 24px)', true)
|
|
498
|
+
* // => 'calc(100% - 24px)'
|
|
490
499
|
*/
|
|
491
500
|
declare function processWidth(initValue: WidthInput, isBase: true): string;
|
|
492
501
|
declare function processWidth(initValue: WidthInput, isBase?: false): WidthStyleResult | {};
|
package/dist/base.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import * as vue from 'vue';
|
|
2
2
|
import { VNode, AppContext, Ref } from 'vue';
|
|
3
|
+
import { SybzComponentTheme } from './theme.js';
|
|
3
4
|
import { ConfirmVariant, ConfirmTarget } from './confirmSemantic.js';
|
|
4
5
|
import { MessageOptions, ElMessageBoxOptions, ElMessageBox } from 'element-plus';
|
|
6
|
+
import { CreateHttpOptions } from './http.js';
|
|
7
|
+
import 'axios';
|
|
5
8
|
|
|
6
9
|
type Func<Args extends any[] = any[], Return = any> = (...args: Args) => Return;
|
|
7
10
|
type StorageValue = unknown;
|
|
@@ -26,12 +29,14 @@ type MockValueOptionItem<T = any> = {
|
|
|
26
29
|
label: string;
|
|
27
30
|
value: T;
|
|
28
31
|
};
|
|
29
|
-
type UtilsTheme =
|
|
32
|
+
type UtilsTheme = SybzComponentTheme;
|
|
30
33
|
interface SybzUtilsConfig {
|
|
31
34
|
/**
|
|
32
35
|
* 工具函数的默认主题。
|
|
33
36
|
*/
|
|
34
37
|
theme?: UtilsTheme;
|
|
38
|
+
/** HTTP 客户端的全局配置,应用入口配置一次即可。 */
|
|
39
|
+
http?: CreateHttpOptions;
|
|
35
40
|
}
|
|
36
41
|
interface ToastOptions extends Partial<MessageOptions> {
|
|
37
42
|
/**
|
|
@@ -476,7 +481,7 @@ declare function toLine(text: string, connect?: string): string;
|
|
|
476
481
|
/**
|
|
477
482
|
* 将宽度值规范化为可直接用于样式的结果。
|
|
478
483
|
*
|
|
479
|
-
* @param initValue 宽度值,支持数字、数字字符串、CSS
|
|
484
|
+
* @param initValue 宽度值,支持数字、数字字符串、CSS 长度、CSS 计算函数和 `ref`。
|
|
480
485
|
* @param isBase 为 `true` 时直接返回宽度字符串;否则返回 `{ width }` 对象。
|
|
481
486
|
* @returns 宽度字符串或宽度样式对象;无效值返回空字符串或空对象。
|
|
482
487
|
*
|
|
@@ -487,6 +492,10 @@ declare function toLine(text: string, connect?: string): string;
|
|
|
487
492
|
* @example
|
|
488
493
|
* processWidth('50%', true)
|
|
489
494
|
* // => '50%'
|
|
495
|
+
*
|
|
496
|
+
* @example
|
|
497
|
+
* processWidth('calc(100% - 24px)', true)
|
|
498
|
+
* // => 'calc(100% - 24px)'
|
|
490
499
|
*/
|
|
491
500
|
declare function processWidth(initValue: WidthInput, isBase: true): string;
|
|
492
501
|
declare function processWidth(initValue: WidthInput, isBase?: false): WidthStyleResult | {};
|
package/dist/base.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
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.
|
|
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.B9RT8TZf.mjs';
|
|
5
5
|
import './confirmSemantic.mjs';
|
|
6
6
|
import 'element-plus';
|
|
7
|
+
import 'axios';
|
|
7
8
|
import './is.mjs';
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { SybzComponentTheme } from './theme.cjs';
|
|
2
|
+
|
|
1
3
|
type ConfirmVariant = 'default' | 'delete' | 'warning';
|
|
2
4
|
type ConfirmTarget = string | number;
|
|
3
|
-
type ConfirmSemanticTheme =
|
|
5
|
+
type ConfirmSemanticTheme = SybzComponentTheme;
|
|
4
6
|
type ConfirmSemanticButtonType = 'default' | 'primary' | 'success' | 'warning' | 'info' | 'danger' | 'text' | '';
|
|
5
7
|
interface ConfirmSemanticOptions {
|
|
6
8
|
variant?: ConfirmVariant;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { SybzComponentTheme } from './theme.mjs';
|
|
2
|
+
|
|
1
3
|
type ConfirmVariant = 'default' | 'delete' | 'warning';
|
|
2
4
|
type ConfirmTarget = string | number;
|
|
3
|
-
type ConfirmSemanticTheme =
|
|
5
|
+
type ConfirmSemanticTheme = SybzComponentTheme;
|
|
4
6
|
type ConfirmSemanticButtonType = 'default' | 'primary' | 'success' | 'warning' | 'info' | 'danger' | 'text' | '';
|
|
5
7
|
interface ConfirmSemanticOptions {
|
|
6
8
|
variant?: ConfirmVariant;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { SybzComponentTheme } from './theme.js';
|
|
2
|
+
|
|
1
3
|
type ConfirmVariant = 'default' | 'delete' | 'warning';
|
|
2
4
|
type ConfirmTarget = string | number;
|
|
3
|
-
type ConfirmSemanticTheme =
|
|
5
|
+
type ConfirmSemanticTheme = SybzComponentTheme;
|
|
4
6
|
type ConfirmSemanticButtonType = 'default' | 'primary' | 'success' | 'warning' | 'info' | 'danger' | 'text' | '';
|
|
5
7
|
interface ConfirmSemanticOptions {
|
|
6
8
|
variant?: ConfirmVariant;
|
package/dist/format.cjs
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const format = require('./shared/utils.
|
|
3
|
+
const format = require('./shared/utils.1vSv2Q9r.cjs');
|
|
4
4
|
require('./is.cjs');
|
|
5
5
|
require('consola');
|
|
6
6
|
require('vue');
|
|
7
7
|
require('es-toolkit');
|
|
8
8
|
require('./confirmSemantic.cjs');
|
|
9
9
|
require('element-plus');
|
|
10
|
+
require('axios');
|
|
10
11
|
|
|
11
12
|
|
|
12
13
|
|
package/dist/format.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
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.
|
|
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.B9RT8TZf.mjs';
|
|
2
2
|
import './is.mjs';
|
|
3
3
|
import 'consola';
|
|
4
4
|
import 'vue';
|
|
5
5
|
import 'es-toolkit';
|
|
6
6
|
import './confirmSemantic.mjs';
|
|
7
7
|
import 'element-plus';
|
|
8
|
+
import 'axios';
|
package/dist/http.cjs
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
require('axios');
|
|
4
|
+
const format = require('./shared/utils.1vSv2Q9r.cjs');
|
|
5
|
+
require('vue');
|
|
6
|
+
require('consola');
|
|
7
|
+
require('es-toolkit');
|
|
8
|
+
require('./confirmSemantic.cjs');
|
|
9
|
+
require('element-plus');
|
|
10
|
+
require('./is.cjs');
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
exports.HttpError = format.HttpError;
|
|
15
|
+
exports.configureHttp = format.configureHttp;
|
|
16
|
+
exports.createHttp = format.createHttp;
|
|
17
|
+
Object.defineProperty(exports, "http", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function () { return format.http; }
|
|
20
|
+
});
|
package/dist/http.d.cts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { CreateAxiosDefaults, AxiosResponse, AxiosRequestConfig, AxiosInstance } from 'axios';
|
|
2
|
+
|
|
3
|
+
interface HttpRequestConfig<D = unknown> extends AxiosRequestConfig<D> {
|
|
4
|
+
rawResponse?: boolean;
|
|
5
|
+
skipAuth?: boolean;
|
|
6
|
+
/** 是否显示当前请求的错误提示;默认继承全局配置。 */
|
|
7
|
+
showErrorToast?: boolean;
|
|
8
|
+
/** 当前请求的自定义错误文案。 */
|
|
9
|
+
message?: string | ((error: HttpError) => string);
|
|
10
|
+
}
|
|
11
|
+
declare class HttpError<T = unknown> extends Error {
|
|
12
|
+
readonly status?: number;
|
|
13
|
+
readonly code?: string;
|
|
14
|
+
readonly data?: T;
|
|
15
|
+
readonly cause?: unknown;
|
|
16
|
+
constructor(message: string, options?: {
|
|
17
|
+
status?: number;
|
|
18
|
+
code?: string;
|
|
19
|
+
data?: T;
|
|
20
|
+
cause?: unknown;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
interface CreateHttpOptions<D = unknown> extends CreateAxiosDefaults<D> {
|
|
24
|
+
/** 返回 false 时视为业务失败;默认仅识别 success === false。 */
|
|
25
|
+
isBusinessSuccess?: (data: unknown, response: AxiosResponse<D>) => boolean;
|
|
26
|
+
/** 从后端返回体提取业务错误文案。 */
|
|
27
|
+
getBusinessMessage?: (data: unknown, fallback: string) => string;
|
|
28
|
+
/** 统一转换响应体,适用于 { data: ... } 等包装格式。 */
|
|
29
|
+
transformResponseData?: (data: D, response: AxiosResponse<D>) => unknown;
|
|
30
|
+
/** 是否自动使用 $toast.error 提示错误;默认 `true`。 */
|
|
31
|
+
showErrorToast?: boolean;
|
|
32
|
+
toast?: (message: string) => void;
|
|
33
|
+
normalizeError?: (error: unknown) => HttpError;
|
|
34
|
+
/** 统一获取请求令牌。 */
|
|
35
|
+
getToken?: () => string | undefined | null;
|
|
36
|
+
/** 请求发出前的统一处理。 */
|
|
37
|
+
onRequest?: (config: HttpRequestConfig) => HttpRequestConfig | void;
|
|
38
|
+
/** 响应成功后的统一处理。 */
|
|
39
|
+
onResponse?: (response: AxiosResponse) => void;
|
|
40
|
+
/** 响应失败后的统一处理,例如 401 跳转登录。 */
|
|
41
|
+
onError?: (error: HttpError, response?: AxiosResponse) => void | Promise<void>;
|
|
42
|
+
}
|
|
43
|
+
type HttpClient = Omit<AxiosInstance, 'get' | 'post' | 'put' | 'patch' | 'delete'> & {
|
|
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
|
+
send<T = unknown, D = unknown>(config: HttpRequestConfig<D> & {
|
|
47
|
+
rawResponse: true;
|
|
48
|
+
}): Promise<AxiosResponse<T>>;
|
|
49
|
+
send<T = unknown, D = unknown>(config: HttpRequestConfig<D> & {
|
|
50
|
+
rawResponse?: false;
|
|
51
|
+
}): Promise<T>;
|
|
52
|
+
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>;
|
|
57
|
+
delete<T = unknown>(url: string, config?: HttpRequestConfig): Promise<T>;
|
|
58
|
+
download(url: string, params?: unknown, config?: HttpRequestConfig): Promise<Blob>;
|
|
59
|
+
};
|
|
60
|
+
declare function createHttp<D = unknown>(options?: CreateHttpOptions<D>): HttpClient;
|
|
61
|
+
/** 全局 HTTP 客户端;通过 configureUtils({ http: ... }) 配置一次。 */
|
|
62
|
+
declare let http: HttpClient;
|
|
63
|
+
declare function configureHttp(options?: CreateHttpOptions): HttpClient;
|
|
64
|
+
|
|
65
|
+
export { HttpError, configureHttp, createHttp, http };
|
|
66
|
+
export type { CreateHttpOptions, HttpClient, HttpRequestConfig };
|
package/dist/http.d.mts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { CreateAxiosDefaults, AxiosResponse, AxiosRequestConfig, AxiosInstance } from 'axios';
|
|
2
|
+
|
|
3
|
+
interface HttpRequestConfig<D = unknown> extends AxiosRequestConfig<D> {
|
|
4
|
+
rawResponse?: boolean;
|
|
5
|
+
skipAuth?: boolean;
|
|
6
|
+
/** 是否显示当前请求的错误提示;默认继承全局配置。 */
|
|
7
|
+
showErrorToast?: boolean;
|
|
8
|
+
/** 当前请求的自定义错误文案。 */
|
|
9
|
+
message?: string | ((error: HttpError) => string);
|
|
10
|
+
}
|
|
11
|
+
declare class HttpError<T = unknown> extends Error {
|
|
12
|
+
readonly status?: number;
|
|
13
|
+
readonly code?: string;
|
|
14
|
+
readonly data?: T;
|
|
15
|
+
readonly cause?: unknown;
|
|
16
|
+
constructor(message: string, options?: {
|
|
17
|
+
status?: number;
|
|
18
|
+
code?: string;
|
|
19
|
+
data?: T;
|
|
20
|
+
cause?: unknown;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
interface CreateHttpOptions<D = unknown> extends CreateAxiosDefaults<D> {
|
|
24
|
+
/** 返回 false 时视为业务失败;默认仅识别 success === false。 */
|
|
25
|
+
isBusinessSuccess?: (data: unknown, response: AxiosResponse<D>) => boolean;
|
|
26
|
+
/** 从后端返回体提取业务错误文案。 */
|
|
27
|
+
getBusinessMessage?: (data: unknown, fallback: string) => string;
|
|
28
|
+
/** 统一转换响应体,适用于 { data: ... } 等包装格式。 */
|
|
29
|
+
transformResponseData?: (data: D, response: AxiosResponse<D>) => unknown;
|
|
30
|
+
/** 是否自动使用 $toast.error 提示错误;默认 `true`。 */
|
|
31
|
+
showErrorToast?: boolean;
|
|
32
|
+
toast?: (message: string) => void;
|
|
33
|
+
normalizeError?: (error: unknown) => HttpError;
|
|
34
|
+
/** 统一获取请求令牌。 */
|
|
35
|
+
getToken?: () => string | undefined | null;
|
|
36
|
+
/** 请求发出前的统一处理。 */
|
|
37
|
+
onRequest?: (config: HttpRequestConfig) => HttpRequestConfig | void;
|
|
38
|
+
/** 响应成功后的统一处理。 */
|
|
39
|
+
onResponse?: (response: AxiosResponse) => void;
|
|
40
|
+
/** 响应失败后的统一处理,例如 401 跳转登录。 */
|
|
41
|
+
onError?: (error: HttpError, response?: AxiosResponse) => void | Promise<void>;
|
|
42
|
+
}
|
|
43
|
+
type HttpClient = Omit<AxiosInstance, 'get' | 'post' | 'put' | 'patch' | 'delete'> & {
|
|
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
|
+
send<T = unknown, D = unknown>(config: HttpRequestConfig<D> & {
|
|
47
|
+
rawResponse: true;
|
|
48
|
+
}): Promise<AxiosResponse<T>>;
|
|
49
|
+
send<T = unknown, D = unknown>(config: HttpRequestConfig<D> & {
|
|
50
|
+
rawResponse?: false;
|
|
51
|
+
}): Promise<T>;
|
|
52
|
+
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>;
|
|
57
|
+
delete<T = unknown>(url: string, config?: HttpRequestConfig): Promise<T>;
|
|
58
|
+
download(url: string, params?: unknown, config?: HttpRequestConfig): Promise<Blob>;
|
|
59
|
+
};
|
|
60
|
+
declare function createHttp<D = unknown>(options?: CreateHttpOptions<D>): HttpClient;
|
|
61
|
+
/** 全局 HTTP 客户端;通过 configureUtils({ http: ... }) 配置一次。 */
|
|
62
|
+
declare let http: HttpClient;
|
|
63
|
+
declare function configureHttp(options?: CreateHttpOptions): HttpClient;
|
|
64
|
+
|
|
65
|
+
export { HttpError, configureHttp, createHttp, http };
|
|
66
|
+
export type { CreateHttpOptions, HttpClient, HttpRequestConfig };
|
package/dist/http.d.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { CreateAxiosDefaults, AxiosResponse, AxiosRequestConfig, AxiosInstance } from 'axios';
|
|
2
|
+
|
|
3
|
+
interface HttpRequestConfig<D = unknown> extends AxiosRequestConfig<D> {
|
|
4
|
+
rawResponse?: boolean;
|
|
5
|
+
skipAuth?: boolean;
|
|
6
|
+
/** 是否显示当前请求的错误提示;默认继承全局配置。 */
|
|
7
|
+
showErrorToast?: boolean;
|
|
8
|
+
/** 当前请求的自定义错误文案。 */
|
|
9
|
+
message?: string | ((error: HttpError) => string);
|
|
10
|
+
}
|
|
11
|
+
declare class HttpError<T = unknown> extends Error {
|
|
12
|
+
readonly status?: number;
|
|
13
|
+
readonly code?: string;
|
|
14
|
+
readonly data?: T;
|
|
15
|
+
readonly cause?: unknown;
|
|
16
|
+
constructor(message: string, options?: {
|
|
17
|
+
status?: number;
|
|
18
|
+
code?: string;
|
|
19
|
+
data?: T;
|
|
20
|
+
cause?: unknown;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
interface CreateHttpOptions<D = unknown> extends CreateAxiosDefaults<D> {
|
|
24
|
+
/** 返回 false 时视为业务失败;默认仅识别 success === false。 */
|
|
25
|
+
isBusinessSuccess?: (data: unknown, response: AxiosResponse<D>) => boolean;
|
|
26
|
+
/** 从后端返回体提取业务错误文案。 */
|
|
27
|
+
getBusinessMessage?: (data: unknown, fallback: string) => string;
|
|
28
|
+
/** 统一转换响应体,适用于 { data: ... } 等包装格式。 */
|
|
29
|
+
transformResponseData?: (data: D, response: AxiosResponse<D>) => unknown;
|
|
30
|
+
/** 是否自动使用 $toast.error 提示错误;默认 `true`。 */
|
|
31
|
+
showErrorToast?: boolean;
|
|
32
|
+
toast?: (message: string) => void;
|
|
33
|
+
normalizeError?: (error: unknown) => HttpError;
|
|
34
|
+
/** 统一获取请求令牌。 */
|
|
35
|
+
getToken?: () => string | undefined | null;
|
|
36
|
+
/** 请求发出前的统一处理。 */
|
|
37
|
+
onRequest?: (config: HttpRequestConfig) => HttpRequestConfig | void;
|
|
38
|
+
/** 响应成功后的统一处理。 */
|
|
39
|
+
onResponse?: (response: AxiosResponse) => void;
|
|
40
|
+
/** 响应失败后的统一处理,例如 401 跳转登录。 */
|
|
41
|
+
onError?: (error: HttpError, response?: AxiosResponse) => void | Promise<void>;
|
|
42
|
+
}
|
|
43
|
+
type HttpClient = Omit<AxiosInstance, 'get' | 'post' | 'put' | 'patch' | 'delete'> & {
|
|
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
|
+
send<T = unknown, D = unknown>(config: HttpRequestConfig<D> & {
|
|
47
|
+
rawResponse: true;
|
|
48
|
+
}): Promise<AxiosResponse<T>>;
|
|
49
|
+
send<T = unknown, D = unknown>(config: HttpRequestConfig<D> & {
|
|
50
|
+
rawResponse?: false;
|
|
51
|
+
}): Promise<T>;
|
|
52
|
+
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>;
|
|
57
|
+
delete<T = unknown>(url: string, config?: HttpRequestConfig): Promise<T>;
|
|
58
|
+
download(url: string, params?: unknown, config?: HttpRequestConfig): Promise<Blob>;
|
|
59
|
+
};
|
|
60
|
+
declare function createHttp<D = unknown>(options?: CreateHttpOptions<D>): HttpClient;
|
|
61
|
+
/** 全局 HTTP 客户端;通过 configureUtils({ http: ... }) 配置一次。 */
|
|
62
|
+
declare let http: HttpClient;
|
|
63
|
+
declare function configureHttp(options?: CreateHttpOptions): HttpClient;
|
|
64
|
+
|
|
65
|
+
export { HttpError, configureHttp, createHttp, http };
|
|
66
|
+
export type { CreateHttpOptions, HttpClient, HttpRequestConfig };
|
package/dist/http.mjs
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import 'axios';
|
|
2
|
+
export { H as HttpError, G as configureHttp, I as createHttp, J as http } from './shared/utils.B9RT8TZf.mjs';
|
|
3
|
+
import 'vue';
|
|
4
|
+
import 'consola';
|
|
5
|
+
import 'es-toolkit';
|
|
6
|
+
import './confirmSemantic.mjs';
|
|
7
|
+
import 'element-plus';
|
|
8
|
+
import './is.mjs';
|
package/dist/index.cjs
CHANGED
|
@@ -1,21 +1,26 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const format = require('./shared/utils.
|
|
3
|
+
const format = require('./shared/utils.1vSv2Q9r.cjs');
|
|
4
4
|
const confirmSemantic = require('./confirmSemantic.cjs');
|
|
5
5
|
const is = require('./is.cjs');
|
|
6
|
+
const theme = require('./theme.cjs');
|
|
6
7
|
require('vue');
|
|
7
8
|
require('consola');
|
|
8
9
|
require('es-toolkit');
|
|
9
10
|
require('element-plus');
|
|
11
|
+
require('axios');
|
|
10
12
|
|
|
11
13
|
|
|
12
14
|
|
|
13
15
|
exports.$toast = format.$toast;
|
|
16
|
+
exports.HttpError = format.HttpError;
|
|
14
17
|
exports.clearStorage = format.clearStorage;
|
|
15
18
|
exports.clone = format.clone;
|
|
19
|
+
exports.configureHttp = format.configureHttp;
|
|
16
20
|
exports.configureUtils = format.configureUtils;
|
|
17
21
|
exports.confirm = format.confirm;
|
|
18
22
|
exports.copy = format.copy;
|
|
23
|
+
exports.createHttp = format.createHttp;
|
|
19
24
|
exports.debounce = format.debounce;
|
|
20
25
|
exports.delay = format.delay;
|
|
21
26
|
exports.formatBytes = format.formatBytes;
|
|
@@ -29,6 +34,10 @@ exports.getStorage = format.getStorage;
|
|
|
29
34
|
exports.getType = format.getType;
|
|
30
35
|
exports.getUtilsBuildTime = format.getUtilsBuildTime;
|
|
31
36
|
exports.getVariable = format.getVariable;
|
|
37
|
+
Object.defineProperty(exports, "http", {
|
|
38
|
+
enumerable: true,
|
|
39
|
+
get: function () { return format.http; }
|
|
40
|
+
});
|
|
32
41
|
exports.isEmpty = format.isEmpty;
|
|
33
42
|
exports.log = format.log;
|
|
34
43
|
exports.merge = format.merge;
|
|
@@ -66,3 +75,6 @@ exports.isUrl = is.isUrl;
|
|
|
66
75
|
exports.objectToString = is.objectToString;
|
|
67
76
|
exports.toRawType = is.toRawType;
|
|
68
77
|
exports.toTypeString = is.toTypeString;
|
|
78
|
+
exports.SYBZ_THEME_PREFIX = theme.SYBZ_THEME_PREFIX;
|
|
79
|
+
exports.isSybzTheme = theme.isSybzTheme;
|
|
80
|
+
exports.resolveSybzComponentTheme = theme.resolveSybzComponentTheme;
|
package/dist/index.d.cts
CHANGED
|
@@ -2,5 +2,8 @@ export { $toast, ConfirmCustomOptions, ConfirmMessage, ConfirmOptions, ConfirmTh
|
|
|
2
2
|
export { ConfirmSemanticButtonType, ConfirmSemanticOptions, ConfirmSemanticResult, ConfirmSemanticTheme, ConfirmTarget, ConfirmVariant, resolveConfirmSemantic } from './confirmSemantic.cjs';
|
|
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.cjs';
|
|
4
4
|
export { FormatBytesConvertOptions, FormatBytesOptions, FormatTimeFallback, FormatTimeInput, FormatToFixedOptions, formatBytes, formatBytesConvert, formatDurationTime, formatTextToHtml, formatThousands, formatTime, formatToFixed } from './format.cjs';
|
|
5
|
+
export { SYBZ_THEME_PREFIX, SybzComponentTheme, SybzThemeName, isSybzTheme, resolveSybzComponentTheme } from './theme.cjs';
|
|
6
|
+
export { CreateHttpOptions, HttpClient, HttpError, HttpRequestConfig, configureHttp, createHttp, http } from './http.cjs';
|
|
5
7
|
import 'vue';
|
|
6
8
|
import 'element-plus';
|
|
9
|
+
import 'axios';
|
package/dist/index.d.mts
CHANGED
|
@@ -2,5 +2,8 @@ export { $toast, ConfirmCustomOptions, ConfirmMessage, ConfirmOptions, ConfirmTh
|
|
|
2
2
|
export { ConfirmSemanticButtonType, ConfirmSemanticOptions, ConfirmSemanticResult, ConfirmSemanticTheme, ConfirmTarget, ConfirmVariant, 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 { FormatBytesConvertOptions, FormatBytesOptions, FormatTimeFallback, FormatTimeInput, FormatToFixedOptions, formatBytes, formatBytesConvert, formatDurationTime, formatTextToHtml, formatThousands, formatTime, formatToFixed } from './format.mjs';
|
|
5
|
+
export { SYBZ_THEME_PREFIX, SybzComponentTheme, SybzThemeName, isSybzTheme, resolveSybzComponentTheme } from './theme.mjs';
|
|
6
|
+
export { CreateHttpOptions, HttpClient, HttpError, HttpRequestConfig, configureHttp, createHttp, http } from './http.mjs';
|
|
5
7
|
import 'vue';
|
|
6
8
|
import 'element-plus';
|
|
9
|
+
import 'axios';
|
package/dist/index.d.ts
CHANGED
|
@@ -2,5 +2,8 @@ export { $toast, ConfirmCustomOptions, ConfirmMessage, ConfirmOptions, ConfirmTh
|
|
|
2
2
|
export { ConfirmSemanticButtonType, ConfirmSemanticOptions, ConfirmSemanticResult, ConfirmSemanticTheme, ConfirmTarget, ConfirmVariant, resolveConfirmSemantic } from './confirmSemantic.js';
|
|
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.js';
|
|
4
4
|
export { FormatBytesConvertOptions, FormatBytesOptions, FormatTimeFallback, FormatTimeInput, FormatToFixedOptions, formatBytes, formatBytesConvert, formatDurationTime, formatTextToHtml, formatThousands, formatTime, formatToFixed } from './format.js';
|
|
5
|
+
export { SYBZ_THEME_PREFIX, SybzComponentTheme, SybzThemeName, isSybzTheme, resolveSybzComponentTheme } from './theme.js';
|
|
6
|
+
export { CreateHttpOptions, HttpClient, HttpError, HttpRequestConfig, configureHttp, createHttp, http } from './http.js';
|
|
5
7
|
import 'vue';
|
|
6
8
|
import 'element-plus';
|
|
9
|
+
import 'axios';
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
export { $ as $toast, c as clearStorage, a as clone, b as configureUtils, d as confirm, e as copy, 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, 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.
|
|
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.B9RT8TZf.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
|
+
export { SYBZ_THEME_PREFIX, isSybzTheme, resolveSybzComponentTheme } from './theme.mjs';
|
|
4
5
|
import 'vue';
|
|
5
6
|
import 'consola';
|
|
6
7
|
import 'es-toolkit';
|
|
7
8
|
import 'element-plus';
|
|
9
|
+
import 'axios';
|
|
@@ -5,8 +5,13 @@ const consola = require('consola');
|
|
|
5
5
|
const esToolkit = require('es-toolkit');
|
|
6
6
|
const confirmSemantic = require('../confirmSemantic.cjs');
|
|
7
7
|
const elementPlus = require('element-plus');
|
|
8
|
+
const axios = require('axios');
|
|
8
9
|
const is = require('../is.cjs');
|
|
9
10
|
|
|
11
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
12
|
+
|
|
13
|
+
const axios__default = /*#__PURE__*/_interopDefaultCompat(axios);
|
|
14
|
+
|
|
10
15
|
function formatBytes(bytes, options = {}) {
|
|
11
16
|
let { digit = 2, thousands = false, prefix = "", suffix = "", roundType = "floor" } = options;
|
|
12
17
|
if (is.isStringNumber(bytes) || is.isNumber(bytes)) {
|
|
@@ -220,21 +225,141 @@ function formatTextToHtml(str) {
|
|
|
220
225
|
return withBreaks.replace(/\t/g, " ");
|
|
221
226
|
}
|
|
222
227
|
|
|
228
|
+
class HttpError extends Error {
|
|
229
|
+
status;
|
|
230
|
+
code;
|
|
231
|
+
data;
|
|
232
|
+
cause;
|
|
233
|
+
constructor(message, options = {}) {
|
|
234
|
+
super(message);
|
|
235
|
+
this.name = "HttpError";
|
|
236
|
+
Object.assign(this, options);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
const record = (value) => typeof value === "object" && value !== null;
|
|
240
|
+
const defaultMessage = (data, fallback) => {
|
|
241
|
+
if (!record(data)) return fallback;
|
|
242
|
+
for (const key of ["detail", "error", "message"])
|
|
243
|
+
if (typeof data[key] === "string" && data[key]) return data[key];
|
|
244
|
+
return fallback;
|
|
245
|
+
};
|
|
246
|
+
function createHttp(options = {}) {
|
|
247
|
+
const {
|
|
248
|
+
isBusinessSuccess = (data) => !(record(data) && data.success === false),
|
|
249
|
+
getBusinessMessage = defaultMessage,
|
|
250
|
+
transformResponseData,
|
|
251
|
+
showErrorToast = true,
|
|
252
|
+
toast = (message) => $toast.error(message),
|
|
253
|
+
normalizeError,
|
|
254
|
+
getToken,
|
|
255
|
+
onRequest,
|
|
256
|
+
onResponse,
|
|
257
|
+
onError,
|
|
258
|
+
...axiosOptions
|
|
259
|
+
} = options;
|
|
260
|
+
const instance = axios__default.create(axiosOptions);
|
|
261
|
+
const normalize = (error) => {
|
|
262
|
+
if (error instanceof HttpError) return error;
|
|
263
|
+
if (!axios__default.isAxiosError(error))
|
|
264
|
+
return new HttpError(error instanceof Error ? error.message : "\u8BF7\u6C42\u5931\u8D25", { cause: error });
|
|
265
|
+
const response = error.response;
|
|
266
|
+
const message = error.code === axios.AxiosError.ECONNABORTED || error.code === "ETIMEDOUT" ? "\u8BF7\u6C42\u8D85\u65F6\uFF0C\u8BF7\u91CD\u8BD5" : error.code === axios.AxiosError.ERR_CANCELED ? "\u8BF7\u6C42\u5DF2\u53D6\u6D88" : response ? `\u8BF7\u6C42\u5931\u8D25\uFF08${response.status}\uFF09` : "\u7F51\u7EDC\u8FDE\u63A5\u5931\u8D25\uFF0C\u8BF7\u68C0\u67E5\u7F51\u7EDC\u540E\u91CD\u8BD5";
|
|
267
|
+
return new HttpError(getBusinessMessage(response?.data, message), {
|
|
268
|
+
status: response?.status,
|
|
269
|
+
code: error.code,
|
|
270
|
+
data: response?.data,
|
|
271
|
+
cause: error
|
|
272
|
+
});
|
|
273
|
+
};
|
|
274
|
+
instance.interceptors.request.use((config) => {
|
|
275
|
+
const requestConfig = config;
|
|
276
|
+
requestConfig.headers = axios.AxiosHeaders.from(requestConfig.headers);
|
|
277
|
+
if (!requestConfig.skipAuth) {
|
|
278
|
+
const token = getToken?.();
|
|
279
|
+
if (token && !requestConfig.headers.has("Authorization"))
|
|
280
|
+
requestConfig.headers.set("Authorization", `Bearer ${token}`);
|
|
281
|
+
}
|
|
282
|
+
return onRequest?.(requestConfig) || requestConfig;
|
|
283
|
+
});
|
|
284
|
+
instance.interceptors.response.use(
|
|
285
|
+
(response) => {
|
|
286
|
+
const config = response.config;
|
|
287
|
+
if (!isBusinessSuccess(response.data, response))
|
|
288
|
+
throw new HttpError(getBusinessMessage(response.data, "\u8BF7\u6C42\u5931\u8D25"), {
|
|
289
|
+
status: response.status,
|
|
290
|
+
data: response.data
|
|
291
|
+
});
|
|
292
|
+
if (transformResponseData && !config.rawResponse)
|
|
293
|
+
response.data = transformResponseData(
|
|
294
|
+
response.data,
|
|
295
|
+
response
|
|
296
|
+
);
|
|
297
|
+
onResponse?.(response);
|
|
298
|
+
return response;
|
|
299
|
+
},
|
|
300
|
+
async (error) => {
|
|
301
|
+
const normalized = normalizeError ? normalizeError(error) : normalize(error);
|
|
302
|
+
const response = axios__default.isAxiosError(error) ? error.response : void 0;
|
|
303
|
+
const requestConfig = response?.config;
|
|
304
|
+
const customMessage = requestConfig?.message;
|
|
305
|
+
const message = typeof customMessage === "function" ? customMessage(normalized) : customMessage || normalized.message;
|
|
306
|
+
if (requestConfig?.showErrorToast ?? showErrorToast) toast?.(message);
|
|
307
|
+
await onError?.(normalized, response);
|
|
308
|
+
throw normalized;
|
|
309
|
+
}
|
|
310
|
+
);
|
|
311
|
+
const send = async (config) => {
|
|
312
|
+
const response = await instance.request(config);
|
|
313
|
+
return config.rawResponse ? response : response.data;
|
|
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
|
+
};
|
|
323
|
+
const client = Object.assign(request, instance, {
|
|
324
|
+
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 }),
|
|
329
|
+
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 })
|
|
331
|
+
});
|
|
332
|
+
return client;
|
|
333
|
+
}
|
|
334
|
+
exports.http = createHttp();
|
|
335
|
+
function configureHttp(options = {}) {
|
|
336
|
+
exports.http = createHttp(options);
|
|
337
|
+
return exports.http;
|
|
338
|
+
}
|
|
339
|
+
|
|
223
340
|
const DEFAULT_CONFIRM_BUTTON_CLASS = "s-message-box__confirm-btn";
|
|
224
341
|
const DEFAULT_CANCEL_BUTTON_CLASS = "s-message-box__cancel-btn";
|
|
225
342
|
const CHENGHUA_CONFIRM_BOX_CLASS = "s-message-box--chenghua";
|
|
226
343
|
const CHENGHUA_CONFIRM_BUTTON_CLASS = "s-message-box__confirm-btn--chenghua";
|
|
227
344
|
const CHENGHUA_CANCEL_BUTTON_CLASS = "s-message-box__cancel-btn--chenghua";
|
|
228
345
|
const SHIJINGSHAN_CONFIRM_BOX_CLASS = "s-message-box--shijingshan";
|
|
346
|
+
const SYBZ_CONFIRM_BOX_CLASS = "s-message-box--sybz";
|
|
229
347
|
const SHIJINGSHAN_CONFIRM_BUTTON_CLASS = "s-message-box__confirm-btn--shijingshan";
|
|
348
|
+
const SYBZ_CONFIRM_BUTTON_CLASS = "s-message-box__confirm-btn--sybz";
|
|
230
349
|
const SHIJINGSHAN_CANCEL_BUTTON_CLASS = "s-message-box__cancel-btn--shijingshan";
|
|
350
|
+
const SYBZ_CANCEL_BUTTON_CLASS = "s-message-box__cancel-btn--sybz";
|
|
231
351
|
const utilsConfig = {
|
|
232
|
-
theme: "default"
|
|
352
|
+
theme: "default",
|
|
353
|
+
http: {}
|
|
233
354
|
};
|
|
234
355
|
function configureUtils(config) {
|
|
235
356
|
if (config.theme !== void 0) {
|
|
236
357
|
utilsConfig.theme = config.theme;
|
|
237
358
|
}
|
|
359
|
+
if (config.http !== void 0) {
|
|
360
|
+
utilsConfig.http = config.http;
|
|
361
|
+
configureHttp(config.http);
|
|
362
|
+
}
|
|
238
363
|
return { ...utilsConfig };
|
|
239
364
|
}
|
|
240
365
|
function _getBrowserStorage(isSession = false) {
|
|
@@ -800,6 +925,7 @@ function toLine(text, connect = "-") {
|
|
|
800
925
|
return translateText;
|
|
801
926
|
}
|
|
802
927
|
const _CSS_UNIT_RE = /^[0-9]+(\.[0-9]+)?(px|%|em|rem|vw|vh|ch)$/;
|
|
928
|
+
const _CSS_LENGTH_FUNCTION_RE = /^(?:calc|min|max|clamp|var)\(.+\)$/;
|
|
803
929
|
function processWidth(initValue, isBase = false) {
|
|
804
930
|
const raw = vue.unref(initValue);
|
|
805
931
|
if (raw === void 0 || raw === null || raw === "") {
|
|
@@ -809,7 +935,7 @@ function processWidth(initValue, isBase = false) {
|
|
|
809
935
|
let res;
|
|
810
936
|
if (!isNaN(Number(str))) {
|
|
811
937
|
res = str + "px";
|
|
812
|
-
} else if (_CSS_UNIT_RE.test(str)) {
|
|
938
|
+
} else if (_CSS_UNIT_RE.test(str) || _CSS_LENGTH_FUNCTION_RE.test(str)) {
|
|
813
939
|
res = str;
|
|
814
940
|
} else {
|
|
815
941
|
return isBase ? "" : {};
|
|
@@ -976,6 +1102,7 @@ function confirm(messageOrOptions, optionsOrAppContext = null, appContext = null
|
|
|
976
1102
|
const resolvedAppContext = _resolveAppContext(optionAppContext || argumentAppContext);
|
|
977
1103
|
const isChenghuaTheme = theme === "chenghua";
|
|
978
1104
|
const isShijingshanTheme = theme === "shijingshan";
|
|
1105
|
+
const isSybzTheme = theme === "sybz";
|
|
979
1106
|
const mergeOptions = {
|
|
980
1107
|
title: semantic.title,
|
|
981
1108
|
draggable: true,
|
|
@@ -989,6 +1116,7 @@ function confirm(messageOrOptions, optionsOrAppContext = null, appContext = null
|
|
|
989
1116
|
customClass: _mergeClassNames(
|
|
990
1117
|
isChenghuaTheme && CHENGHUA_CONFIRM_BOX_CLASS,
|
|
991
1118
|
isShijingshanTheme && SHIJINGSHAN_CONFIRM_BOX_CLASS,
|
|
1119
|
+
isSybzTheme && SYBZ_CONFIRM_BOX_CLASS,
|
|
992
1120
|
variant !== "default" && `s-message-box--${variant}`,
|
|
993
1121
|
customClass
|
|
994
1122
|
),
|
|
@@ -996,12 +1124,14 @@ function confirm(messageOrOptions, optionsOrAppContext = null, appContext = null
|
|
|
996
1124
|
DEFAULT_CONFIRM_BUTTON_CLASS,
|
|
997
1125
|
isChenghuaTheme && CHENGHUA_CONFIRM_BUTTON_CLASS,
|
|
998
1126
|
isShijingshanTheme && SHIJINGSHAN_CONFIRM_BUTTON_CLASS,
|
|
1127
|
+
isSybzTheme && SYBZ_CONFIRM_BUTTON_CLASS,
|
|
999
1128
|
confirmButtonClass
|
|
1000
1129
|
),
|
|
1001
1130
|
cancelButtonClass: _mergeClassNames(
|
|
1002
1131
|
DEFAULT_CANCEL_BUTTON_CLASS,
|
|
1003
1132
|
isChenghuaTheme && CHENGHUA_CANCEL_BUTTON_CLASS,
|
|
1004
1133
|
isShijingshanTheme && SHIJINGSHAN_CANCEL_BUTTON_CLASS,
|
|
1134
|
+
isSybzTheme && SYBZ_CANCEL_BUTTON_CLASS,
|
|
1005
1135
|
cancelButtonClass
|
|
1006
1136
|
)
|
|
1007
1137
|
};
|
|
@@ -1072,7 +1202,7 @@ function getVariable(propertyName, fallback = "") {
|
|
|
1072
1202
|
const DEFAULT_BUILD_TIME_FALLBACK = "\u672A\u6CE8\u5165";
|
|
1073
1203
|
function getUtilsBuildTime(fallback = DEFAULT_BUILD_TIME_FALLBACK) {
|
|
1074
1204
|
{
|
|
1075
|
-
return "2026-09-
|
|
1205
|
+
return "2026-09-18 15:19:39";
|
|
1076
1206
|
}
|
|
1077
1207
|
}
|
|
1078
1208
|
function test() {
|
|
@@ -1080,11 +1210,14 @@ function test() {
|
|
|
1080
1210
|
}
|
|
1081
1211
|
|
|
1082
1212
|
exports.$toast = $toast;
|
|
1213
|
+
exports.HttpError = HttpError;
|
|
1083
1214
|
exports.clearStorage = clearStorage;
|
|
1084
1215
|
exports.clone = clone;
|
|
1216
|
+
exports.configureHttp = configureHttp;
|
|
1085
1217
|
exports.configureUtils = configureUtils;
|
|
1086
1218
|
exports.confirm = confirm;
|
|
1087
1219
|
exports.copy = copy;
|
|
1220
|
+
exports.createHttp = createHttp;
|
|
1088
1221
|
exports.debounce = debounce;
|
|
1089
1222
|
exports.delay = delay;
|
|
1090
1223
|
exports.formatBytes = formatBytes;
|
|
@@ -2,7 +2,8 @@ import { isRef, unref, isVNode, toRaw } from 'vue';
|
|
|
2
2
|
import { consola } from 'consola';
|
|
3
3
|
import { cloneDeep } from 'es-toolkit';
|
|
4
4
|
import { resolveConfirmSemantic } from '../confirmSemantic.mjs';
|
|
5
|
-
import {
|
|
5
|
+
import { ElMessage, ElMessageBox } from 'element-plus';
|
|
6
|
+
import axios, { AxiosHeaders, AxiosError } from 'axios';
|
|
6
7
|
import { isStringNumber, isNumber } from '../is.mjs';
|
|
7
8
|
|
|
8
9
|
function formatBytes(bytes, options = {}) {
|
|
@@ -218,21 +219,141 @@ function formatTextToHtml(str) {
|
|
|
218
219
|
return withBreaks.replace(/\t/g, " ");
|
|
219
220
|
}
|
|
220
221
|
|
|
222
|
+
class HttpError extends Error {
|
|
223
|
+
status;
|
|
224
|
+
code;
|
|
225
|
+
data;
|
|
226
|
+
cause;
|
|
227
|
+
constructor(message, options = {}) {
|
|
228
|
+
super(message);
|
|
229
|
+
this.name = "HttpError";
|
|
230
|
+
Object.assign(this, options);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
const record = (value) => typeof value === "object" && value !== null;
|
|
234
|
+
const defaultMessage = (data, fallback) => {
|
|
235
|
+
if (!record(data)) return fallback;
|
|
236
|
+
for (const key of ["detail", "error", "message"])
|
|
237
|
+
if (typeof data[key] === "string" && data[key]) return data[key];
|
|
238
|
+
return fallback;
|
|
239
|
+
};
|
|
240
|
+
function createHttp(options = {}) {
|
|
241
|
+
const {
|
|
242
|
+
isBusinessSuccess = (data) => !(record(data) && data.success === false),
|
|
243
|
+
getBusinessMessage = defaultMessage,
|
|
244
|
+
transformResponseData,
|
|
245
|
+
showErrorToast = true,
|
|
246
|
+
toast = (message) => $toast.error(message),
|
|
247
|
+
normalizeError,
|
|
248
|
+
getToken,
|
|
249
|
+
onRequest,
|
|
250
|
+
onResponse,
|
|
251
|
+
onError,
|
|
252
|
+
...axiosOptions
|
|
253
|
+
} = options;
|
|
254
|
+
const instance = axios.create(axiosOptions);
|
|
255
|
+
const normalize = (error) => {
|
|
256
|
+
if (error instanceof HttpError) return error;
|
|
257
|
+
if (!axios.isAxiosError(error))
|
|
258
|
+
return new HttpError(error instanceof Error ? error.message : "\u8BF7\u6C42\u5931\u8D25", { cause: error });
|
|
259
|
+
const response = error.response;
|
|
260
|
+
const message = error.code === AxiosError.ECONNABORTED || error.code === "ETIMEDOUT" ? "\u8BF7\u6C42\u8D85\u65F6\uFF0C\u8BF7\u91CD\u8BD5" : error.code === AxiosError.ERR_CANCELED ? "\u8BF7\u6C42\u5DF2\u53D6\u6D88" : response ? `\u8BF7\u6C42\u5931\u8D25\uFF08${response.status}\uFF09` : "\u7F51\u7EDC\u8FDE\u63A5\u5931\u8D25\uFF0C\u8BF7\u68C0\u67E5\u7F51\u7EDC\u540E\u91CD\u8BD5";
|
|
261
|
+
return new HttpError(getBusinessMessage(response?.data, message), {
|
|
262
|
+
status: response?.status,
|
|
263
|
+
code: error.code,
|
|
264
|
+
data: response?.data,
|
|
265
|
+
cause: error
|
|
266
|
+
});
|
|
267
|
+
};
|
|
268
|
+
instance.interceptors.request.use((config) => {
|
|
269
|
+
const requestConfig = config;
|
|
270
|
+
requestConfig.headers = AxiosHeaders.from(requestConfig.headers);
|
|
271
|
+
if (!requestConfig.skipAuth) {
|
|
272
|
+
const token = getToken?.();
|
|
273
|
+
if (token && !requestConfig.headers.has("Authorization"))
|
|
274
|
+
requestConfig.headers.set("Authorization", `Bearer ${token}`);
|
|
275
|
+
}
|
|
276
|
+
return onRequest?.(requestConfig) || requestConfig;
|
|
277
|
+
});
|
|
278
|
+
instance.interceptors.response.use(
|
|
279
|
+
(response) => {
|
|
280
|
+
const config = response.config;
|
|
281
|
+
if (!isBusinessSuccess(response.data, response))
|
|
282
|
+
throw new HttpError(getBusinessMessage(response.data, "\u8BF7\u6C42\u5931\u8D25"), {
|
|
283
|
+
status: response.status,
|
|
284
|
+
data: response.data
|
|
285
|
+
});
|
|
286
|
+
if (transformResponseData && !config.rawResponse)
|
|
287
|
+
response.data = transformResponseData(
|
|
288
|
+
response.data,
|
|
289
|
+
response
|
|
290
|
+
);
|
|
291
|
+
onResponse?.(response);
|
|
292
|
+
return response;
|
|
293
|
+
},
|
|
294
|
+
async (error) => {
|
|
295
|
+
const normalized = normalizeError ? normalizeError(error) : normalize(error);
|
|
296
|
+
const response = axios.isAxiosError(error) ? error.response : void 0;
|
|
297
|
+
const requestConfig = response?.config;
|
|
298
|
+
const customMessage = requestConfig?.message;
|
|
299
|
+
const message = typeof customMessage === "function" ? customMessage(normalized) : customMessage || normalized.message;
|
|
300
|
+
if (requestConfig?.showErrorToast ?? showErrorToast) toast?.(message);
|
|
301
|
+
await onError?.(normalized, response);
|
|
302
|
+
throw normalized;
|
|
303
|
+
}
|
|
304
|
+
);
|
|
305
|
+
const send = async (config) => {
|
|
306
|
+
const response = await instance.request(config);
|
|
307
|
+
return config.rawResponse ? response : response.data;
|
|
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
|
+
};
|
|
317
|
+
const client = Object.assign(request, instance, {
|
|
318
|
+
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 }),
|
|
323
|
+
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 })
|
|
325
|
+
});
|
|
326
|
+
return client;
|
|
327
|
+
}
|
|
328
|
+
let http = createHttp();
|
|
329
|
+
function configureHttp(options = {}) {
|
|
330
|
+
http = createHttp(options);
|
|
331
|
+
return http;
|
|
332
|
+
}
|
|
333
|
+
|
|
221
334
|
const DEFAULT_CONFIRM_BUTTON_CLASS = "s-message-box__confirm-btn";
|
|
222
335
|
const DEFAULT_CANCEL_BUTTON_CLASS = "s-message-box__cancel-btn";
|
|
223
336
|
const CHENGHUA_CONFIRM_BOX_CLASS = "s-message-box--chenghua";
|
|
224
337
|
const CHENGHUA_CONFIRM_BUTTON_CLASS = "s-message-box__confirm-btn--chenghua";
|
|
225
338
|
const CHENGHUA_CANCEL_BUTTON_CLASS = "s-message-box__cancel-btn--chenghua";
|
|
226
339
|
const SHIJINGSHAN_CONFIRM_BOX_CLASS = "s-message-box--shijingshan";
|
|
340
|
+
const SYBZ_CONFIRM_BOX_CLASS = "s-message-box--sybz";
|
|
227
341
|
const SHIJINGSHAN_CONFIRM_BUTTON_CLASS = "s-message-box__confirm-btn--shijingshan";
|
|
342
|
+
const SYBZ_CONFIRM_BUTTON_CLASS = "s-message-box__confirm-btn--sybz";
|
|
228
343
|
const SHIJINGSHAN_CANCEL_BUTTON_CLASS = "s-message-box__cancel-btn--shijingshan";
|
|
344
|
+
const SYBZ_CANCEL_BUTTON_CLASS = "s-message-box__cancel-btn--sybz";
|
|
229
345
|
const utilsConfig = {
|
|
230
|
-
theme: "default"
|
|
346
|
+
theme: "default",
|
|
347
|
+
http: {}
|
|
231
348
|
};
|
|
232
349
|
function configureUtils(config) {
|
|
233
350
|
if (config.theme !== void 0) {
|
|
234
351
|
utilsConfig.theme = config.theme;
|
|
235
352
|
}
|
|
353
|
+
if (config.http !== void 0) {
|
|
354
|
+
utilsConfig.http = config.http;
|
|
355
|
+
configureHttp(config.http);
|
|
356
|
+
}
|
|
236
357
|
return { ...utilsConfig };
|
|
237
358
|
}
|
|
238
359
|
function _getBrowserStorage(isSession = false) {
|
|
@@ -798,6 +919,7 @@ function toLine(text, connect = "-") {
|
|
|
798
919
|
return translateText;
|
|
799
920
|
}
|
|
800
921
|
const _CSS_UNIT_RE = /^[0-9]+(\.[0-9]+)?(px|%|em|rem|vw|vh|ch)$/;
|
|
922
|
+
const _CSS_LENGTH_FUNCTION_RE = /^(?:calc|min|max|clamp|var)\(.+\)$/;
|
|
801
923
|
function processWidth(initValue, isBase = false) {
|
|
802
924
|
const raw = unref(initValue);
|
|
803
925
|
if (raw === void 0 || raw === null || raw === "") {
|
|
@@ -807,7 +929,7 @@ function processWidth(initValue, isBase = false) {
|
|
|
807
929
|
let res;
|
|
808
930
|
if (!isNaN(Number(str))) {
|
|
809
931
|
res = str + "px";
|
|
810
|
-
} else if (_CSS_UNIT_RE.test(str)) {
|
|
932
|
+
} else if (_CSS_UNIT_RE.test(str) || _CSS_LENGTH_FUNCTION_RE.test(str)) {
|
|
811
933
|
res = str;
|
|
812
934
|
} else {
|
|
813
935
|
return isBase ? "" : {};
|
|
@@ -974,6 +1096,7 @@ function confirm(messageOrOptions, optionsOrAppContext = null, appContext = null
|
|
|
974
1096
|
const resolvedAppContext = _resolveAppContext(optionAppContext || argumentAppContext);
|
|
975
1097
|
const isChenghuaTheme = theme === "chenghua";
|
|
976
1098
|
const isShijingshanTheme = theme === "shijingshan";
|
|
1099
|
+
const isSybzTheme = theme === "sybz";
|
|
977
1100
|
const mergeOptions = {
|
|
978
1101
|
title: semantic.title,
|
|
979
1102
|
draggable: true,
|
|
@@ -987,6 +1110,7 @@ function confirm(messageOrOptions, optionsOrAppContext = null, appContext = null
|
|
|
987
1110
|
customClass: _mergeClassNames(
|
|
988
1111
|
isChenghuaTheme && CHENGHUA_CONFIRM_BOX_CLASS,
|
|
989
1112
|
isShijingshanTheme && SHIJINGSHAN_CONFIRM_BOX_CLASS,
|
|
1113
|
+
isSybzTheme && SYBZ_CONFIRM_BOX_CLASS,
|
|
990
1114
|
variant !== "default" && `s-message-box--${variant}`,
|
|
991
1115
|
customClass
|
|
992
1116
|
),
|
|
@@ -994,12 +1118,14 @@ function confirm(messageOrOptions, optionsOrAppContext = null, appContext = null
|
|
|
994
1118
|
DEFAULT_CONFIRM_BUTTON_CLASS,
|
|
995
1119
|
isChenghuaTheme && CHENGHUA_CONFIRM_BUTTON_CLASS,
|
|
996
1120
|
isShijingshanTheme && SHIJINGSHAN_CONFIRM_BUTTON_CLASS,
|
|
1121
|
+
isSybzTheme && SYBZ_CONFIRM_BUTTON_CLASS,
|
|
997
1122
|
confirmButtonClass
|
|
998
1123
|
),
|
|
999
1124
|
cancelButtonClass: _mergeClassNames(
|
|
1000
1125
|
DEFAULT_CANCEL_BUTTON_CLASS,
|
|
1001
1126
|
isChenghuaTheme && CHENGHUA_CANCEL_BUTTON_CLASS,
|
|
1002
1127
|
isShijingshanTheme && SHIJINGSHAN_CANCEL_BUTTON_CLASS,
|
|
1128
|
+
isSybzTheme && SYBZ_CANCEL_BUTTON_CLASS,
|
|
1003
1129
|
cancelButtonClass
|
|
1004
1130
|
)
|
|
1005
1131
|
};
|
|
@@ -1070,11 +1196,11 @@ function getVariable(propertyName, fallback = "") {
|
|
|
1070
1196
|
const DEFAULT_BUILD_TIME_FALLBACK = "\u672A\u6CE8\u5165";
|
|
1071
1197
|
function getUtilsBuildTime(fallback = DEFAULT_BUILD_TIME_FALLBACK) {
|
|
1072
1198
|
{
|
|
1073
|
-
return "2026-09-
|
|
1199
|
+
return "2026-09-18 15:19:39";
|
|
1074
1200
|
}
|
|
1075
1201
|
}
|
|
1076
1202
|
function test() {
|
|
1077
1203
|
return `build time: ${getUtilsBuildTime()}`;
|
|
1078
1204
|
}
|
|
1079
1205
|
|
|
1080
|
-
export { $toast as $, formatBytesConvert as A, formatDurationTime as B, formatTextToHtml as C, formatThousands as D, formatTime as E, formatToFixed as F, clone as a, configureUtils as b, clearStorage as c, confirm as d, copy as e, debounce as f, delay as g, getStorage as h, getType as i, getUtilsBuildTime as j, getVariable as k, isEmpty as l, log as m, merge as n, mockValue as o, processWidth as p, throttle as q, random as r, setStorage as s, test as t, toLine as u, tryCatch as v, validate as w, validateForm as x, validateOnSubmit as y, formatBytes as z };
|
|
1206
|
+
export { $toast as $, formatBytesConvert as A, formatDurationTime as B, formatTextToHtml as C, formatThousands as D, formatTime as E, formatToFixed as F, configureHttp as G, HttpError as H, createHttp as I, http as J, clone as a, configureUtils as b, clearStorage as c, confirm as d, copy as e, debounce as f, delay as g, getStorage as h, getType as i, getUtilsBuildTime as j, getVariable as k, isEmpty as l, log as m, merge as n, mockValue as o, processWidth as p, throttle as q, random as r, setStorage as s, test as t, toLine as u, tryCatch as v, validate as w, validateForm as x, validateOnSubmit as y, formatBytes as z };
|
|
@@ -45,30 +45,47 @@ const runPackageBin = (packageName, binPath, args2) => {
|
|
|
45
45
|
const executablePath = node_path.resolve(packageJsonPath, "..", binPath);
|
|
46
46
|
node_child_process.execFileSync(process.execPath, [executablePath, ...args2], { cwd, stdio: "inherit" });
|
|
47
47
|
};
|
|
48
|
-
const
|
|
48
|
+
const backupFile = (filePath) => {
|
|
49
|
+
const backupPath = `${filePath}.sybz-code-standard.bak`;
|
|
50
|
+
node_fs.copyFileSync(filePath, backupPath);
|
|
51
|
+
return backupPath;
|
|
52
|
+
};
|
|
53
|
+
const writeConfigFile = (relativePath, content, force) => {
|
|
49
54
|
const filePath = node_path.resolve(cwd, relativePath);
|
|
50
55
|
if (!node_fs.existsSync(filePath)) {
|
|
51
56
|
node_fs.writeFileSync(filePath, content, "utf8");
|
|
52
57
|
console.log(`\u521B\u5EFA ${relativePath}`);
|
|
53
58
|
return;
|
|
54
59
|
}
|
|
55
|
-
if (node_fs.readFileSync(filePath, "utf8")
|
|
56
|
-
|
|
60
|
+
if (node_fs.readFileSync(filePath, "utf8") === content) return;
|
|
61
|
+
if (!force) {
|
|
62
|
+
console.warn(`\u8DF3\u8FC7 ${relativePath}\uFF1A\u5DF2\u5B58\u5728\u81EA\u5B9A\u4E49\u5185\u5BB9\uFF0C\u53EF\u4F7F\u7528 init --force \u5F3A\u5236\u8986\u76D6`);
|
|
63
|
+
return;
|
|
57
64
|
}
|
|
65
|
+
const backupPath = backupFile(filePath);
|
|
66
|
+
node_fs.writeFileSync(filePath, content, "utf8");
|
|
67
|
+
console.log(`\u8986\u76D6 ${relativePath}\uFF08\u539F\u6587\u4EF6\u5DF2\u5907\u4EFD\u4E3A ${backupPath}\uFF09`);
|
|
58
68
|
};
|
|
59
|
-
const configurePackageJson = () => {
|
|
69
|
+
const configurePackageJson = (force) => {
|
|
60
70
|
const packageJsonPath = node_path.resolve(cwd, "package.json");
|
|
61
71
|
if (!node_fs.existsSync(packageJsonPath)) throw new Error(`\u5F53\u524D\u76EE\u5F55\u4E0D\u5B58\u5728 package.json\uFF1A${cwd}`);
|
|
62
|
-
const
|
|
72
|
+
const packageJsonContent = node_fs.readFileSync(packageJsonPath, "utf8");
|
|
73
|
+
const packageJson = JSON.parse(packageJsonContent);
|
|
63
74
|
packageJson.scripts ??= {};
|
|
75
|
+
let shouldBackup = false;
|
|
64
76
|
for (const [name, command2] of Object.entries(scripts)) {
|
|
65
77
|
const current = packageJson.scripts[name];
|
|
66
|
-
if (!current || current === command2) {
|
|
78
|
+
if (!current || current === command2 || force) {
|
|
79
|
+
if (force && current && current !== command2) shouldBackup = true;
|
|
67
80
|
packageJson.scripts[name] = command2;
|
|
68
81
|
} else {
|
|
69
|
-
console.warn(`\u4FDD\u7559 scripts.${name}\uFF1A\u5DF2\u5B58\u5728\u81EA\u5B9A\u4E49\u547D\u4EE4`);
|
|
82
|
+
console.warn(`\u4FDD\u7559 scripts.${name}\uFF1A\u5DF2\u5B58\u5728\u81EA\u5B9A\u4E49\u547D\u4EE4\uFF0C\u53EF\u4F7F\u7528 init --force \u5F3A\u5236\u8986\u76D6`);
|
|
70
83
|
}
|
|
71
84
|
}
|
|
85
|
+
if (shouldBackup) {
|
|
86
|
+
const backupPath = backupFile(packageJsonPath);
|
|
87
|
+
console.log(`\u5907\u4EFD package.json \u4E3A ${backupPath}`);
|
|
88
|
+
}
|
|
72
89
|
node_fs.writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}
|
|
73
90
|
`, "utf8");
|
|
74
91
|
console.log("\u66F4\u65B0 package.json scripts");
|
|
@@ -90,16 +107,18 @@ const configurePreCommit = () => {
|
|
|
90
107
|
`, { encoding: "utf8", mode: 493 });
|
|
91
108
|
console.log("\u66F4\u65B0 .husky/pre-commit");
|
|
92
109
|
};
|
|
93
|
-
const init = () => {
|
|
94
|
-
|
|
95
|
-
|
|
110
|
+
const init = (args2) => {
|
|
111
|
+
const force = args2.includes("--force");
|
|
112
|
+
configurePackageJson(force);
|
|
113
|
+
for (const [filePath, content] of Object.entries(generatedFiles)) writeConfigFile(filePath, content, force);
|
|
96
114
|
configurePreCommit();
|
|
97
|
-
console.log(
|
|
115
|
+
console.log(`
|
|
116
|
+
\u524D\u7AEF\u4EE3\u7801\u7EDF\u4E00\u89C4\u8303\u5DF2${force ? "\u5F3A\u5236\u8986\u76D6\u5E76" : ""}\u63A5\u5165\u3002`);
|
|
98
117
|
};
|
|
99
118
|
const [command = "init", ...args] = process.argv.slice(2);
|
|
100
119
|
switch (command) {
|
|
101
120
|
case "init":
|
|
102
|
-
init();
|
|
121
|
+
init(args);
|
|
103
122
|
break;
|
|
104
123
|
case "prepare":
|
|
105
124
|
prepareHusky();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { execFileSync } from 'node:child_process';
|
|
3
|
-
import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'node:fs';
|
|
3
|
+
import { existsSync, readFileSync, writeFileSync, mkdirSync, copyFileSync } from 'node:fs';
|
|
4
4
|
import { createRequire } from 'node:module';
|
|
5
5
|
import { resolve } from 'node:path';
|
|
6
6
|
import husky from 'husky';
|
|
@@ -38,30 +38,47 @@ const runPackageBin = (packageName, binPath, args2) => {
|
|
|
38
38
|
const executablePath = resolve(packageJsonPath, "..", binPath);
|
|
39
39
|
execFileSync(process.execPath, [executablePath, ...args2], { cwd, stdio: "inherit" });
|
|
40
40
|
};
|
|
41
|
-
const
|
|
41
|
+
const backupFile = (filePath) => {
|
|
42
|
+
const backupPath = `${filePath}.sybz-code-standard.bak`;
|
|
43
|
+
copyFileSync(filePath, backupPath);
|
|
44
|
+
return backupPath;
|
|
45
|
+
};
|
|
46
|
+
const writeConfigFile = (relativePath, content, force) => {
|
|
42
47
|
const filePath = resolve(cwd, relativePath);
|
|
43
48
|
if (!existsSync(filePath)) {
|
|
44
49
|
writeFileSync(filePath, content, "utf8");
|
|
45
50
|
console.log(`\u521B\u5EFA ${relativePath}`);
|
|
46
51
|
return;
|
|
47
52
|
}
|
|
48
|
-
if (readFileSync(filePath, "utf8")
|
|
49
|
-
|
|
53
|
+
if (readFileSync(filePath, "utf8") === content) return;
|
|
54
|
+
if (!force) {
|
|
55
|
+
console.warn(`\u8DF3\u8FC7 ${relativePath}\uFF1A\u5DF2\u5B58\u5728\u81EA\u5B9A\u4E49\u5185\u5BB9\uFF0C\u53EF\u4F7F\u7528 init --force \u5F3A\u5236\u8986\u76D6`);
|
|
56
|
+
return;
|
|
50
57
|
}
|
|
58
|
+
const backupPath = backupFile(filePath);
|
|
59
|
+
writeFileSync(filePath, content, "utf8");
|
|
60
|
+
console.log(`\u8986\u76D6 ${relativePath}\uFF08\u539F\u6587\u4EF6\u5DF2\u5907\u4EFD\u4E3A ${backupPath}\uFF09`);
|
|
51
61
|
};
|
|
52
|
-
const configurePackageJson = () => {
|
|
62
|
+
const configurePackageJson = (force) => {
|
|
53
63
|
const packageJsonPath = resolve(cwd, "package.json");
|
|
54
64
|
if (!existsSync(packageJsonPath)) throw new Error(`\u5F53\u524D\u76EE\u5F55\u4E0D\u5B58\u5728 package.json\uFF1A${cwd}`);
|
|
55
|
-
const
|
|
65
|
+
const packageJsonContent = readFileSync(packageJsonPath, "utf8");
|
|
66
|
+
const packageJson = JSON.parse(packageJsonContent);
|
|
56
67
|
packageJson.scripts ??= {};
|
|
68
|
+
let shouldBackup = false;
|
|
57
69
|
for (const [name, command2] of Object.entries(scripts)) {
|
|
58
70
|
const current = packageJson.scripts[name];
|
|
59
|
-
if (!current || current === command2) {
|
|
71
|
+
if (!current || current === command2 || force) {
|
|
72
|
+
if (force && current && current !== command2) shouldBackup = true;
|
|
60
73
|
packageJson.scripts[name] = command2;
|
|
61
74
|
} else {
|
|
62
|
-
console.warn(`\u4FDD\u7559 scripts.${name}\uFF1A\u5DF2\u5B58\u5728\u81EA\u5B9A\u4E49\u547D\u4EE4`);
|
|
75
|
+
console.warn(`\u4FDD\u7559 scripts.${name}\uFF1A\u5DF2\u5B58\u5728\u81EA\u5B9A\u4E49\u547D\u4EE4\uFF0C\u53EF\u4F7F\u7528 init --force \u5F3A\u5236\u8986\u76D6`);
|
|
63
76
|
}
|
|
64
77
|
}
|
|
78
|
+
if (shouldBackup) {
|
|
79
|
+
const backupPath = backupFile(packageJsonPath);
|
|
80
|
+
console.log(`\u5907\u4EFD package.json \u4E3A ${backupPath}`);
|
|
81
|
+
}
|
|
65
82
|
writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}
|
|
66
83
|
`, "utf8");
|
|
67
84
|
console.log("\u66F4\u65B0 package.json scripts");
|
|
@@ -83,16 +100,18 @@ const configurePreCommit = () => {
|
|
|
83
100
|
`, { encoding: "utf8", mode: 493 });
|
|
84
101
|
console.log("\u66F4\u65B0 .husky/pre-commit");
|
|
85
102
|
};
|
|
86
|
-
const init = () => {
|
|
87
|
-
|
|
88
|
-
|
|
103
|
+
const init = (args2) => {
|
|
104
|
+
const force = args2.includes("--force");
|
|
105
|
+
configurePackageJson(force);
|
|
106
|
+
for (const [filePath, content] of Object.entries(generatedFiles)) writeConfigFile(filePath, content, force);
|
|
89
107
|
configurePreCommit();
|
|
90
|
-
console.log(
|
|
108
|
+
console.log(`
|
|
109
|
+
\u524D\u7AEF\u4EE3\u7801\u7EDF\u4E00\u89C4\u8303\u5DF2${force ? "\u5F3A\u5236\u8986\u76D6\u5E76" : ""}\u63A5\u5165\u3002`);
|
|
91
110
|
};
|
|
92
111
|
const [command = "init", ...args] = process.argv.slice(2);
|
|
93
112
|
switch (command) {
|
|
94
113
|
case "init":
|
|
95
|
-
init();
|
|
114
|
+
init(args);
|
|
96
115
|
break;
|
|
97
116
|
case "prepare":
|
|
98
117
|
prepareHusky();
|
package/dist/theme.cjs
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const SYBZ_THEME_PREFIX = {
|
|
4
|
+
chenghua: "--s-ch-",
|
|
5
|
+
shijingshan: "--s-sjs-",
|
|
6
|
+
sybz: "--s-sybz-",
|
|
7
|
+
// 鼓楼是石景山布局主题的换色预设,共用组件结构和 token 前缀。
|
|
8
|
+
gulou: "--s-sjs-"
|
|
9
|
+
};
|
|
10
|
+
const isSybzTheme = (theme) => typeof theme === "string" && Object.prototype.hasOwnProperty.call(SYBZ_THEME_PREFIX, theme);
|
|
11
|
+
function resolveSybzComponentTheme(theme) {
|
|
12
|
+
return theme === "gulou" ? "shijingshan" : theme;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
exports.SYBZ_THEME_PREFIX = SYBZ_THEME_PREFIX;
|
|
16
|
+
exports.isSybzTheme = isSybzTheme;
|
|
17
|
+
exports.resolveSybzComponentTheme = resolveSybzComponentTheme;
|
package/dist/theme.d.cts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** 内置主题注册表:新增主题名称和颜色前缀只在这里维护。 */
|
|
2
|
+
declare const SYBZ_THEME_PREFIX: {
|
|
3
|
+
readonly chenghua: "--s-ch-";
|
|
4
|
+
readonly shijingshan: "--s-sjs-";
|
|
5
|
+
readonly sybz: "--s-sybz-";
|
|
6
|
+
readonly gulou: "--s-sjs-";
|
|
7
|
+
};
|
|
8
|
+
type SybzThemeName = keyof typeof SYBZ_THEME_PREFIX;
|
|
9
|
+
type SybzComponentTheme = 'default' | SybzThemeName;
|
|
10
|
+
declare const isSybzTheme: (theme: unknown) => theme is "chenghua" | "shijingshan" | "sybz" | "gulou";
|
|
11
|
+
/** 颜色预设对应的基础组件主题。新增同结构换色主题时只需在这里登记。 */
|
|
12
|
+
declare function resolveSybzComponentTheme(theme: SybzComponentTheme): SybzComponentTheme;
|
|
13
|
+
declare function resolveSybzComponentTheme(theme: unknown): unknown;
|
|
14
|
+
|
|
15
|
+
export { SYBZ_THEME_PREFIX, isSybzTheme, resolveSybzComponentTheme };
|
|
16
|
+
export type { SybzComponentTheme, SybzThemeName };
|
package/dist/theme.d.mts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** 内置主题注册表:新增主题名称和颜色前缀只在这里维护。 */
|
|
2
|
+
declare const SYBZ_THEME_PREFIX: {
|
|
3
|
+
readonly chenghua: "--s-ch-";
|
|
4
|
+
readonly shijingshan: "--s-sjs-";
|
|
5
|
+
readonly sybz: "--s-sybz-";
|
|
6
|
+
readonly gulou: "--s-sjs-";
|
|
7
|
+
};
|
|
8
|
+
type SybzThemeName = keyof typeof SYBZ_THEME_PREFIX;
|
|
9
|
+
type SybzComponentTheme = 'default' | SybzThemeName;
|
|
10
|
+
declare const isSybzTheme: (theme: unknown) => theme is "chenghua" | "shijingshan" | "sybz" | "gulou";
|
|
11
|
+
/** 颜色预设对应的基础组件主题。新增同结构换色主题时只需在这里登记。 */
|
|
12
|
+
declare function resolveSybzComponentTheme(theme: SybzComponentTheme): SybzComponentTheme;
|
|
13
|
+
declare function resolveSybzComponentTheme(theme: unknown): unknown;
|
|
14
|
+
|
|
15
|
+
export { SYBZ_THEME_PREFIX, isSybzTheme, resolveSybzComponentTheme };
|
|
16
|
+
export type { SybzComponentTheme, SybzThemeName };
|
package/dist/theme.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** 内置主题注册表:新增主题名称和颜色前缀只在这里维护。 */
|
|
2
|
+
declare const SYBZ_THEME_PREFIX: {
|
|
3
|
+
readonly chenghua: "--s-ch-";
|
|
4
|
+
readonly shijingshan: "--s-sjs-";
|
|
5
|
+
readonly sybz: "--s-sybz-";
|
|
6
|
+
readonly gulou: "--s-sjs-";
|
|
7
|
+
};
|
|
8
|
+
type SybzThemeName = keyof typeof SYBZ_THEME_PREFIX;
|
|
9
|
+
type SybzComponentTheme = 'default' | SybzThemeName;
|
|
10
|
+
declare const isSybzTheme: (theme: unknown) => theme is "chenghua" | "shijingshan" | "sybz" | "gulou";
|
|
11
|
+
/** 颜色预设对应的基础组件主题。新增同结构换色主题时只需在这里登记。 */
|
|
12
|
+
declare function resolveSybzComponentTheme(theme: SybzComponentTheme): SybzComponentTheme;
|
|
13
|
+
declare function resolveSybzComponentTheme(theme: unknown): unknown;
|
|
14
|
+
|
|
15
|
+
export { SYBZ_THEME_PREFIX, isSybzTheme, resolveSybzComponentTheme };
|
|
16
|
+
export type { SybzComponentTheme, SybzThemeName };
|
package/dist/theme.mjs
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const SYBZ_THEME_PREFIX = {
|
|
2
|
+
chenghua: "--s-ch-",
|
|
3
|
+
shijingshan: "--s-sjs-",
|
|
4
|
+
sybz: "--s-sybz-",
|
|
5
|
+
// 鼓楼是石景山布局主题的换色预设,共用组件结构和 token 前缀。
|
|
6
|
+
gulou: "--s-sjs-"
|
|
7
|
+
};
|
|
8
|
+
const isSybzTheme = (theme) => typeof theme === "string" && Object.prototype.hasOwnProperty.call(SYBZ_THEME_PREFIX, theme);
|
|
9
|
+
function resolveSybzComponentTheme(theme) {
|
|
10
|
+
return theme === "gulou" ? "shijingshan" : theme;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { SYBZ_THEME_PREFIX, isSybzTheme, resolveSybzComponentTheme };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sybz-components/utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.13",
|
|
4
4
|
"description": "utils of sybz-components",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -54,6 +54,7 @@
|
|
|
54
54
|
},
|
|
55
55
|
"author": "",
|
|
56
56
|
"dependencies": {
|
|
57
|
+
"axios": "^1.19.0",
|
|
57
58
|
"@eslint/js": "9.39.4",
|
|
58
59
|
"@tailwindcss/vite": "^4.3.3",
|
|
59
60
|
"@typescript-eslint/eslint-plugin": "8.62.0",
|