index.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <script setup lang="ts">
  2. import { initRouter } from "@/router/utils";
  3. import { storageLocal } from "@pureadmin/utils";
  4. import { type CSSProperties, ref, computed } from "vue";
  5. import { useUserStoreHook } from "@/store/modules/user";
  6. import { usePermissionStoreHook } from "@/store/modules/permission";
  7. defineOptions({
  8. name: "PermissionPage"
  9. });
  10. const elStyle = computed((): CSSProperties => {
  11. return {
  12. width: "85vw",
  13. justifyContent: "start"
  14. };
  15. });
  16. const username = ref(useUserStoreHook()?.username);
  17. const options = [
  18. {
  19. value: "admin",
  20. label: "管理员角色"
  21. },
  22. {
  23. value: "common",
  24. label: "普通角色"
  25. }
  26. ];
  27. function onChange() {
  28. useUserStoreHook()
  29. .loginByUsername({ username: username.value, password: "admin123" })
  30. .then(res => {
  31. if (res.success) {
  32. storageLocal().removeItem("async-routes");
  33. usePermissionStoreHook().clearAllCachePage();
  34. initRouter();
  35. }
  36. });
  37. }
  38. </script>
  39. <template>
  40. <el-space direction="vertical" size="large">
  41. <el-tag :style="elStyle" size="large" effect="dark">
  42. 模拟后台根据不同角色返回对应路由,观察左侧菜单变化(管理员角色可查看系统管理菜单、普通角色不可查看系统管理菜单)
  43. </el-tag>
  44. <el-card shadow="never" :style="elStyle">
  45. <template #header>
  46. <div class="card-header">
  47. <span>当前角色:{{ username }}</span>
  48. </div>
  49. </template>
  50. <el-select v-model="username" @change="onChange">
  51. <el-option
  52. v-for="item in options"
  53. :key="item.value"
  54. :label="item.label"
  55. :value="item.value"
  56. />
  57. </el-select>
  58. </el-card>
  59. </el-space>
  60. </template>