<template>
  <div class="home" @click="goHome">
    {{ source?'点击返回新医视':'点击返回首页' }}
    <!-- <div
      v-if="source==3"
      class="appbtn"
      style="
        position: absolute;
        left: 0;
        right: 0;
        top: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        z-index: 9999;
        opacity: 0;
      "
    >
      <wx-open-launch-weapp
        :key="freshkey"
        style="
          width:94px;
          height: 30px;
          position: absolute;
          left: 0;
          right: 0;
          top: 0;
          bottom: 0;
        "
        id="launch-btn-miniApp"
        appid="wx6e3ba63efef32cc4"
        :env-version="envVersion"
        path="pages/media_home/index"
      >
        <div v-is="'script'" type="text/wxtag-template">
          <button class="btn" style="width:100%;height:30px;position:absolute;left:0;right:0;top:0;bottom:0;">打开小程序</button>
        </div>
      </wx-open-launch-weapp>
    </div> -->
    <!-- <img src="../assets/home.png"  @click="goHome" /> -->
    <!-- <img src="../assets/home.png"  v-else  @click="goHome"/> -->
  </div>
</template>

<script setup>
import { onMounted, nextTick } from "vue";
import { useRouter, useRoute } from 'vue-router';
import openTag from "../utils/openTag";
import wx from 'jweixin-1.6.0'
const router = useRouter();
const route = useRoute();
let origin=route.query.source?route.query.source:'';
const source=ref(origin);
const freshkey = ref(0);
const props=defineProps({
  project_id:{
    type:String,
    default:''
  }
})
const envVersion=computed(()=>{
  if(source.value==3){
    return 'release'
  }
})
const goHome = () => {
  if(source.value==3){
    //  try {
    //   wx.miniProgram.navigateBack();
    //  } catch (error) {
    //        wx.miniProgram.switchTab({
    //         url: '/pages/media_home/index'
    //         })
    //  }
    wx.miniProgram.switchTab({
      url: '/pages/media_home/index',
      success(res) {
        consoe.log('跳转成功');
      },
      fail(res) {
        consoe.log('跳转失败');
      }
    });
  }else{
    router.push({
    path: "/caseList",
    query: { project_id: props.project_id },
   });
  }

 
};
onMounted(() => {
  openTag();
  // nextTick(() => {
  //   var btn = document.getElementById("launch-btn-miniApp");
  //   if (btn) {
  //     btn.addEventListener("launch", function (e) {
  //       showToast("success");
  //       freshkey.value++;
  //     });
  //     btn.addEventListener("error", function (e) {
  //       showToast("fail", e.detail);
  //     });
  //   }
  // });
});
</script>

<style lang='scss' scoped>
.home {
  position: fixed;
  right: 0;
  z-index: 10;
  width:26px;
  padding:8px 0;
  line-height: 17px;
  top:50%;
  font-size: 14px;
  color:#fff;
  display: flex;
  text-align: center;
  align-items: center;
  justify-content: center;
  border-radius: 5px;
  background:#0caf98;
  flex-direction: column;
  transform: translateY(-50%);
}
</style>
