snow 3 months ago
parent
commit
a047b5694b
1 changed files with 18 additions and 12 deletions
  1. 18 12
      pages/home/index.vue

+ 18 - 12
pages/home/index.vue

@@ -5,7 +5,7 @@
 				<text class="section-title">输入</text>
 				<el-button size="small" type="primary" @click="addTargetRow">添加</el-button>
 			</div> -->
-			<el-table size="small" border :data="inputData" max-height="calc(100vh - 150px)" empty-text="暂无数据,请添加猫咪势力">
+			<el-table size="small" border :data="inputData" max-height="calc(100vh - 450px)" empty-text="暂无数据,请添加猫咪势力">
 				<el-table-column label="顺序" width="55px">
 					<template #="{ $index }">{{ $index + 1 }}</template>
 				</el-table-column>
@@ -58,12 +58,12 @@
 		<!-- 输出表格 -->
 		<view class="section" v-if="outputData.length > 0">
 
-			<div style="display: flex;justify-content: space-between;">
+			<div style="display: flex;justify-content: space-between;" >
 				<text class="section-title">输出, 计算时间 {{}} ms </text>
 				<span>差额: {{ powerDifference }}</span>
 			</div>
 
-			<el-table size="small" border :data="outputData">
+			<el-table size="small" border :data="outputData" max-height="260px">
 				<el-table-column label="顺序" width="55px">
 					<template #="{ $index }">{{ $index + 1 === outputData.length ? '合计' : $index + 1}}</template>
 				</el-table-column>
@@ -355,6 +355,15 @@ function generatePowers(_powers, gender){
 		}
 	}
 
+	inputData.value = inputData.value.filter(item => {
+		if(!item.backupFemale && !item.backupMale && !item.targetFemale && !item.targetMale){
+			return false
+		}
+		
+		return true
+	})
+	
+	console.log(inputData.value)
 }
 
 
@@ -415,8 +424,6 @@ function calculateBestMatch() {
 	const targetFemale = targetData.filter(item => item.gender === '母').map(item => Number(item.power));
 	const backupMale = backupData.filter(item => item.gender === '公').map(item => Number(item.power));
 	const backupFemale = backupData.filter(item => item.gender === '母').map(item => Number(item.power));
-
-
 	// const targetMale = [153, 91, 77, 138, 90, 80, 60, 54, 52, 52, 52];
 	// const targetFemale = [121, 118, 115, 86, 84, 84, 59, 53, 51];
 	// const backupMale = [180, 165, 158, 154, 152, 151, 150, 150, 102, 101, 101, 93, 61, 30, 30, 29, 29, 29, 27, 10, 10];
@@ -427,7 +434,6 @@ function calculateBestMatch() {
 	// const backupMale = [153, 91, 77];
 	// const backupFemale = [121, 118, 115]; 
 
-
 	if (targetFemale.length > backupMale.length && backupMale.length !== 0){
 		ElMessage.warning('备选角色的公数据长度必须大于或等于目标角色的母数据')
 		return
@@ -451,10 +457,9 @@ function calculateBestMatch() {
 		targetWeight = targetMale.reduce((acc, val) => acc + val, 0) + targetFemale.reduce((acc, val) => acc + val, 0);
 	}
 
-	let minDifference = Infinity;  // 初始化最小差额为正无穷大
+	let minDifference = Infinity; 
     let bestfemaleCombination = null;
     let bestMaleCombination = null;
-	
 	const femaleCombinations = getCombinations(backupFemale, targetMaleLen);
 	const maleCombinations = getCombinations(backupMale, targetFemaleLen);
 
@@ -499,6 +504,7 @@ function calculateBestMatch() {
 				if (difference < minDifference) {
 					minDifference = difference;
 					bestfemaleCombination = femaleComb;
+					// bestMaleCombination = maleComb;
 					if (minDifference == 0) {
 						break;
 					}
@@ -506,10 +512,10 @@ function calculateBestMatch() {
 		}
 	}
 
-	bestMaleCombination && bestMaleCombination.sort((a, b) => a - b)
-	bestfemaleCombination && bestfemaleCombination.sort((a, b) => a - b)
-	targetMale.sort((a, b) => a - b)
-	targetFemale.sort((a, b) => a - b)
+	bestMaleCombination && bestMaleCombination.sort((a, b) => b - a)
+	bestfemaleCombination && bestfemaleCombination.sort((a, b) => b - a)
+	targetMale.sort((a, b) =>  b - a)
+	targetFemale.sort((a, b) =>  b - a)
 
 	if (!bestMaleCombination && !bestfemaleCombination){ return }