如何使用 Deepseek 寫的uniapp油耗計(jì)算器

下面是一個(gè)基于 Uniapp 的油耗計(jì)算器實(shí)現(xiàn),包含 Vue 組件和頁面代碼。
1. 創(chuàng)建頁面文件
在 pages 目錄下創(chuàng)建 fuel-calculator 頁面:
<!-- pages/fuel-calculator/fuel-calculator.vue -->
<template>
<view class="container">
<view class="calculator">
<view class="header">
<text class="title">油耗計(jì)算器</text>
</view>
<view class="input-group">
<text class="label">當(dāng)前油價(jià) (元/升)</text>
<input
type="number"
v-model="price"
placeholder="例如:7.85"
class="input"
@input="validateInput('price')"
/>
</view>
<view class="input-group">
<text class="label">加油金額 (元)</text>
<input
type="number"
v-model="money"
placeholder="例如:300"
class="input"
@input="validateInput('money')"
/>
</view>
<view class="input-group">
<text class="label">行駛里程 (公里)</text>
<input
type="number"
v-model="distance"
placeholder="例如:450"
class="input"
@input="validateInput('distance')"
/>
</view>
<button class="calculate-btn" @click="calculate">計(jì)算油耗</button>
<view class="result" v-if="showResult">
<view class="result-header">
<text class="result-title">計(jì)算結(jié)果</text>
</view>
<view class="result-item">
<text>加油量:</text>
<text class="result-value">{{ fuel.toFixed(2) }} 升</text>
</view>
<view class="result-item">
<text>百公里油耗:</text>
<text class="result-value">{{ consumption.toFixed(2) }} 升/百公里</text>
</view>
<view class="result-item">
<text>每公里油費(fèi):</text>
<text class="result-value">{{ costPerKm.toFixed(2) }} 元</text>
</view>
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
price: '',
money: '',
distance: '',
fuel: 0,
consumption: 0,
costPerKm: 0,
showResult: false
}
},
methods: {
validateInput(field) {
// 確保輸入是正數(shù)
if (this[field] < 0) {
this[field] = ''
}
},
calculate() {
// 驗(yàn)證輸入
if (!this.price || !this.money || !this.distance) {
uni.showToast({
title: '請(qǐng)?zhí)顚懲暾畔?,
icon: 'none'
})
return
}
if (this.price <= 0 || this.money <= 0 || this.distance <= 0) {
uni.showToast({
title: '請(qǐng)輸入大于0的數(shù)值',
icon: 'none'
})
return
}
// 計(jì)算
this.fuel = this.money / this.price
this.consumption = (this.fuel / this.distance) * 100
this.costPerKm = this.money / this.distance
this.showResult = true
// 隱藏鍵盤
uni.hideKeyboard()
}
}
}
</script>
<style>
.container {
padding: 20px;
background-color: #f5f5f5;
min-height: 100vh;
}
.calculator {
background-color: #ffffff;
border-radius: 10px;
padding: 20px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}
.header {
margin-bottom: 25px;
}
.title {
font-size: 22px;
font-weight: bold;
color: #333;
text-align: center;
display: block;
}
.input-group {
margin-bottom: 20px;
}
.label {
font-size: 16px;
color: #555;
font-weight: bold;
display: block;
margin-bottom: 8px;
}
.input {
border: 1px solid #ddd;
border-radius: 5px;
padding: 12px;
font-size: 16px;
width: 100%;
box-sizing: border-box;
}
.calculate-btn {
background-color: #4CAF50;
color: white;
border: none;
border-radius: 5px;
padding: 12px;
font-size: 16px;
margin-top: 10px;
width: 100%;
}
.calculate-btn:active {
background-color: #45a049;
}
.result {
margin-top: 25px;
padding: 15px;
background-color: #f9f9f9;
border-radius: 8px;
}
.result-header {
margin-bottom: 15px;
}
.result-title {
font-size: 18px;
font-weight: bold;
color: #333;
}
.result-item {
display: flex;
justify-content: space-between;
margin-bottom: 10px;
font-size: 16px;
}
.result-value {
font-weight: bold;
color: #2196F3;
}
</style>2. 配置頁面路由
在 pages.json 中添加頁面路由配置:
{
"pages": [
// ...其他頁面配置
{
"path": "pages/fuel-calculator/fuel-calculator",
"style": {
"navigationBarTitleText": "油耗計(jì)算器"
}
}
]
}3. 功能說明
這個(gè) Uniapp 油耗計(jì)算器具有以下特點(diǎn):
- 響應(yīng)式設(shè)計(jì):適配各種屏幕尺寸
- 輸入驗(yàn)證:確保輸入值為正數(shù)
- 計(jì)算結(jié)果:
- 加油量(升)
- 百公里油耗(升/百公里)
- 每公里油費(fèi)(元)
- 用戶體驗(yàn)優(yōu)化:
- 計(jì)算后自動(dòng)隱藏鍵盤
- 錯(cuò)誤輸入提示
- 清晰的結(jié)果展示
4. 使用方法
- 將代碼添加到您的 Uniapp 項(xiàng)目中
- 通過路由跳轉(zhuǎn)或?qū)Ш綑谠L問油耗計(jì)算器頁面
- 輸入油價(jià)、加油金額和行駛里程
- 點(diǎn)擊"計(jì)算油耗"按鈕查看結(jié)果
5. 擴(kuò)展建議
如果需要進(jìn)一步增強(qiáng)功能,可以考慮:
- 添加歷史記錄功能,保存每次計(jì)算結(jié)果
- 實(shí)現(xiàn)多車管理,比較不同車輛的油耗
- 增加圖表展示,可視化油耗變化趨勢(shì)
- 添加分享功能,方便分享計(jì)算結(jié)果
這個(gè)組件已經(jīng)包含了完整的計(jì)算邏輯和基本的UI界面,可以直接集成到您的Uniapp項(xiàng)目中使用。
到此這篇關(guān)于如何使用 Deepseek 寫的uniapp油耗計(jì)算器的文章就介紹到這了,更多相關(guān)Deepseek uniapp油耗計(jì)算器內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- ClaudeCode中的Agent系統(tǒng)工作原理、如何使用和自定義開發(fā)
- 如何使用 Deepseek 寫的html油耗計(jì)算器
- 如何用 Deepseek 寫的uniapp血型遺傳查詢工具
- 通過Docker為本地DeepSeek-r1部署WebUI界面的完整教程
- deepseek本地部署及java、python調(diào)用步驟詳解
- 本地部署DeepSeek開源多模態(tài)大模型Janus-Pro-7B實(shí)操教程
- 華為昇騰920b服務(wù)器部署DeepSeek翻車現(xiàn)場(chǎng)演示
- 5分鐘獲取deepseek api并搭建簡(jiǎn)易問答應(yīng)用
- DeepSeek V4-Pro驅(qū)動(dòng)Claude Code,OA審批+BI大屏+自動(dòng)部署的真實(shí)體驗(yàn)
相關(guān)文章
vite打包出現(xiàn)"default"?is?not?exported?by?"no
這篇文章主要給大家介紹了關(guān)于vite打包出現(xiàn)"default"?is?not?exported?by?"node_modules/...問題解決的相關(guān)資料,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-11-11
關(guān)于vue3使用particles粒子特效的問題
這篇文章主要介紹了關(guān)于vue3使用particles粒子特效的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-06-06
Vue項(xiàng)目中實(shí)現(xiàn)ElementUI按需引入過程解析
這篇文章主要介紹了Vue項(xiàng)目中實(shí)現(xiàn)ElementUI按需引入,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-05-05
VUE+Element UI實(shí)現(xiàn)簡(jiǎn)單的表格行內(nèi)編輯效果的示例的代碼
這篇文章主要介紹了VUE+Element UI實(shí)現(xiàn)簡(jiǎn)單的表格行內(nèi)編輯效果的示例的代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-10-10
vuejs響應(yīng)用戶事件(如點(diǎn)擊事件)
本篇文章主要介紹了vuejs響應(yīng)用戶事件(如點(diǎn)擊),通過vuejs響應(yīng)用戶事件的技巧,具有一定的參考價(jià)值,有興趣的小伙伴們可以參考一下。2017-03-03
移動(dòng)端Vue2.x Picker的全局調(diào)用實(shí)現(xiàn)
這篇文章主要介紹了移動(dòng)端Vue2.x Picker的全局調(diào)用實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-03-03
Vue 組件參數(shù)校驗(yàn)與非props特性的方法
這篇文章主要介紹了Vue 組件參數(shù)校驗(yàn)與非props特性的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2019-02-02
vue實(shí)現(xiàn)鼠標(biāo)滑動(dòng)展示tab欄切換
這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)鼠標(biāo)滑動(dòng)展示tab欄切換,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-04-04

