ModifyPaperArea.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <template>
  2. <el-dialog
  3. class="modify-mark-area"
  4. :visible.sync="modalIsShow"
  5. top="0"
  6. :close-on-click-modal="false"
  7. :close-on-press-escape="false"
  8. append-to-body
  9. fullscreen
  10. :show-close="false"
  11. @open="visibleChange"
  12. >
  13. <div class="box-justify" slot="title">
  14. <h2 class="el-dialog__title">设置遮盖区域</h2>
  15. <div>
  16. <el-button type="success" @click="confirm">确定</el-button>
  17. <el-button @click="cancel">取消</el-button>
  18. </div>
  19. </div>
  20. <div class="tips-info">
  21. <i class="el-icon-warning"></i>
  22. 按住鼠标左键拖动,框选遮盖区。可以设置多个遮盖区。
  23. </div>
  24. <div v-if="modalIsShow" class="area-container">
  25. <area-cropper
  26. v-for="(paper, index) in papers"
  27. :id="`area-cropper-${index}`"
  28. :imgUrl="paper.imgUrl"
  29. ref="AreaCropper"
  30. :key="paper.imgUrl"
  31. :paper="paper"
  32. @curarea-change="cropperCurareaChange"
  33. @change="(areas) => areaChange(index, areas)"
  34. @paper-load="() => areaPaperLoaded(index)"
  35. ></area-cropper>
  36. </div>
  37. <div slot="footer"></div>
  38. </el-dialog>
  39. </template>
  40. <script>
  41. import AreaCropper from "./markParam//areaCropper/AreaCropper.vue";
  42. export default {
  43. name: "modify-paper-area",
  44. components: { AreaCropper },
  45. props: {
  46. areaConfigs: {
  47. type: Array,
  48. default() {
  49. return [];
  50. },
  51. },
  52. paperList: {
  53. type: Array,
  54. default() {
  55. return [];
  56. },
  57. },
  58. },
  59. data() {
  60. return {
  61. modalIsShow: false,
  62. papers: [],
  63. paperLoadedList: [],
  64. };
  65. },
  66. methods: {
  67. visibleChange() {
  68. this.paperLoadedList = [];
  69. this.papers = this.paperList.map((paper) => {
  70. let npaper = { ...paper };
  71. npaper.areas = [];
  72. return npaper;
  73. });
  74. this.areaConfigs.forEach((config) => {
  75. const index = config.i - 1;
  76. this.papers[index].areas.push({ ...config });
  77. });
  78. },
  79. areaPaperLoaded(paperIndex) {
  80. if (this.paperLoadedList.includes(paperIndex)) return;
  81. this.paperLoadedList.push(paperIndex);
  82. if (this.paperLoadedList.length === this.paperList.length) {
  83. this.scrollToFirstArea();
  84. }
  85. },
  86. scrollToFirstArea() {
  87. if (!this.areaConfigs.length) return;
  88. let paperIndexs = this.areaConfigs.map((item) => item.i - 1);
  89. paperIndexs.sort((a, b) => a - b);
  90. const firstPaperIndex = paperIndexs[0];
  91. this.$nextTick(() => {
  92. const areaCropperDom = document.getElementById(
  93. `area-cropper-${firstPaperIndex}`
  94. );
  95. let areaItems = areaCropperDom.querySelectorAll(".element-resize");
  96. let firstAreaItem = null;
  97. let topNum = 9999;
  98. for (let i = 0; i < areaItems.length; i++) {
  99. const element = areaItems[i];
  100. if (element.offsetTop < topNum) {
  101. topNum = element.offsetTop;
  102. firstAreaItem = element;
  103. }
  104. }
  105. // console.log(firstAreaItem);
  106. const scrollTop =
  107. areaCropperDom.offsetTop + firstAreaItem.offsetTop - 100;
  108. this.$el.querySelector(".el-dialog").scrollTop = scrollTop;
  109. });
  110. },
  111. cancel() {
  112. this.modalIsShow = false;
  113. },
  114. open() {
  115. this.modalIsShow = true;
  116. },
  117. areaChange(index, areas) {
  118. this.papers[index].areas = areas;
  119. },
  120. cropperCurareaChange(area) {
  121. this.$refs.AreaCropper.forEach((cropper) => {
  122. cropper.curareaChange(area);
  123. });
  124. },
  125. confirm() {
  126. let areas = [];
  127. this.papers.forEach((paper, pindex) => {
  128. if (!paper.areas.length) return;
  129. paper.areas.forEach((area) => {
  130. const narea = {
  131. i: pindex + 1,
  132. x: area.x,
  133. y: area.y,
  134. w: area.w,
  135. h: area.h,
  136. };
  137. areas.push(narea);
  138. });
  139. });
  140. this.$emit("modified", areas);
  141. this.cancel();
  142. },
  143. },
  144. };
  145. </script>