UNPKG

logic-helper

Version:

This template should help get you started developing with Vue 3 in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.

86 lines (84 loc) 2.42 kB
import { deepMerge, deepClone } from "@/utils/util.js"; import Actions from './extends/Actions.js' const allPorts = ['T', 'B', 'L', 'R'] export default class Node extends Actions { constructor(config) { super(); this.eleType = 'node'; this.model = null; this.init(config); } init(config) { for (let k in config) { this[k] = config[k]; } this.id = config.key; this.config = config; } getPort(name = allPorts) { if (Array.isArray(name)) { return name.map(n => this.getPort(n)); } return this.model.getNodePorts(this.id)[name]; } disablePort(fromto = 'both',name = allPorts) { if (Array.isArray(name)) { return name.forEach(n => this.disablePort(fromto,n)); } const port = this.getPort(name) if (port) { if (fromto == 'both' || fromto == 'from') { port.fromLinkable = false; } if (fromto == 'both' || fromto == 'to') { port.toLinkable = false; } } } enabledPort(fromto = 'both',name = allPorts) { this.syncData.enabledPort = [fromto,name] if (Array.isArray(name)) { return name.forEach(n => this.enabledPort(fromto,n)); } const port = this.getPort(name) if (port) { if (fromto == 'both' || fromto == 'from') { port.fromLinkable = true; } if (fromto == 'both' || fromto == 'to') { port.toLinkable = true; } } } showPort(name = allPorts) { if (Array.isArray(name)) { return name.forEach(n => this.showPort(n)); } const port = this.getPort(name) if (port) { port.visible = true } } hidePort(name = allPorts) { if (Array.isArray(name)) { return name.forEach(n => this.hidePort(n)); } const port = this.getPort(name) if (port) { port.visible = false } } refresh(){ const lines = {} this.getToEles().forEach(link=>{ if(lines[`${link.from}>${link.to}`]){ lines[`${link.from}>${link.to}`].remove(); } else { lines[`${link.from}>${link.to}`] = link } }) } }