|
|
@@ -5,6 +5,7 @@ import { cloneDeep } from 'lodash-es';
|
|
|
import { useGlobSetting } from '@/hooks/setting';
|
|
|
import urlJoin from 'url-join';
|
|
|
import LabelPoint from '../component/mapContainer/LabelPoint.vue';
|
|
|
+import LabelRect from '../component/mapContainer/LabelRect.vue';
|
|
|
import emptyImg from '@/assets/images/table/table-empty.png';
|
|
|
|
|
|
export enum LabelPositionEnum {
|
|
|
@@ -22,6 +23,9 @@ export type EditStyle = {
|
|
|
fontSize: number;
|
|
|
fontColor: string;
|
|
|
posType: LabelPositionEnum;
|
|
|
+
|
|
|
+ pointSvg?: HTMLImageElement;
|
|
|
+ rectSvg?: HTMLImageElement;
|
|
|
};
|
|
|
|
|
|
export type MapWorkShopInfoItem = WorkShopInfoItem & EditStyle;
|
|
|
@@ -36,11 +40,8 @@ export const useMapEditor = defineStore('home-map-ediotr', () => {
|
|
|
const showShops = ref<MapWorkShopInfoItem[]>([]);
|
|
|
const activeShop = ref<MapWorkShopInfoItem>({} as MapWorkShopInfoItem);
|
|
|
|
|
|
- let tempDiv: HTMLDivElement;
|
|
|
-
|
|
|
/** konva elements refs */
|
|
|
const bgImage = ref<HTMLImageElement>(new Image());
|
|
|
- const pointImage = ref<HTMLImageElement>(new Image());
|
|
|
|
|
|
const addBg = () => {
|
|
|
const imgUrl = urlJoin(globSetting.imgUrl!, bgImg.value);
|
|
|
@@ -53,11 +54,11 @@ export const useMapEditor = defineStore('home-map-ediotr', () => {
|
|
|
bgImage.value.src = emptyImg;
|
|
|
};
|
|
|
|
|
|
- const addShop = (shop: MapWorkShopInfoItem) => {
|
|
|
- activeShop.value = shop;
|
|
|
- addedShops.value.push(cloneDeep(shop));
|
|
|
- showShops.value.push(cloneDeep(shop));
|
|
|
- };
|
|
|
+ // const addShop = (shop: MapWorkShopInfoItem) => {
|
|
|
+ // activeShop.value = shop;
|
|
|
+ // addedShops.value.push(cloneDeep(shop));
|
|
|
+ // showShops.value.push(cloneDeep(shop));
|
|
|
+ // };
|
|
|
|
|
|
const toJson = () => {
|
|
|
const layout = {
|
|
|
@@ -90,13 +91,57 @@ export const useMapEditor = defineStore('home-map-ediotr', () => {
|
|
|
activeShop.value = {} as MapWorkShopInfoItem;
|
|
|
};
|
|
|
|
|
|
- const getPointSvg = (url: string) => {
|
|
|
+ const getSvgImages = (shop: MapWorkShopInfoItem): MapWorkShopInfoItem => {
|
|
|
+ let hasPoint = false;
|
|
|
+ let hasRect = false;
|
|
|
+
|
|
|
+ const tempDiv = document.createElement('div') as HTMLDivElement;
|
|
|
+ tempDiv.setAttribute('style', `position: absolute; left: -3000px; top: 0px;`);
|
|
|
+ const parentEl = document.getElementById('shopEditContainer') as HTMLDivElement;
|
|
|
+ parentEl.append(tempDiv);
|
|
|
+
|
|
|
const svgImg = new Image();
|
|
|
svgImg.onload = () => {
|
|
|
- pointImage.value = svgImg;
|
|
|
- // tempDiv?.remove();
|
|
|
+ hasPoint = true;
|
|
|
+ if (hasRect) {
|
|
|
+ // tempDiv?.remove();
|
|
|
+ }
|
|
|
+ addedShops.value.find((item) => item.id === shop.id)!.pointSvg = svgImg;
|
|
|
+ showShops.value.find((item) => item.id === shop.id)!.pointSvg = svgImg;
|
|
|
+ };
|
|
|
+ const pointSvg = h(LabelPoint, {
|
|
|
+ color: shop.bgColor,
|
|
|
+ getSvg: (url: string) => {
|
|
|
+ svgImg.src = url;
|
|
|
+ },
|
|
|
+ });
|
|
|
+ render(pointSvg, tempDiv);
|
|
|
+
|
|
|
+ const rectImg = new Image();
|
|
|
+ rectImg.onload = () => {
|
|
|
+ hasRect = true;
|
|
|
+ if (hasPoint) {
|
|
|
+ // tempDiv?.remove();
|
|
|
+ }
|
|
|
+ addedShops.value.find((item) => item.id === shop.id)!.rectSvg = rectImg;
|
|
|
+ showShops.value.find((item) => item.id === shop.id)!.rectSvg = rectImg;
|
|
|
};
|
|
|
- svgImg.src = url;
|
|
|
+ shop.name = 'ARJ21部装车间';
|
|
|
+ const rectSvg = h(LabelRect, {
|
|
|
+ shop,
|
|
|
+ getSvg: (url: string) => {
|
|
|
+ rectImg.src = url;
|
|
|
+ },
|
|
|
+ });
|
|
|
+ render(rectSvg, tempDiv);
|
|
|
+
|
|
|
+ return { ...shop };
|
|
|
+ };
|
|
|
+
|
|
|
+ const addShop = (shop: MapWorkShopInfoItem) => {
|
|
|
+ activeShop.value = getSvgImages(shop);
|
|
|
+ addedShops.value.push(cloneDeep(activeShop.value));
|
|
|
+ showShops.value.push(cloneDeep(activeShop.value));
|
|
|
};
|
|
|
|
|
|
const resetMap = () => {
|
|
|
@@ -108,14 +153,7 @@ export const useMapEditor = defineStore('home-map-ediotr', () => {
|
|
|
activeShop.value = {} as MapWorkShopInfoItem;
|
|
|
};
|
|
|
|
|
|
- onMounted(() => {
|
|
|
- tempDiv = document.createElement('div') as HTMLDivElement;
|
|
|
- tempDiv.setAttribute('style', `position: absolute; left: -3000px; top: 0px;`);
|
|
|
- const pointSvg = h(LabelPoint, { color: 'red', getSvg: getPointSvg });
|
|
|
- render(pointSvg, tempDiv);
|
|
|
- const parentEl = document.getElementById('shopEditContainer') as HTMLDivElement;
|
|
|
- parentEl.append(tempDiv);
|
|
|
- });
|
|
|
+ onMounted(() => {});
|
|
|
|
|
|
return {
|
|
|
bgImg,
|
|
|
@@ -125,7 +163,6 @@ export const useMapEditor = defineStore('home-map-ediotr', () => {
|
|
|
showShops,
|
|
|
activeShop,
|
|
|
bgImage,
|
|
|
- pointImage,
|
|
|
addShop,
|
|
|
addBg,
|
|
|
toJson,
|