EdbSourceToolTip.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <script setup>
  2. import { inject, nextTick, onMounted, ref } from 'vue'
  3. import { Node } from '@antv/x6'
  4. const getNode = inject('getNode')
  5. const getGraph = inject('getGraph')
  6. const data = ref({
  7. fold: false,
  8. routeQuery: {}
  9. })
  10. const show = ref(false)
  11. let node = {}, graph = {};
  12. function initNode() {
  13. node = getNode();
  14. graph = getGraph()
  15. node.data = node.data ? { ...data.value, ...node.data } : data.value
  16. data.value = node.data
  17. let { style } = data.value
  18. initStyle(style)
  19. }
  20. const container = ref(null)
  21. const antvTooltip = ref(null)
  22. const containerText = ref(null)
  23. function initStyle(style) {
  24. // !important 是有的节点 :hover不变色
  25. if (style) {
  26. // 背景色
  27. if (style.backgroundColor && style.backgroundColor.indexOf("!important") != -1) {
  28. let value = style.backgroundColor.split("!")[0]
  29. containerText.value.style.setProperty('background-color', value, 'important')
  30. } else {
  31. container.value.style.backgroundColor = style.backgroundColor ? style.backgroundColor :
  32. data.value.isRoot ? '#0052d9' : "#f2f6fa"
  33. }
  34. // 字体颜色
  35. if (style.color && style.color.indexOf("!important") != -1) {
  36. let value = style.color.split("!")[0]
  37. containerText.value.style.setProperty('color', value, 'important')
  38. } else {
  39. container.value.style.color = style.color ? style.color :
  40. data.value.isRoot ? '#ffffff' : "#000000"
  41. }
  42. nextTick(()=>{
  43. containerText.value.style.color = style.color
  44. })
  45. }
  46. }
  47. function flodApi(event) {
  48. const succ = graph.getSuccessors(node)
  49. if (succ) {
  50. succ.forEach((node, index) => {
  51. node.setVisible(data.value.fold)
  52. if (data.value.fold) {
  53. node.toBack()
  54. requestAnimationFrame(() => {
  55. let edge = graph.getIncomingEdges(node) || []
  56. edge[0].toBack()
  57. })
  58. }
  59. node.data.fold = !data.value.fold
  60. })
  61. }
  62. data.value.fold = !data.value.fold
  63. }
  64. function nodeMouseEnter() {
  65. show.value = true
  66. }
  67. function nodeMouseOut() {
  68. show.value = false
  69. }
  70. onMounted(() => {
  71. initNode()
  72. })
  73. </script>
  74. <template>
  75. <div
  76. class="container"
  77. ref="container"
  78. @mouseover="nodeMouseEnter"
  79. @mouseout="nodeMouseOut"
  80. >
  81. <t-tooltip
  82. class="container-input"
  83. ref="antvTooltip"
  84. >
  85. <span ref="containerText">{{ data.EdbName }}</span>
  86. <template #content>
  87. <div class="edb-tooltips-content-box" v-html="data.RuleTitle"></div>
  88. </template>
  89. </t-tooltip>
  90. <t-icon
  91. :name="data.fold ? 'add-circle' : 'minus-circle'"
  92. v-if="!data.isLeaf"
  93. @click="flodApi"
  94. v-show="show"
  95. class="fold-icon"
  96. />
  97. </div>
  98. </template>
  99. <style lang="scss">
  100. .edb-tooltips-content-box{
  101. div{
  102. padding-bottom: 5px;
  103. }
  104. }
  105. </style>
  106. <style lang="scss" scoped>
  107. .container {
  108. display: flex;
  109. align-items: center;
  110. justify-content: center;
  111. padding: 20px;
  112. height: 100%;
  113. width: 100%;
  114. box-sizing: border-box;
  115. background-color: #0052d9;
  116. box-shadow: 0 1px 5px rgba(0, 0, 0, 0.15);
  117. display: flex;
  118. cursor: pointer;
  119. position: relative;
  120. border-radius: 4px;
  121. .container-input {
  122. text-align: center;
  123. font-size: 16px;
  124. color: #ffffff;
  125. font-weight: 400;
  126. word-break: break-all;
  127. }
  128. // &:hover {
  129. // background-color: #ecf5ff;
  130. // .container-input {
  131. // color: #0052d9 !important;
  132. // text-decoration: underline;
  133. // }
  134. // }
  135. .fold-icon {
  136. position: absolute;
  137. font-size: 24px;
  138. color: #666666;
  139. bottom: -24px;
  140. left: 50%;
  141. transform: translateX(-50%);
  142. }
  143. }
  144. </style>