App.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <template>
  2. <div id="app">
  3. <div class="pub-title">MeeChat</div>
  4. <div class="router-wrap" :class="{'bottom': !navShow}">
  5. <router-view></router-view>
  6. </div>
  7. <div class="pub-nav" v-if="navShow">
  8. <router-link to="/" class="nav-item">
  9. <i class="chat-icon"></i>
  10. <span class="title">聊天</span>
  11. </router-link>
  12. <router-link to="/me" class="nav-item">
  13. <i class="me-icon"></i>
  14. <span class="title">我的</span>
  15. </router-link>
  16. </div>
  17. </div>
  18. </template>
  19. <script>
  20. import ScatterJS from 'scatter-js/dist/scatter.esm'
  21. import { showError } from '@/util/util.js'
  22. import { mapActions } from 'vuex'
  23. export default {
  24. name: 'App',
  25. computed: {
  26. navShow () {
  27. return this.$route.name !== 'groupChat' && this.$route.name !== 'pmChat'
  28. }
  29. },
  30. methods: {
  31. ...mapActions([
  32. 'setScatter',
  33. 'setAccount',
  34. 'doScatterLogin',
  35. 'doContractLogin',
  36. 'initSocket'
  37. ])
  38. },
  39. async created () {
  40. // 连接scatter
  41. ScatterJS.scatter.connect('MEE_CHAT').then(async connected => {
  42. if (connected) {
  43. // 设置scatter
  44. this.setScatter(ScatterJS.scatter)
  45. // 清空全局scatter引用
  46. window.ScatterJS = null
  47. try {
  48. // 调起scatter授权登录
  49. await this.doScatterLogin()
  50. // 签名登录
  51. await this.doContractLogin()
  52. await this.initSocket()
  53. } catch (error) {
  54. }
  55. } else {
  56. // 用户scatter未解锁
  57. showError(this.$t('installScatter'), 'Scatter')
  58. this.setAccount('')
  59. }
  60. })
  61. }
  62. }
  63. </script>
  64. <style lang="scss">
  65. @import '@/style/base.scss';
  66. @import '@/style/h5.scss';
  67. .router-wrap{
  68. position: fixed;
  69. top: px2rem(86);
  70. left: 0;
  71. right: 0;
  72. bottom: px2rem(104);
  73. overflow: auto;
  74. background-color: #f2f2f2;
  75. &.bottom{
  76. bottom: 0;
  77. }
  78. }
  79. .pub-nav{
  80. position: fixed;
  81. left: 0;
  82. right: 0;
  83. bottom: 0;
  84. height: px2rem(106);
  85. background-color: #fafafa;
  86. border-top: 1px solid #e5e5e5;
  87. display: flex;
  88. .chat-icon{
  89. background: url('../../assets/h5/nav-chat-icon1.png') no-repeat;
  90. width: px2rem(48);
  91. height: px2rem(41);
  92. background-size: 100%;
  93. }
  94. .me-icon{
  95. background: url('../../assets/h5/nav-me-icon1.png') no-repeat;
  96. width: px2rem(37);
  97. height: px2rem(41);
  98. background-size: 100%;
  99. }
  100. .title{
  101. display: block;
  102. text-align: center;
  103. font-size: px2rem(20);
  104. color: #a5b5ce;
  105. margin-top: px2rem(10);
  106. }
  107. .nav-item{
  108. flex: 1;
  109. box-sizing: border-box;
  110. padding-top: px2rem(22);
  111. text-decoration: none;
  112. &.router-link-exact-active{
  113. .chat-icon{
  114. background: url('../../assets/h5/nav-chat-icon.png') no-repeat;
  115. background-size: 100%;
  116. }
  117. .me-icon{
  118. background: url('../../assets/h5/nav-me-icon.png') no-repeat;
  119. background-size: 100%;
  120. }
  121. .title{
  122. color: #32a1f7;
  123. }
  124. }
  125. i{
  126. display: block;
  127. margin: 0 auto;
  128. }
  129. }
  130. }
  131. </style>