Skip to content

Commit b89a7a0

Browse files
authored
update simulator (#48)
1 parent 581b534 commit b89a7a0

File tree

9 files changed

+97
-43
lines changed

9 files changed

+97
-43
lines changed

src/assets/image/device.svg

+6
Loading

src/assets/locales/en.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@
9797
"reference": "See detection rule"
9898
},
9999
"page": {
100-
"element": "Element"
100+
"element": "Element",
101+
"device": "Device"
101102
},
102103
"storage": {
103104
"empty-detail": "Select one to preview its value"

src/assets/locales/zh.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@
9797
"reference": "查看检测规则"
9898
},
9999
"page": {
100-
"element": "元素"
100+
"element": "元素",
101+
"device": "设备"
101102
},
102103
"storage": {
103104
"empty-detail": "选择查看其中一项的值"

src/pages/Devtools/BrowserFrame/index.less

+11
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,17 @@
5454
&-content {
5555
flex: 1;
5656
}
57+
.mobile-frame {
58+
flex: 1;
59+
display: flex;
60+
justify-content: center;
61+
align-items: center;
62+
&__body-content {
63+
height: 90%;
64+
aspect-ratio: 375 / 667;
65+
box-shadow: 0 0 4px 1px rgba(0, 0, 0, 0.1);
66+
}
67+
}
5768
&-divider {
5869
position: relative;
5970
width: 2px;

src/pages/Devtools/BrowserFrame/index.tsx

+40-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import type { PropsWithChildren } from 'react';
2-
import { useEffect, useRef } from 'react';
2+
import { useEffect, useMemo, useRef } from 'react';
33
import { useState } from 'react';
4-
import Icon from '@ant-design/icons';
4+
import Icon, { PicLeftOutlined, ReloadOutlined } from '@ant-design/icons';
55
import { ReactComponent as CellularSVG } from '@/assets/image/cellular.svg';
66
import { ReactComponent as BatterySVG } from '@/assets/image/battery.svg';
7+
import { ReactComponent as DeviceSVG } from '@/assets/image/device.svg';
78
import './index.less';
89
import { Button, Space, Spin } from 'antd';
910
import { ElementPanel } from '../ElementPanel';
1011
import { useTranslation } from 'react-i18next';
1112
import { useSocketMessageStore } from '@/store/socket-message';
13+
import { resolveClientInfo } from '@/utils/brand';
14+
import useSearch from '@/utils/useSearch';
1215

1316
function getTime() {
1417
const date = new Date();
@@ -41,6 +44,7 @@ export const PCFrame = ({
4144
const utilsRef = useRef<HTMLDivElement | null>(null);
4245
const xAxisRef = useRef(0);
4346
const [width, setWidth] = useState<string | number>('40%');
47+
4448
useEffect(() => {
4549
if (!elementVisible) {
4650
return;
@@ -60,8 +64,8 @@ export const PCFrame = ({
6064
// `mousemove` not working when meet iframe
6165
clientIframe.style.pointerEvents = 'none';
6266
containerWidth = containerArea?.getBoundingClientRect().width || 0;
63-
MAX_SIZE = containerWidth * 0.8;
64-
MIN_SIZE = containerWidth * 0.2;
67+
MAX_SIZE = containerWidth * 0.6;
68+
MIN_SIZE = containerWidth * 0.4;
6569
rightWidth = utilsArea?.getBoundingClientRect().width || 0;
6670
const { clientX } = e;
6771
xAxisRef.current = clientX;
@@ -92,6 +96,16 @@ export const PCFrame = ({
9296
document.removeEventListener('mouseup', end);
9397
};
9498
}, [elementVisible]);
99+
100+
const [enableDevice, setEnableDevice] = useState(false);
101+
const { version } = useSearch();
102+
useEffect(() => {
103+
const { osName } = resolveClientInfo(version);
104+
if (['iPhone', 'iPad', 'Android'].indexOf(osName) >= 0) {
105+
setEnableDevice(true);
106+
}
107+
}, [version]);
108+
95109
return (
96110
<div className="pc-frame" ref={containerRef}>
97111
<div className="pc-frame__top">
@@ -108,6 +122,16 @@ export const PCFrame = ({
108122
<div className="pc-frame__top-right">
109123
<Space>
110124
<Button
125+
type={elementVisible ? 'primary' : 'default'}
126+
icon={<PicLeftOutlined />}
127+
onClick={() => {
128+
setElementVisible(!elementVisible);
129+
}}
130+
>
131+
{t('element')}
132+
</Button>
133+
<Button
134+
icon={<ReloadOutlined />}
111135
onClick={() => {
112136
if (loading) return;
113137
onRefresh();
@@ -116,18 +140,27 @@ export const PCFrame = ({
116140
{ct('refresh')}
117141
</Button>
118142
<Button
143+
type={enableDevice ? 'primary' : 'default'}
144+
icon={<Icon component={DeviceSVG} style={{ fontSize: 14 }} />}
119145
onClick={() => {
120-
setElementVisible(!elementVisible);
146+
setEnableDevice((state) => !state);
147+
onRefresh();
121148
}}
122149
>
123-
{t('element')}
150+
{t('device')}
124151
</Button>
125152
</Space>
126153
</div>
127154
</div>
128155
<div className="pc-frame__body spin-container">
129156
<Spin spinning={loading} className="spin-controller" />
130-
<div className="pc-frame__body-content">{children}</div>
157+
{enableDevice ? (
158+
<div className="mobile-frame">
159+
<div className="mobile-frame__body-content">{children}</div>
160+
</div>
161+
) : (
162+
<div className="pc-frame__body-content">{children}</div>
163+
)}
131164
{elementVisible && (
132165
<>
133166
<div className="pc-frame__body-divider" ref={dividerRef} />

src/pages/Devtools/ConsolePanel/components/MainContent/index.tsx

+23-6
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,41 @@ export const MainContent = () => {
3535
}, [data]);
3636
useEffect(() => {
3737
const logType = [...data].pop()?.logType || '';
38-
const isEval = logType === 'debug-eval';
38+
const isDebug = ['debug-origin', 'debug-eval'].includes(logType);
3939
const evalError =
4040
data.length > 1 && data[data.length - 2].logType === 'debug-origin';
41-
if (isEval || evalError) {
41+
if (isDebug || evalError) {
4242
scrollToBottom();
4343
} else {
4444
const container = containerEl.current;
4545
if (!container) return;
4646

47-
const { offsetHeight, scrollTop, scrollHeight } = container;
47+
const { offsetHeight, scrollHeight } = container;
4848
if (scrollHeight > offsetHeight) {
49-
if (scrollTop + offsetHeight <= scrollHeight - 30) {
50-
setNewTips(true);
51-
}
49+
setNewTips(true);
5250
}
5351
}
5452
}, [data, scrollToBottom]);
5553

54+
useEffect(() => {
55+
const container = containerEl.current;
56+
if (!container) return;
57+
58+
const fn = () => {
59+
const { offsetHeight, scrollTop, scrollHeight } = container;
60+
if (scrollHeight > offsetHeight) {
61+
if (scrollTop + offsetHeight > scrollHeight - 30) {
62+
setNewTips(false);
63+
}
64+
}
65+
};
66+
67+
container.addEventListener('scrollend', fn);
68+
return () => {
69+
container.removeEventListener('scrollend', fn);
70+
};
71+
}, []);
72+
5673
return (
5774
<div className="console-list" ref={containerEl}>
5875
{data.map((item) => (

src/pages/Devtools/PagePanel/index.tsx

+4-25
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import { Empty } from 'antd';
2-
import { useEffect, useMemo, useRef, useState } from 'react';
3-
import { PCFrame, MobileFrame } from '../BrowserFrame';
2+
import { useEffect, useRef, useState } from 'react';
3+
import { PCFrame } from '../BrowserFrame';
44
import './index.less';
5-
import React from 'react';
6-
import useSearch from '@/utils/useSearch';
7-
import { resolveClientInfo } from '@/utils/brand';
85
import { useSocketMessageStore } from '@/store/socket-message';
96

107
function insertStyle(doc: Document, text: string) {
@@ -21,30 +18,12 @@ const PagePanel = () => {
2118
]);
2219
const [loading, setLoading] = useState(false);
2320
const frameRef = useRef<HTMLIFrameElement | null>(null);
24-
const { version } = useSearch();
25-
const os = useMemo(() => {
26-
const { osName } = resolveClientInfo(version);
27-
if (['iPhone', 'iPad'].indexOf(osName) >= 0) return 'iOS';
28-
if (osName === 'Android') return 'Android';
29-
return 'PC';
30-
}, [version]);
3121

3222
useEffect(() => {
3323
setLoading(true);
3424
refresh('page');
3525
// eslint-disable-next-line react-hooks/exhaustive-deps
3626
}, []);
37-
const FrameWrapper = useMemo(() => {
38-
switch (os) {
39-
case 'iOS':
40-
case 'Android':
41-
return ({ children, ...props }: any) =>
42-
React.createElement(MobileFrame, { ...props, os }, children);
43-
case 'PC':
44-
default:
45-
return PCFrame;
46-
}
47-
}, [os]);
4827

4928
useEffect(() => {
5029
if (html) {
@@ -80,7 +59,7 @@ const PagePanel = () => {
8059
return (
8160
<div className="page-panel">
8261
<div className="page-panel__content">
83-
<FrameWrapper
62+
<PCFrame
8463
loading={loading}
8564
onRefresh={() => {
8665
setLoading(true);
@@ -95,7 +74,7 @@ const PagePanel = () => {
9574
sandbox="allow-same-origin"
9675
referrerPolicy="strict-origin-when-cross-origin"
9776
/>
98-
</FrameWrapper>
77+
</PCFrame>
9978
</div>
10079
</div>
10180
);

src/pages/Devtools/SystemPanel/index.tsx

+8-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,13 @@ const SystemPanel = memo(() => {
6969
>
7070
<Row>
7171
{noSupport.map((feature) => (
72-
<Col span={8} key={feature.title}>
72+
<Col
73+
span={8}
74+
xxl={{
75+
span: 6,
76+
}}
77+
key={feature.title}
78+
>
7379
<FeatureItem {...feature} />
7480
</Col>
7581
))}
@@ -83,7 +89,7 @@ const SystemPanel = memo(() => {
8389
<Card>
8490
<Row>
8591
{value.map((feature) => (
86-
<Col span={8} key={feature.title}>
92+
<Col span={8} xxl={{ span: 6 }} key={feature.title}>
8793
<FeatureItem {...feature} />
8894
</Col>
8995
))}

yarn.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@
748748

749749
"@huolala-tech/page-spy@^1.3.0":
750750
version "1.3.0"
751-
resolved "https://registry.yarnpkg.com/@huolala-tech/page-spy/-/page-spy-1.3.0.tgz#9bc75341c0158efdf8400ddb036c5afd83657446"
751+
resolved "https://registry.npmjs.org/@huolala-tech/page-spy/-/page-spy-1.3.0.tgz#9bc75341c0158efdf8400ddb036c5afd83657446"
752752
integrity sha512-ivIVyHz0uyep96bsoPQHn+o30nOEwlwXoQ8rTxVv5E5I23fItdNAa827k2ZcUHbVnf7CaBWQa9DzPteNou9NdQ==
753753
dependencies:
754754
"@babel/runtime" "^7.13.0"

0 commit comments

Comments
 (0)