src/views/mdc/base/MdcWorkshopSignage.vue
@@ -6,8 +6,7 @@
        <a-row style="height: 100%">
          <a-col :span="7" class="header-left">
            <a-space>
              <span v-if="!isSwitchChecked">开启功能</span>
              <span v-else>关闭功能</span>
              <span>功能开关</span>
              <a-switch
                checked-children="开"
                un-checked-children="关"
@@ -22,17 +21,9 @@
          <a-col :span="10" class="workshop-name">{{ workshopDetails.workshopName }}</a-col>
          <a-col :span="7" class="device-status-info">
            <!--<a-space v-for="item in deviceStatusList" :key="item.value" class="single-status-info"-->
            <!--@click="handleScreenDevive(item)">-->
            <!--<div :style="{color:item.checked?'#1890FF':'#fff'}">{{ item.label }}</div>-->
            <!--<div class="status-square" :style="{ backgroundColor: item.color }"></div>-->
            <!--&lt;!&ndash;<a-checkbox :checked="item.checked" @change="checkboxChange(item)"></a-checkbox>&ndash;&gt;-->
            <!--<div>{{getDeviceNumberByStatus(item.value) }}</div>-->
            <!--</a-space>-->
            <a-space v-for="item in deviceStatusList" :key="item.value" class="single-status-info">
              <div :style="{color:item.checked?'#1890FF':'#fff'}">{{ item.label }}</div>
              <div class="status-square" :style="{ backgroundColor: item.color }"></div>
              <!--<a-checkbox :checked="item.checked" @change="checkboxChange(item)"></a-checkbox>-->
              <div>{{getDeviceNumberByStatus(item.value) }}</div>
            </a-space>
          </a-col>
@@ -67,23 +58,7 @@
               @click="openDetail(item)">
            <div class="device-status">
              <div
                v-if="item.equipmentStatus == 2 || item.equipmentStatus == 1"
                :style="{ backgroundImage: `url(${require('@/assets/yellow.png')})` }"
                class="status-image"
              ></div>
              <div
                v-if="item.equipmentStatus == 22"
                :style="{ backgroundImage: `url(${require('@/assets/red.png')})` }"
                class="status-image"
              ></div>
              <div
                v-if="item.equipmentStatus == 0"
                :style="{ backgroundImage: `url(${require('@/assets/gray.png')})` }"
                class="status-image"
              ></div>
              <div
                v-if="item.equipmentStatus == 3"
                :style="{ backgroundImage: `url(${require('@/assets/green.png')})` }"
                :style="{ backgroundImage: `url(${getStatusImgUrl(item.equipmentStatus)})` }"
                class="status-image"
              ></div>
              <div
@@ -91,8 +66,7 @@
                class="device-image"
              ></div>
            </div>
            <div class="device-id" id="deviceId"
                 :style="{ color:workshopDetails.equipmentIdColor }">
            <div :style="{ color:workshopDetails.equipmentIdColor }">
              {{ item.equipmentId }}
            </div>
          </div>
@@ -133,48 +107,32 @@
        showGuideline: 'none',
        guidelineXTop: 0,
        guidelineYLeft: 0,
        deviceList: [
          // {
          //   equipmentId: '123213213123232',// 设备ID
          //   equipmentImage: require('@/assets/8.png'), // 设备图片
          //   coordinateTop: 200, // 拖拽元素距盒子顶距离
          //   coordinateLeft: 100, // 拖拽元素距盒子左侧距离
          //   vw: 100,  // 缩放元素宽度
          //   vh: 100, // 缩放元素高度
          //   equipmentStatus: 1 // 设备状态 0:关机 22:报警 2:待机 3:运行 开机:1(没有四色灯标识归为待机)
          // }
        ], // 设备信息列表
        deviceList_copy: [],
        deviceList: [], // 设备信息列表
        deviceStatusList: [
          // {
          //   label: '全部',
          //   value: 99,
          //   color: '#fff',
          //   checked: true
          // },
          {
            label: '关机',
            value: 0,
            color: '#A8A8A8',
            checked: false
            color: '#A8A8A8'
          },
          {
            label: '待机',
            value: 2,
            color: '#FFFF00',
            checked: false
            color: '#FFFF00'
          },
          {
            label: '运行',
            value: 3,
            color: '#00EE00',
            checked: false
            color: '#00EE00'
          },
          {
            label: '报警',
            value: 22,
            color: '#FF0000',
            checked: false
            color: '#FF0000'
          },
          {
            label: '故障',
            value: 5,
            color: '#C11900'
          }
        ],// 设备状态指示灯列表,
        windowHeight: null,// 当前浏览器可视区域高度((不包括工具栏、书签、底部任务栏)
@@ -207,11 +165,9 @@
       * @param id 车间Id
       */
      getDeviceListByApi(id) {
        console.log('重新刷新')
        api.getDeviceListInWorkshopSignagePageApi(id).then((res) => {
          if (res.result && res.result.length > 0) {
            this.deviceList = res.result
            this.deviceList_copy = res.result
          }
        })
      },
@@ -223,12 +179,8 @@
      getWorkshopDetailsByApi(id) {
        api.getWorkshopDetailByWorkshopIdApi(id).then((res) => {
          this.workshopDetails = res.result
          // this.$refs.deviceContainerRef.style.backgroundImage = `url(${this.getImgView(
          //   this.workshopDetails.backgroundImage
          // )})`
          this.imgSrc = this.getImgView(this.workshopDetails.backgroundImage)
          this.$refs.deviceContainerRef.style.height = (this.windowHeight - this.pageHeaderHeight) + 'px'
          // this.parentH = this.windowHeight - this.pageHeaderHeight
          this.parentH = 900
          this.parentLimitation = true // 在父元素高度设置后再设置限制拖拽区域,不这样有概率导致父元素高度未设置就限制拖拽
        })
@@ -280,15 +232,6 @@
       * @param index 拖拽设备在数组中的下标
       */
      resize(newRect, index) {
        // if (newRect.width > 100) {
        //   if (newRect.width / newRect.height < 2) {
        //     this.deviceList[index].fontSize = newRect.width / 10
        //   } else {
        //     this.deviceList[index].fontSize = newRect.height / 5
        //   }
        // } else {
        //   this.deviceList[index].fontSize = 12
        // }
        this.showGuideline = 'block'
        this.deviceList[index].vw = newRect.width
        this.deviceList[index].vh = newRect.height
@@ -304,8 +247,8 @@
       * @returns {number} 设备数量
       */
      getDeviceNumberByStatus(value) {
        if (value === 99) return this.deviceList_copy.length
        return this.deviceList_copy.filter((item) => item.equipmentStatus === value).length
        if (value === 99) return this.deviceList.length
        return this.deviceList.filter((item) => item.equipmentStatus === value).length
      },
      /**
@@ -318,19 +261,38 @@
        this.isDraggable = !this.isDraggable
      },
      openDetail(item) {
      /**
       * 开启功能触发事件
       * @param record 点击的设备信息
       */
      openDetail(record) {
        if (!this.isSwitchChecked) {
          if (item.equipmentStatus == 0) {
          if (record.equipmentStatus == 0) {
            this.$message.warning('设备处于关机状态!')
            return false
          }
          console.log(item)
          console.log(this.$refs.EquipmentDetailModal)
          this.$refs.EquipmentDetailModal.initData(item.equId)
          this.$refs.EquipmentDetailModal.timerModel(item.equId)
          // this.equipMessageTimer = setInterval(() => {
          //   setTimeout( this.$refs.equmentDetaiModel.initData(item.equipmentId),0)
          // },1000*10)
          this.$refs.EquipmentDetailModal.initData(record.equId)
          this.$refs.EquipmentDetailModal.timerModel(record.equId)
        }
      },
      /**
       * 根据设备状态值获取对应三色灯图片地址
       * @param imgStatus 设备状态值
       */
      getStatusImgUrl(imgStatus) {
        switch (imgStatus) {
          case 1:
          case 2:
            return require('@/assets/yellow.png')
          case 3:
            return require('@/assets/green.png')
          case 22:
            return require('@/assets/red.png')
          case 5:
            return require('@/assets/orange.png')
          default:
            return require('@/assets/gray.png')
        }
      },
@@ -338,87 +300,11 @@
       * 浏览器尺寸发生改变时触发
       */
      handleWindowSizeChange() {
        // this.isFullScreen = !this.isFullScreen
        // if (!this.isFullScreen) location.reload() // 如果为全屏模式,则在切换模式时重新加载页面以重新获取浏览器可视区域高度
        const windowHeight =
          window.innerHeight ||
          document.documentElement.clientHeight ||
          document.body.clientHeight
        // this.parentH = 99999
        // const scaleRate = windowHeight / this.windowHeight
        // this.windowHeight = windowHeight
        this.$refs.deviceContainerRef.style.height = (windowHeight - this.pageHeaderHeight) + 'px'
        // const timer = setTimeout(() => {
        //   this.deviceList.forEach(item => {
        //     item.coordinateTop = item.coordinateTop * scaleRate
        //     item.vh = item.vh * scaleRate
        //     console.log('vh', item.vh)
        //   })
        //   this.parentH = windowHeight - this.pageHeaderHeight
        //   console.log('changeDeviceList', this.deviceList)
        // }, 500)
        // console.log('scaleRate', scaleRate)
      },
      checkboxChange(obj) {
        //需要判断是否开启功能,目的是为了关闭定时器避免筛选后设备被定时刷新的新设备覆盖
        if (this.isOperatingDevice) {
          obj.checked = !obj.checked
          if (obj.value !== 99) {
            if (obj.checked) this.checkedStatusCount++
            else this.checkedStatusCount--
          }
          if (obj.value == 99) {
            this.deviceStatusList.forEach(item => {
              if (item.value !== obj.value) item.checked = obj.checked
            })
            if (obj.checked) {
              this.deviceList = this.deviceList_copy
              this.checkedStatusCount = this.deviceStatusList.length - 1
            } else {
              this.deviceList = []
              this.checkedStatusCount = 0
            }
          } else {
            this.deviceStatusList.forEach(item => {
              if (item.value === 99) {
                if (this.checkedStatusCount !== this.deviceStatusList.length - 1 || this.checkedStatusCount === 0) item.checked = false
                if (this.checkedStatusCount === this.deviceStatusList.length - 1) item.checked = true
              }
            })
            if (obj.checked) {
              this.deviceList.push(...this.deviceList_copy.filter(item => item.equipmentStatus === obj.value))
            } else {
              this.deviceList = this.deviceList.filter(item => item.equipmentStatus !== obj.value)
            }
          }
        } else {
          this.$notification.warning({
            message: '消息',
            description: '请开启功能后再进行筛选'
          })
        }
      },
      handleScreenDevive(obj) {
        //需要判断是否开启功能,目的是为了关闭定时器避免筛选后设备被定时刷新的新设备覆盖
        if (this.isOperatingDevice) {
          obj.checked = true
          this.deviceList = this.deviceList_copy
          this.deviceStatusList.forEach(item => {
            if (item.value !== obj.value) item.checked = false
          })
          if (obj.value == 99) this.deviceList = this.deviceList_copy
          else this.deviceList = this.deviceList.filter(item => item.equipmentStatus === obj.value)
        } else {
          this.$notification.warning({
            message: '消息',
            description: '请开启功能后再进行筛选'
          })
        }
      }
    },
    created() {
@@ -437,9 +323,6 @@
        document.documentElement.clientHeight ||
        document.body.clientHeight
      // 判断浏览器可视区域高度是否等于分辨率,若相等则表示进入时浏览器为全屏模式
      // if (this.windowHeight === screen.height) this.isFullScreen = true
      window.addEventListener('resize', this.handleWindowSizeChange)
    },
    beforeDestroy() {
@@ -457,10 +340,6 @@
    color: #fff;
    .page-header {
      /*font-size: 50px;*/
      /*text-align: center;*/
      /*position: relative;*/
      .header-left {
        height: 100%;
        display: flex;
@@ -485,7 +364,6 @@
        .single-status-info {
          margin: 10px;
          cursor: pointer;
          .status-square {
            width: 14px;
@@ -526,11 +404,7 @@
        flex-direction: column;
        align-items: center;
        justify-content: space-between;
        cursor: default;
        &:active {
          border: 1px solid #1890ff;
        }
        cursor: pointer;
        .device-status {
          width: 100%;
@@ -557,10 +431,5 @@
        }
      }
    }
  }
  /deep/ .ant-checkbox-inner {
    background-color: transparent;
    border-color: #fff;
  }
</style>