cropper.vue 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <template>
  2. <view class="container">
  3. <web-view
  4. :webview-styles="webviewStyles"
  5. @message="handleMessage"
  6. :src="webviewSrc"
  7. >
  8. </web-view>
  9. </view>
  10. </template>
  11. <script>
  12. export default {
  13. name: "buuug7-img-cropper",
  14. data() {
  15. return {
  16. webviewStyles: {},
  17. platform: "",
  18. webviewSrc:
  19. "/uni_modules/buuug7-img-cropper/hybrid/html/cropper/index.html",
  20. };
  21. },
  22. mounted() {
  23. const { platform } = uni.getSystemInfoSync();
  24. this.platform = platform;
  25. console.log(platform);
  26. if (platform === "windows" || platform === "mac") {
  27. this.handleH5Message();
  28. }
  29. },
  30. methods: {
  31. handleMessage(event) {
  32. const platform = this.platform;
  33. const data = event.detail.data[0];
  34. if (platform === "android" || platform === "ios") {
  35. const eventChannel = this.getOpenerEventChannel();
  36. eventChannel.emit("imgCropped", { data: data.dataUrl });
  37. }
  38. },
  39. handleH5Message(e) {
  40. console.log(`H5Message`);
  41. window.addEventListener("message", (event) => {
  42. const data = event.data.data;
  43. if (data && data.type === "croppedData") {
  44. const eventChannel = this.getOpenerEventChannel();
  45. eventChannel.emit("imgCropped", { data: data.dataUrl });
  46. }
  47. });
  48. },
  49. },
  50. };
  51. </script>
  52. <style></style>