Window.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <!--除主页意外的其他窗口-->
  2. <template>
  3. <div>
  4. <div v-for="item in windows"
  5. :style="{
  6. position: 'absolute',
  7. left:item ? item.Left*bigScale+'px' : '',
  8. top:item ? item.Top*bigScale+'px' : '',
  9. width:item ? item.Width*bigScale + 'px' : '',
  10. height:item ? item.Height*bigScale + 'px' : '',
  11. zIndex:item ? item.ZIndex : '',
  12. display:item ? (item.IsVisibility ? 'block' : 'none') : '',
  13. backgroundRepeat:'no-repeat',
  14. backgroundSize:'100% 100%',
  15. }"
  16. :ref="item.ID"
  17. >
  18. <Button :window="item"/>
  19. <Label :window="item"/>
  20. <Img :window="item"/>
  21. <BigShow :window="item"/>
  22. </div>
  23. </div>
  24. </template>
  25. <script>
  26. import {mapState} from "vuex"
  27. import {getNeedMoutedEleArr, getStaticFile} from "../../utils/tools"
  28. import PubSub from 'pubsub-js'
  29. import Button from "./Button"
  30. import Label from './Label'
  31. import Img from './Image'
  32. import BigShow from './BigShow'
  33. import {OPEN_WINDOWS} from "../../utils/constant"
  34. export default {
  35. components: {
  36. Button,
  37. Label,
  38. Img,
  39. BigShow
  40. },
  41. data() {
  42. return {
  43. windows:[],
  44. eleObj:{},
  45. staticUrl:this.$store.state.staticUrl, // 静态资源路径
  46. }
  47. },
  48. async beforeCreate() {
  49. const eleObj = {}
  50. this.windows = await getStaticFile('EnityWindow.Data')
  51. for(const item of this.windows){
  52. eleObj[item.ID] = await getNeedMoutedEleArr(item.ID)
  53. }
  54. this.eleObj = eleObj
  55. },
  56. mounted() {
  57. this.open_windows = PubSub.subscribe(OPEN_WINDOWS,(msg,data) => {
  58. // 需要显示的window
  59. let showWindows = []
  60. for(const item of this.windows){
  61. data.forEach(item2 => {
  62. if(item.ID === item2){
  63. item.IsVisibility = true
  64. showWindows.push(item)
  65. }
  66. })
  67. }
  68. // 需要隐藏的window
  69. for(const item of this.windows){
  70. showWindows.forEach(item2 => {
  71. if(item2.GroupNumber === item.GroupNumber && item2.ID !== item.ID){
  72. item.IsVisibility = false
  73. }
  74. })
  75. }
  76. })
  77. },
  78. updated() {
  79. // 设置背景图片
  80. const keyArr = Object.keys(this.$refs)
  81. keyArr.forEach(item => {
  82. if(this.eleObj[item]){
  83. const arr = this.eleObj[item].filter(item => item.BackIcon)
  84. for(const a of arr){
  85. this.$refs[a.ID] ? this.$refs[a.ID][0].style.backgroundImage = a.BackIcon ? 'url('+`${this.staticUrl}/Data/${a.BackIcon}`+')' : null : ''
  86. }
  87. }
  88. })
  89. },
  90. beforeDestroy() {
  91. PubSub.unsubscribe(this.open_windows)
  92. },
  93. computed: {
  94. ...mapState(['bigScale'])
  95. }
  96. }
  97. </script>