|
@@ -1,12 +1,12 @@
|
|
|
<template>
|
|
|
<div class="bar">
|
|
|
- <el-tooltip class="item" effect="dark" content="清除 (Cmd + D)" placement="bottom">
|
|
|
+ <el-tooltip class="item" effect="dark" content="清除 (Ctrl + D)" placement="bottom">
|
|
|
<el-button name="delete" @click="handleClick" class="item-space" size="small">
|
|
|
清除
|
|
|
</el-button>
|
|
|
</el-tooltip>
|
|
|
|
|
|
- <el-tooltip class="item" effect="dark" content="撤销 (Cmd + Z)" placement="bottom">
|
|
|
+ <el-tooltip class="item" effect="dark" content="撤销 (Ctrl + Z)" placement="bottom">
|
|
|
<el-button
|
|
|
:disabled="!canUndo"
|
|
|
name="undo"
|
|
@@ -17,66 +17,64 @@
|
|
|
</el-button>
|
|
|
</el-tooltip>
|
|
|
|
|
|
- <el-tooltip class="item" effect="dark" content="Redo (Cmd + Shift + Z)" placement="bottom">
|
|
|
+ <el-tooltip class="item" effect="dark" content="Redo (Ctrl + Shift + Z)" placement="bottom">
|
|
|
<el-button
|
|
|
:disabled="!canRedo"
|
|
|
name="redo"
|
|
|
@click="handleClick"
|
|
|
class="item-space"
|
|
|
size="small">
|
|
|
- redo
|
|
|
+ 恢复
|
|
|
</el-button>
|
|
|
</el-tooltip>
|
|
|
|
|
|
- <el-tooltip class="item" effect="dark" content="复制 (Cmd + Shift + Z)" placement="bottom">
|
|
|
+ <el-tooltip class="item" effect="dark" content="复制 (Ctrl + Shift + Z)" placement="bottom">
|
|
|
<el-button name="copy" @click="handleClick" class="item-space" size="small"> 复制 </el-button>
|
|
|
</el-tooltip>
|
|
|
|
|
|
- <el-tooltip class="item" effect="dark" content="剪切 (Cmd + X)" placement="bottom">
|
|
|
+ <el-tooltip class="item" effect="dark" content="剪切 (Ctrl + X)" placement="bottom">
|
|
|
<el-button name="cut" @click="handleClick" class="item-space" size="small"> 剪切 </el-button>
|
|
|
</el-tooltip>
|
|
|
|
|
|
- <el-tooltip class="item" effect="dark" content="粘贴 (Cmd + V)" placement="bottom">
|
|
|
+ <el-tooltip class="item" effect="dark" content="粘贴 (Ctrl + V)" placement="bottom">
|
|
|
<el-button name="paste" @click="handleClick" class="item-space" size="small">
|
|
|
粘贴
|
|
|
</el-button>
|
|
|
</el-tooltip>
|
|
|
|
|
|
- <el-tooltip class="item" effect="dark" content="保存PNG (Cmd + S)" placement="bottom">
|
|
|
- <el-button name="savePNG" @click="handleClick" class="item-space" size="small">
|
|
|
- 保存PNG
|
|
|
- </el-button>
|
|
|
- </el-tooltip>
|
|
|
+ <el-button name="print" @click="handleClick" class="item-space" size="small"> 打印 </el-button>
|
|
|
|
|
|
- <el-tooltip class="item" effect="dark" content="保存SVG (Cmd + S)" placement="bottom">
|
|
|
- <el-button name="saveSVG" @click="handleClick" class="item-space" size="small">
|
|
|
- 保存SVG
|
|
|
- </el-button>
|
|
|
- </el-tooltip>
|
|
|
+ <el-button name="savePNG" @click="handleClick" class="item-space" size="small">
|
|
|
+ 导出PNG
|
|
|
+ </el-button>
|
|
|
|
|
|
- <el-tooltip class="item" effect="dark" content="打印 (Cmd + P)" placement="bottom">
|
|
|
- <el-button name="print" @click="handleClick" class="item-space" size="small">
|
|
|
- 打印
|
|
|
- </el-button>
|
|
|
- </el-tooltip>
|
|
|
+ <el-button name="saveSVG" @click="handleClick" class="item-space" size="small">
|
|
|
+ 导出SVG
|
|
|
+ </el-button>
|
|
|
|
|
|
- <el-tooltip class="item" effect="dark" content="导出 (Cmd + P)" placement="bottom">
|
|
|
- <el-button name="toJSON" @click="handleClick" class="item-space" size="small">
|
|
|
- 导出JSON
|
|
|
- </el-button>
|
|
|
- </el-tooltip>
|
|
|
+ <el-button name="toJSON" @click="handleClick" class="item-space" size="small">
|
|
|
+ 导出JSON
|
|
|
+ </el-button>
|
|
|
+
|
|
|
+ <el-button name="toXML" @click="handleClick" class="item-space" size="small">
|
|
|
+ 导出XML
|
|
|
+ </el-button>
|
|
|
+ <el-button name="save" @click="handleClick" class="item-space" size="small"> 保存 </el-button>
|
|
|
</div>
|
|
|
</template>
|
|
|
<script setup lang="ts">
|
|
|
import FlowGraph from '../../graph'
|
|
|
import { DataUri } from '@antv/x6'
|
|
|
import { ref } from 'vue'
|
|
|
-import { XMLBuilder, XMLParser } from 'fast-xml-parser'
|
|
|
+import { XMLBuilder } from 'fast-xml-parser'
|
|
|
+import { downloadJson, downloadXml } from '@/utils/fileSaver'
|
|
|
+import { useWebSocketManager, wsClient, wsStatus } from '@/utils/webSocket'
|
|
|
+import { ElMessage } from 'element-plus'
|
|
|
+const { sendMessage } = useWebSocketManager()
|
|
|
const builder = new XMLBuilder()
|
|
|
-const parser = new XMLParser()
|
|
|
const { graph } = FlowGraph
|
|
|
const { history } = graph
|
|
|
-
|
|
|
+const route = useRoute()
|
|
|
const canUndo = ref(history.canUndo())
|
|
|
const canRedo = ref(history.canRedo())
|
|
|
|
|
@@ -192,13 +190,27 @@ function handleClick(event: Event) {
|
|
|
paste()
|
|
|
break
|
|
|
case 'toJSON':
|
|
|
- window.localStorage.setItem('graphJson', JSON.stringify(graph.toJSON()))
|
|
|
- // graph.fromJSON({cells:[graph.toJSON().cells[0],graph.toJSON().cells[1]]})
|
|
|
+ downloadJson(graph.toJSON(), 'graph')
|
|
|
+ break
|
|
|
+ case 'toXML':
|
|
|
const xmlContent = builder.build(graph.toJSON())
|
|
|
- window.localStorage.setItem('graphXML', xmlContent)
|
|
|
- // 解析 XML
|
|
|
- const jsonObj = parser.parse(xmlContent)
|
|
|
- window.localStorage.setItem('jsonObj', JSON.stringify(jsonObj))
|
|
|
+ downloadXml(xmlContent, 'graph')
|
|
|
+ break
|
|
|
+ case 'save':
|
|
|
+ if (wsClient.value && wsStatus.value === '已连接') {
|
|
|
+ const id = route.params.id as string
|
|
|
+ sendMessage({
|
|
|
+ serverName: 'wsClient',
|
|
|
+ type: 'saveFlow',
|
|
|
+ data: {
|
|
|
+ id,
|
|
|
+ flow: graph.toJSON()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ ElMessage.success('保存成功')
|
|
|
+ } else {
|
|
|
+ console.log('WebSocket 未连接,无法保存')
|
|
|
+ }
|
|
|
break
|
|
|
default:
|
|
|
break
|