zhangzengfei
2022-08-23 e37e45cfe1123928dba5d9c5a427b0ee497b7ad6
src/views/equipmentManagement/equipmentList/components/FormList.vue
@@ -23,12 +23,7 @@
        <div class="cluster">
          所属集群
          <el-select v-model="cluster" placeholder="请选择">
            <el-option
              v-for="item in clusterArr"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            <el-option v-for="item in clusterArr" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </div>
@@ -41,12 +36,8 @@
    </div>
    <div class="btns">
      <div class="button add" @click="isShowAdd = true">
        <span>+</span>添加设备
      </div>
      <div class="button export">
        <span class="iconfont">&#xe614;</span>导出
      </div>
      <div class="button add" @click="isShowAdd = true"><span>+</span>添加设备</div>
      <div class="button export" @click="exportFile"><span class="iconfont">&#xe614;</span>导出</div>
    </div>
    <div class="table-area">
@@ -59,28 +50,12 @@
        :default-sort="{ prop: 'createTime', order: 'descending' }"
        :stripe="true"
      >
        <el-table-column label="序号" width="48" class-name="index">
          <template slot-scope="scope">{{
            scope.$index + 1 + (page - 1) * size
          }}</template>
        <el-table-column label="序号" width="80" class-name="index">
          <template slot-scope="scope">{{ scope.$index + 1 + (page - 1) * size }}</template>
        </el-table-column>
        <el-table-column
          prop="devId"
          label="设备ID"
          min-width="180"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="devName"
          label="设备名称"
          min-width="140"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="devIp"
          label="IP地址"
          min-width="150"
        ></el-table-column>
        <el-table-column prop="devId" label="设备ID" min-width="210" show-overflow-tooltip></el-table-column>
        <el-table-column prop="devName" label="设备名称" min-width="140" show-overflow-tooltip></el-table-column>
        <el-table-column prop="devIp" label="IP地址" min-width="150"></el-table-column>
        <el-table-column label="安装时间" min-width="159">
          <template slot-scope="scope">
            <div v-if="scope.row.installTime.length > 1">
@@ -90,7 +65,7 @@
            <div v-else>--</div>
          </template>
        </el-table-column>
        <el-table-column label="首次使用时间" min-width="159">
        <!-- <el-table-column label="首次使用时间" min-width="159">
          <template slot-scope="scope">
            <div v-if="scope.row.firstUseTime.length > 1">
              <div>{{ scope.row.firstUseTime[0] }}</div>
@@ -98,10 +73,10 @@
            </div>
            <div v-else>--</div>
          </template>
        </el-table-column>
        </el-table-column> -->
        <el-table-column label="所属集群" show-overflow-tooltip min-width="154">
          <template> -- </template>
          <template slot-scope="scope"> {{ scope.row.clusterName }} </template>
        </el-table-column>
        <el-table-column label="状态" min-width="70">
@@ -114,28 +89,47 @@
        <el-table-column label="操作" min-width="180">
          <template slot-scope="scope">
            <!-- 加入 -->
            <span class="iconfont option" @click="joinCluster(scope.row)"
              >&#xe640;</span
            >
            <el-tooltip content="加入集群" placement="top" v-if="!scope.row.clusterId">
              <span
                class="iconfont option"
                @click="joinCluster(scope.row)"
                :class="{ disable: scope.row.isOnline != 1 }"
                >&#xe640;</span
              >
            </el-tooltip>
            <!-- 退出 -->
            <span
              class="iconfont option"
              @click="quitCluster(scope.row)"
              v-if="false"
              >&#xe63c;</span
            >
            <el-tooltip content="退出集群" placement="top" v-else>
              <span
                class="iconfont option"
                @click="quitCluster(scope.row)"
                :class="{ disable: scope.row.isOnline != 1 }"
                >&#xe63c;</span
              >
            </el-tooltip>
            <!-- 算法详情 -->
            <span class="iconfont option" @click="algorithmDetail(scope.row)"
              >&#xe621;</span
            >
            <el-tooltip content="应用详情" placement="top">
              <span
                class="iconfont option"
                :class="{ disable: scope.row.isOnline != 1 }"
                @click="algorithmDetail(scope.row)"
                >&#xe621;</span
              >
            </el-tooltip>
            <!-- 设备详情 -->
            <span class="iconfont option" @click="checkDetail(scope.row)"
              >&#xe619;</span
            >
            <el-tooltip content="设备详情" placement="top">
              <span
                class="iconfont option"
                :class="{ disable: scope.row.isOnline != 1 }"
                @click="checkDetail(scope.row)"
                >&#xe619;</span
              >
            </el-tooltip>
            <!-- 解绑 -->
            <span class="iconfont option" @click="Untying(scope.row)"
              >&#xe617;</span
            >
            <el-tooltip content="解除绑定" placement="top">
              <span class="iconfont option" @click="Untying(scope.row)" :class="{ disable: scope.row.isOnline != 1 }"
                >&#xe617;</span
              >
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
@@ -154,51 +148,41 @@
    </div>
    <!-- 解绑弹窗 -->
    <UnbindBox
      @close="closeUnbindBox"
      v-if="isShowUnbind"
      :id="unbindId"
      @reflash="reflash"
    ></UnbindBox>
    <UnbindBox @close="closeUnbindBox" v-if="isShowUnbind" :id="unbindId" @reflash="reflash"></UnbindBox>
    <!-- 添加设备弹窗 -->
    <AddBox @close="closeAddBox" v-if="isShowAdd"></AddBox>
    <!-- 退出集群弹窗 -->
    <QuitClusterBox
      :equipment="activeEquipment"
      v-if="showQuit"
      @close="showQuit = false"
    ></QuitClusterBox>
    <QuitClusterBox :equipment="activeEquipment" v-if="showQuit" @close="showQuit = false"></QuitClusterBox>
    <!-- 加入集群弹窗 -->
    <JoinClusterBox
      :equipment="activeEquipment"
      v-if="showJoin"
      @close="showJoin = false"
    ></JoinClusterBox>
    <JoinClusterBox :equipment="activeEquipment" v-if="showJoin" @close="showJoin = false"></JoinClusterBox>
  </div>
</template>
<script>
import { findDevList } from "@/api/device";
import AddBox from "@/views/equipmentManagement/equipmentList/components/AddBox";
import UnbindBox from "@/views/equipmentManagement/equipmentDetail/components/UnbindBox";
import QuitClusterBox from "@/views/equipmentManagement/equipmentList/components/QuitClusterBox";
import JoinClusterBox from "@/views/equipmentManagement/equipmentList/components/JoinClusterBox";
import { findDevList, findClustersBySearch, exportDevListExcel } from "@/api/device"
import AddBox from "@/views/equipmentManagement/equipmentList/components/AddBox"
import UnbindBox from "@/views/equipmentManagement/equipmentDetail/components/UnbindBox"
import QuitClusterBox from "@/views/equipmentManagement/equipmentList/components/QuitClusterBox"
import JoinClusterBox from "@/views/equipmentManagement/equipmentList/components/JoinClusterBox"
import bus from "@/plugin/bus"
export default {
  components: {
    AddBox,
    UnbindBox,
    QuitClusterBox,
    JoinClusterBox,
    JoinClusterBox
  },
  created() {
    this.getCluster()
  },
  data() {
    return {
      searchTime: [
        this.$moment().format("YYYY-MM-DD 00:00:00"),
        this.$moment().format("YYYY-MM-DD HH:mm:ss"),
      ], //搜索时间
      searchTime: [], //搜索时间
      page: 1,
      size: 10, //分页相关
      inputText: "", //输入框内容
@@ -207,181 +191,225 @@
      isShowAdd: false, //是否展示新增弹窗
      isShowUnbind: false, //是否展示解绑弹窗
      unbindId: "",
      clusterArr: [
        {
          value: 0,
          label: "集群1",
        },
        {
          value: 1,
          label: "集群2",
        },
      ], //所属集群下拉框
      clusterArr: [], //所属集群下拉框
      cluster: null, //选中的集群类型
      showQuit: false, //展示退出集群的弹窗
      showJoin: false, //展示加入集群的弹窗
      activeEquipment: null, //处理中的设备
    };
      activeEquipment: null //处理中的设备
    }
  },
  methods: {
    async getCluster() {
      const res = await findClustersBySearch({
        InputText: "",
        Page: 1,
        Size: 10000,
        userId: JSON.parse(sessionStorage.getItem("userInfo")).id
      })
      if (res && res.success) {
        res.data.list.forEach((item) => {
          this.clusterArr.push({
            label: item.clusterName,
            value: item.clusterId
          })
        })
      }
    },
    // 跳到设备详情
    checkDetail(row) {
      if (row.isOnline != 1) {
        return
      }
      this.$router.push({
        path: "/equipmentDetail",
        query: {
          id: row.devId,
          ip: row.devIp,
          port: row.serverPort,
          ndid: row.id,
        },
      });
          id: row.devId
        }
      })
    },
    // 跳到算法详情
    algorithmDetail(row) {
      if (row.isOnline != 1) {
        return
      }
      this.$router.push({
        path: "/algorithmDetail",
        query: {
          id: row.devId,
          ip: row.devIp,
          port: row.serverPort,
        },
      });
          id: row.devId
        }
      })
    },
    // 查询列表
    searchingBtn() {
      let param = {
        page: this.page,
        size: this.size,
        // startTime: this.searchTime[0],
        // endTime: this.searchTime[1],
        inputText: this.inputText,
      };
      let param = {}
      if (!this.searchTime) {
        param = {
          page: this.page,
          size: this.size,
          startTime: "",
          endTime: "",
          clusterId: this.cluster,
          inputText: this.inputText
        }
      } else {
        param = {
          page: this.page,
          size: this.size,
          startTime: this.searchTime[0],
          endTime: this.searchTime[1],
          clusterId: this.cluster,
          inputText: this.inputText
        }
      }
      findDevList(param)
        .then((res) => {
          this.dataList = res.data.list;
          this.dataList = res.data.list
          //时间分行显示
          this.dataList.forEach((item) => {
            item.installTime = item.installTime.split(" ");
            item.firstUseTime = item.firstUseTime.split(" ");
          });
          this.total = res.data.total;
            item.installTime = item.installTime.split(" ")
            item.firstUseTime = item.firstUseTime.split(" ")
          })
          this.total = res.data.total
          if (res.data.total <= this.size) {
            this.page = 1;
            this.page = 1
          }
          bus.$emit("refleshNode", this.dataList)
        })
        .catch((err) => {
          console.log(err);
        });
          console.log(err)
        })
    },
    //分页功能
    handleSizeChange(size) {
      this.size = size;
      this.searchingBtn();
      this.size = size
      this.searchingBtn()
    },
    //分页功能
    refrash(page) {
      this.page = page;
      this.searchingBtn();
      this.page = page
      this.searchingBtn()
    },
    //解绑按钮
    Untying(row) {
      console.log(row);
      this.unbindId = row.id;
      this.isShowUnbind = true;
      /*  this.$confirm(
        "解绑后该设备将从设备列表中移除,是否确认操作?",
        "解绑提示",
        {
          type: "warning",
          center: true,
        }
      )
        .then(() => {
          unbind({ ids: [row.id] })
            .then(() => {
              this.$notify({
                type: "success",
                message: "解绑成功",
                duration: 2500,
                offset: 57,
              });
              this.searchingBtn();
            })
            .catch(() => {
              this.$notify({
                type: "error",
                message: "解绑失败,请联系客服",
                duration: 2500,
                offset: 57,
              });
            });
        })
        .catch((e) => {
          console.log(e);
        }); */
      if (row.isOnline != 1) {
        return
      }
      this.unbindId = row.devId
      this.isShowUnbind = true
    },
    //获得默认时间
    getDateInit() {
      // 要求 默认一个月
      const end = new Date();
      const start = new Date();
      const nowDate = new Date();
      nowDate.setHours(0);
      nowDate.setMinutes(0);
      nowDate.setSeconds(0);
      nowDate.setMilliseconds(0);
      start.setTime(nowDate.getTime() - 3600 * 1000 * 24 * 30);
      end.setTime(nowDate.getTime() + 3600 * 1000 * 24 - 1);
      return [
        this.$moment(start).format("YYYY-MM-DD HH:mm:ss"),
        this.$moment(end).format("YYYY-MM-DD HH:mm:ss"),
      ];
      const end = new Date()
      const start = new Date()
      const nowDate = new Date()
      nowDate.setHours(0)
      nowDate.setMinutes(0)
      nowDate.setSeconds(0)
      nowDate.setMilliseconds(0)
      start.setTime(nowDate.getTime() - 3600 * 1000 * 24 * 30)
      end.setTime(nowDate.getTime() + 3600 * 1000 * 24 - 1)
      return [this.$moment(start).format("YYYY-MM-DD HH:mm:ss"), this.$moment(end).format("YYYY-MM-DD HH:mm:ss")]
    },
    //关闭新增弹窗
    closeAddBox() {
      this.isShowAdd = false;
      this.isShowAdd = false
      this.searchingBtn()
    },
    // 关闭解绑弹窗
    closeUnbindBox() {
      this.isShowUnbind = false;
      this.isShowUnbind = false
    },
    //解绑成功回调
    reflash() {
      this.isShowUnbind = false;
      this.searchingBtn();
      this.isShowUnbind = false
      this.searchingBtn()
    },
    clearSearch() {
      this.searchTime = this.getDateInit();
      this.inputText = "";
      this.searchingBtn();
      this.searchTime = this.getDateInit()
      this.inputText = ""
      this.cluster = ""
      this.searchingBtn()
    },
    //退出集群
    quitCluster(equipment) {
      this.activeEquipment = equipment;
      this.showQuit = true;
      if (equipment.isOnline != 1) {
        return
      }
      this.activeEquipment = equipment
      this.showQuit = true
    },
    //加入集群
    joinCluster(equipment) {
      this.activeEquipment = equipment;
      this.showJoin = true;
      if (equipment.isOnline != 1) {
        return
      }
      this.activeEquipment = equipment
      this.showJoin = true
    },
    //导出列表文件
    async exportFile() {
      let param = {}
      if (!this.searchTime) {
        param = {
          page: this.page,
          size: this.size,
          startTime: "",
          endTime: "",
          clusterId: this.cluster,
          inputText: this.inputText
        }
      } else {
        param = {
          page: this.page,
          size: this.size,
          startTime: this.searchTime[0],
          endTime: this.searchTime[1],
          clusterId: this.cluster,
          inputText: this.inputText
        }
      }
      const result = await exportDevListExcel(param)
      var blob = new Blob([result.body.data], {
          type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"
        }),
        Temp = document.createElement("a")
      Temp.href = window.URL.createObjectURL(blob)
      Temp.download = window.decodeURI(result.fileName)
      Temp.setAttribute("download", result.fileName)
      document.body.appendChild(Temp)
      Temp.click()
      document.body.removeChild(Temp)
      window.URL.revokeObjectURL(Temp)
    }
  },
  mounted() {
    this.searchTime = this.getDateInit();
    this.searchingBtn();
  },
};
    this.searchingBtn()
  }
}
</script>
<style scoped lang="scss">
@@ -389,9 +417,10 @@
  .search {
    display: flex;
    justify-content: space-between;
    padding: 60px 0 30px 0;
    padding: 20px 0 30px 0;
    font-size: 14px;
    border-bottom: 1px solid #e9ebee;
    background-color: #fff;
    .left,
    .right,
@@ -400,6 +429,26 @@
    .cluster {
      display: flex;
      align-items: center;
    }
    .cluster {
      .el-select {
        width: 190px;
        height: 40px;
        line-height: 40px;
        ::v-deep input {
          height: 40px;
        }
        .el-icon-arrow-up {
          line-height: 40px;
        }
        ::v-deep .el-icon-arrow-up {
          height: 40px;
        }
      }
    }
    .id .el-input ::v-deep {
@@ -425,7 +474,7 @@
    }
    .el-input ::v-deep {
      width: 280px;
      width: 270px;
      height: 40px;
      margin-left: 10px;
      margin-right: 20px;
@@ -443,7 +492,7 @@
    }
    .el-date-editor {
      width: 318px;
      width: 340px;
      height: 40px;
      margin-left: 10px;
      margin-right: 20px;
@@ -459,7 +508,7 @@
    }
    .searchBtn {
      width: 120px;
      width: 110px;
      height: 40px;
      line-height: 40px;
      text-align: center;
@@ -469,13 +518,17 @@
    }
    .resetBtn {
      width: 120px;
      width: 110px;
      height: 40px;
      line-height: 40px;
      text-align: center;
      color: #0065ff;
      border: 1px solid #0065ff;
    }
  }
  .table-area {
    min-height: 600px;
  }
  .btns {
@@ -562,12 +615,17 @@
      font-size: 24px;
      color: rgb(0, 101, 255);
      cursor: pointer;
      &.disable {
        color: #666;
        cursor: default;
      }
    }
  }
  .el-pagination ::v-deep {
    margin-top: 30px;
    text-align: center;
    text-align: right;
    height: 24px;
    .el-pagination__sizes {
      margin-right: 0;
@@ -601,11 +659,21 @@
        border-color: #0065ff;
      }
    }
    .el-pagination__jump {
      margin-left: 12px;
      .el-pagination__editor {
        width: 37px;
        input {
          width: 32px;
        }
      }
    }
  }
}
</style>
<style >
<style>
.el-date-table td.start-date span,
.el-date-table td.end-date span {
  background-color: #0065ff;
@@ -620,4 +688,4 @@
  color: #0065ff;
  border-color: #0065ff;
}
</style>
</style>