From a1aca8be99e62ea683fd8d7db82d7a480f5d0305 Mon Sep 17 00:00:00 2001 From: web <candymxq888@outlook.com> Date: 星期二, 08 七月 2025 09:58:05 +0800 Subject: [PATCH] feat:增加取水能力 --- pages/device/index.vue | 46 +++++++++++++++++++--- pages/user/index.vue | 7 +++ manifest.json | 10 ++-- api/index.js | 5 ++ pages/index/index.vue | 2 5 files changed, 56 insertions(+), 14 deletions(-) diff --git a/api/index.js b/api/index.js index 88c26e2..846220c 100644 --- a/api/index.js +++ b/api/index.js @@ -38,4 +38,9 @@ // 充值记录 export function getrechargeRecord(data) { return request('/api/user/searchRechargeRecords', data, 'POST') +} + +// 取水 +export function getWater(data) { + return request('/api/user/userWaterInTaking', data, 'POST') } \ No newline at end of file diff --git a/manifest.json b/manifest.json index db6f0b4..ea91e37 100644 --- a/manifest.json +++ b/manifest.json @@ -59,11 +59,11 @@ "enable" : false }, "lazyCodeLoading" : "requiredComponents", - "permission" : { - "scope.userLocation" : { - "desc" : "你的位置信息将用于计算设备与您的距离" - } - } + "permission" : { + "scope.userLocation" : { + "desc" : "你的位置信息将用于计算设备与您的距离" + } + } }, "vueVersion" : "3" } diff --git a/pages/device/index.vue b/pages/device/index.vue index e54abd7..a60b760 100644 --- a/pages/device/index.vue +++ b/pages/device/index.vue @@ -28,11 +28,12 @@ </view> <uni-popup ref="qushuiDialog" type="dialog"> <uni-popup-dialog type="info" cancelText="取消" confirmText="确认" title="请输入取水量" + before-close="true" @confirm="dialogConfirm" @close="dialogClose" > <view> - <input v-model="qushuiNum" placeholder="请输入取水量(L)" /> + <input v-model="qushuiNum" type="number" placeholder="请输入取水量(L)" /> </view> </uni-popup-dialog> </uni-popup> @@ -42,13 +43,13 @@ <script setup> import{ ref, onMounted } from 'vue' import Navbar from '../../components/navbar/navbar.vue' - import { getFacitily } from '@/api/index.js' + import { getFacitily, getWater } from '@/api/index.js' import { BASE_URL } from '../../config/index.js' const userLocation = ref() const facitilyList = ref([]) const qushuiDialog = ref() - const facitilyId = ref() + const facilityId = ref() const qushuiNum = ref() const getFacitilyList = () => { @@ -67,19 +68,49 @@ // 取水 const handleQushui = (id) => { - facitilyId.value = id + facilityId.value = id qushuiDialog.value.open() } // 取消 const dialogClose = () => { - facitilyId.value = '' + facilityId.value = '' qushuiNum.value = '' + qushuiDialog.value.close() } // 确认 const dialogConfirm = () => { - + if(!qushuiNum.value) { + uni.showToast({ + title:'请输入取水量', + icon:'none' + }) + return + } + const data = { + facilityId: facilityId.value, + amount: Number(qushuiNum.value) + } + getWater(data).then(res => { + if(res.code === 200) { + uni.showToast({ + title:res.data, + icon:'success' + }) + dialogClose() + }else{ + uni.showToast({ + title:res.msg, + icon:'error' + }) + } + }).catch(err => { + uni.showToast({ + title:'指令发送失败,请稍后重试', + icon:'error' + }) + }) } //打开地图导航 @@ -102,6 +133,7 @@ lon: res.longitude } uni.setStorageSync('userLocation',JSON.stringify(userLocation.value)) + getFacitilyList() }, fail:(err) =>{ locationToast() @@ -112,7 +144,7 @@ const locationToast = () => { uni.showModal({ title: "请求授权当前位置", - content: "请求获取您的位置,加载附近饮水设备信息!", + content: "请求获取您的位置,加载附近取水设备信息!", confirmText: "前往设置", success: (res) => { if (res.confirm) { diff --git a/pages/index/index.vue b/pages/index/index.vue index 6d99bd1..9564b1e 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -109,7 +109,7 @@ const locationToast = () => { uni.showModal({ title: "请求授权当前位置", - content: "请求获取您的位置,加载附近饮水设备信息!", + content: "请求获取您的位置,加载附近取水设备信息!", confirmText: "前往设置", success: (res) => { if (res.confirm) { diff --git a/pages/user/index.vue b/pages/user/index.vue index 3bdda58..c5e9a8d 100644 --- a/pages/user/index.vue +++ b/pages/user/index.vue @@ -32,6 +32,7 @@ <script setup> import { onMounted, ref } from "vue"; + import { onShow } from "@dcloudio/uni-app" const topHeight = ref(0) const userInfo = ref() @@ -66,9 +67,12 @@ }) } + onShow(() => { + userInfo.value = JSON.parse(uni.getStorageSync('userInfo')) + }) + onMounted(() => { getTopHeight() - userInfo.value = JSON.parse(uni.getStorageSync('userInfo')) }) </script> @@ -84,6 +88,7 @@ height: 80rpx; image{ width: 100%; + height: 100%; border-radius: 50%; } } -- Gitblit v1.9.3