CoverArea.vue 1.5 KB

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