60 lines
1.2 KiB
Vue
60 lines
1.2 KiB
Vue
<template>
|
|
<view class="box">
|
|
<image id="img" src="https://static.hshuishang.com/water_filter/customer.jpg" mode="widthFix"/>
|
|
|
|
<view class="btn" @click="save">保存到相册</view>
|
|
</view>
|
|
</template>
|
|
|
|
<script>
|
|
export default {
|
|
data() {
|
|
return {
|
|
|
|
}
|
|
},
|
|
|
|
methods: {
|
|
save() {
|
|
uni.downloadFile({
|
|
url: 'https://static.hshuishang.com/water_filter/customer.jpg',
|
|
success(res) {
|
|
console.log('downloadFile res', res);
|
|
if (res.statusCode === 200) {
|
|
const tempFilePath = res.tempFilePath; // 获取临时文件路径
|
|
|
|
// 保存图片到相册
|
|
uni.saveImageToPhotosAlbum({
|
|
filePath: tempFilePath,
|
|
success() {
|
|
uni.showToast({
|
|
title: '保存成功',
|
|
icon: 'success',
|
|
});
|
|
},
|
|
fail(err) {
|
|
console.error('保存失败', err);
|
|
uni.showToast({
|
|
title: '保存失败,请重试',
|
|
icon: 'none',
|
|
});
|
|
},
|
|
});
|
|
}
|
|
},
|
|
fail(err) {
|
|
console.error('下载失败', err);
|
|
uni.showToast({
|
|
title: '下载失败,请重试',
|
|
icon: 'none',
|
|
});
|
|
},
|
|
});
|
|
},
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style>
|
|
@import url("./index.css");
|
|
</style> |