Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
admin
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
afcb7e76
authored
Jul 05, 2024
by
cherishsince
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【解决todo】图片下载抽离到 download
parent
557dc7d5
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
20 deletions
+20
-20
src/utils/download.ts
+19
-0
src/views/ai/image/ImageTask.vue
+1
-20
No files found.
src/utils/download.ts
View file @
afcb7e76
...
@@ -36,3 +36,22 @@ const download = {
...
@@ -36,3 +36,22 @@ const download = {
}
}
export
default
download
export
default
download
/** 图片下载(通过浏览器图片下载) */
export
const
downloadImage
=
async
(
imageUrl
)
=>
{
const
image
=
new
Image
()
image
.
setAttribute
(
'crossOrigin'
,
'anonymous'
)
image
.
src
=
imageUrl
image
.
onload
=
()
=>
{
const
canvas
=
document
.
createElement
(
'canvas'
)
canvas
.
width
=
image
.
width
canvas
.
height
=
image
.
height
const
ctx
=
canvas
.
getContext
(
'2d'
)
as
CanvasDrawImage
ctx
.
drawImage
(
image
,
0
,
0
,
image
.
width
,
image
.
height
)
const
url
=
canvas
.
toDataURL
(
'image/png'
)
const
a
=
document
.
createElement
(
'a'
)
a
.
href
=
url
a
.
download
=
'image.png'
a
.
click
()
}
}
src/views/ai/image/ImageTask.vue
View file @
afcb7e76
...
@@ -33,6 +33,7 @@ import ImageDetailDrawer from './ImageDetailDrawer.vue'
...
@@ -33,6 +33,7 @@ import ImageDetailDrawer from './ImageDetailDrawer.vue'
import
ImageTaskCard
from
'./ImageTaskCard.vue'
import
ImageTaskCard
from
'./ImageTaskCard.vue'
import
{
ElLoading
,
LoadingOptionsResolved
}
from
'element-plus'
import
{
ElLoading
,
LoadingOptionsResolved
}
from
'element-plus'
import
{
AiImageStatusEnum
}
from
'@/views/ai/utils/constants'
import
{
AiImageStatusEnum
}
from
'@/views/ai/utils/constants'
import
{
downloadImage
}
from
'@/utils/download'
const
message
=
useMessage
()
// 消息弹窗
const
message
=
useMessage
()
// 消息弹窗
...
@@ -150,26 +151,6 @@ const handleImageMjBtnClick = async (button: ImageMjButtonsVO, imageDetail: Imag
...
@@ -150,26 +151,6 @@ const handleImageMjBtnClick = async (button: ImageMjButtonsVO, imageDetail: Imag
await
getImageList
()
await
getImageList
()
}
}
/** 下载 - image */
// TODO @fan:貌似可以考虑抽到 download 里面,作为一个方法
const
downloadImage
=
async
(
imageUrl
)
=>
{
const
image
=
new
Image
()
image
.
setAttribute
(
'crossOrigin'
,
'anonymous'
)
image
.
src
=
imageUrl
image
.
onload
=
()
=>
{
const
canvas
=
document
.
createElement
(
'canvas'
)
canvas
.
width
=
image
.
width
canvas
.
height
=
image
.
height
const
ctx
=
canvas
.
getContext
(
'2d'
)
as
CanvasDrawImage
ctx
.
drawImage
(
image
,
0
,
0
,
image
.
width
,
image
.
height
)
const
url
=
canvas
.
toDataURL
(
'image/png'
)
const
a
=
document
.
createElement
(
'a'
)
a
.
href
=
url
a
.
download
=
'image.png'
a
.
click
()
}
}
// page change
// page change
const
handlePageChange
=
async
(
page
)
=>
{
const
handlePageChange
=
async
(
page
)
=>
{
pageNo
.
value
=
page
pageNo
.
value
=
page
...
...
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