Window.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. this.$refs[item.ID][0].style.backgroundImage = item.BackIcon ? 'url('+`${this.staticUrl}/Data/${item.BackIcon}`+')' : null
  66. }
  67. })
  68. }
  69. // 需要隐藏的window
  70. for(const item of this.windows){
  71. showWindows.forEach(item2 => {
  72. if(item2.GroupNumber === item.GroupNumber && item2.ID !== item.ID){
  73. item.IsVisibility = false
  74. }
  75. })
  76. }
  77. })
  78. },
  79. updated() {
  80. // 设置背景图片
  81. const keyArr = Object.keys(this.$refs)
  82. keyArr.forEach(item => {
  83. if(this.eleObj[item]){
  84. const arr = this.eleObj[item].filter(item => item.BackIcon)
  85. for(const a of arr){
  86. this.$refs[a.ID] ? this.$refs[a.ID][0].style.backgroundImage = a.BackIcon ? 'url('+`${this.staticUrl}/Data/${a.BackIcon}`+')' : null : ''
  87. }
  88. }
  89. })
  90. },
  91. beforeDestroy() {
  92. PubSub.unsubscribe(this.open_windows)
  93. },
  94. computed: {
  95. ...mapState(['bigScale'])
  96. }
  97. }
  98. </script>