index.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <template>
  2. <div class="image-cut">
  3. <ImgCutter @cutDown="handleCutDown" ref="imageCut" :crossOrigin="true" :originalGraph="false" :cutWidth="400" :cutHeight="260" v-show="cutImageShow" @on-clear-all="handleCutClearAll" :showChooseBtn="false" :lockScroll="false" :box-width="boxWidth" :box-height="boxHeight" :tool="true" @error="handleCutError">
  4. <span slot="open"></span>
  5. </ImgCutter>
  6. </div>
  7. </template>
  8. <script>
  9. import service from '@/service';
  10. import ImgCutter from 'vue-img-cutter';
  11. export default {
  12. name: 'image-cut',
  13. components: {ImgCutter},
  14. props:{
  15. /**
  16. * [boxWidth 弹出层宽度]
  17. * @type {Object}
  18. */
  19. boxWidth:{
  20. type:Number,
  21. default:service.dialogMax(0.9,0.7).width
  22. },
  23. /**
  24. * [boxHeight 弹出层高度]
  25. * @type {Object}
  26. */
  27. boxHeight:{
  28. type:Number,
  29. default:service.dialogMax(0.7,0.7).height
  30. },
  31. },
  32. data() {
  33. return {
  34. /**
  35. * [cutImageShow 是否显示图片裁剪功能]
  36. * @type {Boolean}
  37. */
  38. cutImageShow:false,
  39. /**
  40. * [openParams 设置参数]
  41. * @type {Object}
  42. */
  43. openParams:{}
  44. };
  45. },
  46. methods:{
  47. /**
  48. * [initialize 初始化]
  49. * @author szjcomo
  50. * @date 2021-02-22
  51. * @return {[type]} [description]
  52. */
  53. initialize:function() {
  54. let that = this;
  55. },
  56. /**
  57. * [cutOpen 开始图片裁剪]
  58. * @author szjcomo
  59. * @date 2021-02-22
  60. * @param {Object} data [description]
  61. * @return {[type]} [description]
  62. */
  63. cutOpen:function(data = {},params = {}) {
  64. let that = this;
  65. that.cutImageShow = true;
  66. that.openParams = params;
  67. that.$refs.imageCut.handleOpen(data);
  68. },
  69. /**
  70. * [handleCutDown 图片裁剪完成后回调函数]
  71. * @author szjcomo
  72. * @date 2021-02-22
  73. * @param {[type]} data [description]
  74. * @return {[type]} [description]
  75. */
  76. handleCutDown:function(data) {
  77. let that = this;
  78. that.cutImageShow = false;
  79. that.$emit('success',data,that.openParams);
  80. },
  81. /**
  82. * [handleCutClearAll 清空画布回调函数]
  83. * @author szjcomo
  84. * @date 2021-02-22
  85. * @return {[type]} [description]
  86. */
  87. handleCutClearAll:function() {
  88. let that = this;
  89. that.cutImageShow = false;
  90. },
  91. /**
  92. * [handleCutError 图片裁剪错误信息]
  93. * @author szjcomo
  94. * @date 2021-02-22
  95. * @param {[type]} err [description]
  96. * @return {[type]} [description]
  97. */
  98. handleCutError:function(err) {
  99. let that = this;
  100. that.$emit('error',err);
  101. }
  102. },
  103. //计算属性
  104. computed:{
  105. },
  106. //侦听属性
  107. watch:{
  108. },
  109. //实例刚在内存中被创建出来,此时,还没有初始化好 data 和 methods 属性
  110. beforeCreate:function(){
  111. },
  112. //实例已经在内存中创建OK,此时 data 和 methods 已经创建OK,此时还没有开始 编译模板
  113. created:function(){
  114. },
  115. //此时已经完成了模板的编译,但是还没有挂载到页面中
  116. beforeMount:function(){
  117. },
  118. //此时,已经将编译好的模板,挂载到了页面指定的容器中显示
  119. mounted:function(){
  120. let that = this;
  121. that.initialize();
  122. },
  123. //状态更新之前执行此函数, 此时 data 中的状态值是最新的,但是界面上显示的 数据还是旧的,因为此时还没有开始重新渲染DOM节点
  124. beforeUpdate:function(){
  125. },
  126. //实例更新完毕之后调用此函数,此时 data 中的状态值 和 界面上显示的数据,都已经完成了更新,界面已经被重新渲染好了!
  127. updated:function(){
  128. },
  129. //实例销毁之前调用。在这一步,实例仍然完全可用。
  130. beforeDestroy:function(){
  131. },
  132. //Vue 实例销毁后调用。调用后,Vue 实例指示的所有东西都会解绑定,所有的事件监听器会被移除,所有的子实例也会被销毁。
  133. destroyed:function(){
  134. }
  135. }
  136. </script>
  137. <style>
  138. .image-cut .mask{z-index: 9999;}
  139. </style>