@haluo/util 2.0.1 → 2.0.2-0.1

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.
Files changed (61) hide show
  1. package/README.md +12 -1
  2. package/dist/index.d.ts +39 -0
  3. package/dist/index.js +74 -33
  4. package/dist/modules/cookie/index.d.ts +27 -0
  5. package/dist/modules/cookie/index.js +55 -54
  6. package/dist/modules/date/index.d.ts +52 -0
  7. package/dist/modules/date/index.js +192 -192
  8. package/dist/modules/dom/index.d.ts +28 -0
  9. package/dist/modules/dom/index.js +62 -62
  10. package/dist/modules/filter/index.d.ts +24 -0
  11. package/dist/modules/filter/index.js +48 -44
  12. package/dist/modules/format/index.d.ts +15 -0
  13. package/dist/modules/format/index.js +22 -21
  14. package/dist/modules/match/index.d.ts +12 -0
  15. package/dist/modules/match/index.js +31 -31
  16. package/dist/modules/monitor/index.d.ts +3 -0
  17. package/dist/modules/monitor/index.js +17 -17
  18. package/dist/modules/monitor/lib/jsError.d.ts +1 -0
  19. package/dist/modules/monitor/lib/jsError.js +53 -53
  20. package/dist/modules/monitor/lib/timing.d.ts +1 -0
  21. package/dist/modules/monitor/lib/timing.js +69 -69
  22. package/dist/modules/monitor/lib/xhr.d.ts +1 -0
  23. package/dist/modules/monitor/lib/xhr.js +48 -48
  24. package/dist/modules/monitor/utils/onload.d.ts +1 -0
  25. package/dist/modules/monitor/utils/onload.js +11 -11
  26. package/dist/modules/monitor/utils/tracker.d.ts +7 -0
  27. package/dist/modules/monitor/utils/tracker.js +63 -63
  28. package/dist/modules/number/index.d.ts +47 -0
  29. package/dist/modules/number/index.js +118 -102
  30. package/dist/modules/open-app/index.d.ts +84 -0
  31. package/dist/modules/open-app/index.js +239 -0
  32. package/dist/modules/sentry/index.d.ts +15 -0
  33. package/dist/modules/sentry/index.js +81 -81
  34. package/dist/modules/tools/index.d.ts +166 -0
  35. package/dist/modules/tools/index.js +393 -393
  36. package/dist/modules/upload/ALIOSS_EXAMPLE.d.ts +12 -0
  37. package/dist/modules/upload/ALIOSS_EXAMPLE.js +320 -0
  38. package/dist/modules/upload/aliOss.d.ts +324 -0
  39. package/dist/modules/upload/aliOss.js +838 -0
  40. package/dist/modules/upload/index.d.ts +51 -0
  41. package/dist/modules/upload/index.js +55 -0
  42. package/dist/tsconfig.tsbuildinfo +1 -1
  43. package/dist/types/index.d.ts +3 -11
  44. package/dist/types/index.js +2 -2
  45. package/dist/types/modules/cookie/index.d.ts +27 -25
  46. package/dist/types/modules/date/index.d.ts +52 -1
  47. package/dist/types/modules/dom/index.d.ts +28 -1
  48. package/dist/types/modules/filter/index.d.ts +24 -25
  49. package/dist/types/modules/format/index.d.ts +15 -13
  50. package/dist/types/modules/match/index.d.ts +12 -1
  51. package/dist/types/modules/monitor/index.d.ts +3 -3
  52. package/dist/types/modules/monitor/lib/jsError.d.ts +1 -1
  53. package/dist/types/modules/monitor/lib/timing.d.ts +1 -1
  54. package/dist/types/modules/monitor/lib/xhr.d.ts +1 -1
  55. package/dist/types/modules/monitor/utils/onload.d.ts +1 -1
  56. package/dist/types/modules/monitor/utils/tracker.d.ts +7 -7
  57. package/dist/types/modules/number/index.d.ts +41 -39
  58. package/dist/types/modules/sentry/index.d.ts +15 -15
  59. package/dist/types/modules/tools/index.d.ts +166 -1
  60. package/dist/types/types/index.d.ts +3 -3
  61. package/package.json +18 -14
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @file aliOss 使用示例
3
+ * @description 展示如何在项目中使用统一的 aliOss 工具
4
+ */
5
+ declare const basicOssUploader: import("./aliOss").AliOssClass;
6
+ declare const fullOssUploader: import("./aliOss").AliOssClass;
7
+ declare function uploadNormalImage(file: File): Promise<any>;
8
+ declare function uploadAvatar(file: File): Promise<any>;
9
+ declare function uploadVideo(file: File): Promise<any>;
10
+ declare function uploadIdCard(file: File): Promise<any>;
11
+ declare function uploadShopDetail(file: File): Promise<any>;
12
+ export { basicOssUploader, fullOssUploader, uploadNormalImage, uploadAvatar, uploadVideo, uploadIdCard, uploadShopDetail };
@@ -0,0 +1,320 @@
1
+ "use strict";
2
+ /**
3
+ * @file aliOss 使用示例
4
+ * @description 展示如何在项目中使用统一的 aliOss 工具
5
+ */
6
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
7
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
8
+ return new (P || (P = Promise))(function (resolve, reject) {
9
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
10
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
11
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
12
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
13
+ });
14
+ };
15
+ var __generator = (this && this.__generator) || function (thisArg, body) {
16
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
17
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
18
+ function verb(n) { return function (v) { return step([n, v]); }; }
19
+ function step(op) {
20
+ if (f) throw new TypeError("Generator is already executing.");
21
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
22
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
23
+ if (y = 0, t) op = [op[0] & 2, t.value];
24
+ switch (op[0]) {
25
+ case 0: case 1: t = op; break;
26
+ case 4: _.label++; return { value: op[1], done: false };
27
+ case 5: _.label++; y = op[1]; op = [0]; continue;
28
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
29
+ default:
30
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
31
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
32
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
33
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
34
+ if (t[2]) _.ops.pop();
35
+ _.trys.pop(); continue;
36
+ }
37
+ op = body.call(thisArg, _);
38
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
39
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
40
+ }
41
+ };
42
+ Object.defineProperty(exports, "__esModule", { value: true });
43
+ exports.uploadShopDetail = exports.uploadIdCard = exports.uploadVideo = exports.uploadAvatar = exports.uploadNormalImage = exports.fullOssUploader = exports.basicOssUploader = void 0;
44
+ var aliOss_1 = require("./aliOss");
45
+ // ============================================
46
+ // 示例1:基础配置(最小配置)
47
+ // ============================================
48
+ var basicOssUploader = (0, aliOss_1.createAliOssUploader)({
49
+ // 必需:获取阿里云STS临时凭证
50
+ getAliyunSts: function (params) { return __awaiter(void 0, void 0, void 0, function () {
51
+ var response;
52
+ return __generator(this, function (_a) {
53
+ switch (_a.label) {
54
+ case 0: return [4 /*yield*/, fetch('/api/getAliyunSts', {
55
+ method: 'POST',
56
+ body: JSON.stringify(params)
57
+ })];
58
+ case 1:
59
+ response = _a.sent();
60
+ return [2 /*return*/, response.json()];
61
+ }
62
+ });
63
+ }); },
64
+ // 必需:日期格式化函数
65
+ dateFormat: function (date, format) {
66
+ // 简单实现,实际项目中使用 util.date.format 或 util.filter.format
67
+ var year = date.getFullYear();
68
+ var month = String(date.getMonth() + 1).padStart(2, '0');
69
+ var day = String(date.getDate()).padStart(2, '0');
70
+ var hour = String(date.getHours()).padStart(2, '0');
71
+ var minute = String(date.getMinutes()).padStart(2, '0');
72
+ var second = String(date.getSeconds()).padStart(2, '0');
73
+ return format
74
+ .replace('YYYY', String(year))
75
+ .replace('MM', month)
76
+ .replace('DD', day)
77
+ .replace('HH', hour)
78
+ .replace('mm', minute)
79
+ .replace('ss', second);
80
+ },
81
+ // 可选:消息提示
82
+ messageWarning: function (msg) {
83
+ console.warn(msg);
84
+ // 或使用你的消息组件:window.$message.warning(msg)
85
+ }
86
+ });
87
+ exports.basicOssUploader = basicOssUploader;
88
+ // ============================================
89
+ // 示例2:完整配置(OSS后台项目)
90
+ // ============================================
91
+ var fullOssUploader = (0, aliOss_1.createAliOssUploader)({
92
+ getAliyunSts: function (params) { return __awaiter(void 0, void 0, void 0, function () {
93
+ var response;
94
+ return __generator(this, function (_a) {
95
+ switch (_a.label) {
96
+ case 0: return [4 /*yield*/, fetch('/api/getAliyunSts', {
97
+ method: 'POST',
98
+ body: JSON.stringify(params)
99
+ })];
100
+ case 1:
101
+ response = _a.sent();
102
+ return [2 /*return*/, response.json()];
103
+ }
104
+ });
105
+ }); },
106
+ // 暗水印上传
107
+ darkWaterUploadImage: function (params) { return __awaiter(void 0, void 0, void 0, function () {
108
+ var formData, response;
109
+ return __generator(this, function (_a) {
110
+ switch (_a.label) {
111
+ case 0:
112
+ formData = new FormData();
113
+ formData.append('file', params.file);
114
+ return [4 /*yield*/, fetch('/api/darkWaterUploadImage', {
115
+ method: 'POST',
116
+ body: formData
117
+ })];
118
+ case 1:
119
+ response = _a.sent();
120
+ return [2 /*return*/, response.json()];
121
+ }
122
+ });
123
+ }); },
124
+ // 批量转换水印
125
+ multiTransferImage: function (params) { return __awaiter(void 0, void 0, void 0, function () {
126
+ var formData, response;
127
+ return __generator(this, function (_a) {
128
+ switch (_a.label) {
129
+ case 0:
130
+ formData = new FormData();
131
+ formData.append('file', params.file);
132
+ return [4 /*yield*/, fetch('/api/multiTransferImage', {
133
+ method: 'POST',
134
+ body: formData
135
+ })];
136
+ case 1:
137
+ response = _a.sent();
138
+ return [2 /*return*/, response.json()];
139
+ }
140
+ });
141
+ }); },
142
+ // 头像处理
143
+ aliyunPersist: function (params) { return __awaiter(void 0, void 0, void 0, function () {
144
+ var response;
145
+ return __generator(this, function (_a) {
146
+ switch (_a.label) {
147
+ case 0: return [4 /*yield*/, fetch('/api/aliyunPersist', {
148
+ method: 'POST',
149
+ body: JSON.stringify(params)
150
+ })];
151
+ case 1:
152
+ response = _a.sent();
153
+ return [2 /*return*/, response.json()];
154
+ }
155
+ });
156
+ }); },
157
+ // 生成预签名URL
158
+ generatePrePresignedUrl: function (params) { return __awaiter(void 0, void 0, void 0, function () {
159
+ var response;
160
+ return __generator(this, function (_a) {
161
+ switch (_a.label) {
162
+ case 0: return [4 /*yield*/, fetch('/api/generatePrePresignedUrl', {
163
+ method: 'GET'
164
+ })];
165
+ case 1:
166
+ response = _a.sent();
167
+ return [2 /*return*/, response.json()];
168
+ }
169
+ });
170
+ }); },
171
+ // 上传配置
172
+ uploadConf: function (businessType) { return __awaiter(void 0, void 0, void 0, function () {
173
+ var response;
174
+ return __generator(this, function (_a) {
175
+ switch (_a.label) {
176
+ case 0: return [4 /*yield*/, fetch("/api/uploadConf?businessType=".concat(businessType))];
177
+ case 1:
178
+ response = _a.sent();
179
+ return [2 /*return*/, response.json()];
180
+ }
181
+ });
182
+ }); },
183
+ dateFormat: function (date, format) {
184
+ // 日期格式化实现
185
+ return format;
186
+ },
187
+ messageWarning: function (msg) {
188
+ console.warn(msg);
189
+ }
190
+ });
191
+ exports.fullOssUploader = fullOssUploader;
192
+ // ============================================
193
+ // 使用示例
194
+ // ============================================
195
+ // 1. 普通图片上传
196
+ function uploadNormalImage(file) {
197
+ return __awaiter(this, void 0, void 0, function () {
198
+ var result, error_1;
199
+ return __generator(this, function (_a) {
200
+ switch (_a.label) {
201
+ case 0:
202
+ _a.trys.push([0, 2, , 3]);
203
+ return [4 /*yield*/, basicOssUploader.ossUploadImage({
204
+ file: file,
205
+ imageType: 'official',
206
+ quality: 0.7,
207
+ onProgress: function (e) {
208
+ console.log("\u4E0A\u4F20\u8FDB\u5EA6: ".concat(e.percent, "%"));
209
+ },
210
+ onSuccess: function (val) {
211
+ console.log('上传成功:', val.imgUrl);
212
+ },
213
+ onError: function (err) {
214
+ console.error('上传失败:', err);
215
+ }
216
+ })];
217
+ case 1:
218
+ result = _a.sent();
219
+ return [2 /*return*/, result];
220
+ case 2:
221
+ error_1 = _a.sent();
222
+ console.error('上传异常:', error_1);
223
+ return [3 /*break*/, 3];
224
+ case 3: return [2 /*return*/];
225
+ }
226
+ });
227
+ });
228
+ }
229
+ exports.uploadNormalImage = uploadNormalImage;
230
+ // 2. 头像上传
231
+ function uploadAvatar(file) {
232
+ return __awaiter(this, void 0, void 0, function () {
233
+ var result;
234
+ return __generator(this, function (_a) {
235
+ switch (_a.label) {
236
+ case 0: return [4 /*yield*/, fullOssUploader.ossUploadImage({
237
+ file: file,
238
+ imageType: 'avatar',
239
+ quality: 0.8,
240
+ businessType: aliOss_1.BusinessType.AVATAR,
241
+ onSuccess: function (val) {
242
+ console.log('头像上传成功:', val.imgUrl);
243
+ }
244
+ })];
245
+ case 1:
246
+ result = _a.sent();
247
+ return [2 /*return*/, result];
248
+ }
249
+ });
250
+ });
251
+ }
252
+ exports.uploadAvatar = uploadAvatar;
253
+ // 3. 视频上传
254
+ function uploadVideo(file) {
255
+ return __awaiter(this, void 0, void 0, function () {
256
+ var result;
257
+ return __generator(this, function (_a) {
258
+ switch (_a.label) {
259
+ case 0: return [4 /*yield*/, fullOssUploader.ossUploadFile({
260
+ file: file,
261
+ isVideo: true,
262
+ onProgress: function (e) {
263
+ console.log("\u89C6\u9891\u4E0A\u4F20\u8FDB\u5EA6: ".concat(e.percent, "%"));
264
+ },
265
+ onSuccess: function (val) {
266
+ console.log('视频上传成功:', val.url);
267
+ }
268
+ })];
269
+ case 1:
270
+ result = _a.sent();
271
+ return [2 /*return*/, result];
272
+ }
273
+ });
274
+ });
275
+ }
276
+ exports.uploadVideo = uploadVideo;
277
+ // 4. 身份证上传(私有)
278
+ function uploadIdCard(file) {
279
+ return __awaiter(this, void 0, void 0, function () {
280
+ var result;
281
+ return __generator(this, function (_a) {
282
+ switch (_a.label) {
283
+ case 0: return [4 /*yield*/, fullOssUploader.ossUploadImage({
284
+ file: file,
285
+ imageType: 'official',
286
+ idCard: true,
287
+ businessType: aliOss_1.BusinessType.PRIVATE,
288
+ onSuccess: function (val) {
289
+ console.log('身份证上传成功:', val.imgUrl);
290
+ }
291
+ })];
292
+ case 1:
293
+ result = _a.sent();
294
+ return [2 /*return*/, result];
295
+ }
296
+ });
297
+ });
298
+ }
299
+ exports.uploadIdCard = uploadIdCard;
300
+ // 5. 商品详情图片上传
301
+ function uploadShopDetail(file) {
302
+ return __awaiter(this, void 0, void 0, function () {
303
+ var result;
304
+ return __generator(this, function (_a) {
305
+ switch (_a.label) {
306
+ case 0: return [4 /*yield*/, fullOssUploader.shopDetailUpdate({
307
+ file: file,
308
+ imageType: 'official',
309
+ onSuccess: function (val) {
310
+ console.log('商品详情图片上传成功:', val.imgUrl);
311
+ }
312
+ })];
313
+ case 1:
314
+ result = _a.sent();
315
+ return [2 /*return*/, result];
316
+ }
317
+ });
318
+ });
319
+ }
320
+ exports.uploadShopDetail = uploadShopDetail;
@@ -0,0 +1,324 @@
1
+ /**
2
+ * @file 阿里云OSS上传统一工具类
3
+ * @description 整合所有项目的aliOss业务逻辑,通过传参形式支持不同业务场景
4
+ * @Author: wanghui
5
+ * @createBy: @2025.11.17
6
+ *
7
+ * 文档:https://help.aliyun.com/document_detail/64041.html
8
+ *
9
+ * 使用示例:
10
+ * ```typescript
11
+ * import { createAliOssUploader } from '@haluo/util'
12
+ *
13
+ * // 创建上传实例,传入业务相关的API函数
14
+ * const ossUploader = createAliOssUploader({
15
+ * getAliyunSts: (params) => api.getAliyunSts(params),
16
+ * darkWaterUploadImage: (params) => api.darkWaterUploadImage(params),
17
+ * multiTransferImage: (params) => api.multiTransferImage(params),
18
+ * aliyunPersist: (params) => api.aliyunPersist(params),
19
+ * generatePrePresignedUrl: (params) => api.generatePrePresignedUrl(params),
20
+ * uploadConf: (params) => api.uploadConf(params),
21
+ * dateFormat: util.date.format, // 或 util.filter.format
22
+ * messageWarning: (msg) => window.$message.warning(msg)
23
+ * })
24
+ *
25
+ * // 图片上传
26
+ * ossUploader.ossUploadImage({
27
+ * file: file,
28
+ * imageType: 'official', // nowater、official、panoram、forum、avatar、square、carport
29
+ * quality: 0.7, // 压缩质量
30
+ * businessType: 1500, // 业务类型:0(无水印)、1(头像)、4(GIF)、6(视频)、8(UnProtect)、1000(文章)、1199(私有)、1299(加密)、1500(默认)
31
+ * batchTransfer: false, // 是否批量转换水印
32
+ * notCompress: false, // 是否不压缩
33
+ * idCard: false, // 是否身份证上传
34
+ * onProgress: (e) => console.log(e.percent),
35
+ * onSuccess: (val) => console.log(val),
36
+ * onError: (err) => console.error(err)
37
+ * })
38
+ *
39
+ * // 文件上传
40
+ * ossUploader.ossUploadFile({
41
+ * file: file,
42
+ * isVideo: false, // 是否视频
43
+ * isUnProtect: false, // 是否UnProtect
44
+ * isDocument: false, // 是否文档
45
+ * businessType: 1500,
46
+ * onProgress: (e) => console.log(e.percent),
47
+ * onSuccess: (val) => console.log(val),
48
+ * onError: (err) => console.error(err)
49
+ * })
50
+ * ```
51
+ */
52
+ /**
53
+ * 业务类型枚举
54
+ * 不同的businessType对应不同的OSS bucket和水印策略
55
+ */
56
+ export declare enum BusinessType {
57
+ NO_WATER = 0,
58
+ AVATAR = 1,
59
+ GIF = 4,
60
+ VIDEO = 6,
61
+ UNPROTECT = 8,
62
+ ARTICLE = 1000,
63
+ PRIVATE = 1199,
64
+ ENCRYPTED = 1299,
65
+ DEFAULT = 1500
66
+ }
67
+ /**
68
+ * 图片类型后缀枚举
69
+ */
70
+ export declare const SuffixEnum: {
71
+ readonly nowater: "!nowater";
72
+ readonly official: "!official";
73
+ readonly panoram: "!panoram";
74
+ readonly forum: "!forum";
75
+ readonly avatar: "!avatar";
76
+ readonly square: "!square";
77
+ readonly carport: "!carport";
78
+ };
79
+ /** 图片类型 */
80
+ export type ImageType = keyof typeof SuffixEnum;
81
+ /**
82
+ * OSS客户端配置接口
83
+ */
84
+ export interface OSSClientParams {
85
+ region?: string;
86
+ accessKeyId?: string;
87
+ accessKeySecret?: string;
88
+ stsToken?: string;
89
+ bucket?: string;
90
+ realmName?: string;
91
+ suffix?: string;
92
+ style?: string;
93
+ [key: string]: any;
94
+ }
95
+ /**
96
+ * 上传结果接口
97
+ */
98
+ export interface UploadResult {
99
+ imgUrl?: string;
100
+ imgOrgUrl?: string;
101
+ url?: string;
102
+ fileName?: string;
103
+ name?: string;
104
+ bucket?: string;
105
+ [key: string]: any;
106
+ }
107
+ /**
108
+ * 上传选项接口
109
+ */
110
+ export interface UploadOption {
111
+ file: File;
112
+ imageType?: ImageType | string;
113
+ quality?: number;
114
+ businessType?: BusinessType | number;
115
+ batchTransfer?: boolean;
116
+ notCompress?: boolean;
117
+ idCard?: boolean;
118
+ imggeCarType?: any;
119
+ isVideo?: boolean;
120
+ isUnProtect?: boolean;
121
+ isDocument?: boolean;
122
+ onProgress?: (e: {
123
+ percent: number;
124
+ }) => void;
125
+ onSuccess?: (val: UploadResult) => void;
126
+ onError?: (err: string) => void;
127
+ }
128
+ /**
129
+ * API响应接口
130
+ */
131
+ interface ApiResponse<T = any> {
132
+ data: {
133
+ code: number;
134
+ data: T;
135
+ };
136
+ }
137
+ /**
138
+ * API函数配置接口
139
+ * 业务相关的API通过此接口传入,实现业务逻辑解耦
140
+ */
141
+ export interface AliOssApiConfig {
142
+ /** 获取阿里云STS临时凭证 - 必需 */
143
+ getAliyunSts: (params: {
144
+ businessType: number;
145
+ imggeCarType?: any;
146
+ }) => Promise<ApiResponse<OSSClientParams>>;
147
+ /** 暗水印上传接口 - 可选,用于carport类型 */
148
+ darkWaterUploadImage?: (params: {
149
+ file: File;
150
+ }) => Promise<ApiResponse<string>>;
151
+ /** 批量转换水印接口 - 可选,用于batchTransfer */
152
+ multiTransferImage?: (params: {
153
+ file: File;
154
+ }) => Promise<ApiResponse<string>>;
155
+ /** 阿里云持久化接口 - 可选,用于avatar类型 */
156
+ aliyunPersist?: (params: {
157
+ object: string;
158
+ businessType: number;
159
+ }) => Promise<ApiResponse<string>>;
160
+ /** 生成预签名URL接口 - 可选,用于idCard */
161
+ generatePrePresignedUrl?: (params: {
162
+ objectId: string;
163
+ expireMils: number;
164
+ }) => Promise<ApiResponse<string>>;
165
+ /** 上传配置接口 - 可选,用于document上传 */
166
+ uploadConf?: (businessType: number) => Promise<ApiResponse>;
167
+ /** 日期格式化函数 - 必需,支持 util.date.format 或 util.filter.format */
168
+ dateFormat: (date: Date, format: string) => string;
169
+ /** 消息提示函数 - 可选 */
170
+ messageWarning?: (msg: string) => void;
171
+ }
172
+ /**
173
+ * 生成随机字符串
174
+ * @param length 字符串长度
175
+ * @returns 随机字符串
176
+ */
177
+ declare function randomString(length: number): string;
178
+ /**
179
+ * 阿里云OSS上传类
180
+ * 整合所有项目的aliOss业务逻辑,通过依赖注入实现业务API解耦
181
+ */
182
+ export declare class AliOssClass {
183
+ private apiConfig;
184
+ private clientCache;
185
+ constructor(apiConfig: AliOssApiConfig);
186
+ /**
187
+ * 创建OSS客户端
188
+ * @param businessType 业务类型
189
+ * @param imggeCarType 车辆图片类型(可选,用于特定业务)
190
+ * @returns OSS客户端实例
191
+ */
192
+ createOssClient(businessType: number, imggeCarType?: any): Promise<any>;
193
+ /**
194
+ * 预加载图片获取尺寸
195
+ * @param file 文件对象
196
+ * @returns 图片对象
197
+ */
198
+ imgUpload(file: File): Promise<HTMLImageElement>;
199
+ /**
200
+ * 生成文件名
201
+ * @param imageType 图片类型
202
+ * @param extension 文件扩展名
203
+ * @returns 文件名信息
204
+ */
205
+ private generateFileName;
206
+ /**
207
+ * 检查图片是否为长图
208
+ * @param width 图片宽度
209
+ * @param height 图片高度
210
+ * @returns 是否为长图
211
+ */
212
+ private isLongImage;
213
+ /**
214
+ * 执行OSS上传
215
+ * @param client OSS客户端
216
+ * @param fileName 文件名
217
+ * @param file 文件对象
218
+ * @param year 年份
219
+ * @param mimeType MIME类型
220
+ * @param onProgress 进度回调
221
+ * @returns 上传结果
222
+ */
223
+ private performOssUpload;
224
+ /**
225
+ * 确定业务类型
226
+ * @param option 上传选项
227
+ * @param isGif 是否为GIF
228
+ * @returns 业务类型
229
+ */
230
+ private determineBusinessType;
231
+ /**
232
+ * 加载图片并返回结果
233
+ * 用于标准的图片上传场景
234
+ * @param params 加载参数
235
+ */
236
+ loadImage(params: {
237
+ url: string;
238
+ val: any;
239
+ suffix: string;
240
+ file: File;
241
+ option: UploadOption;
242
+ resolve: (value: any) => void;
243
+ reject: (reason?: any) => void;
244
+ isGif?: boolean;
245
+ }): void;
246
+ /**
247
+ * 加载图片并返回结果(新版)
248
+ * 用于avatar、idCard等特殊场景,返回格式不同
249
+ * @param params 加载参数
250
+ */
251
+ loadImageNew(params: {
252
+ url: string;
253
+ val: any;
254
+ file: File;
255
+ option: UploadOption;
256
+ resolve: (value: any) => void;
257
+ reject: (reason?: any) => void;
258
+ }): void;
259
+ /**
260
+ * 图片上传主方法
261
+ * 整合了所有项目的图片上传逻辑
262
+ * @param option 上传选项
263
+ * @returns Promise
264
+ */
265
+ ossUploadImage(option: UploadOption): Promise<any>;
266
+ /**
267
+ * 文件上传方法
268
+ * 支持视频、文档、APK等文件类型
269
+ * @param option 上传选项
270
+ * @returns Promise
271
+ */
272
+ ossUploadFile(option: UploadOption): Promise<any>;
273
+ /**
274
+ * 商品详情图片上传
275
+ * 注释:此方法用于商品详情页的图片上传,不压缩,使用NoWater客户端
276
+ * @param option 上传选项
277
+ * @returns Promise
278
+ */
279
+ shopDetailUpdate(option: UploadOption): Promise<any>;
280
+ /**
281
+ * 生成随机字符串
282
+ * @param num 字符串长度
283
+ */
284
+ randomString: typeof randomString;
285
+ /**
286
+ * 后缀枚举
287
+ */
288
+ suffixEnum: {
289
+ readonly nowater: "!nowater";
290
+ readonly official: "!official";
291
+ readonly panoram: "!panoram";
292
+ readonly forum: "!forum";
293
+ readonly avatar: "!avatar";
294
+ readonly square: "!square";
295
+ readonly carport: "!carport";
296
+ };
297
+ /**
298
+ * 业务类型枚举
299
+ */
300
+ businessType: typeof BusinessType;
301
+ }
302
+ /**
303
+ * 创建阿里云OSS上传器(工厂函数)
304
+ * @param apiConfig API配置对象,包含业务相关的API函数
305
+ * @returns OSS上传器实例
306
+ */
307
+ export declare function createAliOssUploader(apiConfig: AliOssApiConfig): AliOssClass;
308
+ /**
309
+ * 默认导出
310
+ */
311
+ declare const _default: {
312
+ createAliOssUploader: typeof createAliOssUploader;
313
+ BusinessType: typeof BusinessType;
314
+ SuffixEnum: {
315
+ readonly nowater: "!nowater";
316
+ readonly official: "!official";
317
+ readonly panoram: "!panoram";
318
+ readonly forum: "!forum";
319
+ readonly avatar: "!avatar";
320
+ readonly square: "!square";
321
+ readonly carport: "!carport";
322
+ };
323
+ };
324
+ export default _default;