1
+ import * as React from 'react'
2
+ import { observable , action , autorun , runInAction , computed } from 'mobx' ;
3
+ import { inject , observer } from 'mobx-react'
4
+ import { Row , Col , Button , Badge , Icon , Form , Input , Select } from 'antd' ;
5
+
6
+ const FormItem = Form . Item
7
+ const TextArea = Input . TextArea
8
+ const Option = Select . Option
9
+
10
+ const styles = {
11
+ block : {
12
+ marginBottom : '20px' ,
13
+ boxShadow : 'rgba(0, 0, 0, 0.12) 0px 1px 6px, rgba(0, 0, 0, 0.12) 0px 1px 4px' ,
14
+ padding : '10px'
15
+ } ,
16
+ flex : {
17
+ display : 'flex' ,
18
+ alignItems : 'center'
19
+ } ,
20
+ padding : {
21
+ padding : '10px 0'
22
+ }
23
+ }
24
+
25
+ @observer
26
+ export default class DemoMobx extends React . Component < IProps > {
27
+
28
+ // state = {
29
+ // count: 0,
30
+ // }
31
+ // add = () => {
32
+ // this.setState({
33
+ // count: ++this.state.count
34
+ // })
35
+ // }
36
+ // dec = () => {
37
+ // this.setState({
38
+ // count: --this.state.count
39
+ // })
40
+ // }
41
+
42
+ @observable count = 66 ;
43
+
44
+ @action add = ( ) => { this . count ++ }
45
+ @action dec = ( ) => { this . count -- }
46
+
47
+ componentDidMount ( ) {
48
+ // console.log($http)
49
+ // console.log(this.props)
50
+ console . log ( this )
51
+ }
52
+
53
+ render ( ) {
54
+ // const {count} = this.state
55
+ const { count, add, dec} = this
56
+
57
+ return < div >
58
+ < section style = { styles . block } >
59
+ < h3 > mini测试</ h3 >
60
+ < Row style = { styles . padding } >
61
+ < Col span = { 24 } >
62
+ < Button onClick = { dec } >
63
+ < Icon type = "minus" />
64
+ </ Button >
65
+ < Badge count = { count } showZero = { true } />
66
+ < Button onClick = { add } >
67
+ < Icon type = "plus" />
68
+ </ Button >
69
+ </ Col >
70
+ </ Row >
71
+ </ section >
72
+
73
+ { /* <section style={styles.block}>
74
+ <h3>接口测试</h3>
75
+ <Row style={styles.padding}>
76
+ <Col span={24}>
77
+ <Form>
78
+ <FormItem label="api" labelCol={{span: 4}} wrapperCol={{span: 20}}>
79
+ <Row gutter={8}>
80
+ <Col span={12}>
81
+ <Input placeholder="请输入url" onChange={e => inputApi(e.target.value)} value={apiUrl}/>
82
+ </Col>
83
+ {
84
+ apiType === '/api' ?
85
+ <Col span={3}>
86
+ <Select value={apiMethod}
87
+ onChange={methodChange}>
88
+ <Option value="GET">GET</Option>
89
+ <Option value="POST">POST</Option>
90
+ <Option value="PUT">PUT</Option>
91
+ <Option value="DELETE">DELETE</Option>
92
+ </Select>
93
+ </Col> : ''
94
+ }
95
+ <Col span={3}>
96
+ <Select value={apiType}
97
+ onChange={typeChange}>
98
+ <Option value="/api">RESTful</Option>
99
+ <Option value="/graphql">GraphQL</Option>
100
+ </Select>
101
+ </Col>
102
+ <Col span={6}>
103
+ <Button type="primary" onClick={testApi}>发送</Button>
104
+ </Col>
105
+ </Row>
106
+ </FormItem>
107
+ <FormItem label="参数(json格式)" labelCol={{span: 4}} wrapperCol={{span: 12}}>
108
+ <TextArea rows={6} onChange={e => inputParams(e.target.value)} value={apiParams}/>
109
+ </FormItem>
110
+ <FormItem label="结果" labelCol={{span: 4}} wrapperCol={{span: 18}}>
111
+ <TextArea rows={24} value={apiResult}/>
112
+ </FormItem>
113
+ </Form>
114
+ </Col>
115
+ </Row>
116
+ </section>
117
+
118
+ <section style={styles.block}>
119
+ <h3>文件上传</h3>
120
+ <Row style={styles.padding}>
121
+ <Col span={24}>
122
+ <Form>
123
+ <FormItem label="选择文件" labelCol={{span: 4}} wrapperCol={{span: 20}}>
124
+ <Row gutter={8}>
125
+ <Col span={12}>
126
+ <input type="file" placeholder="请选择文件" onChange={e => fileChange(e)}/>
127
+ </Col>
128
+ <Col span={6}>
129
+ <Button type="primary" onClick={upload}>上传</Button>
130
+ <Button onClick={fileChange}>清空</Button>
131
+ </Col>
132
+ </Row>
133
+ </FormItem>
134
+ </Form>
135
+ </Col>
136
+ </Row>
137
+ </section>
138
+ */ }
139
+ </ div >
140
+ }
141
+ }
0 commit comments