fix:价值透析数据修改; #369

Merged
yangws merged 1 commits from yangws into main 2024-10-25 16:37:29 +08:00
1 changed files with 34 additions and 58 deletions

View File

@ -20,82 +20,58 @@
<script setup> <script setup>
import {ref, watch} from 'vue' import {ref, watch} from 'vue'
import overviewStore from '@/store/modules/overview' import overviewStore from '@/store/modules/overview'
import {listEntpcoursework} from '@/api/education/entpCourseWork'
const useOverview = overviewStore() const useOverview = overviewStore()
const tableData = ref([]) const tableData = ref([])
//id
const ids = ref('')
//
const allScore = ref(0)
// //
const konwledge = ref([]) const konwledge = ref([])
// //
const getKonwledge = () => { const getKonwledge = () => {
const getScoreRate = []
//
const ledges = []
useOverview.tableList.forEach(item => { useOverview.tableList.forEach(item => {
//
if(item.knowledgePoint){ if(item.knowledgePoint){
konwledge.value.push({...JSON.parse(item.knowledgePoint),...{scoingRate:Number(item.scoingRate),point:item.point,allPoint:allScore.value}}) const title = JSON.parse(item.knowledgePoint)
//
if(!ledges.includes(title.id)){
ledges.push(title.id)
konwledge.value.push({title:title.title,allPoint:item.point,id:title.id})
}
//
if(useOverview.allData[0].hasAnswers.includes(item.studentid))
getScoreRate.push({rate:item.scoingRate,id:title.id})
} }
}) })
tableData.value = getTableList(konwledge.value)
tableData.value = tableData.value.map(item => { //
return{ konwledge.value.forEach(item => {
let sunRate = 0
let num = 0
getScoreRate.forEach(item2 => {
if(item.id === item2.id){
sunRate += extractedNumber(item2.rate)
num ++
}
})
const scoreRate = sunRate / num
tableData.value.push({
scoingRate:scoreRate.toFixed(2),
...item, ...item,
allPoint: allScore.value point:(item.allPoint * scoreRate / 100).toFixed(2)
} })
}) })
console.log(tableData.value,'tableData.value')
}
//
const getScore = async () => {
const scoreId = useOverview.tableList[0].entpcourseworklist
const fixedJsonString = `[${scoreId}]`;
const objects = JSON.parse(fixedJsonString);
const id = objects.map(obj => obj.id);
ids.value = id.join(',')
const res = await listEntpcoursework({ids: ids.value, pageSize: 500})
if(res.code === 200){
allScore.value = res.rows.reduce((acc, cur) => acc + cur.workScore, 0);
getKonwledge()
} }
//
const extractedNumber = (score) => {
const match = score.match(/\d+/);
return match ? parseInt(match[0], 10) : null;
} }
//tableList //tableList
const getTableList = (data) => {
const result = [];
data.forEach(item => {
const existingItem = result.find(i => i.id === item.id);
if (existingItem) {
// pointscoingRate
existingItem.pointTotal += parseInt(item.point);
existingItem.scoingRateTotal += parseFloat(item.scoingRate);
existingItem.count++;
} else {
//
result.push({
id: item.id,
title: item.title,
pointTotal: item.point,
scoingRateTotal: parseFloat(item.scoingRate),
count: 1
});
}
});
//
result.forEach(item => {
item.point = Math.round(item.pointTotal / item.count);
// item.scoingRate = Math.round((item.scoingRateTotal / item.count) * 100) / 100;
item.scoingRate = Math.round((item.point / allScore.value) * 100);
delete item.pointTotal;
delete item.scoingRateTotal;
delete item.count;
});
return result;
}
watch(() => useOverview.tableList,() => { watch(() => useOverview.tableList,() => {
console.log(useOverview.tableList,'useOverview.tableList') getKonwledge()
getScore()
}) })
</script> </script>