Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
jiaxiu-miniapp
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
蔡亮华(贵阳日报)
jiaxiu-miniapp
Commits
edf721fb
Commit
edf721fb
authored
Aug 29, 2024
by
彭佳妮(贵阳日报)
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
下载图片
parent
a2a4958a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
63 deletions
+43
-63
detail.vue
src/pages/classify/detail.vue
+43
-63
No files found.
src/pages/classify/detail.vue
View file @
edf721fb
...
...
@@ -145,30 +145,6 @@ const convertSize = (sizeInKB) => {
// 下载图片
const
handleDownload
=
()
=>
{
// uni.downloadFile({
// url: previewImages.value[index.value],
// success: (res) => {
// if (res.statusCode === 200) {
// // 保存图片到相册
// plus.gallery.save(res.tempFilePath, () => {
// uni.showToast({
// title: '图片保存成功',
// icon: 'success'
// });
// }, (err) => {
// console.error('保存图片失败', err);
// uni.showToast({
// title: '图片保存失败',
// icon: 'none'
// });
// });
// } else {
// console.error('图片下载失败');
// }
// }, fail: (err) => {
// console.error('图片下载失败', err);
// }
// });
xma
.
downloadFile
({
url
:
previewImages
.
value
[
index
.
value
],
// 替换为你要下载的图片URL
success
:
(
res
)
=>
{
...
...
@@ -185,46 +161,50 @@ const handleDownload = () => {
});
}
// 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);
// }
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
)
});
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);
// uni.showToast({
// title: '下载成功',
// icon: 'success'
// })
// })
// .catch(error => {
// uni.showToast({
// title: '下载失败',
// icon: 'none'
// })
// console.log('下载图片失败', error)
// });
// }
</
script
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment