Compare commits

..

No commits in common. "4fed57c2375542eb3b5b8b72a46e9227d54efeaa" and "940ed930ae7b5ee58ba34bdad44cea024b5c6f2e" have entirely different histories.

7 changed files with 106 additions and 240 deletions

109
README.md
View File

@ -1,65 +1,70 @@
# EVA Form # Getting Started with Create React App
EVA 对外表单填报系统 用于精品活动/纳新报名页
可接受自定义参数生成表格 This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
API LIST ## Available Scripts
问题格式 In the project directory, you can run:
- methods:get ### `npm start`
- url:/api/forminfo/*{router}*
```json Runs the app in the development mode.\
{ Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
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.
- methods:post ### `npm test`
- url: /api/formsubmit/{router} 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.
- post格式 ### `npm run build`
```json Builds the app for production to the `build` folder.\
{ It correctly bundles React in production mode and optimizes the build for the best performance.
"title":value, //title是之前题目生成时传的title
"title":value, //value根据题目类型而定 可能是string number boolean
"title":value,
}
```
## TODO The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!
增加图片上传组件 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)

5
src/App.css 100644
View File

@ -0,0 +1,5 @@
.App {
text-align: center;
background-image: url(https://gw.alipayobjects.com/zos/rmsportal/TVYTbAXWheQpRcWDaDMu.svg);
background-size: 100%;
}

View File

@ -1,9 +1,11 @@
import "./App.css";
import React, { Component } from "react"; import React, { Component } from "react";
import axios from "axios"; import axios from "axios";
import config from "./config.json"; import config from "./config.json";
import { Result } from "antd"; import Inputsmall from "./Test";
import {Result } from "antd";
import EVAfooter from "./EVAfooter"; import EVAfooter from "./EVAfooter";
import EVAForm from "./EVAForm"; import From from "./From";
class App extends Component { class App extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
@ -12,18 +14,20 @@ class App extends Component {
devurl: config.devurl, devurl: config.devurl,
formname: "EVA", formname: "EVA",
error: false, error: false,
info: "", info:{}
}; };
} }
getforminfo() { componentDidMount() {
this.setState({ router: window.location.pathname });
axios axios
.get(`${this.state.devurl}/api/forminfo/${this.state.router}/`) .get(`${this.state.devurl}/api/forminfo/${this.state.router}/`)
.then((res) => { .then((res) => {
if (res.data.code === 200) { if (res.data.code === 200) {
this.setState({ formname: res.data.data.formname }); this.setState({ formname: res.data.data.formname });
this.setState({ info: res.data.data.info }); this.setState({info:res.data.data.info})
// console.log(this.state.info); console.log(this.state.info);
document.title = this.state.formname; document.title = this.state.formname;
this.render();
} else { } else {
throw "network error when getting forminfo"; throw "network error when getting forminfo";
} }
@ -33,10 +37,6 @@ class App extends Component {
this.setState({ error: true }); this.setState({ error: true });
}); });
} }
componentDidMount() {
this.setState({ router: window.location.pathname });
this.getforminfo();
}
render() { render() {
return ( return (
<> <>
@ -49,15 +49,14 @@ class App extends Component {
/> />
) : ( ) : (
<> <>
<center> <div className="App">
<div className="App"> <h1>My React App!</h1>
<h1>My React App!</h1> <p>Welcome :)</p>
<p>Welcome :)</p> <p>{this.state.router}</p>
<p>{this.state.router}</p> <Inputsmall />
</div> <From info = {this.state.info}/>
</center> </div>
<EVAForm key={this.state.info} info={this.state.info} /> <EVAfooter/>
<EVAfooter />
</> </>
)} )}
</> </>

View File

@ -1,150 +0,0 @@
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 100644
View File

@ -0,0 +1,19 @@
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;

View File

@ -1,29 +1,22 @@
import { Radio } from "antd"; import { Input} from "antd";
import React, { Component } from "react"; import React, { Component } from "react";
class Radiomiddle extends Component { class Inputsmall extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { this.state = {
describe: "你的名字是?", describe: "#",
choice: ["option1", "option2", "option3"], placeholder: "请输入你的名字",
value: 0,
}; };
} }
render() { render() {
return ( return (
<div> <div>
<span style={{ marginRight: "1%" }}>{this.state.describe}</span> <span style={{ marginRight: "1%" }}>你的名字是?</span>
<span> <span>
<Radio.Group > <Input style={{ width: "20%" }} />
{
this.state.choice.map((item, index) => {
return <Radio value={index}>{item}</Radio>
})
}
</Radio.Group>
</span> </span>
</div> </div>
); );
} }
} }
export default Radiomiddle; export default Inputsmall;

View File

@ -11,8 +11,3 @@ code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace; monospace;
} }
#root{
background-image: url(https://gw.alipayobjects.com/zos/rmsportal/TVYTbAXWheQpRcWDaDMu.svg);
background-size: 100%;
}