12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352 |
- <template>
- <view class="container" style="position: relative;">
-
- <!-- 首屏广告 -->
- <div style="margin-bottom: 8px;min-height: 130px">
- <ad-custom v-if="isShow" unit-id="adunit-f8a0fb31ae0f3569" bindload="adLoad" binderror="adError" bindclose="adClose"></ad-custom>
- </div>
-
- <!-- 侧边广告 -->
- <div style="position: absolute;top:400px;right:0px;z-index:999;opacity: 0.5">
- <ad-custom v-if="isShow" unit-id="adunit-2768960e9f32db36" bindload="adLoad" binderror="adError" bindclose="adClose"></ad-custom>
- </div>
-
- <div style="display: flex;flex-direction: column;">
- <div style="display: flex;justify-content: space-between;margin-bottom:8px">
- <button plain="true" class="primary-btn" style="padding:5px;width:70px;margin:2px" @click="viewExplam">
- {{ isMockData ? '清除' : '查看' }}示例
- </button>
-
-
- <button plain="true" class="primary-btn" style="padding:5px;width:70px;margin:2px" @click="switchRoles">
- 交换角色
- </button>
-
- <button plain="true" class="primary-btn" style="padding:5px;width:135px;margin:2px" @click="calculateBestMatch">
- 点击获取最佳搭配
- </button>
- </div>
- <uni-table border stripe>
- <uni-tr>
- <uni-th align="left" width="65px">
- <div style="display: flex;flex-direction: column;color:#989ba1">
- <p style="text-wrap:nowrap;text-align:center">角色</p>
- </div>
- </uni-th>
-
- <uni-th >
- <div style="display: flex;flex-direction: column;color:#989ba1">
- <p style="text-align:left">数量_性别: 势力</p>
- </div>
- </uni-th>
- <!-- <uni-th width="40px" ></uni-th> -->
- </uni-tr>
-
-
- <!-- 表格数据行 -->
- <uni-tr v-for="(item, index) in computedInputData" :key="index">
- <uni-td width="50px" >
- <div style="display: flex;flex-direction: column;">
- <p style="text-wrap:nowrap;text-align:center">{{ item.role }}</p>
- <!-- <p style="text-align:center">—</p> -->
- <p style="text-align:center">{{ item.role === '目标' ? totalTarget : totalBackup }}</p>
- </div>
- </uni-td>
-
-
- <uni-td>
- <div style="display: flex;flex-direction: column;">
- <div style="display:flex">
- <p style="width:50px;min-width:50px ;white-space: nowrap;text-align: right;">{{item.gender.male.length}}_公:</p>
-
- <div style="display: flex;flex-wrap:wrap;flex:1">
- <p
- :style="`margin-right: 5px;width:25px;text-align: center;color:${item.role === '备选' && picks.male.includes(index) ? '#67c23a' : ''}`"
- v-for="(power, index) in item.gender.male"
- >
- {{ power }}
- </p>
- </div>
-
- <div type="primary" link style="margin-left: 0px;" @click="editRow(item.role)">
- <!-- <uni-icons style="color: #409eff" size="14" type="compose" /> -->
-
- <image src="./edit.png" style="width:15px;height:15px" />
- </div>
- </div>
-
- <div style="display:flex">
- <p style="width:50px;min-width:50px ;white-space: nowrap;text-align: right;">{{item.gender.female.length}}_母:</p>
-
- <div style="display: flex;flex-wrap:wrap">
- <p :style="`margin-right: 5px;width:25px;text-align: center;color:${item.role === '备选' && picks.female.includes(index) ? '#67c23a' : ''}`" v-for="(power, index) in item.gender.female">{{ power }}</p>
- </div>
- </div>
- </div>
- </uni-td>
-
-
- <!-- <uni-td> -->
-
- <!-- </uni-td> -->
- </uni-tr>
- </uni-table>
-
- <!-- <div style="border:1px #ebeef5 solid;padding: 10px;text-align:center;color:#909399;margin-top:-1px" v-if="com">
- 暂无数据
- </div -->
- <view class="section" v-if="outputData.length > 0" style="flex: 1;margin-bottom: 0px">
- <div style="display: flex;justify-content: space-between;margin-top:10px">
- <text class="section-title" style="color: #303133;font-weight: 500;">最佳搭配方案</text>
- <text style="color:red">差额:{{ powerDifference }}</text>
- </div>
- <uni-table border stripe style="width:100%">
- <uni-tr class="has-bg" style="background: #f2f2f2">
- <uni-th align="left" width="65px">
- <div style="display: flex;flex-direction: column;border-bottom: 0px !important;position: absolute;top:26px;left: 2px;width:62px;background: #f5f7fa;">
- <p style="text-wrap:nowrap;text-align:center;color:#989ba1">角色</p>
- <!-- <p style="text-align:center">—</p> -->
- </div>
- </uni-th>
- <uni-th align="left" style="border-right:0px !important">
- <div style="display: flex;flex-direction: column;">
- <p style="text-align:left;color:#989ba1">搭配结果</p>
- <div style="position: absolute;height:42px;left:223px;background:#f5f7fa;top:1px;width:10px"></div>
- </div>
- </uni-th>
- <uni-th align="left" style="border-left:0px !important"></uni-th>
- </uni-tr>
-
- <div class="uni-table-tr no-padding" style="display: table-row;">
- <uni-th align="left" width="50px">
- </uni-th>
- <!-- <uni-th align="center" width="70px"></uni-th> -->
- <uni-th :width="1000 + 'px'" class="uni-table-th table--border no-padding" style="text-align: left;color:#989ba1;">
- {{ outputData[1].femalePowers.length }}对
- </uni-th>
-
- <uni-th :width="1000 + 'px'" class="uni-table-th table--border no-padding" style="text-align: left;color:#989ba1">
- {{ outputData[1].malePowers.length }}对
- </uni-th>
- </div>
-
- <!-- 表格数据行 -->
- <uni-tr v-for="(item, index) in outputData" :key="index">
- <uni-td width="50px" >
- <div style="display: flex;flex-direction: column;">
- <p style="text-wrap:nowrap;text-align:center">{{ item.role }}</p>
- <!-- <p style="text-align:center">—</p> -->
- <p style="text-align:center">{{ item.role === '目标' ? totalTarget : totalPick }}</p>
- </div>
- </uni-td>
-
- <uni-td >
- <div style="display: flex;">
- <!-- <p style="width: 25px;min-width:25px">{{ index === 0 ? '公' : '母' }}:</p> -->
-
- <div style="display:flex;flex-wrap:wrap">
- <p :style="`margin-right: 5px;width:25px;text-align: center;color: ${index === 0 ? 'rgb(103, 194, 58)' : '#e6a23c'}`" v-for="power in (index ===0 ? item.malePowers : item.femalePowers)">{{ power }}</p>
- </div>
- </div>
- </uni-td>
-
- <uni-td>
- <div style="display: flex;">
- <!-- <p style="width: 25px;min-width:25px">{{ index === 0 ? '母' : '公' }}:</p> -->
-
- <div style="display:flex;flex-wrap:wrap">
- <p :style="`margin-right: 5px;width:25px;text-align: center;color: ${index === 1 ? 'rgb(103, 194, 58)' : '#e6a23c'}`" v-for="power in (index === 0 ? item.femalePowers : item.malePowers)">{{ power }}</p>
- </div>
- </div>
- </uni-td>
- </uni-tr>
- </uni-table>
- </view>
- </div>
- <uni-popup ref="batchRef" :is-mask-click="false">
- <div
- style="display: flex;flex-direction: column;justify-content: center;padding: 10px; width: 95%;background: #fff;border-radius: 10px;padding: 10px;">
- <div style="display: flex;justify-content: space-between;align-items: center;margin-bottom: 10px;">
- <h4 style="margin-bottom: 10px"> 编辑{{ role }}</h4>
- <uni-icons type="closeempty" size="18" @click="batchRef.close()"></uni-icons>
- </div>
- <div style="display: flex;justify-content: space-between; align-items: center;">
- <span class="dialog-title">猫咪势力(公)</span>
- <uni-icons type="close" size="18" @click="malePowers = ''"></uni-icons>
- </div>
- <textarea v-model="malePowers" placeholder="用逗号或顿号隔开,如:200,150,100"
- style="height: 70px;border: 1px solid #dfe2e5" />
- <div style="display: flex;justify-content: space-between; align-items: center;">
- <span class="dialog-title">猫咪势力(母)</span>
- <uni-icons type="close" size="18" @click="feMalePowers = ''"></uni-icons>
- </div>
- <textarea v-model="feMalePowers" placeholder="用逗号或顿号隔开,如:200,150,100"
- style="height: 70px;border: 1px solid #dfe2e5" />
- <div style="display: flex;justify-content: flex-end;">
- <button size='mini' type="primary" @click="handleConfirm">保存</button>
- </div>
- </div>
- </uni-popup>
- <uni-popup ref="messageRef" type="message">
- <uni-popup-message type="error" :message="messageText" :duration="5000"></uni-popup-message>
- </uni-popup>
- <uni-popup ref="helpRef" :is-mask-click="false">
- <div class="help-modal"
- style="display: flex; justify-content: center;flex-direction: column;padding: 10px; width: 90vw;background: #fff;border-radius: 10px;padding: 30px;box-sizing: border-box;">
- <div style="display: flex;justify-content: space-between;align-items: center;margin-bottom: 10px;">
- <span></span>
- <h4 style="margin-bottom: 10px">使用说明</h4>
- <uni-icons type="closeempty" size="18" @click="helpRef.close()"></uni-icons>
- </div>
- <div style="margin-bottom: 10px;">
- “喵缘礼堂”是一款专注于为猫咪结婚提供解决方案的应用。它以所有目标角色猫咪的势力总和作为基准,通过筛选备选角色猫咪,为用户匹配出其势力总和最接近目标角色猫咪势力总和的方案。
- </div>
- <div>
- <p style="font-weight: bold;margin-bottom: 10px">使用方法:</p>
- <p style="margin-bottom: 10px">1.录入目标猫咪势力数据,总数≤20 只,依次准确填写。</p>
- <p style="margin-bottom: 10px">2.输入备选猫咪势力数据,不同性别数均≤20 只,详细填写。</p>
- <p>3.点击 “计算最佳匹配方案”,系统将据此算出最适配方案。</p>
- </div>
- </div>
- </uni-popup>
- <div class="loading" v-if="loading">
- <div class="loading-wrapper">
- <image src="./cat-load.gif" style="width:260px;height:260px" />
- </div>
- </div>
- </view>
- </template>
- <script setup>
- import { ref, computed, onMounted, nextTick } from 'vue';
- const helpRef = ref(null)
- const messageText = ref('')
- const messageRef = ref(null)
- const loading = ref(false)
- const isMockData = ref(false)
- const index = ref(-1)
- const time = ref("")
- const role = ref("")
- const type = ref('')
- const gender = ref("")
- const powers = ref("")
- const malePowers = ref('')
- const feMalePowers = ref('')
- const totalTarget = ref(0)
- const totalBackup = ref(0)
- const totalPick = ref(0)
- const picks = ref({
- male: [],
- female: []
- })
- const isShow = ref(true)
- setInterval(() => {
- isShow.value = false
-
- nextTick(() => isShow.value = true)
- }, 10000)
- const mockData = [
- {
- role: '目标', num: 11, gender: '公',
- power: '153, 91, 77, 138, 90, 80, 60, 54, 52, 52, 52'
- },
- {
- role: '目标', num: 9, gender: '母',
- power: '121, 118, 115, 86, 84, 84, 59, 53, 51'
- },
- {
- role: '备选', num:12, gender: '公',
- power: '174, 152, 147, 102, 101, 98, 98, 97, 62, 60, 58, 19'
- },
- {
- role: '备选', num: 20, gender: '母',
- power: '180, 165, 158, 154, 152, 151, 150, 150, 102, 101, 101, 93, 61, 30, 30, 29, 29, 29, 27, 10'
- }
- ]
- const mockOutData = [
- {
- "role": "目标",
- "malePowers": [
- "153",
- " 138",
- " 91",
- " 90",
- " 80",
- " 77",
- " 60",
- " 54",
- " 52",
- " 52",
- " 52"
- ],
- "femalePowers": [
- "121",
- " 118",
- " 115",
- " 86",
- " 84",
- " 84",
- " 59",
- " 53",
- " 51"
- ]
- },
- {
- "role": "备选",
- "malePowers": [
- 102,
- 101,
- 98,
- 98,
- 97,
- 62,
- 60,
- 58,
- 19
- ],
- "femalePowers": [
- 180,
- 165,
- 158,
- 154,
- 101,
- 93,
- 29,
- 29,
- 29,
- 27,
- 10
- ]
- }
- ]
- const inputData = ref([
- { role: '目标', num: 0, gender: '公', power: '' },
- { role: '目标', num: 0, gender: '母', power: '' },
- { role: '备选', num: 0, gender: '公', power: '' },
- { role: '备选', num: 0, gender: '母', power: '' }
- ]);
- const computedInputData = computed(() => {
- const target = inputData.value.slice(0, 2)
- const backup = inputData.value.slice(2)
-
-
- return [
- {
- role: '目标',
- gender: {
- male: target[0].power.split(',').filter(item => !!item).sort((a, b) => b - a),
- female: target[1].power.split(',').filter(item => !!item).sort((a, b) => b - a),
- }
- },
- {
- role: '备选',
- gender: {
- male: backup[0].power.split(',').filter(item => !!item).sort((a, b) => b - a),
- female: backup[1].power.split(',').filter(item => !!item).sort((a, b) => b - a),
- }
- }
- ]
- })
- const computedOutputData = computed(() => {
- console.log(outputData.value)
- })
-
- const outputData = ref([]);
- const batchRef = ref(null)
- function editRow(_role) {
- type.value = 'edit'
- role.value = _role
- // index.value = _index
- if(_role === '目标'){
-
- inputData.value[1].power = inputData.value[1].power.split(',').sort((a,b) => b - a).join(',')
- inputData.value[0].power = inputData.value[0].power.split(',').sort((a,b) => b - a).join(',')
-
- feMalePowers.value = inputData.value[1].power
- malePowers.value = inputData.value[0].power
- } else {
- inputData.value[3].power = inputData.value[3].power.split(',').sort((a,b) => b - a).join(',')
- inputData.value[2].power = inputData.value[2].power.split(',').sort((a,b) => b - a).join(',')
- feMalePowers.value = inputData.value[3].power
- malePowers.value = inputData.value[2].power
- }
- batchRef.value.open()
- }
- function viewExplam(){
- if(!isMockData.value){
- inputData.value = JSON.parse(JSON.stringify(mockData))
- outputData.value = JSON.parse(JSON.stringify(mockOutData))
- totalTarget.value = 1670
- totalBackup.value = 3070
- totalPick.value = 1670
-
-
- picks.value = {
- "male": [
- 3,
- 4,
- 5,
- 6,
- 7,
- 8,
- 9,
- 10,
- 11
- ],
- "female": [
- 0,
- 1,
- 2,
- 3,
- 9,
- 11,
- 15,
- 16,
- 17,
- 18,
- 19
- ]
- }
-
- } else {
- picks.value = { male: [], female: [] }
- inputData.value = [
- { role: '目标', num: 0, gender: '公', power: '' },
- { role: '目标', num: 0, gender: '母', power: '' },
- { role: '备选', num: 0, gender: '公', power: '' },
- { role: '备选', num: 0, gender: '母', power: '' }
- ]
- outputData.value = []
- totalTarget.value = 0
- totalBackup.value = 0
- }
-
- isMockData.value = !isMockData.value
- }
- function switchRoles(){
- outputData.value = []
- const [t1, t2, b1, b2] = inputData.value
-
- picks.value.male = []
- picks.value.female = []
-
- const temp = totalBackup.value
- totalBackup.value = totalTarget.value
- totalTarget.value = temp
-
- inputData.value[0] = { ...b1 }
- inputData.value[1] = { ...b2 }
- inputData.value[2] = { ...t1 }
- inputData.value[3] = { ...t2 }
-
- isMockData.value = false
- }
- const powerDifference = ref(0)
- function isPositiveInteger(str) {
- return /^[1-9]\d*$/.test(str);
- }
- function generatePowers(){
- const melePowers = malePowers.value.replace(/,|、|,/g, ',')
- const femalePowers = feMalePowers.value.replace(/,|、|,/g, ',')
-
- const malePowerSet = melePowers.split(',').map(item => item.trim()).filter(item => item !== '')
- const femalePowerSet = femalePowers.split(',').map(item => item.trim()).filter(item => item !== '')
-
- const isOk = malePowerSet.every(num => isPositiveInteger(num))
- const isFeOk = femalePowerSet.every(num => isPositiveInteger(num))
- if ((!isOk && malePowerSet.length !== 0) && (!isFeOk && femalePowerSet.length === 0)) return false
-
-
- const isTaget = role.value === '目标'
-
-
- if(isTaget){
- if(malePowerSet.length + femalePowerSet.length > 20){
- messageRef.value.close()
- messageRef.value.open()
- messageText.value = '目标角色总数不能超过20只'
- return 'overflow'
- }
-
- inputData.value[0].num = malePowerSet.length;
- inputData.value[0].power = malePowerSet.join(',')
- inputData.value[1].num = femalePowerSet.length;
- inputData.value[1].power = femalePowerSet.join(',')
- const total1 = inputData.value[0].power.split(',').reduce((prev, current) => Number(current) + prev, 0)
- const total2 = inputData.value[1].power.split(',').reduce((prev, current) => Number(current) + prev, 0)
- totalTarget.value = total1 + total2
- } else {
- if(malePowerSet.length === 0 && femalePowerSet.length === 0){
- messageRef.value.close()
- messageRef.value.open()
- messageText.value = '至少输入一个势力!'
- return 'overflow'
- }
-
- inputData.value[2].num = malePowerSet.length;
- inputData.value[2].power = malePowerSet.join(',')
- inputData.value[3].num = femalePowerSet.length;
- inputData.value[3].power = femalePowerSet.join(',')
- const total1 = inputData.value[2].power.split(',').reduce((prev, current) => Number(current) + prev, 0)
- const total2 = inputData.value[3].power.split(',').reduce((prev, current) => Number(current) + prev,0)
- totalBackup.value = total1 + total2
- }
- }
- function handleConfirm(){
- messageRef.value.close()
- const isMaleOk = generatePowers()
- const isFemaleOk = generatePowers()
-
- if(isMaleOk === 'overflow'){ return }
-
-
- if (typeof isMaleOk === 'boolean' && !isMaleOk){
- messageRef.value.close()
- messageRef.value.open()
- messageText.value = '势力必须为数字'
- return
- } else if (typeof isFemaleOk === 'boolean' && !isFemaleOk) {
- messageRef.value.close()
- messageRef.value.open()
- messageText.value = '势力必须为数字'
- return
- }
- outputData.value = []
- picks.value.male = []
- picks.value.female = []
- batchRef.value.close()
-
- isMockData.value = false
- }
- function adLoad() {
- console.log('原生模板广告加载成功')
- }
-
- function adError(err) {
- console.error('原生模板广告加载失败', err)
- }
-
- function adClose() {
- console.log('原生模板广告关闭')
- }
- // 生成数组的所有组合(辅助函数,用于生成指定个数元素的组合情况)
- function getCombinations(arr, num) {
- const result = [];
- if (num === 0) { return [[]]; }
- for (let i = 0; i < arr.length; i++) {
- const element = arr[i];
- const remainingCombos = getCombinations(arr.slice(i + 1), num - 1);
- for (const combo of remainingCombos) {
- result.push([element].concat(combo));
- }
- }
- return result;
- }
- function stop(delay) {
- return new Promise((resolve) => setTimeout(() => { resolve(true) }, delay))
- }
- let videoAd = null
- if (process.env.UNI_PLATFORM.toUpperCase() === 'MP-WEIXIN') {
- if (wx.createRewardedVideoAd) {
- videoAd = wx.createRewardedVideoAd({
- adUnitId: 'adunit-c90f984d29d8d175'
- })
- videoAd.onLoad(() => {
- loading.value = false
- console.log('激励视频家加载....')
- })
- videoAd.onError((err) => {
- loading.value = false
- console.error('激励视频光告加载失败', err)
- })
- }
-
- }
- function onShareAppMessage(res){
- return{
- title:"喵缘礼堂",
- path:"/pages/index/index",
- imageUrl:"https://example.com/share-image.png",
- }
- }
-
- function onShareTimeline(res){
- return{
- title:"喵缘礼堂",
- query:"path/to/page?param=value",
- imageUrl:"https://example.com/share-timeline-image.png"
- }
- }
- function calculateBestMatch() {
- // loading.value = true
- if (outputData.value.length !== 0) {
- loading.value = false
- messageRef.value.open()
- messageText.value = '请编辑猫咪势力后,再匹配方案'
- return
- }
- const result = handleDataSync()
- if(!result){ return }
-
- if (process.env.UNI_PLATFORM.toUpperCase() === 'MP-WEIXIN') {
- videoAd.onClose((res) => {
- if(res.isEnded){
- console.log('加载完成', result)
- outputData.value = result
- } else {
- picks.value.male = []
- picks.value.female = []
- outputData.value = []
- }
- })
-
- // 用户触发广告后,显示激励视频广告
- if (videoAd) {
- videoAd.show().catch((res) => {
- // 失败重试
- videoAd.load()
- .then(() => {
- console.log('拉取失败')
- loading.value = false
- videoAd.show()
- })
- .catch(err => {
- console.error('激励视频 广告显示失败', err)
- loading.value = false
- })
- })
- }
- } else {
- outputData.value = result
- loading.value = false
- }
-
- }
- function handleDataSync(){
- let startTime = new Date().getTime()
- let endTime = null
-
- outputData.value = []
-
- const targetMale = inputData.value[0].power.split(',').filter(item => item !== '').map(Number)
- const targetFemale = inputData.value[1].power.split(',').filter(item => item !== '').map(Number)
- const backupMale = inputData.value[2].power.split(',').filter(item => item !== '').map(Number)
- const backupFemale = inputData.value[3].power.split(',').filter(item => item !== '').map(Number)
-
- if (targetMale.length === 0 && targetFemale.length === 0) {
- loading.value = false
- messageRef.value.open()
- messageText.value = '至少输入一个势力!'
- return
- }
-
- if(targetFemale.length + targetFemale.length > 20){
- loading.value = false
- messageRef.value.open()
- messageText.value = '目标角色的猫咪总数不能超过20只!'
- return
- }
-
- if(backupMale.length > 20){
- loading.value = false
- messageRef.value.open()
- messageText.value = '备选角色的公猫咪不能超过20只!'
- return
- }
-
- if(backupFemale.length > 20){
- loading.value = false
- messageRef.value.open()
- messageText.value = '备选角色的母猫咪不能超过20只!'
- return
- }
-
-
- if (targetFemale.length > backupMale.length && backupMale.length !== 0){
- loading.value = false
- messageRef.value.open()
- messageText.value = '备选角色的公猫咪数量应不少于目标角色的母猫咪数量!'
- return
- }
-
- if (targetMale.length > backupFemale.length && backupFemale.length !== 0) {
- loading.value = false
- messageRef.value.open()
- messageText.value = '备选角色的母猫咪数量应不少于目标角色的公猫咪数量!'
- return
- }
-
-
- const targetMaleLen = targetMale.length;
- const targetFemaleLen = targetFemale.length;
-
-
- let targetWeight = 0
- if (backupMale.length === 0){
- targetWeight = targetMale.reduce((acc, val) => acc + val, 0);
- } else if(backupFemale.length === 0){
- targetWeight = targetFemale.reduce((acc, val) => acc + val, 0)
- } else if(backupMale.length !== 0 && backupFemale.length !== 0){
- targetWeight = targetMale.reduce((acc, val) => acc + val, 0) + targetFemale.reduce((acc, val) => acc + val, 0);
- }
-
- let minDifference = Infinity;
- let bestfemaleCombination = null;
- let bestMaleCombination = null;
- const femaleCombinations = getCombinations(backupFemale, targetMaleLen);
- const maleCombinations = getCombinations(backupMale, targetFemaleLen);
-
- if (femaleCombinations.length !== 0 && maleCombinations.length !== 0){
- for (const femaleComb of femaleCombinations) {
- for (const maleComb of maleCombinations) {
- const totalWeight = femaleComb.reduce((acc, val) => acc + val, 0) + maleComb.reduce((acc, val) => acc + val, 0);
- const difference = Math.abs(totalWeight - targetWeight);
- if (difference < minDifference) {
- minDifference = difference;
- bestfemaleCombination = femaleComb;
- bestMaleCombination = maleComb;
- if (minDifference == 0) {
- break;
- }
- }
- }
- }
- }
-
-
- // 备选数据的母为空
- if (femaleCombinations.length === 0 && maleCombinations.length !== 0) {
- for (const maleComb of maleCombinations) {
- const totalWeight = maleComb.reduce((acc, val) => acc + val , 0);
- const difference = Math.abs(totalWeight - targetWeight);
- if (difference < minDifference) {
- minDifference = difference;
- bestMaleCombination = maleComb;
- if (minDifference == 0) {
- break;
- }
- }
- }
- }
-
- // 备选数据的公为空
- if (femaleCombinations.length !== 0 && maleCombinations.length === 0) {
- for (const femaleComb of femaleCombinations) {
- const totalWeight = femaleComb.reduce((acc, val) => acc + val, 0)
- const difference = Math.abs(totalWeight - targetWeight);
- if (difference < minDifference) {
- minDifference = difference;
- bestfemaleCombination = femaleComb;
- // bestMaleCombination = maleComb;
- if (minDifference == 0) {
- break;
- }
- }
- }
- }
-
- 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 }
-
- const result = [
- {
- role: '目标',
- malePowers: computedInputData.value[0].gender.male.sort((a, b) => b - a),
- femalePowers: computedInputData.value[0].gender.female.sort((a, b) => b - a),
- },
- {
- role: '备选',
- malePowers: bestMaleCombination.sort((a, b) => b - a),
- femalePowers: bestfemaleCombination.sort((a, b) => b - a),
- }
- ]
-
-
- bestMaleCombination.forEach(power => {
- const index = backupMale.findIndex(p => p === power)
- backupMale[index] = null
- picks.value.male.push(index)
- })
-
-
- bestfemaleCombination.forEach(power => {
- const index = backupFemale.findIndex(p => p === power)
- backupFemale[index] = null
- picks.value.female.push(index)
- })
-
-
- totalPick.value = bestfemaleCombination.reduce((prev, current) => Number(current) + prev, 0)
- totalPick.value += bestMaleCombination.reduce((prev, current) => Number(current) + prev, 0)
-
-
- powerDifference.value = totalTarget.value - totalPick.value
- endTime = new Date().getTime()
- time.value = endTime - startTime
-
- return result
- // resolve(result)
- }
- function handleData(){
- return new Promise(async (resolve) => {
- setTimeout(async () => {
-
- let startTime = new Date().getTime()
- let endTime = null
-
- outputData.value = []
-
- const targetMale = inputData.value[0].power.split(',').filter(item => item !== '').map(Number)
- const targetFemale = inputData.value[1].power.split(',').filter(item => item !== '').map(Number)
- const backupMale = inputData.value[2].power.split(',').filter(item => item !== '').map(Number)
- const backupFemale = inputData.value[3].power.split(',').filter(item => item !== '').map(Number)
-
- if (targetMale.length === 0 && targetFemale.length === 0) {
- loading.value = false
- messageRef.value.open()
- messageText.value = '至少输入一个势力!'
- return
- }
-
- if(targetFemale.length + targetFemale.length > 20){
- loading.value = false
- messageRef.value.open()
- messageText.value = '目标角色的猫咪总数不能超过20只!'
- return
- }
-
- if(backupMale.length > 20){
- loading.value = false
- messageRef.value.open()
- messageText.value = '备选角色的公猫咪不能超过20只!'
- return
- }
-
- if(backupFemale.length > 20){
- loading.value = false
- messageRef.value.open()
- messageText.value = '备选角色的母猫咪不能超过20只!'
- return
- }
-
-
- if (targetFemale.length > backupMale.length && backupMale.length !== 0){
- loading.value = false
- messageRef.value.open()
- messageText.value = '备选角色的公猫咪数量应不少于目标角色的母猫咪数量!'
- return
- }
-
- if (targetMale.length > backupFemale.length && backupFemale.length !== 0) {
- loading.value = false
- messageRef.value.open()
- messageText.value = '备选角色的母猫咪数量应不少于目标角色的公猫咪数量!'
- return
- }
-
-
- const targetMaleLen = targetMale.length;
- const targetFemaleLen = targetFemale.length;
-
-
- let targetWeight = 0
- if (backupMale.length === 0){
- targetWeight = targetMale.reduce((acc, val) => acc + val, 0);
- } else if(backupFemale.length === 0){
- targetWeight = targetFemale.reduce((acc, val) => acc + val, 0)
- } else if(backupMale.length !== 0 && backupFemale.length !== 0){
- targetWeight = targetMale.reduce((acc, val) => acc + val, 0) + targetFemale.reduce((acc, val) => acc + val, 0);
- }
-
- let minDifference = Infinity;
- let bestfemaleCombination = null;
- let bestMaleCombination = null;
- const femaleCombinations = getCombinations(backupFemale, targetMaleLen);
- const maleCombinations = getCombinations(backupMale, targetFemaleLen);
-
- if (femaleCombinations.length !== 0 && maleCombinations.length !== 0){
- for (const femaleComb of femaleCombinations) {
- for (const maleComb of maleCombinations) {
- const totalWeight = femaleComb.reduce((acc, val) => acc + val, 0) + maleComb.reduce((acc, val) => acc + val, 0);
- const difference = Math.abs(totalWeight - targetWeight);
- if (difference < minDifference) {
- minDifference = difference;
- bestfemaleCombination = femaleComb;
- bestMaleCombination = maleComb;
- if (minDifference == 0) {
- break;
- }
- }
- }
- }
- }
-
-
- // 备选数据的母为空
- if (femaleCombinations.length === 0 && maleCombinations.length !== 0) {
- for (const maleComb of maleCombinations) {
- const totalWeight = maleComb.reduce((acc, val) => acc + val , 0);
- const difference = Math.abs(totalWeight - targetWeight);
- if (difference < minDifference) {
- minDifference = difference;
- bestMaleCombination = maleComb;
- if (minDifference == 0) {
- break;
- }
- }
- }
- }
-
- // 备选数据的公为空
- if (femaleCombinations.length !== 0 && maleCombinations.length === 0) {
- for (const femaleComb of femaleCombinations) {
- const totalWeight = femaleComb.reduce((acc, val) => acc + val, 0)
- const difference = Math.abs(totalWeight - targetWeight);
- if (difference < minDifference) {
- minDifference = difference;
- bestfemaleCombination = femaleComb;
- // bestMaleCombination = maleComb;
- if (minDifference == 0) {
- break;
- }
- }
- }
- }
-
- 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 }
-
-
- loading.value = false
-
-
- const result = [
- {
- role: '目标',
- malePowers: computedInputData.value[0].gender.male.sort((a, b) => b - a),
- femalePowers: computedInputData.value[0].gender.female.sort((a, b) => b - a),
- },
- {
- role: '备选',
- malePowers: bestMaleCombination.sort((a, b) => b - a),
- femalePowers: bestfemaleCombination.sort((a, b) => b - a),
- }
- ]
-
-
-
- bestMaleCombination.forEach(power => {
- const index = backupMale.findIndex(p => p === power)
- backupMale[index] = null
- picks.value.male.push(index)
- })
-
-
- bestfemaleCombination.forEach(power => {
- const index = backupFemale.findIndex(p => p === power)
- backupFemale[index] = null
- picks.value.female.push(index)
- })
-
-
- totalPick.value = bestfemaleCombination.reduce((prev, current) => Number(current) + prev, 0)
- totalPick.value += bestMaleCombination.reduce((prev, current) => Number(current) + prev, 0)
-
-
- powerDifference.value = totalTarget.value - totalPick.value
- endTime = new Date().getTime()
- time.value = endTime - startTime
-
- resolve(result)
- }, 0)
- })
- }
- const width = ref(0)
- function getInner(){
- uni.getSystemInfo({
- success: function (res) {
- const windowWidth = res.windowWidth; // 窗口宽度
- width.value = (windowWidth - 40 - 85) / 2
- }
- });
- }
- onMounted(() => {
- getInner()
- })
- // uni.onWindowResize(getInner)
- viewExplam()
- </script>
- <style>
- </style>
- <style>
- /* uni-button {
- margin: 2px !important;
- }
- */
- uni-button::after {
- /* display: none; */
- /* border: 0px solid rgb(224.6, 242.8, 215.6) !important; */
- /* border: 2px solid transparent !important; */
- }
- button {
- border: none !important;
- background: rgb(239.8, 248.9, 235.3) !important;
- color: #67c23a !important;
- outline: none !important;
- }
-
- .primary-btn {
- }
-
-
- .no-padding .uni-table-th {
- padding: 0px !important;
- padding-left: 10px !important;
- }
-
- .uni-table-th {
- background: #f5f7fa !important;
- /* margin-left: -1px !important; */
- /* border: 1px solid rgb(226, 226, 226) !important; */
- /* margin-bottom: -1px !important; */
- }
-
- .uni-table-td {
- /* border: 1px solid rgb(226, 226, 226) !important; */
- }
- .edit-button {
- color: #409eff !important;
- cursor: pointer;
- }
-
- textarea {
- font-size: 13px;
- padding: 8px;
- }
-
- .text-power {
- overflow-wrap: anywhere;
- text-wrap: wrap;
- }
-
- .help-modal {
- line-height: 24px;
- color: #2c3e50;
- }
-
- .u-table{
- display: flex;
- flex-direction: column;
- width: 100%;
- height: 80px;
- justify-content: flex-start;
- font-size: 14px !important;
- height: auto;
- border-top: 1px solid #ebeef5;
- border-left: 1px solid #ebeef5;
- /* background: red */
- }
- .u-table-tr {
- display: flex;
- color: #909399;
- height: 40px !important;
- margin-top: -1px;
- }
- .u-table-body {
- height: calc(100% - 80px);
- overflow: auto;
- }
- .u-table-th {
- display: flex;
- border: 1px solid #ebeef5;
- padding: 8px 10px;
- margin-left: -1px;
- font-weight: bold;
- }
- .u-table-td {
- display: flex;
- border: 1px solid #ebeef5;
- padding: 8px 10px;
- margin-left: -1px;
- }
- .u-table-th-custom {
- display: flex;
- border: 1px solid #ebeef5;
- margin-left: -1px;
- }
-
- .edit-btn {
- padding: 0px !important;
- border: 0px !important;
- display: block;
- background: #fff !important;
- }
- .edit-btn:after {
- border: 0px !important;
- }
- @keyframes spin {
- 0% { transform: rotate(0deg); }
- 100% { transform: rotate(360deg); }
- }
- .loader {
- animation: spin 2s linear infinite; /* 应用旋转动画 */
- }
- textarea {
- font-size: 13px;
- padding: 8px;
- }
-
- .uni-table-loading {
- display: none !important;
- }
- </style>
- <style lang="scss" scoped>
-
- button {
- height: 30px;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14px;
- text-wrap: nowrap !important;
-
- width: 85px;
- // padding: 13px 10px;
- }
- .dialog-title {
- line-height: 30px;
- padding-left: 10px;
- font-size: 14px;
- }
- .table-wrapper {
- font-size: 14px !important;
- }
- .custom-picker {
- border: 1px solid #e3e3e3;
- padding: 3px 5px;
- text-align: center;
- width: 100%;
-
-
- div {
- display: flex;
- justify-content: space-between;
-
- text {
- overflow: hidden;
- white-space: nowrap;
- text-overflow: ellipsis;
- }
- }
- }
- .container {
- padding: 10px 20px;
- }
- .section {
- margin-bottom: 20px;
- }
- .section-title {
- font-size: 18px;
- font-weight: bold;
- margin-bottom: 10px;
- text-wrap: nowrap;
- }
- .input {
- width: 100%;
- text-align: center;
- border: 1px solid #ddd;
- padding: 5px;
- }
- button {
- margin: 5px;
- }
- .add-btn,
- .calculate-btn {
- background-color: #007bff;
- color: white;
- padding: 10px;
- font-size: 16px;
- text-align: center;
- border-radius: 5px;
- }
- .delete-btn {
- background-color: #ff4d4f;
- color: white;
- padding: 5px;
- font-size: 14px;
- border-radius: 5px;
- }
- .summary {
- margin-top: 20px;
- font-size: 14px;
- text-align: right;
- font-weight: bold;
- }
- .loading {
- position: fixed;
- top: 0px;
- left: 0px;
- width: 100vw;
- height: 100vh;
- background: rgba(0, 0, 0, .6);
- display: flex;
- justify-content: center;
- align-items: center;
- .loading-wrapper {
- height: 260px;
- width: 260px;
- border-radius: 100%;
- overflow: hidden;
- display: flex;
- justify-content: center;
- align-items: center;
- img {
- height: 260px;
- width: 260px;
- }
- }
- }
- .uni-table-th-content {
- text-wrap: nowrap;
- }
- .uni-table-loading {
- display: block !important;
- }
- .uni-table-scroll {
- border: 1px solid #EBEEF5;
- }
- </style>
|