Skip to content

Commit fffdcf9

Browse files
committed
fix: not local ip access mini tips
1 parent 7792397 commit fffdcf9

File tree

6 files changed

+36
-11
lines changed

6 files changed

+36
-11
lines changed

packages/umi-plugin-ui/src/bubble/Error.jsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,18 @@ const ErrorWrapper = styled.div`
3030
span {
3131
font-size: 14px;
3232
color: rgba(255, 255, 255, 0.65);
33+
font-weight: 300;
3334
}
3435
`;
3536

36-
export default ({ isBigfish, message }) => (
37+
export default ({ isBigfish, message, tips }) => (
3738
<ErrorWrapper>
38-
<ErrorSvg />
39-
<p>
40-
{isBigfish ? 'Bigfish' : 'Umi'} {message.offline}
41-
</p>
42-
<span>{message.restart}</span>
39+
<div style={{ maxWidth: '45%' }}>
40+
<ErrorSvg />
41+
<p>
42+
{isBigfish ? 'Bigfish' : 'Umi'} {message.offline}
43+
</p>
44+
<span>{tips || message.restart}</span>
45+
</div>
4346
</ErrorWrapper>
4447
);

packages/umi-plugin-ui/src/bubble/bubble-locale/en-US.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ export default {
55
offline: 'UI connection failed',
66
restart: 'Please try restarting the dev service',
77
loading: 'Loading',
8+
code_1002:
9+
'Umi UI does not allow non-local IP access for project security reasons, if you want non-local IP access, add HOST=0.0.0.0 environment variable at startup',
810
};

packages/umi-plugin-ui/src/bubble/bubble-locale/pt-BR.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ export default {
55
offline: 'UI falha na conexão',
66
restart: 'Por favor, tente reiniciar o serviço dev',
77
loading: 'Carregar',
8+
code_1002:
9+
'A interface do usuário do Umi não permite acesso IP não local por razões de segurança do projeto. Se você deseja acesso IP local, adicione a variável de ambiente HOST = 0.0.0.0 na inicialização',
810
};

packages/umi-plugin-ui/src/bubble/bubble-locale/zh-CN.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ export default {
55
offline: 'UI 连接失败',
66
restart: '请尝试重启 dev 服务',
77
loading: '加载中',
8+
code_1002:
9+
'Umi UI 出于项目安全考虑,不允许非本地 IP 访问,如果希望非本地 IP 访问,启动时加上 HOST=0.0.0.0 环境变量',
810
};

packages/umi-plugin-ui/src/bubble/bubble-locale/zh-TW.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ export default {
55
offline: 'UI 連接失敗',
66
restart: '請嘗試重啟 dev 服務',
77
loading: '加載中',
8+
code_1002:
9+
'Umi UI 出於項目安全考慮,不允許非本地 IP 訪問,如果希望非本地 IP 訪問,啟動時加上 HOST=0.0.0.0 環境變量',
810
};

packages/umi-plugin-ui/src/bubble/index.jsx

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class App extends React.Component {
4848
locale,
4949
edit: false,
5050
editText: {},
51+
tips: '',
5152
};
5253
window.addEventListener('message', this.handleMessage, false);
5354
const { hostname, protocol } = window.location;
@@ -69,6 +70,9 @@ class App extends React.Component {
6970
}
7071

7172
componentWillUnmount() {
73+
this.setState({
74+
tips: '',
75+
});
7276
window.removeEventListener('message', this.handleMessage, false);
7377
}
7478

@@ -125,11 +129,16 @@ class App extends React.Component {
125129

126130
async componentDidMount() {
127131
const { path } = this.props;
132+
const message = this.getMessage();
128133
try {
129134
await initSocket(`${this.baseUrl}/umiui`, {
130-
onError: () => {
135+
onError: e => {
136+
// https://developer.mozilla.org/zh-CN/docs/Web/API/CloseEvent
137+
// 非 localhost 访问
138+
const { code } = e;
131139
this.setState({
132140
connected: false,
141+
tips: message[`code_${code}`] || '',
133142
});
134143
},
135144
onMessage: ({ type, payload }) => {
@@ -218,14 +227,19 @@ class App extends React.Component {
218227
});
219228
};
220229

230+
getMessage = () => {
231+
const { locale } = this.state;
232+
return messages[locale] || messages['zh-CN'];
233+
};
234+
221235
render() {
222-
const { open, connected, uiLoaded, loading, locale, edit, editText } = this.state;
236+
const { open, connected, uiLoaded, loading, locale, edit, editText, tips } = this.state;
223237
const { isBigfish = false } = this.props;
224238
const miniUrl = this.getMiniUrl();
225239
// get locale when first render
226240
// switch in the project can't be listened, the lifecycle can't be trigger
227241
// TODO: use Context but need to compatible with other React version
228-
const message = messages[locale] || messages['zh-CN'];
242+
const message = this.getMessage();
229243

230244
return (
231245
<Bubble
@@ -242,14 +256,14 @@ class App extends React.Component {
242256
>
243257
{open !== undefined && (
244258
<Modal visible={open}>
245-
{!uiLoaded && (
259+
{!uiLoaded && !tips && (
246260
<LoadingWrapper>
247261
<Loading />
248262
<p style={{ marginTop: 8 }}>{message.loading}</p>
249263
</LoadingWrapper>
250264
)}
251265
{!connected ? (
252-
<Error message={message} isBigfish={isBigfish} />
266+
<Error message={message} tips={tips} isBigfish={isBigfish} />
253267
) : (
254268
<iframe
255269
id="umi-ui-bubble"

0 commit comments

Comments
 (0)