2025-04-28 15:37:57 +08:00
|
|
|
|
<template>
|
2025-08-01 09:00:22 +08:00
|
|
|
|
<div class="container">
|
|
|
|
|
|
<button @click="scanQRCode">扫码用车</button>
|
|
|
|
|
|
<div v-if="carInfo">
|
|
|
|
|
|
<p>车牌号:{{ carInfo.licensePlate }}</p>
|
|
|
|
|
|
<p>车主姓名:{{ carInfo.ownerName }}</p>
|
|
|
|
|
|
<p>车辆状态:{{ carInfo.status }}</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2025-04-28 15:37:57 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script setup>
|
2025-08-01 09:00:22 +08:00
|
|
|
|
import { ref } from "vue";
|
|
|
|
|
|
import * as api from "@/utils/api.js";
|
|
|
|
|
|
import { showModelMessage } from "@/utils/tools.js";
|
2025-04-28 15:37:57 +08:00
|
|
|
|
|
2025-08-01 09:00:22 +08:00
|
|
|
|
const carInfo = ref(null); // 用来存储车辆信息
|
2025-04-28 15:37:57 +08:00
|
|
|
|
|
2025-08-01 09:00:22 +08:00
|
|
|
|
// 扫码功能
|
|
|
|
|
|
const scanQRCode = () => {
|
|
|
|
|
|
uni.scanCode({
|
|
|
|
|
|
success: (res) => {
|
|
|
|
|
|
const carId = res.result; // 获取扫码结果(车辆ID)
|
|
|
|
|
|
getCarInfo(carId); // 获取车辆信息
|
|
|
|
|
|
},
|
|
|
|
|
|
fail: () => {
|
|
|
|
|
|
uni.showToast({
|
|
|
|
|
|
title: "扫码失败,请重试",
|
|
|
|
|
|
icon: "none",
|
|
|
|
|
|
});
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 获取车辆信息
|
|
|
|
|
|
const getCarInfo = (carId) => {
|
|
|
|
|
|
uni.request({
|
|
|
|
|
|
url: `https://example.com/api/car/${carId}`, // 假设的API接口
|
|
|
|
|
|
method: "GET",
|
|
|
|
|
|
success: (response) => {
|
|
|
|
|
|
if (response.statusCode === 200) {
|
|
|
|
|
|
carInfo.value = response.data; // 更新车信息
|
|
|
|
|
|
} else {
|
|
|
|
|
|
uni.showToast({
|
|
|
|
|
|
title: "获取车辆信息失败",
|
|
|
|
|
|
icon: "none",
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
fail: () => {
|
|
|
|
|
|
uni.showToast({
|
|
|
|
|
|
title: "请求失败,请检查网络",
|
|
|
|
|
|
icon: "none",
|
|
|
|
|
|
});
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
};
|
2025-04-28 15:37:57 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
2025-08-01 09:00:22 +08:00
|
|
|
|
.container {
|
|
|
|
|
|
padding: 20px;
|
|
|
|
|
|
}
|
2025-04-28 15:37:57 +08:00
|
|
|
|
|
2025-08-01 09:00:22 +08:00
|
|
|
|
button {
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
padding: 10px;
|
|
|
|
|
|
background-color: #007aff;
|
|
|
|
|
|
color: white;
|
|
|
|
|
|
border-radius: 5px;
|
|
|
|
|
|
margin: 10px 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
</style>
|