From 1fc8b09ca2d729ee0e1b58e2410924bff9bf97da Mon Sep 17 00:00:00 2001 From: jiangx <1457960500@qq.com> Date: Mon, 26 Jun 2023 15:46:17 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E2=99=BB=EF=B8=8F=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9url=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/static/offline/JSON/config.json | 2 +- src/composables/useServeNav.ts | 20 +++++--------------- src/http/api/base/index.ts | 11 ++++++----- src/http/api/brand/index.ts | 8 +++++--- src/http/api/building/index.ts | 3 ++- src/http/api/parking/index.ts | 4 +++- src/http/api/shop/index.ts | 5 +++-- src/http/api/statistics/index.ts | 5 ++++- src/http/http.ts | 20 +++++--------------- 9 files changed, 34 insertions(+), 44 deletions(-) diff --git a/public/static/offline/JSON/config.json b/public/static/offline/JSON/config.json index aad3eea..c98087c 100644 --- a/public/static/offline/JSON/config.json +++ b/public/static/offline/JSON/config.json @@ -3,7 +3,7 @@ "msg": "操作成功", "data": { "interfaceUrl": "https://project-iot.test.1000my.com/api", - "mobileNav": "https://1000my.obs.cn-east-2.myhuaweicloud.com/mobileqmgo/index.html#/", + "mobileNav": "https://1000my.obs.cn-east-2.myhuaweicloud.com/mobileqmgo/index.html#/?", "handWriteUrl": "http://saas.1000my.com:8014/words" } } diff --git a/src/composables/useServeNav.ts b/src/composables/useServeNav.ts index d0fb794..e851848 100644 --- a/src/composables/useServeNav.ts +++ b/src/composables/useServeNav.ts @@ -1,26 +1,16 @@ import { useRouter } from 'vue-router' -import { storeToRefs } from 'pinia' import { useRootStore } from '@/store/root' import Brand from '@/utils/Class/Brand' -import { useFacilityNav } from './useFacilityNav' export const useServeNav = () => { const router = useRouter() const store = useRootStore() - const { facilityList } = storeToRefs(store) - const { handleFacility } = useFacilityNav() - function nav({ isPoint, floor, floorOrder, name, nameEn, facilityCode, point, logoUrl }: ServeItem) { - if (isPoint === 1) { - const facility = facilityList.value.find(item => item.code === facilityCode) - if (facility) { - handleFacility(facility) - } - } else if (isPoint === 2) { - const shop = new Brand({ shopName: name, shopNameEn: nameEn, floor, floorOrder, logoUrl, yaxis: point, shopCode: logoUrl }) - store.SET_SHOP(shop) - router.push('/nav') - } + function nav({ floor, floorOrder, name, nameEn, point, logoUrl }: ServeItem) { + const shop = new Brand({ shopName: name, shopNameEn: nameEn, floor, floorOrder, logoUrl, yaxis: point, shopCode: logoUrl }) + store.SET_SHOP(shop) + router.push('/nav') } + return { nav } } diff --git a/src/http/api/base/index.ts b/src/http/api/base/index.ts index 05fbadc..5b54fee 100644 --- a/src/http/api/base/index.ts +++ b/src/http/api/base/index.ts @@ -1,20 +1,21 @@ import { request } from '@/http/http' import type { WrittenQuery } from './types' +import { PREFIX } from '@/enums' //获取配置项 -export const getConfig = () => request({ url: '/JSON/config.json' }) +export const getConfig = () => request({ url: `${PREFIX.STATIC_URL}/JSON/config.json` }) //获取天气 -export const getWeather = () => request({ url: `/JSON/GetWeather.json` }) +export const getWeather = () => request({ url: `${PREFIX.STATIC_URL}/JSON/GetWeather.json` }) //获取设施列表 -export const getFacilitiesList = () => request({ url: `/JSON/getFacilityList.json` }) +export const getFacilitiesList = () => request({ url: `${PREFIX.STATIC_URL}/JSON/getFacilityList.json` }) //地图模型数据 -export const getMapData = () => request({ url: `/JSON/getMap.json` }) +export const getMapData = () => request({ url: `${PREFIX.STATIC_URL}/JSON/getMap.json` }) // 指定时间返回 -export const getBackTime = () => request<[number, number]>({ url: `/JSON/getBackTime.json` }) +export const getBackTime = () => request<[number, number]>({ url: `${PREFIX.STATIC_URL}/JSON/getBackTime.json` }) //手写地址 export const getHandWriting = (data: WrittenQuery) => request({ url: 'http://saas.1000my.com:8014/words', method: 'post', data }) diff --git a/src/http/api/brand/index.ts b/src/http/api/brand/index.ts index 60d71c9..d8e7644 100644 --- a/src/http/api/brand/index.ts +++ b/src/http/api/brand/index.ts @@ -1,8 +1,10 @@ import { request } from '@/http/http' import type { GroupList, BrandRes } from './types' +import { PREFIX } from '@/enums' -export const getBrandInfo = () => request({ url: `/JSON/getBrandShopList.json` }) +export const getBrandInfo = () => request({ url: `${PREFIX.STATIC_URL}/JSON/getBrandShopList.json` }) -export const getShopListByFloor = () => request<{ list: GroupList }>({ url: `/JSON/getBrandShopListByFloor.json` }) +export const getShopListByFloor = () => request<{ list: GroupList }>({ url: `${PREFIX.STATIC_URL}/JSON/getBrandShopListByFloor.json` }) -export const getShopListByIndustry = () => request<{ list: GroupList }>({ url: `/JSON/getBrandShopListByIndustryId.json` }) +export const getShopListByIndustry = () => + request<{ list: GroupList }>({ url: `${PREFIX.STATIC_URL}/JSON/getBrandShopListByIndustryId.json` }) diff --git a/src/http/api/building/index.ts b/src/http/api/building/index.ts index 5792a98..23a0d41 100644 --- a/src/http/api/building/index.ts +++ b/src/http/api/building/index.ts @@ -1,4 +1,5 @@ import { request } from '../../http' +import { PREFIX } from '@/enums' //获取当前所处楼层 -export const getDeviceInfo = () => request({ url: `/JSON/getDevCoordinateByIP.json` }) +export const getDeviceInfo = () => request({ url: `${PREFIX.STATIC_URL}/JSON/getDevCoordinateByIP.json` }) diff --git a/src/http/api/parking/index.ts b/src/http/api/parking/index.ts index 6730808..bdef6ef 100644 --- a/src/http/api/parking/index.ts +++ b/src/http/api/parking/index.ts @@ -1,3 +1,5 @@ import { request } from '../../http' +import { getPrefixUrl } from '../../http' //找车 -export const getFindCar = (license: string) => request({ url: `/ThirdPark/GetPlaceInfo?carCode=${license}` }) +export const getFindCar = (license: string) => + request({ url: `${getPrefixUrl().interfaceUrl}/ThirdPark/GetPlaceInfo?carCode=${license}` }) diff --git a/src/http/api/shop/index.ts b/src/http/api/shop/index.ts index cb018a6..3b6e1f2 100644 --- a/src/http/api/shop/index.ts +++ b/src/http/api/shop/index.ts @@ -1,5 +1,6 @@ -//获取店铺及楼栋列表 import { request } from '@/http/http' import type { ShopListAndBuildingList } from './types' +import { PREFIX } from '@/enums' -export const getShopAndBuildingList = () => request({ url: `/JSON/getMapInfo.json` }) +//获取店铺及楼栋列表 +export const getShopAndBuildingList = () => request({ url: `${PREFIX.STATIC_URL}/JSON/getMapInfo.json` }) diff --git a/src/http/api/statistics/index.ts b/src/http/api/statistics/index.ts index 87d9a04..8f26fb8 100644 --- a/src/http/api/statistics/index.ts +++ b/src/http/api/statistics/index.ts @@ -1,4 +1,7 @@ import { request } from '../../http' import type { Query } from './types' +import { getPrefixUrl } from '../../http' + //数据统计 -export const getStatistics = (data: Query) => request({ url: `/analysis/v1/web/deviceUseClickDataUpload`, data, method: 'post' }) +export const getStatistics = (data: Query) => + request({ url: `${getPrefixUrl().interfaceUrl}/analysis/v1/web/deviceUseClickDataUpload`, data, method: 'post' }) diff --git a/src/http/http.ts b/src/http/http.ts index be9e975..18a224d 100644 --- a/src/http/http.ts +++ b/src/http/http.ts @@ -2,7 +2,6 @@ import axios, { type AxiosResponse, AxiosInstance, InternalAxiosRequestConfig } import { addPrefixByRecursive } from '@/utils/utils' import { useRootStore } from '@/store/root' import type { RequestConfig, RequestInterceptors, CreateRequestConfig } from './types' -import { PREFIX } from '@/enums' class Request { // axios 实例 @@ -88,20 +87,6 @@ const _request = new Request({ timeout: 10000, timeoutErrorMessage: '网络超时', interceptors: { - requestInterceptors(_config) { - const store = useRootStore() - const { url } = _config - if (/.json$/.test(url as string)) { - Object.assign(_config, { - url: PREFIX.STATIC_URL + _config.url - }) - } else { - Object.assign(_config, { - url: store.config.interfaceUrl + _config.url - }) - } - return _config - }, responseInterceptors(config) { const isJson = /.json$/.test(config.config.url as string) isJson && addPrefixByRecursive(config.data.data) @@ -110,6 +95,11 @@ const _request = new Request({ } }) +export function getPrefixUrl() { + const store = useRootStore() + return store.config +} + export type Response = { msg: string data: T