|
|
@@ -11,20 +11,28 @@
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
import {storeToRefs} from 'pinia'
|
|
|
-import {onMounted, onUnmounted} from 'vue'
|
|
|
+import {computed, onMounted, onUnmounted, ref} from 'vue'
|
|
|
import {useFabricStore, useMainStore, useTemplatesStore, useUserStore} from '@/store'
|
|
|
import {useRouter} from 'vue-router'
|
|
|
import {unzip} from "@/utils/crypto"
|
|
|
import {getDesignTemplateEdit, getPreViewTemplate, getTemplateData, newDesignOrder, tmpSaveUserDesign, updateDesignTemplate} from '@/api/template'
|
|
|
import {contextMenus} from '@/configs/contextMenu'
|
|
|
-import {initEditor} from '@/views/Canvas/useCanvas'
|
|
|
+import useCanvas, {initEditor} from '@/views/Canvas/useCanvas'
|
|
|
import {initPixi} from '@/views/Canvas/usePixi'
|
|
|
import {ElMessage, ElLoading} from 'element-plus'
|
|
|
import useCanvasHotkey from '@/hooks/useCanvasHotkey'
|
|
|
import useCanvasExport from "@/hooks/useCanvasExport";
|
|
|
+import {WorkSpaceElement} from "@/types/canvas";
|
|
|
+import {propertiesToInclude, WorkSpaceDrawType} from "@/configs/canvas";
|
|
|
+import {Pattern} from "fabric";
|
|
|
+import {MaxSize, MinSize, TransparentFill} from "@/configs/background";
|
|
|
+import {mm2px, px2mm} from "@/utils/image";
|
|
|
+
|
|
|
|
|
|
const fabricStore = useFabricStore()
|
|
|
const mainStore = useMainStore()
|
|
|
+const {sizeMode, unitMode} = storeToRefs(mainStore);
|
|
|
+const {clip, safe, zoom, opacity} = storeToRefs(fabricStore);
|
|
|
const router = useRouter()
|
|
|
const templatesStore = useTemplatesStore()
|
|
|
const userStore = useUserStore()
|
|
|
@@ -192,7 +200,20 @@ onMounted(async () => {
|
|
|
const message = JSON.parse(event.data);
|
|
|
|
|
|
if (message.msgType == "loadTemplate") {
|
|
|
- getPreviewTemplateDetail(query.template, message.data, uuid.value)
|
|
|
+ // getPreviewTemplateDetail(query.template, message.data, outerSessionId)
|
|
|
+ // 这个地方有未知原因,重新加载模板后会让canvas渲染停止,用别的方法该参数吧
|
|
|
+
|
|
|
+ // const formData = ref({
|
|
|
+ // backgroundWidth: 2000.0,
|
|
|
+ // backgroundHeight: 400.0,
|
|
|
+ // backgroundColor: "rgba(255,0,0,1)",
|
|
|
+ // objects: "",
|
|
|
+ // });
|
|
|
+ const color = message.data.backgroundColor
|
|
|
+ const width = mm2px(message.data.backgroundWidth) * zoom.value
|
|
|
+ const height = mm2px(message.data.backgroundHeight) * zoom.value
|
|
|
+ updateBackground({color: color, fill: color})
|
|
|
+ changeTemplateSize(width, height)
|
|
|
} else if (message.msgType == "submitOrder") {
|
|
|
//提交当前设计
|
|
|
// const svgData: string[] = []
|
|
|
@@ -232,6 +253,111 @@ onUnmounted(() => {
|
|
|
window.removeEventListener('paste', pasteListener as any)
|
|
|
})
|
|
|
|
|
|
+//以下是loadTemplate需要的东西,当前已放弃后台渲染,直接纯前端操作了
|
|
|
+const {currentTemplate} = storeToRefs(templatesStore);
|
|
|
+const background = computed(() => {
|
|
|
+ if (!currentTemplate.value) {
|
|
|
+ return {
|
|
|
+ fillType: 0,
|
|
|
+ fill: TransparentFill,
|
|
|
+ backgroundColor: "#fff",
|
|
|
+ } as WorkSpaceElement;
|
|
|
+ }
|
|
|
+ if (!currentTemplate.value.workSpace) {
|
|
|
+ return {
|
|
|
+ fillType: 0,
|
|
|
+ fill: TransparentFill,
|
|
|
+ backgroundColor: "#fff",
|
|
|
+ } as WorkSpaceElement;
|
|
|
+ }
|
|
|
+ return currentTemplate.value.workSpace;
|
|
|
+});
|
|
|
+// 设置背景
|
|
|
+const updateBackground = (props: Partial<WorkSpaceElement>) => {
|
|
|
+ const [canvas] = useCanvas();
|
|
|
+ const workSpaceDraw = canvas.getObjects().filter((item) => item.id === WorkSpaceDrawType)[0];
|
|
|
+ if (!workSpaceDraw) return;
|
|
|
+ workSpaceDraw.set({...props});
|
|
|
+ if (props.fill instanceof Pattern) {
|
|
|
+ props.fill = props.fill.toObject() as Pattern
|
|
|
+ }
|
|
|
+ templatesStore.updateWorkSpace({workSpace: {...background.value, ...props}});
|
|
|
+ const workProps = workSpaceDraw.toObject(propertiesToInclude as any[]);
|
|
|
+ templatesStore.updateElement({id: workSpaceDraw.id, props: {...workProps, ...props}});
|
|
|
+ canvas.renderAll();
|
|
|
+};
|
|
|
+
|
|
|
+const templateWidth = computed(() => {
|
|
|
+ const workWidth = currentTemplate.value.width / currentTemplate.value.zoom;
|
|
|
+ return unitMode.value === 0 ? px2mm(workWidth) : workWidth;
|
|
|
+});
|
|
|
+const templateHeight = computed(() => {
|
|
|
+ const workHeight = currentTemplate.value.height / currentTemplate.value.zoom;
|
|
|
+ return unitMode.value === 0 ? px2mm(workHeight) : workHeight;
|
|
|
+});
|
|
|
+const canvasWidth = ref<number>(templateWidth.value);
|
|
|
+const canvasHeight = ref<number>(templateHeight.value);
|
|
|
+// 固定宽高
|
|
|
+const isFixed = ref(false);
|
|
|
+// 获取画布尺寸
|
|
|
+const getCanvasSize = () => {
|
|
|
+ let width =
|
|
|
+ unitMode.value === 0 ? mm2px(canvasWidth.value) : canvasWidth.value;
|
|
|
+ let height =
|
|
|
+ unitMode.value === 0 ? mm2px(canvasHeight.value) : canvasHeight.value;
|
|
|
+ width = width * zoom.value;
|
|
|
+ height = height * zoom.value;
|
|
|
+ return {width, height};
|
|
|
+};
|
|
|
+
|
|
|
+// 修改画布宽度
|
|
|
+const changeTemplateSize = (width, height) => {
|
|
|
+ const [canvas] = useCanvas();
|
|
|
+ const workSpaceDraw = canvas
|
|
|
+ .getObjects()
|
|
|
+ .filter((item) => item.id === WorkSpaceDrawType)[0];
|
|
|
+ if (!workSpaceDraw) return;
|
|
|
+ const ratio = currentTemplate.value.height / currentTemplate.value.width;
|
|
|
+ // let {width, height} = getCanvasSize();
|
|
|
+ if (width / zoom.value < mm2px(MinSize)) {
|
|
|
+ ElMessage({
|
|
|
+ message: t("style.minimumSizeLimit") + MinSize,
|
|
|
+ type: "warning",
|
|
|
+ });
|
|
|
+ width = mm2px(MinSize) * zoom.value;
|
|
|
+ }
|
|
|
+ if (width / zoom.value > mm2px(MaxSize)) {
|
|
|
+ ElMessage({
|
|
|
+ message: t("style.maximumSizeLimit") + MaxSize,
|
|
|
+ type: "warning",
|
|
|
+ });
|
|
|
+ width = mm2px(MaxSize) * zoom.value;
|
|
|
+ }
|
|
|
+ if (height / zoom.value < mm2px(MinSize)) {
|
|
|
+ ElMessage({
|
|
|
+ message: t("style.minimumSizeLimit") + MinSize,
|
|
|
+ type: "warning",
|
|
|
+ });
|
|
|
+ height = mm2px(MinSize) * zoom.value;
|
|
|
+ }
|
|
|
+ if (height / zoom.value > mm2px(MaxSize)) {
|
|
|
+ ElMessage({
|
|
|
+ message: t("style.maximumSizeLimit") + MaxSize,
|
|
|
+ type: "warning",
|
|
|
+ });
|
|
|
+ height = mm2px(MaxSize) * zoom.value;
|
|
|
+ }
|
|
|
+ // width = isFixed.value ? height / ratio : width;
|
|
|
+ // height = isFixed.value ? width * ratio : height;
|
|
|
+ workSpaceDraw.set({width: width / zoom.value, height: height / zoom.value});
|
|
|
+ templatesStore.setSize(width, height, zoom.value);
|
|
|
+ sizeMode.value = 2;
|
|
|
+ canvas.renderAll();
|
|
|
+ // resetCanvas()
|
|
|
+ // addHistorySnapshot();
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
</script>
|
|
|
|
|
|
<style lang="scss" scoped>
|