update 思维导图
This commit is contained in:
@@ -89,7 +89,8 @@ export default {
|
|||||||
},
|
},
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
data: {}
|
data: {},
|
||||||
|
graph: null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
@@ -186,12 +187,12 @@ export default {
|
|||||||
x: 0,
|
x: 0,
|
||||||
y: 0,
|
y: 0,
|
||||||
width: this.nodeWidth + this.expendCollapseIconR + NODE_ICON_MARGIN,
|
width: this.nodeWidth + this.expendCollapseIconR + NODE_ICON_MARGIN,
|
||||||
height: this.nodeHeight,
|
height: this.nodeHeight
|
||||||
})
|
})
|
||||||
return nodeContainer
|
return nodeContainer
|
||||||
}
|
}
|
||||||
}, 'single-shape')
|
}, 'single-shape')
|
||||||
const graph = new G6.TreeGraph({
|
this.graph = new G6.TreeGraph({
|
||||||
container: this.domId,
|
container: this.domId,
|
||||||
modes: {
|
modes: {
|
||||||
default: [{
|
default: [{
|
||||||
@@ -236,9 +237,43 @@ export default {
|
|||||||
G6.Util.traverseTree(this.data, (item) => {
|
G6.Util.traverseTree(this.data, (item) => {
|
||||||
item.id = item[this.mapDataKeyField]
|
item.id = item[this.mapDataKeyField]
|
||||||
})
|
})
|
||||||
graph.data(this.data)
|
this.graph.data(this.data)
|
||||||
graph.render()
|
this.graph.render()
|
||||||
graph.fitView()
|
this.graph.fitView()
|
||||||
|
},
|
||||||
|
searchNode (nodeId) {
|
||||||
|
const item = this.graph.findById(nodeId)
|
||||||
|
const matrix = item.get('group').getMatrix()
|
||||||
|
const point = {
|
||||||
|
x: matrix[6],
|
||||||
|
y: matrix[7]
|
||||||
|
}
|
||||||
|
const width = this.graph.get('width')
|
||||||
|
const height = this.graph.get('height')
|
||||||
|
// 找到视口中心
|
||||||
|
var viewCenter = {
|
||||||
|
x: width / 2,
|
||||||
|
y: height / 2
|
||||||
|
}
|
||||||
|
var modelCenter = this.graph.getPointByCanvas(viewCenter.x, viewCenter.y)
|
||||||
|
var viewportMatrix = this.graph.get('group').getMatrix()
|
||||||
|
// 画布平移的目标位置,最终目标是graph.translate(dx, dy);
|
||||||
|
var dx = (modelCenter.x - point.x) * viewportMatrix[0]
|
||||||
|
var dy = (modelCenter.y - point.y) * viewportMatrix[4]
|
||||||
|
var lastX = 0
|
||||||
|
var lastY = 0
|
||||||
|
var newX = void 0
|
||||||
|
var newY = void 0
|
||||||
|
// 动画每次平移一点,直到目标位置
|
||||||
|
this.graph.get('canvas').animate({
|
||||||
|
onFrame: (ratio) => {
|
||||||
|
newX = dx * ratio
|
||||||
|
newY = dy * ratio
|
||||||
|
this.graph.translate(newX - lastX, newY - lastY)
|
||||||
|
lastX = newX
|
||||||
|
lastY = newY
|
||||||
|
}
|
||||||
|
}, 300, 'easeCubic')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<a-form layout="inline" @keyup.enter.native="searchQuery">
|
<a-form layout="inline" @keyup.enter.native="searchQuery">
|
||||||
<a-row :gutter="24">
|
<a-row :gutter="24">
|
||||||
<a-col :md="6" :sm="8">
|
<a-col :md="6" :sm="8">
|
||||||
<!--编号-->
|
<!-- 节点名称-->
|
||||||
<a-form-item :label="$t('businessSupport.standardizationActivity.nodeName')" :labelCol="labelCol" :wrapperCol="wrapperCol">
|
<a-form-item :label="$t('businessSupport.standardizationActivity.nodeName')" :labelCol="labelCol" :wrapperCol="wrapperCol">
|
||||||
<a-select
|
<a-select
|
||||||
show-search
|
show-search
|
||||||
@@ -33,7 +33,7 @@
|
|||||||
</a-row>
|
</a-row>
|
||||||
</a-form>
|
</a-form>
|
||||||
</div>
|
</div>
|
||||||
<mind-map dom-id="mountNode" :map-data="data" map-data-key-field="name" />
|
<mind-map ref="mindMap" dom-id="mountNode" :map-data="data" map-data-key-field="name" />
|
||||||
</a-card>
|
</a-card>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -54,6 +54,7 @@ export default {
|
|||||||
},
|
},
|
||||||
queryParam: {},
|
queryParam: {},
|
||||||
nodeNameList: [], // 查询的下拉数据
|
nodeNameList: [], // 查询的下拉数据
|
||||||
|
defaultNodeNameList: [], // 查询的下拉数据
|
||||||
data: {
|
data: {
|
||||||
name: '五十个字啊五十个字啊五十个字啊五十个字啊五十个字啊',
|
name: '五十个字啊五十个字啊五十个字啊五十个字啊五十个字啊',
|
||||||
children: [
|
children: [
|
||||||
@@ -164,12 +165,11 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
created () {
|
created () {
|
||||||
this.treeToArr([this.data], null, this.nodeNameList)
|
this.treeToArr([this.data], null, this.defaultNodeNameList)
|
||||||
console.log(this.nodeNameList)
|
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
handleSearch () {
|
handleSearch (value) {
|
||||||
|
this.nodeNameList = this.defaultNodeNameList.filter(tt => tt.name.indexOf(value) !== -1)
|
||||||
},
|
},
|
||||||
handleChange () {
|
handleChange () {
|
||||||
|
|
||||||
@@ -178,7 +178,7 @@ export default {
|
|||||||
|
|
||||||
},
|
},
|
||||||
searchQuery () {
|
searchQuery () {
|
||||||
|
this.$refs.mindMap.searchNode(this.queryParam.nodeName)
|
||||||
},
|
},
|
||||||
treeToArr (data, pid = null, res) {
|
treeToArr (data, pid = null, res) {
|
||||||
data.forEach(item => {
|
data.forEach(item => {
|
||||||
|
|||||||
Reference in New Issue
Block a user