Browse Source

布置作业时候,乐器和当前班级和学生进行验证

黄琪勇 9 months ago
parent
commit
237e7bfe5a

+ 42 - 0
src/components/TheTipDialog/index.module.less

@@ -0,0 +1,42 @@
+.theTipDialog {
+  width: 28vw;
+  .tipCon {
+    display: flex;
+    flex-direction: column;
+    .tipBox {
+      width: 100%;
+      :global {
+        .n-scrollbar {
+          max-height: 40vh;
+          .n-scrollbar-content {
+            padding: 0 30px;
+          }
+        }
+      }
+    }
+    .tip {
+      font-weight: 400;
+      font-size: 20px;
+      color: #777777;
+      line-height: 28px;
+      > div {
+        margin-bottom: 16px;
+        &:last-child {
+          margin-bottom: 0;
+        }
+      }
+    }
+    .tipBtnBox {
+      padding: 30px 0;
+      text-align: center;
+      :global {
+        .n-button {
+          --n-padding: 0 42px !important;
+          & + .n-button {
+            margin-left: 20px;
+          }
+        }
+      }
+    }
+  }
+}

+ 67 - 0
src/components/TheTipDialog/index.tsx

@@ -0,0 +1,67 @@
+import { NButton, NScrollbar, NModal } from 'naive-ui';
+import { defineComponent } from 'vue';
+import styles from './index.module.less';
+
+export default defineComponent({
+  name: 'the-tip-dialog',
+  props: {
+    show: Boolean,
+    title: {
+      type: String,
+      default: '提示'
+    },
+    cancelButtonText: {
+      type: String,
+      default: '取消'
+    },
+    confirmButtonText: {
+      type: String,
+      default: '确定'
+    },
+    cancelBtn: {
+      type: Boolean,
+      default: true
+    },
+    confirmBtn: {
+      type: Boolean,
+      default: true
+    },
+    content: {
+      type: String,
+      default: ''
+    }
+  },
+  emits: ['close', 'confirm'],
+  setup(props, { emit }) {
+    return () => (
+      <NModal
+        class={['modalTitle', styles.theTipDialog]}
+        on-close={() => {
+          emit('close');
+        }}
+        show={props.show}
+        preset="card"
+        title={props.title}>
+        <div class={styles.tipCon}>
+          <div class={styles.tipBox}>
+            <NScrollbar>
+              <div class={styles.tip} v-html={props.content}></div>
+            </NScrollbar>
+          </div>
+          <div class={styles.tipBtnBox}>
+            {props.cancelBtn && (
+              <NButton round onClick={() => emit('close')}>
+                {props.cancelButtonText}
+              </NButton>
+            )}
+            {props.confirmBtn && (
+              <NButton type="primary" round onClick={() => emit('confirm')}>
+                {props.confirmButtonText}
+              </NButton>
+            )}
+          </div>
+        </div>
+      </NModal>
+    );
+  }
+});

+ 69 - 5
src/views/attend-class/model/train-settings/index.tsx

@@ -21,6 +21,8 @@ import dayjs from 'dayjs';
 import TheEmpty from '/src/components/TheEmpty';
 import requestOrigin from 'umi-request';
 import { modalClickMask } from '/src/state';
+import TheTipDialog from "@/components/TheTipDialog"
+import router from '/src/router';
 
 export default defineComponent({
   name: 'train-settings',
@@ -139,6 +141,52 @@ export default defineComponent({
       trainForms.editStatus = true;
     };
 
+    const tipDialog = reactive({
+      show: false,
+      msg:"",
+      confirmButtonText:"",
+      cancelBtn: false,
+      type: "CLASS" as "CLASS"|"PERSON"|"MUSIC"
+    })
+    function handleLessonAddErr(data:any){
+      const { type, errList } = data
+      tipDialog.type = type
+      if(type === "CLASS"){
+        // 班级乐器没有设置
+        tipDialog.cancelBtn = true
+        tipDialog.confirmButtonText = "去设置"
+        const msg = errList.map((item:any)=>{
+          return `<div><span style="color:#F44541">【${item.classGroupName}】</span>未设置乐器,请设置乐器后布置作业;</div>`
+        })
+        tipDialog.msg = msg.join("")
+      }else if(type === "PERSON"){
+        // 学生乐器没有设置
+        tipDialog.cancelBtn = true
+        tipDialog.confirmButtonText = "去设置"
+        const msg = errList.map((item:any)=>{
+          return `<div><span style="color:#F44541">【${item.studentName}】</span>所在<span style="color:#F44541">【${item.classGroupName}】</span>未设置乐器,请设置乐器后布置作业</div>`
+        })
+        tipDialog.msg = msg.join("")
+      }else if(type === "MUSIC"){
+        // 曲目和当前选择学生的乐器对不上的时候
+        tipDialog.cancelBtn = false
+        tipDialog.confirmButtonText = "我知道了"
+        const msg = errList.map((item:any)=>{
+          return `<div><span style="color:#F44541">【${item.musicSheetName}】</span>不支持<span style="color:#F44541">【${item.instrumentName}】</span>练习,请更换曲目或取消<span style="color:#F44541">【${item.instrumentName}】</span>的学生</div>`
+        })
+        tipDialog.msg = msg.join("")
+      }
+      tipDialog.show = true
+    }
+    function handleTipConfirm(){
+      if(["CLASS", "PERSON"].includes(tipDialog.type)){
+        router.push({
+          path: "/classList"
+        })
+      }else if(tipDialog.type === "MUSIC"){
+        tipDialog.show = false
+      }
+    }
     const onSubmit = async () => {
       // 训练内容不能为空
       if (!trainForms.expireDate) {
@@ -166,11 +214,16 @@ export default defineComponent({
           classGroupId: props.classGroupId,
           courseScheduleId: props.courseScheduleId || null
         };
-        await lessonTrainingAdd(params);
-        message.success('布置成功');
-
-        emit('close');
-        emit('confirm');
+        const lessonRes =  await lessonTrainingAdd(params);
+        if(lessonRes.code === 200){
+          if(lessonRes.data.status){
+            message.success('布置成功');
+            emit('close');
+            emit('confirm');
+          }else{
+            handleLessonAddErr(lessonRes.data)
+          }
+        }
       } catch {
         //
       }
@@ -322,6 +375,17 @@ export default defineComponent({
             }}
           />
         </NModal>
+        <TheTipDialog
+          show={tipDialog.show}
+          content={tipDialog.msg}
+          onClose={() => {
+            tipDialog.show = false
+          }}
+          onConfirm={handleTipConfirm}
+          cancelButtonText={"暂不设置"}
+          cancelBtn={tipDialog.cancelBtn}
+          confirmButtonText={tipDialog.confirmButtonText}
+        ></TheTipDialog>
       </div>
     );
   }

+ 69 - 4
src/views/prepare-lessons/components/lesson-main/train/assign-homework.tsx

@@ -31,6 +31,8 @@ import { useUserStore } from '@/store/modules/users';
 import { api_getCurrentGradeYear } from '/src/views/studentList/api';
 import request from '/src/utils/request';
 import { modalClickMask } from '/src/state';
+import TheTipDialog from "@/components/TheTipDialog"
+import router from '/src/router';
 
 export default defineComponent({
   name: 'assign-homework',
@@ -149,6 +151,52 @@ export default defineComponent({
       }
     };
 
+    const tipDialog = reactive({
+      show: false,
+      msg:"",
+      confirmButtonText:"",
+      cancelBtn: false,
+      type: "CLASS" as "CLASS"|"PERSON"|"MUSIC"
+    })
+    function handleLessonAddErr(data:any){
+      const { type, errList } = data
+      tipDialog.type = type
+      if(type === "CLASS"){
+        // 班级乐器没有设置
+        tipDialog.cancelBtn = true
+        tipDialog.confirmButtonText = "去设置"
+        const msg = errList.map((item:any)=>{
+          return `<div><span style="color:#F44541">【${item.classGroupName}】</span>未设置乐器,请设置乐器后布置作业;</div>`
+        })
+        tipDialog.msg = msg.join("")
+      }else if(type === "PERSON"){
+        // 学生乐器没有设置
+        tipDialog.cancelBtn = true
+        tipDialog.confirmButtonText = "去设置"
+        const msg = errList.map((item:any)=>{
+          return `<div><span style="color:#F44541">【${item.studentName}】</span>所在<span style="color:#F44541">【${item.classGroupName}】</span>未设置乐器,请设置乐器后布置作业</div>`
+        })
+        tipDialog.msg = msg.join("")
+      }else if(type === "MUSIC"){
+        // 曲目和当前选择学生的乐器对不上的时候
+        tipDialog.cancelBtn = false
+        tipDialog.confirmButtonText = "我知道了"
+        const msg = errList.map((item:any)=>{
+          return `<div><span style="color:#F44541">【${item.musicSheetName}】</span>不支持<span style="color:#F44541">【${item.instrumentName}】</span>练习,请更换曲目或取消<span style="color:#F44541">【${item.instrumentName}】</span>的学生</div>`
+        })
+        tipDialog.msg = msg.join("")
+      }
+      tipDialog.show = true
+    }
+    function handleTipConfirm(){
+      if(["CLASS", "PERSON"].includes(tipDialog.type)){
+        router.push({
+          path: "/classList"
+        })
+      }else if(tipDialog.type === "MUSIC"){
+        tipDialog.show = false
+      }
+    }
     const onSubmit = async () => {
       formsRef.value?.validate(async (err: any) => {
         if (err) {
@@ -186,10 +234,16 @@ export default defineComponent({
             });
             params.studentIds = ids.join(',');
           }
-          await lessonTrainingAdd(params);
-          message.success('布置成功');
-          emit('close');
-          emit('confirm');
+          const lessonRes =  await lessonTrainingAdd(params);
+          if(lessonRes.code === 200){
+            if(lessonRes.data.status){
+              message.success('布置成功');
+              emit('close');
+              emit('confirm');
+            }else{
+              handleLessonAddErr(lessonRes.data)
+            }
+          }
         } catch {
           //
         }
@@ -524,6 +578,17 @@ export default defineComponent({
           />
           {props.from === 'class' && <Dragbom></Dragbom>}
         </NModal>
+        <TheTipDialog
+          show={tipDialog.show}
+          content={tipDialog.msg}
+          onClose={() => {
+            tipDialog.show = false
+          }}
+          onConfirm={handleTipConfirm}
+          cancelButtonText={"暂不设置"}
+          cancelBtn={tipDialog.cancelBtn}
+          confirmButtonText={tipDialog.confirmButtonText}
+        ></TheTipDialog>
       </div>
     );
   }