You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.5 KiB

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