-
-
Notifications
You must be signed in to change notification settings - Fork 40
/
index.tsx
87 lines (80 loc) · 2.53 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import { useEffect, useRef, useState } from 'react';
import { Card, Input, Checkbox, Button, Form } from 'antd';
import { history, useLocation } from 'umi';
import { PageHeaderWrapper } from '@ant-design/pro-layout';
import { withSwitchTab } from 'use-switch-tabs';
export default withSwitchTab(() => {
const [text, setText] = useState<string>();
const [options, setOptions] = useState<any[]>([]);
const pageLocation = useLocation();
const pageTabKeyRef = useRef(window.tabsAction.getTabKey(pageLocation));
const [active, setActive] = useState(pageTabKeyRef.current === window.tabsAction.getTabKey());
useEffect(() => {
const disposer = window.tabsAction.listenActiveChange((tabKey) => {
setActive(pageTabKeyRef.current === tabKey);
});
return () => disposer();
}, []);
const handleSearch = () => {
history.push({
pathname: `/switch-tabs-demos/result`,
state: options.includes('withState') ? { state: 'yes', text } : null,
query: options.includes('withQuery')
? { query: 'yes', text: text || null }
: { text: text || null },
});
};
return (
<PageHeaderWrapper
title={`Query [${active ? 'active' : 'inactive'}]`}
content="Input and press enter to new page"
>
<Card title={`Query [${active ? 'active' : 'inactive'}]`}>
<Form.Item
labelCol={{ xs: 24 }}
labelAlign="left"
label="text"
extra={
<>
<Checkbox.Group
style={{ marginTop: 12 }}
value={options}
options={[
{
label: 'with state (`{ state: "yes"}`)',
value: 'withState',
},
{
label: 'with query (`{ query: "yes"}`)',
value: 'withQuery',
},
]}
onChange={(_options) => {
setOptions(_options);
}}
/>
<Button
onClick={() => {
setText('nice');
}}
>
setText: nice
</Button>
</>
}
>
<Input
value={text}
onChange={(e) => setText(e.target.value)}
onPressEnter={() => {
handleSearch();
}}
/>
</Form.Item>
<Button type="primary" onClick={() => handleSearch()}>
查询
</Button>
</Card>
</PageHeaderWrapper>
);
});