前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >el-select二级联动效果-摄像头

el-select二级联动效果-摄像头

作者头像
不爱吃糖的程序媛
发布2024-01-18 21:22:06
1140
发布2024-01-18 21:22:06
举报
效果图

需求:改变货架编号,显示出对应的监控层数。 并且初次渲染的时候,也要展示货架编号的对应监控层列表。

在这里插入图片描述
在这里插入图片描述
源代码
代码语言:javascript
复制
<template>
  <Dialog
    :title="$t('lang.camera')"
    width="800px"
    :visible="visible"
    :btnName="$t('lang.close')"
    @handleOk="handleOk"
    @handleClose="handleClose"
  >
    <div
      class="title"
      v-if="cameraDetailInfo.imgDeviceName && cameraDetailInfo.imgDeviceSn"
    >
      {{
        cameraDetailInfo.imgDeviceName +
          "(" +
          cameraDetailInfo.imgDeviceSn +
          ")"
      }}
    </div>
    <div class="dialog-content">
      <el-table :data="deviceCameras || []">
        <el-table-column prop="cameraSn" :label="$t('lang.no')" :min-width="30">
          <template slot-scope="scope">
            <span>{{ scope.row.cameraSn }}</span>
          </template>
        </el-table-column>

        <el-table-column
          prop="shelvesSn"
          :label="$t('lang.monitorShielfNo')"
          :min-width="110"
        >
          <template slot-scope="scope">
            <el-select
              v-model="deviceCameras[scope.$index].shelvesSn"
              @change="val => changeShelvesSn(val, scope.$index)"
              size="small"
            >
              <el-option
                :placeholder="$t('lang.pleaseSelect')"
                v-for="item in shelvesList"
                :key="item.shelvesSn"
                :label="item.shelvesSn"
                :value="item.shelvesSn"
              ></el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column
          prop="cameraLevel"
          :label="$t('lang.monitorShielfLevel')"
          :min-width="110"
        >
          <template slot-scope="scope">
            <el-select
              v-model="deviceCameras[scope.$index].cameraLevel"
              size="small"
            >
              <el-option
                :placeholder="$t('lang.pleaseSelect')"
                v-for="item in deviceCameras[scope.$index].levelList"
                :key="item"
                :label="item"
                :value="item"
              ></el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column
          prop="status"
          :label="$t('lang.connectionStatus')"
          :min-width="50"
        >
          <template slot-scope="scope">
            <span>{{
              scope.row.status === 1 ? $t("lang.onLine") : $t("lang.offLine")
            }}</span>
          </template>
        </el-table-column>
        <el-table-column :label="$t('lang.operation')" :min-width="50">
          <template slot-scope="scope">
            <div class="icon-box">
              <el-popconfirm
                hide-icon
                placement="left"
                :title="$t('lang.confirmRefreshShelf')"
                :ref="`popover-${scope.$index}`"
                popper-class="my-popper"
                class="popper-style"
                @confirm="
                  refreshCamera(
                    scope.row.cameraSn,
                    cameraDetailInfo.imgDeviceSn,
                    scope.row.cameraLevel,
                    scope.row.shelvesSn
                  )
                "
              >
                <div class="delete-icon" slot="reference">
                  <Icon
                    link="icon-gengxin2"
                    :allowProp="
                      (deviceCameras[scope.$index].shelvesSn !==
                        cameraDetailInfo.deviceCameras[scope.$index]
                          .shelvesSn ||
                      deviceCameras[scope.$index].cameraLevel !==
                        cameraDetailInfo.deviceCameras[scope.$index].cameraLevel
                        ? true
                        : false)
                    "
                  ></Icon>
                </div>
              </el-popconfirm>
            </div>

            <div class="icon-box" v-show="scope.row.status === 0">
              <el-popconfirm
                hide-icon
                :title="$t('lang.confirmDelete')"
                :ref="`popover-${scope.$index}`"
                popper-class="delete-popper"
                class="popper-style"
                @confirm="
                  deleteCamera(scope.row.cameraSn, cameraDetailInfo.imgDeviceSn,scope.$index)
                "
              >
                <div class="delete-icon" slot="reference">
                  <Icon link="icon-shanchu-copy" :allowProp="true"></Icon>
                </div>
              </el-popconfirm>
            </div>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </Dialog>
</template>
代码语言:javascript
复制
script>
import { get } from "http";
import { runInThisContext } from "vm";
import Vue from "vue";
export default {
  props: {
    visible: Boolean,
    warehouseSn: String,
    cameraDetailInfo:{
      type: Object,
      default:{}
    }
  },
  data() {
    return {
      shelvesList: [], //货架编号
      levelList: [],
      deviceCameras: []
    };
  },

  watch: {
    cameraDetailInfo: {
      handler(newVal, oldVal) {
        if (newVal !== null && oldVal !== null) {
          this.deviceCameras = JSON.parse(
            JSON.stringify(this.cameraDetailInfo.deviceCameras)
          )
          this.deviceCameras.map(item =>{
              item.levelList=[]
              this.shelvesList.map(shelve=>{
                if(shelve.shelvesSn === item.shelvesSn){
                  item.levelList = shelve.levels
                }
              })
            })
        }
      }
    }
  },

  computed: {
    // deviceCameras() {
    //   return this.cameraDetailInfo === null
    //     ? []
    //     : this.cameraDetailInfo.deviceCameras;
    // },
    'deviceCameras[scope.$index].shelvesSn'(){
      return this.allowProp = true
    }
  },

  created() {
    this.getSelectShelfList();
  },

  methods: {
    //获取下拉列表
    getSelectShelfList() {
      this.$api.shelf
        .shelvesSelectList({ houseSn: this.warehouseSn })
        .then(({ code, data }) => {
          if (code === 0) {
            this.shelvesList = data;
            this.shelvesList.unshift({
              shelvesSn: "",
              levels: ""
            });
          }
        });
    },
    
    changeShelvesSn(val, index) {
      if (val === "") {
        this.deviceCameras[index].cameraLevel = "";
        // this.levelList[index] = "";
        return;
      }
      //shelvesList 它是里面包含了shelvesSn 和 levels的数组
      //selectedShelf:选中货架编号
      let selectedShelf = this.shelvesList.filter(
        item => item.shelvesSn === val
      );

      if (selectedShelf && selectedShelf.length > 0) {
        //货架层数组
        // this.levelList[index] =
        //   (selectedShelf.length > 0 && selectedShelf[0].levels) || [];
        //默认层
        this.deviceCameras[index].levelList = selectedShelf[0].levels
        this.deviceCameras[index].cameraLevel = this.levelList[0] > 0 ? 1 : "";
      }
    },
    refreshCamera(cameraSn, imgDeviceSn, cameraLevel, shelvesSn) {
      this.$api.device
        .bindCamera({
          cameraSn: cameraSn,
          imgDeviceSn: imgDeviceSn,
          level: cameraLevel,
          shelvesSn: shelvesSn
        })
        .then(({ code, msg }) => {
          if (code === 0) {
            this.$message({
              message: this.$t("lang.updateSuccess"),
              type: "success"
            });
          } else {
            return false;
          }
        });
    },
    deleteCamera(cameraSn, imgDeviceSn,index) {
      //cameraSn	摄像头编号
      //imageSn	图像采集设备编号
      this.$api.device
        .deleteCameraDetail({ cameraSn: cameraSn, imageSn: imgDeviceSn })
        .then(({ code, msg }) => {
          if (code === 0) {
            this.$message({
              message: msg,
              type: "success"
            });
            this.deviceCameras.splice(index,1)//删除单行,这是最简单的方法,
           // 而不是调用父组件的刷新方法,直接用index的方式就好了
          }
        });
    },
    //关闭
    handleClose() {
      this.$parent.handleCloseCameraDialog();
    },
    //关闭按钮
    handleOk() {
      this.$parent.handleCloseCameraDialog();
    }
  }
};
</script>
我的难点在于

不知道将对应的层数怎样将它展示出来 这个后端给的结构是这样的 思路:定义一个选中的变量,然后里面从this.shelvesList.filter过滤掉,里面的shelvesSn 就是change里面的val,然后让 v-for里面的this.deviceCameras[index].levelList = selectedShelf[0].levels 意思就是绑定的=选中的层数

在这里插入图片描述
在这里插入图片描述
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2024-01-18,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 效果图
  • 源代码
  • 我的难点在于
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档