longyvfengyun
2024-09-02 2b7d8aa9b25adb6de0e58e6a26a48a46bce3be83
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<template>
  <div class="dashboard-container">
    <component :is="currentRole" />
  </div>
</template>
 
<script>
import { defineComponent } from 'vue';
import { mapState } from 'pinia';
import adminDashboard from './admin';
import editorDashboard from './editor';
import store from '@/store';
 
export default defineComponent({
  name: 'Dashboard',
  components: { adminDashboard, editorDashboard },
  data() {
    return {
      currentRole: 'adminDashboard'
    };
  },
  computed: {
    ...mapState(store.user, ['roles'])
  },
  created() {
    console.log('dashboard created');
    if (!this.roles.includes('admin')) {
      this.currentRole = 'editorDashboard';
    }
  }
});
</script>