userbar.vue 5.5 KB

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