refactor code

This commit is contained in:
Jeffrey Hsu 2025-02-21 20:42:25 +08:00
parent 68acac2257
commit 40bc2aa605
2 changed files with 20 additions and 33 deletions

View File

@ -21,12 +21,17 @@ import { defineStore } from 'pinia'
import { ref } from 'vue' import { ref } from 'vue'
import { IAssessment, IAssessmentMethod, ICourse, IGoalRef, IStudent } from '@renderer/types' import { IAssessment, IAssessmentMethod, ICourse, IGoalRef, IStudent } from '@renderer/types'
import { ElMessage } from 'element-plus' 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', () => { export const useGlobalStore = defineStore('global', () => {
const courseInfo = ref<ICourse | null>(null) const courseInfo = ref<ICourse | null>(null)
const studentList = ref<IStudent[]>([]) const studentList = ref<IStudent[]>([])
const goals = ref<IGoalRef[]>([]) const goals = ref<IGoalRef[]>([])
const doc = ReportDocument.factory()
// 平时 // 平时
const normalStage = ref<IAssessment>({ method: [], weight: 0, stage: '' }) const normalStage = ref<IAssessment>({ method: [], weight: 0, stage: '' })
// 过程 // 过程
@ -114,7 +119,7 @@ export const useGlobalStore = defineStore('global', () => {
return false return false
} }
studentList.value = [] doc.students = []
const classList: string[] = [] const classList: string[] = []
for (let i = 6; ; i++) { for (let i = 6; ; i++) {
@ -134,7 +139,7 @@ export const useGlobalStore = defineStore('global', () => {
classList.push(stu.className) classList.push(stu.className)
} }
studentList.value.push(stu) doc.students.push(Student.factoryFromImpl(stu))
} }
let classStr = '' let classStr = ''
@ -162,7 +167,7 @@ export const useGlobalStore = defineStore('global', () => {
} }
} }
courseInfo.value = { doc.course = Course.factoryFromImpl({
campus: sheet['A4']['v'].split('')[1], campus: sheet['A4']['v'].split('')[1],
className: classStr, className: classStr,
credit: parseFloat(sheet['E4']['v'].split('')[1]), credit: parseFloat(sheet['E4']['v'].split('')[1]),
@ -170,11 +175,12 @@ export const useGlobalStore = defineStore('global', () => {
master: '', master: '',
name: sheet['E3']['v'].split('')[1], name: sheet['E3']['v'].split('')[1],
teacher: sheet['D4']['v'].split('')[1] teacher: sheet['D4']['v'].split('')[1]
} })
return true return true
} }
return { return {
doc,
courseInfo, courseInfo,
saveCourseInfo, saveCourseInfo,
clearCourseInfo, clearCourseInfo,

View File

@ -20,33 +20,22 @@
<script setup lang="ts"> <script setup lang="ts">
import { useGlobalStore } from '@renderer/store' import { useGlobalStore } from '@renderer/store'
import router from '@renderer/router' import router from '@renderer/router'
import { storeToRefs } from 'pinia'
import { computed, ref } from 'vue' import { computed, ref } from 'vue'
import { ICourse } from '@renderer/types' import { ICourse } from '@renderer/types'
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
import { ArrowLeft } from '@element-plus/icons-vue' import { ArrowLeft } from '@element-plus/icons-vue'
import { Course } from '@renderer/models/Course'
const store = useGlobalStore() const store = useGlobalStore()
const { courseInfo } = storeToRefs(store) const tempCourseInfo = ref<ICourse>(Course.factoryToImpl())
const isShowCopyBtn = ref<boolean>(false)
const tempCourseInfo = ref<ICourse>({
campus: '',
className: '',
credit: 0,
id: '',
master: '',
name: '',
teacher: ''
})
const isShowCopyFrom = ref<boolean>(false)
const enableSubmit = computed(() => !Object.values(tempCourseInfo.value).every((v) => v)) const enableSubmit = computed(() => !Object.values(tempCourseInfo.value).every((v) => v))
const handleCreateFrom = async (from: 'xlsx' | 'jwxt') => { const handleCreateFrom = async (from: 'xlsx' | 'jwxt') => {
if (from === 'xlsx') { if (from === 'xlsx') {
if (await store.createCourseFromXlsx()) { if (await store.createCourseFromXlsx()) {
ElMessage({ type: 'success', message: '成功' }) ElMessage({ type: 'success', message: '成功' })
tempCourseInfo.value = courseInfo.value! tempCourseInfo.value = store.doc.course.getCurrImpl()
} }
} else if (from === 'jwxt') { } else if (from === 'jwxt') {
ElMessage({ type: 'warning', message: '功能暂时不可用,敬请期待' }) ElMessage({ type: 'warning', message: '功能暂时不可用,敬请期待' })
@ -56,28 +45,20 @@ const handleCreateFrom = async (from: 'xlsx' | 'jwxt') => {
const handleBack = () => router.back() const handleBack = () => router.back()
const handleFormReset = () => { const handleFormReset = () => {
tempCourseInfo.value = { tempCourseInfo.value = Course.factoryToImpl()
campus: '',
className: '',
credit: 0,
id: '',
master: '',
name: '',
teacher: ''
}
} }
const handleShowCopyBtn = () => { const handleShowCopyBtn = () => {
isShowCopyFrom.value = (!tempCourseInfo.value.master && tempCourseInfo.value.teacher) as boolean isShowCopyBtn.value = (!tempCourseInfo.value.master && tempCourseInfo.value.teacher) as boolean
} }
const handleCopyFromTeacher = () => { const handleCopyFromTeacher = () => {
tempCourseInfo.value.master = tempCourseInfo.value.teacher tempCourseInfo.value.master = tempCourseInfo.value.teacher
isShowCopyFrom.value = false isShowCopyBtn.value = false
} }
const handleSubmit = async () => { const handleSubmit = async () => {
store.saveCourseInfo(tempCourseInfo.value) store.doc.course.setFromImpl(tempCourseInfo.value)
await router.push({ name: 'panel' }) await router.push({ name: 'panel' })
} }
</script> </script>
@ -120,7 +101,7 @@ const handleSubmit = async () => {
/> />
<div <div
class="invisible absolute right-4 cursor-pointer text-gray-400" class="invisible absolute right-4 cursor-pointer text-gray-400"
:class="{ visible: isShowCopyFrom }" :class="{ visible: isShowCopyBtn }"
@click="handleCopyFromTeacher" @click="handleCopyFromTeacher"
> >
从任课教师复制 从任课教师复制