roomMsg.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <template>
  2. <div class="box-bd" ref="msgBox">
  3. <div ref="scrollWrap"
  4. @scroll.prevent="handleScroll"
  5. class="scroller"
  6. >
  7. <div ref="msgWrap" class="msg-wrap">
  8. <div class="msg-top-more" v-if="lockEnd">
  9. <em>{{ $t('chat.noMore') }}</em>
  10. </div>
  11. <div class="msg-top-load" v-if="lockMore && !lockEnd">
  12. <i class="msg-loading-icon"></i>
  13. </div>
  14. <msg-item v-for="(item, key) in group.chatList"
  15. :key="key"
  16. :isMobile="true"
  17. :isAdmin="isAdmin"
  18. v-bind="item"
  19. :msgItem="item"
  20. @quoteMsg="quoteMsg"
  21. @deleteMsg="deleteMsg"
  22. ></msg-item>
  23. </div>
  24. </div>
  25. <at-me :atList="atList" class="mini" @scrollToMsg="scrollToMsg"></at-me>
  26. <div class="msg-unread"
  27. @click="doSetRead"
  28. v-show="unreadNums > 0 && enableScroll && !isBottom">
  29. <em><i class="el-icon-d-arrow-right"></i>{{unreadNums}}{{ $t('chat.unreadMsg') }}</em>
  30. </div>
  31. </div>
  32. </template>
  33. <script>
  34. import msgItem from '@/components/msgItem'
  35. import { chatAtMixin, chatInputMixin, changeLangMixin } from '@/mixins'
  36. import { accountLoginMixin } from '@/mixins/login'
  37. import { chatMixin, inputMixin } from '@/mixins/chat'
  38. import { isMobile, getMeechatType } from '@/util/util.js'
  39. import { mapState } from 'vuex'
  40. import { Message } from 'element-ui'
  41. import API from '@/api'
  42. export default {
  43. name: 'chatRoomMiniWap',
  44. mixins: [accountLoginMixin, chatAtMixin, chatInputMixin, chatMixin, inputMixin, changeLangMixin],
  45. components: {
  46. },
  47. props: {
  48. showMiniChat: {
  49. type: Boolean
  50. }
  51. },
  52. data () {
  53. return {
  54. emojiShow: false,
  55. toolShow: false,
  56. inputHeight: 18,
  57. meechatType: getMeechatType(),
  58. isMobile: isMobile(),
  59. // mini
  60. showMenuExtra: false, // 显示左上角菜单
  61. showLoginBtn: true, // 显示登录按钮
  62. personUnRead: 0, // 私聊未读
  63. serverUnRead: 0 // 客服未读
  64. }
  65. },
  66. computed: {
  67. ...mapState([
  68. 'account'
  69. ])
  70. },
  71. watch: {
  72. inputMsg (val, newval) {
  73. let ele = this.$refs.chatInput
  74. this.inputHeight = 'auto'
  75. this.$nextTick(() => {
  76. this.inputHeight = Math.max(18, Math.min(ele.scrollHeight, 75)) + 'px'
  77. })
  78. },
  79. showMiniChat (val) {
  80. if (val) this.resizeToBottom()
  81. }
  82. },
  83. methods: {
  84. handleEmojiClick () {
  85. this.toolShow = false
  86. this.emojiShow = !this.emojiShow
  87. this.checkNeedToBottom()
  88. },
  89. handleMoreClick () {
  90. this.emojiShow = false
  91. this.toolShow = !this.toolShow
  92. this.checkNeedToBottom()
  93. },
  94. checkNeedToBottom () {
  95. if (!this.isBottom) return
  96. this.$nextTick(() => {
  97. this.resizeToBottom()
  98. })
  99. },
  100. /**
  101. * @des 引用某条消息
  102. */
  103. quoteMsg (msg) {
  104. this.inputMsg = msg
  105. },
  106. /**
  107. * --------------for mini-------------------
  108. */
  109. getPmUnRead () {
  110. API.session.getMiniUnRead().then(({ data }) => {
  111. this.personUnRead = data.data['0']
  112. this.serverUnRead = data.data[this.groupId] || 0
  113. })
  114. },
  115. /**
  116. * 清空私聊未读
  117. * @param {type} 1.客服2.私聊
  118. **/
  119. clearPmUnread (type) {
  120. if (type == 1) this.serverUnRead = 0
  121. else this.personUnRead = 0
  122. },
  123. /**
  124. * 登录处理
  125. */
  126. async handleLogin () {
  127. // 设置登录按钮状态
  128. this.showLoginBtn = 'loading'
  129. if (self !== top) {
  130. this.handleParentLogin()
  131. } else {
  132. // 连接scatter
  133. this.scatterConnect()
  134. }
  135. },
  136. async scatterConnect () {
  137. await this.loginEos()
  138. },
  139. /**
  140. * @des 调用父级页面getIdentity
  141. */
  142. async getParentIdentity () {
  143. if (self !== top) {
  144. try {
  145. let response = await this.postMessager.send({ action: 'meechat:getIdentity' })
  146. let account = response.accounts.find(x => x.blockchain === 'eos')
  147. localStorage.setItem('account', JSON.stringify(account))
  148. this.setAccount(account)
  149. } catch (error) {
  150. this.showLoginBtn = true
  151. }
  152. }
  153. },
  154. /**
  155. * @des 调用父级页面登录
  156. */
  157. async handleParentLogin () {
  158. try {
  159. // scatter登录
  160. await this.getParentIdentity()
  161. if (!this.account) return
  162. // 合约登录
  163. await this.doContractLogin()
  164. location.replace(location.href.replace('show=false', 'show=true'))
  165. } catch (msg) {
  166. if (msg.type) {
  167. // scatter报错的情况
  168. } else {
  169. let json = JSON.parse(msg)
  170. let details = json.error.details
  171. Message({
  172. message: details[0].message,
  173. type: 'error'
  174. })
  175. }
  176. this.showLoginBtn = true
  177. }
  178. },
  179. async handleLogout () {
  180. this.doScatterLogout()
  181. this.showLoginBtn = true
  182. if (self !== top) {
  183. localStorage.removeItem('account')
  184. this.postMessager.send({
  185. action: 'meechat:logout'
  186. })
  187. }
  188. // 初始vuex数据
  189. this.$store.commit('setUserInfo', null)
  190. this.$store.commit('initChatData')
  191. this.$store.commit('initGroupData')
  192. // 注销后,刷新页面
  193. location.replace(location.href.replace('show=false', 'show=true'))
  194. },
  195. async handleLogout2 () {
  196. this.doScatterLogout()
  197. this.showLoginBtn = true
  198. }
  199. }
  200. }
  201. </script>
  202. <style lang="scss" scoped>
  203. @import "./chatRoom.scss";
  204. </style>