refactor code
This commit is contained in:
parent
68acac2257
commit
40bc2aa605
@ -21,12 +21,17 @@ import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
import { IAssessment, IAssessmentMethod, ICourse, IGoalRef, IStudent } from '@renderer/types'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { ReportDocument } from '@renderer/models/ReportDocument'
|
||||
import { Student } from '@renderer/models/Student'
|
||||
import { Course } from '@renderer/models/Course'
|
||||
|
||||
export const useGlobalStore = defineStore('global', () => {
|
||||
const courseInfo = ref<ICourse | null>(null)
|
||||
const studentList = ref<IStudent[]>([])
|
||||
const goals = ref<IGoalRef[]>([])
|
||||
|
||||
const doc = ReportDocument.factory()
|
||||
|
||||
// 平时
|
||||
const normalStage = ref<IAssessment>({ method: [], weight: 0, stage: '' })
|
||||
// 过程
|
||||
@ -114,7 +119,7 @@ export const useGlobalStore = defineStore('global', () => {
|
||||
return false
|
||||
}
|
||||
|
||||
studentList.value = []
|
||||
doc.students = []
|
||||
const classList: string[] = []
|
||||
|
||||
for (let i = 6; ; i++) {
|
||||
@ -134,7 +139,7 @@ export const useGlobalStore = defineStore('global', () => {
|
||||
classList.push(stu.className)
|
||||
}
|
||||
|
||||
studentList.value.push(stu)
|
||||
doc.students.push(Student.factoryFromImpl(stu))
|
||||
}
|
||||
|
||||
let classStr = ''
|
||||
@ -162,7 +167,7 @@ export const useGlobalStore = defineStore('global', () => {
|
||||
}
|
||||
}
|
||||
|
||||
courseInfo.value = {
|
||||
doc.course = Course.factoryFromImpl({
|
||||
campus: sheet['A4']['v'].split(':')[1],
|
||||
className: classStr,
|
||||
credit: parseFloat(sheet['E4']['v'].split(':')[1]),
|
||||
@ -170,11 +175,12 @@ export const useGlobalStore = defineStore('global', () => {
|
||||
master: '',
|
||||
name: sheet['E3']['v'].split(':')[1],
|
||||
teacher: sheet['D4']['v'].split(':')[1]
|
||||
}
|
||||
})
|
||||
return true
|
||||
}
|
||||
|
||||
return {
|
||||
doc,
|
||||
courseInfo,
|
||||
saveCourseInfo,
|
||||
clearCourseInfo,
|
||||
|
@ -20,33 +20,22 @@
|
||||
<script setup lang="ts">
|
||||
import { useGlobalStore } from '@renderer/store'
|
||||
import router from '@renderer/router'
|
||||
import { storeToRefs } from 'pinia'
|
||||
import { computed, ref } from 'vue'
|
||||
import { ICourse } from '@renderer/types'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { ArrowLeft } from '@element-plus/icons-vue'
|
||||
import { Course } from '@renderer/models/Course'
|
||||
|
||||
const store = useGlobalStore()
|
||||
const { courseInfo } = storeToRefs(store)
|
||||
|
||||
const tempCourseInfo = ref<ICourse>({
|
||||
campus: '',
|
||||
className: '',
|
||||
credit: 0,
|
||||
id: '',
|
||||
master: '',
|
||||
name: '',
|
||||
teacher: ''
|
||||
})
|
||||
|
||||
const isShowCopyFrom = ref<boolean>(false)
|
||||
|
||||
const tempCourseInfo = ref<ICourse>(Course.factoryToImpl())
|
||||
const isShowCopyBtn = ref<boolean>(false)
|
||||
const enableSubmit = computed(() => !Object.values(tempCourseInfo.value).every((v) => v))
|
||||
|
||||
const handleCreateFrom = async (from: 'xlsx' | 'jwxt') => {
|
||||
if (from === 'xlsx') {
|
||||
if (await store.createCourseFromXlsx()) {
|
||||
ElMessage({ type: 'success', message: '成功' })
|
||||
tempCourseInfo.value = courseInfo.value!
|
||||
tempCourseInfo.value = store.doc.course.getCurrImpl()
|
||||
}
|
||||
} else if (from === 'jwxt') {
|
||||
ElMessage({ type: 'warning', message: '功能暂时不可用,敬请期待' })
|
||||
@ -56,28 +45,20 @@ const handleCreateFrom = async (from: 'xlsx' | 'jwxt') => {
|
||||
const handleBack = () => router.back()
|
||||
|
||||
const handleFormReset = () => {
|
||||
tempCourseInfo.value = {
|
||||
campus: '',
|
||||
className: '',
|
||||
credit: 0,
|
||||
id: '',
|
||||
master: '',
|
||||
name: '',
|
||||
teacher: ''
|
||||
}
|
||||
tempCourseInfo.value = Course.factoryToImpl()
|
||||
}
|
||||
|
||||
const handleShowCopyBtn = () => {
|
||||
isShowCopyFrom.value = (!tempCourseInfo.value.master && tempCourseInfo.value.teacher) as boolean
|
||||
isShowCopyBtn.value = (!tempCourseInfo.value.master && tempCourseInfo.value.teacher) as boolean
|
||||
}
|
||||
|
||||
const handleCopyFromTeacher = () => {
|
||||
tempCourseInfo.value.master = tempCourseInfo.value.teacher
|
||||
isShowCopyFrom.value = false
|
||||
isShowCopyBtn.value = false
|
||||
}
|
||||
|
||||
const handleSubmit = async () => {
|
||||
store.saveCourseInfo(tempCourseInfo.value)
|
||||
store.doc.course.setFromImpl(tempCourseInfo.value)
|
||||
await router.push({ name: 'panel' })
|
||||
}
|
||||
</script>
|
||||
@ -120,7 +101,7 @@ const handleSubmit = async () => {
|
||||
/>
|
||||
<div
|
||||
class="invisible absolute right-4 cursor-pointer text-gray-400"
|
||||
:class="{ visible: isShowCopyFrom }"
|
||||
:class="{ visible: isShowCopyBtn }"
|
||||
@click="handleCopyFromTeacher"
|
||||
>
|
||||
从任课教师复制
|
||||
|
Loading…
x
Reference in New Issue
Block a user