From 6626fab9044ecd418595765a272bdd56724dcbf7 Mon Sep 17 00:00:00 2001 From: liyongle Date: Sat, 6 May 2023 15:50:40 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=9A=80=20=E5=81=9C=E8=BD=A6?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/CarInfo/CarInfo.vue | 35 +++++++++--- src/components/PlateInput/PlateInput.vue | 17 +++++- src/composables/useFindCar.ts | 72 +++++++++++++++++------- src/composables/useParkingKeyboard.ts | 2 +- src/types/car.d.ts | 4 +- src/types/map.d.ts | 2 +- src/views/Parking/Parking.vue | 4 +- 7 files changed, 102 insertions(+), 34 deletions(-) diff --git a/src/components/CarInfo/CarInfo.vue b/src/components/CarInfo/CarInfo.vue index 177d69c..5f9f98e 100644 --- a/src/components/CarInfo/CarInfo.vue +++ b/src/components/CarInfo/CarInfo.vue @@ -2,19 +2,19 @@
- +
车牌号 - 辽A88888 + {{ carInfo.carCode }}
车位号 - E-666 + {{ carInfo.spaceNo }}
停车时长 - 1小时 + {{ carInfo.parkingTime }}
@@ -39,19 +39,40 @@ diff --git a/src/components/PlateInput/PlateInput.vue b/src/components/PlateInput/PlateInput.vue index 6d1e61f..13af4b6 100644 --- a/src/components/PlateInput/PlateInput.vue +++ b/src/components/PlateInput/PlateInput.vue @@ -17,7 +17,15 @@
-
+
查找车辆
@@ -51,7 +59,12 @@ function handleEnergy() { }) } function confirm() { - emits('confirm') + if ( + (props.searchMethod === '车牌' && ((isEnergy.value && props.list.length === 8) || (!isEnergy.value && props.list.length === 7))) || + (props.searchMethod === '车位' && props.list.length === 6) + ) { + emits('confirm') + } } onMounted(() => { diff --git a/src/composables/useFindCar.ts b/src/composables/useFindCar.ts index ee2a64a..db6ac1e 100644 --- a/src/composables/useFindCar.ts +++ b/src/composables/useFindCar.ts @@ -2,35 +2,69 @@ import { ref } from 'vue' import { getFindCar } from '@/http/api/parking' import { HTTP_CODE } from '@/enums' import { isLicensePlate } from '@/utils/utils' +import { useRootStore } from '@/store/root' +import { useRouter } from 'vue-router' import Message from '@/base/Message/Message' export const useFindCar = () => { const showCarDetail = ref(false) const loading = ref(false) const result = ref() - async function confirm(plate: string) { - if (!isLicensePlate(plate)) { - Message({ text: '车牌错误,请重新输入', type: 'success' }) - return - } - if (loading.value) { - return - } - try { - loading.value = true - const { code, msg, data } = await getFindCar(plate) - if (code === HTTP_CODE.ERR_OK) { - result.value = data - showCarDetail.value = true + const store = useRootStore() + const router = useRouter() + async function confirm(plate: string, type: number) { + if (!type) { + if (!isLicensePlate(plate)) { + Message({ text: '车牌错误,请重新输入', type: 'success' }) + return + } + if (loading.value) { + return + } + try { + loading.value = true + const { code, msg, data } = await getFindCar(plate) + if (code === HTTP_CODE.ERR_OK) { + result.value = { ...data, carCode: plate, parkingTime: toHoursAndMinutes(Number(data.parkingTime)) } + showCarDetail.value = true + } else { + Message({ text: msg, type: 'success' }) + } + } catch (error) { + Message({ text: error as string, type: 'success' }) + } finally { + loading.value = false + } + } else { + if (!plate.length) { + Message({ type: 'success', text: '请输入正确的车位号' }) + return + } + const info = window.Map_QM.pathPark({ shopNum: plate }) + + if (info?.node?.length) { + const floor: any = store.buildingList[0].floorList.find(item => item.floorOrder === info.floor)?.floor + const shop = { + shopCode: '', + shopName: plate, + floorOrder: info.floor, + floor, + logoUrl: '/static/img/tcjf.png', + yaxis: info.node + } + store.SET_SHOP(shop) + router.push('/nav') } else { - Message({ text: msg, type: 'success' }) + Message({ text: `暂未查到相关信息`, type: 'success' }) } - } catch (error) { - Message({ text: error as string, type: 'success' }) - } finally { - loading.value = false } } + // 格式化停车时间 + function toHoursAndMinutes(totalMinutes: number) { + const hours = Math.floor(totalMinutes / 60) + const minutes = totalMinutes % 60 + return `${hours > 0 ? `${hours}小时` : ''}${minutes > 0 ? ` ${minutes}分钟` : ''}` + } return { loading, result, showCarDetail, confirm } } diff --git a/src/composables/useParkingKeyboard.ts b/src/composables/useParkingKeyboard.ts index f583be8..da19900 100644 --- a/src/composables/useParkingKeyboard.ts +++ b/src/composables/useParkingKeyboard.ts @@ -7,7 +7,7 @@ export const useParkingKeyboard = () => { const NOT_ENERGY_PLATE = 7 //非能源车牌长度 const ENERGY_PLATE = 8 //能源车牌长度 const SPACE_MAX_LENGTH = 4 //车位最大允许长度 - const LICENSE = ['苏', 'A'] //默认车牌前缀 + const LICENSE = ['辽', 'A'] //默认车牌前缀 const plate = ref(LICENSE.slice()) const plateToString = computed(() => plate.value.join('')) diff --git a/src/types/car.d.ts b/src/types/car.d.ts index d975ce4..66e80e7 100644 --- a/src/types/car.d.ts +++ b/src/types/car.d.ts @@ -6,6 +6,6 @@ declare interface CarInfo { cost: number //费用 enterTime: string //入场时间 floor: string //楼层 - parkingTime: number // 停车时长 - placeCode: string //车位号 + parkingTime: string // 停车时长 + spaceNo: string //车位号 } diff --git a/src/types/map.d.ts b/src/types/map.d.ts index ab9a326..25fde41 100644 --- a/src/types/map.d.ts +++ b/src/types/map.d.ts @@ -288,7 +288,7 @@ export declare global { */ pathPark(obj: { shopNum: string }): { shopNum: string - node: string | number + node: string floor: number xaxis: number | string yaxis: number | string diff --git a/src/views/Parking/Parking.vue b/src/views/Parking/Parking.vue index 3640b4e..cc6d69c 100644 --- a/src/views/Parking/Parking.vue +++ b/src/views/Parking/Parking.vue @@ -31,7 +31,7 @@
- +