OcrAreaSetDialog.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <template>
  2. <el-dialog
  3. class="ocr-area-dialog"
  4. :visible.sync="modalIsShow"
  5. fullscreen
  6. :close-on-click-modal="false"
  7. :close-on-press-escape="false"
  8. :show-close="false"
  9. append-to-body
  10. @opened="dialogOpened"
  11. @closed="dialogClosed"
  12. >
  13. <div class="ocr-area-head">
  14. <h3>条码识别区设置</h3>
  15. <div>
  16. <el-button type="primary" @click="confirm">确认</el-button>
  17. <el-button @click="close">取消</el-button>
  18. </div>
  19. </div>
  20. <div class="ocr-area-body">
  21. <div class="ocr-area-cont">
  22. <img :src="curImageUrl" ref="editImage" />
  23. </div>
  24. <div class="ocr-area-side">
  25. <div class="ocr-area-preview">
  26. <div class="ocr-area-spin">
  27. <div
  28. class="ocr-area-spin-img"
  29. :style="spinStyle"
  30. ref="OcrAreaSpinImg"
  31. ></div>
  32. </div>
  33. <div
  34. class="ocr-area-icon"
  35. title="顺时针旋转90度"
  36. @click="toRotateSpin"
  37. >
  38. <i class="icon icon-rotate-right-act"></i>
  39. </div>
  40. </div>
  41. </div>
  42. </div>
  43. </el-dialog>
  44. </template>
  45. <script>
  46. import Cropper from "cropperjs";
  47. import db from "@/plugins/db";
  48. import {
  49. getPreUploadFiles,
  50. renamePreUploadJsonFile
  51. } from "../../../plugins/imageOcr";
  52. import { evokeScanner } from "../../../plugins/scanner";
  53. export default {
  54. name: "ocr-area-set",
  55. data() {
  56. return {
  57. modalIsShow: false,
  58. cropper: "",
  59. rotate: 0,
  60. spinStyle: {},
  61. ocrArea: {},
  62. curImageUrl: ""
  63. };
  64. },
  65. methods: {
  66. close() {
  67. this.modalIsShow = false;
  68. },
  69. open() {
  70. this.modalIsShow = true;
  71. },
  72. async dialogOpened() {
  73. await this.evokeScanExe();
  74. await this.initData();
  75. this.initCropper();
  76. renamePreUploadJsonFile(this.GLOBAL.input);
  77. },
  78. async evokeScanExe() {
  79. await evokeScanner(this.GLOBAL.input).catch(error => {
  80. console.error(error);
  81. });
  82. },
  83. async initData() {
  84. const ocrArea = await db.getDict("ocrArea", "").catch(() => {});
  85. this.ocrArea = ocrArea ? JSON.parse(ocrArea) : {};
  86. const res = getPreUploadFiles(this.GLOBAL.input);
  87. console.log(res);
  88. if (!res.succeed) {
  89. this.$message.error(res.errorMsg);
  90. return;
  91. }
  92. this.curImageUrl = "file:///" + res.data[0].frontFile;
  93. },
  94. initCropper() {
  95. const _this = this;
  96. let defCodeArea = { ...this.ocrArea };
  97. this.rotate = this.ocrArea.rotate || 0;
  98. delete defCodeArea.rotate;
  99. this.spinStyle = {
  100. transform: `translate(-50%, -50%) rotate(${this.rotate}deg)`
  101. };
  102. this.cropper = new Cropper(this.$refs.editImage, {
  103. viewMode: 1,
  104. checkCrossOrigin: false,
  105. zoomable: false,
  106. minCropBoxWidth: 10,
  107. minCropBoxHeight: 10,
  108. preview: _this.$refs.OcrAreaSpinImg,
  109. ready() {
  110. _this.cropper.setData(defCodeArea);
  111. // _this.$emit("on-ready");
  112. }
  113. });
  114. },
  115. toRotateSpin() {
  116. this.rotate += 90;
  117. if (this.rotate === 360) this.rotate = 0;
  118. this.spinStyle = {
  119. transform: `translate(-50%, -50%) rotate(${this.rotate}deg)`
  120. };
  121. },
  122. confirm() {
  123. const ocrArea = {
  124. ...this.cropper.getData(),
  125. rotate: this.rotate
  126. };
  127. db.setDict("ocrArea", JSON.stringify(ocrArea));
  128. this.$store.commit("client/setOcrArea", ocrArea);
  129. this.$emit("modified", ocrArea);
  130. this.close();
  131. },
  132. dialogClosed() {
  133. if (this.cropper) {
  134. this.cropper.destroy();
  135. this.cropper = false;
  136. }
  137. }
  138. },
  139. beforeDestroy() {
  140. if (this.cropper) {
  141. this.cropper.destroy();
  142. this.cropper = false;
  143. }
  144. }
  145. };
  146. </script>