TheUserAvatar.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <script lang="jsx">
  2. import { defineComponent } from 'vue';
  3. import { useRouter } from 'vue-router';
  4. import { NPopover } from 'naive-ui';
  5. import { userApi } from '@/api/user';
  6. import { useUserStore } from '@/stores/modules/userStore'
  7. const RenderUserAvatar = ({ store }) => {
  8. const router = useRouter();
  9. const user = store.userInfo;
  10. const clearLoginStatus = async () => {
  11. localStorage.removeItem("isLogin");
  12. router.push("/login");
  13. }
  14. const userMenuOptions = [
  15. {
  16. label: '个人中心',
  17. key: "/user"
  18. },
  19. // {
  20. // label: '修改密码',
  21. // key: "edit"
  22. // },
  23. {
  24. label: '退出登录',
  25. key: "logout"
  26. },
  27. ]
  28. const handleUserMenuOptions = async ({ key }) => {
  29. switch (key) {
  30. case '/user':
  31. router.push(key)
  32. return
  33. case 'edit':
  34. const userStore = useUserStore();
  35. userStore.setDialogStatus(true)
  36. return
  37. case 'logout':
  38. clearLoginStatus();
  39. }
  40. }
  41. const slots = {
  42. default: () => (
  43. <ul class="
  44. w-[120px] px-[10px] py-[10px]
  45. rounded-[4px] bg-white
  46. text-[12px] text-[#272D35] leading-[30px] text-center
  47. ">
  48. {
  49. userMenuOptions.map(item => (
  50. <li
  51. class="h-[30px] rounded-[4px] hover:bg-[#F4F6F8] hover:text-[#2454FF] cursor-pointer"
  52. key={item.key}
  53. onClick={() => handleUserMenuOptions(item)}
  54. >
  55. {item.label}
  56. </li>
  57. ))
  58. }
  59. </ul>
  60. ),
  61. trigger: () => (
  62. <div class="flex items-center cursor-pointer">
  63. <img src="https://static.fuxicarbon.com/bigModel/pc/xlht-icon.svg" alt="" class="w-[32px] h-[32px] mr-[10px] rounded-[50%] shrink-0" />
  64. <span class="text-[#272D35] text-[12px]">锡林浩特</span>
  65. </div>
  66. )
  67. };
  68. return (
  69. <NPopover
  70. v-slots={slots}
  71. trigger="hover"
  72. raw={true}
  73. show-arrow={false}
  74. style="box-shadow: 0px 10px 31px 0px #B1B6B933"
  75. ></NPopover>
  76. )
  77. }
  78. export default defineComponent({
  79. setup () {
  80. const userStore = useUserStore();
  81. return () => (
  82. <div >{<RenderUserAvatar store={userStore} />}</div>
  83. );
  84. },
  85. });
  86. </script>