import { ref, computed } from "vue"; import { NODE_TYPE } from '../tools/index.d' import { ElMessageBox } from 'element-plus' import i18n from '@/lang' const t = i18n.global.t export class StateManager { // 历史记录-撤回/重做 mxHistory: any historyList: any historyIndex: any // 管理器 canvasManager: any layerManager: any eventManager: any toolManager: any // 设置管理器 setManager(options) { options.eventManager && (this.eventManager = options.eventManager) options.canvasManager && (this.canvasManager = options.canvasManager) options.layerManager && (this.layerManager = options.layerManager) options.toolManager && (this.toolManager = options.toolManager) } constructor(options) { this.mxHistory = ref(50) this.historyList = ref([]) this.historyIndex = ref(0) this.activeNodeID = ref("") } /** 设置激活节点 */ setActiveNodeID(id: string) { this.activeNodeID.value = id } /** 记录状态 */ recordState() { // if (this.historyIndex.value < this.historyList.value.length - 1) { // this.historyList.value.splice(this.historyIndex.value + 1) // } // const state = { // nodes: JSON.stringify(this.nodes.value) // } // this.historyList.value.push(state) // const size = this.historyList.value.length - this.mxHistory.value // if (size > 0) this.historyList.value.splice(0, size) // this.historyIndex.value = this.historyList.value.length - 1 } /** 撤回状态 */ undoState() { // var index = this.historyIndex.value - 1 // const state = this.historyList.value[index] // if (!state) return // this.historyIndex.value = index // this.nodes.value = JSON.parse(state.nodes) } /** 重做状态 */ redoState() { // var index = this.historyIndex.value + 1 // const state = this.historyList.value[index] // if (!state) return // this.historyIndex.value = index // this.nodes.value = JSON.parse(state.nodes) } }