@haluo/util 2.0.23 → 2.0.24
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/index.d.ts +3 -1
- package/dist/index.js +33 -61
- package/dist/modules/cookie/index.js +18 -24
- package/dist/modules/date/index.js +49 -56
- package/dist/modules/dom/index.js +16 -23
- package/dist/modules/filter/index.js +15 -25
- package/dist/modules/format/index.js +6 -12
- package/dist/modules/match/index.js +6 -10
- package/dist/modules/monitor/index.js +7 -14
- package/dist/modules/monitor/lib/jsError.js +39 -35
- package/dist/modules/monitor/lib/timing.js +24 -28
- package/dist/modules/monitor/lib/xhr.js +26 -33
- package/dist/modules/monitor/utils/onload.js +1 -4
- package/dist/modules/monitor/utils/tracker.js +13 -27
- package/dist/modules/number/index.js +31 -35
- package/dist/modules/open-app/index.js +66 -61
- package/dist/modules/sentry/index.js +19 -27
- package/dist/modules/tools/index.d.ts +1 -1
- package/dist/modules/tools/index.js +158 -169
- package/dist/modules/upload/aliOss.d.ts +75 -124
- package/dist/modules/upload/aliOss.js +175 -357
- package/dist/modules/upload/index.d.ts +2 -14
- package/dist/modules/upload/index.js +2 -6
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/index.js +1 -2
- package/package.json +14 -3
- package/dist/modules/upload/aliOss copy.d.ts +0 -321
- package/dist/modules/upload/aliOss copy.js +0 -734
- package/dist/modules/upload/backup-aliOss.d.ts +0 -321
- package/dist/modules/upload/backup-aliOss.js +0 -734
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @file 阿里云OSS上传统一工具类
|
|
2
|
+
* @file 阿里云OSS上传统一工具类 v4
|
|
3
3
|
* @description 整合所有项目的aliOss业务逻辑,通过传参形式支持不同业务场景
|
|
4
4
|
* @Author: wanghui
|
|
5
5
|
* @createBy: @2025.11.17
|
|
6
6
|
*
|
|
7
|
-
* 文档:https://help.aliyun.com/document_detail/64041.html
|
|
8
|
-
*
|
|
9
7
|
* 使用示例:
|
|
10
8
|
* ```typescript
|
|
11
9
|
* import { createAliOssUploader } from '@haluo/util'
|
|
@@ -13,12 +11,9 @@
|
|
|
13
11
|
* // 创建上传实例,传入业务相关的API函数
|
|
14
12
|
* const ossUploader = createAliOssUploader({
|
|
15
13
|
* getSts: (params) => api.getSts(params),
|
|
16
|
-
* getAliyunSts: (params) => api.getAliyunSts(params),
|
|
17
14
|
* darkWaterUploadImage: (params) => api.darkWaterUploadImage(params),
|
|
18
15
|
* multiTransferImage: (params) => api.multiTransferImage(params),
|
|
19
|
-
* aliyunPersist: (params) => api.aliyunPersist(params),
|
|
20
16
|
* generatePrePresignedUrl: (params) => api.generatePrePresignedUrl(params),
|
|
21
|
-
* uploadConf: (params) => api.uploadConf(params),
|
|
22
17
|
* dateFormat: util.date.format, // 或 util.filter.format
|
|
23
18
|
* messageWarning: (msg) => window.$message.warning(msg)
|
|
24
19
|
* })
|
|
@@ -26,9 +21,9 @@
|
|
|
26
21
|
* // 图片上传
|
|
27
22
|
* ossUploader.ossUploadImage({
|
|
28
23
|
* file: file,
|
|
24
|
+
* businessType: 1500, // 业务类型 BusinessType
|
|
29
25
|
* imageType: 'official', // nowater、official、panoram、forum、avatar、square、carport
|
|
30
26
|
* quality: 0.7, // 压缩质量
|
|
31
|
-
* businessType: 1500, // 业务类型:0(无水印)、1(头像)、4(GIF)、6(视频)、8(UnProtect)、1000(文章)、1199(私有)、1299(加密)、1500(默认)
|
|
32
27
|
* batchTransfer: false, // 是否批量转换水印
|
|
33
28
|
* notCompress: false, // 是否不压缩
|
|
34
29
|
* idCard: false, // 是否身份证上传
|
|
@@ -40,10 +35,10 @@
|
|
|
40
35
|
* // 文件上传
|
|
41
36
|
* ossUploader.ossUploadFile({
|
|
42
37
|
* file: file,
|
|
38
|
+
* businessType: 1500, // 业务类型 BusinessType
|
|
43
39
|
* isVideo: false, // 是否视频
|
|
44
40
|
* isUnProtect: false, // 是否UnProtect
|
|
45
41
|
* isDocument: false, // 是否文档
|
|
46
|
-
* businessType: 1500,
|
|
47
42
|
* onProgress: (e) => console.log(e.percent),
|
|
48
43
|
* onSuccess: (val) => console.log(val),
|
|
49
44
|
* onError: (err) => console.error(err)
|
|
@@ -52,28 +47,67 @@
|
|
|
52
47
|
*/
|
|
53
48
|
/**
|
|
54
49
|
* 业务类型枚举
|
|
55
|
-
* 不同的businessType对应不同的OSS bucket和水印策略
|
|
56
50
|
*/
|
|
57
51
|
export declare enum BusinessType {
|
|
52
|
+
/** 客户端上传图片(跟用户相关) */
|
|
53
|
+
/** 隐私图片 */
|
|
58
54
|
CREDIT = 130541736,
|
|
55
|
+
/** 内容 */
|
|
59
56
|
CONTENT = 101300784,
|
|
57
|
+
/** 头像 */
|
|
60
58
|
AVATAR = 134539448,
|
|
59
|
+
/** 二手车 */
|
|
61
60
|
USED_CAR = 171978237,
|
|
61
|
+
/** 商城 */
|
|
62
62
|
MALL = 115259415,
|
|
63
|
+
/** 魔友圈 */
|
|
63
64
|
HOOP = 155669648,
|
|
65
|
+
/** 用户 */
|
|
64
66
|
USER = 170244368,
|
|
67
|
+
/** 骑行 */
|
|
65
68
|
CYCLING = 165103952,
|
|
69
|
+
/** 玩车 */
|
|
66
70
|
MOTORCYCLE = 151637735,
|
|
71
|
+
/** 租车 */
|
|
67
72
|
RENTALCAR = 149095014,
|
|
73
|
+
/** 经销商 */
|
|
68
74
|
SHOP = 172655993,
|
|
75
|
+
/** 财务 */
|
|
69
76
|
FINANCE = 188717541,
|
|
77
|
+
/** 反馈 */
|
|
70
78
|
FEEDBACK = 182411383,
|
|
79
|
+
/** 驾校 */
|
|
71
80
|
DRIVING_SCHOOL = 172137757,
|
|
81
|
+
/** 评论图片 */
|
|
72
82
|
REPLY = 195929698,
|
|
83
|
+
/** 厂家 */
|
|
73
84
|
FACTORY = 118733601,
|
|
85
|
+
/** 骑行数据 */
|
|
74
86
|
CYCLING_DATA = 148681294,
|
|
87
|
+
/** 动图 */
|
|
75
88
|
GIF = 191290831,
|
|
76
|
-
|
|
89
|
+
/** 其他(原则上不可以使用) */
|
|
90
|
+
OTHER = 100694193,
|
|
91
|
+
/** 运营文件(跟用户无关) */
|
|
92
|
+
/** apk */
|
|
93
|
+
APK = 154033062,
|
|
94
|
+
/** 证书 */
|
|
95
|
+
CERT = 142668067,
|
|
96
|
+
/** oss数据文件(xlxs等) */
|
|
97
|
+
OSSDATA = 105038102,
|
|
98
|
+
/** 数据(题库等) */
|
|
99
|
+
DB = 180241065,
|
|
100
|
+
/** PDF */
|
|
101
|
+
PDF = 198157532,
|
|
102
|
+
/** 视频 */
|
|
103
|
+
VIDEOOPS = 172023381,
|
|
104
|
+
/** 运营图片(跟用户无关) */
|
|
105
|
+
/** 商城运营图片 */
|
|
106
|
+
MALLOPS = 137563987,
|
|
107
|
+
/** 运营图片 */
|
|
108
|
+
OSSOPS = 157532694,
|
|
109
|
+
/** 车库运营图片 */
|
|
110
|
+
CARPORT = 137563987
|
|
77
111
|
}
|
|
78
112
|
/**
|
|
79
113
|
* bucket 图片类型后缀枚举
|
|
@@ -89,29 +123,15 @@ export declare const SuffixEnum: {
|
|
|
89
123
|
};
|
|
90
124
|
/** 图片类型 */
|
|
91
125
|
export type ImageType = keyof typeof SuffixEnum;
|
|
92
|
-
/**
|
|
93
|
-
* OSS客户端配置接口
|
|
94
|
-
*/
|
|
95
|
-
export interface OSSClientParams {
|
|
96
|
-
region?: string;
|
|
97
|
-
accessKeyId?: string;
|
|
98
|
-
accessKeySecret?: string;
|
|
99
|
-
stsToken?: string;
|
|
100
|
-
bucket?: string;
|
|
101
|
-
realmName?: string;
|
|
102
|
-
suffix?: string;
|
|
103
|
-
style?: string;
|
|
104
|
-
[key: string]: any;
|
|
105
|
-
}
|
|
106
126
|
/**
|
|
107
127
|
* 上传结果接口
|
|
108
128
|
*/
|
|
109
129
|
export interface UploadResult {
|
|
110
|
-
imgUrl
|
|
111
|
-
imgOrgUrl
|
|
130
|
+
imgUrl: string;
|
|
131
|
+
imgOrgUrl: string;
|
|
132
|
+
fileName: string;
|
|
133
|
+
name: string;
|
|
112
134
|
url?: string;
|
|
113
|
-
fileName?: string;
|
|
114
|
-
name?: string;
|
|
115
135
|
bucket?: string;
|
|
116
136
|
[key: string]: any;
|
|
117
137
|
}
|
|
@@ -120,7 +140,7 @@ export interface UploadResult {
|
|
|
120
140
|
*/
|
|
121
141
|
export interface UploadOption {
|
|
122
142
|
file: File;
|
|
123
|
-
businessType
|
|
143
|
+
businessType: BusinessType | number;
|
|
124
144
|
imageType?: ImageType | string;
|
|
125
145
|
quality?: number;
|
|
126
146
|
batchTransfer?: boolean;
|
|
@@ -155,11 +175,7 @@ export interface AliOssApiConfig {
|
|
|
155
175
|
businessType: BusinessType;
|
|
156
176
|
docType: string;
|
|
157
177
|
size?: string;
|
|
158
|
-
}) =>
|
|
159
|
-
/** 获取阿里云STS临时凭证 - 旧版非必需 */
|
|
160
|
-
getAliyunSts: (params: {
|
|
161
|
-
businessType: number;
|
|
162
|
-
}) => Promise<ApiResponse<OSSClientParams>>;
|
|
178
|
+
}) => any;
|
|
163
179
|
/** 暗水印上传接口 - 可选,用于carport类型 */
|
|
164
180
|
darkWaterUploadImage?: (params: {
|
|
165
181
|
file: File;
|
|
@@ -168,110 +184,64 @@ export interface AliOssApiConfig {
|
|
|
168
184
|
multiTransferImage?: (params: {
|
|
169
185
|
file: File;
|
|
170
186
|
}) => Promise<ApiResponse<string>>;
|
|
171
|
-
/** 阿里云持久化接口 - 可选,用于avatar类型 */
|
|
172
|
-
aliyunPersist?: (params: {
|
|
173
|
-
object: string;
|
|
174
|
-
businessType: number;
|
|
175
|
-
}) => Promise<ApiResponse<string>>;
|
|
176
187
|
/** 生成预签名URL接口 - 可选,用于idCard */
|
|
177
188
|
generatePrePresignedUrl?: (params: {
|
|
178
189
|
objectId: string;
|
|
179
190
|
expireMils: number;
|
|
180
191
|
}) => Promise<ApiResponse<string>>;
|
|
181
|
-
/** 上传配置接口 - 可选,用于document上传 */
|
|
182
|
-
uploadConf?: (businessType: number) => Promise<ApiResponse>;
|
|
183
192
|
/** 日期格式化函数 - 必需,支持 util.date.format 或 util.filter.format */
|
|
184
193
|
dateFormat: (date: Date, format: string) => string;
|
|
185
194
|
/** 消息提示函数 - 可选 */
|
|
186
195
|
messageWarning?: (msg: string) => void;
|
|
187
196
|
}
|
|
188
|
-
/**
|
|
189
|
-
* 生成随机字符串
|
|
190
|
-
* @param length 字符串长度
|
|
191
|
-
* @returns 随机字符串
|
|
192
|
-
*/
|
|
193
|
-
declare function randomString(length: number): string;
|
|
194
197
|
/**
|
|
195
198
|
* 阿里云OSS上传类
|
|
196
199
|
* 整合所有项目的aliOss业务逻辑,通过依赖注入实现业务API解耦
|
|
197
200
|
*/
|
|
198
201
|
export declare class AliOssClass {
|
|
199
202
|
private apiConfig;
|
|
200
|
-
private clientCache;
|
|
201
203
|
constructor(apiConfig: AliOssApiConfig);
|
|
204
|
+
/**
|
|
205
|
+
* 判断文件是否为图片(支持常见图片格式)
|
|
206
|
+
* @param {File} file - 上传的File对象
|
|
207
|
+
* @returns {boolean} 是否为图片
|
|
208
|
+
*/
|
|
209
|
+
isImageFile(file: File): boolean;
|
|
202
210
|
/**
|
|
203
211
|
* 通过V4签名上传
|
|
204
212
|
* @param file 上传的文件
|
|
205
213
|
* @param businessType 业务类型
|
|
206
214
|
* @param size 文件的尺寸
|
|
215
|
+
* @param resolve Promse
|
|
216
|
+
* @param reject Promse
|
|
207
217
|
* @returns 上传图片结果
|
|
208
218
|
*/
|
|
209
|
-
upload(
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
* 执行OSS上传
|
|
218
|
-
* @param client OSS客户端
|
|
219
|
-
* @param fileName 文件名
|
|
220
|
-
* @param file 文件对象
|
|
221
|
-
* @param year 年份
|
|
222
|
-
* @param mimeType MIME类型
|
|
223
|
-
* @param onProgress 进度回调
|
|
224
|
-
* @returns 上传结果
|
|
225
|
-
*/
|
|
226
|
-
private performOssUpload;
|
|
219
|
+
upload(params: {
|
|
220
|
+
file: any;
|
|
221
|
+
businessType: BusinessType;
|
|
222
|
+
size?: string;
|
|
223
|
+
resolve?: Function;
|
|
224
|
+
reject?: Function;
|
|
225
|
+
callbacks?: any;
|
|
226
|
+
}): Promise<{}>;
|
|
227
227
|
/**
|
|
228
228
|
* 预加载图片获取尺寸
|
|
229
229
|
* @param file 文件对象
|
|
230
230
|
* @returns 图片对象
|
|
231
231
|
*/
|
|
232
232
|
getImageInfo(file: File): Promise<HTMLImageElement>;
|
|
233
|
-
/**
|
|
234
|
-
* 生成文件名
|
|
235
|
-
* @param imageType 图片类型
|
|
236
|
-
* @param extension 文件扩展名
|
|
237
|
-
* @returns 文件名信息
|
|
238
|
-
*/
|
|
239
|
-
private generateFileName;
|
|
240
233
|
/**
|
|
241
234
|
* 检查图片是否为长图
|
|
242
|
-
* @param
|
|
243
|
-
* @param height 图片高度
|
|
235
|
+
* @param File 图片
|
|
244
236
|
* @returns 是否为长图
|
|
245
237
|
*/
|
|
246
238
|
private isLongImage;
|
|
247
|
-
/**
|
|
248
|
-
* 确定业务类型
|
|
249
|
-
* @param option 上传选项
|
|
250
|
-
* @param isGif 是否为GIF
|
|
251
|
-
* @returns 业务类型
|
|
252
|
-
*/
|
|
253
|
-
private determineBusinessType;
|
|
254
239
|
/**
|
|
255
240
|
* 加载图片并返回结果
|
|
256
241
|
* 用于标准的图片上传场景
|
|
257
242
|
* @param params 加载参数
|
|
258
243
|
*/
|
|
259
244
|
loadImage(params: {
|
|
260
|
-
url: string;
|
|
261
|
-
val: any;
|
|
262
|
-
suffix: string;
|
|
263
|
-
file: File;
|
|
264
|
-
option: UploadOption;
|
|
265
|
-
resolve: (value: any) => void;
|
|
266
|
-
reject: (reason?: any) => void;
|
|
267
|
-
isGif?: boolean;
|
|
268
|
-
}): void;
|
|
269
|
-
/**
|
|
270
|
-
* 加载图片并返回结果(新版)
|
|
271
|
-
* 用于avatar、idCard等特殊场景,返回格式不同
|
|
272
|
-
* @param params 加载参数
|
|
273
|
-
*/
|
|
274
|
-
loadImageNew(params: {
|
|
275
245
|
url: string;
|
|
276
246
|
val: any;
|
|
277
247
|
file: File;
|
|
@@ -294,29 +264,19 @@ export declare class AliOssClass {
|
|
|
294
264
|
*/
|
|
295
265
|
ossUploadFile: (option: UploadOption) => Promise<any>;
|
|
296
266
|
/**
|
|
297
|
-
*
|
|
298
|
-
*
|
|
267
|
+
* 纯图片上传 pureOssUploadImage
|
|
268
|
+
* 注释:图片上传,不压缩
|
|
299
269
|
* @param option 上传选项
|
|
300
270
|
* @returns Promise
|
|
301
271
|
*/
|
|
302
|
-
|
|
303
|
-
/**
|
|
304
|
-
* 生成随机字符串
|
|
305
|
-
* @param num 字符串长度
|
|
306
|
-
*/
|
|
307
|
-
randomString: typeof randomString;
|
|
272
|
+
pureOssUploadImage: (option: UploadOption) => Promise<any>;
|
|
308
273
|
/**
|
|
309
|
-
*
|
|
274
|
+
* 商品详情图片上传(不建议直接使用,请使用 pureOssUploadImage)
|
|
275
|
+
* 注释:图片上传,不压缩
|
|
276
|
+
* @param option 上传选项
|
|
277
|
+
* @returns Promise
|
|
310
278
|
*/
|
|
311
|
-
|
|
312
|
-
readonly nowater: "!nowater";
|
|
313
|
-
readonly official: "!official";
|
|
314
|
-
readonly panoram: "!panoram";
|
|
315
|
-
readonly forum: "!forum";
|
|
316
|
-
readonly avatar: "!avatar";
|
|
317
|
-
readonly square: "!square";
|
|
318
|
-
readonly carport: "!carport";
|
|
319
|
-
};
|
|
279
|
+
shopDetailUpdate: (option: UploadOption) => Promise<any>;
|
|
320
280
|
/**
|
|
321
281
|
* 业务类型枚举
|
|
322
282
|
*/
|
|
@@ -334,14 +294,5 @@ export declare function createAliOssUploader(apiConfig: AliOssApiConfig): AliOss
|
|
|
334
294
|
declare const _default: {
|
|
335
295
|
createAliOssUploader: typeof createAliOssUploader;
|
|
336
296
|
BusinessType: typeof BusinessType;
|
|
337
|
-
SuffixEnum: {
|
|
338
|
-
readonly nowater: "!nowater";
|
|
339
|
-
readonly official: "!official";
|
|
340
|
-
readonly panoram: "!panoram";
|
|
341
|
-
readonly forum: "!forum";
|
|
342
|
-
readonly avatar: "!avatar";
|
|
343
|
-
readonly square: "!square";
|
|
344
|
-
readonly carport: "!carport";
|
|
345
|
-
};
|
|
346
297
|
};
|
|
347
298
|
export default _default;
|