傅行帆 5 years ago
parent
commit
67d4ac40cf

+ 7
- 1
generator_ice/build.json View File

@@ -14,5 +14,11 @@
14 14
         ]
15 15
       }
16 16
     ]
17
-  ]
17
+  ],
18
+  "proxy": {
19
+    "/**": {
20
+      "enable": true,
21
+      "target": "http://127.0.0.1:8080"
22
+    }
23
+  }
18 24
 }

+ 1
- 1
generator_ice/src/layouts/BasicLayout/menuConfig.js View File

@@ -1,7 +1,7 @@
1 1
 const headerMenuConfig = [];
2 2
 const asideMenuConfig = [
3 3
   {
4
-    name: 'Dashboard',
4
+    name: '代码生成',
5 5
     path: '/',
6 6
     icon: 'smile',
7 7
   },

+ 93
- 27
generator_ice/src/pages/Dashboard/components/Guide/index.jsx View File

@@ -1,33 +1,99 @@
1
-import * as React from 'react';
2
-import { Button } from '@alifd/next';
1
+import React, { useState, useEffect, useRef } from 'react';
2
+import { Button,Form,Input,Message,Select } from '@alifd/next';
3 3
 import styles from './index.module.scss';
4
+import { request } from 'ice';
4 5
 
5
-const Guide = () => (
6
-  <div className={styles.container}>
7
-    <h2 className={styles.title}>Welcome to icejs!</h2>
6
+const postData = {mysqlIp:'123.57.65.31',mysqlPort:'3306',mysqlUsername:'root',mysqlUserpass:'LUfZGvh7j1^qA*2c',mysqlName:'estateagents_test'}
7
+const FormItem = Form.Item;
8
+
9
+const formItemLayout = {
10
+    labelCol: {xxs: 4, l: 4},
11
+    wrapperCol: {xxs: 20, l: 16}
12
+};
8 13
 
9
-    <p className={styles.description}>This is a awesome project, enjoy it!</p>
14
+const Guide = props => {
15
+    const [dataSource, setDataSource] = useState([])
16
+    const [dbData, setDbData] = useState({})
10 17
 
11
-    <div className={styles.action}>
12
-      <a
13
-        href="https://ice.work/docs/guide/about"
14
-        target="_blank"
15
-        rel="noopener noreferrer"
16
-        style={{
17
-          marginRight: 20,
18
-        }}
19
-      >
20
-        <Button type="primary" size="large">
21
-          使用文档
22
-        </Button>
23
-      </a>
24
-      <a href="https://github.com/ice-lab/icejs" target="_blank" rel="noopener noreferrer">
25
-        <Button type="secondary" size="large">
26
-          GitHub
27
-        </Button>
28
-      </a>
29
-    </div>
30
-  </div>
31
-);
18
+    const handleSubmit = (values) => {
19
+        console.log('Get form value:', values);
20
+        setDbData(values)
21
+        request({
22
+          url: '/api/connection',
23
+          method: 'post',
24
+          data: values
25
+        }).then((response) => {
26
+            setDataSource(response)
27
+            Message.success('连接成功,请选择要生成的库')})
28
+        .catch((err) => {Message.error('连接出错,请检查配置')});
29
+    };
30
+      
31
+    const createdCode = (values) => {
32
+        console.log('Get form value22:', {...values,...dbData});
33
+        request({
34
+            url: '/api/create',
35
+            method: 'post',
36
+            responseType: 'arraybuffer',
37
+            data: {...values,...dbData}
38
+          }).then((response) => {
39
+              var binaryData = [];
40
+              binaryData.push(response);
41
+              let blobUrl = window.URL.createObjectURL(new Blob(binaryData, {type: "application/zip"}))
42
+              let aElement = document.createElement('a'); //获取a标签元素
43
+              let filename = 'code.zip';//设置文件名称
44
+              aElement.href = blobUrl;//设置a标签路径
45
+              aElement.download = filename;
46
+              aElement.click();
47
+              window.URL.revokeObjectURL(blobUrl);
48
+          })
49
+          .catch((err) => {console.error(err) ; Message.error('生成失败请重试,或联系工作人员')});
50
+    };
51
+
52
+    return (
53
+  <div className={styles.container}>
54
+      <div>
55
+        <Form style={{width: '60%'}} {...formItemLayout} value={postData}>
56
+            <FormItem label="数据库类型">
57
+                <p>MSQL</p>
58
+            </FormItem>
59
+            <FormItem label="数据库地址" required requiredMessage="必填">
60
+                <Input name="mysqlIp" placeholder="请输入数据库地址"/>
61
+            </FormItem>
62
+            <FormItem label="端口号" required requiredMessage="必填">
63
+                <Input name="mysqlPort" placeholder="请输入数据库端口号"/>
64
+            </FormItem>
65
+            <FormItem label="数据库用户名" required requiredMessage="必填">
66
+                <Input name="mysqlUsername" placeholder="请输入数据库用户名"/>
67
+            </FormItem>
68
+            <FormItem label="数据库密码" required requiredMessage="必填">
69
+                <Input name="mysqlUserpass" placeholder="请输入数据库密码"/>
70
+            </FormItem>
71
+            <FormItem label="数据库库名" required requiredMessage="必填">
72
+                <Input name="mysqlName" placeholder="请输入数据库库名"/>
73
+            </FormItem>
74
+            <FormItem label=" ">
75
+                <Form.Submit onClick={handleSubmit}>连接数据库</Form.Submit>
76
+            </FormItem>
77
+        </Form>
78
+      </div>
79
+      <div>
80
+      <Form style={{width: '60%'}} {...formItemLayout}>
81
+            <FormItem label="包路径" help="如:com.huiju.estateagents">
82
+                <Input name="packPath" placeholder="请输入包路径"/>
83
+            </FormItem>
84
+            <FormItem label="作者">
85
+                <Input name="author" placeholder="请输入作者"/>
86
+            </FormItem>
87
+            <FormItem label="要生成代码的库" required requiredMessage="必填">
88
+                <Select name="mysqlLib" mode="multiple" showSearch dataSource={dataSource} style={{width: 700}} />
89
+            </FormItem>
90
+            <FormItem label=" ">
91
+                <a download><Form.Submit onClick={createdCode}>生成代码</Form.Submit></a>
92
+            </FormItem>
93
+        </Form>
94
+       
95
+      </div>
96
+  </div>)
97
+}
32 98
 
33 99
 export default Guide;

+ 15
- 0
generator_ice/src/pages/Generator/index.jsx View File

@@ -0,0 +1,15 @@
1
+import React from './node_modules/react';
2
+import { ResponsiveGrid } from './node_modules/@alifd/next';
3
+import Guide from './components/Guide';
4
+
5
+const { Cell } = ResponsiveGrid;
6
+
7
+const Generator = () => (
8
+  <ResponsiveGrid gap={20}>
9
+    <Cell colSpan={12}>
10
+       <p>111111</p>
11
+    </Cell>
12
+  </ResponsiveGrid>
13
+);
14
+
15
+export default Generator;