App.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. // 连接scatter
  52. ScatterJS.scatter.connect('MEE_CHAT').then(async connected => {
  53. if (connected) {
  54. // 设置scatter
  55. this.setScatter(ScatterJS.scatter)
  56. // 清空全局scatter引用
  57. window.ScatterJS = null
  58. try {
  59. // 调起scatter授权登录
  60. await this.doScatterLogin()
  61. // 签名登录
  62. await this.doGameLogin()
  63. await this.initSocket()
  64. this.$store.commit('chatAppLogin', true)
  65. this.$store.commit('toApp', true)
  66. } catch (error) {
  67. this.$store.commit('chatAppLogin', false)
  68. }
  69. } else {
  70. // 用户scatter未解锁
  71. showError(this.$t('installScatter'), 'Scatter')
  72. this.setAccount('')
  73. }
  74. })
  75. }
  76. }
  77. </script>
  78. <style lang="scss">
  79. @import '@/style/global.scss';
  80. </style>
  81. <style lang="scss" scoped>
  82. .c-main{
  83. height: 80%;
  84. min-height: 600px;
  85. padding-top: 100px;
  86. -webkit-transition: padding .3s linear;
  87. -webkit-backface-visibility: hidden;
  88. backface-visibility: hidden;
  89. }
  90. @media (max-height: 800px), (max-width: 1000px){
  91. .c-main{
  92. padding-top: 0;
  93. height: 100%;
  94. }
  95. .c-copyright{
  96. display: none;
  97. }
  98. }
  99. .c-wrap{
  100. display: flex;
  101. max-width: 1066px;
  102. min-width: 800px;
  103. height: 100%;
  104. margin: 0 auto;
  105. border-radius: 3px;
  106. -moz-border-radius: 3px;
  107. -webkit-border-radius: 3px;
  108. overflow: hidden;
  109. }
  110. .c-copyright{
  111. position: absolute;
  112. bottom: 30px;
  113. width: 100%;
  114. text-align: center;
  115. font-size: 12px;
  116. color: #e3e3e3;
  117. }
  118. .no-chat{
  119. height: 100%;
  120. background: #eeeeee;
  121. -webkit-box-flex: 1;
  122. -ms-flex: 1;
  123. flex: 1;
  124. position: relative;
  125. .mee-icon{
  126. display: block;
  127. background: url('../../assets/mee-logo.png') no-repeat;
  128. width: 84px;
  129. height: 96px;
  130. margin: 230px auto 0;
  131. }
  132. }
  133. </style>