最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

如何用 Deepseek 寫的uniapp血型遺傳查詢工具

 更新時間:2025年04月21日 09:48:41   作者:—Qeyser  
在現(xiàn)代社會中,了解血型遺傳規(guī)律對于優(yōu)生優(yōu)育、醫(yī)療健康等方面都有重要意義,本文將介紹如何使用Uniapp開發(fā)一個跨平臺的血型遺傳查詢工具,幫助用戶預測孩子可能的血型,感興趣的朋友一起看看吧

引言

在現(xiàn)代社會中,了解血型遺傳規(guī)律對于優(yōu)生優(yōu)育、醫(yī)療健康等方面都有重要意義。本文將介紹如何使用Uniapp開發(fā)一個跨平臺的血型遺傳查詢工具,幫助用戶預測孩子可能的血型。

一、血型遺傳基礎知識

人類的ABO血型系統(tǒng)由三個等位基因決定:IA、IB和i。其中IA和IB對i是顯性關系:

  • A型血基因型:IAIA或IAi
  • B型血基因型:IBIB或IBi
  • AB型血基因型:IAIB
  • O型血基因型:ii

根據(jù)孟德爾遺傳定律,孩子的血型由父母雙方各提供一個等位基因組合而成。

二、Uniapp開發(fā)優(yōu)勢

選擇Uniapp開發(fā)這款工具主要基于以下優(yōu)勢:

  • 跨平臺能力:一次開發(fā),可發(fā)布到iOS、Android、H5及各種小程序平臺
  • 開發(fā)效率高:基于Vue.js框架,學習成本低,開發(fā)速度快
  • 性能優(yōu)良:接近原生應用的體驗
  • 生態(tài)豐富:擁有完善的插件市場和社區(qū)支持

三、核心代碼解析

1. 血型遺傳算法實現(xiàn)

getPossibleGenotypes(parent1, parent2) {
  // 血型對應的可能基因型
  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) {
      // 每個父母貢獻一個等位基因
      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
}

這段代碼實現(xiàn)了血型遺傳的核心算法,通過遍歷父母可能的基因型組合,計算出孩子所有可能的基因型。

2. 概率計算

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)計每種血型的出現(xiàn)次數(shù)
  for (const genotype of genotypes) {
    const type = genotypeToType[genotype]
    bloodTypeCounts[type]++
  }
  const total = genotypes.length
  const probabilities = {}
  // 計算概率
  for (const type in bloodTypeCounts) {
    const count = bloodTypeCounts[type]
    if (count > 0) {
      probabilities[type] = (count / total * 100).toFixed(1)
    }
  }
  return probabilities
}

這部分代碼統(tǒng)計各種血型出現(xiàn)的頻率,并計算出每種血型出現(xiàn)的概率百分比。

3. 界面交互實現(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">計算孩子可能的血型</button>

使用Uniapp的picker組件實現(xiàn)血型選擇,通過按鈕觸發(fā)計算邏輯,界面簡潔友好。

四、項目亮點

  • 科學準確性:嚴格遵循遺傳學原理,計算結果準確可靠
  • 用戶體驗優(yōu)化
    • 結果自動滾動到可視區(qū)域
    • 概率可視化展示
    • 遺傳知識科普
  • 代碼結構清晰
    • 業(yè)務邏輯與UI分離
    • 復用性高的工具函數(shù)
    • 良好的代碼注釋

完整代碼

<template>
	<view class="container">
		<view class="header">
			<text class="title">血型遺傳查詢工具</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">計算孩子可能的血型</button>
		</view>
		<view class="card result-card" v-if="showResult">
			<text class="subtitle">結果</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ī)律說明:</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() {
				// 計算可能的基因組合
				const possibleGenotypes = this.getPossibleGenotypes(this.parent1Value, this.parent2Value)
				// 計算可能的血型及其概率
				const bloodTypeProbabilities = this.calculateProbabilities(possibleGenotypes)
				// 生成結果文本
				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
				// 滾動到結果位置
				uni.pageScrollTo({
					scrollTop: 300,
					duration: 300
				})
			},
			getBloodTypeName(type) {
				const names = {
					'A': 'A型',
					'B': 'B型',
					'AB': 'AB型',
					'O': 'O型'
				}
				return names[type]
			},
			getPossibleGenotypes(parent1, parent2) {
				// 血型對應的可能基因型
				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) {
						// 每個父母貢獻一個等位基因
						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)計每種血型的出現(xiàn)次數(shù)
				for (const genotype of genotypes) {
					const type = genotypeToType[genotype]
					bloodTypeCounts[type]++
				}
				const total = genotypes.length
				const probabilities = {}
				// 計算概率
				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>

到此這篇關于用 Deepseek 寫的uniapp血型遺傳查詢工具的文章就介紹到這了,更多相關Deepseek uniapp血型遺傳內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

  • vue如何實現(xiàn)垂直居中

    vue如何實現(xiàn)垂直居中

    這篇文章主要介紹了vue如何實現(xiàn)垂直居中,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-09-09
  • Vue瀑布流插件的使用示例

    Vue瀑布流插件的使用示例

    這篇文章主要介紹了Vue瀑布流插件的使用示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-09-09
  • uniapp實現(xiàn)省市區(qū)三級級聯(lián)選擇功能(含地區(qū)json文件)

    uniapp實現(xiàn)省市區(qū)三級級聯(lián)選擇功能(含地區(qū)json文件)

    這篇文章主要給大家介紹了關于uniapp實現(xiàn)省市區(qū)三級級聯(lián)選擇功能(含地區(qū)json文件)的相關資料,級級聯(lián)是一種常見的網頁交互設計,用于省市區(qū)選擇,它的目的是方便用戶在一系列選項中進行選擇,并且確保所選選項的正確性和完整性,需要的朋友可以參考下
    2024-06-06
  • Vue實現(xiàn)天氣預報小應用

    Vue實現(xiàn)天氣預報小應用

    這篇文章主要為大家詳細介紹了Vue實現(xiàn)天氣預報小應用,查詢一些城市的天氣情況,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-08-08
  • Vue3?setup中使用$refs的方法詳解

    Vue3?setup中使用$refs的方法詳解

    在?Vue?3?中的?Composition?API?中,$refs?并不直接可用于?setup?函數(shù),但是實際工作中確實有需求,那么該如何解決呢,本文為大家整理了兩個方案,希望對大家有所幫助
    2023-08-08
  • vuedraggable+element ui實現(xiàn)頁面控件拖拽排序效果

    vuedraggable+element ui實現(xiàn)頁面控件拖拽排序效果

    這篇文章主要為大家詳細介紹了vuedraggable+element ui實現(xiàn)頁面控件拖拽排序效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-12-12
  • Vue組件化開發(fā)思考

    Vue組件化開發(fā)思考

    這篇文章主要介紹了Vue組件化開發(fā)的思考以及相關的原理介紹,如果你對此有興趣,可以學習參考下。
    2018-02-02
  • Vue彈窗Dialog最佳使用方案實戰(zhàn)

    Vue彈窗Dialog最佳使用方案實戰(zhàn)

    這篇文章主要為大家介紹了極度舒適的Vue彈窗Dialog最佳使用方案實戰(zhàn),有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-11-11
  • vue循環(huán)語句v-for中的元素綁定值

    vue循環(huán)語句v-for中的元素綁定值

    這篇文章主要介紹了vue循環(huán)語句v-for中的元素綁定值問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2023-11-11
  • Vue編譯器中的過濾器轉換機制(transformFilter)詳解

    Vue編譯器中的過濾器轉換機制(transformFilter)詳解

    本文將詳細解讀?Vue?兼容模式下的過濾器編譯邏輯——transformFilter?模塊,它是?Vue?3?為了兼容?Vue?2?模板過濾器語法而存在的編譯階段轉換器,需要的朋友可以參考下
    2025-11-11

最新評論

双桥区| 齐齐哈尔市| 女性| 保德县| 黄浦区| 湘阴县| 望江县| 伊金霍洛旗| 上高县| 洪江市| 利川市| 蒲城县| 石首市| 鄯善县| 龙陵县| 湛江市| 清水河县| 景洪市| 大厂| 泉州市| 康马县| 贡山| 清苑县| 勃利县| 抚远县| 西乌| 西畴县| 平罗县| 涿州市| 星座| 天等县| 禹城市| 平和县| 凌海市| 噶尔县| 龙州县| 瓦房店市| 额济纳旗| 昌平区| 姚安县| 乐陵市|