diff --git a/src/App.css b/src/App.css deleted file mode 100644 index 03f42e5..0000000 --- a/src/App.css +++ /dev/null @@ -1,5 +0,0 @@ -.App { - text-align: center; - background-image: url(https://gw.alipayobjects.com/zos/rmsportal/TVYTbAXWheQpRcWDaDMu.svg); - background-size: 100%; -} diff --git a/src/App.js b/src/App.js index f7de1a5..2c0ccc4 100644 --- a/src/App.js +++ b/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 { /> ) : ( <> -
-

My React App!

-

Welcome :)

-

{this.state.router}

- - -
- +
+
+

My React App!

+

Welcome :)

+

{this.state.router}

+
+
+ + )} diff --git a/src/EVAForm.js b/src/EVAForm.js new file mode 100644 index 0000000..e194e5c --- /dev/null +++ b/src/EVAForm.js @@ -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 ( +
+ {/* {generateForm()} */} + {info.question !== undefined + ? info.question.map((item, index) => { + return ( +
+ + {item.type === "radio" && ( + + + {item.options.map((item, index) => { + return ( + + {item} + + ); + })} + + + )} + {item.type === "input" && ( + + + + )} + {item.type === "textarea" && ( + +