Преглед изворни кода

1、调整直播时间不给修改

yys пре 3 недеља
родитељ
комит
5bada7a8af
1 измењених фајлова са 39 додато и 42 уклоњено
  1. 39 42
      src/views/live/live/index.vue

+ 39 - 42
src/views/live/live/index.vue

@@ -470,16 +470,10 @@
           <el-date-picker
             size="small"
             v-model="form.startTime"
-            @change="timeChange"
+            @change="onStartTimeChange"
             type="datetime"
             format="yyyy-MM-dd HH:mm:ss"
             value-format="yyyy-MM-dd HH:mm:ss"
-            :picker-options="{
-              timePickerOptions: {
-                selectableRange: '00:00:00 - 23:59:59',
-                format: 'HH:mm:ss',
-              },
-            }"
             placeholder="选择开始时间"
           >
           </el-date-picker>
@@ -495,13 +489,8 @@
             type="datetime"
             format="yyyy-MM-dd HH:mm:ss"
             value-format="yyyy-MM-dd HH:mm:ss"
-            :picker-options="{
-              timePickerOptions: {
-                selectableRange: '00:00:00 - 23:59:59',
-                format: 'HH:mm:ss',
-              },
-            }"
-            placeholder="视屏播放结束"
+            :disabled="form.liveType == 2"
+            :placeholder="form.liveType == 2 ? '根据视频时长自动计算' : '选择结束时间'"
           >
           </el-date-picker>
         </el-form-item>
@@ -830,30 +819,31 @@ export default {
   watch: {
     "form.startTime": {
       handler(newVal) {
-        // 1. 若 startTime 为空,直接返回(避免无效处理)
-        if (!newVal) return;
+        if (!newVal || typeof newVal !== "string") return;
+        // 已是 :01 结尾则不再回写,避免干扰日期选择器导致无法改时间
+        if (/:\d{2}$/.test(newVal) && newVal.slice(-2) === "01") return;
 
-        // 2. 将字符串时间转为 Date 对象(处理 "yyyy-MM-dd HH:mm:ss" 格式)
-        const timeObj = new Date(newVal);
-        // 兼容时间解析失败的情况(如格式错误)
+        const normalized = newVal.replace("T", " ").substring(0, 19);
+        const timeObj = new Date(normalized.replace(/-/g, "/"));
         if (isNaN(timeObj.getTime())) return;
 
-        // 3. 强制将秒数设为 1 并补零(即 01 秒)
-        timeObj.setSeconds(1); // 固定秒数为 1
-        const formattedSeconds = this.pad(timeObj.getSeconds()); // 补零为 "01"
-
-        // 4. 重新拼接完整的时间字符串(保持原格式:yyyy-MM-dd HH:mm:ss)
-        const year = timeObj.getFullYear();
-        const month = this.pad(timeObj.getMonth() + 1); // 月份从 0 开始,需 +1
-        const day = this.pad(timeObj.getDate());
-        const hours = this.pad(timeObj.getHours());
-        const minutes = this.pad(timeObj.getMinutes());
-
-        // 5. 更新 form.startTime,完成格式强制修正
-        this.form.startTime = `${year}-${month}-${day} ${hours}:${minutes}:${formattedSeconds}`;
+        timeObj.setSeconds(1);
+        const formatted = `${timeObj.getFullYear()}-${this.pad(
+          timeObj.getMonth() + 1
+        )}-${this.pad(timeObj.getDate())} ${this.pad(
+          timeObj.getHours()
+        )}:${this.pad(timeObj.getMinutes())}:${this.pad(timeObj.getSeconds())}`;
+        if (formatted !== newVal) {
+          this.form.startTime = formatted;
+        }
       },
-      immediate: true, // 初始化时立即执行一次(确保初始值也符合格式)
-      deep: false, // startTime 是字符串,无需深度监听
+      immediate: true,
+    },
+    "form.liveType"(val) {
+      // 切到录播时,若已有开始时间与时长则重算结束时间
+      if (val == 2) {
+        this.timeChange();
+      }
     },
   },
   methods: {
@@ -943,11 +933,16 @@ export default {
     },
     handleVideoDuration(duration) {
       this.form.duration = duration;
+      this.timeChange();
     },
     handleVideoChange(videoUrl, lineOne) {
       this.videoUrl = videoUrl;
       this.form.videoUrl = videoUrl;
     },
+    /** 开始时间变更:录播时按视频时长重算结束时间 */
+    onStartTimeChange() {
+      this.timeChange();
+    },
 
     showLivingUrl(row) {
       this.serverName = "";
@@ -1071,16 +1066,18 @@ export default {
       this.timeChange();
     },
     timeChange() {
-      if (!this.form.startTime) return;
-      if (!this.form.duration) return;
-      const startDateTime = new Date(this.form.startTime);
-      // 将视频时长(秒)加到开始时间
+      // 仅录播根据视频时长自动计算结束时间
+      if (this.form.liveType != 2) return;
+      if (!this.form.startTime || !this.form.duration) return;
+      const normalized = String(this.form.startTime)
+        .replace("T", " ")
+        .substring(0, 19);
+      const startDateTime = new Date(normalized.replace(/-/g, "/"));
+      if (isNaN(startDateTime.getTime())) return;
       const endDateTime = new Date(
-        startDateTime.getTime() + this.form.duration * 1000
-      ); // 毫秒为单位
-      // 格式化为年月日 时分秒
+        startDateTime.getTime() + Number(this.form.duration) * 1000
+      );
       this.form.finishTime = this.formatDate(endDateTime);
-      this.$forceUpdate();
     },
     // 将秒数转换为时分秒
     secondsToTime(seconds) {