annotation-box.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <div class="annotation-box" :style="style" @mousedown.stop.prevent @touchstart.stop.prevent>
  3. <div class="nw" @mousedown="resizeSelf('nw')" @touchstart="resizeSelf('nw')"></div>
  4. <div class="nn" @mousedown="resizeSelf('nn')" @touchstart="resizeSelf('nn')"></div>
  5. <div class="ne" @mousedown="resizeSelf('ne')" @touchstart="resizeSelf('ne')"></div>
  6. <div class="ww" @mousedown="resizeSelf('ww')" @touchstart="resizeSelf('ww')"></div>
  7. <div class="buttons">
  8. <template v-if="!immutable">
  9. <img alt="delete" src="@/assets/icons/trash.svg" @click="deleteSelf">
  10. </template>
  11. </div>
  12. <div class="ee" @mousedown="resizeSelf('ee')" @touchstart="resizeSelf('ee')"></div>
  13. <div class="sw" @mousedown="resizeSelf('sw')" @touchstart="resizeSelf('sw')"></div>
  14. <div class="ss" @mousedown="resizeSelf('ss')" @touchstart="resizeSelf('ss')"></div>
  15. <div class="se" @mousedown="resizeSelf('se')" @touchstart="resizeSelf('se')"></div>
  16. </div>
  17. </template>
  18. <script>
  19. export default {
  20. name: "annotation-box",
  21. props: ['type', 'image', 'position', 'socket', 'immutable', 'boxUrl'],
  22. computed: {
  23. backgroundColor: function () {
  24. switch (this.type) {
  25. case 'server':
  26. return 'rgba(255, 0, 0, 0.3)';
  27. default:
  28. return 'rgba(255, 255, 255, 0.3)';
  29. }
  30. },
  31. style: function () {
  32. const left = this.image.left;
  33. const top = this.image.top;
  34. const width = this.image.width;
  35. const height = this.image.height;
  36. return {
  37. left: (left + this.position.x * width) + 'px',
  38. top: (top + this.position.y * height) + 'px',
  39. width: (this.position.w * width) + 'px',
  40. height: (this.position.h * height) + 'px',
  41. backgroundColor: this.backgroundColor
  42. }
  43. }
  44. },
  45. methods: {
  46. deleteSelf: function () {
  47. this.socket.post(this.boxUrl, {delete: true, id: this.id});
  48. },
  49. resizeSelf: function (mode) {
  50. this.$emit('resize', this.position, mode, this.updateSelf);
  51. },
  52. updateSelf: function (value) {
  53. this.socket.post(this.boxUrl, value);
  54. }
  55. }
  56. }
  57. </script>
  58. <style scoped>
  59. .annotation-box {
  60. position: absolute;
  61. display: grid;
  62. grid-template-rows: 10px auto 10px;
  63. grid-template-columns: 10px auto 10px;
  64. }
  65. .buttons {
  66. display: flex;
  67. justify-content: center;
  68. align-items: center;
  69. }
  70. img {
  71. width: 2rem;
  72. filter: invert(1);
  73. opacity: 0.9;
  74. }
  75. .nn, .ss {
  76. cursor: ns-resize;
  77. }
  78. .ww, .ee {
  79. cursor: ew-resize;
  80. }
  81. .ne, .sw {
  82. cursor: nesw-resize;
  83. }
  84. .nw, .se {
  85. cursor: nwse-resize;
  86. }
  87. </style>