<template>
  <div class="dashboard-container">
    <component :is="currentRole" />
    <el-dialog
      title="安全提示"
      :visible.sync="dialogVisible"
      type="warning"
      width="30%"
    >
      <span>密码太过简单，请尽快修改密码！</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <router-link to="/other/password"><el-button type="primary">修改密码</el-button></router-link>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import adminDashboard from './admin'
import editorDashboard from './editor'

export default {
  name: 'Dashboard',
  components: { adminDashboard, editorDashboard },
  data() {
    return {
      currentRole: 'adminDashboard',
      dialogVisible: false
    }
  },
  computed: {
    ...mapGetters([
      'roles'
    ]),
    isSimplePwd() {
      return this.$store.getters.isSimplePwd
    }
  },
  created() {
    if (!this.roles.includes('admin')) {
      this.currentRole = 'editorDashboard'
    }
  },
  mounted() {
    if (this.isSimplePwd) {
      this.dialogVisible = true
    }
  }
}
</script>
<style lang="scss" scoped>
  .dashboard-container{
    min-height: calc(100vh - 84px);
  }
</style>
