diff --git a/spug_web/src/pages/system/setting/About.js b/spug_web/src/pages/system/setting/About.js index d4d370c..09cc92b 100644 --- a/spug_web/src/pages/system/setting/About.js +++ b/spug_web/src/pages/system/setting/About.js @@ -5,7 +5,8 @@ */ import React from 'react'; import styles from './index.module.css'; -import { Descriptions, Spin, Icon, notification } from "antd"; +import { SmileTwoTone } from '@ant-design/icons'; +import { Descriptions, Spin, notification } from "antd"; import { observer } from 'mobx-react' import { http, VERSION } from 'libs'; @@ -33,7 +34,7 @@ class About extends React.Component { duration: 0, top: 88, message: `发现新版本 ${res.tag_name}`, - icon: , + icon: , btn: 如何升级?, description:
{logs}
}) diff --git a/spug_web/src/pages/system/setting/AlarmSetting.js b/spug_web/src/pages/system/setting/AlarmSetting.js index 118798d..71ffc63 100644 --- a/spug_web/src/pages/system/setting/AlarmSetting.js +++ b/spug_web/src/pages/system/setting/AlarmSetting.js @@ -3,39 +3,32 @@ * Copyright (c) * Released under the AGPL-3.0 License. */ -import React from 'react'; -import {observer} from 'mobx-react'; -import {Button, Form, Input, Radio, message, Popover} from 'antd'; +import React, { useState } from 'react'; +import { observer } from 'mobx-react'; +import { Button, Form, Input, Radio, Space, message, Popover } from 'antd'; import styles from './index.module.css'; -import {http} from 'libs'; +import { http } from 'libs'; import store from './store'; import lds from 'lodash'; -@observer -class AlarmSetting extends React.Component { - constructor(props) { - super(props); - this.setting = JSON.parse(lds.get(store.settings, 'mail_service.value', "{}")); - this.state = { - mode: this.setting['server'] === undefined ? '1' : '2', - spug_key: lds.get(store.settings, 'spug_key.value', ""), - mail_test_loading: false, - } +export default observer(function () { + const [form] = Form.useForm(); + const setting = JSON.parse(lds.get(store.settings, 'mail_service.value', '{}')); + const [mode, setMode] = useState(setting.server === undefined ? '1' : '2'); + const [spug_key, setSpugKey] = useState(lds.get(store.settings, 'spug_key.value', '')); + const [loading, setLoading] = useState(false); + + function handleEmailTest() { + setLoading(true); + const formData = form.getFieldsValue(); + http.post('/api/setting/email_test/', formData) + .then(() => { + message.success('邮件服务连接成功') + }).finally(() => setLoading(false)) } - handleEmailTest = () => { - this.props.form.validateFields((error, data) => { - if (!error) { - this.setState({mail_test_loading: true}); - http.post('/api/setting/email_test/', data).then(()=> { - message.success('邮件服务连接成功') - }).finally(()=> this.setState({mail_test_loading: false})) - } - }) - }; - - _doSubmit = (formData) => { + function _doSubmit(formData) { store.loading = true; http.post('/api/setting/', {data: formData}) .then(() => { @@ -43,114 +36,74 @@ class AlarmSetting extends React.Component { store.fetchSettings() }) .finally(() => store.loading = false) - }; + } - handleSubmit = () => { - const {mode, spug_key} = this.state; + function handleSubmit() { const formData = [{key: 'spug_key', value: spug_key}]; if (mode === '1') { formData.push({key: 'mail_service', value: '{}'}); - this._doSubmit(formData) + _doSubmit(formData) } else { - this.props.form.validateFields((err, data) => { - if (!err) { - formData.push({key: 'mail_service', value: JSON.stringify(data)}); - this._doSubmit(formData) - } - }) + const tmp = form.getFieldsValue(); + formData.push({key: 'mail_service', value: JSON.stringify(tmp)}); + _doSubmit(formData) } - }; + } - - render() { - const {getFieldDecorator} = this.props.form; - const {mode, spug_key} = this.state; - const spugWx = spug; - return ( - -
报警服务设置
-
- 如需要使用Spug内置的邮件和微信报警服务,请关注公众号 + const spugWx = spug; + return ( + +
报警服务设置
+
+ 如需要使用Spug内置的邮件和微信报警服务,请关注公众号 Spug运维 在【我的】页面获取调用凭据,否则请留空。}> - this.setState({spug_key: e.target.value})} - placeholder="请输入Spug微信公众号获取到的Token"/> - - - this.setState({mode: e.target.value})}> - 内置 - 自定义 - -
- - {getFieldDecorator('server', { - initialValue: this.setting['server'], rules: [ - {required: true, message: '请输入邮件服务器地址'} - ] - })( - - )} + setSpugKey(e.target.value)} + placeholder="请输入Spug微信公众号获取到的Token"/> + + + setMode(e.target.value)}> + 内置 + 自定义 + +
+ + + - - {getFieldDecorator('port', { - initialValue: this.setting['port'], rules: [ - {required: true, message: '请输入邮件服务端口'} - ] - })( - - )} + + - - {getFieldDecorator('username', { - initialValue: this.setting['username'], rules: [ - {required: true, message: '请输入邮箱账号'} - ] - })( - - )} + + - - {getFieldDecorator('password', { - initialValue: this.setting['password'], rules: [ - {required: true, message: '请输入邮箱账号对应的密码或授权码'} - ] - })( - - )} + + - - {getFieldDecorator('nickname', {initialValue: this.setting['nickname']})( - - )} + + -
-
-
- - +
- - - ) - } -} - -export default Form.create()(AlarmSetting) + + + {mode !== '1' && } + + +
+ + ) +}) \ No newline at end of file diff --git a/spug_web/src/pages/system/setting/BasicSetting.js b/spug_web/src/pages/system/setting/BasicSetting.js index cdef639..fba548e 100644 --- a/spug_web/src/pages/system/setting/BasicSetting.js +++ b/spug_web/src/pages/system/setting/BasicSetting.js @@ -5,7 +5,8 @@ */ import React from 'react'; import styles from './index.module.css'; -import { Form} from "antd"; +import { Form } from '@ant-design/compatible'; +import '@ant-design/compatible/assets/index.css'; import { observer } from 'mobx-react' diff --git a/spug_web/src/pages/system/setting/KeySetting.js b/spug_web/src/pages/system/setting/KeySetting.js index 717d34f..b02610c 100644 --- a/spug_web/src/pages/system/setting/KeySetting.js +++ b/spug_web/src/pages/system/setting/KeySetting.js @@ -5,7 +5,7 @@ */ import React from 'react'; import { observer } from 'mobx-react'; -import { Alert, Button, Form, Input, Modal, message } from 'antd'; +import { Form, Alert, Button, Input, Modal, message } from 'antd'; import styles from './index.module.css'; import http from 'libs/http'; import store from './store'; @@ -30,7 +30,12 @@ export default observer(function () { function doModify() { const public_key = lds.get(store.settings, 'public_key.value'); const private_key = lds.get(store.settings, 'private_key.value'); - return http.post('/api/setting/', {data: [{key: 'public_key', value: public_key}, {key: 'private_key', value: private_key}]}) + return http.post('/api/setting/', { + data: [{key: 'public_key', value: public_key}, { + key: 'private_key', + value: private_key + }] + }) .then(() => { message.success('保存成功'); store.fetchSettings() @@ -49,7 +54,7 @@ export default observer(function () { message="小提示" description="在这里你可以上传并使用已有的密钥对,没有上传密钥的情况下,Spug会在首次添加主机时自动生成密钥对。" /> -
+ lds.set(store.settings, 'public_key.value', e.target.value)} placeholder="请输入公钥"/> - + lds.set(store.settings, 'private_key.value', e.target.value)} placeholder="请输入私钥"/> - + diff --git a/spug_web/src/pages/system/setting/LDAPSetting.js b/spug_web/src/pages/system/setting/LDAPSetting.js index c712d2e..b4185fa 100644 --- a/spug_web/src/pages/system/setting/LDAPSetting.js +++ b/spug_web/src/pages/system/setting/LDAPSetting.js @@ -3,102 +3,66 @@ * Copyright (c) * Released under the AGPL-3.0 License. */ -import React from 'react'; +import React, { useState } from 'react'; import styles from './index.module.css'; -import {Button, Form, Input, message} from "antd"; +import { Form, Button, Input, Space, message } from 'antd'; import { http } from 'libs'; import { observer } from 'mobx-react' import store from './store'; import lds from "lodash"; -@observer -class LDAPSetting extends React.Component { - constructor(props) { - super(props); - this.setting = JSON.parse(lds.get(store.settings, 'ldap_service.value', "{}")); - this.state = { - loading: false, - ldap_test_loading: false, - } +export default observer(function () { + const [form] = Form.useForm(); + const [loading, setLoading] = useState(false); + const setting = JSON.parse(lds.get(store.settings, 'ldap_service.value', '{}')); + + function handleSubmit() { + store.loading = true; + const formData = form.getFieldsValue(); + http.post('/api/setting/', {data: [{key: 'ldap_service', value: JSON.stringify(formData)}]}) + .then(() => { + message.success('保存成功'); + store.fetchSettings() + }) + .finally(() => store.loading = false) } - handleSubmit = () => { - const formData = []; - this.props.form.validateFields((err, data) => { - if (!err) { - this.setState({loading: true}); - formData.push({key: 'ldap_service', value: JSON.stringify(data)}); - http.post('/api/setting/', {data: formData}) - .then(() => { - message.success('保存成功'); - store.fetchSettings() - }) - .finally(() => this.setState({loading: false})) - } - }) - }; - ldapTest = () => { - this.props.form.validateFields((error, data) => { - if (!error) { - this.setState({ldap_test_loading: true}); - http.post('/api/setting/ldap_test/', data).then(()=> { - message.success('LDAP服务连接成功') - }).finally(()=> this.setState({ldap_test_loading: false})) - } - }) - }; - - render() { - const {getFieldDecorator} = this.props.form; - return ( - -
LDAP设置
-
- - {getFieldDecorator('server', {initialValue: this.setting['server'], - rules: [{required: true, message: '请输入LDAP服务地址'}]})( - - )} - - - {getFieldDecorator('port', {initialValue: this.setting['port'], - rules: [{required: true, message: '请输入LDAP服务端口'}]})( - - )} - - - {getFieldDecorator('admin_dn', {initialValue: this.setting['admin_dn'], - rules: [{required: true, message: '请输入LDAP管理员DN'}]})( - - )} - - - {getFieldDecorator('password', {initialValue: this.setting['password'], - rules: [{required: true, message: '请输入LDAP管理员密码'}]})( - - )} - - - {getFieldDecorator('rules', {initialValue: this.setting['rules'], - rules: [{required: true, message: '请输入LDAP搜索规则'}]})( - - )} - - - {getFieldDecorator('base_dn', {initialValue: this.setting['base_dn'], - rules: [{required: true, message: '请输入LDAP基本DN'}]})( - - )} - - - - - -
-
- ) + function ldapTest() { + setLoading(true); + const formData = form.getFieldsValue(); + http.post('/api/setting/ldap_test/', formData).then(() => { + message.success('LDAP服务连接成功') + }).finally(() => setLoading(false)) } -} -export default Form.create()(LDAPSetting) + + return ( + +
LDAP设置
+
+ + + + + + + + + + + + + + + + + + + + + + +
+
+ ) +}) \ No newline at end of file diff --git a/spug_web/src/pages/system/setting/OpenService.js b/spug_web/src/pages/system/setting/OpenService.js index de54a61..687b539 100644 --- a/spug_web/src/pages/system/setting/OpenService.js +++ b/spug_web/src/pages/system/setting/OpenService.js @@ -5,7 +5,7 @@ */ import React from 'react'; import { observer } from 'mobx-react'; -import { Button, Form, Input, message } from 'antd'; +import { Form, Button, Input, message } from 'antd'; import styles from './index.module.css'; import http from 'libs/http'; import store from './store'; @@ -27,14 +27,14 @@ export default observer(function () { return (
开放服务设置
-
+ lds.set(store.settings, 'api_key.value', e.target.value)} placeholder="请输入自定义Token"/> - + diff --git a/spug_web/src/pages/system/setting/SecuritySetting.js b/spug_web/src/pages/system/setting/SecuritySetting.js index 1f5f5d2..671967e 100644 --- a/spug_web/src/pages/system/setting/SecuritySetting.js +++ b/spug_web/src/pages/system/setting/SecuritySetting.js @@ -27,17 +27,18 @@ export default observer(function () { return (
安全设置
-
+
+ checked={checked}/> - +
) }) diff --git a/spug_web/src/pages/system/setting/index.js b/spug_web/src/pages/system/setting/index.js index 73958d8..c67d249 100644 --- a/spug_web/src/pages/system/setting/index.js +++ b/spug_web/src/pages/system/setting/index.js @@ -5,7 +5,7 @@ */ import React from 'react'; import { Menu } from 'antd'; -import { AuthDiv } from 'components'; +import { AuthDiv, Breadcrumb } from 'components'; import BasicSetting from './BasicSetting'; import AlarmSetting from './AlarmSetting'; import LDAPSetting from './LDAPSetting'; @@ -32,30 +32,37 @@ class Index extends React.Component { render() { const {selectedKeys} = this.state; return ( - -
- this.setState({selectedKeys})}> - 基本设置 - 安全设置 - LDAP设置 - 密钥设置 - 报警服务设置 - 开放服务设置 - 关于 - -
-
- {selectedKeys[0] === 'basic' && } - {selectedKeys[0] === 'security' && } - {selectedKeys[0] === 'ldap' && } - {selectedKeys[0] === 'alarm' && } - {selectedKeys[0] === 'service' && } - {selectedKeys[0] === 'key' && } - {selectedKeys[0] === 'about' && } + + + 首页 + 系统管理 + 系统设置 + +
+
+ this.setState({selectedKeys})}> + 基本设置 + 安全设置 + LDAP设置 + 密钥设置 + 报警服务设置 + 开放服务设置 + 关于 + +
+
+ {selectedKeys[0] === 'basic' && } + {selectedKeys[0] === 'security' && } + {selectedKeys[0] === 'ldap' && } + {selectedKeys[0] === 'alarm' && } + {selectedKeys[0] === 'service' && } + {selectedKeys[0] === 'key' && } + {selectedKeys[0] === 'about' && } +
) diff --git a/spug_web/src/pages/system/setting/index.module.css b/spug_web/src/pages/system/setting/index.module.css index 0f0a127..1077a2d 100644 --- a/spug_web/src/pages/system/setting/index.module.css +++ b/spug_web/src/pages/system/setting/index.module.css @@ -3,17 +3,19 @@ background-color: #fff; padding: 16px 0; } + .left { flex: 2; border-right: 1px solid #e8e8e8; } + .right { flex: 7; padding: 8px 40px; } .title { - margin-bottom: 12px; + margin-bottom: 24px; color: rgba(0, 0, 0, .85); font-weight: 500; font-size: 20px;