Pārlūkot izejas kodu

课程模板-默认app

sgw 1 dienu atpakaļ
vecāks
revīzija
3faddb9e6d
2 mainītis faili ar 147 papildinājumiem un 5 dzēšanām
  1. 70 2
      src/views/qw/sopTemp/deptIndex.vue
  2. 77 3
      src/views/qw/sopTemp/myIndex.vue

+ 70 - 2
src/views/qw/sopTemp/deptIndex.vue

@@ -283,6 +283,17 @@
             </el-radio>
           </el-radio-group>
         </el-form-item>
+        <el-form-item label="是否开启app看课" v-if="showAppCourseToggle && form.sendType == 11 && (form.id === null || form.id === undefined)">
+          <el-radio-group v-model="form.openAppCourse">
+            <el-radio
+              v-for="dict in openOfficialOptions"
+              :key="dict.dictValue"
+              :label="dict.dictValue"
+            >{{ dict.dictLabel }}
+            </el-radio>
+          </el-radio-group>
+        </el-form-item>
+
         <el-form-item label="内容" prop="modeContent">
           <el-input v-model="form.modeContent" placeholder="请输入文字内容"  type="textarea" :rows="3"/>
         </el-form-item>
@@ -465,7 +476,8 @@ export default {
       // 状态字典
       statusOptions: [],
       openOfficialOptions: [],
-
+      // 控制“是否开启app看课”是否显示
+      showAppCourseToggle: false,
       shareOptions: {
         title: '分享模板',
         open: false,
@@ -580,6 +592,22 @@ export default {
     getCompanyList().then(response => {
       this.companys = response.data;
     });
+
+    //获取 app 看课配置
+    this.getOpenAppCourseStatus();
+  },
+  watch: {
+    //监听 openOfficial 和 openAppCourse 的变化,实现选项互斥
+    'form.openOfficial'(newVal) {
+      if (this.showAppCourseToggle && newVal === '1') {
+        this.$set(this.form, 'openAppCourse', '0');
+      }
+    },
+    'form.openAppCourse'(newVal) {
+      if (this.showAppCourseToggle && newVal === '1') {
+        this.$set(this.form, 'openOfficial', '0');
+      }
+    }
   },
   methods: {
 
@@ -818,6 +846,13 @@ export default {
         if (command == 1) {
           this.title = "修改";
         }
+
+        if (this.showAppCourseToggle && this.form.sendType === 11) {
+          // 如果两个都是 "1",强制修正(理论上不会发生)
+          if (this.form.openOfficial === '1' && this.form.openAppCourse === '1') {
+            this.form.openAppCourse = '0';
+          }
+        }
         this.form = response.data;
         this.open = true;
       });
@@ -827,7 +862,23 @@ export default {
       delete this.form.rules
       this.$refs["form"].validate(valid => {
         if (valid) {
+          // 【新增校验】当 view_course_app=1 时,openOfficial 和 openAppCourse 必须二选一
+          if (this.showAppCourseToggle && this.form.sendType === 11 && !this.form.id) {
+            const official = this.form.openOfficial;
+            const appCourse = this.form.openAppCourse;
+
+            // 至少一个为 "1"
+            if (official !== '1' && appCourse !== '1') {
+              this.$message.error("请至少开启【官方群发】或【APP看课】中的一项!");
+              return;
+            }
 
+            // 不能同时为 "1"(虽然 watch 已处理,但以防绕过)
+            if (official === '1' && appCourse === '1') {
+              this.$message.error("【官方群发】与【APP看课】不能同时开启,请选择其一!");
+              return;
+            }
+          }
           if (this.command != 2 && this.form.id == null && this.form.sendType == 11){
 
             const hasEmptyFields = this.form.timeList.some(item => {
@@ -938,7 +989,24 @@ export default {
         let len = old - val;
         this.form.timeList.splice(Math.max(this.form.timeList.length - len, 0), len);
       }
-    }
+    },
+    getOpenAppCourseStatus(){
+      getConfigByKey("courseAppConfig.config").then(res => {
+        if (res.code === 200 && res.data?.configValue) {
+          try {
+            const config = JSON.parse(res.data.configValue);
+            this.showAppCourseToggle = config.view_course_app === 1;
+          } catch (e) {
+            console.error("解析 courseAppConfig.config 失败", e);
+            this.showAppCourseToggle = false;
+          }
+        } else {
+          this.showAppCourseToggle = false;
+        }
+      }).catch(() => {
+        this.showAppCourseToggle = false;
+      });
+    },
   }
 };
 </script>

+ 77 - 3
src/views/qw/sopTemp/myIndex.vue

@@ -266,6 +266,17 @@
             </el-radio>
           </el-radio-group>
         </el-form-item>
+        <el-form-item label="是否开启app看课" v-if="showAppCourseToggle && form.sendType == 11 && (form.id === null || form.id === undefined)">
+          <el-radio-group v-model="form.openAppCourse">
+            <el-radio
+              v-for="dict in openOfficialOptions"
+              :key="dict.dictValue"
+              :label="dict.dictValue"
+            >{{ dict.dictLabel }}
+            </el-radio>
+          </el-radio-group>
+        </el-form-item>
+
         <el-form-item label="内容" prop="modeContent">
           <el-input v-model="form.modeContent" placeholder="请输入文字内容"  type="textarea" :rows="3"/>
         </el-form-item>
@@ -399,7 +410,7 @@ import {
   redList,
   shareSopTemp,
   updateRedPackage,
-  updateTemp, listSopTempMyList
+  updateTemp, listSopTempMyList, getConfigByKey
 } from "../../../api/qw/sopTemp";
 import { getCompanyList, listCompany } from '@/api/company/company'
 import {courseList, getRoles} from "@/api/qw/sop";
@@ -447,7 +458,8 @@ export default {
       // 状态字典
       statusOptions: [],
       openOfficialOptions: [],
-
+      // 控制“是否开启app看课”是否显示
+      showAppCourseToggle: false,
       shareOptions: {
         title: '分享模板',
         open: false,
@@ -548,6 +560,23 @@ export default {
     getCompanyList().then(response => {
       this.companys = response.data;
     });
+
+    //获取 app 看课配置
+    this.getOpenAppCourseStatus();
+  },
+
+  watch: {
+    //监听 openOfficial 和 openAppCourse 的变化,实现选项互斥
+    'form.openOfficial'(newVal) {
+      if (this.showAppCourseToggle && newVal === '1') {
+        this.$set(this.form, 'openAppCourse', '0');
+      }
+    },
+    'form.openAppCourse'(newVal) {
+      if (this.showAppCourseToggle && newVal === '1') {
+        this.$set(this.form, 'openOfficial', '0');
+      }
+    }
   },
   methods: {
 
@@ -714,7 +743,16 @@ export default {
         if (command == 1) {
           this.title = "修改";
         }
+
         this.form = response.data;
+
+        if (this.showAppCourseToggle && this.form.sendType === 11) {
+          // 如果两个都是 "1",强制修正(理论上不会发生)
+          if (this.form.openOfficial === '1' && this.form.openAppCourse === '1') {
+            this.form.openAppCourse = '0';
+          }
+        }
+
         this.open = true;
       });
     },
@@ -724,6 +762,24 @@ export default {
       this.$refs["form"].validate(valid => {
         if (valid) {
 
+          // 【新增校验】当 view_course_app=1 时,openOfficial 和 openAppCourse 必须二选一
+          if (this.showAppCourseToggle && this.form.sendType === 11 && !this.form.id) {
+            const official = this.form.openOfficial;
+            const appCourse = this.form.openAppCourse;
+
+            // 至少一个为 "1"
+            if (official !== '1' && appCourse !== '1') {
+              this.$message.error("请至少开启【官方群发】或【APP看课】中的一项!");
+              return;
+            }
+
+            // 不能同时为 "1"(虽然 watch 已处理,但以防绕过)
+            if (official === '1' && appCourse === '1') {
+              this.$message.error("【官方群发】与【APP看课】不能同时开启,请选择其一!");
+              return;
+            }
+          }
+
           if (this.command != 2 && this.form.id == null && this.form.sendType == 11){
 
             const hasEmptyFields = this.form.timeList.some(item => {
@@ -834,7 +890,25 @@ export default {
         let len = old - val;
         this.form.timeList.splice(Math.max(this.form.timeList.length - len, 0), len);
       }
-    }
+    },
+
+    getOpenAppCourseStatus(){
+      getConfigByKey("courseAppConfig.config").then(res => {
+        if (res.code === 200 && res.data?.configValue) {
+          try {
+            const config = JSON.parse(res.data.configValue);
+            this.showAppCourseToggle = config.view_course_app === 1;
+          } catch (e) {
+            console.error("解析 courseAppConfig.config 失败", e);
+            this.showAppCourseToggle = false;
+          }
+        } else {
+          this.showAppCourseToggle = false;
+        }
+      }).catch(() => {
+        this.showAppCourseToggle = false;
+      });
+    },
   }
 };
 </script>