如何用 Deepseek 寫(xiě)的uniapp血型遺傳查詢(xún)工具
引言
在現(xiàn)代社會(huì)中,了解血型遺傳規(guī)律對(duì)于優(yōu)生優(yōu)育、醫(yī)療健康等方面都有重要意義。本文將介紹如何使用Uniapp開(kāi)發(fā)一個(gè)跨平臺(tái)的血型遺傳查詢(xún)工具,幫助用戶(hù)預(yù)測(cè)孩子可能的血型。
一、血型遺傳基礎(chǔ)知識(shí)
人類(lèi)的ABO血型系統(tǒng)由三個(gè)等位基因決定:IA、IB和i。其中IA和IB對(duì)i是顯性關(guān)系:
- A型血基因型:IAIA或IAi
- B型血基因型:IBIB或IBi
- AB型血基因型:IAIB
- O型血基因型:ii
根據(jù)孟德?tīng)栠z傳定律,孩子的血型由父母雙方各提供一個(gè)等位基因組合而成。
二、Uniapp開(kāi)發(fā)優(yōu)勢(shì)
選擇Uniapp開(kāi)發(fā)這款工具主要基于以下優(yōu)勢(shì):
- 跨平臺(tái)能力:一次開(kāi)發(fā),可發(fā)布到iOS、Android、H5及各種小程序平臺(tái)
- 開(kāi)發(fā)效率高:基于Vue.js框架,學(xué)習(xí)成本低,開(kāi)發(fā)速度快
- 性能優(yōu)良:接近原生應(yīng)用的體驗(yàn)
- 生態(tài)豐富:擁有完善的插件市場(chǎng)和社區(qū)支持
三、核心代碼解析
1. 血型遺傳算法實(shí)現(xiàn)
getPossibleGenotypes(parent1, parent2) { // 血型對(duì)應(yīng)的可能基因型 const typeToGenotypes = { 'A': ['AA', 'AO'], 'B': ['BB', 'BO'], 'AB': ['AB'], 'O': ['OO'] } const parent1Genotypes = typeToGenotypes[parent1] const parent2Genotypes = typeToGenotypes[parent2] const possibleGenotypes = [] // 生成所有可能的基因組合 for (const g1 of parent1Genotypes) { for (const g2 of parent2Genotypes) { // 每個(gè)父母貢獻(xiàn)一個(gè)等位基因 for (let i = 0; i < 2; i++) { for (let j = 0; j < 2; j++) { const childGenotype = g1[i] + g2[j] possibleGenotypes.push(childGenotype) } } } } return possibleGenotypes }
這段代碼實(shí)現(xiàn)了血型遺傳的核心算法,通過(guò)遍歷父母可能的基因型組合,計(jì)算出孩子所有可能的基因型。
2. 概率計(jì)算
calculateProbabilities(genotypes) { const bloodTypeCounts = { 'A': 0, 'B': 0, 'AB': 0, 'O': 0 } // 基因型到血型的映射 const genotypeToType = { 'AA': 'A', 'AO': 'A', 'BB': 'B', 'BO': 'B', 'AB': 'AB', 'OO': 'O' } // 統(tǒng)計(jì)每種血型的出現(xiàn)次數(shù) for (const genotype of genotypes) { const type = genotypeToType[genotype] bloodTypeCounts[type]++ } const total = genotypes.length const probabilities = {} // 計(jì)算概率 for (const type in bloodTypeCounts) { const count = bloodTypeCounts[type] if (count > 0) { probabilities[type] = (count / total * 100).toFixed(1) } } return probabilities }
這部分代碼統(tǒng)計(jì)各種血型出現(xiàn)的頻率,并計(jì)算出每種血型出現(xiàn)的概率百分比。
3. 界面交互實(shí)現(xiàn)
<view class="form-item"> <text class="label">父親血型:</text> <picker @change="bindParent1Change" :value="parent1Index" :range="bloodTypes" range-key="name"> <view class="picker"> {{bloodTypes[parent1Index].name}} </view> </picker> </view> <button class="calculate-btn" @click="calculateBloodType">計(jì)算孩子可能的血型</button>
使用Uniapp的picker組件實(shí)現(xiàn)血型選擇,通過(guò)按鈕觸發(fā)計(jì)算邏輯,界面簡(jiǎn)潔友好。
四、項(xiàng)目亮點(diǎn)
- 科學(xué)準(zhǔn)確性:嚴(yán)格遵循遺傳學(xué)原理,計(jì)算結(jié)果準(zhǔn)確可靠
- 用戶(hù)體驗(yàn)優(yōu)化:
- 結(jié)果自動(dòng)滾動(dòng)到可視區(qū)域
- 概率可視化展示
- 遺傳知識(shí)科普
- 代碼結(jié)構(gòu)清晰:
- 業(yè)務(wù)邏輯與UI分離
- 復(fù)用性高的工具函數(shù)
- 良好的代碼注釋
完整代碼
<template> <view class="container"> <view class="header"> <text class="title">血型遺傳查詢(xún)工具</text> </view> <view class="card"> <text class="subtitle">選擇父母血型</text> <view class="form-item"> <text class="label">父親血型:</text> <picker @change="bindParent1Change" :value="parent1Index" :range="bloodTypes" range-key="name"> <view class="picker"> {{bloodTypes[parent1Index].name}} </view> </picker> </view> <view class="form-item"> <text class="label">母親血型:</text> <picker @change="bindParent2Change" :value="parent2Index" :range="bloodTypes" range-key="name"> <view class="picker"> {{bloodTypes[parent2Index].name}} </view> </picker> </view> <button class="calculate-btn" @click="calculateBloodType">計(jì)算孩子可能的血型</button> </view> <view class="card result-card" v-if="showResult"> <text class="subtitle">結(jié)果</text> <text class="result-text">父母血型: {{parent1Name}} + {{parent2Name}}</text> <text class="result-text">孩子可能的血型: <text class="blood-type">{{resultText}}</text> </text> <text class="probability" v-if="probabilityText">{{probabilityText}}</text> </view> <view class="card note-card"> <text class="note-title">血型遺傳規(guī)律說(shuō)明:</text> <text class="note-text">? 血型由ABO基因決定,A和B是顯性基因,O是隱性基因。</text> <text class="note-text">? A型血基因型可能是AA或AO,B型血基因型可能是BB或BO。</text> <text class="note-text">? AB型血基因型是AB,O型血基因型是OO。</text> </view> </view> </template> <script> export default { data() { return { bloodTypes: [{ name: 'A型', value: 'A' }, { name: 'B型', value: 'B' }, { name: 'AB型', value: 'AB' }, { name: 'O型', value: 'O' } ], parent1Index: 0, parent2Index: 0, parent1Name: 'A型', parent2Name: 'A型', parent1Value: 'A', parent2Value: 'A', showResult: false, resultText: '', probabilityText: '' } }, methods: { bindParent1Change(e) { this.parent1Index = e.detail.value this.parent1Name = this.bloodTypes[this.parent1Index].name this.parent1Value = this.bloodTypes[this.parent1Index].value }, bindParent2Change(e) { this.parent2Index = e.detail.value this.parent2Name = this.bloodTypes[this.parent2Index].name this.parent2Value = this.bloodTypes[this.parent2Index].value }, calculateBloodType() { // 計(jì)算可能的基因組合 const possibleGenotypes = this.getPossibleGenotypes(this.parent1Value, this.parent2Value) // 計(jì)算可能的血型及其概率 const bloodTypeProbabilities = this.calculateProbabilities(possibleGenotypes) // 生成結(jié)果文本 let resultText = '' let probabilityText = '概率: ' let first = true for (const type in bloodTypeProbabilities) { if (!first) { resultText += '、' probabilityText += ',' } resultText += this.getBloodTypeName(type) probabilityText += `${this.getBloodTypeName(type)} ${bloodTypeProbabilities[type]}%` first = false } this.resultText = resultText this.probabilityText = probabilityText this.showResult = true // 滾動(dòng)到結(jié)果位置 uni.pageScrollTo({ scrollTop: 300, duration: 300 }) }, getBloodTypeName(type) { const names = { 'A': 'A型', 'B': 'B型', 'AB': 'AB型', 'O': 'O型' } return names[type] }, getPossibleGenotypes(parent1, parent2) { // 血型對(duì)應(yīng)的可能基因型 const typeToGenotypes = { 'A': ['AA', 'AO'], 'B': ['BB', 'BO'], 'AB': ['AB'], 'O': ['OO'] } const parent1Genotypes = typeToGenotypes[parent1] const parent2Genotypes = typeToGenotypes[parent2] const possibleGenotypes = [] // 生成所有可能的基因組合 for (const g1 of parent1Genotypes) { for (const g2 of parent2Genotypes) { // 每個(gè)父母貢獻(xiàn)一個(gè)等位基因 for (let i = 0; i < 2; i++) { for (let j = 0; j < 2; j++) { const childGenotype = g1[i] + g2[j] possibleGenotypes.push(childGenotype) } } } } return possibleGenotypes }, calculateProbabilities(genotypes) { const bloodTypeCounts = { 'A': 0, 'B': 0, 'AB': 0, 'O': 0 } // 基因型到血型的映射 const genotypeToType = { 'AA': 'A', 'AO': 'A', 'BB': 'B', 'BO': 'B', 'AB': 'AB', 'OO': 'O' } // 統(tǒng)計(jì)每種血型的出現(xiàn)次數(shù) for (const genotype of genotypes) { const type = genotypeToType[genotype] bloodTypeCounts[type]++ } const total = genotypes.length const probabilities = {} // 計(jì)算概率 for (const type in bloodTypeCounts) { const count = bloodTypeCounts[type] if (count > 0) { probabilities[type] = (count / total * 100).toFixed(1) } } return probabilities } } } </script> <style> .container { padding: 20rpx; } .header { margin: 30rpx 0; text-align: center; } .title { font-size: 40rpx; font-weight: bold; color: #333; } .card { background-color: #fff; border-radius: 16rpx; padding: 30rpx; margin-bottom: 30rpx; box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05); } .subtitle { font-size: 32rpx; font-weight: bold; margin-bottom: 30rpx; display: block; color: #333; } .form-item { margin-bottom: 30rpx; } .label { font-size: 28rpx; color: #666; margin-bottom: 10rpx; display: block; } .picker { height: 80rpx; line-height: 80rpx; padding: 0 20rpx; border: 1rpx solid #eee; border-radius: 8rpx; font-size: 28rpx; } .calculate-btn { background-color: #4CAF50; color: white; margin-top: 40rpx; border-radius: 8rpx; font-size: 30rpx; height: 90rpx; line-height: 90rpx; } .result-card { background-color: #e9f7ef; } .result-text { font-size: 28rpx; margin-bottom: 20rpx; display: block; } .blood-type { color: #e74c3c; font-weight: bold; } .probability { font-size: 26rpx; color: #666; display: block; margin-top: 10rpx; } .note-title { font-weight: bold; font-size: 28rpx; margin-bottom: 15rpx; display: block; color: #333; } .note-text { font-size: 26rpx; color: #666; display: block; margin-bottom: 10rpx; line-height: 1.6; } </style>
到此這篇關(guān)于用 Deepseek 寫(xiě)的uniapp血型遺傳查詢(xún)工具的文章就介紹到這了,更多相關(guān)Deepseek uniapp血型遺傳內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue2.0項(xiàng)目中使用Ueditor富文本編輯器示例代碼
本篇文章主要介紹了vue2.0項(xiàng)目中使用Ueditor富文本編輯器示例代碼,具有一定的參考價(jià)值,有興趣的可以了解一下2017-08-08使用vue3+TS實(shí)現(xiàn)簡(jiǎn)易組件庫(kù)的全過(guò)程
當(dāng)市面上主流的組件庫(kù)不能滿(mǎn)足我們業(yè)務(wù)需求的時(shí)候,那么我們就有必要開(kāi)發(fā)一套屬于自己團(tuán)隊(duì)的組件庫(kù),下面這篇文章主要給大家介紹了如何使用vue3+TS實(shí)現(xiàn)簡(jiǎn)易組件庫(kù)的相關(guān)資料,需要的朋友可以參考下2022-03-03Vue?設(shè)置圖片不轉(zhuǎn)為base64的方式
這篇文章主要介紹了Vue實(shí)現(xiàn)設(shè)置圖片不轉(zhuǎn)為base64的方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-02-02Vue.js組件使用開(kāi)發(fā)實(shí)例教程
Vue.js的組件可以理解為預(yù)先定義好了行為的ViewModel類(lèi)。這篇文章主要介紹了Vue.js組件使用開(kāi)發(fā)實(shí)例教程的相關(guān)資料,需要的朋友可以參考下2016-11-11vue發(fā)送驗(yàn)證碼計(jì)時(shí)器防止刷新實(shí)現(xiàn)詳解
這篇文章主要為大家介紹了vue發(fā)送驗(yàn)證碼計(jì)時(shí)器防止刷新實(shí)現(xiàn)詳解,<BR>有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-03-03如何解決sass-loader和node-sass版本沖突的問(wèn)題
這篇文章主要介紹了如何解決sass-loader和node-sass版本沖突的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-04-04