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
46600c20
Commit
46600c20
authored
Aug 29, 2024
by
彭佳妮(贵阳日报)
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
图片上传
parent
5ed31e72
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
61 deletions
+35
-61
detail.vue
src/pages/classify/detail.vue
+28
-58
index.vue
src/pages/publish/index.vue
+7
-3
No files found.
src/pages/classify/detail.vue
View file @
46600c20
...
...
@@ -77,7 +77,7 @@
</template>
<
script
setup
>
import
{
show
ImagePreview
}
from
'vant'
;
import
{
show
Toast
,
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
>
...
...
src/pages/publish/index.vue
View file @
46600c20
<
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
:
5
0px
;
top
:
8
0px
;
left
:
10px
;
}
:deep
(
#u-a-c
.uni-system-choose-location
.nav-btn.confirm
)
{
background-color
:
#007aff
;
border-radius
:
10px
;
top
:
5
0px
;
top
:
8
0px
;
right
:
10px
;
}
.steps-container
{
...
...
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