<script setup lang="ts">
import { useWindowSize } from '@vueuse/core';
import Konva from 'konva/lib';
import { onMounted, ref } from 'vue';
import { Circle } from 'konva/lib/shapes/Circle';

const { width, height } = useWindowSize();
const circle = ref<Circle>();

const initial = () => {
	const stage = new Konva.Stage({ container: 'container', width: width.value, height: height.value });
	const layer = new Konva.Layer();
	stage.add(layer);

	const group = new Konva.Group();
	layer.add(group);

	circle.value = new Konva.Circle({
		x: 70,
		y: 70,
		fill: 'red',
		radius: 30,
	});
	group.add(circle.value);

	const blackRect = new Konva.Rect({
		x: 20,
		y: 20,
		fill: 'black',
		width: 100,
		height: 100,
	});
	group.add(blackRect);
};

/**
 * * 将圆形zIndex设置为1
 */
const updateCircle = () => {
	circle.value!.zIndex(1);
};

onMounted(() => {
	initial();
});
</script>

<template>
	<div class="container-fluid">
		<button class="btn btn-primary" @click="updateCircle">将圆形zIndex设置为1</button>
		<div id="container"></div>
	</div>
</template>

<style scoped lang="scss"></style>
