From bb1da04177667a289dcda1c6d16f84d4d8db5a2a Mon Sep 17 00:00:00 2001 From: YunaiV Date: Thu, 8 Aug 2024 13:04:34 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E3=80=91=E5=AE=9E=E7=8E=B0=E5=8A=A8=E6=80=81=20terminal=20?= =?UTF-8?q?=E7=BB=88=E7=AB=AF=E7=B1=BB=E5=9E=8B=E7=9A=84=E8=AE=A1=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sheep/request/index.js | 6 ++---- sheep/util/const.js | 21 +++++++++------------ 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/sheep/request/index.js b/sheep/request/index.js index 50ac2dea..492f08c9 100644 --- a/sheep/request/index.js +++ b/sheep/request/index.js @@ -9,7 +9,7 @@ import $store from '@/sheep/store'; import $platform from '@/sheep/platform'; import { showAuthModal } from '@/sheep/hooks/useModal'; import AuthUtil from '@/sheep/api/member/auth'; -import { getTerminalEnumByUniPlatform } from '@/sheep/util/const'; +import { getTerminal } from '@/sheep/util/const'; const options = { // 显示操作成功消息 默认不显示 @@ -94,9 +94,7 @@ http.interceptors.request.use( if (token) { config.header['Authorization'] = token; } - - const terminalType = uni.getSystemInfoSync().uniPlatform - config.header['terminal'] = getTerminalEnumByUniPlatform(terminalType); + config.header['terminal'] = getTerminal(); config.header['Accept'] = '*/*'; config.header['tenant-id'] = tenantId; diff --git a/sheep/util/const.js b/sheep/util/const.js index 4339ef90..9cf98bf3 100644 --- a/sheep/util/const.js +++ b/sheep/util/const.js @@ -12,26 +12,23 @@ export const TerminalEnum = { }; /** - * 将Uniapp提供的平台转换为后端所需的Terminal值 - * @param platformType Uniapp提供的平台类型 + * 将 uni-app 提供的平台转换为后端所需的 terminal值 + * + * @return 终端 */ -export const getTerminalEnumByUniPlatform = (platformType) => { - let terminal; +export const getTerminal = () => { + const platformType = uni.getSystemInfoSync().uniPlatform; // 与后端terminal枚举一一对应 switch (platformType) { case 'app': - terminal = TerminalEnum.APP; - break; + return TerminalEnum.APP; case 'web': - terminal = TerminalEnum.H5; - break; + return TerminalEnum.H5; case 'mp-weixin': - terminal = TerminalEnum.WECHAT_MINI_PROGRAM; - break; + return TerminalEnum.WECHAT_MINI_PROGRAM; default: - terminal = TerminalEnum.UNKNOWN; + return TerminalEnum.UNKNOWN; } - return terminal; }; // ========== MALL - 营销模块 ==========