cropper.vue 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <template>
  2. <view>
  3. <ksp-cropper mode="fixed" :width="minPicWidth" :height="minPicHeight" :maxWidth="1024" :maxHeight="1024"
  4. :url="url" @cancel="oncancel" @ok="uploadSuccess"></ksp-cropper>
  5. </view>
  6. </template>
  7. <script>
  8. import kspCropper from '@/uni_modules/ksp-cropper/components/ksp-cropper/ksp-cropper.vue'
  9. export default {
  10. components: {
  11. kspCropper
  12. },
  13. data() {
  14. return {
  15. // 保存触发事件
  16. eventChannel: '',
  17. minPicWidth: 100, //保存图片最小宽
  18. minPicHeight: 100, //保存图片最小高
  19. url: '' //图片
  20. }
  21. },
  22. onLoad(opt) {
  23. const that = this;
  24. if (opt.width) {
  25. that.minPicWidth = +opt.width;
  26. }
  27. if (opt.height) {
  28. that.minPicHeight = +opt.height;
  29. }
  30. // #ifdef APP-NVUE
  31. that.eventChannel = that.$scope.eventChannel; // 兼容APP-NVUE
  32. // #endif
  33. // #ifndef APP-NVUE
  34. that.eventChannel = that.getOpenerEventChannel();
  35. // #endif
  36. that.eventChannel.on('urlNext', function(data) {
  37. that.url = data.url;
  38. })
  39. },
  40. methods: {
  41. oncancel(e) {
  42. uni.navigateBack();
  43. console.log(e, 'on');
  44. },
  45. // 3.定义自己的回调函数
  46. uploadSuccess(tempFilePath) {
  47. console.log(tempFilePath,'tempFilePath')
  48. this.eventChannel.emit('uploadSuccess', tempFilePath.path);
  49. // 后退回原来的页面
  50. uni.navigateBack();
  51. },
  52. }
  53. }
  54. </script>
  55. <style>
  56. </style>