第三步:使用test.vue
当前位置:   article > 正文

vue中使用go.js实现ER图(节点下拉展示)并去除插件水印_vue er图

vue er图

效果图(可拖拽):

第一步:下载go.js文件

直接通过 Go.js(直接右击保存链接到本地)

第二步:引入

(1)将下载好的js文件放入vue项目中的static文件夹下

 (2)在index.html中引入

 <script src="/static/go.js"></script>

 第三步:使用

test.vue

  1. <!--
  2. @description:
  3. @date:Created in 2021/12/9 18:51
  4. @modified By
  5. @version: 1.0.0
  6. -->
  7. <template>
  8. <div class="example">
  9. <div id="my-diagram-div"></div>
  10. <div></div>
  11. </div>
  12. </template>
  13. <script>
  14. export default {
  15. name: "example",
  16. data() {
  17. return {};
  18. },
  19. mounted() {
  20. this.test();
  21. },
  22. methods: {
  23. test() {
  24. let $ = go.GraphObject.make; // for conciseness in defining templates
  25. let myDiagram = $(
  26. go.Diagram,
  27. "my-diagram-div", // id挂载dome节点
  28. {
  29. allowDelete: false,
  30. allowCopy: false,
  31. layout: $(go.ForceDirectedLayout),
  32. "undoManager.isEnabled": true,
  33. }
  34. );
  35. var colors = {
  36. 'red': '#be4b15',
  37. 'green': '#52ce60',
  38. 'blue': '#6ea5f8',
  39. 'lightred': '#fd8852',
  40. 'lightblue': '#afd4fe',
  41. 'lightgreen': '#b9e986',
  42. 'pink': '#faadc1',
  43. 'purple': '#d689ff',
  44. 'orange': '#fdb400',
  45. }
  46. // the template for each attribute in a node's array of item data
  47. var itemTempl =
  48. $(go.Panel, "Horizontal",
  49. $(go.Shape,
  50. { desiredSize: new go.Size(15, 15), strokeJoin: "round", strokeWidth: 3, stroke: null, margin: 2 },
  51. new go.Binding("figure", "figure"),
  52. new go.Binding("fill", "color"),
  53. new go.Binding("stroke", "color")),
  54. $(go.TextBlock,
  55. {
  56. stroke: "#333333",
  57. font: "bold 14px sans-serif"
  58. },
  59. new go.Binding("text", "name"))
  60. );
  61. // define the Node template, representing an entity
  62. myDiagram.nodeTemplate =
  63. $(go.Node, "Auto", // the whole node panel
  64. {
  65. selectionAdorned: true,
  66. resizable: true,
  67. layoutConditions: go.Part.LayoutStandard & ~go.Part.LayoutNodeSized,
  68. fromSpot: go.Spot.AllSides,
  69. toSpot: go.Spot.AllSides,
  70. isShadowed: true,
  71. shadowOffset: new go.Point(3, 3),
  72. shadowColor: "#C5C1AA"
  73. },
  74. new go.Binding("location", "location").makeTwoWay(),
  75. // whenever the PanelExpanderButton changes the visible property of the "LIST" panel,
  76. // clear out any desiredSize set by the ResizingTool.
  77. new go.Binding("desiredSize", "visible", function (v) { return new go.Size(NaN, NaN); }).ofObject("LIST"),
  78. // define the node's outer shape, which will surround the Table
  79. $(go.Shape, "RoundedRectangle",
  80. { fill: 'white', stroke: "#eeeeee", strokeWidth: 3 }),
  81. $(go.Panel, "Table",
  82. { margin: 8, stretch: go.GraphObject.Fill },
  83. $(go.RowColumnDefinition, { row: 0, sizing: go.RowColumnDefinition.None }),
  84. // the table header
  85. $(go.TextBlock,
  86. {
  87. row: 0, alignment: go.Spot.Center,
  88. margin: new go.Margin(0, 24, 0, 2), // leave room for Button
  89. font: "bold 16px sans-serif"
  90. },
  91. new go.Binding("text", "key")),
  92. // the collapse/expand button
  93. $("PanelExpanderButton", "LIST", // the name of the element whose visibility this button toggles
  94. { row: 0, alignment: go.Spot.TopRight }),
  95. // the list of Panels, each showing an attribute
  96. $(go.Panel, "Vertical",
  97. {
  98. name: "LIST",
  99. row: 1,
  100. padding: 3,
  101. alignment: go.Spot.TopLeft,
  102. defaultAlignment: go.Spot.Left,
  103. stretch: go.GraphObject.Horizontal,
  104. itemTemplate: itemTempl
  105. },
  106. new go.Binding("itemArray", "items"))
  107. ) // end Table Panel
  108. ); // end Node
  109. // define the Link template, representing a relationship
  110. myDiagram.linkTemplate =
  111. $(go.Link, // the whole link panel
  112. {
  113. selectionAdorned: true,
  114. layerName: "Foreground",
  115. reshapable: true,
  116. routing: go.Link.AvoidsNodes,
  117. corner: 5,
  118. curve: go.Link.JumpOver
  119. },
  120. $(go.Shape, // the link shape
  121. { stroke: "#303B45", strokeWidth: 2.5 }),
  122. $(go.TextBlock, // the "from" label
  123. {
  124. textAlign: "center",
  125. font: "bold 14px sans-serif",
  126. stroke: "#1967B3",
  127. segmentIndex: 0,
  128. segmentOffset: new go.Point(NaN, NaN),
  129. segmentOrientation: go.Link.OrientUpright
  130. },
  131. new go.Binding("text", "text")),
  132. $(go.TextBlock, // the "to" label
  133. {
  134. textAlign: "center",
  135. font: "bold 14px sans-serif",
  136. stroke: "#1967B3",
  137. segmentIndex: -1,
  138. segmentOffset: new go.Point(NaN, NaN),
  139. segmentOrientation: go.Link.OrientUpright
  140. },
  141. new go.Binding("text", "toText"))
  142. );
  143. // create the model for the E-R diagram
  144. var nodeDataArray = [
  145. {
  146. key: "Products",
  147. items: [{ name: "ProductID", iskey: true, figure: "Decision", color: colors.red },
  148. { name: "ProductName", iskey: false, figure: "Hexagon", color: colors.blue },
  149. { name: "SupplierID", iskey: false, figure: "Decision", color: "purple" },
  150. { name: "CategoryID", iskey: false, figure: "Decision", color: "purple" }]
  151. },
  152. {
  153. key: "Suppliers",
  154. items: [{ name: "SupplierID", iskey: true, figure: "Decision", color: colors.red },
  155. { name: "CompanyName", iskey: false, figure: "Hexagon", color: colors.blue },
  156. { name: "ContactName", iskey: false, figure: "Hexagon", color: colors.blue },
  157. { name: "Address", iskey: false, figure: "Hexagon", color: colors.blue }]
  158. },
  159. {
  160. key: "Categories",
  161. items: [{ name: "CategoryID", iskey: true, figure: "Decision", color: colors.red },
  162. { name: "CategoryName", iskey: false, figure: "Hexagon", color: colors.blue },
  163. { name: "Description", iskey: false, figure: "Hexagon", color: colors.blue },
  164. { name: "Picture", iskey: false, figure: "TriangleUp", color: colors.pink }]
  165. },
  166. {
  167. key: "Order Details",
  168. items: [{ name: "OrderID", iskey: true, figure: "Decision", color: colors.red },
  169. { name: "ProductID", iskey: true, figure: "Decision", color: colors.red },
  170. { name: "UnitPrice", iskey: false, figure: "Circle", color: colors.green },
  171. { name: "Quantity", iskey: false, figure: "Circle", color: colors.green },
  172. { name: "Discount", iskey: false, figure: "Circle", color: colors.green }]
  173. },
  174. ];
  175. var linkDataArray = [
  176. { from: "Products", to: "Suppliers", text: "0..N", toText: "1" },
  177. { from: "Products", to: "Categories", text: "0..N", toText: "1" },
  178. { from: "Order Details", to: "Products", text: "0..N", toText: "1" }
  179. ];
  180. myDiagram.model = $(go.GraphLinksModel,
  181. {
  182. copiesArrays: true,
  183. copiesArrayObjects: true,
  184. nodeDataArray: nodeDataArray,
  185. linkDataArray: linkDataArray
  186. });
  187. }
  188. },
  189. };
  190. </script>
  191. <style scoped>
  192. #my-diagram-div {
  193. width: 1000px;
  194. height: 800px;
  195. }
  196. </style>

完成之后发现有水印

 第四步:去除水印

(1)在go.js文件中全局搜索si()函数,注意:括号是英文的,且与si中间没有空格。

(2)搜索后一共2个搜索结果,找到si()函数的这个方法,将下图红框处注释掉即可

 注释掉之后,保存

 就没了

 这个插件挺好的,我看里面种类齐全,适合项目中需要画流程图、分组关系图、电路图等都可以使用。

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号