gojs设置

<template>
    <div class="canvas-view" id="userPortrait">
    </div>
</template>
<script>
import '@/common/go/go-debug'
export default {
    name: 'UserPortrait',
    data (){
        return {
            instance: ''
        }
    },
    mounted(){
        console.log(go)
        this.init()
    },
    methods: {
        init(){
            var $ = go.GraphObject.make;
            var myDiagram =
            $(go.Diagram, "userPortrait",
                {
                    initialContentAlignment: go.Spot.Center, // center Diagram contents
                    "undoManager.isEnabled": false, // enable Ctrl-Z to undo and Ctrl-Y to redo
                    isReadOnly: true, //禁止复制
                    layout: $(go.TreeLayout, // specify a Diagram.layout that arranges trees
                        { angle: 90, layerSpacing: 35 }
                    ),
                    nodeSelectionAdornmentTemplate: $(go.Adornment, "Auto",
                        $(go.Shape, "Rectangle", { stroke: null, fill: null }),
                    ),
                }
            );
            
            // the template we defined earlier
            myDiagram.nodeTemplate =
            $(go.Node, "Horizontal",
                // 为整个Node背景设置为浅蓝色
                { background: "#44CCFF" },
                $(go.Panel, "Table",
                    new go.Binding("itemArray", "people"),
                    { margin: 4,
                    defaultAlignment: go.Spot.Left,
                    itemTemplate:
                        $(go.Panel, "TableRow",
                            new go.Binding("background", "back"),
                            $(go.TextBlock, new go.Binding("text", "name"),
                                { column: 0, margin: 2, font: "bold 10pt sans-serif" }
                            ),
                            $(go.TextBlock, new go.Binding("text", "phone"),
                                { column: 1, margin: 2, font: "bold 10pt sans-serif" }
                            )
                        )  // end of itemTemplate
                    }
                ),
                $(go.Picture,
                // Pictures 应该指定宽高.
                // 当没有图片时显示红色的背景
                // 或者当图片为透明的时候也是.
                { margin: 10, width: 100, height: 100, background: "red" },
                // Picture.source参数值与模型数据中的"source"字段绑定
                "./../../assets/images/man.png"),
                $(go.Panel, "Table",
                    new go.Binding("itemArray", "people1"),
                    { margin: 4,
                    defaultAlignment: go.Spot.Left,
                    itemTemplate:
                        $(go.Panel, "TableRow",
                            new go.Binding("background", "back"),
                            $(go.TextBlock, new go.Binding("text", "name"),
                                { column: 0, margin: 2, font: "bold 10pt sans-serif" }
                            ),
                            $(go.TextBlock, new go.Binding("text", "phone"),
                                { column: 1, margin: 2, font: "bold 10pt sans-serif" }
                            )
                        )  // end of itemTemplate
                    }
                ),
            )
            // myDiagram.add(
            //     $(go.Part,  // this Part is not bound to any model data
            //     {
            //         layerName: "Background", position: new go.Point(0, 0),
            //         selectable: false, pickable: false
            //     },
            //     $(go.Picture,{width: '100%',height: '100%'}, "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1560427539066&di=c438347c80d49e56f6cfe6fc99f192b3&imgtype=0&src=http%3A%2F%2Fbpic.588ku.com%2Fback_pic%2F04%2F01%2F56%2F605801d2646e265.jpg")
            // ));

            let nodeDataArray =
            [
                { key: "name1", name: "Don Meow",   source: "cat1.png",people: [
                        { name: "Alice", phone: "2345", loc: "C4-E18" },
                        { name: "Bob", phone: "9876", loc: "E1-B34" },
                        { name: "Carol", phone: "1111", loc: "C4-E23" }
                    ],
                    people1: [
                        { name: "专业", phone: "2345", loc: "C4-E18" },
                        { name: "请求", phone: "9876", loc: "E1-B34"},
                        { name: "颜色", phone: "1111", loc: "C4-E23" }
                    ]
                },
                { key: "name2", name: "Don Meow",   source: "cat1.png",people: [
                        { name: "Alice", phone: "2345", loc: "C4-E18" },
                        { name: "Bob", phone: "9876", loc: "E1-B34" },
                        { name: "Carol", phone: "1111", loc: "C4-E23" }
                    ],
                    people1: [
                        { name: "专业", phone: "2345", loc: "C4-E18" },
                        { name: "请求", phone: "9876", loc: "E1-B34"},
                        { name: "颜色", phone: "1111", loc: "C4-E23" }
                    ]
                }
            ],
            linkDataArray = [{
                from: 'name1', to: 'name2',desc: '说明'
            }];
            myDiagram.linkTemplate =
            $(go.Link,
                $(go.Shape, {stroke: "red", strokeWidth: 1}),//连接线样式
                $(go.Shape, { toArrow: "Standard", stroke: "red", strokeWidth: 1}),//箭头样式
                $(go.Panel, "Auto",  // this whole Panel is a link label
                    $(go.Shape, "TenPointedStar", { fill: "yellow", stroke: "green" }),//填充色彩
                    $(go.TextBlock, { margin: 3 },//文本
                    new go.Binding("text", "desc"))
            ));
            myDiagram.model = new go.GraphLinksModel(nodeDataArray,linkDataArray);
            myDiagram.addDiagramListener("ObjectSingleClicked", this.changeFn)
        },
        changeFn(e){
            console.log(e.subject.part)
            var part = e.subject.part
            if (!(part instanceof go.Link)) console.log(part.data);
        }
    }
}
</script>

<style lang="less">
body,html{
    height: 100%;
    width: 100%;
    margin: 0;
    padding: 0;
}
.canvas-view {
    width: 100%;
    height: 100%;
}
</style>

复制代码

转载于:https://juejin.im/post/5d06fedff265da1b6a34946a

猜你喜欢

转载自blog.csdn.net/weixin_33750452/article/details/93168590