App.vue 2.8 KB

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