From cc94ee7aff888f917849414ba2800d349301db1e Mon Sep 17 00:00:00 2001 From: owen Date: Mon, 16 Oct 2023 15:06:58 +0800 Subject: [PATCH] =?UTF-8?q?1.=20APP=E5=A2=9E=E5=8A=A0=E7=BB=88=E7=AB=AFHea?= =?UTF-8?q?der[terminal]=202.=20=E8=AE=A2=E5=8D=95=E3=80=81=E4=BC=9A?= =?UTF-8?q?=E5=91=98=E6=B3=A8=E5=86=8C=E8=AE=B0=E5=BD=95=E6=9D=A5=E6=BA=90?= =?UTF-8?q?=E7=BB=88=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/dict.js | 22 +++++++++++++++++++++- utils/request.js | 4 ++++ utils/util.js | 22 ++++++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/utils/dict.js b/utils/dict.js index ff1b2696..847a78b8 100644 --- a/utils/dict.js +++ b/utils/dict.js @@ -36,4 +36,24 @@ export const BrokerageWithdrawTypeEnum = { name: '支付宝', icon: 'icon-icon34' } -} \ No newline at end of file +} + +/** 终端的枚举 */ +export const TerminalEnum = { + WECHAT_MINI_PROGRAM: { + terminal: 10, + name: '微信小程序' + }, + WECHAT_WAP: { + terminal: 11, + name: '微信公众号' + }, + H5: { + terminal: 20, + name: 'H5 网页' + }, + APP: { + terminal: 31, + name: '手机 App' + } +} diff --git a/utils/request.js b/utils/request.js index 70e76634..5137e6ef 100644 --- a/utils/request.js +++ b/utils/request.js @@ -9,6 +9,7 @@ import { checkLogin } from '../libs/login'; import store from '../store'; +import {getTerminal} from "./util"; // TODO 芋艿:临时解决 uniapp 在小程序,undefined 会被 tostring 的问题 function deleteUndefinedProperties(obj) { @@ -55,6 +56,9 @@ function baseRequest(url, method, data, { header['tenant-id'] = 1 } + // 终端 + header['terminal'] = getTerminal() + if (store.state.app.token) { // header[TOKENNAME] = store.state.app.token; header['Authorization'] = 'Bearer ' + store.state.app.token; diff --git a/utils/util.js b/utils/util.js index ec2a7953..ba0ca681 100644 --- a/utils/util.js +++ b/utils/util.js @@ -1,4 +1,6 @@ import { HTTP_REQUEST_URL } from '@/config/app.js'; +import {TerminalEnum} from "./dict"; +import wechat from "../libs/wechat"; export default { @@ -814,3 +816,23 @@ export function handleTree(data, id, parentId, children, rootId) { }); return treeData !== '' ? treeData : data; } + +/** + * 获取终端类型 + * https://uniapp.dcloud.net.cn/tutorial/platform.html#preprocessor + * + * @return {number | null} 终端类型 + */ +export function getTerminal() { + let terminal = null; + // #ifdef MP-WEIXIN + terminal = TerminalEnum.WECHAT_MINI_PROGRAM.terminal + // #endif + // #ifdef H5 || WEB + terminal = wechat.isWeixin() ? TerminalEnum.WECHAT_WAP.terminal : TerminalEnum.H5.terminal + // #endif + // #ifdef APP-PLUS || APP + terminal = TerminalEnum.APP.terminal + // #endif + return terminal; +}