userbar.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <template>
  2. <div class="user-bar">
  3. <!-- 搜索面板 -->
  4. <panel-search v-if="!isMobile" />
  5. <div v-if="!isMobile" class="screen panel-item hidden-sm-and-down" @click="fullscreen">
  6. <fullscreen-outlined />
  7. </div>
  8. <!-- <dev-user-message />-->
  9. <a-dropdown class="user panel-item">
  10. <div class="user-avatar">
  11. <a-avatar :src="userInfo.avatar" />
  12. <label>{{ userName }}</label>
  13. </div>
  14. <template #overlay>
  15. <a-menu>
  16. <a-menu-item key="uc" @click="handleUser('uc')">
  17. <UserOutlined style="margin-right: 8px" />
  18. <span>个人中心</span>
  19. </a-menu-item>
  20. <a-menu-item key="clearCache" @click="handleUser('clearCache')">
  21. <loading3-quarters-outlined style="margin-right: 8px" />
  22. <span>清理缓存</span>
  23. </a-menu-item>
  24. <a-menu-divider />
  25. <a-menu-item key="outLogin" @click="handleUser('outLogin')">
  26. <export-outlined style="margin-right: 8px" />
  27. <span>退出登录</span>
  28. </a-menu-item>
  29. </a-menu>
  30. </template>
  31. </a-dropdown>
  32. <a-dropdown v-if="!isMobile" class="panel-item">
  33. <global-outlined />
  34. <template #overlay>
  35. <a-menu :selected-keys="lang">
  36. <a-menu-item key="zh-cn" @click="handleIn18('zh-cn')">
  37. <span>简体中文</span>
  38. </a-menu-item>
  39. <a-menu-item key="en" @click="handleIn18('en')">
  40. <span>English</span>
  41. </a-menu-item>
  42. </a-menu>
  43. </template>
  44. </a-dropdown>
  45. <div v-if="setDrawer === 'true'" class="setting panel-item" @click="openSetting">
  46. <layout-outlined />
  47. </div>
  48. </div>
  49. <!-- 整体风格设置抽屉 -->
  50. <a-drawer v-model:visible="settingDialog" :closable="false" width="300">
  51. <setting />
  52. </a-drawer>
  53. </template>
  54. <script setup name="layoutUserBar">
  55. import { createVNode } from 'vue'
  56. import { ExclamationCircleOutlined } from '@ant-design/icons-vue'
  57. import { Modal } from 'ant-design-vue'
  58. import screenFull from 'screenfull'
  59. import { message } from 'ant-design-vue'
  60. import Setting from './setting.vue'
  61. import router from '@/router'
  62. import tool from '@/utils/tool'
  63. import config from '@/config/index'
  64. import loginApi from '@/api/auth/loginApi'
  65. import DevUserMessage from './message.vue'
  66. import PanelSearch from './panel-search/index.vue'
  67. import { globalStore } from '@/store'
  68. import { useI18n } from 'vue-i18n'
  69. const { locale } = useI18n()
  70. const lang = ref(new Array(tool.data.get('APP_LANG') || config.LANG))
  71. const settingDialog = ref(false)
  72. const setDrawer = ref(import.meta.env.VITE_SET_DRAWER)
  73. const store = globalStore()
  74. const isMobile = computed(() => {
  75. return store.isMobile
  76. })
  77. const userInfo = computed(() => {
  78. return store.userInfo
  79. })
  80. const userName = ref(userInfo.value?.userName || '')
  81. // 个人信息
  82. const handleUser = (key) => {
  83. if (key === 'uc') {
  84. router.push({ path: '/usercenter' })
  85. }
  86. if (key === 'clearCache') {
  87. Modal.confirm({
  88. title: '提示',
  89. content: '确认清理所有缓存?',
  90. icon: createVNode(ExclamationCircleOutlined),
  91. maskClosable: false,
  92. okText: '确定',
  93. cancelText: '取消',
  94. onOk() {
  95. message.loading('正在清理中...', 1)
  96. tool.data.clear()
  97. setTimeout(() => {
  98. router.replace({ path: '/login' })
  99. location.reload()
  100. }, 100)
  101. },
  102. onCancel() {}
  103. })
  104. }
  105. if (key === 'outLogin') {
  106. Modal.confirm({
  107. title: '提示',
  108. content: '确认退出当前用户?',
  109. icon: createVNode(ExclamationCircleOutlined),
  110. maskClosable: false,
  111. onOk() {
  112. // 取得缓存中的token
  113. const token = tool.data.get('TOKEN')
  114. const param = {
  115. token: token
  116. }
  117. message.loading('退出中...', 1)
  118. loginApi
  119. .logout(param)
  120. .then(() => {
  121. // 清理掉个人的一些信息
  122. tool.data.remove('TOKEN')
  123. tool.data.remove('USER_INFO')
  124. tool.data.remove('MENU')
  125. tool.data.remove('PERMISSIONS')
  126. tool.cookie.remove('Token')
  127. router.replace({ path: '/login' })
  128. })
  129. .catch(() => {
  130. tool.data.clear()
  131. router.replace({ path: '/login' })
  132. location.reload()
  133. })
  134. },
  135. onCancel() {}
  136. })
  137. }
  138. }
  139. // 设置多语言语种
  140. const handleIn18 = (key) => {
  141. lang.value = []
  142. lang.value.push(key)
  143. locale.value = key
  144. tool.data.set('APP_LANG', key)
  145. }
  146. // 设置抽屉
  147. const openSetting = () => {
  148. settingDialog.value = true
  149. }
  150. // 全屏
  151. const fullscreen = () => {
  152. const element = document.documentElement
  153. if (screenFull.isEnabled) {
  154. screenFull.toggle(element)
  155. }
  156. }
  157. </script>
  158. <style lang="less" scoped>
  159. :deep(.ant-modal) {
  160. top: 20px;
  161. }
  162. :deep(.ant-modal-content) {
  163. border-radius: 10px;
  164. }
  165. .user-bar {
  166. display: flex;
  167. align-items: center;
  168. height: 100%;
  169. }
  170. .user-bar .user-avatar {
  171. height: 49px;
  172. display: flex;
  173. align-items: center;
  174. }
  175. .user-bar .user-avatar label {
  176. display: inline-block;
  177. margin-left: 5px;
  178. cursor: pointer;
  179. }
  180. .setting {
  181. margin-right: 10px;
  182. }
  183. </style>