<template>
	<!-- 公共webview组件 -->
  <web-view :src="url" @error="onBinderror" @message="messaged"></web-view>
</template>

<script setup>
import { ref } from "vue";
import { onLoad } from "@dcloudio/uni-app";

const url = ref("");
onLoad((query) => {
  url.value = decodeURIComponent(query.url);
});

// 这里是小程序使用H5微信授权接收参数用
function messaged(e) {
  if (e.detail.data.length > 0) {
    uni.setStorageSync("wxCode", e.detail.data[0].date.code);
    console.log("e.detail", e.detail);
  } else {
    uni.showToast({
      title: "授权失败！",
      icon: "none",
    });
  }
}

function onBinderror(e) {
  uni.showModal({
    title: e.detail.fullUrl,
    content: "无法打开当前域名 请复制链接，到浏览器打开",
    cancelText: "返回",
    confirmText: "复制链接",
    success: (res) => {
      if (res.confirm) {
        uni.setClipboardData({
          data: e.detail.fullUrl,
          showToast: false,
          success: () => {
            uni.showToast({
              title: "已复制链接，快去浏览器打开吧",
              icon: "none",
            });
          },
        });
      } else {
        uni.navigateBack();
      }
    },
  });
}
</script>

<style scoped lang="scss"></style>
