App.vue 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <template>
  2. <a-config-provider :locale="locale">
  3. <div id="app">
  4. <div v-if="envtips!=''" class="envtipsBox">{{ envtips }}</div>
  5. <router-view/>
  6. </div>
  7. </a-config-provider>
  8. </template>
  9. <script>
  10. import zhCN from 'ant-design-vue/es/locale/zh_CN'
  11. import { AppDeviceEnquire } from '@/utils/mixin'
  12. export default {
  13. mixins: [AppDeviceEnquire],
  14. data () {
  15. return {
  16. locale: zhCN,
  17. envtips: ''
  18. }
  19. },
  20. created () {
  21. this.envtips = process.env.VUE_APP_ENVTIPS
  22. // 在页面加载时读取sessionStorage
  23. if (sessionStorage.getItem('store')) {
  24. const data = JSON.parse(sessionStorage.getItem('store'))
  25. sessionStorage.setItem('Access-Token', data.user.token)
  26. this.$store.replaceState(Object.assign({}, this.$store.state, data))
  27. }
  28. // 在页面刷新时将store保存到sessionStorage里
  29. window.addEventListener('beforeunload', () => {
  30. sessionStorage.setItem('store', JSON.stringify(this.$store.state))
  31. })
  32. this.$message.config({
  33. top: `100px`,
  34. duration: 3,
  35. maxCount: 3
  36. })
  37. }
  38. }
  39. </script>
  40. <style>
  41. #app {
  42. height: 100%;
  43. }
  44. .envtipsBox{
  45. position: fixed;
  46. z-index: 100000;
  47. background: red;
  48. text-align: center;
  49. color: #fff;
  50. font-size: 30px;
  51. top: 0;
  52. left: 0;
  53. width: 50%;
  54. margin-left: 20%;
  55. }
  56. </style>