edbLabelList.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <template>
  2. <div class="label-list">
  3. <draggable
  4. class="drag-wrap"
  5. v-model="labelList"
  6. animation="300"
  7. @start="dragStartHandler"
  8. @update="dragEnter"
  9. @end="movePageLabel"
  10. >
  11. <el-tooltip placement="bottom-start" v-for="label in labelList" :key="label.code" :content="getLabelText(label)">
  12. <div class="label-item" :class="{'active':activeLabelId===label.code}"
  13. @click.stop="clickLabel(label)"
  14. >
  15. <div class="label-icon-label">
  16. <img :src="require(`@/assets/img/document_m/label.svg`)">
  17. </div>
  18. <div class="label-text">{{getLabelText(label)}}</div>
  19. <div class="label-icon-close" @click.stop="deleteLabel(label)"> <i class="el-icon-close"></i> </div>
  20. </div>
  21. </el-tooltip>
  22. </draggable>
  23. </div>
  24. </template>
  25. <script>
  26. import draggable from 'vuedraggable';
  27. export default {
  28. components:{draggable},
  29. props:{
  30. labelList:{
  31. type:Array,
  32. default:()=>{
  33. return []
  34. }
  35. },
  36. activeLabelId:{ //标签id 一般是指标id/图库图表id
  37. type:String,
  38. default:'1'
  39. },
  40. currentLang:{ //默认是中文版
  41. type:String,
  42. default:'ch'
  43. }
  44. },
  45. data() {
  46. return {
  47. dragStartIndex:0
  48. };
  49. },
  50. methods: {
  51. //决定展示的指标名称为中文还是英文
  52. getLabelText(label){
  53. const nameMap = {
  54. 'ch':label.EdbName,
  55. 'en':label.EdbNameEn.length?label.EdbNameEn:label.EdbName
  56. }
  57. return nameMap[this.currentLang]
  58. },
  59. clickLabel(label){
  60. this.$emit('clickLabel',label)
  61. },
  62. deleteLabel(label){
  63. this.$emit('deleteLabel',label)
  64. },
  65. dragStartHandler({oldIndex}){
  66. this.dragStartIndex = oldIndex
  67. },
  68. dragEnter(){},
  69. movePageLabel({newIndex}){
  70. if(this.dragStartIndex===newIndex) return
  71. this.$emit('moveLabel',{oldIndex:this.dragStartIndex,newIndex})
  72. },
  73. },
  74. };
  75. </script>
  76. <style scoped lang="scss">
  77. .label-list{
  78. width:100%;
  79. //overflow: hidden;
  80. .drag-wrap{
  81. display: flex;
  82. }
  83. .label-item{
  84. display: flex;
  85. justify-content: space-between;
  86. align-items: center;
  87. cursor: pointer;
  88. max-width: 256px;
  89. min-width: 170px;
  90. box-sizing: border-box;
  91. padding:8px;
  92. border:1px solid #DCDFE6;
  93. background-color: white;
  94. border-radius: 4px;
  95. margin-right: 20px;
  96. position: relative;
  97. &.active{
  98. border-color: #409EFF;
  99. background-color: #ECF5FF;
  100. .label-text{
  101. color:#409EFF;
  102. }
  103. .label-icon-label img{
  104. transform:translateX(30px);
  105. filter:drop-shadow(#409EFF -30px 0px 0px);
  106. }
  107. .label-icon-close i{
  108. color: #409eff !important;;
  109. }
  110. }
  111. .label-icon-label{
  112. width:14px;
  113. height:14px;
  114. overflow: hidden;
  115. img{
  116. width: 100%;
  117. height: 100%;
  118. }
  119. }
  120. .label-text{
  121. flex: 1;
  122. overflow: hidden;
  123. text-overflow: ellipsis;
  124. white-space: nowrap;
  125. margin:0 5px;
  126. }
  127. }
  128. }
  129. </style>