<template>
  <view class="page">
    <!-- <image src="../../assets/img/homeImg.jpg" mode="scaleToFill" /> -->
    <video id="myVideo" 
    ref="myVideo"
        src='https://video.metavatar.cc/sv/30f2d513-18c4739c509/30f2d513-18c4739c509.mp4' 
        autoplay
        muted
        loop
        :controls="false">
    </video>  
    
    <view class="bottomBox">
      <view class="orangeBtn" @click="toChooseStyle">拍摄数码写真</view>
      <view class="IMEI" @click="Imei"
        >1.0.10<text @click="reFresh">i</text>
      </view>
      <!-- <view style="margin-top: 20rpx" @click="reFresh">刷新</view> -->
      <!-- <view style="margin-top: 20rpx" @click="runGetAndroidId()">获取</view> -->
    </view>
  </view>
</template>

<script setup>
//#region 导入
import { getCurrentInstance, ref,nextTick } from "vue";
import { isPlainObject, onLoad, onUnload } from "@dcloudio/uni-app";
import { userInfoModules } from "@/store/modules/userInfo";

const myVideo = ref(null);

const userInfoModulesPinia = userInfoModules();
//#endregion ----------------------------------

function toChooseStyle() {
  uni.navigateTo({ url: "/pages/chooseStyle/index" });
}

function fileReaderTest() {
  try {
    plus.io.resolveLocalFileSystemURL(
      "file:///storage/Documents",
      function (entry) {
        /* 获取文件目录 */
        var directoryReader = entry.createReader(); //获取读取对象
        directoryReader.readEntries(
          function (entries) {
            //历遍子目录即可
            for (var i = 0; i < entries.length; i++) {
              console.log("文件信息：" + entries[i].name);
              uni.showToast({
                // title: uni.getStorageSync("androidId"),
                title: "文件信息：" + entries[i].name,
                icon: "success",
              });
            }
          },
          function (err) {
            console.log("访问目录失败");
            uni.showToast({
              title: err,
              icon: "error",
            });
          }
        );
      },
      function (err) {
        console.log("访问指定目录失败:" + err.message);
        uni.showToast({
          title: err,
          icon: "error",
        });
      }
    );
  } catch (error) {
    console.log(error, "error");
  }
}

// // 播放
// const handelPlay = () => {
//   const video = document.querySelector("video.uni-video-video");
//   video.play();
// }

//#region 初始化
onLoad(() => {
  nextTick(()=>{
    const video = document.querySelector("video.uni-video-video");
    video.muted = false
    video.play()
  })
  runGetAndroidId();
  // fileReaderTest();
  userInfoModulesPinia.clearStorage();

  
});
//#endregion ----------------------------------

//#region app交互
const IMEI = ref(null);
function Imei() {
  try {
    runGetAndroidId();
    // window.webview.raiseEvent("getSerial", "test_params");
    // window.webview.raiseEvent("getTestStr", "test_params");
    // const IMEI = window.android.getIMEI();
    // const IMEI = window.android.getSerial();
    // const IMEI = window.android.getTestStr();
    uni.showToast({
      // title: uni.getStorageSync("androidId"),
      title: window.localStorage.getItem("androidIdByWindow"),
      icon: "success",
    });
  } catch (error) {
    uni.showToast({
      title: "Error",
      icon: "error",
    });
  }

  // cordova.exec(
  //   function (imei) {
  //     console.log("IMEI:", imei);
  //   },
  //   function (error) {
  //     console.error("Failed to get IMEI:", error);
  //   },
  //   "MyPlugin",
  //   "getIMEI",
  //   []
  // );
}
function runGetAndroidId() {
  window.webview.raiseEvent("getAndroidId", "test_params");
  // alert("获取成功");
}
// function androidCallback(name, result_str) {
//   IMEI.value = result_str;
//   alert(result_str);
//   alert("callBack " + name + " : " + result_str + "\n");
//   // document.getElementById("text").value +=
// }

function reFresh() {
  console.log("刷新");
  window.webview.raiseEvent("pageRefresh", "test_params"); //刷新页面
  // alert("刷新成功");
}
//#endregion ----------------------------------

//#region 登录

//#endregion ----------------------------------
</script>

<style lang="scss" scoped>
.page {
  padding: 0;
  position: relative;
  width: 100vw;
  height: 100vh;
  // uni-video{
  //   width:100%;
  //   height:100%;
  // }
  #myVideo{
    width: 100%;
    height: 100%;
  }
  image {
    position: absolute;
    width: 100%;
    height: 100%;
  }
  .bottomBox {
    position: absolute;
    bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 100rpx 0;
    width: 100%;
    height: 300rpx;
    background-color: rgba($color: #000000, $alpha: 0.5);
    .IMEI {
      position: absolute;
      bottom: 20rpx;
      right: 30rpx;
      width: 40rpx;
      height: 40rpx;
      line-height: 40rpx;
      text-align: center;
    }
  }
}
</style>
