【代码优化】实现动态 terminal 终端类型的计算
parent
15ce250c1b
commit
bb1da04177
|
@ -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;
|
||||
|
|
|
@ -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 - 营销模块 ==========
|
||||
|
|
Loading…
Reference in New Issue