diff --git a/src/pages/system/index.tsx b/src/pages/system/index.tsx index 76fda8c..2a1e9b5 100644 --- a/src/pages/system/index.tsx +++ b/src/pages/system/index.tsx @@ -1,92 +1,123 @@ import React, { useState, useEffect } from "react"; -import { Button, Space, Col, Empty } from "antd"; -import type { ColumnsType } from "antd/es/table"; -import styles from "./index.module.less"; -import { PlusOutlined, ReloadOutlined } from "@ant-design/icons"; +import { Row, Col, Form, Input, Select, Button, message } from "antd"; +import styles from "./update.module.less"; import { appConfig } from "../../api/index"; -import { dateFormat } from "../../utils/index"; -import { Link, useNavigate } from "react-router-dom"; - -interface DataType { - id: React.Key; - name: string; - created_at: string; -} +import { useParams, useNavigate } from "react-router-dom"; +import { UploadImageButton } from "../../compenents"; export const SystemIndexPage: React.FC = () => { + const params = useParams(); const navigate = useNavigate(); - const [loading, setLoading] = useState(true); - const [list, setList] = useState([]); - const [refresh, setRefresh] = useState(false); - - const columns: ColumnsType = [ - { - title: "角色名", - dataIndex: "name", - render: (text: string) => {text}, - }, - { - title: "时间", - dataIndex: "created_at", - render: (text: string) => {text && dateFormat(text)}, - }, - { - title: "操作", - key: "action", - fixed: "right", - width: 160, - render: (_, record) => ( - - - - ), - }, - ]; + const [form] = Form.useForm(); + const [loading, setLoading] = useState(false); + const [logo, setLogo] = useState(""); useEffect(() => { - getData(); - }, [refresh]); + getDetail(); + }, []); - const getData = () => { - setLoading(true); + const getDetail = () => { appConfig.appConfig().then((res: any) => { - setList(res.data); - setLoading(false); + let configData = res.data; + for (let i = 0; i < configData.length; i++) { + if (configData[i].key_name === "system.name") { + form.setFieldsValue({ + "system.name": configData[i].key_value, + }); + } else if (configData[i].key_name === "system.logo") { + form.setFieldsValue({ + "system.logo": configData[i].key_value, + }); + } else if (configData[i].key_name === "system.api_url") { + form.setFieldsValue({ + "system.api_url": configData[i].key_value, + }); + } else if (configData[i].key_name === "system.pc_url") { + form.setFieldsValue({ + "system.pc_url": configData[i].key_value, + }); + } else if (configData[i].key_name === "system.h5_url") { + form.setFieldsValue({ + "system.h5_url": configData[i].key_value, + }); + } + } }); }; - const resetData = () => { - setList([]); - setRefresh(!refresh); + const onFinish = (values: any) => { + if (loading) { + return; + } + setLoading(true); + appConfig.saveAppConfig(values).then((res: any) => { + message.success("保存成功!"); + setLoading(false); + getDetail(); + }); + }; + + const onFinishFailed = (errorInfo: any) => { + console.log("Failed:", errorInfo); }; return ( <> -
-
基本配置
- {list.length === 0 && ( - - - - )} -
- {list.map((item: any, index: number) => { - return ( -
- - {item.name} -
- ); - })} -
-
+ + +
+
+ + + + +
+
+ { + setLogo(url); + form.setFieldsValue({ "system.logo": url }); + }} + > +
+ {logo && ( + + )} +
+
+ + + + + + + + + + + + +
+
+ +
); };