<!--
 * @Author: your name
 * @Date: 2020-09-08 10:49:07
 * @LastEditTime: 2021-06-29 11:45:03
 * @LastEditors: your name
 * @Description: In User Settings Edit
 * @FilePath: \ydy_wap_front\src\App.vue
-->
<template>
  <div id="app" :class="theme">
    <router-view :key="$route.fullpath" />
    <div class="package-wrap" @touchmove.prevent v-if="showWrap">
      <img @click.stop="closeWrap" :src="imgs" alt="" />
    </div>
    <div class="blank_page" v-if="showBlank">
      <p class="ting">{{ toastMsg }}</p>
    </div>
    <!--  <div class="package-wrap" @touchmove.prevent v-if="showAd">
      
      <img
        src="https://zhuishuyun.oss-cn-hangzhou.aliyuncs.com/zsy_ios_app/user_privacy/20220221155858.png"
        width="100%"
        class="mask-img"
      />
    </div> -->
  </div>
</template>

<script>
import { setUserMode, setFingerprint } from "./api";
import getFingerPrintFunc from "./util/fingerprint";
import { getKeyByWay, setKeyByWay, getQueryString } from "./util/index";

import Vue from "vue";

export default {
  name: "app",
  data() {
    return {
      theme: localStorage.getItem("theme") || "girl",
      showRed: window.options.fission,
      redImage: require("./assets/red_package.png"),
      imgs: null,
      showAd: false,
      showWrap: false,
      // todayDate: new Date().toLocaleDateString(),
      isTargetChannel: window.options.is_show_ad_frame,
      showIframe: false,
      showBlank: false,
      toastMsg: "系统维护中~~~~~~~~~~"
    };
  },
  watch: {
    $route(v) {
      if (v.name === "BookCity") {
        v.query.sex && (this.theme = v.query.sex);
      }
      if (v.name != "Yun" && v.name !== "Reader") {
        this.testToken();
      }
    }
  },
  async created() {
    let { site_gender } = window.options;
    if (site_gender) {
      // 关注用户 根据用户性别 首页展示不同的频道
      this.theme = site_gender === "male" ? "boy" : "girl";
    } else this.theme = "girl";
    this.initWrap();

    //sessionSotrage判断展示加桌提醒图
    /* const showBanner = sessionStorage.getItem("showBanner");
    const showList = [
      "Reader",
      "BookCatalog", 
      "BookCity",
      "BookDetail",
      "BookRecent",
      "BookShelf",
      "Rank",
      "BookLimitFree",
      "Yun"
    ]; */

    //获取是否加桌过
    //const { is_add_desk } = window.options;
    const token = getKeyByWay("token");
    const hashuser = getQueryString("hashuser") || getKeyByWay("hashuser");
    const send_order_id =
      getKeyByWay("send_order_id") || getQueryString("send_order_id");
    if (token && send_order_id) {
      setUserMode(Number(window.navigator.standalone) || 0).then(res => {});
    }

    setKeyByWay("addDestop", window.navigator.standalone);

    //有token 加过桌 上传最新密钥
    if (
      token &&
      hashuser &&
      hashuser != "hashuser" &&
      window.navigator.standalone
    ) {
      let fingerprint = await getFingerPrintFunc();
      try {
        await setFingerprint({
          hashuser,
          fingerprint
        });
      } catch (e) {
        this.$Toast(e.data.msg);
      }
    }
  },

  methods: {
    closeWrap() {
      if (window.options.fission) {
        this.showWrap = false;
        window.options.fission = 0;
        setTimeout(() => {
          this.initWrap();
        }, 500);
      } else {
        this.showWrap = false;
      }
    },
    testToken() {
      const token = getKeyByWay("token");

      //非加桌模式下，并且没有token 并且不是访问派单落地页和阅读器直接白屏
      if (!window.navigator.standalone && this.$route.name != "Pay") {
        if (!token) {
          /* if (this.$route.name == "Pay") {
            this.showBlank = true;
            this.toastMsg = "支付完成后，请从桌面应用重新打开，畅享阅读~";
          }else{
            this.showBlank = true;
          } */
          this.showBlank = true;
        }
      }
    },
    initWrap() {
      if (window.options.fission) {
        // 红包弹窗弹出
        this.showWrap = true;
        this.imgs = this.redImage;
      }
    }
  }
};
</script>

<style lang="scss" scoped>
.blank_page {
  position: fixed;
  background-color: #fff;
  width: 100vw;
  height: 100vh;
  top: 0;
  left: 0;
  z-index: 9999;
  .ting {
    position: absolute;
    width: 300px;
    height: 300px;
    line-height: 300px;
    text-align: center;
    margin: auto;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
  }
}
.package-wrap {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  background: rgba($color: #000000, $alpha: 0.6);
  z-index: 9999;
  .mask-img {
    width: 100%;
    z-index: 100;
  }
  .close-btn {
    width: 1.2rem;
    height: 0.5rem;
    line-height: 0.5rem;
    text-align: center;
    background: rgba(255, 255, 255, 0.6);
    color: #fff;
    font-size: 0.28rem;
    position: absolute;
    right: 0.5rem;
    top: 0.5rem;
    z-index: 101;
    border-radius: 0.4rem;
  }
  img {
    position: absolute;
    width: 80%;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
  }
}
</style>
