[科学实验] - 更改学段学科选择方式

This commit is contained in:
“zouyf” 2025-01-20 16:10:51 +08:00
parent c56b434b4b
commit 28294d0a25
1 changed files with 134 additions and 26 deletions

View File

@ -1,6 +1,9 @@
<template>
<div style="display: flex;">
<div style="margin-left: 15px">
<el-cascader v-model="bindSubject" :options="subjectList" @change="handleChange" />
</div>
<!-- <div style="margin-left: 15px">
<el-dropdown @command="handleUserEduStage">
<span class="el-dropdown-link">
<el-button class="custom-button" type="default" round >{{ useClassTaskStore().experimentObj.edustage }}
@ -9,7 +12,6 @@
</span>
<template #dropdown>
<el-dropdown-menu>
<!-- <el-dropdown-item command="幼儿园">幼儿园</el-dropdown-item> -->
<el-dropdown-item command="小学">小学</el-dropdown-item>
<el-dropdown-item command="初中">初中</el-dropdown-item>
<el-dropdown-item command="高中">高中</el-dropdown-item>
@ -33,7 +35,7 @@
</el-dropdown-menu>
</template>
</el-dropdown>
</div>
</div> -->
</div>
</template>
@ -52,12 +54,114 @@ const userStore = useUserStore().user
// edustage: useClassTaskStore().experimentObj.edustage,
// edusubject: useClassTaskStore().experimentObj.edusubject,
// })
const subjectList = ref([])
//const subjectList = ref([])
const chooseGrade= ref({})
const expList = ref([]) //
const checkList = ref([])//
const isLoaded = ref(false);
const bindSubject = ref([useClassTaskStore().experimentObj.edustage, useClassTaskStore().experimentObj.edusubject]); //
const subjectList = [
{
value: '小学',
label: '小学',
children: [
{
value: '数学',
label: '数学',
},
{
value: '物理',
label: '物理',
},
{
value: '化学',
label: '化学',
},
{
value: '生物',
label: '生物',
},
{
value: '科学',
label: '科学',
}]
},
{
value: '初中',
label: '初中',
children: [
{
value: '数学',
label: '数学',
},
{
value: '物理',
label: '物理',
},
{
value: '化学',
label: '化学',
},
{
value: '生物',
label: '生物',
},
{
value: '科学',
label: '科学',
}]
},
{
value: '高中',
label: '高中',
children: [
{
value: '数学',
label: '数学',
},
{
value: '物理',
label: '物理',
},
{
value: '化学',
label: '化学',
},
{
value: '生物',
label: '生物',
},
{
value: '科学',
label: '科学',
}]
}
]
const handleChange = (val) => {
useClassTaskStore().experimentObj.edustage = val[0];
useClassTaskStore().experimentObj.edusubject = val[1];
handleUserEduStage(useClassTaskStore().experimentObj.edustage);
}
//
const getSubject = () => {
//
@ -67,19 +171,20 @@ const getSubject = () => {
// subjectList.value = res.rows.filter(item => arr.includes(String(item.id))).map(items => items)
// console.log(subjectList,'subjectList');
// })
// list
const edustageList = ['小学','初中','高中'];
const subList = ['数学','物理','化学','生物','科学'];
edustageList.forEach((item) => {
subList.forEach((subItems) => {
subjectList.value.push({
edustage: item,
edusubject: subItems,
itemtitle: subItems
})
})
})
console.log(subjectList,'subjectList');
// const edustageList = ['','',''];
// const subList = ['','','','',''];
// edustageList.forEach((item) => {
// subList.forEach((subItems) => {
// subjectList.value.push({
// edustage: item,
// edusubject: subItems,
// itemtitle: subItems
// })
// })
// })
// console.log(subjectList,'subjectList');
//
const edusubject = useClassTaskStore().experimentObj.edusubject;
@ -90,6 +195,8 @@ const getSubject = () => {
isLoaded.value = true;
//console.log('----');
}
//
const isExpList = (edusubject) => {
let list = [];
@ -101,7 +208,7 @@ const isExpList = (edusubject) => {
list = expList.value.filter(item => item.subject === 'physics')
break;
case '化学':
checkList.value = expList.value.filter(item => item.subject === 'chemistry')
list = expList.value.filter(item => item.subject === 'chemistry')
break;
case '生物':
list = expList.value.filter(item => item.subject === 'biology')
@ -112,19 +219,19 @@ const isExpList = (edusubject) => {
}
return list.length > 0
}
//
const handleUserEduStage = (item) => {
// userStore.edustage = item
useClassTaskStore().experimentObj.edustage = item;
//
expList.value = []
if(item === '小学'){
chooseGrade.value = jsonData.data.primary
expList.value = chooseGrade.value
const newSubjectList = subjectList.value.filter(item => item.edustage === '小学');
for(let i in newSubjectList){
const name = newSubjectList[i].itemtitle
const newSubjectList = subjectList.filter(item => item.value === '小学');
for(let i of newSubjectList[0].children){
const name = i.value
if(isExpList(name) && useClassTaskStore().experimentObj.edusubject===name){
//useClassTaskStore().experimentObj.edusubject = name;
//
@ -135,9 +242,9 @@ const handleUserEduStage = (item) => {
}else if(item === '初中'){
chooseGrade.value = jsonData.data.junior
expList.value = chooseGrade.value
const newSubjectList = subjectList.value.filter(item => item.edustage === '初中');
for(let i in newSubjectList){
const name = newSubjectList[i].itemtitle
const newSubjectList = subjectList.filter(item => item.value === '初中');
for(let i of newSubjectList[0].children){
const name = i.value
if(isExpList(name) && useClassTaskStore().experimentObj.edusubject===name){
//useClassTaskStore().experimentObj.edusubject = name;
//
@ -148,9 +255,9 @@ const handleUserEduStage = (item) => {
}else if(item === '高中'){
chooseGrade.value = jsonData.data.senior
expList.value = chooseGrade.value
const newSubjectList = subjectList.value.filter(item => item.edustage === '高中');
for(let i in newSubjectList){
const name = newSubjectList[i].itemtitle
const newSubjectList = subjectList.filter(item => item.value === '高中');
for(let i of newSubjectList[0].children){
const name = i.value
if(isExpList(name) && useClassTaskStore().experimentObj.edusubject===name){
//useClassTaskStore().experimentObj.edusubject = name;
//
@ -205,6 +312,7 @@ const updateCheckList = async () => {
}
expList.value = chooseGrade.value
const edusubject = useClassTaskStore().experimentObj.edusubject;
bindSubject.value = [edustage, edusubject];
handleUserEduSubject(edusubject);
} catch (error) {
console.error(error);