From b4273c7d950d900fffc78a276bbea4068721c531 Mon Sep 17 00:00:00 2001 From: feige996 <1020102647@qq.com> Date: Mon, 22 Sep 2025 17:46:38 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=A7=BB=E9=99=A4=E4=B8=8EUNI=5FPL?= =?UTF-8?q?ATFORM=E7=9B=B8=E5=85=B3=E7=9A=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 不再需要处理不同平台的特殊逻辑,简化代码结构 --- src/env.d.ts | 1 - src/http/interceptor.ts | 2 -- src/utils/platform.ts | 26 -------------------------- vite.config.ts | 1 - 4 files changed, 30 deletions(-) delete mode 100644 src/utils/platform.ts diff --git a/src/env.d.ts b/src/env.d.ts index cbdf727..ea1334c 100644 --- a/src/env.d.ts +++ b/src/env.d.ts @@ -33,4 +33,3 @@ interface ImportMeta { } declare const __VITE_APP_PROXY__: 'true' | 'false' -declare const __UNI_PLATFORM__: 'app' | 'h5' | 'mp-alipay' | 'mp-baidu' | 'mp-kuaishou' | 'mp-lark' | 'mp-qq' | 'mp-tiktok' | 'mp-weixin' | 'mp-xiaochengxu' diff --git a/src/http/interceptor.ts b/src/http/interceptor.ts index d51912b..e97f06e 100644 --- a/src/http/interceptor.ts +++ b/src/http/interceptor.ts @@ -1,7 +1,6 @@ import type { CustomRequestOptions } from '@/http/types' import { useTokenStore } from '@/store' import { getEnvBaseUrl } from '@/utils' -import { platform } from '@/utils/platform' import { stringifyQuery } from './tools/queryString' // 请求基准地址 @@ -44,7 +43,6 @@ const httpInterceptor = { options.header = { ...options.header, 'Content-Type': 'application/json; charset=utf-8', - platform, // 可选,与 uniapp 定义的平台一致,告诉后台来源 } // 3. 添加 token 请求头标识 const tokenStore = useTokenStore() diff --git a/src/utils/platform.ts b/src/utils/platform.ts deleted file mode 100644 index 86801f1..0000000 --- a/src/utils/platform.ts +++ /dev/null @@ -1,26 +0,0 @@ -/* - * @Author: 菲鸽 - * @Date: 2024-03-28 19:13:55 - * @Last Modified by: 菲鸽 - * @Last Modified time: 2024-03-28 19:24:55 - */ -export const platform = __UNI_PLATFORM__ -export const isH5 = __UNI_PLATFORM__ === 'h5' -export const isApp = __UNI_PLATFORM__ === 'app' -export const isMp = __UNI_PLATFORM__.startsWith('mp-') -export const isMpWeixin = __UNI_PLATFORM__.startsWith('mp-weixin') -export const isMpAplipay = __UNI_PLATFORM__.startsWith('mp-alipay') -export const isMpToutiao = __UNI_PLATFORM__.startsWith('mp-toutiao') -export const isHarmony = __UNI_PLATFORM__.startsWith('app-harmony') - -const PLATFORM = { - platform, - isH5, - isApp, - isMp, - isMpWeixin, - isMpAplipay, - isMpToutiao, - isHarmony, -} -export default PLATFORM diff --git a/vite.config.ts b/vite.config.ts index 0218120..4c9d0c2 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -138,7 +138,6 @@ export default defineConfig(({ command, mode }) => { openDevTools(), ], define: { - __UNI_PLATFORM__: JSON.stringify(UNI_PLATFORM), __VITE_APP_PROXY__: JSON.stringify(VITE_APP_PROXY_ENABLE), }, css: {