App.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. import moment from 'moment';//引入moment
  13. import 'moment/locale/zh-cn';
  14. moment.locale('zh-cn');//配置moment中文环境
  15. export default {
  16. mixins: [AppDeviceEnquire],
  17. data () {
  18. return {
  19. locale:zhCN,
  20. envtips: '',
  21. moment
  22. }
  23. },
  24. created () {
  25. this.envtips = process.env.VUE_APP_ENVTIPS
  26. // 在页面加载时读取sessionStorage
  27. if (sessionStorage.getItem('store')) {
  28. const data = JSON.parse(sessionStorage.getItem('store'))
  29. sessionStorage.setItem('Access-Token', data.user.token)
  30. this.$store.replaceState(Object.assign({}, this.$store.state, data))
  31. }
  32. // 在页面刷新时将store保存到sessionStorage里
  33. window.addEventListener('beforeunload', () => {
  34. sessionStorage.setItem('store', JSON.stringify(this.$store.state))
  35. })
  36. // 按F5 刷新页面
  37. window.addEventListener('keydown', (e) => {
  38. if (e.keyCode == '116') {
  39. window.location.reload()
  40. }
  41. })
  42. this.$message.config({
  43. top: `100px`,
  44. duration: 3,
  45. maxCount: 3
  46. })
  47. }
  48. }
  49. </script>
  50. <style>
  51. #app {
  52. height: 100%;
  53. }
  54. .envtipsBox{
  55. position: fixed;
  56. z-index: 100000;
  57. background: red;
  58. text-align: center;
  59. color: #fff;
  60. font-size: 30px;
  61. top: 0;
  62. left: 0;
  63. width: 50%;
  64. margin-left: 20%;
  65. }
  66. </style>