|
@@ -0,0 +1,139 @@
|
|
|
|
|
+<template>
|
|
|
|
|
+ <v-image ref="pointRef" :config="getPointCurvConfig()" />
|
|
|
|
|
+ <v-image ref="rectRef" :config="getRectCurConfig()" />
|
|
|
|
|
+ <v-text :config="getTextConfig()" />
|
|
|
|
|
+ <v-image :config="shineConfig" />
|
|
|
|
|
+</template>
|
|
|
|
|
+
|
|
|
|
|
+<script setup lang="ts">
|
|
|
|
|
+ import { ref, onMounted, nextTick, computed, watch } from 'vue';
|
|
|
|
|
+ import rectBlock from '@/assets/test/2-rect.svg';
|
|
|
|
|
+ import pointCurv from '@/assets/test/1-curv2.svg';
|
|
|
|
|
+ import shine from '@/assets/test/2-shine.svg';
|
|
|
|
|
+ import Konva from 'konva';
|
|
|
|
|
+ import { MapWorkShopInfoItem } from '../../stores/useMapEditor';
|
|
|
|
|
+
|
|
|
|
|
+ const props = defineProps<{ shop: MapWorkShopInfoItem }>();
|
|
|
|
|
+
|
|
|
|
|
+ const shopData = computed(() => props.shop);
|
|
|
|
|
+
|
|
|
|
|
+ const curvImage = ref<HTMLImageElement>(new Image());
|
|
|
|
|
+ const rectImage = ref<HTMLImageElement>(new Image());
|
|
|
|
|
+ const shineImage = ref<HTMLImageElement>(new Image());
|
|
|
|
|
+ const rectRef = ref<Konva.Image>();
|
|
|
|
|
+ const pointRef = ref<Konva.Image>();
|
|
|
|
|
+
|
|
|
|
|
+ const getRGBANum = (color: string) => {
|
|
|
|
|
+ if (!color) return [0, 0, 0, 0];
|
|
|
|
|
+ const pattern = /\((\d+),\s*(\d+),\s*(\d+),\s*(\d+(\.\d+)?)\)$/;
|
|
|
|
|
+ const array = color.match(pattern);
|
|
|
|
|
+ return [
|
|
|
|
|
+ Number(array![1]) || 0,
|
|
|
|
|
+ Number(array![2]) || 0,
|
|
|
|
|
+ Number(array![3]) || 0,
|
|
|
|
|
+ Number(array![4]) || 0,
|
|
|
|
|
+ ];
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ const nodeUpdateFilter = (node: Konva.Node) => {
|
|
|
|
|
+ node.cache();
|
|
|
|
|
+ const rgba = getRGBANum(shopData.value.bgColor);
|
|
|
|
|
+ node.red(rgba[0]);
|
|
|
|
|
+ node.green(rgba[1]);
|
|
|
|
|
+ node.blue(rgba[2]);
|
|
|
|
|
+ node.alpha(rgba[3]);
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ const getPointCurvConfig = () => {
|
|
|
|
|
+ return {
|
|
|
|
|
+ x: 0,
|
|
|
|
|
+ y: 0,
|
|
|
|
|
+ width: 32,
|
|
|
|
|
+ height: 39,
|
|
|
|
|
+ // fill: shopData.value.bgColor,
|
|
|
|
|
+ image: curvImage.value,
|
|
|
|
|
+ };
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ const getRectCurConfig = () => {
|
|
|
|
|
+ return {
|
|
|
|
|
+ x: 53,
|
|
|
|
|
+ y: 0,
|
|
|
|
|
+ width: 160,
|
|
|
|
|
+ height: 38,
|
|
|
|
|
+ // fill: shopData.value.bgColor,
|
|
|
|
|
+ image: rectImage.value,
|
|
|
|
|
+ };
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ const getTextConfig = () => {
|
|
|
|
|
+ return {
|
|
|
|
|
+ x: 53,
|
|
|
|
|
+ y: 0,
|
|
|
|
|
+ text: shopData.value.name,
|
|
|
|
|
+ fontSize: shopData.value.fontSize,
|
|
|
|
|
+ fontFamily: 'TRENDS',
|
|
|
|
|
+ fill: shopData.value.fontColor,
|
|
|
|
|
+ width: 160,
|
|
|
|
|
+ height: 32,
|
|
|
|
|
+ align: 'center',
|
|
|
|
|
+ verticalAlign: 'middle',
|
|
|
|
|
+ };
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ const shineConfig = computed(() => {
|
|
|
|
|
+ return {
|
|
|
|
|
+ x: 0,
|
|
|
|
|
+ y: 0,
|
|
|
|
|
+ width: 213,
|
|
|
|
|
+ height: 38,
|
|
|
|
|
+ // fill: shopData.value.bgColor,
|
|
|
|
|
+ image: shineImage.value,
|
|
|
|
|
+ };
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ watch(
|
|
|
|
|
+ shopData.value,
|
|
|
|
|
+ () => {
|
|
|
|
|
+ console.log('pointRef.value!.getNode()', pointRef.value!.getNode());
|
|
|
|
|
+ nextTick(() => {
|
|
|
|
|
+ console.log('pointRef.value!.getNode()', pointRef.value!.getNode());
|
|
|
|
|
+ nodeUpdateFilter(pointRef.value!.getNode());
|
|
|
|
|
+
|
|
|
|
|
+ nodeUpdateFilter(rectRef.value!.getNode());
|
|
|
|
|
+ });
|
|
|
|
|
+ },
|
|
|
|
|
+ { deep: true },
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ onMounted(() => {
|
|
|
|
|
+ const svgImg = new Image();
|
|
|
|
|
+ svgImg.onload = () => {
|
|
|
|
|
+ curvImage.value = svgImg;
|
|
|
|
|
+ nextTick(() => {
|
|
|
|
|
+ nodeUpdateFilter(pointRef.value?.getNode());
|
|
|
|
|
+ });
|
|
|
|
|
+ };
|
|
|
|
|
+ svgImg.src = pointCurv;
|
|
|
|
|
+
|
|
|
|
|
+ const rectImg = new Image();
|
|
|
|
|
+ rectImg.onload = () => {
|
|
|
|
|
+ rectImage.value = rectImg;
|
|
|
|
|
+ nextTick(() => {
|
|
|
|
|
+ nodeUpdateFilter(rectRef.value?.getNode());
|
|
|
|
|
+ });
|
|
|
|
|
+ };
|
|
|
|
|
+ rectImg.src = rectBlock;
|
|
|
|
|
+
|
|
|
|
|
+ const shineImg = new Image();
|
|
|
|
|
+ shineImg.onload = () => {
|
|
|
|
|
+ shineImage.value = shineImg;
|
|
|
|
|
+ };
|
|
|
|
|
+ shineImg.src = shine;
|
|
|
|
|
+
|
|
|
|
|
+ rectRef.value?.getNode().filters([Konva.Filters.RGBA]);
|
|
|
|
|
+ pointRef.value?.getNode().filters([Konva.Filters.RGBA]);
|
|
|
|
|
+ });
|
|
|
|
|
+</script>
|
|
|
|
|
+
|
|
|
|
|
+<style scoped></style>
|