App.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 'scatter-js/dist/scatter.esm'
  19. import { getUrlParam, noticeManager } from '@/util/util.js'
  20. import { accountLoginMixin } from '@/mixins/login'
  21. import { mapState } from 'vuex'
  22. import loginBox from '@/components/login/loginBox'
  23. import panel from '@/components/panel/panel'
  24. export default {
  25. name: 'App',
  26. mixins: [accountLoginMixin],
  27. components: {
  28. loginBox,
  29. panel
  30. },
  31. computed: {
  32. ...mapState({
  33. isLogin: state => state.chat.isLogin,
  34. toApp: state => state.chat.toApp,
  35. curSession: state => state.curSession,
  36. sessionList: state => state.chat.sessionList
  37. })
  38. },
  39. data () {
  40. return {
  41. pwa: getUrlParam('pwa') == '1'
  42. }
  43. },
  44. methods: {
  45. showUnreadNum () {
  46. let unreadNum = 0
  47. this.sessionList.forEach((item) => {
  48. if (item.is_mute == 0) unreadNum += Number(item.unread)
  49. })
  50. noticeManager.changeTitle(unreadNum > 99 ? '99+' : unreadNum)
  51. }
  52. },
  53. async created () {
  54. this.checkLocalLogin()
  55. },
  56. mounted () {
  57. // 监听浏览器tab切换事件
  58. let tabTimer = null
  59. // let lastUnreadNum = 0
  60. document.addEventListener('visibilitychange', () => {
  61. if (document.visibilityState !== 'hidden') {
  62. // 切换回当前页面
  63. noticeManager.changeTitle(0)
  64. if (tabTimer) clearInterval(tabTimer)
  65. } else {
  66. this.showUnreadNum()
  67. tabTimer = setInterval(() => {
  68. this.showUnreadNum()
  69. }, 2000)
  70. }
  71. })
  72. window.$router = this.$router
  73. }
  74. }
  75. </script>
  76. <style lang="scss">
  77. @import "@/style/global.scss";
  78. </style>
  79. <style lang="scss" scoped>
  80. .c-main {
  81. height: 80%;
  82. min-height: 600px;
  83. padding-top: 100px;
  84. -webkit-transition: padding 0.3s linear;
  85. -webkit-backface-visibility: hidden;
  86. backface-visibility: hidden;
  87. }
  88. @media (max-height: 800px), (max-width: 1000px) {
  89. .c-main {
  90. padding-top: 0;
  91. height: 100%;
  92. }
  93. .c-copyright {
  94. display: none;
  95. }
  96. }
  97. .c-wrap {
  98. position: relative;
  99. // display: flex;
  100. max-width: 1066px;
  101. min-width: 800px;
  102. height: 100%;
  103. margin: 0 auto;
  104. border-radius: 3px;
  105. -moz-border-radius: 3px;
  106. -webkit-border-radius: 3px;
  107. overflow: hidden;
  108. padding-left: 350px;
  109. box-sizing: border-box;
  110. // background: #eee;
  111. }
  112. .c-copyright {
  113. position: absolute;
  114. bottom: 30px;
  115. width: 100%;
  116. text-align: center;
  117. font-size: 12px;
  118. color: #e3e3e3;
  119. }
  120. .c-pwa {
  121. height: 100%;
  122. padding-top: 0;
  123. }
  124. .c-pwa .c-wrap {
  125. max-width: 100%;
  126. }
  127. </style>