index.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 } from '@/utils'
  29. import { logout, renderLang } from '@/utils'
  30. import { GoSystemSet } from '@/components/GoSystemSet/index'
  31. import { GoSystemInfo } from '@/components/GoSystemInfo/index'
  32. import Person from './person.png'
  33. import { icon } from '@/plugins'
  34. const {
  35. ChatboxEllipsesIcon,
  36. PersonIcon,
  37. LogOutOutlineIcon,
  38. SettingsSharpIcon
  39. } = icon.ionicons5
  40. const t = window['$t']
  41. const modelShowInfo = ref(false)
  42. const modelShow = ref(false)
  43. // 是否失败
  44. const fallback = ref(false)
  45. // 用户图标渲染
  46. const renderUserInfo = () => {
  47. return h(
  48. 'div',
  49. {
  50. style: 'display: flex; align-items: center; padding: 8px 12px;'
  51. },
  52. [
  53. h(NAvatar, {
  54. round: true,
  55. style: 'margin-right: 12px;',
  56. src: Person
  57. }),
  58. h('div', null, [
  59. h('div', null, [
  60. h(NText, { depth: 2 }, { default: () => '奔跑的面条' })
  61. ])
  62. ])
  63. ]
  64. )
  65. }
  66. const options = ref([
  67. {
  68. label: '我的信息',
  69. key: 'info',
  70. type: 'render',
  71. render: renderUserInfo
  72. },
  73. {
  74. type: 'divider',
  75. key: 'd1'
  76. },
  77. {
  78. label: renderLang('global.sys_set'),
  79. key: 'sysSet',
  80. icon: renderIcon(SettingsSharpIcon)
  81. },
  82. {
  83. label: renderLang('global.contact'),
  84. key: 'contact',
  85. icon: renderIcon(ChatboxEllipsesIcon)
  86. },
  87. {
  88. type: 'divider',
  89. key: 'd3'
  90. },
  91. {
  92. label: renderLang('global.logout'),
  93. key: 'logout',
  94. icon: renderIcon(LogOutOutlineIcon)
  95. }
  96. ])
  97. // 图片渲染错误
  98. const errorHandle = (e: Event) => {
  99. fallback.value = true
  100. }
  101. // 系统设置
  102. const sysSetHandle = () => {
  103. modelShow.value = true
  104. }
  105. // 系统设置
  106. const sysInfoHandle = () => {
  107. modelShowInfo.value = true
  108. }
  109. const handleSelect = (key: string) => {
  110. switch (key) {
  111. case 'contact':
  112. sysInfoHandle()
  113. break
  114. case 'sysSet':
  115. sysSetHandle()
  116. break
  117. case 'logout':
  118. logout()
  119. break
  120. }
  121. }
  122. </script>
  123. <style lang="scss" scoped>
  124. .user-info-box {
  125. cursor: pointer;
  126. transform: scale(0.7);
  127. }
  128. </style>