From c9434b9ec9750afcd2de321d1b7fd33d7a89be13 Mon Sep 17 00:00:00 2001 From: Ordinary Date: Sat, 3 Aug 2024 10:33:09 +0800 Subject: [PATCH 1/4] =?UTF-8?q?feat(request):=20=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?=E5=8A=A8=E6=80=81Terminal=E5=8A=9F=E8=83=BD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sheep/request/index.js | 18 +++++++++--------- sheep/util/const.js | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 9 deletions(-) diff --git a/sheep/request/index.js b/sheep/request/index.js index 700c7dda..50ac2dea 100644 --- a/sheep/request/index.js +++ b/sheep/request/index.js @@ -4,13 +4,12 @@ */ import Request from 'luch-request'; -import { baseUrl, apiPath, tenantId } from '@/sheep/config'; +import { apiPath, baseUrl, tenantId } from '@/sheep/config'; import $store from '@/sheep/store'; import $platform from '@/sheep/platform'; -import { - showAuthModal -} from '@/sheep/hooks/useModal'; +import { showAuthModal } from '@/sheep/hooks/useModal'; import AuthUtil from '@/sheep/api/member/auth'; +import { getTerminalEnumByUniPlatform } from '@/sheep/util/const'; const options = { // 显示操作成功消息 默认不显示 @@ -93,13 +92,14 @@ http.interceptors.request.use( // 增加 token 令牌、terminal 终端、tenant 租户的请求头 const token = getAccessToken(); if (token) { - config.header['Authorization'] = token; - } - // TODO 芋艿:特殊处理 + config.header['Authorization'] = token; + } + + const terminalType = uni.getSystemInfoSync().uniPlatform + config.header['terminal'] = getTerminalEnumByUniPlatform(terminalType); + config.header['Accept'] = '*/*'; config.header['tenant-id'] = tenantId; - config.header['terminal'] = '20'; - // config.header['Authorization'] = 'Bearer test247'; return config; }, (error) => { diff --git a/sheep/util/const.js b/sheep/util/const.js index e1d3ee08..4339ef90 100644 --- a/sheep/util/const.js +++ b/sheep/util/const.js @@ -1,3 +1,39 @@ +// ========== COMMON - 公共模块 ========== + +/** + * 与后端Terminal枚举一一对应 + */ +export const TerminalEnum = { + UNKNOWN: 0, // 未知, 目的:在无法解析到 terminal 时,使用它 + WECHAT_MINI_PROGRAM: 10, //微信小程序 + WECHAT_WAP: 11, // 微信公众号 + H5: 20, // H5 网页 + APP: 31, // 手机 App +}; + +/** + * 将Uniapp提供的平台转换为后端所需的Terminal值 + * @param platformType Uniapp提供的平台类型 + */ +export const getTerminalEnumByUniPlatform = (platformType) => { + let terminal; + // 与后端terminal枚举一一对应 + switch (platformType) { + case 'app': + terminal = TerminalEnum.APP; + break; + case 'web': + terminal = TerminalEnum.H5; + break; + case 'mp-weixin': + terminal = TerminalEnum.WECHAT_MINI_PROGRAM; + break; + default: + terminal = TerminalEnum.UNKNOWN; + } + return terminal; +}; + // ========== MALL - 营销模块 ========== import dayjs from "dayjs"; From 2eb1a1bf41473920363f73584e1e0662b1a1a401 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=A2=E8=B6=8A?= <552369664@qq.com> Date: Thu, 8 Aug 2024 09:45:12 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E5=95=86=E5=93=81=E8=AF=A6=E6=83=85?= =?UTF-8?q?=E5=92=8C=E8=B4=AD=E7=89=A9=E8=BD=A6=E8=B7=B3=E8=BD=AC=E5=88=B0?= =?UTF-8?q?=E7=BB=93=E7=AE=97=E9=A1=B5=E9=9D=A2=E6=97=B6=E4=BC=A0=E5=85=A5?= =?UTF-8?q?=E5=95=86=E5=93=81=E5=88=86=E7=B1=BB=E7=BC=96=E5=8F=B7=EF=BC=8C?= =?UTF-8?q?=E4=BB=A5=E4=BE=BF=E6=9F=A5=E8=AF=A2=E5=8F=AF=E7=94=A8=E4=BC=98?= =?UTF-8?q?=E6=83=A0=E5=88=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/goods/index.vue | 3 ++- pages/index/cart.vue | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/pages/goods/index.vue b/pages/goods/index.vue index 488c435d..bf0b0cb9 100644 --- a/pages/goods/index.vue +++ b/pages/goods/index.vue @@ -156,7 +156,8 @@ data: JSON.stringify({ items: [{ skuId: e.id, - count: e.goods_num + count: e.goods_num, + categoryId: state.goodsInfo.categoryId }] }), }); diff --git a/pages/index/cart.vue b/pages/index/cart.vue index 3f42523b..633b567d 100644 --- a/pages/index/cart.vue +++ b/pages/index/cart.vue @@ -107,6 +107,7 @@ skuId: item.sku.id, count: item.count, cartId: item.id, + categoryId: item.spu.categoryId }) goods_list.push({ // goods_id: item.goods_id, From e12698162892ea919105ced07380c62688126d1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=A2=E8=B6=8A?= <552369664@qq.com> Date: Thu, 8 Aug 2024 09:56:21 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=88=87=E6=8D=A2?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E6=96=B9=E5=BC=8F=E7=9A=84=E6=97=B6=E5=80=99?= =?UTF-8?q?=EF=BC=8C=E5=81=B6=E7=8E=B0=E7=99=BB=E5=BD=95=E9=9D=A2=E6=9D=BF?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E5=BC=B9=E5=87=BA=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sheep/hooks/useModal.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sheep/hooks/useModal.js b/sheep/hooks/useModal.js index b8505256..003fe809 100644 --- a/sheep/hooks/useModal.js +++ b/sheep/hooks/useModal.js @@ -14,7 +14,7 @@ export function showAuthModal(type = 'smsLogin') { modal.$patch((state) => { state.auth = type; }); - }, 200); + }, 500); closeAuthModal(); } else { modal.$patch((state) => { From bb1da04177667a289dcda1c6d16f84d4d8db5a2a Mon Sep 17 00:00:00 2001 From: YunaiV Date: Thu, 8 Aug 2024 13:04:34 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E3=80=90=E4=BB=A3=E7=A0=81=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E3=80=91=E5=AE=9E=E7=8E=B0=E5=8A=A8=E6=80=81=20termin?= =?UTF-8?q?al=20=E7=BB=88=E7=AB=AF=E7=B1=BB=E5=9E=8B=E7=9A=84=E8=AE=A1?= =?UTF-8?q?=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 - 营销模块 ==========