<template>
  <div id="app">
    <router-view> </router-view>
  </div>
</template>

<script>
import request from './service/request.js';
export default {
  name: 'App',
  data() {
    return {};
  },
  methods: {
    // 保存用户id，串号标志
    getUserId() {
      request.get('/api-auth/get-login-user-info').then(res => {
        if (res.data.errorCode === 0) {
          const useId = res.data.result.userId;
          localStorage.setItem('useId', useId);
        } else {
          this.$message.error(res.data.message);
        }
      });
    },
    // 浏览器tab切换检查uid是否变化
    changeTab() {
      document.addEventListener('visibilitychange', () => {
        if (document.visibilityState === 'visible') {
          request.get('/api-auth/get-login-user-info').then(res => {
            if (res.data.errorCode === 0) {
              const useId = res.data.result && res.data.result.userId;
              if (localStorage.getItem('useId') !== useId) {
                // 串号
                this.$confirm('出现窜号情况，请首先核对好是哪个商户再进行操作！', '提示', {
                  type: 'error',
                  closeOnClickModal: false,
                  showClose: false
                })
                  .then(() => {
                    localStorage.setItem('useId', useId);
                    window.location.reload();
                  })
                  .catch(() => {
                    window.location.reload();
                  });
              } else {
                localStorage.setItem('useId', useId);
              }
            } else {
              this.$message.error(res.data.message);
            }
          });
        }
      });
    }
  },
  created() {
    this.getUserId();
    this.changeTab();
  }
};
</script>

<style>
#app {
  background-color: #f0f2f5;
}
/*面包屑前面两个加粗*/
.mall-crumbs .el-breadcrumb__inner {
  height: 14px;
  font-size: 14px;
  font-family: PingFangSC-Medium;
  font-weight: bold;
  color: #303133;
}
</style>
