1
1
import type { PropsWithChildren } from 'react' ;
2
- import { useEffect , useRef } from 'react' ;
2
+ import { useEffect , useMemo , useRef } from 'react' ;
3
3
import { useState } from 'react' ;
4
- import Icon from '@ant-design/icons' ;
4
+ import Icon , { PicLeftOutlined , ReloadOutlined } from '@ant-design/icons' ;
5
5
import { ReactComponent as CellularSVG } from '@/assets/image/cellular.svg' ;
6
6
import { ReactComponent as BatterySVG } from '@/assets/image/battery.svg' ;
7
+ import { ReactComponent as DeviceSVG } from '@/assets/image/device.svg' ;
7
8
import './index.less' ;
8
9
import { Button , Space , Spin } from 'antd' ;
9
10
import { ElementPanel } from '../ElementPanel' ;
10
11
import { useTranslation } from 'react-i18next' ;
11
12
import { useSocketMessageStore } from '@/store/socket-message' ;
13
+ import { resolveClientInfo } from '@/utils/brand' ;
14
+ import useSearch from '@/utils/useSearch' ;
12
15
13
16
function getTime ( ) {
14
17
const date = new Date ( ) ;
@@ -41,6 +44,7 @@ export const PCFrame = ({
41
44
const utilsRef = useRef < HTMLDivElement | null > ( null ) ;
42
45
const xAxisRef = useRef ( 0 ) ;
43
46
const [ width , setWidth ] = useState < string | number > ( '40%' ) ;
47
+
44
48
useEffect ( ( ) => {
45
49
if ( ! elementVisible ) {
46
50
return ;
@@ -60,8 +64,8 @@ export const PCFrame = ({
60
64
// `mousemove` not working when meet iframe
61
65
clientIframe . style . pointerEvents = 'none' ;
62
66
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 ;
65
69
rightWidth = utilsArea ?. getBoundingClientRect ( ) . width || 0 ;
66
70
const { clientX } = e ;
67
71
xAxisRef . current = clientX ;
@@ -92,6 +96,16 @@ export const PCFrame = ({
92
96
document . removeEventListener ( 'mouseup' , end ) ;
93
97
} ;
94
98
} , [ 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
+
95
109
return (
96
110
< div className = "pc-frame" ref = { containerRef } >
97
111
< div className = "pc-frame__top" >
@@ -108,6 +122,16 @@ export const PCFrame = ({
108
122
< div className = "pc-frame__top-right" >
109
123
< Space >
110
124
< 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 /> }
111
135
onClick = { ( ) => {
112
136
if ( loading ) return ;
113
137
onRefresh ( ) ;
@@ -116,18 +140,27 @@ export const PCFrame = ({
116
140
{ ct ( 'refresh' ) }
117
141
</ Button >
118
142
< Button
143
+ type = { enableDevice ? 'primary' : 'default' }
144
+ icon = { < Icon component = { DeviceSVG } style = { { fontSize : 14 } } /> }
119
145
onClick = { ( ) => {
120
- setElementVisible ( ! elementVisible ) ;
146
+ setEnableDevice ( ( state ) => ! state ) ;
147
+ onRefresh ( ) ;
121
148
} }
122
149
>
123
- { t ( 'element ' ) }
150
+ { t ( 'device ' ) }
124
151
</ Button >
125
152
</ Space >
126
153
</ div >
127
154
</ div >
128
155
< div className = "pc-frame__body spin-container" >
129
156
< 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
+ ) }
131
164
{ elementVisible && (
132
165
< >
133
166
< div className = "pc-frame__body-divider" ref = { dividerRef } />
0 commit comments