zhuzhuanzhuan
2023-10-17 bed4e60f46a75823d7314311e3d5fafe71c1a2fa
src/views/WorkshopSignage.vue
@@ -6,19 +6,27 @@
        <a-space>
          <span v-if="!isSwitchChecked">开启功能</span>
          <span v-else>关闭功能</span>
          <a-switch checked-children="开" un-checked-children="关" @change="handleSwitchChange"
                    v-model="isSwitchChecked" :disabled="isSwitchChecked"/>
          <a-switch
            checked-children="开"
            un-checked-children="关"
            @change="handleSwitchChange"
            v-model="isSwitchChecked"
            :disabled="isSwitchChecked"
          />
        </a-space>
        <a-button type="primary" icon="save" size="large" @click="saveDevicePositionAndSizeByApi"
        >保存位置
        </a-button>
        <a-button type="primary" icon="save" size="large" @click="saveDevicePositionAndSizeByApi">保存位置</a-button>
      </div>
    </header>
    <dv-border-box-8>
      <div class="content-container" ref="deviceContainerRef">
        <VueDragResize v-for="(item,index) in deviceList" :key="item.equipmentId" :w="item.vw"
                       :h="item.vh" :x="item.coordinateLeft" :y="item.coordinateTop"
        <VueDragResize
          v-for="(item, index) in deviceList"
          :key="item.equipmentId"
          :w="item.vw"
          :h="item.vh"
          :x="item.coordinateLeft"
          :y="item.coordinateTop"
                       v-on:resizing="resize($event,index)"
                       v-on:dragging="resize($event,index)"
                       :parentLimitation="true"
@@ -28,20 +36,32 @@
                       :isResizable="isResizable"
                       :stickSize="6"
        >
          <div class="single-device"
               :style="{width:  item.vw+ 'px',height:item.vh+'px'}">
          <div class="single-device" :style="{ width: item.vw + 'px', height: item.vh + 'px' }">
            <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')})`}"
                   class="status-image"></div>
              <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')})` }"
                class="status-image"
              ></div>
              <div
                :style="{backgroundImage:`url(${getImgView(item.equipmentImage)||require('@/assets/8.png')})`}"
                class="device-image"></div>
                class="device-image"
              ></div>
            </div>
            <div class="device-id" :style="{fontSize: item.fontSize+'px'}">
              {{item.equipmentId}}
@@ -67,7 +87,7 @@
  export default {
    components: {
      VueDragResize
    VueDragResize,
    },
    data() {
      return {
@@ -92,24 +112,24 @@
          {
            label: '关机',
            value: 0,
            color: '#A8A8A8'
          color: '#A8A8A8',
          },
          {
            label: '待机',
            value: 2,
            color: '#FFFF00'
          color: '#FFFF00',
          },
          {
            label: '运行',
            value: 3,
            color: '#00EE00'
          color: '#00EE00',
          },
          {
            label: '报警',
            value: 22,
            color: '#FF0000'
          }
        ] // 设备状态指示灯列表
          color: '#FF0000',
        },
      ], // 设备状态指示灯列表
      }
    },
    watch: {
@@ -126,8 +146,8 @@
            this.timingAcquisition = null
          }
        },
        immediate: true
      }
      immediate: true,
    },
    },
    methods: {
      /**
@@ -136,7 +156,7 @@
       */
      getDeviceListByApi(id) {
        console.log('重新刷新')
        api.getDeviceListInWorkshopSignagePageApi(id).then(res => {
      api.getDeviceListInWorkshopSignagePageApi(id).then((res) => {
          if (res.result && res.result.length > 0) {
            this.deviceList = res.result
          }
@@ -148,9 +168,11 @@
       * @param id 车间Id
       */
      getWorkshopDetailsByApi(id) {
        api.getWorkshopDetailByWorkshopIdApi(id).then(res => {
      api.getWorkshopDetailByWorkshopIdApi(id).then((res) => {
          this.workshopDetails = res.result
          this.$refs.deviceContainerRef.style.backgroundImage = `url(${this.getImgView(this.workshopDetails.backgroundImage)})`
        this.$refs.deviceContainerRef.style.backgroundImage = `url(${this.getImgView(
          this.workshopDetails.backgroundImage
        )})`
        })
      },
@@ -171,11 +193,11 @@
      saveDevicePositionAndSizeByApi() {
        console.log('触发保存')
        if (this.isOperatingDevice) {
          api.saveDevicePositionAndSizeApi(this.deviceList).then(res => {
        api.saveDevicePositionAndSizeApi(this.deviceList).then((res) => {
            if (res.code === 200) {
              this.$notification.success({
                message: '消息',
                description: res.message
              description: res.message,
              })
              this.isOperatingDevice = false
              if (this.isSwitchChecked) {
@@ -189,10 +211,9 @@
        } else {
          this.$notification.warning({
            message: '消息',
            description: '请开启功能后再进行保存'
          description: '请开启功能后再进行保存',
          })
        }
      },
      /**
@@ -222,7 +243,7 @@
       * @returns {number} 设备数量
       */
      getDeviceNumberByStatus(value) {
        return this.deviceList.filter(item => item.equipmentStatus === value).length
      return this.deviceList.filter((item) => item.equipmentStatus === value).length
      },
      /**
@@ -233,7 +254,7 @@
        this.isOperatingDevice = true
        this.isResizable = !this.isResizable
        this.isDraggable = !this.isDraggable
      }
    },
    },
    created() {
      if (this.$route.params.id) {
@@ -249,7 +270,7 @@
      // 确保销毁定时器及回收资源
      clearInterval(this.timingAcquisition)
      this.timingAcquisition = null
    }
  },
  }
</script>
@@ -343,7 +364,6 @@
          }
        }
      }
    }
  }
</style>