mirror of
https://github.com/PlayEdu/backend
synced 2025-07-13 22:17:31 +08:00
系统配置初步
This commit is contained in:
parent
f34c57dc30
commit
6be6b6f70f
@ -1,92 +1,123 @@
|
|||||||
import React, { useState, useEffect } from "react";
|
import React, { useState, useEffect } from "react";
|
||||||
import { Button, Space, Col, Empty } from "antd";
|
import { Row, Col, Form, Input, Select, Button, message } from "antd";
|
||||||
import type { ColumnsType } from "antd/es/table";
|
import styles from "./update.module.less";
|
||||||
import styles from "./index.module.less";
|
|
||||||
import { PlusOutlined, ReloadOutlined } from "@ant-design/icons";
|
|
||||||
import { appConfig } from "../../api/index";
|
import { appConfig } from "../../api/index";
|
||||||
import { dateFormat } from "../../utils/index";
|
import { useParams, useNavigate } from "react-router-dom";
|
||||||
import { Link, useNavigate } from "react-router-dom";
|
import { UploadImageButton } from "../../compenents";
|
||||||
|
|
||||||
interface DataType {
|
|
||||||
id: React.Key;
|
|
||||||
name: string;
|
|
||||||
created_at: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const SystemIndexPage: React.FC = () => {
|
export const SystemIndexPage: React.FC = () => {
|
||||||
|
const params = useParams();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [loading, setLoading] = useState<boolean>(true);
|
const [form] = Form.useForm();
|
||||||
const [list, setList] = useState<any>([]);
|
const [loading, setLoading] = useState<boolean>(false);
|
||||||
const [refresh, setRefresh] = useState(false);
|
const [logo, setLogo] = useState<string>("");
|
||||||
|
|
||||||
const columns: ColumnsType<DataType> = [
|
|
||||||
{
|
|
||||||
title: "角色名",
|
|
||||||
dataIndex: "name",
|
|
||||||
render: (text: string) => <span>{text}</span>,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "时间",
|
|
||||||
dataIndex: "created_at",
|
|
||||||
render: (text: string) => <span>{text && dateFormat(text)}</span>,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "操作",
|
|
||||||
key: "action",
|
|
||||||
fixed: "right",
|
|
||||||
width: 160,
|
|
||||||
render: (_, record) => (
|
|
||||||
<Space size="small">
|
|
||||||
<Button
|
|
||||||
type="link"
|
|
||||||
danger
|
|
||||||
className="b-link c-red"
|
|
||||||
onClick={() => navigate(`/system/adminroles/update/${record.id}`)}
|
|
||||||
>
|
|
||||||
详情
|
|
||||||
</Button>
|
|
||||||
</Space>
|
|
||||||
),
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getData();
|
getDetail();
|
||||||
}, [refresh]);
|
}, []);
|
||||||
|
|
||||||
const getData = () => {
|
const getDetail = () => {
|
||||||
setLoading(true);
|
|
||||||
appConfig.appConfig().then((res: any) => {
|
appConfig.appConfig().then((res: any) => {
|
||||||
setList(res.data);
|
let configData = res.data;
|
||||||
setLoading(false);
|
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 = () => {
|
const onFinish = (values: any) => {
|
||||||
setList([]);
|
if (loading) {
|
||||||
setRefresh(!refresh);
|
return;
|
||||||
|
}
|
||||||
|
setLoading(true);
|
||||||
|
appConfig.saveAppConfig(values).then((res: any) => {
|
||||||
|
message.success("保存成功!");
|
||||||
|
setLoading(false);
|
||||||
|
getDetail();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const onFinishFailed = (errorInfo: any) => {
|
||||||
|
console.log("Failed:", errorInfo);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="playedu-main-body">
|
<Row className="playedu-main-body">
|
||||||
<div className={styles["title"]}>基本配置</div>
|
<Col>
|
||||||
{list.length === 0 && (
|
<div className="float-left">
|
||||||
<Col span={24}>
|
<Form
|
||||||
<Empty description="暂无配置" />
|
form={form}
|
||||||
</Col>
|
name="basic"
|
||||||
)}
|
labelCol={{ span: 8 }}
|
||||||
<div className={styles["body"]}>
|
wrapperCol={{ span: 16 }}
|
||||||
{list.map((item: any, index: number) => {
|
style={{ width: 600 }}
|
||||||
return (
|
initialValues={{ remember: true }}
|
||||||
<div key={index} className={styles["item"]}>
|
onFinish={onFinish}
|
||||||
<img src={item.images} />
|
onFinishFailed={onFinishFailed}
|
||||||
<span>{item.name}</span>
|
autoComplete="off"
|
||||||
</div>
|
>
|
||||||
);
|
<Form.Item label="网站名" name="system.name">
|
||||||
})}
|
<Input placeholder="请输入网站名" />
|
||||||
</div>
|
</Form.Item>
|
||||||
</div>
|
<Form.Item label="Logo" name="system.logo">
|
||||||
|
<div className="c-flex">
|
||||||
|
<div className="d-flex">
|
||||||
|
<UploadImageButton
|
||||||
|
onSelected={(url) => {
|
||||||
|
setLogo(url);
|
||||||
|
form.setFieldsValue({ "system.logo": url });
|
||||||
|
}}
|
||||||
|
></UploadImageButton>
|
||||||
|
</div>
|
||||||
|
{logo && (
|
||||||
|
<img
|
||||||
|
className="mt-10"
|
||||||
|
style={{ width: "100%", height: "auto" }}
|
||||||
|
src={logo}
|
||||||
|
alt=""
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item label="API访问地址" name="system.api_url">
|
||||||
|
<Input placeholder="请输入API访问地址" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item label="PC端口访问地址" name="system.pc_url">
|
||||||
|
<Input placeholder="请输入PC端口访问地址" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item label="H5端口访问地址" name="system.h5_url">
|
||||||
|
<Input placeholder="请输入H5端口访问地址" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item wrapperCol={{ offset: 8, span: 16 }}>
|
||||||
|
<Button type="primary" htmlType="submit" loading={loading}>
|
||||||
|
保存
|
||||||
|
</Button>
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
</div>
|
||||||
|
</Col>
|
||||||
|
</Row>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user