图片上传

parent 5ed31e72
......@@ -77,7 +77,7 @@
</template>
<script setup>
import { showImagePreview } from 'vant';
import { showToast, showSuccessToast, showFailToast } from 'vant';
import { selectPictureById } from '@/api/publish'
import { useInitScroll } from '@/hooks/useScroll'
......@@ -145,66 +145,36 @@ const convertSize = (sizeInKB) => {
// 下载图片
const handleDownload = () => {
xma.downloadFile({
url: previewImages.value[index.value], // 替换为你要下载的图片URL
success: (res) => {
if (res.statusCode === 200) {
// 下载成功后保存图片到相册
saveImage(res.tempFilePath);
} else {
console.error('下载图片失败');
}
},
fail: (err) => {
console.error('下载图片失败', err);
}
});
// #ifdef H5-SGY
showToast('请长按保存图片');
return
// #endif
saveImage(previewImages.value[index.value]);
}
function saveImage(filePath) {
// 创建一个<a>元素
const link = document.createElement('a');
link.href = filePath;
// 设置下载的文件名
link.download = catalog.value.enclosureList[index.value].enclosureDesc + '.jpg';
// 触发点击事件
document.body.appendChild(link); link.click();
// 移除该元素
document.body.removeChild(link);
uni.showToast({
title: '下载成功',
icon: 'success'
})
function saveImage(url) {
fetch(url)
.then(response => response.blob())
.then(blob => {
// 创建一个下载链接
const link = document.createElement('a');
const objectUrl = URL.createObjectURL(blob);
link.href = objectUrl;
// 设置下载的文件名和后缀
link.download = catalog.value.enclosureList[index.value].enclosureDesc + '.jpg';
// 触发点击事件
document.body.appendChild(link);
link.click();
// 移除下载链接
document.body.removeChild(link);
URL.revokeObjectURL(objectUrl);
showSuccessToast('下载成功');
})
.catch(error => {
showFailToast('下载失败');
console.log('下载图片失败', error)
});
}
// function saveImage(url) {
// fetch(url)
// .then(response => response.blob())
// .then(blob => {
// // 创建一个下载链接
// const link = document.createElement('a');
// const objectUrl = URL.createObjectURL(blob);
// link.href = objectUrl;
// // 设置下载的文件名和后缀
// link.download = catalog.value.enclosureList[index.value].enclosureDesc + '.jpg';
// // 触发点击事件
// document.body.appendChild(link);
// link.click();
// // 移除下载链接
// document.body.removeChild(link);
// URL.revokeObjectURL(objectUrl);
// uni.showToast({
// title: '下载成功',
// icon: 'success'
// })
// })
// .catch(error => {
// uni.showToast({
// title: '下载失败',
// icon: 'none'
// })
// console.log('下载图片失败', error)
// });
// }
</script>
......
<template>
<Header :show="false" backgroundBox="white">
<van-nav-bar title="图组" :left-arrow="true" fixed placeholder @click-left="router.go(-1)" />
<van-nav-bar title="图组" :left-arrow="true" fixed placeholder @click-left="back" />
</Header>
<div class="container">
<div class="steps-placeholder" :style="{ height: `${stepsRef?.offsetHeight}px` }">
......@@ -89,6 +89,10 @@ const setCatalog = () => {
catalog.value.coverpicture = enclosureLists.value[coverIndex.value].enclosureAddr
}
const back = () => {
xma.navigateBack()
}
</script>
<style lang="scss" scoped>
:deep(#u-a-c .uni-system-choose-location .nav) {
......@@ -102,13 +106,13 @@ const setCatalog = () => {
:deep(#u-a-c .uni-system-choose-location .nav-btn.back) {
background-color: #007aff;
border-radius: 10px;
top: 50px;
top: 80px;
left: 10px;
}
:deep(#u-a-c .uni-system-choose-location .nav-btn.confirm) {
background-color: #007aff;
border-radius: 10px;
top: 50px;
top: 80px;
right: 10px;
}
.steps-container {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment