Annotation.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <template>
  2. <div class="tipInfo" :style="inputStyle">
  3. <div class="header">
  4. <span>人工标注</span>
  5. </div>
  6. <div class="contentBox">
  7. <el-input
  8. placeholder="输入标注内容"
  9. v-model="currentLabel"
  10. maxlength="10"
  11. size="mini"
  12. clearable
  13. @keydown.native="handleKeyDown"
  14. ref="labelInput"
  15. >
  16. </el-input>
  17. <div class="near" v-if="nearList.length">
  18. 最近:
  19. <el-tag
  20. type="primary"
  21. size="mini"
  22. effect="plain"
  23. v-for="pest in nearList"
  24. @click="currentLabel = pest"
  25. :key="pest"
  26. >{{ pest }}</el-tag
  27. >
  28. </div>
  29. <div class="btnBox">
  30. <el-button size="mini" @click="deleteRect">
  31. 取消操作
  32. </el-button>
  33. <el-button type="primary" size="mini" @click="confirmLabel">
  34. 保存标注
  35. </el-button>
  36. </div>
  37. </div>
  38. </div>
  39. </template>
  40. <script>
  41. export default {
  42. props: {
  43. inputStyle: {
  44. type: Object,
  45. default: () => ({
  46. left: `0px`,
  47. top: `0px`
  48. // transform: 'translate(-50%, -24px)' // 稍微下移避免遮挡
  49. })
  50. }
  51. },
  52. data() {
  53. return {
  54. nearList: [],
  55. currentLabel: ''
  56. }
  57. },
  58. computed: {},
  59. created() {},
  60. mounted() {
  61. this.getNearList()
  62. this.$nextTick(() => {
  63. this.$refs.labelInput.focus()
  64. })
  65. // this.$refs.labelInput.addEventListener('keydown', this.handleKeyDown)
  66. },
  67. beforeDestroy() {
  68. // this.$refs.labelInput.removeEventListener('keydown', this.handleKeyDown)
  69. },
  70. watch: {},
  71. methods: {
  72. handleKeyDown(e) {
  73. if (e.code === 'Enter') {
  74. this.confirmLabel()
  75. }
  76. },
  77. getNearList() {
  78. let nearList = localStorage.getItem('nearPestList')
  79. if (nearList) {
  80. this.nearList = JSON.parse(nearList)
  81. }
  82. },
  83. deleteRect() {
  84. this.$emit('deleteRect')
  85. },
  86. confirmLabel() {
  87. if (this.currentLabel) {
  88. this.$emit('confirmLabel', this.currentLabel)
  89. if (this.nearList.indexOf(this.currentLabel) !== -1) {
  90. this.nearList.splice(this.nearList.indexOf(this.currentLabel), 1) // 删除原来的
  91. }
  92. this.nearList.unshift(this.currentLabel) // 添加到最前面
  93. localStorage.setItem('nearPestList', JSON.stringify(this.nearList))
  94. } else {
  95. this.$message({
  96. message: '请输入标注内容',
  97. type: 'warning'
  98. })
  99. }
  100. }
  101. },
  102. components: {}
  103. }
  104. </script>
  105. <style scoped lang="less">
  106. .tipInfo {
  107. background: #fff;
  108. position: absolute;
  109. z-index: 4;
  110. box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  111. border-radius: 4px;
  112. border: 1px solid #ebeef5;
  113. .header {
  114. padding: 18px 20px;
  115. border-bottom: 1px solid #ebeef5;
  116. box-sizing: border-box;
  117. }
  118. }
  119. .near {
  120. font-size: 12px;
  121. margin: 10px 0;
  122. height: 20px;
  123. overflow: hidden;
  124. .el-tag {
  125. cursor: pointer;
  126. margin-right: 10px;
  127. }
  128. }
  129. .contentBox {
  130. width: 250px;
  131. padding: 20px;
  132. }
  133. .btnBox {
  134. margin-top: 10px;
  135. text-align: center;
  136. }
  137. .annotation-input {
  138. position: fixed;
  139. z-index: 100;
  140. background: white;
  141. padding: 8px;
  142. border-radius: 4px;
  143. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  144. display: flex;
  145. align-items: center;
  146. gap: 8px;
  147. }
  148. .annotation-input input {
  149. padding: 4px 8px;
  150. border: 1px solid #ddd;
  151. border-radius: 3px;
  152. min-width: 150px;
  153. }
  154. .annotation-input button {
  155. padding: 4px 8px;
  156. background: #4caf50;
  157. color: white;
  158. border: none;
  159. border-radius: 3px;
  160. cursor: pointer;
  161. }
  162. </style>