Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
V
vue3-quasar-ts-study01
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hucy
vue3-quasar-ts-study01
Commits
3f2391a4
Commit
3f2391a4
authored
Apr 07, 2023
by
hucy
☘
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:不想写不想写
parent
b54c6275
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
12 deletions
+28
-12
getBoundingBox.ts
src/common/utils/getBoundingBox.ts
+12
-1
IndexPage2.vue
src/modules/vue-konva/IndexPage2.vue
+16
-11
No files found.
src/common/utils/getBoundingBox.ts
View file @
3f2391a4
...
@@ -20,7 +20,9 @@ export const getBoundingBox = function (path: Path[]) {
...
@@ -20,7 +20,9 @@ export const getBoundingBox = function (path: Path[]) {
let
min_x
=
0
,
let
min_x
=
0
,
min_y
=
0
,
min_y
=
0
,
max_x
=
0
,
max_x
=
0
,
max_y
=
0
;
max_y
=
0
,
width
=
0
,
height
=
0
;
const
center
=
{
x
:
0
,
y
:
0
};
const
center
=
{
x
:
0
,
y
:
0
};
let
resPath
:
Path
[]
=
[];
let
resPath
:
Path
[]
=
[];
const
length
=
path
.
length
;
const
length
=
path
.
length
;
...
@@ -60,13 +62,20 @@ export const getBoundingBox = function (path: Path[]) {
...
@@ -60,13 +62,20 @@ export const getBoundingBox = function (path: Path[]) {
}
else
if
(
length
>=
2
)
{
}
else
if
(
length
>=
2
)
{
if
(
min_x
===
max_x
)
{
if
(
min_x
===
max_x
)
{
// 垂直的线
// 垂直的线
width
=
0
;
height
=
Decimal
.
sub
(
max_y
,
min_y
).
toNumber
();
center
.
x
=
min_x
;
center
.
x
=
min_x
;
center
.
y
=
Decimal
.
sub
(
max_y
,
min_y
).
div
(
2
).
plus
(
min_y
).
toNumber
();
center
.
y
=
Decimal
.
sub
(
max_y
,
min_y
).
div
(
2
).
plus
(
min_y
).
toNumber
();
}
else
if
(
min_y
===
max_y
)
{
}
else
if
(
min_y
===
max_y
)
{
// 水平的线
// 水平的线
width
=
Decimal
.
sub
(
max_x
,
min_x
).
toNumber
();
height
=
0
;
center
.
y
=
min_y
;
center
.
y
=
min_y
;
center
.
x
=
Decimal
.
sub
(
max_x
,
min_x
).
div
(
2
).
plus
(
min_x
).
toNumber
();
center
.
x
=
Decimal
.
sub
(
max_x
,
min_x
).
div
(
2
).
plus
(
min_x
).
toNumber
();
}
else
{
}
else
{
width
=
Decimal
.
sub
(
max_x
,
min_x
).
toNumber
();
height
=
Decimal
.
sub
(
max_y
,
min_y
).
toNumber
();
center
.
x
=
Decimal
.
sub
(
max_x
,
min_x
).
div
(
2
).
plus
(
min_x
).
toNumber
();
center
.
x
=
Decimal
.
sub
(
max_x
,
min_x
).
div
(
2
).
plus
(
min_x
).
toNumber
();
center
.
y
=
Decimal
.
sub
(
max_y
,
min_y
).
div
(
2
).
plus
(
min_y
).
toNumber
();
center
.
y
=
Decimal
.
sub
(
max_y
,
min_y
).
div
(
2
).
plus
(
min_y
).
toNumber
();
...
@@ -98,5 +107,7 @@ export const getBoundingBox = function (path: Path[]) {
...
@@ -98,5 +107,7 @@ export const getBoundingBox = function (path: Path[]) {
max_y
,
max_y
,
path
:
resPath
,
path
:
resPath
,
center
,
center
,
width
,
height
,
};
};
};
};
src/modules/vue-konva/IndexPage2.vue
View file @
3f2391a4
...
@@ -88,26 +88,29 @@ function createShape(itemData: any) {
...
@@ -88,26 +88,29 @@ function createShape(itemData: any) {
const
path
=
itemData
.
path
||
[];
const
path
=
itemData
.
path
||
[];
const
fillColor
=
itemData
.
color
||
'#000000'
;
const
fillColor
=
itemData
.
color
||
'#000000'
;
const
name
=
itemData
.
name
;
const
name
=
itemData
.
name
;
const
boundingBox
=
itemData
.
boundingBox
||
{};
const
boundingBoxPath
=
itemData
.
boundingBox
?.
path
||
[];
const
boundingBoxPath
=
itemData
.
boundingBox
?.
path
||
[];
if
(
boundingBoxPath
.
length
<
2
)
{
if
(
boundingBoxPath
.
length
<
2
)
{
console
.
warn
(
'小于两个点,不能构成多边形,没有边界框'
);
console
.
warn
(
'小于两个点,不能构成多边形,没有边界框'
);
}
else
{
}
else
{
let
group
=
new
Konva
.
Group
({
let
group
=
new
Konva
.
Group
({
x
:
boundingBoxPath
[
0
].
x
,
x
:
0
,
y
:
boundingBoxPath
[
0
].
y
,
y
:
0
,
draggable
:
true
,
draggable
:
true
,
});
});
// let rectBox = new Konva.Rect({
let
rectBox
=
new
Konva
.
Rect
({
// x: group.x(),
x
:
boundingBoxPath
[
0
].
x
,
// y: group.y(),
y
:
boundingBoxPath
[
0
].
y
,
// width: state.boundingBox.width,
width
:
boundingBox
.
width
,
// height: state.boundingBox.height,
height
:
boundingBox
.
height
,
// stroke: 'black',
stroke
:
'red'
,
// strokeWidth: 10,
// fill: 'grey',
// });
strokeWidth
:
4
,
});
// 如果添加到group,则坐标的相对位置时基于group的位置
let
shape
:
any
=
new
Konva
.
Shape
({
let
shape
:
any
=
new
Konva
.
Shape
({
sceneFunc
:
function
(
context
,
shape
)
{
sceneFunc
:
function
(
context
,
shape
)
{
context
.
beginPath
();
context
.
beginPath
();
...
@@ -133,6 +136,7 @@ function createShape(itemData: any) {
...
@@ -133,6 +136,7 @@ function createShape(itemData: any) {
// stroke: 'white',
// stroke: 'white',
// strokeWidth: 10,
// strokeWidth: 10,
});
});
group
.
add
(
rectBox
);
group
.
add
(
shape
);
group
.
add
(
shape
);
return
group
;
return
group
;
...
@@ -270,6 +274,7 @@ function drawGrid() {
...
@@ -270,6 +274,7 @@ function drawGrid() {
</
script
>
</
script
>
<
template
>
<
template
>
<div
class=
"konva-main-page container-height center"
>
<div
class=
"konva-main-page container-height center"
>
<div>
666
</div>
<div
class=
"canvas-box"
>
<div
class=
"canvas-box"
>
<canvas
<canvas
id=
"canvas-grid"
id=
"canvas-grid"
...
@@ -290,6 +295,6 @@ function drawGrid() {
...
@@ -290,6 +295,6 @@ function drawGrid() {
width
:
1200px
;
width
:
1200px
;
height
:
800px
;
height
:
800px
;
border
:
1px
solid
#000
;
border
:
1px
solid
#000
;
background
:
pink
;
//
background: pink;
}
}
</
style
>
</
style
>
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