export function replaceState() {
  let state = {}
  for (let key of Object.keys(this.$store.state)) {
    let content = JSON.parse(localStorage.getItem("canary_" + key))
    if (content == null) content = ''
    state[key] = content
  }
  this.$store.replaceState(
    Object.assign(
      this.$store.state,
      state
    )
  );
  // 初始化
  initUserInfo.call(this);
  initSettings.call(this);
}

// 初始化用户信息
function initUserInfo() {
  if (Object.keys(this.user_infos).length == 0) {
    // 初始化用户信息
    let user_infos = {
      user_name: "A Little Canary",
      cid: "Codebook",
      row_login_pwd: "",
      drivce: "",
      cloud_drivce: this.settings.is_chinese ? "暂无" : "unknown",
      update_time: new Date().getTime(),
    };
    this.setUserInfo([user_infos, this]);
    console.log("用户信息覆写完成");
  }
  console.log("用户信息初始化完成");
}

// 初始化配置信息
function initSettings() {
  if (Object.keys(this.settings).length == 0) {
    // 初始化配置信息
    let settings = {
      is_chinese: true,
      is_dark_mode: false,
      expired_time: 300000, // 5分钟
    };
    this.setSettings([settings, this]);
    console.log("配置信息覆写完成");
  }
  console.log("配置信息初始化完成");
}