App.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <template>
  2. <div id="app">
  3. <div :class="[pwa ? 'c-pwa' : '', '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 'scatterjs-core'
  19. import ScatterEOS from 'scatterjs-plugin-eosjs'
  20. import { getUrlParam, noticeManager } from '@/util/util.js'
  21. import { accountLoginMixin } from '@/mixins/login'
  22. import { mapState } from 'vuex'
  23. import loginBox from '@/components/login/loginBox'
  24. import panel from '@/components/panel/panel'
  25. ScatterJS.plugins(new ScatterEOS())
  26. export default {
  27. name: 'App',
  28. mixins: [accountLoginMixin],
  29. components: {
  30. loginBox,
  31. panel
  32. },
  33. computed: {
  34. ...mapState({
  35. isLogin: state => state.chat.isLogin,
  36. toApp: state => state.chat.toApp,
  37. curSession: state => state.curSession,
  38. sessionList: state => state.chat.sessionList
  39. })
  40. },
  41. data () {
  42. return {
  43. pwa: getUrlParam('pwa') == '1'
  44. }
  45. },
  46. methods: {
  47. showUnreadNum () {
  48. let unreadNum = 0
  49. this.sessionList.forEach((item) => {
  50. if (item.is_mute == 0) unreadNum += Number(item.unread)
  51. })
  52. noticeManager.changeTitle(unreadNum > 99 ? '99+' : unreadNum)
  53. }
  54. },
  55. async created () {
  56. this.checkLocalLogin()
  57. },
  58. mounted () {
  59. // 监听浏览器tab切换事件
  60. let tabTimer = null
  61. // let lastUnreadNum = 0
  62. document.addEventListener('visibilitychange', () => {
  63. if (document.visibilityState !== 'hidden') {
  64. // 切换回当前页面
  65. noticeManager.changeTitle(0)
  66. if (tabTimer) clearInterval(tabTimer)
  67. } else {
  68. this.showUnreadNum()
  69. tabTimer = setInterval(() => {
  70. this.showUnreadNum()
  71. }, 2000)
  72. }
  73. })
  74. window.$router = this.$router
  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 0.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. position: relative;
  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. padding-left: 350px;
  111. box-sizing: border-box;
  112. // background: #eee;
  113. }
  114. .c-copyright {
  115. position: absolute;
  116. bottom: 30px;
  117. width: 100%;
  118. text-align: center;
  119. font-size: 12px;
  120. color: #e3e3e3;
  121. }
  122. .c-pwa {
  123. height: 100%;
  124. padding-top: 0;
  125. }
  126. .c-pwa .c-wrap {
  127. max-width: 100%;
  128. }
  129. </style>