ZZJ
2022-07-15 a3f357e8a60443b74b64c7479113c68eb35ce1f5
src/pages/cameraAccess/components/TimeSlider.vue
@@ -79,6 +79,7 @@
        { day: 6, time_range: [{ start: "00:00", end: "24:00" }] },
        { day: 7, time_range: [{ start: "00:00", end: "24:00" }] },
      ],
      isAdding: false,
    };
  },
  mounted() {
@@ -88,16 +89,53 @@
    handleTabsEdit(tabId, action) {
      let tabs = this.VideoManageData.TimeRules;
      if (action === "add") {
        let newRule = {
          id: "",
          name: "时间段" + this.VideoManageData.TimeRules.length,
          time_rule: this.allDay,
        };
        this.updateTimeRule(newRule);
        if (this.isAdding) {
          return;
        } else {
          this.isAdding = true;
          let name = "时间段1";
          for (
            let index = this.VideoManageData.TimeRules.length;
            index > 0;
            index--
          ) {
            const sliceIndex =
              this.VideoManageData.TimeRules[index - 1].name.indexOf("时间段");
            if (sliceIndex != -1) {
              const number = +this.VideoManageData.TimeRules[
                index - 1
              ].name.slice(sliceIndex + 3);
              console.log(number);
              console.log(typeof number);
              console.log(typeof NaN);
              if (
                typeof number === "number" &&
                !Number.isNaN(number) &&
                number != 0
              ) {
                console.log("--------------");
                name = "时间段" + (number + 1);
                break;
              }
            }
          }
          let newRule = {
            id: "",
            name: name,
            time_rule: this.allDay,
          };
          this.updateTimeRule(newRule);
        }
      }
      if (action === "remove") {
        console.log();
        if (this.VideoManageData.TimeRules.length == 1) {
          this.$notify({
            title: "警告",
@@ -144,12 +182,24 @@
      console.log("时间组件宽度:", timeSlideWidth);
    },
    updateTimeRule(rule) {
      saveTimeRule(rule).then((rsp) => {
        if (rsp && rsp.success) {
          this.VideoManageData.getTimeRule();
          this.activeTab = rsp.data.id;
        }
      });
      saveTimeRule(rule)
        .then(async (rsp) => {
          if (rsp && rsp.success) {
            await this.VideoManageData.getTimeRule();
            this.isAdding = false;
            this.$nextTick(() => {
              this.activeTab =
                this.VideoManageData.TimeRules[
                  this.VideoManageData.TimeRuleSum - 1
                ].id;
            });
          } else {
            this.isAdding = false;
          }
        })
        .catch(() => {
          this.isAdding = false;
        });
    },
    tabClick(item) {
      if (this.activeTab === item.id) {
@@ -177,7 +227,7 @@
  },
};
</script>
<style lang='scss'>
<style lang="scss">
.sub-time-box {
  padding-right: 30px;
  position: relative;
@@ -254,4 +304,4 @@
  //   z-index: 1;
  // }
}
</style>
</style>