firstIndex.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <template>
  2. <div class="chooseSystem-container" ref="systemContainer">
  3. <div class="header">
  4. <!-- <img src="../../assets/tg.png" alt="" style="width: auto;height: 100%;"> -->
  5. </div>
  6. <img src="../../assets/content.png" alt="" ref="systemContent">
  7. <div class="common-system system-iTDM" ref="systemiTDM" @click="chooseSystem('/dashboard/analysis')"></div>
  8. </div>
  9. </template>
  10. <script>
  11. export default {
  12. name: '',
  13. data () {
  14. return {
  15. timer: null
  16. }
  17. },
  18. created () {
  19. },
  20. mounted () {
  21. // 设置定时器--因为初始执行方法时img没有加载完,所以获取不到高度;定时一段时间等img加载之后再执行
  22. this.timer = setTimeout(() => {
  23. this.setSystemStyle()
  24. }, 100)
  25. // this.$nextTick(() => {
  26. // })
  27. window.addEventListener('resize', this.setSystemStyle)
  28. },
  29. beforeDestroy() {
  30. // 清除定时器
  31. if(this.timer){
  32. clearInterval(this.timer);
  33. this.timer = null;
  34. }
  35. },
  36. methods: {
  37. setSystemStyle(){
  38. // console.log(this.$refs)
  39. // 获取图片宽高和top以及left
  40. var systemWidth = this.$refs.systemContent.offsetWidth
  41. // var systemHeight = this.$refs.systemContent.offsetHeight
  42. // 因为高度是动态的,所以初始化可能会出现获取不到高度的情况
  43. var systemHeight = systemWidth * (700/1476)
  44. var systemTop = this.$refs.systemContent.offsetTop
  45. var systemLeft = this.$refs.systemContent.offsetLeft
  46. // console.log(systemWidth, systemHeight, systemTop, systemLeft)
  47. // 设置iTDM动态宽高和top以及left
  48. this.$refs.systemiTDM.style.width = (systemWidth * 0.234) + 'px'
  49. this.$refs.systemiTDM.style.height = (systemHeight * 0.107) + 'px'
  50. this.$refs.systemiTDM.style.top = (systemTop - systemHeight/2 + systemHeight*0.18) + 'px'
  51. this.$refs.systemiTDM.style.left = (systemLeft - systemWidth/2 + systemWidth*0.03) + 'px'
  52. },
  53. chooseSystem(url){
  54. this.$router.push({path: url})
  55. // this.$router.push({path: item.url})
  56. },
  57. }
  58. }
  59. </script>
  60. <style lang="scss">
  61. .chooseSystem-container{
  62. width: 100%;
  63. height: 100%;
  64. background: url('../../assets/bg.png') no-repeat center center;
  65. background-size: cover;
  66. position: relative;
  67. .header{
  68. width: 100%;
  69. height: 68px;
  70. position: absolute;
  71. right: 0;
  72. top: 20px;
  73. // padding-right: 20px;
  74. // background: url('../../assets/title.png') no-repeat right center;
  75. background-size: contain;
  76. background: url('../../assets/tg.png') no-repeat right center;
  77. }
  78. img{
  79. width: 80%;
  80. height: auto;
  81. position: absolute;
  82. top: 50%;
  83. left: 50%;
  84. transform: translate(-50%, -50%);
  85. }
  86. .common-system{
  87. cursor: pointer;
  88. position: absolute;
  89. }
  90. .system-iTDM{
  91. width: 0;
  92. height: 0;
  93. // background: red;
  94. top: 0;
  95. left: 0;
  96. }
  97. }
  98. </style>