|
|
@@ -1,3 +1,5 @@
|
|
|
+import { upload } from "../../../../lib/request/upload";
|
|
|
+
|
|
|
Component({
|
|
|
properties: {
|
|
|
visible: { type: Boolean, value: false },
|
|
|
@@ -7,6 +9,7 @@ Component({
|
|
|
data: {
|
|
|
inputDesc: "",
|
|
|
inputImages: [] as string[],
|
|
|
+ uploading: false,
|
|
|
},
|
|
|
observers: {
|
|
|
visible(v: boolean) {
|
|
|
@@ -36,16 +39,44 @@ Component({
|
|
|
wx.showToast({ title: "最多上传9张", icon: "none" });
|
|
|
return;
|
|
|
}
|
|
|
- wx.chooseImage({
|
|
|
+ wx.chooseMedia({
|
|
|
count: remain,
|
|
|
- sizeType: ["compressed"],
|
|
|
+ mediaType: ["image"],
|
|
|
sourceType: ["album", "camera"],
|
|
|
+ camera: "back",
|
|
|
success: (res) => {
|
|
|
- const next = [...this.data.inputImages, ...res.tempFilePaths].slice(0, 9);
|
|
|
- this.setData({ inputImages: next });
|
|
|
+ const tempPaths = res.tempFiles.map((f) => f.tempFilePath);
|
|
|
+ this.setData({ uploading: true });
|
|
|
+ this._uploadSequentially(tempPaths, 0);
|
|
|
},
|
|
|
});
|
|
|
},
|
|
|
+ _uploadSequentially(paths: string[], index: number) {
|
|
|
+ if (index >= paths.length) {
|
|
|
+ this.setData({ uploading: false });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ upload<string, any>({
|
|
|
+ params: { name: "file", file: paths[index] },
|
|
|
+ transform({ data }: any): string {
|
|
|
+ return (data as any)?.url || (data as any);
|
|
|
+ },
|
|
|
+ }).then(
|
|
|
+ (url) => {
|
|
|
+ this.setData({
|
|
|
+ inputImages: [...this.data.inputImages, url],
|
|
|
+ });
|
|
|
+ this._uploadSequentially(paths, index + 1);
|
|
|
+ },
|
|
|
+ (error: any) => {
|
|
|
+ wx.showToast({
|
|
|
+ title: error?.errMsg || "上传失败",
|
|
|
+ icon: "none",
|
|
|
+ });
|
|
|
+ this.setData({ uploading: false });
|
|
|
+ }
|
|
|
+ );
|
|
|
+ },
|
|
|
onRemoveImage(e: WechatMiniprogram.TouchEvent) {
|
|
|
const index = Number((e.currentTarget.dataset as { index?: number })?.index ?? -1);
|
|
|
if (index < 0) return;
|
|
|
@@ -54,6 +85,7 @@ Component({
|
|
|
this.setData({ inputImages: next });
|
|
|
},
|
|
|
onConfirm() {
|
|
|
+ if (this.data.uploading) return;
|
|
|
this.triggerEvent("confirm", {
|
|
|
desc: this.data.inputDesc,
|
|
|
images: this.data.inputImages,
|