surprise
2024-03-05 1ce1b525e7470ebaaeb0d5cd1e59bd905c1a7114
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<template>
  <div class="subpage_Box">
    <My-bread :list="[
      `${$t('dataManage.dataManage')}`,
      `知识图谱`,
    ]"></My-bread>
    <el-divider />
    <div class="mainBox">
 
      <div class="searchComp subpage_Div">
        <el-form ref="ruleForm" :model="ruleForm" :inline="true">
          <div class="flex_box">
            <div style="margin-right: auto">
              <el-form-item size="mini" :label="$t('dataManage.vmobj.keyword')" prop="name">
                <el-input v-model="ruleForm.name" :placeholder="$t('shuJuGuanLi.lable1')" style="width:200px"><i
                    slot="suffix" class="el-icon-search" @click="submitForm('ruleForm')"
                    style="padding-right: 8px"></i></el-input>
              </el-form-item>
            </div>
            <div>
              <el-form-item>
                <el-button icon="el-icon-refresh" type="info" size="mini">{{ $t('common.empty') }}
                </el-button>
 
              </el-form-item>
            </div>
          </div>
 
        </el-form>
      </div>
      <div class="dividing-line"></div>
      <div class="echartBox">
        <div id="mynetwork" class="container">
 
        </div>
 
      </div>
    </div>
  </div>
</template>
<script>
import MyBread from "../../components/MyBread.vue";
import {
 
} from "../../api/api";
import $ from 'jquery'
import { getToken } from '../../utils/auth';
import * as  vis from 'vis';
 
export default {
  name: "vis",
  components: {
    MyBread,
  },
  data() {
    return {
      nodes: null,
      edges: null,
      network: null,
      ruleForm: {
 
      }
    };
  },
  watch: {
 
  },
  methods: {
    setResizeStart() {
      this.nodes = new vis.DataSet([
        { id: 1, label: 'Node 1' },
        { id: 2, label: 'Node 2' },
        { id: 3, label: 'Node 3' },
        { id: 4, label: 'Node 4' },
        { id: 5, label: 'Node 5' }
      ])
      this.edges = new vis.DataSet([
        { from: 1, to: 3 },
        { from: 1, to: 2 },
        { from: 2, to: 4 },
        { from: 2, to: 5 }
      ])
      this.globalTrace() // 页面初始化的时候调用方法
    },
    globalTrace() {
      // 建立拓扑图
      var container = document.querySelector('#mynetwork')
      // 以vis格式提供数据
      var data = {
        nodes: this.nodes,
        edges: this.edges
      }
      var options = { // 对vis的一些设置
        autoResize: true,
        manipulation: {  //该属性表示能够编辑,出现编辑操做按钮
 
          enabled: true
 
        }
      }
      // 初始化你的网络
      this.network = new vis.Network(container, data, options)
      this.network.on('click', function (params) {
        var nodeId = params.nodes[0];
        if (nodeId) {
          var selectedNode = this.body.data.nodes.get(nodeId); // 获取点击的节点对象   
          console.log("Selected Node: " + JSON.stringify(selectedNode));
          console.log("Selected Node ID: " + selectedNode.id);
          console.log("Selected Node Label: " + selectedNode.label);
          // 输出或进行其他操作...
        }
      })
      this.network.on("oncontext", function (params) {
        params.event.preventDefault();
        var nodeId = params.nodes[0];
        console.log(nodeId)
 
 
 
 
      })
    },
  },
  mounted() {
    this.setResizeStart();
 
 
 
 
  },
};
</script>
 
<style lang="less" scoped>
.subpage_Box {
  //height: 96%;
  width: 98%;
  padding: 1%;
  border-radius: 10px;
}
 
.mainBox {
  padding-top: 10px;
  width: 100%;
  height: calc(100% - 75px);
 
  .echartBox {
    width: 100%;
    height: calc(94% - 10px);
    margin-top: 10px;
 
    #mynetwork {
      width: 100%;
      height: 100%;
      border: 1px solid lightgray;
    }
 
 
  }
 
 
}
</style>