App.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. // 获取所有数据字典
  29. this.$store.dispatch('getAllLookUp')
  30. // 在页面加载时读取sessionStorage
  31. if (sessionStorage.getItem('store')) {
  32. const data = JSON.parse(sessionStorage.getItem('store'))
  33. sessionStorage.setItem('Access-Token', data.user.token)
  34. this.$store.replaceState(Object.assign({}, this.$store.state, data))
  35. }
  36. // 在页面刷新时将store保存到sessionStorage里
  37. window.addEventListener('beforeunload', () => {
  38. this.$store.state.app.isNewTab = true
  39. this.$store.state.app.updateList = false
  40. sessionStorage.setItem('store', JSON.stringify(this.$store.state))
  41. })
  42. // 按F5 刷新页面
  43. window.addEventListener('keydown', (e) => {
  44. if (e.keyCode == '116') {
  45. window.location.reload()
  46. }
  47. })
  48. // window.addEventListener('visibilitychange',()=>{
  49. // this.$store.state.app.visibilityState = document.visibilityState == 'visible'
  50. // })
  51. // window.addEventListener('focus',(e)=>{
  52. // if(!this.$store.state.app.visibilityState){
  53. // this.$store.state.app.visibilityState = true
  54. // }
  55. // })
  56. // window.addEventListener('blur',(e)=>{
  57. // if(this.$store.state.app.visibilityState){
  58. // this.$store.state.app.visibilityState = false
  59. // }
  60. // })
  61. // 选择文本后复制
  62. window.addEventListener('mouseup', (e) => {
  63. onTextSelected(this.$copyText,this.$message)
  64. })
  65. window.addEventListener('mousedown', (e) => {
  66. const n = document.getElementsByClassName('copy-rect')
  67. if(n[0]){
  68. document.body.removeChild(n[0])
  69. }
  70. })
  71. this.$message.config({
  72. top: `100px`,
  73. duration: 3,
  74. maxCount: 3
  75. })
  76. }
  77. }
  78. </script>
  79. <style lang="less">
  80. #app {
  81. height: 100%;
  82. }
  83. .copy-rect{
  84. background: #fff;
  85. border: 1px solid #eee;
  86. border-radius: 5px;
  87. font-size: 12px;
  88. padding: 2px 5px;
  89. cursor: pointer;
  90. &:hover{
  91. color: #0282eb;
  92. }
  93. }
  94. .envtipsBox{
  95. position: fixed;
  96. z-index: 100000;
  97. background: red;
  98. text-align: center;
  99. color: #fff;
  100. font-size: 30px;
  101. top: 0;
  102. left: 0;
  103. width: 30%;
  104. margin-left: 20%;
  105. }
  106. </style>