maooo-skyline-ui-system 0.1.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.
- package/README.md +157 -0
- package/miniprogram_dist/button/button.js +43 -0
- package/miniprogram_dist/button/button.json +5 -0
- package/miniprogram_dist/button/button.wxml +12 -0
- package/miniprogram_dist/button/button.wxs +23 -0
- package/miniprogram_dist/button/button.wxss +133 -0
- package/miniprogram_dist/calendar/calendar.js +549 -0
- package/miniprogram_dist/calendar/calendar.json +8 -0
- package/miniprogram_dist/calendar/calendar.wxml +79 -0
- package/miniprogram_dist/calendar/calendar.wxss +265 -0
- package/miniprogram_dist/card/card.js +22 -0
- package/miniprogram_dist/card/card.json +5 -0
- package/miniprogram_dist/card/card.wxml +9 -0
- package/miniprogram_dist/card/card.wxss +34 -0
- package/miniprogram_dist/countdown/countdown.js +213 -0
- package/miniprogram_dist/countdown/countdown.json +3 -0
- package/miniprogram_dist/countdown/countdown.wxml +9 -0
- package/miniprogram_dist/countdown/countdown.wxss +33 -0
- package/miniprogram_dist/form/form.js +12 -0
- package/miniprogram_dist/form/form.json +5 -0
- package/miniprogram_dist/form/form.wxml +12 -0
- package/miniprogram_dist/form/form.wxss +35 -0
- package/miniprogram_dist/form-group/form-group.js +53 -0
- package/miniprogram_dist/form-group/form-group.json +5 -0
- package/miniprogram_dist/form-group/form-group.wxml +11 -0
- package/miniprogram_dist/form-group/form-group.wxss +50 -0
- package/miniprogram_dist/form-input/form-input.js +48 -0
- package/miniprogram_dist/form-input/form-input.json +8 -0
- package/miniprogram_dist/form-input/form-input.wxml +28 -0
- package/miniprogram_dist/form-input/form-input.wxss +3 -0
- package/miniprogram_dist/form-textarea/form-textarea.js +34 -0
- package/miniprogram_dist/form-textarea/form-textarea.json +8 -0
- package/miniprogram_dist/form-textarea/form-textarea.wxml +20 -0
- package/miniprogram_dist/form-textarea/form-textarea.wxss +3 -0
- package/miniprogram_dist/icon/_iconfont/iconfont.js +63 -0
- package/miniprogram_dist/icon/_iconfont/iconfont.json +4 -0
- package/miniprogram_dist/icon/_iconfont/iconfont.wxml +8 -0
- package/miniprogram_dist/icon/_iconfont/iconfont.wxss +3 -0
- package/miniprogram_dist/icon/icon.js +41 -0
- package/miniprogram_dist/icon/icon.json +7 -0
- package/miniprogram_dist/icon/icon.wxml +3 -0
- package/miniprogram_dist/icon/icon.wxss +13 -0
- package/miniprogram_dist/image-cropper/image-cropper.js +703 -0
- package/miniprogram_dist/image-cropper/image-cropper.json +3 -0
- package/miniprogram_dist/image-cropper/image-cropper.wxml +58 -0
- package/miniprogram_dist/image-cropper/image-cropper.wxss +195 -0
- package/miniprogram_dist/index.js +4 -0
- package/miniprogram_dist/input/input.js +119 -0
- package/miniprogram_dist/input/input.json +7 -0
- package/miniprogram_dist/input/input.wxml +38 -0
- package/miniprogram_dist/input/input.wxss +52 -0
- package/miniprogram_dist/media-upload/media-upload.js +1108 -0
- package/miniprogram_dist/media-upload/media-upload.json +7 -0
- package/miniprogram_dist/media-upload/media-upload.wxml +98 -0
- package/miniprogram_dist/media-upload/media-upload.wxss +149 -0
- package/miniprogram_dist/navbar/navbar.js +191 -0
- package/miniprogram_dist/navbar/navbar.json +6 -0
- package/miniprogram_dist/navbar/navbar.wxml +25 -0
- package/miniprogram_dist/navbar/navbar.wxss +60 -0
- package/miniprogram_dist/notify/notify.js +342 -0
- package/miniprogram_dist/notify/notify.json +5 -0
- package/miniprogram_dist/notify/notify.wxml +27 -0
- package/miniprogram_dist/notify/notify.wxss +246 -0
- package/miniprogram_dist/notify/service.js +69 -0
- package/miniprogram_dist/oss-upload/oss-upload.js +505 -0
- package/miniprogram_dist/oss-upload/oss-upload.json +6 -0
- package/miniprogram_dist/oss-upload/oss-upload.wxml +20 -0
- package/miniprogram_dist/oss-upload/oss-upload.wxss +5 -0
- package/miniprogram_dist/popup/popup.js +36 -0
- package/miniprogram_dist/popup/popup.json +5 -0
- package/miniprogram_dist/popup/popup.wxml +14 -0
- package/miniprogram_dist/popup/popup.wxss +138 -0
- package/miniprogram_dist/popup-page/popup-page.js +341 -0
- package/miniprogram_dist/popup-page/popup-page.json +8 -0
- package/miniprogram_dist/popup-page/popup-page.wxml +65 -0
- package/miniprogram_dist/popup-page/popup-page.wxss +92 -0
- package/miniprogram_dist/progress/progress.js +161 -0
- package/miniprogram_dist/progress/progress.json +5 -0
- package/miniprogram_dist/progress/progress.wxml +16 -0
- package/miniprogram_dist/progress/progress.wxss +81 -0
- package/miniprogram_dist/rate/rate.js +127 -0
- package/miniprogram_dist/rate/rate.json +5 -0
- package/miniprogram_dist/rate/rate.wxml +32 -0
- package/miniprogram_dist/rate/rate.wxs +21 -0
- package/miniprogram_dist/rate/rate.wxss +126 -0
- package/miniprogram_dist/stepper/stepper.js +153 -0
- package/miniprogram_dist/stepper/stepper.json +5 -0
- package/miniprogram_dist/stepper/stepper.wxml +19 -0
- package/miniprogram_dist/stepper/stepper.wxss +66 -0
- package/miniprogram_dist/switch/switch.js +29 -0
- package/miniprogram_dist/switch/switch.json +3 -0
- package/miniprogram_dist/switch/switch.wxml +10 -0
- package/miniprogram_dist/switch/switch.wxss +71 -0
- package/miniprogram_dist/textarea/textarea.js +83 -0
- package/miniprogram_dist/textarea/textarea.json +5 -0
- package/miniprogram_dist/textarea/textarea.wxml +14 -0
- package/miniprogram_dist/textarea/textarea.wxss +33 -0
- package/miniprogram_dist/theme/theme.wxss +64 -0
- package/miniprogram_dist/toast/toast.js +51 -0
- package/miniprogram_dist/toast/toast.json +5 -0
- package/miniprogram_dist/toast/toast.wxml +13 -0
- package/miniprogram_dist/toast/toast.wxss +143 -0
- package/miniprogram_dist/upload/upload.js +276 -0
- package/miniprogram_dist/upload/upload.json +3 -0
- package/miniprogram_dist/upload/upload.wxml +36 -0
- package/miniprogram_dist/upload/upload.wxss +136 -0
- package/miniprogram_dist/utils/class.js +37 -0
- package/miniprogram_dist/utils/device.js +67 -0
- package/miniprogram_dist/utils/dom.js +51 -0
- package/miniprogram_dist/utils/event.js +28 -0
- package/miniprogram_dist/utils/form.js +39 -0
- package/miniprogram_dist/utils/function.js +63 -0
- package/miniprogram_dist/utils/index.js +21 -0
- package/miniprogram_dist/utils/props.js +51 -0
- package/miniprogram_dist/utils/style.js +52 -0
- package/miniprogram_dist/utils/theme.js +30 -0
- package/package.json +31 -0
|
@@ -0,0 +1,1108 @@
|
|
|
1
|
+
function normalizeArray(value) {
|
|
2
|
+
return Array.isArray(value) ? value : [];
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
function normalizeObject(value) {
|
|
6
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function normalizeMethod(value, fallback) {
|
|
10
|
+
if (value === "POST") return "POST";
|
|
11
|
+
if (value === "DELETE") return "DELETE";
|
|
12
|
+
return fallback || "GET";
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function normalizeFileList(value) {
|
|
16
|
+
return normalizeArray(value).filter((file) => file && typeof file === "object");
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function normalizeMaxCount(value) {
|
|
20
|
+
const numberValue = Number(value);
|
|
21
|
+
return Number.isFinite(numberValue) && numberValue >= 1 ? Math.floor(numberValue) : 1;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function normalizeCoverFrameCount(value) {
|
|
25
|
+
const numberValue = Number(value);
|
|
26
|
+
if (!Number.isFinite(numberValue) || numberValue < 1) return 6;
|
|
27
|
+
return Math.max(1, Math.min(12, Math.floor(numberValue)));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function normalizeCoverFrameStep(value) {
|
|
31
|
+
const numberValue = Number(value);
|
|
32
|
+
return Number.isFinite(numberValue) && numberValue > 0 ? Math.floor(numberValue) : 1000;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function clampPercent(value) {
|
|
36
|
+
const numberValue = Number(value);
|
|
37
|
+
if (!Number.isFinite(numberValue)) return 0;
|
|
38
|
+
return Math.max(0, Math.min(100, Math.round(numberValue)));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function joinOssPath() {
|
|
42
|
+
return Array.prototype.slice
|
|
43
|
+
.call(arguments)
|
|
44
|
+
.map((part) => String(part || ""))
|
|
45
|
+
.join("/")
|
|
46
|
+
.split("/")
|
|
47
|
+
.filter(Boolean)
|
|
48
|
+
.join("/");
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function getFileExtension(file) {
|
|
52
|
+
const source = file.name || file.tempFilePath || file.url || "";
|
|
53
|
+
const cleanSource = String(source).split("?")[0].split("#")[0];
|
|
54
|
+
const extension = cleanSource.includes(".") ? cleanSource.slice(cleanSource.lastIndexOf(".")) : "";
|
|
55
|
+
|
|
56
|
+
if (extension) return extension;
|
|
57
|
+
return file.type === "video" ? ".mp4" : ".jpg";
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function createFileName(file) {
|
|
61
|
+
const random = Math.random().toString(36).slice(2, 8);
|
|
62
|
+
return `media_${Date.now()}_${random}${getFileExtension(file)}`;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function getResponseData(response) {
|
|
66
|
+
const body = response && response.data;
|
|
67
|
+
if (body && typeof body === "object" && body.data && typeof body.data === "object") {
|
|
68
|
+
return body.data;
|
|
69
|
+
}
|
|
70
|
+
return body && typeof body === "object" ? body : {};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function normalizeCredential(response) {
|
|
74
|
+
const credential = getResponseData(response);
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
host: credential.host || "",
|
|
78
|
+
dir: credential.dir || "",
|
|
79
|
+
policy: credential.policy || "",
|
|
80
|
+
ossAccessKeyId: credential.ossAccessKeyId || credential.OSSAccessKeyId || "",
|
|
81
|
+
signature: credential.signature || "",
|
|
82
|
+
publicHost: credential.publicHost || credential.cdnHost || credential.imageURL || credential.host || "",
|
|
83
|
+
raw: credential
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function validateCredential(credential) {
|
|
88
|
+
return Boolean(
|
|
89
|
+
credential &&
|
|
90
|
+
credential.host &&
|
|
91
|
+
credential.policy &&
|
|
92
|
+
credential.ossAccessKeyId &&
|
|
93
|
+
credential.signature
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function formatPublicUrl(host, ossKey) {
|
|
98
|
+
const safeHost = String(host || "");
|
|
99
|
+
if (!safeHost) return ossKey;
|
|
100
|
+
return `${safeHost.replace(/\/+$/, "")}/${ossKey}`;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function getFilePath(file) {
|
|
104
|
+
return file.tempFilePath || file.url || "";
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function normalizeFileType(file) {
|
|
108
|
+
if (file && file.type === "video") return "video";
|
|
109
|
+
if (file && file.fileType === "video") return "video";
|
|
110
|
+
if (file && (file.videoPath || file.videoName)) return "video";
|
|
111
|
+
return "image";
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function normalizeIncomingFile(file, index) {
|
|
115
|
+
const safeFile = file && typeof file === "object" ? file : {};
|
|
116
|
+
const type = normalizeFileType(safeFile);
|
|
117
|
+
const url = safeFile.url || safeFile.tempFilePath || safeFile.cover || safeFile.thumb || "";
|
|
118
|
+
|
|
119
|
+
return {
|
|
120
|
+
...safeFile,
|
|
121
|
+
id: safeFile.id || `media_upload_${Date.now()}_${index}`,
|
|
122
|
+
url,
|
|
123
|
+
tempFilePath: safeFile.tempFilePath || url,
|
|
124
|
+
type,
|
|
125
|
+
thumb: type === "video" ? safeFile.thumb || safeFile.cover || safeFile.imgPath || url : safeFile.thumb,
|
|
126
|
+
isMain: Boolean(safeFile.isMain)
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function normalizeMainFlags(fileList) {
|
|
131
|
+
return normalizeFileList(fileList).map((file, index) => ({
|
|
132
|
+
...file,
|
|
133
|
+
isMain: index === 0
|
|
134
|
+
}));
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function appendSnapshotProcess(url, time) {
|
|
138
|
+
if (!url) return "";
|
|
139
|
+
const connector = String(url).includes("?") ? "&" : "?";
|
|
140
|
+
return `${url}${connector}x-oss-process=video/snapshot,t_${time},f_jpg,m_fast`;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function getFileSignature(fileList) {
|
|
144
|
+
return JSON.stringify(
|
|
145
|
+
normalizeFileList(fileList).map((file) => ({
|
|
146
|
+
id: file.id,
|
|
147
|
+
url: file.url,
|
|
148
|
+
status: file.status,
|
|
149
|
+
percent: file.percent,
|
|
150
|
+
ossKey: file.ossKey,
|
|
151
|
+
isMain: file.isMain,
|
|
152
|
+
cover: file.cover,
|
|
153
|
+
thumb: file.thumb,
|
|
154
|
+
imgPath: file.imgPath,
|
|
155
|
+
videoPath: file.videoPath
|
|
156
|
+
}))
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function getPreviewHeaderStyle() {
|
|
161
|
+
const fallbackTop = 44;
|
|
162
|
+
let statusBarHeight = fallbackTop;
|
|
163
|
+
|
|
164
|
+
if (typeof wx !== "undefined" && typeof wx.getWindowInfo === "function") {
|
|
165
|
+
const windowInfo = wx.getWindowInfo();
|
|
166
|
+
statusBarHeight = windowInfo.statusBarHeight || (windowInfo.safeArea && windowInfo.safeArea.top) || fallbackTop;
|
|
167
|
+
} else if (typeof wx !== "undefined" && typeof wx.getSystemInfoSync === "function") {
|
|
168
|
+
const systemInfo = wx.getSystemInfoSync();
|
|
169
|
+
statusBarHeight = systemInfo.statusBarHeight || fallbackTop;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return `padding-top: ${statusBarHeight}px; height: ${statusBarHeight + 56}px;`;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function normalizePreviewFile(file) {
|
|
176
|
+
const safeFile = file && typeof file === "object" ? file : {};
|
|
177
|
+
const type = normalizeFileType(safeFile);
|
|
178
|
+
const previewUrl =
|
|
179
|
+
type === "video"
|
|
180
|
+
? safeFile.url || safeFile.videoUrl || safeFile.tempFilePath || ""
|
|
181
|
+
: safeFile.url || safeFile.tempFilePath || safeFile.thumb || "";
|
|
182
|
+
|
|
183
|
+
return {
|
|
184
|
+
...safeFile,
|
|
185
|
+
_isVideo: type === "video",
|
|
186
|
+
_previewUrl: previewUrl,
|
|
187
|
+
_poster: safeFile.cover || safeFile.thumb || safeFile.imgPath || ""
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function hasBlockSuggestion(value) {
|
|
192
|
+
if (!value || typeof value !== "object") return false;
|
|
193
|
+
if (value.suggestion === "block" || value.blocked === true || value.pass === false) return true;
|
|
194
|
+
|
|
195
|
+
return Object.keys(value).some((key) => {
|
|
196
|
+
const item = value[key];
|
|
197
|
+
if (Array.isArray(item)) return item.some((child) => hasBlockSuggestion(child));
|
|
198
|
+
return item && typeof item === "object" ? hasBlockSuggestion(item) : false;
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
Component({
|
|
203
|
+
properties: {
|
|
204
|
+
fileList: {
|
|
205
|
+
type: Array,
|
|
206
|
+
value: [],
|
|
207
|
+
observer: "syncFromProps"
|
|
208
|
+
},
|
|
209
|
+
maxCount: {
|
|
210
|
+
type: Number,
|
|
211
|
+
value: 1
|
|
212
|
+
},
|
|
213
|
+
accept: {
|
|
214
|
+
type: String,
|
|
215
|
+
value: "image"
|
|
216
|
+
},
|
|
217
|
+
sourceType: {
|
|
218
|
+
type: Array,
|
|
219
|
+
value: ["album", "camera"]
|
|
220
|
+
},
|
|
221
|
+
sizeType: {
|
|
222
|
+
type: Array,
|
|
223
|
+
value: ["original", "compressed"]
|
|
224
|
+
},
|
|
225
|
+
disabled: {
|
|
226
|
+
type: Boolean,
|
|
227
|
+
value: false
|
|
228
|
+
},
|
|
229
|
+
deletable: {
|
|
230
|
+
type: Boolean,
|
|
231
|
+
value: true
|
|
232
|
+
},
|
|
233
|
+
preview: {
|
|
234
|
+
type: Boolean,
|
|
235
|
+
value: true
|
|
236
|
+
},
|
|
237
|
+
imageRadius: {
|
|
238
|
+
type: Number,
|
|
239
|
+
value: 16
|
|
240
|
+
},
|
|
241
|
+
enableCrop: {
|
|
242
|
+
type: Boolean,
|
|
243
|
+
value: true
|
|
244
|
+
},
|
|
245
|
+
cropAspectRatio: {
|
|
246
|
+
type: Number,
|
|
247
|
+
value: 1
|
|
248
|
+
},
|
|
249
|
+
cropOutputWidth: {
|
|
250
|
+
type: Number,
|
|
251
|
+
value: 750
|
|
252
|
+
},
|
|
253
|
+
credentialUrl: {
|
|
254
|
+
type: String,
|
|
255
|
+
value: ""
|
|
256
|
+
},
|
|
257
|
+
credentialMethod: {
|
|
258
|
+
type: String,
|
|
259
|
+
value: "GET"
|
|
260
|
+
},
|
|
261
|
+
credentialHeader: {
|
|
262
|
+
type: Object,
|
|
263
|
+
value: {}
|
|
264
|
+
},
|
|
265
|
+
credentialData: {
|
|
266
|
+
type: Object,
|
|
267
|
+
value: {}
|
|
268
|
+
},
|
|
269
|
+
directory: {
|
|
270
|
+
type: String,
|
|
271
|
+
value: ""
|
|
272
|
+
},
|
|
273
|
+
publicHost: {
|
|
274
|
+
type: String,
|
|
275
|
+
value: ""
|
|
276
|
+
},
|
|
277
|
+
audit: {
|
|
278
|
+
type: Boolean,
|
|
279
|
+
value: false
|
|
280
|
+
},
|
|
281
|
+
auditUrl: {
|
|
282
|
+
type: String,
|
|
283
|
+
value: ""
|
|
284
|
+
},
|
|
285
|
+
auditMethod: {
|
|
286
|
+
type: String,
|
|
287
|
+
value: "POST"
|
|
288
|
+
},
|
|
289
|
+
auditHeader: {
|
|
290
|
+
type: Object,
|
|
291
|
+
value: {}
|
|
292
|
+
},
|
|
293
|
+
deleteUrl: {
|
|
294
|
+
type: String,
|
|
295
|
+
value: ""
|
|
296
|
+
},
|
|
297
|
+
deleteMethod: {
|
|
298
|
+
type: String,
|
|
299
|
+
value: "DELETE"
|
|
300
|
+
},
|
|
301
|
+
enableVideoCover: {
|
|
302
|
+
type: Boolean,
|
|
303
|
+
value: true
|
|
304
|
+
},
|
|
305
|
+
coverFrameCount: {
|
|
306
|
+
type: Number,
|
|
307
|
+
value: 6
|
|
308
|
+
},
|
|
309
|
+
coverFrameStep: {
|
|
310
|
+
type: Number,
|
|
311
|
+
value: 1000
|
|
312
|
+
},
|
|
313
|
+
customClass: {
|
|
314
|
+
type: String,
|
|
315
|
+
value: ""
|
|
316
|
+
}
|
|
317
|
+
},
|
|
318
|
+
data: {
|
|
319
|
+
displayFileList: [],
|
|
320
|
+
showCropper: false,
|
|
321
|
+
cropFileList: [],
|
|
322
|
+
cropSrc: "",
|
|
323
|
+
showCoverPanel: false,
|
|
324
|
+
coverCandidates: [],
|
|
325
|
+
showPreview: false,
|
|
326
|
+
previewFile: {},
|
|
327
|
+
previewIndex: -1,
|
|
328
|
+
previewTitle: "预览封面",
|
|
329
|
+
previewHeaderStyle: ""
|
|
330
|
+
},
|
|
331
|
+
lifetimes: {
|
|
332
|
+
attached() {
|
|
333
|
+
this.draftFileList = [];
|
|
334
|
+
this.pendingExternalSync = false;
|
|
335
|
+
this.lastEmittedSignature = "";
|
|
336
|
+
this.uploadTasks = {};
|
|
337
|
+
this.uploadTokens = {};
|
|
338
|
+
this.cancelledIds = {};
|
|
339
|
+
this.batchIndex = 0;
|
|
340
|
+
this.cropTarget = "";
|
|
341
|
+
this.coverTargetFileId = "";
|
|
342
|
+
this.previewFileId = "";
|
|
343
|
+
this.syncFromProps();
|
|
344
|
+
},
|
|
345
|
+
detached() {
|
|
346
|
+
this.abortAllUploads();
|
|
347
|
+
}
|
|
348
|
+
},
|
|
349
|
+
methods: {
|
|
350
|
+
syncFromProps() {
|
|
351
|
+
const incoming = normalizeMainFlags(normalizeFileList(this.data.fileList).map(normalizeIncomingFile));
|
|
352
|
+
const signature = getFileSignature(incoming);
|
|
353
|
+
|
|
354
|
+
if (this.pendingExternalSync && signature !== this.lastEmittedSignature) return;
|
|
355
|
+
if (this.pendingExternalSync && signature === this.lastEmittedSignature) {
|
|
356
|
+
this.pendingExternalSync = false;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
this.setDraftFileList(incoming, false);
|
|
360
|
+
},
|
|
361
|
+
setDraftFileList(fileList, emitChange) {
|
|
362
|
+
const nextFileList = normalizeMainFlags(fileList);
|
|
363
|
+
|
|
364
|
+
this.draftFileList = nextFileList;
|
|
365
|
+
this.setData({
|
|
366
|
+
displayFileList: nextFileList
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
if (emitChange) {
|
|
370
|
+
this.pendingExternalSync = true;
|
|
371
|
+
this.lastEmittedSignature = getFileSignature(nextFileList);
|
|
372
|
+
this.triggerEvent("change", {
|
|
373
|
+
fileList: nextFileList
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
},
|
|
377
|
+
getCurrentFileList() {
|
|
378
|
+
return normalizeFileList(this.draftFileList);
|
|
379
|
+
},
|
|
380
|
+
findFileIndex(fileId) {
|
|
381
|
+
return this.getCurrentFileList().findIndex((file) => file.id === fileId);
|
|
382
|
+
},
|
|
383
|
+
hasFile(fileId) {
|
|
384
|
+
return this.findFileIndex(fileId) >= 0;
|
|
385
|
+
},
|
|
386
|
+
isUploadActive(fileId, token) {
|
|
387
|
+
return !this.cancelledIds[fileId] && this.uploadTokens[fileId] === token && this.hasFile(fileId);
|
|
388
|
+
},
|
|
389
|
+
finishPipeline(fileId) {
|
|
390
|
+
delete this.uploadTokens[fileId];
|
|
391
|
+
delete this.uploadTasks[fileId];
|
|
392
|
+
},
|
|
393
|
+
updateFileById(fileId, updater, emitChange) {
|
|
394
|
+
const fileList = this.getCurrentFileList();
|
|
395
|
+
const index = fileList.findIndex((file) => file.id === fileId);
|
|
396
|
+
|
|
397
|
+
if (index < 0) return null;
|
|
398
|
+
|
|
399
|
+
const currentFile = fileList[index];
|
|
400
|
+
const nextFile = typeof updater === "function" ? updater(currentFile) : { ...currentFile, ...updater };
|
|
401
|
+
const nextFileList = fileList.map((file, itemIndex) => (itemIndex === index ? nextFile : file));
|
|
402
|
+
|
|
403
|
+
this.setDraftFileList(nextFileList, emitChange);
|
|
404
|
+
|
|
405
|
+
return {
|
|
406
|
+
file: this.getCurrentFileList()[index],
|
|
407
|
+
index,
|
|
408
|
+
fileList: this.getCurrentFileList()
|
|
409
|
+
};
|
|
410
|
+
},
|
|
411
|
+
emitError(source, message, error, file) {
|
|
412
|
+
this.triggerEvent("error", {
|
|
413
|
+
source,
|
|
414
|
+
message,
|
|
415
|
+
error,
|
|
416
|
+
file
|
|
417
|
+
});
|
|
418
|
+
},
|
|
419
|
+
requestCredential() {
|
|
420
|
+
return new Promise((resolve, reject) => {
|
|
421
|
+
if (!this.data.credentialUrl) {
|
|
422
|
+
reject({
|
|
423
|
+
message: "credentialUrl 不能为空"
|
|
424
|
+
});
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
wx.request({
|
|
429
|
+
url: this.data.credentialUrl,
|
|
430
|
+
method: normalizeMethod(this.data.credentialMethod, "GET"),
|
|
431
|
+
header: normalizeObject(this.data.credentialHeader),
|
|
432
|
+
data: normalizeObject(this.data.credentialData),
|
|
433
|
+
success: (response) => {
|
|
434
|
+
if (response.statusCode && response.statusCode >= 400) {
|
|
435
|
+
reject(response);
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
const credential = normalizeCredential(response);
|
|
440
|
+
|
|
441
|
+
if (!validateCredential(credential)) {
|
|
442
|
+
reject({
|
|
443
|
+
message: "OSS 签名字段不完整",
|
|
444
|
+
response
|
|
445
|
+
});
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
resolve(credential);
|
|
450
|
+
},
|
|
451
|
+
fail: reject
|
|
452
|
+
});
|
|
453
|
+
});
|
|
454
|
+
},
|
|
455
|
+
buildUploadTarget(file, credential) {
|
|
456
|
+
const fileName = createFileName(file);
|
|
457
|
+
const ossKey = joinOssPath(credential.dir, this.data.directory, fileName);
|
|
458
|
+
const publicHost = this.data.publicHost || credential.publicHost;
|
|
459
|
+
|
|
460
|
+
return {
|
|
461
|
+
fileName,
|
|
462
|
+
ossKey,
|
|
463
|
+
url: formatPublicUrl(publicHost, ossKey)
|
|
464
|
+
};
|
|
465
|
+
},
|
|
466
|
+
normalizeUploadFile(file, index) {
|
|
467
|
+
const safeFile = normalizeIncomingFile(file, index);
|
|
468
|
+
const type = normalizeFileType(safeFile);
|
|
469
|
+
|
|
470
|
+
return {
|
|
471
|
+
...safeFile,
|
|
472
|
+
id: safeFile.id || `media_upload_${Date.now()}_${index}`,
|
|
473
|
+
type,
|
|
474
|
+
url: safeFile.tempFilePath || safeFile.url,
|
|
475
|
+
tempFilePath: safeFile.tempFilePath || safeFile.url,
|
|
476
|
+
status: "uploading",
|
|
477
|
+
percent: 0
|
|
478
|
+
};
|
|
479
|
+
},
|
|
480
|
+
handleChoose(event) {
|
|
481
|
+
const files = normalizeFileList(event.detail.files).map((file, index) => this.normalizeUploadFile(file, index));
|
|
482
|
+
const rawFiles = normalizeArray(event.detail.rawFiles);
|
|
483
|
+
const currentFileList = this.getCurrentFileList();
|
|
484
|
+
const maxCount = normalizeMaxCount(this.data.maxCount);
|
|
485
|
+
const remaining = Math.max(0, maxCount - currentFileList.length);
|
|
486
|
+
const nextFiles = files.slice(0, remaining);
|
|
487
|
+
const imageFiles = nextFiles.filter((file) => file.type !== "video");
|
|
488
|
+
const videoFiles = nextFiles.filter((file) => file.type === "video");
|
|
489
|
+
|
|
490
|
+
this.triggerEvent("choose", {
|
|
491
|
+
files: nextFiles,
|
|
492
|
+
rawFiles,
|
|
493
|
+
source: event.detail.source
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
if (videoFiles.length) {
|
|
497
|
+
this.processUploadFiles(videoFiles, "video");
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
if (!imageFiles.length) return;
|
|
501
|
+
|
|
502
|
+
if (this.data.enableCrop) {
|
|
503
|
+
this.cropTarget = "image";
|
|
504
|
+
this.setData({
|
|
505
|
+
showCropper: true,
|
|
506
|
+
cropFileList: imageFiles,
|
|
507
|
+
cropSrc: "",
|
|
508
|
+
showCoverPanel: false
|
|
509
|
+
});
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
this.processUploadFiles(imageFiles, "image");
|
|
514
|
+
},
|
|
515
|
+
processUploadFiles(files, pipelineType) {
|
|
516
|
+
const uploadFiles = files.map((file, index) => this.normalizeUploadFile(file, index));
|
|
517
|
+
const currentFileList = this.getCurrentFileList();
|
|
518
|
+
|
|
519
|
+
if (!uploadFiles.length) return;
|
|
520
|
+
|
|
521
|
+
this.setDraftFileList([...currentFileList, ...uploadFiles], true);
|
|
522
|
+
this.requestCredential()
|
|
523
|
+
.then((credential) => {
|
|
524
|
+
this.uploadFilesSequentially(uploadFiles, credential, `${Date.now()}_${this.batchIndex + 1}`, 0, pipelineType);
|
|
525
|
+
this.batchIndex += 1;
|
|
526
|
+
})
|
|
527
|
+
.catch((error) => {
|
|
528
|
+
this.markFilesFailed(uploadFiles, "获取 OSS 签名失败", "credential", error);
|
|
529
|
+
});
|
|
530
|
+
},
|
|
531
|
+
uploadFilesSequentially(files, credential, token, index, pipelineType) {
|
|
532
|
+
if (index >= files.length) return;
|
|
533
|
+
|
|
534
|
+
const file = files[index];
|
|
535
|
+
|
|
536
|
+
this.cancelledIds[file.id] = false;
|
|
537
|
+
this.uploadTokens[file.id] = token;
|
|
538
|
+
this.uploadOneFile(file, credential, token, file.id, pipelineType)
|
|
539
|
+
.catch(() => {})
|
|
540
|
+
.then(() => {
|
|
541
|
+
this.uploadFilesSequentially(files, credential, token, index + 1, pipelineType);
|
|
542
|
+
});
|
|
543
|
+
},
|
|
544
|
+
uploadOneFile(file, credential, token, updateFileId, pipelineType) {
|
|
545
|
+
return new Promise((resolve, reject) => {
|
|
546
|
+
if (!this.isUploadActive(updateFileId, token)) {
|
|
547
|
+
resolve();
|
|
548
|
+
return;
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
const filePath = getFilePath(file);
|
|
552
|
+
const target = this.buildUploadTarget(file, credential);
|
|
553
|
+
|
|
554
|
+
if (!filePath) {
|
|
555
|
+
const error = {
|
|
556
|
+
message: "文件路径为空"
|
|
557
|
+
};
|
|
558
|
+
this.handleUploadFailure(updateFileId, token, "文件路径为空", error);
|
|
559
|
+
reject(error);
|
|
560
|
+
return;
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
const uploadTask = wx.uploadFile({
|
|
564
|
+
url: credential.host,
|
|
565
|
+
filePath,
|
|
566
|
+
name: "file",
|
|
567
|
+
formData: {
|
|
568
|
+
key: target.ossKey,
|
|
569
|
+
policy: credential.policy,
|
|
570
|
+
OSSAccessKeyId: credential.ossAccessKeyId,
|
|
571
|
+
success_action_status: 200,
|
|
572
|
+
signature: credential.signature
|
|
573
|
+
},
|
|
574
|
+
success: (response) => {
|
|
575
|
+
if (!this.isUploadActive(updateFileId, token)) {
|
|
576
|
+
resolve();
|
|
577
|
+
return;
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
if (response.statusCode === 200 || response.statusCode === 204) {
|
|
581
|
+
this.handleUploadSuccess(updateFileId, file, target, response, token, pipelineType)
|
|
582
|
+
.then(resolve)
|
|
583
|
+
.catch(reject);
|
|
584
|
+
return;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
this.handleUploadFailure(updateFileId, token, "OSS 上传失败", response);
|
|
588
|
+
reject(response);
|
|
589
|
+
},
|
|
590
|
+
fail: (error) => {
|
|
591
|
+
if (this.cancelledIds[updateFileId]) {
|
|
592
|
+
resolve();
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
this.handleUploadFailure(updateFileId, token, "OSS 上传失败", error);
|
|
597
|
+
reject(error);
|
|
598
|
+
},
|
|
599
|
+
complete: () => {
|
|
600
|
+
delete this.uploadTasks[updateFileId];
|
|
601
|
+
}
|
|
602
|
+
});
|
|
603
|
+
|
|
604
|
+
this.uploadTasks[updateFileId] = uploadTask;
|
|
605
|
+
|
|
606
|
+
if (uploadTask && typeof uploadTask.onProgressUpdate === "function") {
|
|
607
|
+
uploadTask.onProgressUpdate((progress) => {
|
|
608
|
+
if (!this.isUploadActive(updateFileId, token)) return;
|
|
609
|
+
|
|
610
|
+
const percent = clampPercent(progress.progress);
|
|
611
|
+
const result = this.updateFileById(
|
|
612
|
+
updateFileId,
|
|
613
|
+
(currentFile) => ({
|
|
614
|
+
...currentFile,
|
|
615
|
+
status: "uploading",
|
|
616
|
+
percent
|
|
617
|
+
}),
|
|
618
|
+
true
|
|
619
|
+
);
|
|
620
|
+
|
|
621
|
+
if (result) {
|
|
622
|
+
this.triggerEvent("progress", {
|
|
623
|
+
file: result.file,
|
|
624
|
+
index: result.index,
|
|
625
|
+
percent,
|
|
626
|
+
fileList: result.fileList
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
});
|
|
632
|
+
},
|
|
633
|
+
handleUploadSuccess(fileId, sourceFile, target, response, token, pipelineType) {
|
|
634
|
+
if (pipelineType === "cover") {
|
|
635
|
+
return this.handleCoverUploadSuccess(fileId, target, response, token);
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
if (sourceFile.type === "video") {
|
|
639
|
+
return this.handleVideoUploadSuccess(fileId, target, response, token);
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
return this.handleImageUploadSuccess(fileId, target, response, token);
|
|
643
|
+
},
|
|
644
|
+
handleImageUploadSuccess(fileId, target, response, token) {
|
|
645
|
+
const result = this.updateFileById(
|
|
646
|
+
fileId,
|
|
647
|
+
(currentFile) => ({
|
|
648
|
+
...currentFile,
|
|
649
|
+
url: target.url,
|
|
650
|
+
ossKey: target.ossKey,
|
|
651
|
+
imgPath: target.ossKey,
|
|
652
|
+
imgName: target.fileName,
|
|
653
|
+
response,
|
|
654
|
+
percent: 100,
|
|
655
|
+
status: this.data.audit ? "auditing" : "success",
|
|
656
|
+
message: ""
|
|
657
|
+
}),
|
|
658
|
+
true
|
|
659
|
+
);
|
|
660
|
+
|
|
661
|
+
if (!result) return Promise.resolve(response);
|
|
662
|
+
|
|
663
|
+
if (!this.data.audit) {
|
|
664
|
+
this.finishPipeline(fileId);
|
|
665
|
+
this.triggerEvent("success", result);
|
|
666
|
+
return Promise.resolve(response);
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
return this.requestAudit(result.file).then(
|
|
670
|
+
() => {
|
|
671
|
+
if (!this.isUploadActive(fileId, token)) return response;
|
|
672
|
+
|
|
673
|
+
const successResult = this.updateFileById(
|
|
674
|
+
fileId,
|
|
675
|
+
{
|
|
676
|
+
status: "success",
|
|
677
|
+
percent: 100,
|
|
678
|
+
message: ""
|
|
679
|
+
},
|
|
680
|
+
true
|
|
681
|
+
);
|
|
682
|
+
|
|
683
|
+
this.finishPipeline(fileId);
|
|
684
|
+
if (successResult) this.triggerEvent("success", successResult);
|
|
685
|
+
return response;
|
|
686
|
+
},
|
|
687
|
+
(auditError) => {
|
|
688
|
+
if (!this.isUploadActive(fileId, token)) return response;
|
|
689
|
+
|
|
690
|
+
const blocked = auditError && auditError.blocked;
|
|
691
|
+
const message = blocked ? "图片未通过审核" : "图片审核失败";
|
|
692
|
+
const status = blocked ? "rejected" : "fail";
|
|
693
|
+
const errorResult = this.updateFileById(
|
|
694
|
+
fileId,
|
|
695
|
+
{
|
|
696
|
+
status,
|
|
697
|
+
message
|
|
698
|
+
},
|
|
699
|
+
true
|
|
700
|
+
);
|
|
701
|
+
|
|
702
|
+
this.finishPipeline(fileId);
|
|
703
|
+
this.emitError("audit", message, auditError.error || auditError, errorResult ? errorResult.file : result.file);
|
|
704
|
+
|
|
705
|
+
if (blocked) {
|
|
706
|
+
this.deleteOssFile(result.file).catch((deleteError) => {
|
|
707
|
+
this.emitError("delete", "删除未通过审核的 OSS 文件失败", deleteError, result.file);
|
|
708
|
+
});
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
return response;
|
|
712
|
+
}
|
|
713
|
+
);
|
|
714
|
+
},
|
|
715
|
+
handleVideoUploadSuccess(fileId, target, response) {
|
|
716
|
+
const snapshot = this.data.enableVideoCover ? appendSnapshotProcess(target.url, normalizeCoverFrameStep(this.data.coverFrameStep)) : "";
|
|
717
|
+
const result = this.updateFileById(
|
|
718
|
+
fileId,
|
|
719
|
+
(currentFile) => ({
|
|
720
|
+
...currentFile,
|
|
721
|
+
url: target.url,
|
|
722
|
+
ossKey: target.ossKey,
|
|
723
|
+
videoPath: target.ossKey,
|
|
724
|
+
videoName: target.fileName,
|
|
725
|
+
cover: snapshot,
|
|
726
|
+
thumb: snapshot,
|
|
727
|
+
imgPath: snapshot,
|
|
728
|
+
imgName: snapshot ? "snapshot.jpg" : "",
|
|
729
|
+
response,
|
|
730
|
+
status: "success",
|
|
731
|
+
percent: 100,
|
|
732
|
+
message: ""
|
|
733
|
+
}),
|
|
734
|
+
true
|
|
735
|
+
);
|
|
736
|
+
|
|
737
|
+
this.finishPipeline(fileId);
|
|
738
|
+
if (result) this.triggerEvent("success", result);
|
|
739
|
+
return Promise.resolve(response);
|
|
740
|
+
},
|
|
741
|
+
handleCoverUploadSuccess(fileId, target, response, token) {
|
|
742
|
+
const finalize = () => {
|
|
743
|
+
if (!this.isUploadActive(fileId, token)) return response;
|
|
744
|
+
|
|
745
|
+
const result = this.updateFileById(
|
|
746
|
+
fileId,
|
|
747
|
+
(currentFile) => ({
|
|
748
|
+
...currentFile,
|
|
749
|
+
cover: target.url,
|
|
750
|
+
thumb: target.url,
|
|
751
|
+
imgPath: target.url,
|
|
752
|
+
imgName: target.fileName,
|
|
753
|
+
coverOssKey: target.ossKey,
|
|
754
|
+
status: "success",
|
|
755
|
+
percent: 100,
|
|
756
|
+
message: ""
|
|
757
|
+
}),
|
|
758
|
+
true
|
|
759
|
+
);
|
|
760
|
+
|
|
761
|
+
this.finishPipeline(fileId);
|
|
762
|
+
if (result) {
|
|
763
|
+
this.triggerEvent("coverchange", result);
|
|
764
|
+
this.triggerEvent("success", result);
|
|
765
|
+
}
|
|
766
|
+
return response;
|
|
767
|
+
};
|
|
768
|
+
|
|
769
|
+
if (!this.data.audit) return Promise.resolve(finalize());
|
|
770
|
+
|
|
771
|
+
return this.requestAudit({
|
|
772
|
+
url: target.url,
|
|
773
|
+
ossKey: target.ossKey
|
|
774
|
+
}).then(
|
|
775
|
+
finalize,
|
|
776
|
+
(auditError) => {
|
|
777
|
+
if (!this.isUploadActive(fileId, token)) return response;
|
|
778
|
+
|
|
779
|
+
const blocked = auditError && auditError.blocked;
|
|
780
|
+
const message = blocked ? "封面未通过审核" : "封面审核失败";
|
|
781
|
+
const status = blocked ? "rejected" : "fail";
|
|
782
|
+
const result = this.updateFileById(
|
|
783
|
+
fileId,
|
|
784
|
+
{
|
|
785
|
+
status,
|
|
786
|
+
message
|
|
787
|
+
},
|
|
788
|
+
true
|
|
789
|
+
);
|
|
790
|
+
|
|
791
|
+
this.finishPipeline(fileId);
|
|
792
|
+
this.emitError("audit", message, auditError.error || auditError, result ? result.file : null);
|
|
793
|
+
return response;
|
|
794
|
+
}
|
|
795
|
+
);
|
|
796
|
+
},
|
|
797
|
+
requestAudit(file) {
|
|
798
|
+
return new Promise((resolve, reject) => {
|
|
799
|
+
if (!this.data.auditUrl) {
|
|
800
|
+
reject({
|
|
801
|
+
source: "audit",
|
|
802
|
+
message: "auditUrl 不能为空",
|
|
803
|
+
error: {
|
|
804
|
+
message: "auditUrl 不能为空"
|
|
805
|
+
}
|
|
806
|
+
});
|
|
807
|
+
return;
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
wx.request({
|
|
811
|
+
url: this.data.auditUrl,
|
|
812
|
+
method: normalizeMethod(this.data.auditMethod, "POST"),
|
|
813
|
+
header: normalizeObject(this.data.auditHeader),
|
|
814
|
+
data: {
|
|
815
|
+
imgUrl: file.url,
|
|
816
|
+
url: file.url,
|
|
817
|
+
ossKey: file.ossKey
|
|
818
|
+
},
|
|
819
|
+
success: (response) => {
|
|
820
|
+
if (response.statusCode && response.statusCode >= 400) {
|
|
821
|
+
reject({
|
|
822
|
+
source: "audit",
|
|
823
|
+
error: response
|
|
824
|
+
});
|
|
825
|
+
return;
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
const payload = response && response.data && response.data.data ? response.data.data : response.data;
|
|
829
|
+
|
|
830
|
+
if (hasBlockSuggestion(payload)) {
|
|
831
|
+
reject({
|
|
832
|
+
source: "audit",
|
|
833
|
+
blocked: true,
|
|
834
|
+
error: response
|
|
835
|
+
});
|
|
836
|
+
return;
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
resolve(response);
|
|
840
|
+
},
|
|
841
|
+
fail: (error) => {
|
|
842
|
+
reject({
|
|
843
|
+
source: "audit",
|
|
844
|
+
error
|
|
845
|
+
});
|
|
846
|
+
}
|
|
847
|
+
});
|
|
848
|
+
});
|
|
849
|
+
},
|
|
850
|
+
deleteOssFile(file) {
|
|
851
|
+
return new Promise((resolve, reject) => {
|
|
852
|
+
if (!this.data.deleteUrl) {
|
|
853
|
+
resolve();
|
|
854
|
+
return;
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
wx.request({
|
|
858
|
+
url: this.data.deleteUrl,
|
|
859
|
+
method: normalizeMethod(this.data.deleteMethod, "DELETE"),
|
|
860
|
+
data: {
|
|
861
|
+
imgUrl: file.ossKey,
|
|
862
|
+
ossKey: file.ossKey,
|
|
863
|
+
url: file.url
|
|
864
|
+
},
|
|
865
|
+
success: (response) => {
|
|
866
|
+
if (response.statusCode && response.statusCode >= 400) {
|
|
867
|
+
reject(response);
|
|
868
|
+
return;
|
|
869
|
+
}
|
|
870
|
+
resolve(response);
|
|
871
|
+
},
|
|
872
|
+
fail: reject
|
|
873
|
+
});
|
|
874
|
+
});
|
|
875
|
+
},
|
|
876
|
+
markFilesFailed(files, message, source, error) {
|
|
877
|
+
const ids = files.map((file) => file.id);
|
|
878
|
+
const nextFileList = this.getCurrentFileList().map((file) =>
|
|
879
|
+
ids.includes(file.id)
|
|
880
|
+
? {
|
|
881
|
+
...file,
|
|
882
|
+
status: "fail",
|
|
883
|
+
message
|
|
884
|
+
}
|
|
885
|
+
: file
|
|
886
|
+
);
|
|
887
|
+
|
|
888
|
+
this.setDraftFileList(nextFileList, true);
|
|
889
|
+
files.forEach((file) => {
|
|
890
|
+
this.finishPipeline(file.id);
|
|
891
|
+
this.emitError(source, message, error, file);
|
|
892
|
+
});
|
|
893
|
+
},
|
|
894
|
+
handleUploadFailure(fileId, token, message, error) {
|
|
895
|
+
if (!this.isUploadActive(fileId, token)) return;
|
|
896
|
+
|
|
897
|
+
const result = this.updateFileById(
|
|
898
|
+
fileId,
|
|
899
|
+
{
|
|
900
|
+
status: "fail",
|
|
901
|
+
message
|
|
902
|
+
},
|
|
903
|
+
true
|
|
904
|
+
);
|
|
905
|
+
|
|
906
|
+
this.finishPipeline(fileId);
|
|
907
|
+
this.emitError("upload", message, error, result ? result.file : null);
|
|
908
|
+
},
|
|
909
|
+
handleCropConfirm(event) {
|
|
910
|
+
const detail = event.detail || {};
|
|
911
|
+
const files = normalizeFileList(detail.files || detail.fileList).map((file, index) => this.normalizeUploadFile(file, index));
|
|
912
|
+
|
|
913
|
+
this.triggerEvent("crop", detail);
|
|
914
|
+
this.setData({
|
|
915
|
+
showCropper: false,
|
|
916
|
+
cropFileList: [],
|
|
917
|
+
cropSrc: ""
|
|
918
|
+
});
|
|
919
|
+
|
|
920
|
+
if (this.cropTarget === "cover") {
|
|
921
|
+
this.uploadCoverFile(files[0]);
|
|
922
|
+
return;
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
this.processUploadFiles(files, "image");
|
|
926
|
+
},
|
|
927
|
+
handleCropCancel() {
|
|
928
|
+
this.setData({
|
|
929
|
+
showCropper: false,
|
|
930
|
+
cropFileList: [],
|
|
931
|
+
cropSrc: "",
|
|
932
|
+
showCoverPanel: false
|
|
933
|
+
});
|
|
934
|
+
this.cropTarget = "";
|
|
935
|
+
this.coverTargetFileId = "";
|
|
936
|
+
},
|
|
937
|
+
handleCropError(event) {
|
|
938
|
+
this.emitError("crop", event.detail.message || "裁剪失败", event.detail, null);
|
|
939
|
+
},
|
|
940
|
+
uploadCoverFile(file) {
|
|
941
|
+
const targetFileId = this.coverTargetFileId;
|
|
942
|
+
|
|
943
|
+
this.cropTarget = "";
|
|
944
|
+
this.coverTargetFileId = "";
|
|
945
|
+
|
|
946
|
+
if (!targetFileId || !file) return;
|
|
947
|
+
|
|
948
|
+
this.cancelledIds[targetFileId] = false;
|
|
949
|
+
this.requestCredential()
|
|
950
|
+
.then((credential) => {
|
|
951
|
+
const token = `${Date.now()}_${this.batchIndex + 1}`;
|
|
952
|
+
this.batchIndex += 1;
|
|
953
|
+
this.uploadTokens[targetFileId] = token;
|
|
954
|
+
this.updateFileById(
|
|
955
|
+
targetFileId,
|
|
956
|
+
{
|
|
957
|
+
status: "uploading",
|
|
958
|
+
percent: 0,
|
|
959
|
+
message: ""
|
|
960
|
+
},
|
|
961
|
+
true
|
|
962
|
+
);
|
|
963
|
+
return this.uploadOneFile(file, credential, token, targetFileId, "cover");
|
|
964
|
+
})
|
|
965
|
+
.catch((error) => {
|
|
966
|
+
this.handleUploadFailure(targetFileId, this.uploadTokens[targetFileId], "封面上传失败", error);
|
|
967
|
+
});
|
|
968
|
+
},
|
|
969
|
+
handleDelete(event) {
|
|
970
|
+
const file = event.detail.file;
|
|
971
|
+
const nextFileList = normalizeMainFlags(normalizeFileList(event.detail.fileList));
|
|
972
|
+
|
|
973
|
+
if (file && file.id) {
|
|
974
|
+
const uploadTask = this.uploadTasks[file.id];
|
|
975
|
+
this.cancelledIds[file.id] = true;
|
|
976
|
+
delete this.uploadTokens[file.id];
|
|
977
|
+
delete this.uploadTasks[file.id];
|
|
978
|
+
|
|
979
|
+
if (uploadTask && typeof uploadTask.abort === "function") {
|
|
980
|
+
uploadTask.abort();
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
this.setDraftFileList(nextFileList, true);
|
|
985
|
+
this.triggerEvent("delete", {
|
|
986
|
+
file,
|
|
987
|
+
index: event.detail.index,
|
|
988
|
+
fileList: this.getCurrentFileList()
|
|
989
|
+
});
|
|
990
|
+
},
|
|
991
|
+
handlePreview(event) {
|
|
992
|
+
const detail = event.detail || {};
|
|
993
|
+
const index = Number(detail.index);
|
|
994
|
+
const file = detail.file || this.getCurrentFileList()[index];
|
|
995
|
+
|
|
996
|
+
this.triggerEvent("preview", detail);
|
|
997
|
+
|
|
998
|
+
if (!this.data.preview || !file) return;
|
|
999
|
+
|
|
1000
|
+
const currentIndex = Number.isFinite(index) && index >= 0 ? index : this.findFileIndex(file.id);
|
|
1001
|
+
const previewFile = normalizePreviewFile(file);
|
|
1002
|
+
|
|
1003
|
+
this.previewFileId = previewFile.id || "";
|
|
1004
|
+
this.setData({
|
|
1005
|
+
showPreview: true,
|
|
1006
|
+
previewFile,
|
|
1007
|
+
previewIndex: currentIndex,
|
|
1008
|
+
previewTitle: previewFile._isVideo ? "预览视频" : "预览封面",
|
|
1009
|
+
previewHeaderStyle: getPreviewHeaderStyle()
|
|
1010
|
+
});
|
|
1011
|
+
},
|
|
1012
|
+
handleClosePreview() {
|
|
1013
|
+
this.previewFileId = "";
|
|
1014
|
+
this.setData({
|
|
1015
|
+
showPreview: false,
|
|
1016
|
+
previewFile: {},
|
|
1017
|
+
previewIndex: -1
|
|
1018
|
+
});
|
|
1019
|
+
},
|
|
1020
|
+
handlePreviewTouchMove() {},
|
|
1021
|
+
handleUploadError(event) {
|
|
1022
|
+
this.emitError(event.detail.source || "choose", event.detail.message || "媒体选择失败", event.detail.error || event.detail);
|
|
1023
|
+
},
|
|
1024
|
+
handleSetMain(event) {
|
|
1025
|
+
if (this.data.disabled) return;
|
|
1026
|
+
|
|
1027
|
+
const fileId = event.currentTarget.dataset.id || this.previewFileId;
|
|
1028
|
+
const currentFileList = this.getCurrentFileList();
|
|
1029
|
+
const index = currentFileList.findIndex((file) => file.id === fileId);
|
|
1030
|
+
|
|
1031
|
+
if (index <= 0) return;
|
|
1032
|
+
|
|
1033
|
+
const target = currentFileList[index];
|
|
1034
|
+
const nextFileList = [target, ...currentFileList.filter((file) => file.id !== fileId)];
|
|
1035
|
+
|
|
1036
|
+
this.setDraftFileList(nextFileList, true);
|
|
1037
|
+
this.triggerEvent("setmain", {
|
|
1038
|
+
file: this.getCurrentFileList()[0],
|
|
1039
|
+
index: 0,
|
|
1040
|
+
fileList: this.getCurrentFileList()
|
|
1041
|
+
});
|
|
1042
|
+
this.handleClosePreview();
|
|
1043
|
+
},
|
|
1044
|
+
handleOpenCoverPanel(event) {
|
|
1045
|
+
if (this.data.disabled) return;
|
|
1046
|
+
|
|
1047
|
+
const fileId = event.currentTarget.dataset.id || this.previewFileId;
|
|
1048
|
+
const file = this.getCurrentFileList().find((item) => item.id === fileId);
|
|
1049
|
+
|
|
1050
|
+
if (!file || file.type !== "video") return;
|
|
1051
|
+
|
|
1052
|
+
const count = normalizeCoverFrameCount(this.data.coverFrameCount);
|
|
1053
|
+
const step = normalizeCoverFrameStep(this.data.coverFrameStep);
|
|
1054
|
+
const baseUrl = file.url || file.videoUrl || file.videoPath || "";
|
|
1055
|
+
const coverCandidates = Array.from({ length: count }).map((_item, index) => {
|
|
1056
|
+
const time = (index + 1) * step;
|
|
1057
|
+
|
|
1058
|
+
return {
|
|
1059
|
+
url: appendSnapshotProcess(baseUrl, time),
|
|
1060
|
+
rowEnd: index % 3 === 2
|
|
1061
|
+
};
|
|
1062
|
+
});
|
|
1063
|
+
|
|
1064
|
+
this.coverTargetFileId = fileId;
|
|
1065
|
+
this.setData({
|
|
1066
|
+
showPreview: false,
|
|
1067
|
+
previewFile: {},
|
|
1068
|
+
previewIndex: -1,
|
|
1069
|
+
showCoverPanel: true,
|
|
1070
|
+
coverCandidates
|
|
1071
|
+
});
|
|
1072
|
+
},
|
|
1073
|
+
handleCloseCoverPanel() {
|
|
1074
|
+
this.coverTargetFileId = "";
|
|
1075
|
+
this.setData({
|
|
1076
|
+
showCoverPanel: false,
|
|
1077
|
+
coverCandidates: []
|
|
1078
|
+
});
|
|
1079
|
+
},
|
|
1080
|
+
handleSelectCoverCandidate(event) {
|
|
1081
|
+
const url = event.currentTarget.dataset.url;
|
|
1082
|
+
|
|
1083
|
+
if (!url || !this.coverTargetFileId) return;
|
|
1084
|
+
|
|
1085
|
+
this.cropTarget = "cover";
|
|
1086
|
+
this.setData({
|
|
1087
|
+
showCoverPanel: false,
|
|
1088
|
+
coverCandidates: [],
|
|
1089
|
+
showCropper: true,
|
|
1090
|
+
cropSrc: url,
|
|
1091
|
+
cropFileList: []
|
|
1092
|
+
});
|
|
1093
|
+
},
|
|
1094
|
+
abortAllUploads() {
|
|
1095
|
+
Object.keys(this.uploadTasks || {}).forEach((fileId) => {
|
|
1096
|
+
const uploadTask = this.uploadTasks[fileId];
|
|
1097
|
+
this.cancelledIds[fileId] = true;
|
|
1098
|
+
|
|
1099
|
+
if (uploadTask && typeof uploadTask.abort === "function") {
|
|
1100
|
+
uploadTask.abort();
|
|
1101
|
+
}
|
|
1102
|
+
});
|
|
1103
|
+
|
|
1104
|
+
this.uploadTasks = {};
|
|
1105
|
+
this.uploadTokens = {};
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
});
|