feat: 上传图片
This commit is contained in:
parent
6e79d1658d
commit
d414e56d9c
|
@ -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)),
|
||||
});
|
||||
},
|
||||
// 异常上报
|
||||
|
|
|
@ -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) {
|
||||
// 成功的处理
|
||||
|
|
Loading…
Reference in New Issue