TailorTailorArea.vue 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <template>
  2. <div class="tailor-area">
  3. <div class="code-area-cont">
  4. <img :src="imageUrl" ref="editImage" />
  5. </div>
  6. </div>
  7. </template>
  8. <script>
  9. import Cropper from "cropperjs";
  10. export default {
  11. name: "tailor-area",
  12. props: {
  13. imageUrl: {
  14. type: String,
  15. require: true
  16. },
  17. curSetting: {
  18. type: Object,
  19. default() {
  20. return {};
  21. }
  22. }
  23. },
  24. data() {
  25. return {
  26. cropper: ""
  27. };
  28. },
  29. mounted() {
  30. this.initCropper();
  31. },
  32. methods: {
  33. initCropper() {
  34. const _this = this;
  35. const defTailorArea = this.curSetting
  36. ? this.curSetting.tailorTailorArea || this.curSetting.originTailorArea
  37. : {};
  38. this.cropper = new Cropper(this.$refs.editImage, {
  39. viewMode: 1,
  40. checkCrossOrigin: false,
  41. zoomable: false,
  42. minCropBoxWidth: 10,
  43. minCropBoxHeight: 10,
  44. ready() {
  45. _this.cropper.setData(defTailorArea);
  46. _this.$emit("on-ready");
  47. }
  48. });
  49. },
  50. checkValid() {
  51. const tailorTailorArea = {
  52. ...this.cropper.getData()
  53. };
  54. this.$emit("on-next", { tailorTailorArea });
  55. },
  56. pass() {
  57. this.$emit("on-next", { tailorTailorArea: {} });
  58. }
  59. },
  60. beforeDestroy() {
  61. if (this.cropper) {
  62. this.cropper.destroy();
  63. this.cropper = false;
  64. }
  65. }
  66. };
  67. </script>