App.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 { onTextSelected } from '@/utils/util'
  13. import moment from 'moment';//引入moment
  14. import 'moment/locale/zh-cn';
  15. moment.locale('zh-cn'); //设置语言 或 moment.lang('zh-cn');
  16. export default {
  17. mixins: [AppDeviceEnquire],
  18. data () {
  19. return {
  20. locale:zhCN,
  21. envtips: '',
  22. moment
  23. }
  24. },
  25. created () {
  26. const _this = this
  27. this.envtips = process.env.VUE_APP_ENVTIPS
  28. // 在页面加载时读取sessionStorage
  29. if (sessionStorage.getItem('store')) {
  30. const data = JSON.parse(sessionStorage.getItem('store'))
  31. sessionStorage.setItem('Access-Token', data.user.token)
  32. this.$store.replaceState(Object.assign({}, this.$store.state, data))
  33. }
  34. // 在页面刷新时将store保存到sessionStorage里
  35. window.addEventListener('beforeunload', () => {
  36. this.$store.state.app.isNewTab = true
  37. this.$store.state.app.updateList = false
  38. sessionStorage.setItem('store', JSON.stringify(this.$store.state))
  39. })
  40. // 按F5 刷新页面
  41. window.addEventListener('keydown', (e) => {
  42. if (e.keyCode == '116') {
  43. window.location.reload()
  44. }
  45. })
  46. // window.addEventListener('visibilitychange',()=>{
  47. // this.$store.state.app.visibilityState = document.visibilityState == 'visible'
  48. // })
  49. // window.addEventListener('focus',(e)=>{
  50. // if(!this.$store.state.app.visibilityState){
  51. // this.$store.state.app.visibilityState = true
  52. // }
  53. // })
  54. // window.addEventListener('blur',(e)=>{
  55. // if(this.$store.state.app.visibilityState){
  56. // this.$store.state.app.visibilityState = false
  57. // }
  58. // })
  59. // 选择文本后复制
  60. window.addEventListener('mouseup', (e) => {
  61. onTextSelected(this.$copyText,this.$message)
  62. })
  63. window.addEventListener('mousedown', (e) => {
  64. const n = document.getElementsByClassName('copy-rect')
  65. if(n[0]){
  66. document.body.removeChild(n[0])
  67. }
  68. })
  69. this.$message.config({
  70. top: `100px`,
  71. duration: 3,
  72. maxCount: 3
  73. })
  74. }
  75. }
  76. </script>
  77. <style lang="less">
  78. #app {
  79. height: 100%;
  80. }
  81. .copy-rect{
  82. background: #fff;
  83. border: 1px solid #eee;
  84. border-radius: 5px;
  85. font-size: 12px;
  86. padding: 2px 5px;
  87. cursor: pointer;
  88. &:hover{
  89. color: #0282eb;
  90. }
  91. }
  92. .envtipsBox{
  93. position: fixed;
  94. z-index: 100000;
  95. background: red;
  96. text-align: center;
  97. color: #fff;
  98. font-size: 30px;
  99. top: 0;
  100. left: 0;
  101. width: 30%;
  102. margin-left: 20%;
  103. }
  104. </style>