roomToolbar.vue 6.0 KB

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