panel.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <template>
  2. <div class="c-panel">
  3. <div class="c-panel-header">
  4. <div class="avatar-wrap" @click="$showUserInfo" v-if="userInfo">
  5. <img v-if="userInfo.cover_photo" :src="userInfo.cover_photo" alt="">
  6. <div v-else class="user-avatar"
  7. :class="'avatar_bg' + userInfo.user_id % 9"
  8. :data-name="userInfo.nick_name && userInfo.nick_name.slice(0,2).toUpperCase()"></div>
  9. </div>
  10. <ul class="panel-ctrls">
  11. <li class="current">
  12. <i class="mee-icon-chat"></i>
  13. </li>
  14. <!-- <li>
  15. <i class="friend-icon-chat"></i>
  16. </li> -->
  17. </ul>
  18. <div class="panel-setting">
  19. <div :class="['panel-nav-icon',{'active':isShowSetting}]" @click.stop="toggleLoginOut()"></div>
  20. <ul :class="['menu',{'active':isShowSetting}]">
  21. <!-- <li class="item" @click.stop="handleLoginOut">
  22. <i class="icon-mute icon-mute0"></i>关闭声音
  23. </li> -->
  24. <li class="item" @click.stop="handleGlobalMute">
  25. <i :class="['icon-msg','icon-msg'+openGlobalNotice]"></i>{{openGlobalNotice==0?$t('public.closeMsg'):$t('public.openMsg')}}
  26. </li>
  27. <li class="item" @click.stop="handleFeedback">
  28. <i class="icon-feedback"></i>{{$t('public.feedback')}}
  29. </li>
  30. <li class="item" @click.stop="changeLang">
  31. <i class="icon-lang"></i>{{curLang=="en"?$t('public.chinese'):$t('public.english')}}
  32. </li>
  33. <li class="item" @click.stop="handleLoginOut">
  34. <i class="icon-logout"></i>{{$t('public.quit')}}
  35. </li>
  36. </ul>
  37. </div>
  38. </div>
  39. <div class="c-panel-nav">
  40. <div class="panel-searbar">
  41. <div class="input-con">
  42. <i class="el-icon-search"></i>
  43. <input type="text" @input="searchUser($event, sessionList)" :placeholder="$t('public.search')">
  44. </div>
  45. <i class="el-icon-plus" @click="$showInvite(1)"></i>
  46. </div>
  47. <router-link to="/hotGroup">
  48. <div :class="['group-recommand',{'current':curSession=='0'}]">
  49. <i class="group-icon"></i>
  50. <p class="title">{{ $t('chat.hotGroupRecommend') }}<i class="el-icon-arrow-right"></i></p>
  51. </div>
  52. </router-link>
  53. <div class="chat-list pub-scroll-box">
  54. <template v-if="!isSearch">
  55. <session-item
  56. v-for="(item, index) in sessionList"
  57. :key="index"
  58. :item="item">
  59. </session-item>
  60. </template>
  61. <template v-else>
  62. <session-item
  63. v-for="(item, index) in searchList"
  64. :key="index"
  65. :item="item">
  66. </session-item>
  67. </template>
  68. </div>
  69. </div>
  70. </div>
  71. </template>
  72. <script>
  73. import { mapState } from 'vuex'
  74. import sessionItem from './sessionItem'
  75. import { searchUserMixin, addPanelSessionMixin, changeLangMixin } from '@/mixins'
  76. import { noticeManager } from '@/util/util'
  77. import API from '@/api'
  78. export default {
  79. name: 'panel',
  80. mixins: [searchUserMixin, addPanelSessionMixin, changeLangMixin],
  81. data () {
  82. return {
  83. isShowSetting: false,
  84. openGlobalNotice: noticeManager.getGlobalNotice()
  85. }
  86. },
  87. computed: {
  88. ...mapState({
  89. curSession: state => state.curSession,
  90. userId: state => state.userId,
  91. sessionList: state => state.chat.sessionList,
  92. userInfo: state => state.userInfo
  93. })
  94. },
  95. components: {
  96. sessionItem
  97. },
  98. methods: {
  99. toggleLoginOut (flag = true) {
  100. if (flag) this.isShowSetting = !this.isShowSetting
  101. else this.isShowSetting = false
  102. },
  103. handleLoginOut () {
  104. // 初始vuex数据
  105. this.$store.commit('setUserInfo', null)
  106. this.$store.commit('initChatData')
  107. this.$store.commit('initGroupData')
  108. this.$store.dispatch('doScatterLogout')
  109. this.$store.commit('chatAppLogin', false)
  110. this.$store.commit('toApp', false)
  111. this.isShowSetting = false
  112. },
  113. handleFeedback () {
  114. API.base.feedback().then(({ data }) => {
  115. let serverId = data.data.serverId
  116. let sessionId = this.userId > serverId
  117. ? `${serverId}-${this.userId}`
  118. : `${this.userId}-${serverId}`
  119. this.addPanelSession(serverId, sessionId)
  120. this.$store.commit('changeSessionId', sessionId)
  121. this.$router.push({ path: `/pm/${sessionId}` })
  122. this.isShowSetting = false
  123. })
  124. },
  125. handleGlobalMute () {
  126. let flag = this.openGlobalNotice == 0 ? 1 : 0
  127. noticeManager.setGlobalNotice(flag, this)
  128. }
  129. },
  130. async created () {
  131. this.$store.dispatch('getSessionList')
  132. await this.$store.dispatch('getUserInfo')
  133. if (location.hash.match('user')) {
  134. this.$showUserInfo()
  135. }
  136. },
  137. mounted () {
  138. document.addEventListener('click', () => {
  139. this.toggleLoginOut(false)
  140. })
  141. }
  142. }
  143. </script>
  144. <style lang="scss" scoped>
  145. @import './panel.scss';
  146. </style>