App.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <div id="app">
  3. <div class="c-main">
  4. <div class="c-wrap" v-if="toApp">
  5. <panel></panel>
  6. <chat-room v-if="curSession" :sessionId="curSession"></chat-room>
  7. <div v-else class="no-chat">
  8. <i class="mee-icon"></i>
  9. </div>
  10. </div>
  11. <div v-else class="c-login">
  12. <login-box></login-box>
  13. </div>
  14. </div>
  15. <div class="c-copyright">
  16. <span>copyright © 2019 MeeChat.</span>
  17. </div>
  18. </div>
  19. </template>
  20. <script>
  21. import ScatterJS from 'scatter-js/dist/scatter.esm'
  22. import { showError } from '@/util/util.js'
  23. import { mapActions, mapState } from 'vuex'
  24. import loginBox from '@/components/login/loginBox'
  25. import chatRoom from '@/components/chatRoom/chatRoom'
  26. import panel from '@/components/panel/panel'
  27. export default {
  28. name: 'App',
  29. components: {
  30. loginBox,
  31. chatRoom,
  32. panel
  33. },
  34. computed: {
  35. ...mapState({
  36. isLogin: state => state.chat.isLogin,
  37. toApp: state => state.chat.toApp,
  38. curSession: state => state.curSession
  39. })
  40. },
  41. methods: {
  42. ...mapActions([
  43. 'setScatter',
  44. 'setAccount',
  45. 'doScatterLogin',
  46. 'doGameLogin',
  47. 'initSocket'
  48. ])
  49. },
  50. async created () {
  51. console.log('test')
  52. // 连接scatter
  53. ScatterJS.scatter.connect('MEE_CHAT').then(async connected => {
  54. if (connected) {
  55. // 设置scatter
  56. this.setScatter(ScatterJS.scatter)
  57. // 清空全局scatter引用
  58. window.ScatterJS = null
  59. try {
  60. // 调起scatter授权登录
  61. await this.doScatterLogin()
  62. // 签名登录
  63. await this.doGameLogin()
  64. await this.initSocket()
  65. this.$store.commit('chatAppLogin', true)
  66. this.$store.commit('toApp', true)
  67. } catch (error) {
  68. this.$store.commit('chatAppLogin', false)
  69. }
  70. } else {
  71. // 用户scatter未解锁
  72. showError(this.$t('installScatter'), 'Scatter')
  73. this.setAccount('')
  74. }
  75. })
  76. }
  77. }
  78. </script>
  79. <style lang="scss">
  80. @import '@/style/global.scss';
  81. </style>
  82. <style lang="scss" scoped>
  83. .c-main{
  84. height: 80%;
  85. min-height: 600px;
  86. padding-top: 100px;
  87. -webkit-transition: padding .3s linear;
  88. -webkit-backface-visibility: hidden;
  89. backface-visibility: hidden;
  90. }
  91. @media (max-height: 800px), (max-width: 1000px){
  92. .c-main{
  93. padding-top: 0;
  94. height: 100%;
  95. }
  96. .c-copyright{
  97. display: none;
  98. }
  99. }
  100. .c-wrap{
  101. display: flex;
  102. max-width: 1066px;
  103. min-width: 800px;
  104. height: 100%;
  105. margin: 0 auto;
  106. border-radius: 3px;
  107. -moz-border-radius: 3px;
  108. -webkit-border-radius: 3px;
  109. overflow: hidden;
  110. }
  111. .c-copyright{
  112. position: absolute;
  113. bottom: 30px;
  114. width: 100%;
  115. text-align: center;
  116. font-size: 12px;
  117. color: #e3e3e3;
  118. }
  119. .no-chat{
  120. height: 100%;
  121. background: #eeeeee;
  122. -webkit-box-flex: 1;
  123. -ms-flex: 1;
  124. flex: 1;
  125. position: relative;
  126. .mee-icon{
  127. display: block;
  128. background: url('../../assets/mee-logo.png') no-repeat;
  129. width: 84px;
  130. height: 96px;
  131. margin: 230px auto 0;
  132. }
  133. }
  134. </style>