index.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <n-dropdown
  3. trigger="hover"
  4. @select="handleSelect"
  5. :show-arrow="true"
  6. :options="options"
  7. >
  8. <div class="user-info-box">
  9. <person-icon v-if="fallback"></person-icon>
  10. <n-avatar
  11. v-if="!fallback"
  12. round
  13. object-fit="cover"
  14. size="medium"
  15. :src="Person"
  16. @error="errorHandle"
  17. ></n-avatar>
  18. </div>
  19. </n-dropdown>
  20. <!-- 系统设置 model -->
  21. <go-system-set v-model:modelShow="modelShow"></go-system-set>
  22. <!-- 关于软件 model -->
  23. <go-system-info v-model:modelShow="modelShowInfo"></go-system-info>
  24. </template>
  25. <script lang="ts" setup>
  26. import { h, ref } from 'vue'
  27. import { NAvatar, NText } from 'naive-ui'
  28. import { renderIcon, getLocalStorage } from '@/utils'
  29. import { SystemStoreEnum, SystemStoreUserInfoEnum } from '@/store/modules/systemStore/systemStore.d'
  30. import { StorageEnum } from '@/enums/storageEnum'
  31. import { logout, renderLang } from '@/utils'
  32. import { GoSystemSet } from '@/components/GoSystemSet/index'
  33. import { GoSystemInfo } from '@/components/GoSystemInfo/index'
  34. import Person from './person.png'
  35. import { icon } from '@/plugins'
  36. const {
  37. ChatboxEllipsesIcon,
  38. PersonIcon,
  39. LogOutOutlineIcon,
  40. SettingsSharpIcon
  41. } = icon.ionicons5
  42. const t = window['$t']
  43. const modelShowInfo = ref(false)
  44. const modelShow = ref(false)
  45. // 是否失败
  46. const fallback = ref(false)
  47. // 用户图标渲染
  48. const renderUserInfo = () => {
  49. return h(
  50. 'div',
  51. {
  52. style: 'display: flex; align-items: center; padding: 8px 12px;'
  53. },
  54. [
  55. h(NAvatar, {
  56. round: true,
  57. style: 'margin-right: 12px;',
  58. src: Person
  59. }),
  60. h('div', null, [
  61. h('div', null, [
  62. h(NText, { depth: 2 }, {
  63. default: () => {
  64. const info = getLocalStorage(StorageEnum.GO_SYSTEM_STORE)
  65. if (info) {
  66. return info[SystemStoreEnum.USER_INFO][SystemStoreUserInfoEnum.USER_NAME];
  67. }
  68. else {
  69. return 'admin';
  70. }
  71. }
  72. })
  73. ])
  74. ])
  75. ]
  76. )
  77. }
  78. const options = ref([
  79. {
  80. label: '我的信息',
  81. key: 'info',
  82. type: 'render',
  83. render: renderUserInfo
  84. },
  85. {
  86. type: 'divider',
  87. key: 'd1'
  88. },
  89. {
  90. label: renderLang('global.sys_set'),
  91. key: 'sysSet',
  92. icon: renderIcon(SettingsSharpIcon)
  93. },
  94. {
  95. label: renderLang('global.contact'),
  96. key: 'contact',
  97. icon: renderIcon(ChatboxEllipsesIcon)
  98. },
  99. {
  100. type: 'divider',
  101. key: 'd3'
  102. },
  103. {
  104. label: renderLang('global.logout'),
  105. key: 'logout',
  106. icon: renderIcon(LogOutOutlineIcon)
  107. }
  108. ])
  109. // 图片渲染错误
  110. const errorHandle = (e: Event) => {
  111. fallback.value = true
  112. }
  113. // 系统设置
  114. const sysSetHandle = () => {
  115. modelShow.value = true
  116. }
  117. // 系统设置
  118. const sysInfoHandle = () => {
  119. modelShowInfo.value = true
  120. }
  121. const handleSelect = (key: string) => {
  122. switch (key) {
  123. case 'contact':
  124. sysInfoHandle()
  125. break
  126. case 'sysSet':
  127. sysSetHandle()
  128. break
  129. case 'logout':
  130. logout()
  131. break
  132. }
  133. }
  134. </script>
  135. <style lang="scss" scoped>
  136. .user-info-box {
  137. cursor: pointer;
  138. transform: scale(0.7);
  139. }
  140. </style>