|
|
@@ -167,6 +167,68 @@ const tmpSaveCurrentTemplate = () => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+function onWindowMessage(event) {
|
|
|
+ // 确保消息来自信任的来源
|
|
|
+ // if (event.origin !== "https://www.sd2000.com") {
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+
|
|
|
+ // 处理接收到的消息
|
|
|
+ console.log("Received message:", event.data);
|
|
|
+
|
|
|
+ //消息格式
|
|
|
+ // {
|
|
|
+ // msgType: 'loadTemplate',
|
|
|
+ // data: {
|
|
|
+ // xxx
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ const message = JSON.parse(event.data);
|
|
|
+
|
|
|
+ if (message.msgType == "loadTemplate") {
|
|
|
+ // 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
|
|
|
+ if (color)
|
|
|
+ updateBackground({color: color, fill: color})
|
|
|
+ if (width && height)
|
|
|
+ changeTemplateSize(width, height)
|
|
|
+ } else if (message.msgType == "submitOrder") {
|
|
|
+ //提交当前设计
|
|
|
+ // const svgData: string[] = []
|
|
|
+ // svgData.push(btoa(unescape(encodeURIComponent(getSVGData()))))
|
|
|
+
|
|
|
+ // exportSVG()
|
|
|
+
|
|
|
+ //先停止自动暂存定时器
|
|
|
+ tmpSaveFlag = false
|
|
|
+
|
|
|
+ const svgHtml = getSVGData()
|
|
|
+ console.log(svgHtml)
|
|
|
+ newDesignOrder(svgHtml, uuid.value).then((response) => {
|
|
|
+ if (response.httpCode == 200) {
|
|
|
+ console.log(response.data)
|
|
|
+
|
|
|
+ //给父页面发送canClose消息,表示可以关掉本页面了
|
|
|
+ const closeMsg = {
|
|
|
+ msgType: 'canClose'
|
|
|
+ }
|
|
|
+ window.parent.postMessage(JSON.stringify(closeMsg), '*');
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
onMounted(async () => {
|
|
|
const query = router.currentRoute.value.query
|
|
|
initRouter(query.template, query.runMode, query.sessionId)
|
|
|
@@ -181,65 +243,7 @@ onMounted(async () => {
|
|
|
if (query.runMode == 0) {
|
|
|
// 使用iframe方案,本网页是内嵌页面
|
|
|
// 监听来自父页面的消息
|
|
|
- window.addEventListener("message", function (event) {
|
|
|
- // 确保消息来自信任的来源
|
|
|
- // if (event.origin !== "https://www.sd2000.com") {
|
|
|
- // return;
|
|
|
- // }
|
|
|
-
|
|
|
- // 处理接收到的消息
|
|
|
- console.log("Received message:", event.data);
|
|
|
-
|
|
|
- //消息格式
|
|
|
- // {
|
|
|
- // msgType: 'loadTemplate',
|
|
|
- // data: {
|
|
|
- // xxx
|
|
|
- // }
|
|
|
- // }
|
|
|
- const message = JSON.parse(event.data);
|
|
|
-
|
|
|
- if (message.msgType == "loadTemplate") {
|
|
|
- // 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[] = []
|
|
|
- // svgData.push(btoa(unescape(encodeURIComponent(getSVGData()))))
|
|
|
-
|
|
|
- // exportSVG()
|
|
|
-
|
|
|
- //先停止自动暂存定时器
|
|
|
- tmpSaveFlag = false
|
|
|
-
|
|
|
- const svgHtml = getSVGData()
|
|
|
- console.log(svgHtml)
|
|
|
- newDesignOrder(svgHtml, uuid.value).then((response) => {
|
|
|
- if (response.httpCode == 200) {
|
|
|
- console.log(response.data)
|
|
|
-
|
|
|
- //给父页面发送canClose消息,表示可以关掉本页面了
|
|
|
- const closeMsg = {
|
|
|
- msgType: 'canClose'
|
|
|
- }
|
|
|
- window.parent.postMessage(JSON.stringify(closeMsg), '*');
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- }
|
|
|
- })
|
|
|
+ window.addEventListener("message", onWindowMessage)
|
|
|
|
|
|
//每隔5秒暂存一次用户的设计
|
|
|
setTimeout(tmpSaveCurrentTemplate, 5000);
|
|
|
@@ -251,6 +255,11 @@ onUnmounted(() => {
|
|
|
document.removeEventListener('keyup', keyupListener)
|
|
|
window.removeEventListener('blur', keyupListener)
|
|
|
window.removeEventListener('paste', pasteListener as any)
|
|
|
+ if (query.runMode == 0) {
|
|
|
+ // 使用iframe方案,本网页是内嵌页面
|
|
|
+ // 监听来自父页面的消息
|
|
|
+ window.removeEventListener("message", onWindowMessage)
|
|
|
+ }
|
|
|
})
|
|
|
|
|
|
//以下是loadTemplate需要的东西,当前已放弃后台渲染,直接纯前端操作了
|