panel.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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="avatarUrl" 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="handleGlobalMute">
  22. <i :class="['icon-msg','icon-msg'+openGlobalNotice]"></i>{{openGlobalNotice==0?$t('public.closeMsg'):$t('public.openMsg')}}
  23. </li>
  24. <li class="item" @click.stop="handleFeedback">
  25. <i class="icon-feedback"></i>{{$t('public.feedback')}}
  26. </li>
  27. <li class="item" @click.stop="changeLang">
  28. <i class="icon-lang"></i>{{curLang=="en"?$t('public.chinese'):$t('public.english')}}
  29. </li>
  30. <!-- <li class="item" @click.stop="$pswSetting">
  31. <i class="icon-psw"></i>{{$t('public.pswSetting')}}
  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" v-model="searchTxt" @input="searchUser($event, sessionList)" :placeholder="$t('public.searchHotGroup')">
  44. </div>
  45. <i class="el-icon-plus" @click="$showInvite(1)"></i>
  46. </div>
  47. <div class="panel-pwa" id="btnPwa" style="display:none">
  48. <span>{{$t('public.installPwa')}}</span>
  49. <i class="el-icon-close" @click.stop="closePwaGuide()"></i>
  50. </div>
  51. <div v-show="!isSearch" :class="['group-recommand',{'current':curSession=='0'}]" @click="$router.push('/hotGroup')">
  52. <i class="group-icon"></i>
  53. <p class="title">{{ $t('chat.hotGroupRecommend') }}<i class="el-icon-arrow-right"></i></p>
  54. </div>
  55. <div class="chat-list pub-scroll-box">
  56. <template v-if="!isSearch">
  57. <session-item
  58. v-for="item in sessionList"
  59. :key="item.group_id"
  60. :item="item">
  61. </session-item>
  62. </template>
  63. <template v-else>
  64. <session-item
  65. v-for="item in searchList"
  66. :key="item.group_id"
  67. :item="item">
  68. </session-item>
  69. <hot-group :searchTxt="searchTxt"></hot-group>
  70. </template>
  71. </div>
  72. </div>
  73. </div>
  74. </template>
  75. <script>
  76. import { mapState } from 'vuex'
  77. import sessionItem from './sessionItem'
  78. import hotGroup from '@/components/hotGroup/hotGroup'
  79. import { searchUserMixin, addPanelSessionMixin, changeLangMixin } from '@/mixins'
  80. import { noticeManager } from '@/util/util'
  81. import API from '@/api'
  82. export default {
  83. name: 'panel',
  84. mixins: [searchUserMixin, addPanelSessionMixin, changeLangMixin],
  85. data () {
  86. return {
  87. searchTxt: '', // 搜索关键字
  88. isShowSetting: false,
  89. openGlobalNotice: noticeManager.getGlobalNotice()
  90. }
  91. },
  92. computed: {
  93. avatarUrl () {
  94. if (/^http/.test(this.userInfo.cover_photo)) return `${this.userInfo.cover_photo}?imageview/0/w/180`
  95. else return this.userInfo.cover_photo
  96. },
  97. ...mapState({
  98. curSession: state => state.curSession,
  99. userId: state => state.userId,
  100. sessionList: state => state.chat.sessionList,
  101. userInfo: state => state.userInfo
  102. })
  103. },
  104. components: {
  105. hotGroup,
  106. sessionItem
  107. },
  108. methods: {
  109. closePwaGuide () {
  110. let btnPwa = document.getElementById('btnPwa')
  111. btnPwa.style.display = 'none'
  112. },
  113. toggleLoginOut (flag = true) {
  114. if (flag) this.isShowSetting = !this.isShowSetting
  115. else this.isShowSetting = false
  116. },
  117. handleLoginOut () {
  118. this.isShowSetting = false
  119. // 初始vuex数据
  120. this.$store.commit('setUserInfo', null)
  121. this.$store.commit('initChatData')
  122. this.$store.commit('initGroupData')
  123. this.$store.commit('chatAppLogin', false)
  124. this.$store.commit('toApp', false)
  125. this.$store.dispatch('doScatterLogout')
  126. },
  127. handleFeedback () {
  128. API.base.feedback().then(({ data }) => {
  129. let serverId = data.data.serverId
  130. let sessionId = this.userId > serverId
  131. ? `${serverId}-${this.userId}`
  132. : `${this.userId}-${serverId}`
  133. this.addPanelSession(serverId, sessionId)
  134. this.$store.commit('changeSessionId', sessionId)
  135. this.$router.push({ path: `/pm/${sessionId}` })
  136. this.isShowSetting = false
  137. })
  138. },
  139. handleGlobalMute () {
  140. let flag = this.openGlobalNotice == 0 ? 1 : 0
  141. noticeManager.setGlobalNotice(flag, this)
  142. }
  143. },
  144. async created () {
  145. this.$store.dispatch('getSessionList')
  146. await this.$store.dispatch('getUserInfo')
  147. if (location.hash.match('user')) {
  148. this.$showUserInfo()
  149. }
  150. },
  151. mounted () {
  152. document.addEventListener('click', () => {
  153. this.toggleLoginOut(false)
  154. })
  155. }
  156. }
  157. </script>
  158. <style lang="scss" scoped>
  159. @import './panel.scss';
  160. </style>