Legend.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <template>
  2. <div class="legend">
  3. <MenuCard
  4. :menuData="{
  5. type: 'legend',
  6. title: '图例',
  7. ifChange: false,
  8. boxWidth: legendData.boxWidth,
  9. boxHeight: legendData.boxHeight,
  10. menuIndex: legendData.menuIndex,
  11. subMenuIndex: legendData.subMenuIndex ? legendData.subMenuIndex : ''
  12. }"
  13. >
  14. <div class="legend-container">
  15. <div
  16. class="legend-container-left"
  17. :style="{
  18. width: legendData.leftWidth ? legendData.leftWidth : '50%'
  19. }"
  20. >
  21. <div
  22. class="legend-icon"
  23. v-for="(item, index) in legendData.legendIcon"
  24. :key="index"
  25. :style="{ background: item.background, border: item.border }"
  26. ></div>
  27. </div>
  28. <div
  29. class="legend-container-right"
  30. :style="{
  31. width: legendData.rightWidth ? legendData.rightWidth : '50%'
  32. }"
  33. >
  34. <el-popover
  35. placement="right-start"
  36. width="200"
  37. :content="item.info"
  38. trigger="hover"
  39. v-for="item in legendData.legendTitle"
  40. :key="item.name"
  41. >
  42. <div
  43. slot="reference"
  44. class="legend-title"
  45. :style="{
  46. width: legendData.rightItemWidth + 'px' ? legendData.rightItemWidth + 'px' : '50px'
  47. }"
  48. >
  49. <div slot="reference">
  50. <el-dropdown trigger="click" v-if="legendData.deleteLegendEdit" @command="commandDropdown">
  51. <span class="el-dropdown-link">
  52. {{ item.name }}
  53. </span>
  54. <el-dropdown-menu slot="dropdown">
  55. <!-- <el-dropdown-item icon="el-icon-edit" @click="updateColor()">修改颜色</el-dropdown-item> -->
  56. <el-dropdown-item icon="el-icon-delete" :command="item.name">删除图例</el-dropdown-item>
  57. </el-dropdown-menu>
  58. </el-dropdown>
  59. <span v-else>{{ item.name }}</span>
  60. </div>
  61. </div>
  62. </el-popover>
  63. <!-- <div
  64. class="legend-title"
  65. v-for="item in legendData.legendTitle"
  66. :key="item"
  67. :style="{
  68. width:
  69. legendData.rightItemWidth + 'px'
  70. ? legendData.rightItemWidth + 'px'
  71. : '50px',
  72. }"
  73. >
  74. {{ item }}
  75. </div> -->
  76. </div>
  77. </div>
  78. </MenuCard>
  79. </div>
  80. </template>
  81. <script>
  82. import MenuCard from "@/components/layout/MenuCard.vue";
  83. /**
  84. * 通用图例
  85. */
  86. export default {
  87. name: "Legend",
  88. components: {
  89. MenuCard
  90. },
  91. props: ["legendData"],
  92. data() {
  93. return {};
  94. },
  95. mounted() {},
  96. destroy() {},
  97. methods: {
  98. commandDropdown(command) {
  99. this.$emit("deleteLegend", command);
  100. }
  101. }
  102. };
  103. </script>
  104. <style lang="less" scoped>
  105. @commonBorderColor: #00aaff;
  106. .tooltip {
  107. display: block !important;
  108. padding: 4px;
  109. z-index: 10000;
  110. .tooltip-inner {
  111. background: black;
  112. color: white;
  113. border-radius: 16px;
  114. padding: 5px 10px 4px;
  115. }
  116. .tooltip-arrow {
  117. display: none;
  118. }
  119. &[aria-hidden="true"] {
  120. visibility: hidden;
  121. opacity: 0;
  122. transition: opacity 0.15s, visibility 0.15s;
  123. }
  124. &[aria-hidden="false"] {
  125. visibility: visible;
  126. opacity: 1;
  127. transition: opacity 0.15s;
  128. }
  129. }
  130. .legend {
  131. pointer-events: auto;
  132. .legend-container {
  133. width: 100%;
  134. height: 100%;
  135. position: relative;
  136. display: flex;
  137. justify-content: center;
  138. align-items: center;
  139. &-left {
  140. height: 100%;
  141. position: absolute;
  142. left: 0;
  143. top: 0;
  144. display: flex;
  145. flex-direction: column;
  146. justify-content: space-evenly;
  147. .legend-icon {
  148. width: 25px;
  149. height: 15px;
  150. background: @commonBorderColor;
  151. border-radius: 2px;
  152. margin: 0 auto;
  153. }
  154. }
  155. &-right {
  156. height: 100%;
  157. position: absolute;
  158. right: 0;
  159. top: 0;
  160. display: flex;
  161. flex-direction: column;
  162. align-items: center;
  163. justify-content: space-evenly;
  164. overflow: hidden;
  165. text-overflow: ellipsis;
  166. white-space: nowrap;
  167. .legend-title {
  168. // width: 50px;
  169. height: 20px;
  170. display: flex;
  171. align-items: center;
  172. justify-content: flex-start;
  173. color: white;
  174. pointer-events: auto;
  175. }
  176. }
  177. }
  178. }
  179. </style>