feat: 上传图片
This commit is contained in:
parent
6e79d1658d
commit
d414e56d9c
|
@ -83,7 +83,7 @@
|
||||||
<view class="content-title">刷卡成功</view>
|
<view class="content-title">刷卡成功</view>
|
||||||
<view class="btn-box">
|
<view class="btn-box">
|
||||||
<view class="btn-cancel" @click="successShow = false">暂不</view>
|
<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>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
@ -199,13 +199,20 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// 上传图片
|
// 上传图片
|
||||||
uploadFn() {
|
toUploadPage() {
|
||||||
console.log("%c%s", "color:red", "上传图片");
|
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;
|
this.successShow = false;
|
||||||
uni.navigateTo({
|
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">
|
||||||
<view class="content-header-title">
|
<view class="content-header-title">
|
||||||
{{ areaName }} — {{ planName }}
|
{{ params.aeraNmae }} — {{ params.planName }}
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
|
@ -111,9 +111,15 @@ export default {
|
||||||
// 备注
|
// 备注
|
||||||
remark: "",
|
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() {},
|
created() {},
|
||||||
methods: {
|
methods: {
|
||||||
switchTab(tab) {
|
switchTab(tab) {
|
||||||
|
@ -137,9 +143,8 @@ export default {
|
||||||
sourceType: ["camera"], // 仅限拍照
|
sourceType: ["camera"], // 仅限拍照
|
||||||
sizeType: ["compressed"], // 压缩图片
|
sizeType: ["compressed"], // 压缩图片
|
||||||
success: async (res) => {
|
success: async (res) => {
|
||||||
console.log("拍照成功", res);
|
// console.log("拍照成功", res);
|
||||||
|
this.imageList = [...this.imageList, res.tempFilePaths[0]];
|
||||||
this.uploadFiles(res.tempFilePaths[0]);
|
|
||||||
},
|
},
|
||||||
fail: (err) => {
|
fail: (err) => {
|
||||||
uni.showToast({ title: "拍照失败,请重试", icon: "none" });
|
uni.showToast({ title: "拍照失败,请重试", icon: "none" });
|
||||||
|
@ -175,19 +180,22 @@ export default {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const picturesDto = this.imageList.map((item) => {
|
const params = {
|
||||||
return {
|
id: this.params.areaId,
|
||||||
path: item,
|
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);
|
console.log("提交表单", picturesDto, this.remark);
|
||||||
|
|
||||||
const res = await UploadArea({
|
const res = await UploadArea(formData);
|
||||||
id: this.id,
|
|
||||||
picturesDto: picturesDto,
|
|
||||||
note: this.remark,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (res.succeed) {
|
if (res.succeed) {
|
||||||
// 成功的处理
|
// 成功的处理
|
||||||
|
|
Loading…
Reference in New Issue