UserMenu.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <template>
  2. <div class="user-wrapper">
  3. <div class="content-box">
  4. <a href="https://www.stylefeng.cn" target="_blank">
  5. <span class="action">
  6. <a-icon type="question-circle-o"></a-icon>
  7. </span>
  8. </a>
  9. <notice-icon class="action"/>
  10. <a-dropdown>
  11. <span class="action ant-dropdown-link user-dropdown-menu">
  12. <a-avatar class="avatar" size="small" :src="avatar"/>
  13. <span>{{ nickname }}</span>
  14. </span>
  15. <a-menu slot="overlay" class="user-dropdown-menu-wrapper">
  16. <a-menu-item key="4" v-if="mode === 'sidemenu'">
  17. <a @click="appToggled()" >
  18. <a-icon type="swap"/>
  19. <span>切换应用</span>
  20. </a>
  21. </a-menu-item>
  22. <a-menu-item key="0">
  23. <router-link :to="{ name: 'center' }">
  24. <a-icon type="user"/>
  25. <span>个人中心</span>
  26. </router-link>
  27. </a-menu-item>
  28. <a-menu-item key="1">
  29. <router-link :to="{ name: 'settings' }">
  30. <a-icon type="setting"/>
  31. <span>账户设置</span>
  32. </router-link>
  33. </a-menu-item>
  34. <a-menu-divider/>
  35. <a-menu-item key="3">
  36. <a href="javascript:;" @click="handleLogout">
  37. <a-icon type="logout"/>
  38. <span>退出登录</span>
  39. </a>
  40. </a-menu-item>
  41. </a-menu>
  42. </a-dropdown>
  43. </div>
  44. <a-modal
  45. title="切换应用"
  46. :visible="visible"
  47. :footer="null"
  48. :confirm-loading="confirmLoading"
  49. @cancel="handleCancel"
  50. >
  51. <a-form :form="form1" >
  52. <a-form-item
  53. :labelCol="labelCol"
  54. :wrapperCol="wrapperCol"
  55. label="选择应用"
  56. >
  57. <a-menu
  58. mode="inline"
  59. :default-selected-keys="this.defApp"
  60. style="border-bottom:0px;lineHeight:62px;"
  61. >
  62. <a-menu-item v-for="(item) in userInfo.apps" :key="item.code" style="top:0px;" @click="switchApp(item.code)">
  63. {{ item.name }}
  64. </a-menu-item>
  65. </a-menu>
  66. </a-form-item>
  67. </a-form>
  68. </a-modal>
  69. </div>
  70. </template>
  71. <script>
  72. import NoticeIcon from '@/components/NoticeIcon'
  73. import { mapActions, mapGetters } from 'vuex'
  74. import { ALL_APPS_MENU } from '@/store/mutation-types'
  75. import Vue from 'vue'
  76. import { message } from 'ant-design-vue/es'
  77. export default {
  78. name: 'UserMenu',
  79. components: {
  80. NoticeIcon
  81. },
  82. props: {
  83. mode: {
  84. type: String,
  85. // sidemenu, topmenu
  86. default: 'sidemenu'
  87. }
  88. },
  89. data () {
  90. return {
  91. labelCol: {
  92. xs: { span: 24 },
  93. sm: { span: 5 }
  94. },
  95. wrapperCol: {
  96. xs: { span: 24 },
  97. sm: { span: 16 }
  98. },
  99. visible: false,
  100. confirmLoading: false,
  101. form1: this.$form.createForm(this),
  102. defApp: []
  103. }
  104. },
  105. computed: {
  106. ...mapGetters(['nickname', 'avatar', 'userInfo'])
  107. },
  108. methods: {
  109. ...mapActions(['Logout', 'MenuChange']),
  110. handleLogout () {
  111. this.$confirm({
  112. title: '提示',
  113. content: '真的要注销登录吗 ?',
  114. onOk: () => {
  115. return this.Logout({}).then(() => {
  116. setTimeout(() => {
  117. window.location.reload()
  118. }, 16)
  119. }).catch(err => {
  120. this.$message.error({
  121. title: '错误',
  122. description: err.message
  123. })
  124. })
  125. },
  126. onCancel () {
  127. }
  128. })
  129. },
  130. /**
  131. * 打开切换应用框
  132. */
  133. appToggled () {
  134. this.visible = true
  135. this.defApp.push(Vue.ls.get(ALL_APPS_MENU)[0].code)
  136. },
  137. switchApp (appCode) {
  138. this.visible = false
  139. this.defApp = []
  140. const applicationData = this.userInfo.apps.filter(item => item.code === appCode)
  141. const hideMessage = message.loading('正在切换应用!', 0)
  142. this.MenuChange(applicationData[0]).then((res) => {
  143. hideMessage()
  144. // eslint-disable-next-line handle-callback-err
  145. }).catch((err) => {
  146. message.error('应用切换异常')
  147. })
  148. },
  149. handleCancel () {
  150. this.form1.resetFields()
  151. this.visible = false
  152. }
  153. }
  154. }
  155. </script>
  156. <style lang="less" scoped>
  157. .appRedio {
  158. border:1px solid #91d5ff;
  159. padding:10px 20px;
  160. background: #e6f7ff;
  161. border-radius:2px;
  162. margin-bottom:10px;
  163. color: #91d5ff;
  164. /*display: inline;
  165. margin-bottom:10px;*/
  166. }
  167. </style>