page: 📄 新增path

This commit is contained in:
bunny 2024-07-11 10:03:32 +08:00
parent c1fe533b14
commit 082aa2e29e
3 changed files with 86 additions and 16 deletions

View File

@ -1 +1 @@
{"version":1720598261150} {"version":1720656560503}

40
src/views/path/index.vue Normal file
View File

@ -0,0 +1,40 @@
<template>
<div id="container"></div>
</template>
<script setup lang="ts">
import { useWindowSize } from '@vueuse/core';
import Konva from 'konva/lib/index';
import { onMounted } from 'vue';
const { width, height } = useWindowSize();
const initial = () => {
const stage = new Konva.Stage({
container: 'container',
width: width.value,
height: height.value,
});
const layer = new Konva.Layer({
draggable: true,
});
const myPath = new Konva.Path({
x: 50,
y: 40,
data:
'M213.1,6.7c-32.4-14.4-73.7,0-88.1,30.6C110.6,4.9,67.5-9.5,36.9,6.7C2.8,22.9-13.4,62.4,13.5,110.9C33.3,145.1,67.5,170.3,125,217c59.3.136.7,93.5-71.9,111.5-106.1C263.4,64.2,247.2,22.9.3.13.1,6.7z',
fill: 'red',
scaleX: 0.5,
scaleY: 0.5,
});
layer.add(myPath);
stage.add(layer);
};
onMounted(() => {
initial();
});
</script>

View File

@ -3,15 +3,15 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import * as Konva from 'konva/lib'; import Konva from 'konva/lib/index';
import { Layer } from 'konva/lib/Layer'; import { Layer } from 'konva/lib/Layer';
import { Stage } from 'konva/lib/Stage';
import { Arc } from 'konva/lib/shapes/Arc'; import { Arc } from 'konva/lib/shapes/Arc';
import { Label } from 'konva/lib/shapes/Label'; import { Label } from 'konva/lib/shapes/Label';
import { Ring } from 'konva/lib/shapes/Ring'; import { Ring } from 'konva/lib/shapes/Ring';
import { Star } from 'konva/lib/shapes/Star'; import { Star } from 'konva/lib/shapes/Star';
import { Text } from 'konva/lib/shapes/Text'; import { Text } from 'konva/lib/shapes/Text';
import { TextPath } from 'konva/lib/shapes/TextPath'; import { TextPath } from 'konva/lib/shapes/TextPath';
import { Stage } from 'konva/lib/Stage';
import { nextTick, onMounted } from 'vue'; import { nextTick, onMounted } from 'vue';
@ -87,19 +87,36 @@ const initial = () => {
innerRadius: 40, innerRadius: 40,
outerRadius: 70, outerRadius: 70,
fill: 'green', fill: 'green',
stroke: 'red', stroke: '#fff',
strokeWidth: 4, strokeWidth: 4,
}); });
const label = new Label({ // tooltip
x: 180, const tooltip = new Label({
y: 180, x: 170,
opacity: 0.6, y: 75,
opacity: 0.75,
draggable: true,
}); });
label.add( tooltip.add(
new Text({ new Konva.Tag({
text: 'Label pointing left', fill: 'black',
pointerDirection: 'down',
pointerWidth: 10,
pointerHeight: 10,
lineJoin: 'round',
shadowColor: 'black',
shadowBlur: 10,
shadowOffsetX: 10,
shadowOffsetY: 10,
shadowOpacity: 0.5,
}),
);
tooltip.add(
new Konva.Text({
text: 'Tooltip pointing down',
fontFamily: 'Calibri', fontFamily: 'Calibri',
fontSize: 18, fontSize: 18,
padding: 5, padding: 5,
@ -107,14 +124,28 @@ const initial = () => {
}), }),
); );
label.add( const label1 = new Label({
x: 300,
y: 150,
opacity: 1,
draggable: true,
});
label1.add(
new Konva.Tag({ new Konva.Tag({
fill: 'red', fill: 'green',
pointerDirection: 'left', pointerDirection: 'left',
pointerWidth: 20, pointerWidth: 20,
pointerHeight: 28, pointerHeight: 28,
lineJoin: 'round', lineJoin: 'round',
}), }),
new Konva.Text({
text: 'Label pointing left',
fontFamily: 'Calibri',
fontSize: 18,
padding: 5,
fill: '#fff',
}),
); );
layer.add(text); layer.add(text);
@ -122,7 +153,8 @@ const initial = () => {
layer.add(start); layer.add(start);
layer.add(ring); layer.add(ring);
layer.add(arc); layer.add(arc);
layer.add(label); layer.add(label1);
layer.add(tooltip);
stage.add(layer); stage.add(layer);
}); });
@ -132,5 +164,3 @@ onMounted(() => {
initial(); initial();
}); });
</script> </script>
<style lang="scss" scoped></style>