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

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