Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qq_32624153
VueJS_382639
提交
d617780e
V
VueJS_382639
项目概览
qq_32624153
/
VueJS_382639
与 Fork 源项目一致
Fork自
inscode / VueJS
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
VueJS_382639
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
d617780e
编写于
9月 12, 2023
作者:
Q
qq_32624153
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Tue Sep 12 20:26:00 CST 2023 inscode
上级
8cffb4df
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
155 addition
and
0 deletion
+155
-0
package.json
package.json
+1
-0
src/konva.vue
src/konva.vue
+149
-0
yarn.lock
yarn.lock
+5
-0
未找到文件。
package.json
浏览文件 @
d617780e
...
...
@@ -12,6 +12,7 @@
"
element-ui
"
:
"
^2.15.14
"
,
"
fabric
"
:
"
^5.3.0
"
,
"
guess
"
:
"
^1.0.2
"
,
"
konva
"
:
"
^9.2.0
"
,
"
vue
"
:
"
^3.2.37
"
,
"
vuedraggable
"
:
"
^2.24.3
"
},
...
...
src/konva.vue
0 → 100644
浏览文件 @
d617780e
<
template
>
<div
ref=
"canvasContainer"
class=
"canvas-container"
>
<canvas
ref=
"canvas"
class=
"canvas"
@
mousedown=
"onMouseDown"
@
mousemove=
"onMouseMove"
@
mouseup=
"onMouseUp"
></canvas>
<div
v-for=
"(shape, index) in shapes"
:key=
"index"
:style=
"
{top: shape.top + 'px', left: shape.left + 'px'}" class="shape" draggable="true" @dragstart="onDragStart(index)" @dragend="onDragEnd(index)">
<span
class=
"value"
>
{{
shape
.
value
}}
</span>
</div>
</div>
</
template
>
<
script
>
export
default
{
data
()
{
return
{
shapes
:
[],
selectedShape
:
null
,
dragOffsetX
:
0
,
dragOffsetY
:
0
,
isDragging
:
false
}
},
mounted
()
{
const
canvas
=
this
.
$refs
.
canvas
canvas
.
width
=
this
.
$refs
.
canvasContainer
.
clientWidth
canvas
.
height
=
this
.
$refs
.
canvasContainer
.
clientHeight
this
.
drawShapes
()
},
methods
:
{
addShape
(
x
,
y
)
{
const
shape
=
{
value
:
Math
.
floor
(
Math
.
random
()
*
100
),
left
:
x
,
top
:
y
,
width
:
50
,
height
:
50
}
this
.
shapes
.
push
(
shape
)
this
.
drawShape
(
shape
)
},
drawShapes
()
{
const
canvas
=
this
.
$refs
.
canvas
const
context
=
canvas
.
getContext
(
'
2d
'
)
context
.
clearRect
(
0
,
0
,
canvas
.
width
,
canvas
.
height
)
this
.
shapes
.
forEach
(
shape
=>
this
.
drawShape
(
shape
))
},
drawShape
(
shape
)
{
const
canvas
=
this
.
$refs
.
canvas
const
context
=
canvas
.
getContext
(
'
2d
'
)
context
.
fillStyle
=
'
#2196F3
'
context
.
fillRect
(
shape
.
left
,
shape
.
top
,
shape
.
width
,
shape
.
height
)
context
.
font
=
'
16px Arial
'
context
.
fillStyle
=
'
#fff
'
context
.
textAlign
=
'
center
'
context
.
fillText
(
shape
.
value
,
shape
.
left
+
shape
.
width
/
2
,
shape
.
top
+
shape
.
height
/
2
+
6
)
},
onMouseDown
(
event
)
{
const
canvas
=
this
.
$refs
.
canvas
const
rect
=
canvas
.
getBoundingClientRect
()
const
x
=
event
.
clientX
-
rect
.
left
const
y
=
event
.
clientY
-
rect
.
top
this
.
selectedShape
=
this
.
shapes
.
find
(
shape
=>
x
>=
shape
.
left
&&
x
<=
shape
.
left
+
shape
.
width
&&
y
>=
shape
.
top
&&
y
<=
shape
.
top
+
shape
.
height
)
if
(
this
.
selectedShape
)
{
this
.
isDragging
=
true
this
.
dragOffsetX
=
x
-
this
.
selectedShape
.
left
this
.
dragOffsetY
=
y
-
this
.
selectedShape
.
top
}
},
onMouseMove
(
event
)
{
if
(
this
.
isDragging
)
{
const
canvas
=
this
.
$refs
.
canvas
const
rect
=
canvas
.
getBoundingClientRect
()
const
x
=
event
.
clientX
-
rect
.
left
const
y
=
event
.
clientY
-
rect
.
top
this
.
selectedShape
.
left
=
x
-
this
.
dragOffsetX
this
.
selectedShape
.
top
=
y
-
this
.
dragOffsetY
this
.
drawShapes
()
}
},
onMouseUp
()
{
this
.
isDragging
=
false
},
onDragStart
(
index
)
{
this
.
selectedShape
=
this
.
shapes
[
index
]
this
.
selectedShape
.
width
+=
10
this
.
selectedShape
.
height
+=
10
this
.
drawShapes
()
},
onDragEnd
(
index
)
{
this
.
selectedShape
=
this
.
shapes
[
index
]
this
.
selectedShape
.
width
-=
10
this
.
selectedShape
.
height
-=
10
this
.
drawShapes
()
const
canvas
=
this
.
$refs
.
canvas
const
rect
=
canvas
.
getBoundingClientRect
()
const
x
=
this
.
selectedShape
.
left
+
this
.
selectedShape
.
width
/
2
const
y
=
this
.
selectedShape
.
top
+
this
.
selectedShape
.
height
/
2
const
otherShapes
=
this
.
shapes
.
filter
(
shape
=>
shape
!==
this
.
selectedShape
)
const
targetShape
=
otherShapes
.
find
(
shape
=>
x
>=
shape
.
left
&&
x
<=
shape
.
left
+
shape
.
width
&&
y
>=
shape
.
top
&&
y
<=
shape
.
top
+
shape
.
height
)
if
(
targetShape
)
{
const
context
=
canvas
.
getContext
(
'
2d
'
)
context
.
beginPath
()
context
.
moveTo
(
this
.
selectedShape
.
left
+
this
.
selectedShape
.
width
/
2
,
this
.
selectedShape
.
top
+
this
.
selectedShape
.
height
/
2
)
context
.
lineTo
(
targetShape
.
left
+
targetShape
.
width
/
2
,
targetShape
.
top
+
targetShape
.
height
/
2
)
context
.
strokeStyle
=
'
#2196F3
'
context
.
lineWidth
=
3
context
.
stroke
()
}
}
}
}
</
script
>
<
style
>
.canvas-container
{
position
:
relative
;
width
:
100%
;
height
:
100%
;
overflow
:
hidden
;
}
.canvas
{
position
:
absolute
;
top
:
0
;
left
:
0
;
}
.shape
{
position
:
absolute
;
display
:
flex
;
align-items
:
center
;
justify-content
:
center
;
width
:
50px
;
height
:
50px
;
background-color
:
#2196F3
;
border
:
2px
solid
#fff
;
border-radius
:
50%
;
cursor
:
move
;
}
.shape
:hover
{
border-color
:
#2196F3
;
background-color
:
#fff
;
}
.value
{
font-size
:
16px
;
color
:
#fff
;
pointer-events
:
none
;
}
</
style
>
yarn.lock
浏览文件 @
d617780e
...
...
@@ -705,6 +705,11 @@ json-formatter-js@^2.3.4, json-formatter-js@~2.3.4:
resolved "https://registry.npmmirror.com/json-formatter-js/-/json-formatter-js-2.3.4.tgz"
integrity sha512-gmAzYRtPRmYzeAT4T7+t3NhTF89JOAIioCVDddl9YDb3ls3kWcskirafw/MZGJaRhEU6fRimGJHl7CC7gaAI2Q==
konva@^9.2.0:
version "9.2.0"
resolved "https://registry.npmmirror.com/konva/-/konva-9.2.0.tgz"
integrity sha512-+woI76Sk+VFVl9z7zPkuTnN2zFpEYg27YWz8BCdQXpt5IS3pdnSPAPQVPPMidcbDi9/G5b/IOIp35/KqMGiYPA==
lodash@~4.17.21:
version "4.17.21"
resolved "https://registry.npmmirror.com/lodash/-/lodash-4.17.21.tgz"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录