【代码优化】实现动态 terminal 终端类型的计算
parent
15ce250c1b
commit
bb1da04177
|
|
@ -9,7 +9,7 @@ import $store from '@/sheep/store';
|
||||||
import $platform from '@/sheep/platform';
|
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 AuthUtil from '@/sheep/api/member/auth';
|
||||||
import { getTerminalEnumByUniPlatform } from '@/sheep/util/const';
|
import { getTerminal } from '@/sheep/util/const';
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
// 显示操作成功消息 默认不显示
|
// 显示操作成功消息 默认不显示
|
||||||
|
|
@ -94,9 +94,7 @@ http.interceptors.request.use(
|
||||||
if (token) {
|
if (token) {
|
||||||
config.header['Authorization'] = token;
|
config.header['Authorization'] = token;
|
||||||
}
|
}
|
||||||
|
config.header['terminal'] = getTerminal();
|
||||||
const terminalType = uni.getSystemInfoSync().uniPlatform
|
|
||||||
config.header['terminal'] = getTerminalEnumByUniPlatform(terminalType);
|
|
||||||
|
|
||||||
config.header['Accept'] = '*/*';
|
config.header['Accept'] = '*/*';
|
||||||
config.header['tenant-id'] = tenantId;
|
config.header['tenant-id'] = tenantId;
|
||||||
|
|
|
||||||
|
|
@ -12,26 +12,23 @@ export const TerminalEnum = {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将Uniapp提供的平台转换为后端所需的Terminal值
|
* 将 uni-app 提供的平台转换为后端所需的 terminal值
|
||||||
* @param platformType Uniapp提供的平台类型
|
*
|
||||||
|
* @return 终端
|
||||||
*/
|
*/
|
||||||
export const getTerminalEnumByUniPlatform = (platformType) => {
|
export const getTerminal = () => {
|
||||||
let terminal;
|
const platformType = uni.getSystemInfoSync().uniPlatform;
|
||||||
// 与后端terminal枚举一一对应
|
// 与后端terminal枚举一一对应
|
||||||
switch (platformType) {
|
switch (platformType) {
|
||||||
case 'app':
|
case 'app':
|
||||||
terminal = TerminalEnum.APP;
|
return TerminalEnum.APP;
|
||||||
break;
|
|
||||||
case 'web':
|
case 'web':
|
||||||
terminal = TerminalEnum.H5;
|
return TerminalEnum.H5;
|
||||||
break;
|
|
||||||
case 'mp-weixin':
|
case 'mp-weixin':
|
||||||
terminal = TerminalEnum.WECHAT_MINI_PROGRAM;
|
return TerminalEnum.WECHAT_MINI_PROGRAM;
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
terminal = TerminalEnum.UNKNOWN;
|
return TerminalEnum.UNKNOWN;
|
||||||
}
|
}
|
||||||
return terminal;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// ========== MALL - 营销模块 ==========
|
// ========== MALL - 营销模块 ==========
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue