Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
AI_BOOK_TOOL
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
template admin
AI_BOOK_TOOL
Commits
0a07f8d1
Commit
0a07f8d1
authored
May 12, 2025
by
liujiangnan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 图片编辑
parent
f26bf78e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
224 additions
and
1 deletion
+224
-1
index.css
form/index.css
+65
-0
index.html
form/index.html
+57
-0
index.js
form/index.js
+102
-1
No files found.
form/index.css
View file @
0a07f8d1
...
...
@@ -351,4 +351,69 @@ html, body {
right
:
0
;
height
:
2px
;
background-color
:
#409EFF
;
}
/* 全屏按钮 */
.fullscreen-btn
{
position
:
absolute
;
right
:
15px
;
top
:
15px
;
z-index
:
100
;
opacity
:
0.8
;
transition
:
opacity
0.3s
;
box-shadow
:
0
2px
12px
0
rgba
(
0
,
0
,
0
,
0.1
);
}
.fullscreen-btn
:hover
{
opacity
:
1
;
}
/* 全屏编辑器 */
.fullscreen-editor
{
position
:
fixed
;
top
:
0
;
left
:
0
;
right
:
0
;
bottom
:
0
;
background-color
:
rgba
(
0
,
0
,
0
,
0.7
);
z-index
:
2000
;
display
:
flex
;
justify-content
:
center
;
align-items
:
center
;
padding
:
20px
;
}
.fullscreen-content
{
background-color
:
#fff
;
border-radius
:
4px
;
width
:
100%
;
height
:
100%
;
display
:
flex
;
flex-direction
:
column
;
overflow
:
hidden
;
}
.fullscreen-content
.image-container
{
flex
:
1
;
margin
:
0
;
border
:
none
;
border-radius
:
0
;
display
:
flex
;
justify-content
:
center
;
align-items
:
center
;
background-color
:
#f5f7fa
;
}
.fullscreen-content
.image-wrapper
{
position
:
relative
;
display
:
flex
;
justify-content
:
center
;
align-items
:
center
;
line-height
:
0
;
}
.fullscreen-content
img
{
display
:
block
;
max-width
:
100%
;
max-height
:
100%
;
}
\ No newline at end of file
form/index.html
View file @
0a07f8d1
...
...
@@ -70,6 +70,63 @@
@
click=
"addNewRect"
>
<i
class=
"el-icon-plus"
></i>
</el-button>
<el-button
class=
"fullscreen-btn"
type=
"primary"
circle
size=
"small"
@
click=
"toggleFullscreen"
>
<i
:class=
"isFullscreen ? 'el-icon-close' : 'el-icon-full-screen'"
></i>
</el-button>
</div>
</div>
<!-- 全屏浮层 -->
<div
class=
"fullscreen-editor"
v-if=
"isFullscreen"
@
click
.
self=
"toggleFullscreen"
>
<div
class=
"fullscreen-content"
>
<div
class=
"image-container"
ref=
"fullscreenContainer"
>
<div
class=
"image-wrapper"
>
<img
:src=
"currentPage.image_url"
ref=
"fullscreenImage"
@
load=
"handleFullscreenImageLoad"
>
<template
v-for=
"(group, groupIndex) in currentPage.groups"
>
<div
v-for=
"(item, itemIndex) in group.group"
:key=
"groupIndex + '-' + itemIndex"
class=
"text-rect"
:class=
"{
'selected': selectedGroup === groupIndex,
'highlighted': selectedGroup === groupIndex && selectedItemIndex === itemIndex
}"
:style=
"getFullscreenRectStyle(item.rect)"
@
mousedown=
"startDrag($event, groupIndex, itemIndex)"
>
<div
class=
"resize-handle"
@
mousedown
.
stop=
"startResize($event, groupIndex, itemIndex)"
></div>
<el-button
class=
"delete-rect-btn"
type=
"danger"
size=
"mini"
circle
@
click
.
stop=
"deleteRectFromGroup(selectedGroup, itemIndex)"
>
<i
class=
"el-icon-delete"
></i>
</el-button>
</div>
</template>
</div>
<el-button
class=
"add-rect-btn"
type=
"primary"
circle
size=
"small"
@
click=
"addNewRect"
>
<i
class=
"el-icon-plus"
></i>
</el-button>
<el-button
class=
"fullscreen-btn"
type=
"primary"
circle
size=
"small"
@
click=
"toggleFullscreen"
>
<i
class=
"el-icon-close"
></i>
</el-button>
</div>
</div>
</div>
</el-col>
...
...
form/index.js
View file @
0a07f8d1
...
...
@@ -30,7 +30,13 @@ new Vue({
imageWidth
:
0
,
imageHeight
:
0
,
imageLoaded
:
false
,
imageRect
:
null
imageRect
:
null
,
// 全屏相关
isFullscreen
:
false
,
fullscreenImageWidth
:
0
,
fullscreenImageHeight
:
0
,
fullscreenImageRect
:
null
},
mounted
()
{
...
...
@@ -733,6 +739,101 @@ new Vue({
sentence
=
sentence
.
slice
(
0
,
replacePos
)
+
newText
+
sentence
.
slice
(
replacePos
+
oldText
.
length
);
this
.
currentGroup
.
sentence
=
sentence
;
}
},
// 切换全屏模式
toggleFullscreen
()
{
this
.
isFullscreen
=
!
this
.
isFullscreen
;
if
(
this
.
isFullscreen
)
{
// 进入全屏时,等待 DOM 更新后初始化全屏图片
this
.
$nextTick
(()
=>
{
const
img
=
this
.
$refs
.
fullscreenImage
;
if
(
img
&&
img
.
complete
)
{
this
.
handleFullscreenImageLoad
();
}
});
}
},
// 处理全屏图片加载
handleFullscreenImageLoad
()
{
const
img
=
this
.
$refs
.
fullscreenImage
;
const
container
=
this
.
$refs
.
fullscreenContainer
;
if
(
!
img
||
!
container
)
return
;
// 获取容器的实际尺寸(减去padding和一些边距)
const
containerWidth
=
container
.
clientWidth
-
40
;
// 两边各留20px边距
const
containerHeight
=
container
.
clientHeight
-
40
;
// 获取图片的原始尺寸
const
imgNaturalWidth
=
img
.
naturalWidth
;
const
imgNaturalHeight
=
img
.
naturalHeight
;
// 计算容器和图片的宽高比
const
containerRatio
=
containerWidth
/
containerHeight
;
const
imageRatio
=
imgNaturalWidth
/
imgNaturalHeight
;
let
finalWidth
,
finalHeight
;
if
(
imageRatio
>
containerRatio
)
{
// 图片较宽,以容器宽度为准,上下居中
finalWidth
=
containerWidth
;
finalHeight
=
containerWidth
/
imageRatio
;
}
else
{
// 图片较高,以容器高度为准,左右居中
finalHeight
=
containerHeight
;
finalWidth
=
containerHeight
*
imageRatio
;
}
// 设置图片尺寸
img
.
style
.
width
=
`
${
finalWidth
}
px`
;
img
.
style
.
height
=
`
${
finalHeight
}
px`
;
// 更新包装器尺寸
const
wrapper
=
img
.
parentElement
;
if
(
wrapper
)
{
wrapper
.
style
.
width
=
`
${
finalWidth
}
px`
;
wrapper
.
style
.
height
=
`
${
finalHeight
}
px`
;
}
// 保存全屏模式的尺寸信息
this
.
fullscreenImageWidth
=
finalWidth
;
this
.
fullscreenImageHeight
=
finalHeight
;
this
.
fullscreenImageRect
=
img
.
getBoundingClientRect
();
console
.
log
(
'
Fullscreen image loaded:
'
,
{
container
:
{
width
:
containerWidth
,
height
:
containerHeight
,
ratio
:
containerRatio
},
image
:
{
naturalWidth
:
imgNaturalWidth
,
naturalHeight
:
imgNaturalHeight
,
finalWidth
,
finalHeight
,
ratio
:
imageRatio
}
});
},
// 获取全屏模式下矩形框的样式
getFullscreenRectStyle
(
rect
)
{
if
(
!
rect
||
!
this
.
isFullscreen
||
!
this
.
fullscreenImageRect
)
return
{
display
:
'
none
'
};
const
x
=
parseFloat
(
rect
.
x
);
const
y
=
parseFloat
(
rect
.
y
);
const
width
=
parseFloat
(
rect
.
width
);
const
height
=
parseFloat
(
rect
.
height
);
const
actualX
=
x
*
this
.
fullscreenImageWidth
;
const
actualY
=
y
*
this
.
fullscreenImageHeight
;
const
actualWidth
=
width
*
this
.
fullscreenImageWidth
;
const
actualHeight
=
height
*
this
.
fullscreenImageHeight
;
return
{
position
:
'
absolute
'
,
left
:
actualX
+
'
px
'
,
top
:
actualY
+
'
px
'
,
width
:
actualWidth
+
'
px
'
,
height
:
actualHeight
+
'
px
'
};
}
},
...
...
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