index.vue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <template>
  2. <div class="app-container">
  3. <!-- 有权限时显示统计仪表板 -->
  4. <statistics-dashboard v-if="hasDashboardPermission && !loading" />
  5. <!-- 无权限时显示欢迎页面 -->
  6. <welcome-page v-else-if="!hasDashboardPermission && !loading" />
  7. <!-- 加载状态 -->
  8. <div v-else class="loading-container">
  9. <el-skeleton animated>
  10. <template #template>
  11. <el-skeleton-item variant="image" style="width: 100%; height: 400px;" />
  12. </template>
  13. </el-skeleton>
  14. </div>
  15. </div>
  16. </template>
  17. <script>
  18. // 异步加载组件
  19. const StatisticsDashboard = () => import('./components/index/statisticsDashboard')
  20. const WelcomePage = () => import('./components/index/welcomePage')
  21. export default {
  22. name: 'Index',
  23. components: {
  24. StatisticsDashboard,
  25. WelcomePage
  26. },
  27. data() {
  28. return {
  29. hasDashboardPermission: false,
  30. loading: true
  31. }
  32. },
  33. created() {
  34. this.checkDashboardPermission()
  35. },
  36. methods: {
  37. checkDashboardPermission() {
  38. // 方式2: 检查用户权限
  39. if (this.hasPermi(['his:index'])) {
  40. this.hasDashboardPermission = true
  41. }
  42. // 方式3: 检查用户角色
  43. else if (this.hasRole(['admin'])) {
  44. this.hasDashboardPermission = true
  45. }
  46. this.loading = false
  47. },
  48. // 使用若依的权限检查方法
  49. hasPermi(permissions) {
  50. return this.$store.state.user.permissions.some(permission => {
  51. return permissions.includes(permission)
  52. })
  53. },
  54. // 使用若依的角色检查方法
  55. hasRole(roles) {
  56. return this.$store.state.user.roles.some(role => {
  57. return roles.includes(role)
  58. })
  59. }
  60. }
  61. }
  62. </script>
  63. <style scoped>
  64. .app-container {
  65. min-height: calc(100vh - 84px);
  66. }
  67. .loading-container {
  68. padding: 20px;
  69. }
  70. </style>