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
814989b2
Commit
814989b2
authored
May 22, 2025
by
liujiangnan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 矩形可以移动
parent
ce52db0f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
86 additions
and
48 deletions
+86
-48
index.css
form/index.css
+12
-6
index.js
form/index.js
+74
-42
No files found.
form/index.css
View file @
814989b2
...
...
@@ -398,25 +398,31 @@ html, body {
/* 矩形框样式 */
.text-rect
{
position
:
absolute
;
border
:
2px
dashed
#409EFF
;
border
:
2px
solid
rgba
(
64
,
158
,
255
,
0.7
)
;
background-color
:
rgba
(
64
,
158
,
255
,
0.1
);
cursor
:
move
;
transform-origin
:
top
left
;
user-select
:
none
;
}
.text-rect.selected
{
border-color
:
#
67C23A
;
background-color
:
rgba
(
103
,
194
,
58
,
0.1
);
border-color
:
#
409EFF
;
background-color
:
rgba
(
64
,
158
,
255
,
0.2
);
z-index
:
2
;
}
.text-rect.highlighted
{
border-color
:
#
E6A23C
;
background-color
:
rgba
(
230
,
162
,
60
,
0.2
);
border-color
:
#
67C23A
;
background-color
:
rgba
(
103
,
194
,
58
,
0.2
);
z-index
:
3
;
}
/* 预览模式下禁用拖拽 */
.preview-mode
.text-rect
{
pointer-events
:
none
;
cursor
:
default
;
opacity
:
0.7
;
}
.text-content
{
position
:
absolute
;
bottom
:
-20px
;
...
...
form/index.js
View file @
814989b2
...
...
@@ -93,7 +93,7 @@ new Vue({
let
data
=
await
new
Promise
((
resolve
)
=>
{
window
.
courseware
.
getData
((
data
)
=>
{
resolve
(
data
);
});
}
,
t_name
);
});
if
(
!
data
)
{
const
response
=
await
fetch
(
'
./defaultData.json
'
);
...
...
@@ -834,24 +834,17 @@ new Vue({
getRectStyle
(
rect
)
{
if
(
!
rect
||
!
this
.
imageLoaded
||
!
this
.
imageRect
)
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
.
imageWidth
;
const
actualY
=
y
*
this
.
imageHeight
;
const
actualWidth
=
width
*
this
.
imageWidth
;
const
actualHeight
=
height
*
this
.
imageHeight
;
return
{
position
:
'
absolute
'
,
left
:
actualX
+
'
px
'
,
top
:
actualY
+
'
px
'
,
width
:
actualWidth
+
'
px
'
,
height
:
actualHeight
+
'
px
'
left
:
(
x
*
100
)
+
'
%
'
,
top
:
(
y
*
100
)
+
'
%
'
,
width
:
(
width
*
100
)
+
'
%
'
,
height
:
(
height
*
100
)
+
'
%
'
};
},
...
...
@@ -871,18 +864,34 @@ new Vue({
// 开始拖拽
startDrag
(
event
,
groupIndex
,
itemIndex
)
{
if
(
event
.
target
.
classList
.
contains
(
'
resize-handle
'
)
||
!
this
.
imageLoaded
||
this
.
isPreviewMode
)
return
;
if
(
event
.
target
.
classList
.
contains
(
'
resize-handle
'
))
return
;
if
(
this
.
isPreviewMode
)
return
;
// 获取图片容器的位置信息
const
imageWrapper
=
this
.
$refs
.
imageContainer
.
querySelector
(
'
.image-wrapper
'
);
const
imageRect
=
imageWrapper
.
getBoundingClientRect
();
this
.
isDragging
=
true
;
this
.
dragStartX
=
event
.
clientX
;
this
.
dragStartY
=
event
.
clientY
;
this
.
dragStartX
=
event
.
clientX
-
imageRect
.
left
;
this
.
dragStartY
=
event
.
clientY
-
imageRect
.
top
;
this
.
selectedGroup
=
groupIndex
;
this
.
currentGroup
=
this
.
currentPage
.
groups
[
groupIndex
];
this
.
selectedItemIndex
=
itemIndex
;
this
.
originalRect
=
this
.
currentGroup
.
group
[
itemIndex
].
rect
?
{
...
this
.
currentGroup
.
group
[
itemIndex
].
rect
}
:
null
;
const
rect
=
this
.
currentGroup
.
group
[
itemIndex
].
rect
;
this
.
originalRect
=
{
x
:
rect
?
rect
.
x
:
0.2
,
y
:
rect
?
rect
.
y
:
0.2
,
width
:
rect
?
rect
.
width
:
0.2
,
height
:
rect
?
rect
.
height
:
0.2
};
// 记录初始点击位置相对于矩形框的偏移
this
.
dragOffsetX
=
this
.
dragStartX
-
(
this
.
originalRect
.
x
*
this
.
imageWidth
);
this
.
dragOffsetY
=
this
.
dragStartY
-
(
this
.
originalRect
.
y
*
this
.
imageHeight
);
event
.
preventDefault
();
event
.
stopPropagation
();
// 阻止事件冒泡
event
.
stopPropagation
();
},
// 开始调整大小
...
...
@@ -902,42 +911,58 @@ new Vue({
// 处理鼠标移动
handleMouseMove
(
event
)
{
if
((
!
this
.
isDragging
&&
!
this
.
isResizing
)
||
!
this
.
currentGroup
||
!
this
.
originalRect
||
!
this
.
imageLoaded
)
return
;
if
(
!
this
.
isDragging
&&
!
this
.
isResizing
)
return
;
if
(
!
this
.
currentGroup
||
!
this
.
originalRect
)
return
;
const
currentRect
=
this
.
currentGroup
.
group
[
this
.
selectedItemIndex
].
rect
;
if
(
!
currentRect
||
!
this
.
imageRect
)
return
;
// 获取图片容器的位置信息
const
imageWrapper
=
this
.
$refs
.
imageContainer
.
querySelector
(
'
.image-wrapper
'
);
const
imageRect
=
imageWrapper
.
getBoundingClientRect
();
// 计算鼠标移动的相对距离
const
deltaX
=
(
event
.
clientX
-
this
.
dragStartX
)
/
this
.
imageWidth
;
const
deltaY
=
(
event
.
clientY
-
this
.
dragStartY
)
/
this
.
imageHeight
;
const
currentRect
=
this
.
currentGroup
.
group
[
this
.
selectedItemIndex
].
rect
;
if
(
!
currentRect
)
return
;
if
(
this
.
isDragging
)
{
// 计算新位置,确保不超出图片边界
currentRect
.
x
=
Math
.
max
(
0
,
Math
.
min
(
1
-
currentRect
.
width
,
this
.
originalRect
.
x
+
deltaX
));
currentRect
.
y
=
Math
.
max
(
0
,
Math
.
min
(
1
-
currentRect
.
height
,
this
.
originalRect
.
y
+
deltaY
));
// 计算鼠标相对于图片容器的位置
const
mouseX
=
event
.
clientX
-
imageRect
.
left
;
const
mouseY
=
event
.
clientY
-
imageRect
.
top
;
// 考虑拖拽起始点的偏移
let
newX
=
(
mouseX
-
this
.
dragOffsetX
)
/
this
.
imageWidth
;
let
newY
=
(
mouseY
-
this
.
dragOffsetY
)
/
this
.
imageHeight
;
// 限制在图片范围内
newX
=
Math
.
max
(
0
,
Math
.
min
(
1
-
currentRect
.
width
,
newX
));
newY
=
Math
.
max
(
0
,
Math
.
min
(
1
-
currentRect
.
height
,
newY
));
// 更新位置
this
.
$set
(
currentRect
,
'
x
'
,
newX
);
this
.
$set
(
currentRect
,
'
y
'
,
newY
);
}
else
if
(
this
.
isResizing
)
{
// 计算
最小宽度和高度(5像素对应的相对值)
const
m
inWidth
=
5
/
this
.
imageWidth
;
const
m
inHeight
=
5
/
this
.
imageHeight
;
// 计算
鼠标相对于图片的位置
const
m
ouseX
=
event
.
clientX
-
imageRect
.
left
;
const
m
ouseY
=
event
.
clientY
-
imageRect
.
top
;
// 计算新
尺寸,确保不超出图片边界且不小于5像素
c
urrentRect
.
width
=
Math
.
max
(
minWidth
,
Math
.
min
(
1
-
currentRect
.
x
,
this
.
originalRect
.
width
+
deltaX
))
;
c
urrentRect
.
height
=
Math
.
max
(
minHeight
,
Math
.
min
(
1
-
currentRect
.
y
,
this
.
originalRect
.
height
+
deltaY
))
;
// 计算新
的宽度和高度
c
onst
newWidth
=
Math
.
max
(
5
,
mouseX
-
(
this
.
originalRect
.
x
*
this
.
imageWidth
))
/
this
.
imageWidth
;
c
onst
newHeight
=
Math
.
max
(
5
,
mouseY
-
(
this
.
originalRect
.
y
*
this
.
imageHeight
))
/
this
.
imageHeight
;
// 限制大小
currentRect
.
width
=
Math
.
min
(
1
-
currentRect
.
x
,
newWidth
);
currentRect
.
height
=
Math
.
min
(
1
-
currentRect
.
y
,
newHeight
);
}
},
// 处理鼠标松开
handleMouseUp
(
event
)
{
// 如果是拖拽或调整大小操作,阻止后续的 click 事件
if
(
this
.
isDragging
||
this
.
isResizing
)
{
event
.
preventDefault
();
event
.
stopPropagation
();
}
this
.
isDragging
=
false
;
this
.
isResizing
=
false
;
this
.
dragStartX
=
null
;
this
.
dragStartY
=
null
;
this
.
dragOffsetX
=
null
;
this
.
dragOffsetY
=
null
;
this
.
originalRect
=
null
;
}
},
// 更新音频区域
...
...
@@ -1982,7 +2007,14 @@ new Vue({
save
()
{
if
(
!
this
.
isDataModified
)
return
;
let
data
=
{
audio_points
:
this
.
audioPoints
,
pages
:
this
.
pages
};
window
.
courseware
.
setData
(
data
,
()
=>
{
console
.
log
(
'
----save----
'
);
this
.
isDataModified
=
false
;
},
t_name
);
}
},
...
...
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