Commit a39c5a94 authored by 武广's avatar 武广

feat: 添加tob进入页面入口

parent 896d3873
......@@ -11,9 +11,10 @@ import { connect } from 'dva';
import { Icon as LegacyIcon } from '@ant-design/compatible';
import { Result, Button, Layout, Menu } from 'antd';
import Authorized from '@/utils/Authorized';
import localStorage from '@/utils/localStorage';
import RightContent from '@/components/GlobalHeader/RightContent';
import MessageReminder from '@/components/MessageReminder';
import { getAuthorityFromRouter } from '@/utils/utils';
import { getAuthorityFromRouter, getUrlSearchParams } from '@/utils/utils';
import { getSocketUrl } from '@/services/messageReminder';
import logo from '../assets/logo.png';
import style from './BasicLayout.less';
......@@ -54,6 +55,7 @@ const BasicLayout = props => {
const [siderCollapsed, setSiderCollapsed] = useState(false);
const messageReminderComplexRef = useRef();
// const audioRef = useRef()
useEffect(() => {
......@@ -131,7 +133,8 @@ const BasicLayout = props => {
),
);
return window.__POWERED_BY_QIANKUN__ ? (
// 嵌套乾坤
const qianKunLayout = () => (
<div id="micro">
<Layout className={style.layout}>
<Sider
......@@ -148,7 +151,10 @@ const BasicLayout = props => {
</Layout>
</Layout>
</div>
) : (
);
// 商家端直接登录
const merchantLayout = () => (
<ProLayout
logo={logo}
onCollapse={handleMenuCollapse}
......@@ -206,6 +212,26 @@ const BasicLayout = props => {
{/* <Button ref={audioRef} onClick={() => { socket.play() }}>声音</Button> */}
</ProLayout>
);
// tob登录
const tobLayout = () => (
<Layout className={style.tobLayout}>
<Authorized noMatch={noMatch}>{children}</Authorized>
</Layout>
);
// 是否从消费地图后管跳转过来
const searchPrams = getUrlSearchParams();
const isTob = searchPrams.source === 'tob';
if (window.__POWERED_BY_QIANKUN__) {
return qianKunLayout();
}
if (isTob && searchPrams.token) {
localStorage.set('tobToken', searchPrams.token || '');
return tobLayout();
}
return merchantLayout();
};
export default connect(({ global, settings, menu }) => ({
collapsed: global.collapsed,
......
......@@ -44,3 +44,11 @@
}
}
}
.tobLayout {
:global {
.ant-pro-page-header-wrap-page-header-warp {
display: none !important;
}
}
}
......@@ -76,7 +76,7 @@ const refreshRequest = async (url, options) => {
// request拦截器, 改变url 或 options.
request.interceptors.request.use(async (url, options) => {
const token = localStorage.get('token');
const token = localStorage.get('tobToken') || localStorage.get('token');
if (!token && !url.includes('/v2/oauth/login')) {
window.location.href = `${window.origin}/user/login`;
}
......
......@@ -171,3 +171,24 @@ export const getErrorMessage = err => {
})(err);
return message;
};
// 获取地址栏参数,name:参数名称
export const getUrlParams = name => {
const regArg = new RegExp(`(^|&)${name}=([^&]*)(&|$)`);
const r = window.location.search.substr(1).match(regArg);
if (r != null) return decodeURIComponent(r[2]);
return null;
};
// 获取地址栏所以参数
export const getUrlSearchParams = () => {
const newObj = {};
const url = window.location.search; // 获取url中"?"符后的字符串
if (url.indexOf('?') !== -1) {
const strs = url.replace('?', '').split('&');
for (let i = 0; i < strs.length; i++) {
newObj[strs[i].split('=')[0]] = strs[i].split('=')[1] || '';
}
}
return newObj;
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment