feat: 上传图片

This commit is contained in:
yangzhe 2025-04-11 11:50:55 +08:00
parent 6e79d1658d
commit d414e56d9c
2 changed files with 33 additions and 18 deletions

View File

@ -83,7 +83,7 @@
<view class="content-title">刷卡成功</view>
<view class="btn-box">
<view class="btn-cancel" @click="successShow = false">暂不</view>
<view class="btn-success" @click="uploadFn">上传图片</view>
<view class="btn-success" @click="toUploadPage">上传图片</view>
</view>
</view>
</view>
@ -199,13 +199,20 @@ export default {
}
},
//
uploadFn() {
toUploadPage() {
console.log("%c%s", "color:red", "上传图片");
const params = {
planName: this.dataInfo.planName,
areaId: this.dataInfo.areas[this.dataInfo.areas.length - 1].id,
aeraNmae: this.dataInfo.areas[this.dataInfo.areas.length - 1].aeraNmae,
};
console.log(params);
//
this.successShow = false;
uni.navigateTo({
url: "/pages/index/uploadPhoto",
url: "/pages/index/uploadPhoto?params=" + encodeURIComponent(JSON.stringify(params)),
});
},
//

View File

@ -36,7 +36,7 @@
<view class="content-header">
<view class="content-header-title">
{{ areaName }} {{ planName }}
{{ params.aeraNmae }} {{ params.planName }}
</view>
</view>
@ -111,9 +111,15 @@ export default {
//
remark: "",
imageList: ["/static/images/logo.png"], //
imageList: [], //
params: {},
};
},
onLoad(options) {
console.log("options", JSON.parse(decodeURIComponent(options.params)));
this.params = JSON.parse(decodeURIComponent(options.params));
},
created() {},
methods: {
switchTab(tab) {
@ -137,9 +143,8 @@ export default {
sourceType: ["camera"], //
sizeType: ["compressed"], //
success: async (res) => {
console.log("拍照成功", res);
this.uploadFiles(res.tempFilePaths[0]);
// console.log("", res);
this.imageList = [...this.imageList, res.tempFilePaths[0]];
},
fail: (err) => {
uni.showToast({ title: "拍照失败,请重试", icon: "none" });
@ -175,19 +180,22 @@ export default {
return;
}
const picturesDto = this.imageList.map((item) => {
return {
path: item,
};
});
const params = {
id: this.params.areaId,
note: this.remark,
};
const formData = new FormData();
formData.append("id", this.params.areaId);
formData.append("note", this.remark);
for (const file of this.imageList) {
formData.append("files", file);
}
console.log("提交表单", params);
console.log("提交表单", picturesDto, this.remark);
const res = await UploadArea({
id: this.id,
picturesDto: picturesDto,
note: this.remark,
});
const res = await UploadArea(formData);
if (res.succeed) {
//