my-uniapp-tools 1.0.13 → 1.0.15
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/README.md +688 -477
- package/dist/index.d.ts +1 -0
- package/dist/my-uniapp-tools.cjs.js +1 -1780
- package/dist/my-uniapp-tools.esm.js +1 -1732
- package/dist/system/index.d.ts +21 -0
- package/dist/upload/index.d.ts +153 -0
- package/package.json +76 -72
- package/dist/core/errorHandler.d.ts +0 -44
- package/dist/core/performance.d.ts +0 -42
- package/dist/my-uniapp-tools.cjs.js.map +0 -1
- package/dist/my-uniapp-tools.esm.js.map +0 -1
package/dist/system/index.d.ts
CHANGED
|
@@ -65,3 +65,24 @@ export declare const getTopNavBarHeight: () => {
|
|
|
65
65
|
statusBarHeight: number;
|
|
66
66
|
navHeight: number;
|
|
67
67
|
};
|
|
68
|
+
/**
|
|
69
|
+
* 修改浏览器标题
|
|
70
|
+
* @param title 新的页面标题
|
|
71
|
+
* @description 动态修改浏览器标签页显示的标题,仅在H5/Web平台有效
|
|
72
|
+
* @example
|
|
73
|
+
* // 修改页面标题
|
|
74
|
+
* setPageTitle('新的页面标题')
|
|
75
|
+
*/
|
|
76
|
+
export declare const setPageTitle: (title: string) => boolean | null;
|
|
77
|
+
/**
|
|
78
|
+
* 修改浏览器图标(favicon)
|
|
79
|
+
* @param iconUrl 新的图标URL地址
|
|
80
|
+
* @param iconType 图标类型,默认为 'image/x-icon'
|
|
81
|
+
* @description 动态修改浏览器标签页显示的图标,仅在H5/Web平台有效
|
|
82
|
+
* @example
|
|
83
|
+
* // 修改页面图标
|
|
84
|
+
* setPageIcon('https://example.com/new-icon.ico')
|
|
85
|
+
* // 或使用PNG格式
|
|
86
|
+
* setPageIcon('https://example.com/new-icon.png', 'image/png')
|
|
87
|
+
*/
|
|
88
|
+
export declare const setPageIcon: (iconUrl: string, iconType?: string) => boolean | null;
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 文件上传相关工具函数
|
|
3
|
+
* 支持微信小程序、支付宝小程序、H5多端兼容
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* 上传配置接口
|
|
7
|
+
*/
|
|
8
|
+
export interface UploadConfig {
|
|
9
|
+
/** 上传服务器地址 */
|
|
10
|
+
url: string;
|
|
11
|
+
/** 文件对应的 key,开发者在服务端可以通过这个 key 获取文件的二进制内容 */
|
|
12
|
+
name?: string;
|
|
13
|
+
/** HTTP 请求中其他额外的 form data */
|
|
14
|
+
formData?: Record<string, any>;
|
|
15
|
+
/** HTTP 请求 Header,Header 中不能设置 Referer */
|
|
16
|
+
header?: Record<string, string>;
|
|
17
|
+
/** 文件大小限制(MB) */
|
|
18
|
+
maxSize?: number;
|
|
19
|
+
/** 允许的文件类型 */
|
|
20
|
+
allowedTypes?: string[];
|
|
21
|
+
/** 是否显示提示信息 */
|
|
22
|
+
showToast?: boolean;
|
|
23
|
+
/** 超时时间(ms) */
|
|
24
|
+
timeout?: number;
|
|
25
|
+
/** 成功提示信息 */
|
|
26
|
+
successMessage?: string;
|
|
27
|
+
/** 失败提示信息 */
|
|
28
|
+
failMessage?: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* 文件选择类型
|
|
32
|
+
*/
|
|
33
|
+
export type FileSelectType = 'image' | 'messagefile' | 'local';
|
|
34
|
+
/**
|
|
35
|
+
* 选择文件配置接口
|
|
36
|
+
*/
|
|
37
|
+
export interface ChooseFileConfig {
|
|
38
|
+
/** 文件选择类型 */
|
|
39
|
+
type?: FileSelectType;
|
|
40
|
+
/** 最多可以选择的文件数量 */
|
|
41
|
+
count?: number;
|
|
42
|
+
/** 所选的图片的尺寸(仅image类型有效) */
|
|
43
|
+
sizeType?: ('original' | 'compressed')[];
|
|
44
|
+
/** 选择图片的来源(仅image类型有效) */
|
|
45
|
+
sourceType?: ('album' | 'camera')[];
|
|
46
|
+
/** 文件类型限制(仅local类型有效) */
|
|
47
|
+
extension?: string[];
|
|
48
|
+
/** 文件大小限制(MB) */
|
|
49
|
+
maxSize?: number;
|
|
50
|
+
/** 是否显示提示信息 */
|
|
51
|
+
showToast?: boolean;
|
|
52
|
+
/** 失败提示信息 */
|
|
53
|
+
failMessage?: string;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* 选择图片配置接口(向后兼容)
|
|
57
|
+
*/
|
|
58
|
+
export interface ChooseImageConfig extends Omit<ChooseFileConfig, 'type' | 'extension'> {
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* 上传结果接口
|
|
62
|
+
*/
|
|
63
|
+
export interface UploadResult {
|
|
64
|
+
/** 是否成功 */
|
|
65
|
+
success: boolean;
|
|
66
|
+
/** 服务器返回的数据 */
|
|
67
|
+
data?: any;
|
|
68
|
+
/** 提示信息 */
|
|
69
|
+
message?: string;
|
|
70
|
+
/** 本地临时文件路径 */
|
|
71
|
+
tempFilePath?: string;
|
|
72
|
+
/** HTTP 状态码 */
|
|
73
|
+
statusCode?: number;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* 选择文件结果接口
|
|
77
|
+
*/
|
|
78
|
+
export interface ChooseFileResult {
|
|
79
|
+
/** 是否成功 */
|
|
80
|
+
success: boolean;
|
|
81
|
+
/** 临时文件路径数组 */
|
|
82
|
+
tempFilePaths?: string[];
|
|
83
|
+
/** 临时文件对象数组 */
|
|
84
|
+
tempFiles?: Array<{
|
|
85
|
+
path: string;
|
|
86
|
+
size: number;
|
|
87
|
+
}>;
|
|
88
|
+
/** 提示信息 */
|
|
89
|
+
message?: string;
|
|
90
|
+
/** 文件选择类型 */
|
|
91
|
+
type: FileSelectType;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* 选择图片结果接口(向后兼容)
|
|
95
|
+
*/
|
|
96
|
+
export interface ChooseImageResult extends Omit<ChooseFileResult, 'type'> {
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* 上传进度回调函数类型
|
|
100
|
+
*/
|
|
101
|
+
export type ProgressCallback = (progress: {
|
|
102
|
+
/** 上传进度百分比 */
|
|
103
|
+
progress: number;
|
|
104
|
+
/** 已经上传的数据长度 */
|
|
105
|
+
totalBytesSent: number;
|
|
106
|
+
/** 预期需要上传的数据总长度 */
|
|
107
|
+
totalBytesExpectedToSend: number;
|
|
108
|
+
}) => void;
|
|
109
|
+
export declare function chooseFile(config?: ChooseFileConfig): Promise<ChooseFileResult>;
|
|
110
|
+
/**
|
|
111
|
+
* 选择图片(向后兼容)
|
|
112
|
+
* @param config 选择配置
|
|
113
|
+
* @returns Promise<ChooseImageResult> 选择结果
|
|
114
|
+
*/
|
|
115
|
+
export declare function chooseImage(config?: ChooseImageConfig): Promise<ChooseImageResult>;
|
|
116
|
+
/**
|
|
117
|
+
* 上传文件
|
|
118
|
+
* @param filePath 文件路径
|
|
119
|
+
* @param config 上传配置
|
|
120
|
+
* @param onProgress 进度回调
|
|
121
|
+
* @returns Promise<UploadResult> 上传结果
|
|
122
|
+
*/
|
|
123
|
+
export declare function uploadFile(filePath: string, config: UploadConfig, onProgress?: ProgressCallback): Promise<UploadResult>;
|
|
124
|
+
/**
|
|
125
|
+
* 选择并上传文件(一体化功能)
|
|
126
|
+
* @param config 上传配置
|
|
127
|
+
* @param chooseConfig 选择文件配置
|
|
128
|
+
* @param onProgress 进度回调
|
|
129
|
+
* @returns Promise<UploadResult[]> 上传结果数组
|
|
130
|
+
*/
|
|
131
|
+
export declare function chooseAndUploadFile(config: UploadConfig, chooseConfig?: ChooseFileConfig, onProgress?: ProgressCallback): Promise<UploadResult[]>;
|
|
132
|
+
/**
|
|
133
|
+
* 选择并上传图片(向后兼容)
|
|
134
|
+
* @param config 上传配置
|
|
135
|
+
* @param chooseConfig 选择图片配置
|
|
136
|
+
* @param onProgress 进度回调
|
|
137
|
+
* @returns Promise<UploadResult[]> 上传结果数组
|
|
138
|
+
*/
|
|
139
|
+
export declare function chooseAndUploadImage(config: UploadConfig, chooseConfig?: ChooseImageConfig, onProgress?: ProgressCallback): Promise<UploadResult[]>;
|
|
140
|
+
/**
|
|
141
|
+
* 检查是否支持文件上传
|
|
142
|
+
* @returns boolean 是否支持
|
|
143
|
+
*/
|
|
144
|
+
export declare function isUploadSupported(): boolean;
|
|
145
|
+
/**
|
|
146
|
+
* 获取文件信息
|
|
147
|
+
* @param filePath 文件路径
|
|
148
|
+
* @returns Promise<{size: number, type?: string}> 文件信息
|
|
149
|
+
*/
|
|
150
|
+
export declare function getFileInfo(filePath: string): Promise<{
|
|
151
|
+
size: number;
|
|
152
|
+
digest?: string;
|
|
153
|
+
} | null>;
|
package/package.json
CHANGED
|
@@ -1,72 +1,76 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "my-uniapp-tools",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"type": "module",
|
|
5
|
-
"description": "一个功能强大、性能优化的 uni-app 开发工具库,提供剪贴板、本地存储、导航、系统信息等常用功能",
|
|
6
|
-
"main": "dist/my-uniapp-tools.cjs.js",
|
|
7
|
-
"module": "dist/my-uniapp-tools.esm.js",
|
|
8
|
-
"types": "dist/index.d.ts",
|
|
9
|
-
"files": [
|
|
10
|
-
"dist",
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
"url": "https://github.com/yourusername/my-uniapp-tools
|
|
45
|
-
},
|
|
46
|
-
"
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
},
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
},
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
"@
|
|
61
|
-
"@
|
|
62
|
-
"@
|
|
63
|
-
"@
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"vuepress": "^2.0.0-rc.24"
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
"
|
|
71
|
-
|
|
72
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "my-uniapp-tools",
|
|
3
|
+
"version": "1.0.15",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "一个功能强大、性能优化的 uni-app 开发工具库,提供剪贴板、本地存储、导航、系统信息等常用功能",
|
|
6
|
+
"main": "dist/my-uniapp-tools.cjs.js",
|
|
7
|
+
"module": "dist/my-uniapp-tools.esm.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist/*.js",
|
|
11
|
+
"dist/*.d.ts",
|
|
12
|
+
"dist/*/index.d.ts",
|
|
13
|
+
"README.md"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "rollup -c && tsc --declaration --emitDeclarationOnly --outDir dist",
|
|
17
|
+
"build:prod": "NODE_ENV=production rollup -c && tsc --declaration --emitDeclarationOnly --outDir dist",
|
|
18
|
+
"prepublishOnly": "npm run build:prod",
|
|
19
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
20
|
+
"dev": "node src/index.js",
|
|
21
|
+
"docs:dev": "vuepress dev docs",
|
|
22
|
+
"docs:build": "vuepress build docs"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"uniapp",
|
|
26
|
+
"uni-app",
|
|
27
|
+
"utils",
|
|
28
|
+
"tools",
|
|
29
|
+
"clipboard",
|
|
30
|
+
"storage",
|
|
31
|
+
"navigation",
|
|
32
|
+
"system",
|
|
33
|
+
"performance",
|
|
34
|
+
"typescript",
|
|
35
|
+
"微信小程序",
|
|
36
|
+
"支付宝小程序",
|
|
37
|
+
"H5",
|
|
38
|
+
"App"
|
|
39
|
+
],
|
|
40
|
+
"author": "Your Name <your.email@example.com>",
|
|
41
|
+
"license": "MIT",
|
|
42
|
+
"repository": {
|
|
43
|
+
"type": "git",
|
|
44
|
+
"url": "git+https://github.com/yourusername/my-uniapp-tools.git"
|
|
45
|
+
},
|
|
46
|
+
"bugs": {
|
|
47
|
+
"url": "https://github.com/yourusername/my-uniapp-tools/issues"
|
|
48
|
+
},
|
|
49
|
+
"homepage": "https://github.com/yourusername/my-uniapp-tools#readme",
|
|
50
|
+
"engines": {
|
|
51
|
+
"node": ">=14.0.0"
|
|
52
|
+
},
|
|
53
|
+
"peerDependencies": {
|
|
54
|
+
"@dcloudio/types": "^3.0.0"
|
|
55
|
+
},
|
|
56
|
+
"dependencies": {
|
|
57
|
+
"tslib": "^2.8.1"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@dcloudio/types": "^3.4.14",
|
|
61
|
+
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
62
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
63
|
+
"@rollup/plugin-typescript": "^12.1.4",
|
|
64
|
+
"@vuepress/bundler-vite": "^2.0.0-rc.24",
|
|
65
|
+
"@vuepress/client": "^2.0.0-rc.24",
|
|
66
|
+
"@vuepress/theme-default": "^2.0.0-rc.112",
|
|
67
|
+
"@vuepress/utils": "^2.0.0-rc.24",
|
|
68
|
+
"rollup": "^4.45.1",
|
|
69
|
+
"sass-embedded": "^1.89.2",
|
|
70
|
+
"typescript": "^5.8.3",
|
|
71
|
+
"vuepress": "^2.0.0-rc.24"
|
|
72
|
+
},
|
|
73
|
+
"directories": {
|
|
74
|
+
"example": "examples"
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 统一错误处理机制
|
|
3
|
-
*/
|
|
4
|
-
export interface ErrorInfo {
|
|
5
|
-
code: string;
|
|
6
|
-
message: string;
|
|
7
|
-
module: string;
|
|
8
|
-
timestamp: number;
|
|
9
|
-
stack?: string;
|
|
10
|
-
}
|
|
11
|
-
export declare class UniAppToolsError extends Error {
|
|
12
|
-
code: string;
|
|
13
|
-
module: string;
|
|
14
|
-
timestamp: number;
|
|
15
|
-
constructor(code: string, message: string, module: string);
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* 全局错误处理器
|
|
19
|
-
*/
|
|
20
|
-
export declare class ErrorHandler {
|
|
21
|
-
private static instance;
|
|
22
|
-
private errorCallbacks;
|
|
23
|
-
static getInstance(): ErrorHandler;
|
|
24
|
-
/**
|
|
25
|
-
* 注册错误回调
|
|
26
|
-
*/
|
|
27
|
-
onError(callback: (error: ErrorInfo) => void): void;
|
|
28
|
-
/**
|
|
29
|
-
* 处理错误
|
|
30
|
-
*/
|
|
31
|
-
handleError(error: Error | UniAppToolsError, module: string): void;
|
|
32
|
-
/**
|
|
33
|
-
* 创建模块专用的错误处理函数
|
|
34
|
-
*/
|
|
35
|
-
createModuleErrorHandler(moduleName: string): (code: string, message: string, originalError?: Error) => UniAppToolsError;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* 异步操作包装器,统一错误处理
|
|
39
|
-
*/
|
|
40
|
-
export declare function safeAsync<T>(operation: () => Promise<T>, moduleName: string, errorCode?: string): Promise<T | null>;
|
|
41
|
-
/**
|
|
42
|
-
* 同步操作包装器,统一错误处理
|
|
43
|
-
*/
|
|
44
|
-
export declare function safeSync<T>(operation: () => T, moduleName: string, errorCode?: string, defaultValue?: T | null): T | null;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 性能监控工具
|
|
3
|
-
*/
|
|
4
|
-
export interface PerformanceMetric {
|
|
5
|
-
name: string;
|
|
6
|
-
startTime: number;
|
|
7
|
-
endTime?: number;
|
|
8
|
-
duration?: number;
|
|
9
|
-
module: string;
|
|
10
|
-
metadata?: Record<string, any>;
|
|
11
|
-
}
|
|
12
|
-
export declare class PerformanceMonitor {
|
|
13
|
-
private static instance;
|
|
14
|
-
private metrics;
|
|
15
|
-
private completedMetrics;
|
|
16
|
-
private maxStoredMetrics;
|
|
17
|
-
static getInstance(): PerformanceMonitor;
|
|
18
|
-
/**
|
|
19
|
-
* 开始性能测量
|
|
20
|
-
*/
|
|
21
|
-
start(name: string, module: string, metadata?: Record<string, any>): void;
|
|
22
|
-
/**
|
|
23
|
-
* 结束性能测量
|
|
24
|
-
*/
|
|
25
|
-
end(name: string): PerformanceMetric | null;
|
|
26
|
-
/**
|
|
27
|
-
* 获取性能报告
|
|
28
|
-
*/
|
|
29
|
-
getReport(): {
|
|
30
|
-
byModule: Record<string, PerformanceMetric[]>;
|
|
31
|
-
slowest: PerformanceMetric[];
|
|
32
|
-
average: Record<string, number>;
|
|
33
|
-
};
|
|
34
|
-
/**
|
|
35
|
-
* 清除性能记录
|
|
36
|
-
*/
|
|
37
|
-
clear(): void;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* 性能装饰器
|
|
41
|
-
*/
|
|
42
|
-
export declare function measurePerformance(moduleName: string): (target: any, propertyName: string, descriptor: PropertyDescriptor) => void;
|