add:创建班级;

This commit is contained in:
小杨 2024-10-30 15:54:48 +08:00
parent 32ab4dbbfb
commit 1c463ed58b
3 changed files with 251 additions and 23 deletions

View File

@ -0,0 +1,232 @@
<template>
<div>
<el-dialog v-model="dialogVisible" title="创建班级" width="50%" append-to-body>
<el-form
style="width: 100%"
label-width="auto"
:model="classForm"
:rules="rules"
ref="myForm"
>
<el-form-item label="班级名称" style="margin-right: 10px;width: 100%" prop="caption">
<el-input v-model="classForm.caption" placeholder="请输入班级名称"></el-input>
</el-form-item>
<el-form-item label="任选学科" style="margin-right: 10px;">
<el-radio-group v-model="classForm.edusubject" class="ml-4">
<template v-for="(item, index) in courseList" :key="index">
<el-radio v-if="item.edustage == userStore.edustage" :label="item.itemtitle">{{ item.itemtitle }}</el-radio>
</template>
</el-radio-group>
</el-form-item>
<el-form-item label="年级" style="margin-right: 10px;" prop="agekey">
<el-radio-group v-model="classForm.agekey">
<template v-for="(item, index) in gradeList" :key="index">
<el-radio v-if="item.edustage == userStore.edustage" :label="item.agekey">{{ item.label }}</el-radio>
</template>
</el-radio-group>
</el-form-item>
<el-form-item label="老师" prop="teacherid">
{{ userStore.nickName }}
</el-form-item>
<el-form-item label="简要说明" style="margin-right: 10px;" prop="classdesc">
<el-input v-model="classForm.classdesc" placeholder="请输入简要说明"></el-input>
</el-form-item>
</el-form>
<template #footer>
<el-button @click="dialogVisible = false"> </el-button>
<el-button type="primary" @click="btnSave"> </el-button>
</template>
</el-dialog>
</div>
</template>
<script setup>
import { ref, onMounted, reactive, watch, defineEmits, defineExpose } from 'vue'
import { listClassmain, addClassmain, listEvaluation } from '@/api/classManage/index'
import useUserStore from '@/store/modules/user'
import { ElMessage } from 'element-plus'
import delClassDemo from '@/store/modules/delClass'
const userStore = useUserStore().user
const emit = defineEmits(['refreshList'])
const isDel = delClassDemo()
//
const classList = ref([])
//
const classForm = reactive({
caption: '',
classdesc: '',
teacherid: '',
agekey: '',
edusubject: userStore.edusubject,
edudegree: userStore.edustage
})
//
const courseList = ref([])
// id
const classId = ref('')
//
const currentIndex = ref(0)
//
const gradeList = ref([
{ label: '一年级', value: '1年级', checked: false, edustage: '小学', agekey: 1 },
{ label: '二年级', value: '2年级', checked: false, edustage: '小学', agekey: 2 },
{ label: '三年级', value: '3年级', checked: false, edustage: '小学', agekey: 3 },
{ label: '四年级', value: '4年级', checked: false, edustage: '小学', agekey: 4 },
{ label: '五年级', value: '5年级', checked: false, edustage: '小学', agekey: 5 },
{ label: '六年级', value: '6年级', checked: false, edustage: '小学', agekey: 6 },
{ label: '初一', value: '初一', checked: false, edustage: '初中', agekey: 7 },
{ label: '初二', value: '初二', checked: false, edustage: '初中', agekey: 8 },
{ label: '初三', value: '初三', checked: false, edustage: '初中', agekey: 9 },
{ label: '高一', value: '高一', checked: false, edustage: '高中', agekey: 10 },
{ label: '高二', value: '高二', checked: false, edustage: '高中', agekey: 11 },
{ label: '高三', value: '高三', checked: false, edustage: '高中', agekey: 12 },
])
//
const dialogVisible = ref(false)
//
const myForm = ref(null)
const rules = reactive({
caption: [
{ required: true, message: '请输入班级名称', trigger: 'blur' },
{ min: 1, max: 10, message: '班级名称必须是 1-10 位 的字符', trigger: 'blur' }
],
agekey: [
{ required: true, message: '请选择年级', trigger: 'change' }
],
})
//
const getClassInfo = () => {
classList.value = []
listClassmain({ entpid: userStore.deptId, pageSize: 500, status: 'open' }).then(response => {
response.rows.forEach(item => {
if (item.classteacherids && Number(item.classteacherids) === userStore?.id) {
classList.value.push(item)
}
})
if (classList.value.length > 0) {
classId.value = classList.value[0].id
currentIndex.value = 0
}
});
}
//
const getCourseList = () => {
//
listEvaluation({ itemkey: "subject", pageSize: 500 }).then((res) => {
courseList.value = [...res.rows];
});
}
//
const addClass = () => {
dialogVisible.value = true
getCourseList()
getClassInfo()
}
const btnSave = () => {
myForm.value.validate((valid) => {
if (valid) {
//
listClassmain({ entpid: userStore.deptId, status: 'open', pageSize: 500 }).then(response => {
const data = [...response.rows]
const existList = [];
data.forEach(item => {
if (parseInt(textSimilar(item.caption, classForm.caption, 2)) > 80) {
existList.push(item);
}
})
if (existList.length == 0) {
const age = classForm.agekey;
const index = gradeList.value.findIndex(item => item.agekey === age);
classForm.edudegree = gradeList.value[index].value
classForm.entpid = userStore.deptId;
classForm.status = 'open';
classForm.teachername = userStore.nickName;
classForm.teacherid = userStore.userId;
classForm.teacherSubject = classForm.edusubject;
classForm.action = 'new';
classForm.teachtype = 'standard';
classForm.isSaving = true;
addClassmain(classForm).then(response => {
if (response.code === 200) {
dialogVisible.value = false
ElMessage({
message: '新增成功',
type: 'success',
})
emit('refreshList')
}
});
} else {
ElMessage({
message: '班级名称重复',
type: 'warning',
})
}
})
}
})
}
//
const textSimilar = (s, t, f) => {
if (!s || !t) {
return 0
}
if (s === t) {
return 100;
}
var l = s.length > t.length ? s.length : t.length
var n = s.length
var m = t.length
var d = []
f = f || 2
var min = function (a, b, c) {
return a < b ? (a < c ? a : c) : (b < c ? b : c)
}
var i, j, si, tj, cost
if (n === 0) return m
if (m === 0) return n
for (i = 0; i <= n; i++) {
d[i] = []
d[i][0] = i
}
for (j = 0; j <= m; j++) {
d[0][j] = j
}
for (i = 1; i <= n; i++) {
si = s.charAt(i - 1)
for (j = 1; j <= m; j++) {
tj = t.charAt(j - 1)
if (si === tj) {
cost = 0
} else {
cost = 1
}
d[i][j] = min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost)
}
}
let res = (1 - d[n][m] / l) * 100
return res.toFixed(f)
}
watch(() => isDel.idDelete, () => {
//
getClassInfo()
isDel.idDelete = false
})
defineExpose({
addClass
})
</script>
<style scoped>
.el-card-demo {
width: 200px;
overflow-y: auto;
display: flex;
justify-content: space-between;
flex-direction: column;
}
</style>

View File

@ -1,14 +1,15 @@
<template> <template>
<div class="common-layout"> <div class="common-layout">
<el-container> <el-container>
<el-aside style="width: 200px;"> <el-aside style="width: 230px;">
<el-card style="width: 200px" class="el-card-demo"> <el-card style="width: 230px" class="el-card-demo">
<div > <div >
<Aside :menuItems="menuItems" :classList="classList" @handleSelect="handleSelect"></Aside> <Aside :menuItems="menuItems" :classList="classList" @handleSelect="handleSelect"></Aside>
</div> </div>
<template #footer> <template #footer>
<div> <div style="display: flex;">
<el-button @click="addClass" type="primary" :icon="Plus" >加入班级</el-button> <el-button @click="addClass" type="primary">加入班级</el-button>
<el-button @click="addNewClass" type="primary">创建班级</el-button>
</div> </div>
</template> </template>
</el-card> </el-card>
@ -23,11 +24,11 @@
<!-- 分组情况--> <!-- 分组情况-->
<BasicGroup v-else-if="currentIndex==2" :classId="classId"></BasicGroup> <BasicGroup v-else-if="currentIndex==2" :classId="classId"></BasicGroup>
</div> </div>
<!-- 创建班级 -->
<NewClass ref="newClassRef" @refreshList="refreshList"/>
</el-container> </el-container>
</div> </div>
<el-dialog v-model="dialogVisible" title="新增班级" width="50%" append-to-body> <el-dialog v-model="dialogVisible" title="加入班级" width="50%" append-to-body>
<el-form <el-form
style="width: 100%" style="width: 100%"
label-width="auto" label-width="auto"
@ -69,11 +70,14 @@
import BasicGroup from './basicGroup.vue' import BasicGroup from './basicGroup.vue'
import ClassInfo from './classInfo.vue' import ClassInfo from './classInfo.vue'
import Aside from './aside.vue' import Aside from './aside.vue'
import NewClass from './components/newClass.vue'
const userStore = useUserStore().user const userStore = useUserStore().user
const isDel = delClassDemo() const isDel = delClassDemo()
// //
const classList = ref([]) const classList = ref([])
//
const newClassRef = ref()
const menuItems = [ const menuItems = [
{ {
index: '1-1', index: '1-1',
@ -108,21 +112,6 @@
const classId = ref(0) const classId = ref(0)
// //
const currentIndex = ref(0) const currentIndex = ref(0)
//
const gradeList = ref([
{ label: '一年级', value: '1年级', checked: false, edustage: '小学', agekey: 1 },
{ label: '二年级', value: '2年级', checked: false, edustage: '小学', agekey: 2 },
{ label: '三年级', value: '3年级', checked: false, edustage: '小学', agekey: 3 },
{ label: '四年级', value: '4年级', checked: false, edustage: '小学', agekey: 4 },
{ label: '五年级', value: '5年级', checked: false, edustage: '小学', agekey: 5},
{ label: '六年级', value: '6年级', checked: false, edustage: '小学', agekey: 6 },
{ label: '初一', value: '初一', checked: false, edustage: '初中', agekey: 7 },
{ label: '初二', value: '初二', checked: false, edustage: '初中', agekey: 8 },
{ label: '初三', value: '初三', checked: false, edustage: '初中', agekey: 9 },
{ label: '高一', value: '高一', checked: false, edustage: '高中', agekey: 10 },
{ label: '高二', value: '高二', checked: false, edustage: '高中', agekey: 11 },
{ label: '高三', value: '高三', checked: false, edustage: '高中', agekey: 12 },
])
// //
const dialogVisible = ref(false) const dialogVisible = ref(false)
// //
@ -287,6 +276,14 @@
classId.value = obj.id classId.value = obj.id
currentIndex.value = obj.index currentIndex.value = obj.index
} }
//
const addNewClass = () => {
newClassRef.value.addClass()
}
//
const refreshList = () => {
getClassInfo()
}
onMounted(() => { onMounted(() => {
getClassInfo() getClassInfo()

View File

@ -66,7 +66,6 @@ onMounted(() => {
} }
.text-center { .text-center {
margin-bottom: 15px; margin-bottom: 15px;
border-bottom: 1px solid #dddddd;
display: flex; display: flex;
align-items: center; align-items: center;
.info{ .info{