Compare commits
2 Commits
940ed930ae
...
4fed57c237
| Author | SHA1 | Date |
|---|---|---|
|
|
4fed57c237 | |
|
|
e3d72167f7 |
107
README.md
107
README.md
|
|
@ -1,70 +1,65 @@
|
|||
# Getting Started with Create React App
|
||||
# EVA Form
|
||||
EVA 对外表单填报系统 用于精品活动/纳新报名页
|
||||
|
||||
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
|
||||
可接受自定义参数生成表格
|
||||
|
||||
## Available Scripts
|
||||
API LIST
|
||||
|
||||
In the project directory, you can run:
|
||||
问题格式
|
||||
|
||||
### `npm start`
|
||||
- methods:get
|
||||
- url:/api/forminfo/*{router}*
|
||||
|
||||
Runs the app in the development mode.\
|
||||
Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
|
||||
```json
|
||||
{
|
||||
code:200,
|
||||
data:{
|
||||
formname:"EVA",
|
||||
question:[
|
||||
{
|
||||
type: "input", //输入框
|
||||
title: "blank1",// label
|
||||
placeholder: "placeholder1",//文本框提示语
|
||||
message: "please input the blank",//未填写提交 报错提示语
|
||||
style: { width: "200px" },
|
||||
},
|
||||
{
|
||||
type: "radio",//选择题
|
||||
title: "radio1",//label
|
||||
options: ["option1", "option2", "option3"],//选项
|
||||
message: "please select one option",
|
||||
},
|
||||
{
|
||||
type: "textarea",//长文本输入框
|
||||
title: "textarea1",
|
||||
placeholder: "text area placeholder1",//文本框提示语
|
||||
message: "please input the text area",
|
||||
style: { width: "400px" },
|
||||
rows: 4,//行数
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The page will reload when you make changes.\
|
||||
You may also see any lint errors in the console.
|
||||
答案提交
|
||||
|
||||
### `npm test`
|
||||
- methods:post
|
||||
|
||||
Launches the test runner in the interactive watch mode.\
|
||||
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
|
||||
- url: /api/formsubmit/{router}
|
||||
|
||||
### `npm run build`
|
||||
- post格式
|
||||
|
||||
Builds the app for production to the `build` folder.\
|
||||
It correctly bundles React in production mode and optimizes the build for the best performance.
|
||||
```json
|
||||
{
|
||||
"title":value, //title是之前题目生成时传的title
|
||||
"title":value, //value根据题目类型而定 可能是string number boolean
|
||||
"title":value,
|
||||
}
|
||||
```
|
||||
|
||||
The build is minified and the filenames include the hashes.\
|
||||
Your app is ready to be deployed!
|
||||
## TODO
|
||||
|
||||
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
|
||||
增加图片上传组件
|
||||
|
||||
### `npm run eject`
|
||||
|
||||
**Note: this is a one-way operation. Once you `eject`, you can't go back!**
|
||||
|
||||
If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
|
||||
|
||||
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.
|
||||
|
||||
You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.
|
||||
|
||||
## Learn More
|
||||
|
||||
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
|
||||
|
||||
To learn React, check out the [React documentation](https://reactjs.org/).
|
||||
|
||||
### Code Splitting
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
|
||||
|
||||
### Analyzing the Bundle Size
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
|
||||
|
||||
### Making a Progressive Web App
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
|
||||
|
||||
### Advanced Configuration
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
|
||||
|
||||
### Deployment
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
|
||||
|
||||
### `npm run build` fails to minify
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
|
||||
|
|
|
|||
|
|
@ -1,5 +0,0 @@
|
|||
.App {
|
||||
text-align: center;
|
||||
background-image: url(https://gw.alipayobjects.com/zos/rmsportal/TVYTbAXWheQpRcWDaDMu.svg);
|
||||
background-size: 100%;
|
||||
}
|
||||
27
src/App.js
27
src/App.js
|
|
@ -1,11 +1,9 @@
|
|||
import "./App.css";
|
||||
import React, { Component } from "react";
|
||||
import axios from "axios";
|
||||
import config from "./config.json";
|
||||
import Inputsmall from "./Test";
|
||||
import {Result } from "antd";
|
||||
import { Result } from "antd";
|
||||
import EVAfooter from "./EVAfooter";
|
||||
import From from "./From";
|
||||
import EVAForm from "./EVAForm";
|
||||
class App extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
|
@ -14,20 +12,18 @@ class App extends Component {
|
|||
devurl: config.devurl,
|
||||
formname: "EVA",
|
||||
error: false,
|
||||
info:{}
|
||||
info: "",
|
||||
};
|
||||
}
|
||||
componentDidMount() {
|
||||
this.setState({ router: window.location.pathname });
|
||||
getforminfo() {
|
||||
axios
|
||||
.get(`${this.state.devurl}/api/forminfo/${this.state.router}/`)
|
||||
.then((res) => {
|
||||
if (res.data.code === 200) {
|
||||
this.setState({ formname: res.data.data.formname });
|
||||
this.setState({info:res.data.data.info})
|
||||
console.log(this.state.info);
|
||||
this.setState({ info: res.data.data.info });
|
||||
// console.log(this.state.info);
|
||||
document.title = this.state.formname;
|
||||
this.render();
|
||||
} else {
|
||||
throw "network error when getting forminfo";
|
||||
}
|
||||
|
|
@ -37,6 +33,10 @@ class App extends Component {
|
|||
this.setState({ error: true });
|
||||
});
|
||||
}
|
||||
componentDidMount() {
|
||||
this.setState({ router: window.location.pathname });
|
||||
this.getforminfo();
|
||||
}
|
||||
render() {
|
||||
return (
|
||||
<>
|
||||
|
|
@ -49,14 +49,15 @@ class App extends Component {
|
|||
/>
|
||||
) : (
|
||||
<>
|
||||
<center>
|
||||
<div className="App">
|
||||
<h1>My React App!</h1>
|
||||
<p>Welcome :)</p>
|
||||
<p>{this.state.router}</p>
|
||||
<Inputsmall />
|
||||
<From info = {this.state.info}/>
|
||||
</div>
|
||||
<EVAfooter/>
|
||||
</center>
|
||||
<EVAForm key={this.state.info} info={this.state.info} />
|
||||
<EVAfooter />
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,150 @@
|
|||
import React, { useState } from "react";
|
||||
import { Form, Input, Radio, Button } from "antd";
|
||||
import axios from "axios";
|
||||
import config from "./config.json";
|
||||
const { TextArea } = Input;
|
||||
function EVAForm(props) {
|
||||
const [info] = useState(props.info);
|
||||
const [form] = Form.useForm();
|
||||
let router = window.location.pathname;
|
||||
const onFinish = (values) => {
|
||||
console.log("Success:", values);
|
||||
axios.post(`${config.devurl}/api/formsubmit/${router}`, values).then((res) => {
|
||||
if (res.data.code === 200) {
|
||||
console.log("success");
|
||||
} else {
|
||||
throw "network error when submitting form";
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
})
|
||||
};
|
||||
const onFinishFailed = (errorInfo) => {
|
||||
console.log("Failed:", errorInfo);
|
||||
};
|
||||
const onSaveStorage = () => {
|
||||
console.log(form.getFieldValue());
|
||||
//save value to localstorage
|
||||
localStorage.setItem("form", JSON.stringify(form.getFieldValue()));
|
||||
};
|
||||
const onLoadStorage = () => {
|
||||
//load value from localstorage
|
||||
form.setFieldsValue(JSON.parse(localStorage.getItem("form")));
|
||||
}
|
||||
|
||||
|
||||
return (
|
||||
<Form
|
||||
name="basic"
|
||||
labelCol={{
|
||||
span: 8,
|
||||
}}
|
||||
wrapperCol={{
|
||||
span: 16,
|
||||
}}
|
||||
initialValues={{
|
||||
remember: true,
|
||||
}}
|
||||
form={form}
|
||||
onFinish={onFinish}
|
||||
onFinishFailed={onFinishFailed}
|
||||
autoComplete="off"
|
||||
>
|
||||
{/* {generateForm()} */}
|
||||
{info.question !== undefined
|
||||
? info.question.map((item, index) => {
|
||||
return (
|
||||
<div>
|
||||
<Form.Item
|
||||
key={item.title}
|
||||
label={item.title}
|
||||
>
|
||||
{item.type === "radio" && (
|
||||
<Form.Item
|
||||
name={item.title}
|
||||
key={item.title}
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
message: item.message,
|
||||
},
|
||||
]}
|
||||
noStyle
|
||||
>
|
||||
<Radio.Group>
|
||||
{item.options.map((item, index) => {
|
||||
return (
|
||||
<Radio.Button key={index} value={index}>
|
||||
{item}
|
||||
</Radio.Button>
|
||||
);
|
||||
})}
|
||||
</Radio.Group>
|
||||
</Form.Item>
|
||||
)}
|
||||
{item.type === "input" && (
|
||||
<Form.Item
|
||||
name={item.title}
|
||||
key={item.title}
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
message: item.message,
|
||||
},
|
||||
]}
|
||||
noStyle
|
||||
>
|
||||
<Input
|
||||
key={item.title}
|
||||
placeholder={item.placeholder}
|
||||
style={item.style}
|
||||
/>
|
||||
</Form.Item>
|
||||
)}
|
||||
{item.type === "textarea" && (
|
||||
<Form.Item
|
||||
name={item.title}
|
||||
key={item.title}
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
message: item.message,
|
||||
},
|
||||
]}
|
||||
noStyle
|
||||
>
|
||||
<TextArea
|
||||
placeholder={item.placeholder}
|
||||
style={item.style}
|
||||
rows={item.rows}
|
||||
/>
|
||||
</Form.Item>
|
||||
)}
|
||||
</Form.Item>
|
||||
</div>
|
||||
);
|
||||
})
|
||||
: null}
|
||||
<Form.Item
|
||||
key="submit"
|
||||
wrapperCol={{
|
||||
offset: 8,
|
||||
span: 16,
|
||||
}}
|
||||
>
|
||||
<Button type="primary" htmlType="submit" style={{"margin":"0 8px 0 0"}}>
|
||||
Submit
|
||||
</Button>
|
||||
<Button htmlType="button" onClick={onSaveStorage} style={{"margin":"0 8px 0 0"}}>
|
||||
save
|
||||
</Button>
|
||||
<Button htmlType="button" onClick={onLoadStorage} style={{"margin":"0 8px 0 0"}}>
|
||||
load
|
||||
</Button>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
);
|
||||
}
|
||||
|
||||
export default EVAForm;
|
||||
19
src/From.js
19
src/From.js
|
|
@ -1,19 +0,0 @@
|
|||
import React from "react";
|
||||
class From extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
info: {}
|
||||
}
|
||||
}
|
||||
componentDidMount() {
|
||||
console.log(this.props.info);
|
||||
this.setState({ info: this.props.info })
|
||||
}
|
||||
render() {
|
||||
return (
|
||||
<></>
|
||||
);
|
||||
}
|
||||
}
|
||||
export default From;
|
||||
21
src/Test.js
21
src/Test.js
|
|
@ -1,22 +1,29 @@
|
|||
import { Input} from "antd";
|
||||
import { Radio } from "antd";
|
||||
import React, { Component } from "react";
|
||||
class Inputsmall extends Component {
|
||||
class Radiomiddle extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
describe: "#",
|
||||
placeholder: "请输入你的名字",
|
||||
describe: "你的名字是?",
|
||||
choice: ["option1", "option2", "option3"],
|
||||
value: 0,
|
||||
};
|
||||
}
|
||||
render() {
|
||||
return (
|
||||
<div>
|
||||
<span style={{ marginRight: "1%" }}>你的名字是?</span>
|
||||
<span style={{ marginRight: "1%" }}>{this.state.describe}</span>
|
||||
<span>
|
||||
<Input style={{ width: "20%" }} />
|
||||
<Radio.Group >
|
||||
{
|
||||
this.state.choice.map((item, index) => {
|
||||
return <Radio value={index}>{item}</Radio>
|
||||
})
|
||||
}
|
||||
</Radio.Group>
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
export default Inputsmall;
|
||||
export default Radiomiddle;
|
||||
|
|
|
|||
|
|
@ -11,3 +11,8 @@ code {
|
|||
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
|
||||
monospace;
|
||||
}
|
||||
|
||||
#root{
|
||||
background-image: url(https://gw.alipayobjects.com/zos/rmsportal/TVYTbAXWheQpRcWDaDMu.svg);
|
||||
background-size: 100%;
|
||||
}
|
||||
Loading…
Reference in New Issue