|
@@ -1,110 +1,126 @@
|
1
|
1
|
import React, { useState, useEffect, useRef } from 'react';
|
2
|
2
|
import { Button,Form,Input,Message,Select, Switch } from '@alifd/next';
|
3
|
|
-import styles from './index.module.scss';
|
4
|
3
|
import { request } from 'ice';
|
|
4
|
+import styles from './index.module.scss';
|
|
5
|
+
|
|
6
|
+const apiService = 'http://codeapi.njyunzhi.com'
|
5
|
7
|
|
6
|
8
|
const postData = {
|
7
|
|
- mysqlIp: process.env.NODE_ENV === 'development' ? 'rm-uf6z3z6jq11x653d77o.mysql.rds.aliyuncs.com' : undefined,
|
8
|
|
- mysqlPort: '3306',
|
9
|
|
- mysqlUsername: 'root',
|
10
|
|
- mysqlUserpass: process.env.NODE_ENV === 'development' ? 'DQ@0lW##kBb2+-jPZC1s$Ma0h5$9W((q' : undefined,
|
11
|
|
- mysqlName: '',
|
|
9
|
+ mysqlIp: process.env.NODE_ENV === 'development' ? 'rm-uf6z3z6jq11x653d77o.mysql.rds.aliyuncs.com' : undefined,
|
|
10
|
+ mysqlPort: '3306',
|
|
11
|
+ mysqlUsername: 'root',
|
|
12
|
+ mysqlUserpass: process.env.NODE_ENV === 'development' ? 'DQ@0lW##kBb2+-jPZC1s$Ma0h5$9W((q' : undefined,
|
|
13
|
+ mysqlName: '',
|
12
|
14
|
}
|
13
|
15
|
|
14
|
16
|
const tjData = { packPath:'com.yunzhi',author:'yansen' }
|
15
|
17
|
const FormItem = Form.Item;
|
16
|
18
|
|
17
|
19
|
const formItemLayout = {
|
18
|
|
- labelCol: {xxs: 4, l: 4},
|
19
|
|
- wrapperCol: {xxs: 20, l: 16}
|
|
20
|
+ labelCol: {xxs: 4, l: 4},
|
|
21
|
+ wrapperCol: {xxs: 20, l: 16}
|
20
|
22
|
};
|
21
|
23
|
|
22
|
24
|
const Guide = props => {
|
23
|
|
- const [dataSource, setDataSource] = useState([])
|
24
|
|
- const [dbData, setDbData] = useState({})
|
|
25
|
+ const [loading, setLoading] = useState(false)
|
|
26
|
+ const [generating, setGenerating] = useState(false)
|
|
27
|
+ const [dataSource, setDataSource] = useState([])
|
|
28
|
+ const [dbData, setDbData] = useState({})
|
25
|
29
|
|
26
|
|
- const handleSubmit = (values) => {
|
27
|
|
- console.log('Get form value:', values);
|
28
|
|
- setDbData(values)
|
29
|
|
- request({
|
30
|
|
- url: '/mydb/connection',
|
31
|
|
- method: 'post',
|
32
|
|
- data: values
|
33
|
|
- }).then((response) => {
|
34
|
|
- setDataSource(response)
|
35
|
|
- Message.success('连接成功,请选择要生成的库')})
|
36
|
|
- .catch((err) => {Message.error('连接出错,请检查配置')});
|
37
|
|
- };
|
|
30
|
+ const handleSubmit = (values) => {
|
|
31
|
+ console.log('Get form value:', values);
|
|
32
|
+ setDbData(values)
|
|
33
|
+ setLoading(true)
|
|
34
|
+ request({
|
|
35
|
+ url: `${apiService}/mydb/connection`,
|
|
36
|
+ method: 'post',
|
|
37
|
+ data: values
|
|
38
|
+ }).then((response) => {
|
|
39
|
+ setLoading(false)
|
|
40
|
+ setDataSource(response)
|
|
41
|
+ Message.success('连接成功,请选择要生成的库')})
|
|
42
|
+ .catch((err) => {
|
|
43
|
+ console.error(err)
|
|
44
|
+ setLoading(false)
|
|
45
|
+ Message.error('连接出错,请检查配置')
|
|
46
|
+ });
|
|
47
|
+ };
|
38
|
48
|
|
39
|
|
- const createdCode = (values) => {
|
40
|
|
- console.log('Get form value22:', {...values,...dbData});
|
41
|
|
- request({
|
42
|
|
- url: '/mydb/create',
|
43
|
|
- method: 'post',
|
44
|
|
- responseType: 'arraybuffer',
|
45
|
|
- data: {...values,...dbData}
|
46
|
|
- }).then((response) => {
|
47
|
|
- var binaryData = [];
|
48
|
|
- binaryData.push(response);
|
49
|
|
- let blobUrl = window.URL.createObjectURL(new Blob(binaryData, {type: "application/zip"}))
|
50
|
|
- let aElement = document.createElement('a'); //获取a标签元素
|
51
|
|
- let filename = 'code.zip';//设置文件名称
|
52
|
|
- aElement.href = blobUrl;//设置a标签路径
|
53
|
|
- aElement.download = filename;
|
54
|
|
- aElement.click();
|
55
|
|
- window.URL.revokeObjectURL(blobUrl);
|
56
|
|
- })
|
57
|
|
- .catch((err) => {console.error(err) ; Message.error('生成失败请重试,或联系工作人员')});
|
58
|
|
- };
|
|
49
|
+ const createdCode = (values) => {
|
|
50
|
+ console.log('Get form value22:', {...values,...dbData});
|
|
51
|
+ setGenerating(true)
|
|
52
|
+ request({
|
|
53
|
+ url: `${apiService}/mydb/create`,
|
|
54
|
+ method: 'post',
|
|
55
|
+ responseType: 'arraybuffer',
|
|
56
|
+ data: {...values,...dbData}
|
|
57
|
+ }).then((response) => {
|
|
58
|
+ setGenerating(false)
|
|
59
|
+ const binaryData = [];
|
|
60
|
+ binaryData.push(response);
|
|
61
|
+ const blobUrl = window.URL.createObjectURL(new Blob(binaryData, {type: 'application/zip'}))
|
|
62
|
+ const aElement = document.createElement('a'); // 获取a标签元素
|
|
63
|
+ const filename = 'code.zip';// 设置文件名称
|
|
64
|
+ aElement.href = blobUrl;// 设置a标签路径
|
|
65
|
+ aElement.download = filename;
|
|
66
|
+ aElement.click();
|
|
67
|
+ window.URL.revokeObjectURL(blobUrl);
|
|
68
|
+ })
|
|
69
|
+ .catch((err) => {
|
|
70
|
+ console.error(err);
|
|
71
|
+ setGenerating(false)
|
|
72
|
+ Message.error('生成失败请重试,或联系工作人员')
|
|
73
|
+ });
|
|
74
|
+ };
|
59
|
75
|
|
60
|
|
- return (
|
61
|
|
- <div className={styles.container}>
|
|
76
|
+ return (
|
|
77
|
+ <div className={styles.container}>
|
62
|
78
|
<div>
|
63
|
79
|
<Form style={{width: '60%'}} {...formItemLayout} value={postData}>
|
64
|
|
- <FormItem label="数据库类型">
|
65
|
|
- <p>MSQL</p>
|
66
|
|
- </FormItem>
|
67
|
|
- <FormItem label="数据库地址" required requiredMessage="必填">
|
68
|
|
- <Input name="mysqlIp" placeholder="请输入数据库地址"/>
|
69
|
|
- </FormItem>
|
70
|
|
- <FormItem label="端口号" required requiredMessage="必填">
|
71
|
|
- <Input name="mysqlPort" placeholder="请输入数据库端口号"/>
|
72
|
|
- </FormItem>
|
73
|
|
- <FormItem label="数据库用户名" required requiredMessage="必填">
|
74
|
|
- <Input name="mysqlUsername" placeholder="请输入数据库用户名"/>
|
75
|
|
- </FormItem>
|
76
|
|
- <FormItem label="数据库密码" required requiredMessage="必填">
|
77
|
|
- <Input.Password name="mysqlUserpass" placeholder="请输入数据库密码"/>
|
78
|
|
- </FormItem>
|
79
|
|
- <FormItem label="数据库库名" required requiredMessage="必填">
|
80
|
|
- <Input name="mysqlName" placeholder="请输入数据库库名"/>
|
81
|
|
- </FormItem>
|
82
|
|
- <FormItem label=" ">
|
83
|
|
- <Form.Submit onClick={handleSubmit}>连接数据库</Form.Submit>
|
84
|
|
- </FormItem>
|
|
80
|
+ <FormItem label="数据库类型">
|
|
81
|
+ <p>MSQL</p>
|
|
82
|
+ </FormItem>
|
|
83
|
+ <FormItem label="数据库地址" required requiredMessage="必填">
|
|
84
|
+ <Input name="mysqlIp" placeholder="请输入数据库地址"/>
|
|
85
|
+ </FormItem>
|
|
86
|
+ <FormItem label="端口号" required requiredMessage="必填">
|
|
87
|
+ <Input name="mysqlPort" placeholder="请输入数据库端口号"/>
|
|
88
|
+ </FormItem>
|
|
89
|
+ <FormItem label="数据库用户名" required requiredMessage="必填">
|
|
90
|
+ <Input name="mysqlUsername" placeholder="请输入数据库用户名"/>
|
|
91
|
+ </FormItem>
|
|
92
|
+ <FormItem label="数据库密码" required requiredMessage="必填">
|
|
93
|
+ <Input.Password name="mysqlUserpass" placeholder="请输入数据库密码"/>
|
|
94
|
+ </FormItem>
|
|
95
|
+ <FormItem label="数据库库名" required requiredMessage="必填">
|
|
96
|
+ <Input name="mysqlName" placeholder="请输入数据库库名"/>
|
|
97
|
+ </FormItem>
|
|
98
|
+ <FormItem label=" ">
|
|
99
|
+ <Form.Submit onClick={handleSubmit} loading={loading}>连接数据库</Form.Submit>
|
|
100
|
+ </FormItem>
|
85
|
101
|
</Form>
|
86
|
102
|
</div>
|
87
|
103
|
<div>
|
88
|
|
- <Form style={{width: '60%'}} {...formItemLayout} value={tjData}>
|
89
|
|
- <FormItem label="包路径" help="如:com.huiju.estateagents">
|
90
|
|
- <Input name="packPath" placeholder="请输入包路径"/>
|
91
|
|
- </FormItem>
|
92
|
|
- <FormItem label="作者">
|
93
|
|
- <Input name="author" placeholder="请输入作者"/>
|
94
|
|
- </FormItem>
|
95
|
|
- <FormItem label="开启 Swagger2" style={{ textAlign: 'left' }}>
|
96
|
|
- <Switch name="swagger2" checkedChildren="on" unCheckedChildren="off" style={{ width: `60px` }} />
|
97
|
|
- </FormItem>
|
98
|
|
- <FormItem label="要生成代码的表" required requiredMessage="必填">
|
99
|
|
- <Select name="mysqlLib" mode="multiple" showSearch dataSource={dataSource} style={{width: 700}} />
|
100
|
|
- </FormItem>
|
101
|
|
- <FormItem label=" ">
|
102
|
|
- <a download><Form.Submit onClick={createdCode}>生成代码</Form.Submit></a>
|
103
|
|
- </FormItem>
|
|
104
|
+ <Form style={{width: '60%'}} {...formItemLayout} value={tjData}>
|
|
105
|
+ <FormItem label="包路径" help="如:com.huiju.estateagents">
|
|
106
|
+ <Input name="packPath" placeholder="请输入包路径"/>
|
|
107
|
+ </FormItem>
|
|
108
|
+ <FormItem label="作者">
|
|
109
|
+ <Input name="author" placeholder="请输入作者"/>
|
|
110
|
+ </FormItem>
|
|
111
|
+ <FormItem label="开启 Swagger2" style={{ textAlign: 'left' }}>
|
|
112
|
+ <Switch name="swagger2" checkedChildren="on" unCheckedChildren="off" style={{ width: '60px' }} />
|
|
113
|
+ </FormItem>
|
|
114
|
+ <FormItem label="要生成代码的表" required requiredMessage="必填">
|
|
115
|
+ <Select name="mysqlLib" mode="multiple" showSearch dataSource={dataSource} style={{width: 700}} />
|
|
116
|
+ </FormItem>
|
|
117
|
+ <FormItem label=" ">
|
|
118
|
+ <a download><Form.Submit onClick={createdCode} loading={generating}>生成代码</Form.Submit></a>
|
|
119
|
+ </FormItem>
|
104
|
120
|
</Form>
|
105
|
121
|
|
106
|
122
|
</div>
|
107
|
|
- </div>)
|
|
123
|
+ </div>)
|
108
|
124
|
}
|
109
|
125
|
|
110
|
126
|
export default Guide;
|