ソースを参照

添加班级+获取班级

LiShiwei 1 年間 前
コミット
ffa22524b2

+ 0 - 95
src/views/management/lesson/component/add_lesson.vue

@@ -1,95 +0,0 @@
-<template>
- <n-form ref="formRef" :model="model" :rules="rules">
-    <n-form-item path="age" label="班级名称">
-      <n-input v-model:value="model.age" @keydown.enter.prevent />
-    </n-form-item>
-    <n-row :gutter="[0, 24]">
-      <n-col :span="24">
-        <div style="display: flex; justify-content: flex-end">
-          <n-button
-            :disabled="model.age === null"
-            round
-            type="primary"
-            @click="handleValidateButtonClick"
-          >
-            提交
-          </n-button>
-        </div>
-      </n-col>
-    </n-row>
-  </n-form>
-
-</template>
-
-<script lang="ts">
-import { defineComponent, ref } from 'vue'
-import {
-  FormInst,
-  FormItemInst,
-  FormItemRule,
-  useMessage,
-  FormRules
-} from 'naive-ui'
-
-interface ModelType {
-  age: string | null
-}
-
-export default defineComponent({
-  setup (props,context) {
-    
-    const formRef = ref<FormInst | null>(null)
-    const rPasswordFormItemRef = ref<FormItemInst | null>(null)
-    const message = useMessage()
-    const modelRef = ref<ModelType>({
-      age: null,
-      password: null,
-      reenteredPassword: null
-    })
-    function validatePasswordStartWith (
-      rule: FormItemRule,
-      value: string
-    ): boolean {
-      return (
-        !!modelRef.value.password &&
-        modelRef.value.password.startsWith(value) &&
-        modelRef.value.password.length >= value.length
-      )
-    }
-    function validatePasswordSame (rule: FormItemRule, value: string): boolean {
-      return value === modelRef.value.password
-    }
-    const rules: FormRules = {
-      age: [
-        {
-          required: true,
-          validator (rule: FormItemRule, value: string) {
-            if (!value) {
-              return new Error('需要班级名称')
-            } 
-            return true
-          },
-          trigger: ['input', 'blur']
-        }
-      ],
-    }
-    return {
-      formRef,
-      rPasswordFormItemRef,
-      model: modelRef,
-      rules,
-      handlePasswordInput () {
-        if (modelRef.value.reenteredPassword) {
-          rPasswordFormItemRef.value?.validate({ trigger: 'password-input' })
-        }
-      },
-      handleValidateButtonClick(){
-        message.success("提交成功")
-        this.$emit('showModal',false)
-      }
-    }
-  }
-})
-</script>
-
-<style scoped></style>

+ 56 - 24
src/views/management/lesson/index.vue

@@ -1,6 +1,5 @@
 <template>
-
-<!-- 上层状态 -->
+  <!-- 上层状态 -->
 
   <!-- 模态框 -->
   <n-modal v-model:show="showModal" block-scroll close-on-esc trap-focus>
@@ -56,6 +55,14 @@ import { NButton } from 'naive-ui'
 import type { DataTableColumns } from 'naive-ui'
 import { selectTotal, addClass } from '~/src/service/api/lesson'
 import { ref } from 'vue'
+import {
+  onBeforeMount,
+  onMounted,
+  onBeforeUpdate,
+  onUpdated,
+  onBeforeUnmount,
+  onUnmounted,
+} from 'vue'
 //获取所有班级类
 type RowData = {
   id: number
@@ -117,23 +124,47 @@ const createColumns = ({
 
 
 //增加班级类
-type easEduClass={
-  id:number,
-  name:string,
-  manageId:number,
-  assistantId:number,
-  createTime:string,
-  modifyTime:string,
-  createUid:string,
-  disabled:string
+type easEduClass = {
+  id: number,
+  name: string,
+  manageId: number,
+  assistantId: number,
+  createTime: string,
+  modifyTime: string,
+  createUid: number,
+  disabled: string
 }
-addClass().then(r=>{
-  console.log(r);
-  
-})
+//添加班级的函数
+let params: easEduClass = {
+  id: 0,
+  name: "",
+  manageId: 0,
+  assistantId: 0,
+  createTime: "",
+  modifyTime: "",
+  createUid: 0,
+  disabled: null
+}
+function AddClassInter(params): void {
+  if (params != "") {
+    addClass(params).then(r => {
+      console.log(r);
+    })
+   
+    
+  }
+  return;
+}
+
 export default defineComponent({
 
   setup() {
+    onMounted(() => {
+      // AddClassInter(params);
+      console.log(111);
+      
+
+    });
     const showModal = ref(false);
     const formRef = ref<FormInst | null>(null)
     const rPasswordFormItemRef = ref<FormItemInst | null>(null)
@@ -156,16 +187,23 @@ export default defineComponent({
       ],
     }
     return {
+      onMounted,
       formRef,
       rPasswordFormItemRef,
       model: modelRef,
       rules,
-      handleValidateButtonClick() {
+      async handleValidateButtonClick() {
         //点击添加
+        if (modelRef.value.name == "") {
+          return;
+        }
+        params.name = modelRef.value.name;
+        // console.log(params);
+        AddClassInter(params);
+        getTableData();
         showModal.value = false;
         message.success("添加成功");
         modelRef.value.name = null;//清空表单值
-
       },
       showModal,
       FlashOutline,
@@ -182,10 +220,4 @@ export default defineComponent({
   }
 })
 </script>
-<style scoped>
-.n-grid{
-  /* display: flex;
-  justify-content: center;
-  align-items: center; */
-}
-</style>
+<style scoped></style>