From 9e37a796526ab2e8157e3eac0a5491f2fcae7e6e Mon Sep 17 00:00:00 2001 From: jiangx <1457960500@qq.com> Date: Sun, 25 Jun 2023 13:16:19 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E2=9A=A1=EF=B8=8F=20=E9=80=89=E4=B8=AD?= =?UTF-8?q?=E5=9C=B0=E5=9B=BE=E5=BC=B9=E6=A1=86=E5=85=83=E7=B4=A0=E6=97=B6?= =?UTF-8?q?=E5=8F=AA=E8=8E=B7=E5=8F=96=E4=B8=80=E6=AC=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/composables/useInitMap.ts | 9 +++++---- src/types/map.d.ts | 3 ++- src/utils/utils.ts | 13 +++++++++++-- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/composables/useInitMap.ts b/src/composables/useInitMap.ts index 2e1d589..6e6a62d 100644 --- a/src/composables/useInitMap.ts +++ b/src/composables/useInitMap.ts @@ -9,7 +9,7 @@ export const useInitMap = async function () { const { device, facilityList, shopList } = storeToRefs(store) try { const { data } = await getMapData() - const delPrefixOfFacilityList = facilityList.value.slice().map(item => ({ + const delPrefixOfFacilityList = facilityList.value.map(item => ({ ...item, filePath: item.filePath.replace(PREFIX.STATIC_URL, '') })) @@ -42,7 +42,8 @@ function onClickShop(event: any) { if (event.data) { showMapDialog() - window.Map_QM.addElementLabel(document.getElementById('shopInfo'), event.data.xaxis, event.data.yaxis) + !window.shopInfo && document.getElementById('shopInfo') + window.Map_QM.addElementLabel(window.shopInfo, event.data.xaxis, event.data.yaxis) store.SET_SHOP(event.data.shopData) } else { hideMapDialog() @@ -50,12 +51,12 @@ function onClickShop(event: any) { } //地图弹框消失 export function hideMapDialog() { - ;(document.getElementById('shopInfo') as HTMLElement).style.visibility = 'hidden' + window.shopInfo.style.visibility = 'hidden' } //显示地图弹框 function showMapDialog() { - ;(document.getElementById('shopInfo') as HTMLElement).style.visibility = 'visible' + window.shopInfo.style.visibility = 'visible' } //监听地图上下文丢失 刷新页面 diff --git a/src/types/map.d.ts b/src/types/map.d.ts index ab9a326..c309511 100644 --- a/src/types/map.d.ts +++ b/src/types/map.d.ts @@ -25,6 +25,7 @@ export declare global { } interface Window { + shopInfo: HTMLDivElement MainMap_QM: { init(callBack: () => void, options: Partial): void } @@ -32,7 +33,7 @@ export declare global { // 地图工具对象 util: { options: { playSpeed: number } - changePlaySpeed(speed?: number = 6): void + changePlaySpeed(speed: number = 6): void } // render 对象 renderer: any diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 7a67874..f8d2244 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -13,7 +13,7 @@ export const randomNumber = (min: number, max: number): number => Math.floor(min * @param {string} phone * @returns {boolean} */ -export const checkPhoneNumber = (phone: string): boolean => /^(?:(?:\+|00)86)?1[3-9]\d{9}$/.test(phone) +export const isPhoneNumber = (phone: string): boolean => /^(?:(?:\+|00)86)?1[3-9]\d{9}$/.test(phone) /** * 大写字母 @@ -119,7 +119,16 @@ export const formatDay = (date: Date, format: 'y.m.d' | 'y/m/d' | 'y-m-d' = 'y-m return `${year}-${month}-${week}` } -//指定key的图片类型加上前缀 +//当前时间是否在指定时间段内 +export const isInDuringDate = (startDate: string, endDate: string) => { + const currentDate = new Date().toLocaleString() + const start = new Date(startDate).toLocaleString() + const end = new Date(endDate).toLocaleString() + + return currentDate >= start && currentDate <= end +} + +//图片地址加上前缀 export const addPrefixByRecursive = (data: any[], prefix = PREFIX.STATIC_URL, exp = /\.(png|jpg|jpeg|JPG|PNG|MP4|mp4)$/) => { if (data && typeof data === 'object') { for (const key in data) {