index.vue 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <template>
  2. <!-- 公共webview组件 -->
  3. <web-view :src="url" @error="onBinderror" @message="messaged"></web-view>
  4. </template>
  5. <script setup>
  6. import { ref } from "vue";
  7. import { onLoad } from "@dcloudio/uni-app";
  8. const url = ref("");
  9. onLoad((query) => {
  10. url.value = decodeURIComponent(query.url);
  11. });
  12. // 这里是小程序使用H5微信授权接收参数用
  13. function messaged(e) {
  14. if (e.detail.data.length > 0) {
  15. uni.setStorageSync("wxCode", e.detail.data[0].date.code);
  16. console.log("e.detail", e.detail);
  17. } else {
  18. uni.showToast({
  19. title: "授权失败!",
  20. icon: "none",
  21. });
  22. }
  23. }
  24. function onBinderror(e) {
  25. uni.showModal({
  26. title: e.detail.fullUrl,
  27. content: "无法打开当前域名 请复制链接,到浏览器打开",
  28. cancelText: "返回",
  29. confirmText: "复制链接",
  30. success: (res) => {
  31. if (res.confirm) {
  32. uni.setClipboardData({
  33. data: e.detail.fullUrl,
  34. showToast: false,
  35. success: () => {
  36. uni.showToast({
  37. title: "已复制链接,快去浏览器打开吧",
  38. icon: "none",
  39. });
  40. },
  41. });
  42. } else {
  43. uni.navigateBack();
  44. }
  45. },
  46. });
  47. }
  48. </script>
  49. <style scoped lang="scss"></style>