|
@@ -8,50 +8,48 @@
|
|
|
</a-space>
|
|
|
</div>
|
|
|
<div ref="container" class="container" :style="{transform: `scale(${scale / 100})`}">
|
|
|
- <slot name="default">
|
|
|
-
|
|
|
- </slot>
|
|
|
+ <div v-for="item in details" :key="item.id" :id="item.id" :style="{position: 'absolute',left:item.x+'px',top:item.y+'px'}">
|
|
|
+ <slot name="default" :detail="item">
|
|
|
+ {{ item.x }}
|
|
|
+ </slot>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
// import jsPlumb from 'jsplumb'
|
|
|
-import Node from './modules/Node.vue'
|
|
|
import { newInstance, EVENT_CONNECTION, EVENT_CONNECTION_DBL_CLICK, EVENT_DRAG_STOP } from '@jsplumb/browser-ui'
|
|
|
export default {
|
|
|
- components: {
|
|
|
- Node,
|
|
|
- BaseForm,
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ jsPlumb: null,
|
|
|
+ instance: null,
|
|
|
+ scale: 100,
|
|
|
+ }
|
|
|
},
|
|
|
props: {
|
|
|
details: {
|
|
|
type: Array,
|
|
|
default: () => [
|
|
|
// {
|
|
|
- // name: '发起人',
|
|
|
// id: '1',
|
|
|
- // type: 1,
|
|
|
// y: 100,
|
|
|
// x: 500,
|
|
|
- // children: [],
|
|
|
// },
|
|
|
],
|
|
|
},
|
|
|
+ importDefaults: {
|
|
|
+ type: Object,
|
|
|
+ default: () => ({}),
|
|
|
+ },
|
|
|
+ config: {
|
|
|
+ type: Object,
|
|
|
+ default: () => ({}),
|
|
|
+ },
|
|
|
},
|
|
|
- data() {
|
|
|
- return {
|
|
|
- jsPlumb: null,
|
|
|
- instance: null,
|
|
|
- scale: 100,
|
|
|
- }
|
|
|
- },
|
|
|
- mounted() {
|
|
|
- this.init()
|
|
|
- },
|
|
|
- created() {},
|
|
|
methods: {
|
|
|
- init() {
|
|
|
+ init(details) {
|
|
|
const that = this
|
|
|
// 初始化节点
|
|
|
this.instance = newInstance({
|
|
@@ -60,10 +58,12 @@ export default {
|
|
|
containmentPadding: 10,
|
|
|
grid: { w: 20, h: 20 },
|
|
|
},
|
|
|
+ ...this.config,
|
|
|
})
|
|
|
this.instance.importDefaults({
|
|
|
- anchor: 'Continuous',
|
|
|
+ anchors: ['Bottom', 'Top'],
|
|
|
connectionsDetachable: false,
|
|
|
+ reattachConnections: true,
|
|
|
// 连接器类型,这里设置为Flowchart
|
|
|
connector: {
|
|
|
type: 'Flowchart',
|
|
@@ -98,6 +98,7 @@ export default {
|
|
|
// }
|
|
|
// }
|
|
|
],
|
|
|
+ ...this.importDefaults,
|
|
|
// 添加两个标签和箭头
|
|
|
})
|
|
|
this.instance.addSourceSelector('.bottom')
|
|
@@ -107,11 +108,10 @@ export default {
|
|
|
item.children.forEach((children) => {
|
|
|
that.instance.connect({
|
|
|
// 获取节点1和节点2的引用
|
|
|
- source: this.$refs[item.id][0].$el,
|
|
|
- target: this.$refs[children][0].$el,
|
|
|
+ source: document.getElementById(item.id),
|
|
|
+ target: document.getElementById(children),
|
|
|
// 连接方式,这里设置为连续
|
|
|
// paintStyle: { stroke: children.label == '同意' ? '#345' : 'red', strokeWidth: 3 },
|
|
|
- anchor: 'AutoDefault',
|
|
|
// 连接器类型,这里设置为Flowchart
|
|
|
connector: 'Flowchart',
|
|
|
// 添加两个标签和箭头
|
|
@@ -121,53 +121,22 @@ export default {
|
|
|
// instance.addEndpoint(this.$refs[item.name][0].$el, { target: false, source: false })
|
|
|
}
|
|
|
})
|
|
|
- // this.$refs.node.forEach((item) => {
|
|
|
- // console.log(item)
|
|
|
- // })
|
|
|
-
|
|
|
- // 连接三个端点
|
|
|
- // instance.connect({
|
|
|
- // // 获取节点1和节点2的引用
|
|
|
- // source: this.$refs.node1,
|
|
|
- // target: this.$refs.node2,
|
|
|
- // // 连接方式,这里设置为连续
|
|
|
- // anchor: 'AutoDefault',
|
|
|
- // // 连接器类型,这里设置为Flowchart
|
|
|
- // connector: 'Flowchart',
|
|
|
- // // 添加两个标签和箭头
|
|
|
- // overlays: [
|
|
|
- // { type: 'Label', options: { label: 'Connection 1', location: 0.5 } },
|
|
|
- // { type: 'Arrow', options: { location: 1 } },
|
|
|
- // ],
|
|
|
- // })
|
|
|
- // instance.connect({
|
|
|
- // source: this.$refs.node2,
|
|
|
- // target: this.$refs.node3,
|
|
|
- // connector: 'Flowchart',
|
|
|
- // anchor: 'AutoDefault',
|
|
|
- // overlays: [
|
|
|
- // { type: 'Label', options: { label: 'Connection 2', location: 0.5 } },
|
|
|
- // { type: 'Arrow', options: { location: 1 } },
|
|
|
- // ],
|
|
|
- // })
|
|
|
//拖拽
|
|
|
this.instance.bind(EVENT_DRAG_STOP, (val) => {
|
|
|
- console.log(val.el.__vue__)
|
|
|
- console.log(3)
|
|
|
- val.el.__vue__.setPosition(val.elements[0].pos)
|
|
|
+ that.$emit('dragStop', val.elements[0].pos)
|
|
|
})
|
|
|
// 建立链接
|
|
|
this.instance.bind(EVENT_CONNECTION, (val) => {
|
|
|
- console.log(val)
|
|
|
- console.log(2)
|
|
|
+ that.$emit('connection', {
|
|
|
+ source: val.source.__vue__,
|
|
|
+ target: val.target.__vue__,
|
|
|
+ })
|
|
|
})
|
|
|
- // 删除连接
|
|
|
+ // 双击连线
|
|
|
this.instance.bind(EVENT_CONNECTION_DBL_CLICK, (conn) => {
|
|
|
- this.$confirm({
|
|
|
- title: '确定删除所点击的链接吗?',
|
|
|
- onOk() {
|
|
|
- that.instance.deleteConnection(conn)
|
|
|
- },
|
|
|
+ that.$emit('connectionDblClick', {
|
|
|
+ source: conn.source.__vue__,
|
|
|
+ target: conn.target.__vue__,
|
|
|
})
|
|
|
})
|
|
|
this.$forceUpdate()
|
|
@@ -184,65 +153,18 @@ export default {
|
|
|
}
|
|
|
this.instance.setZoom(this.scale / 100)
|
|
|
},
|
|
|
- add(record, type) {
|
|
|
- const newVal = {
|
|
|
- name: type === 2 ? '条件分支' : '审核人',
|
|
|
- id: +new Date(),
|
|
|
- }
|
|
|
- if (record.children.length > 0) {
|
|
|
- const children = this.details
|
|
|
- .filter((detail) => {
|
|
|
- return record.children.includes(detail.id)
|
|
|
- })
|
|
|
- .reduce((pre, item) => {
|
|
|
- if (item.x > pre.x) {
|
|
|
- pre = item
|
|
|
- }
|
|
|
- return pre
|
|
|
- })
|
|
|
- record.children.push(newVal.id)
|
|
|
- this.details.push({
|
|
|
- x: children.x + 240,
|
|
|
- y: children.y,
|
|
|
- type,
|
|
|
- children: [],
|
|
|
- ...newVal,
|
|
|
- })
|
|
|
- } else {
|
|
|
- record.children.push(newVal.id)
|
|
|
- this.details.push({
|
|
|
- x: record.x,
|
|
|
- y: record.y + 250,
|
|
|
- type,
|
|
|
- children: [],
|
|
|
- ...newVal,
|
|
|
- })
|
|
|
- }
|
|
|
+ add(record) {
|
|
|
this.$nextTick(() => {
|
|
|
this.instance.connect({
|
|
|
- // 获取节点1和节点2的引用
|
|
|
- source: this.$refs[record.id][0].$el,
|
|
|
- target: this.$refs[newVal.id][0].$el,
|
|
|
- // 连接方式,这里设置为连续
|
|
|
- // paintStyle: { stroke: children.label == '同意' ? '#345' : 'red', strokeWidth: 3 },
|
|
|
- anchor: 'AutoDefault',
|
|
|
- // 连接器类型,这里设置为Flowchart
|
|
|
+ source: document.getElementById(record.source.id),
|
|
|
+ target: document.getElementById(record.target.id),
|
|
|
connector: 'Flowchart',
|
|
|
- // 添加两个标签和箭头
|
|
|
})
|
|
|
})
|
|
|
- // this.details.push()
|
|
|
},
|
|
|
//删除节点
|
|
|
-
|
|
|
- handleDelete(record) {
|
|
|
- this.instance.unmanage(this.$refs[record.id][0].$el, true)
|
|
|
- this.details = this.details.filter((item) => {
|
|
|
- return item.id !== record.id
|
|
|
- })
|
|
|
- },
|
|
|
- edit(record) {
|
|
|
- this.$refs.baseModal.base(record)
|
|
|
+ delete(record) {
|
|
|
+ this.instance.unmanage(document.getElementById(record.id), true)
|
|
|
},
|
|
|
},
|
|
|
}
|
|
@@ -294,11 +216,14 @@ export default {
|
|
|
position: relative;
|
|
|
display: flex;
|
|
|
flex-direction: column;
|
|
|
- min-height: calc(100vh - 100px);
|
|
|
+ min-height: calc(100vh - 200px);
|
|
|
+ max-height: calc(100vh - 200px);
|
|
|
+ overflow-y: auto;
|
|
|
+
|
|
|
width: 100%;
|
|
|
}
|
|
|
.scale {
|
|
|
- position: absolute;
|
|
|
+ position: fixed;
|
|
|
bottom: 20px;
|
|
|
right: 30px;
|
|
|
z-index: 9999;
|