<template>
  <div class="account">
    <md-app md-waterfall md-mode="fixed">
      <md-app-toolbar class="md-primary toolbar">
        <div class="md-toolbar-section-start">
          <md-button class="md-icon-button" @click="back()">
            <md-icon>arrow_back</md-icon>
          </md-button>
          <h3 class="md-title" style="flex: 1">{{ lang.title }}</h3>
        </div>
      </md-app-toolbar>

      <md-app-content>
        <v-touch @swiperight="back()" :swipe-options="{ direction: 'horizontal' }">
          <div ref="list_placeholder" style="height: 54px;"></div>
          <md-steppers md-vertical>
            <md-step
              v-for="(item, index) in lang.timeline"
              :key="index"
              :id="index.toString()"
              :md-label="item.label"
              :md-description="item.tag"
            >
              <p v-for="(content, content_index) in item.content" :key="content_index">{{ content }}</p>
            </md-step>
          </md-steppers>
        </v-touch>
      </md-app-content>
    </md-app>
  </div>
</template>

<script>
// @ is an alias to /src
import { mapState, mapActions } from "vuex";
import { lang } from "@/utils/language.js";
import { setHtmlFontSize } from "@/utils/px2rem.js";
import { replaceState } from "@/utils/getStore.js";

export default {
  name: "UpdateLog",
  data() {
    return {
      // 语言
      lang: "",
      // 页面高度
      clientHeight: "",
    };
  },
  computed: {
    ...mapState(["row_pwd", "settings", "user_infos"]),
  },
  methods: {
    ...mapActions(["setSettings", "setUserInfo"]),
    // 修改md-app的最小高度
    changeFixed(clientHeight) {
      //动态修改样式
      // console.log(clientHeight);
      // window.document.getElementsByClassName('md-content')[0].style.minHeight = clientHeight + 'px';
      this.$refs.list_placeholder.parentNode.parentNode.style.maxHeight =
        clientHeight + "px";
      this.$refs.list_placeholder.parentNode.style.minHeight =
        clientHeight - 32 + "px";
      window.document.documentElement.setAttribute(
        "data-theme",
        this.settings.is_dark_mode ? "dark" : "light"
      );
    },

    // 初始化
    init() {
      // 刷新本页vuex
      replaceState.call(this);
      // 判断有无用户密码
      if (Object.keys(this.row_pwd).length != 0) {
        // 有密码，已经输入过了
        let now = new Date().getTime();
        if (now - this.row_pwd.create_time < this.settings.expired_time) {
          // 上次写入时间距离现在在（默认五分钟）之内
          // 初始化本页信息
          this.initLanguage();
        } else {
          // 密码超时
          this.turnToHome("密码超时");
        }
      } else {
        // 没有密码
        this.turnToHome("无密码");
      }
    },

    // 配置语言
    initLanguage() {
      if (this.settings.is_chinese) {
        this.lang = lang().update_log.CHS;
      } else {
        this.lang = lang().update_log.EN;
      }
      console.log("语言配置完成");
    },

    //返回上一页
    back() {
      this.$router.go(-1);
    },

    // 强制返回Home
    turnToHome(msg) {
      console.log(msg);
      this.$router.replace("/");
    },
  },
  created() {
    this.lang = lang().update_log.CHS;
    console.log("临时语言系统加载完成");
    this.init();
  },
  mounted() {
    // 获取浏览器可视区域高度
    this.clientHeight = `${document.documentElement.clientHeight}`;
    //document.body.clientWidth;
    window.onresize = function temp() {
      this.clientHeight = `${document.documentElement.clientHeight}`;
      setHtmlFontSize();
    }.bind(this);
  },
  watch: {
    // 如果 `clientHeight` 发生改变，这个函数就会运行
    clientHeight: function () {
      this.changeFixed(this.clientHeight);
    },
  },
  beforeDestroy() {},
  components: {},
};
</script>

<style scoped lang="scss" type="text/scss">
@import "../../style/main";
.account {
  width: 100%;
  min-height: 100%;
  background: #fff;
  .expand {
    width: 100%;
    margin: 0 !important;
    min-height: 1.2rem !important;
    margin-top: 0.5rem !important;
  }
  .time-content {
    text-align: right !important;
  }
  .loading-box {
    position: absolute;
    right: 50%;
    top: 50%;
    margin-right: -11px;
    margin-top: -11px;
  }
  .toolbar {
    position: fixed !important;
  }
}
</style>
