mirror of https://github.com/openspug/spug
A web update
parent
63e734f70b
commit
b3e64cb497
|
@ -11,6 +11,7 @@ export default [
|
||||||
{
|
{
|
||||||
icon: 'deployment-unit', title: '配置中心', child: [
|
icon: 'deployment-unit', title: '配置中心', child: [
|
||||||
{title: '环境管理', path: '/config/environment'},
|
{title: '环境管理', path: '/config/environment'},
|
||||||
|
{title: '服务管理', path: '/config/service'},
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{icon: 'monitor', title: '监控中心', path: '/monitor'},
|
{icon: 'monitor', title: '监控中心', path: '/monitor'},
|
||||||
|
|
|
@ -3,13 +3,11 @@ import http from 'libs/http';
|
||||||
|
|
||||||
class Store {
|
class Store {
|
||||||
@observable records = [];
|
@observable records = [];
|
||||||
@observable types = [];
|
|
||||||
@observable record = {};
|
@observable record = {};
|
||||||
@observable isFetching = false;
|
@observable isFetching = false;
|
||||||
@observable formVisible = false;
|
@observable formVisible = false;
|
||||||
|
|
||||||
@observable f_name;
|
@observable f_name;
|
||||||
@observable f_type;
|
|
||||||
|
|
||||||
fetchRecords = () => {
|
fetchRecords = () => {
|
||||||
this.isFetching = true;
|
this.isFetching = true;
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
import { makeRoute } from 'libs/router';
|
import { makeRoute } from 'libs/router';
|
||||||
import Environment from './environment';
|
import Environment from './environment';
|
||||||
|
import Service from './service';
|
||||||
|
|
||||||
|
|
||||||
export default [
|
export default [
|
||||||
makeRoute('/environment', Environment),
|
makeRoute('/environment', Environment),
|
||||||
|
makeRoute('/service', Service),
|
||||||
]
|
]
|
|
@ -0,0 +1,66 @@
|
||||||
|
import React from 'react';
|
||||||
|
import { observer } from 'mobx-react';
|
||||||
|
import { Modal, Form, Input, message } from 'antd';
|
||||||
|
import http from 'libs/http';
|
||||||
|
import store from './store';
|
||||||
|
|
||||||
|
@observer
|
||||||
|
class ComForm extends React.Component {
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.state = {
|
||||||
|
loading: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
handleSubmit = () => {
|
||||||
|
this.setState({loading: true});
|
||||||
|
const formData = this.props.form.getFieldsValue();
|
||||||
|
formData['id'] = store.record.id;
|
||||||
|
http.post('/api/config/service/', formData)
|
||||||
|
.then(res => {
|
||||||
|
message.success('操作成功');
|
||||||
|
store.formVisible = false;
|
||||||
|
store.fetchRecords()
|
||||||
|
}, () => this.setState({loading: false}))
|
||||||
|
};
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const info = store.record;
|
||||||
|
const {getFieldDecorator} = this.props.form;
|
||||||
|
const itemLayout = {
|
||||||
|
labelCol: {span: 6},
|
||||||
|
wrapperCol: {span: 14}
|
||||||
|
};
|
||||||
|
return (
|
||||||
|
<Modal
|
||||||
|
visible
|
||||||
|
width={800}
|
||||||
|
maskClosable={false}
|
||||||
|
title={store.record.id ? '编辑服务' : '新建服务'}
|
||||||
|
onCancel={() => store.formVisible = false}
|
||||||
|
confirmLoading={this.state.loading}
|
||||||
|
onOk={this.handleSubmit}>
|
||||||
|
<Form>
|
||||||
|
<Form.Item {...itemLayout} required label="服务名称">
|
||||||
|
{getFieldDecorator('name', {initialValue: info['name']})(
|
||||||
|
<Input placeholder="请输入服务名称,例如:订单处理服务"/>
|
||||||
|
)}
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item {...itemLayout} required label="唯一标识符">
|
||||||
|
{getFieldDecorator('key', {initialValue: info['key']})(
|
||||||
|
<Input placeholder="请输入唯一标识符,例如:api_order"/>
|
||||||
|
)}
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item {...itemLayout} label="备注信息">
|
||||||
|
{getFieldDecorator('desc', {initialValue: info['desc']})(
|
||||||
|
<Input.TextArea placeholder="请输入备注信息"/>
|
||||||
|
)}
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
</Modal>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Form.create()(ComForm)
|
|
@ -0,0 +1,69 @@
|
||||||
|
import React from 'react';
|
||||||
|
import { observer } from 'mobx-react';
|
||||||
|
import { Table, Divider, Modal, message } from 'antd';
|
||||||
|
import ComForm from './Form';
|
||||||
|
import http from 'libs/http';
|
||||||
|
import store from './store';
|
||||||
|
import { LinkButton } from "components";
|
||||||
|
|
||||||
|
@observer
|
||||||
|
class ComTable extends React.Component {
|
||||||
|
componentDidMount() {
|
||||||
|
store.fetchRecords()
|
||||||
|
}
|
||||||
|
|
||||||
|
columns = [{
|
||||||
|
title: '序号',
|
||||||
|
key: 'series',
|
||||||
|
render: (_, __, index) => index + 1,
|
||||||
|
width: 80,
|
||||||
|
}, {
|
||||||
|
title: '服务名称',
|
||||||
|
dataIndex: 'name',
|
||||||
|
}, {
|
||||||
|
title: '标识符',
|
||||||
|
dataIndex: 'key',
|
||||||
|
}, {
|
||||||
|
title: '描述信息',
|
||||||
|
dataIndex: 'desc',
|
||||||
|
ellipsis: true
|
||||||
|
}, {
|
||||||
|
title: '操作',
|
||||||
|
render: info => (
|
||||||
|
<span>
|
||||||
|
<LinkButton onClick={() => store.showForm(info)}>编辑</LinkButton>
|
||||||
|
<Divider type="vertical"/>
|
||||||
|
<LinkButton onClick={() => this.handleDelete(info)}>删除</LinkButton>
|
||||||
|
</span>
|
||||||
|
)
|
||||||
|
}];
|
||||||
|
|
||||||
|
handleDelete = (text) => {
|
||||||
|
Modal.confirm({
|
||||||
|
title: '删除确认',
|
||||||
|
content: `确定要删除【${text['name']}】?`,
|
||||||
|
onOk: () => {
|
||||||
|
return http.delete('/api/config/service/', {params: {id: text.id}})
|
||||||
|
.then(() => {
|
||||||
|
message.success('删除成功');
|
||||||
|
store.fetchRecords()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
|
render() {
|
||||||
|
let data = store.records;
|
||||||
|
if (store.f_name) {
|
||||||
|
data = data.filter(item => item['name'].toLowerCase().includes(store.f_name.toLowerCase()))
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<React.Fragment>
|
||||||
|
<Table rowKey="id" loading={store.isFetching} dataSource={data} columns={this.columns}/>
|
||||||
|
{store.formVisible && <ComForm/>}
|
||||||
|
</React.Fragment>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ComTable
|
|
@ -0,0 +1,25 @@
|
||||||
|
import React from 'react';
|
||||||
|
import { observer } from 'mobx-react';
|
||||||
|
import { Card, Input, Button } from 'antd';
|
||||||
|
import { SearchForm } from 'components';
|
||||||
|
import ComTable from './Table';
|
||||||
|
import store from './store';
|
||||||
|
|
||||||
|
export default observer(function () {
|
||||||
|
return (
|
||||||
|
<Card>
|
||||||
|
<SearchForm>
|
||||||
|
<SearchForm.Item span={8} title="服务名称">
|
||||||
|
<Input allowClear onChange={e => store.f_name = e.target.value} placeholder="请输入"/>
|
||||||
|
</SearchForm.Item>
|
||||||
|
<SearchForm.Item span={8}>
|
||||||
|
<Button type="primary" icon="sync" onClick={store.fetchRecords}>刷新</Button>
|
||||||
|
</SearchForm.Item>
|
||||||
|
</SearchForm>
|
||||||
|
<div style={{marginBottom: 16}}>
|
||||||
|
<Button type="primary" icon="plus" onClick={() => store.showForm()}>新建</Button>
|
||||||
|
</div>
|
||||||
|
<ComTable/>
|
||||||
|
</Card>
|
||||||
|
)
|
||||||
|
})
|
|
@ -0,0 +1,25 @@
|
||||||
|
import { observable } from "mobx";
|
||||||
|
import http from 'libs/http';
|
||||||
|
|
||||||
|
class Store {
|
||||||
|
@observable records = [];
|
||||||
|
@observable record = {};
|
||||||
|
@observable isFetching = false;
|
||||||
|
@observable formVisible = false;
|
||||||
|
|
||||||
|
@observable f_name;
|
||||||
|
|
||||||
|
fetchRecords = () => {
|
||||||
|
this.isFetching = true;
|
||||||
|
http.get('/api/config/service/')
|
||||||
|
.then(res => this.records = res)
|
||||||
|
.finally(() => this.isFetching = false)
|
||||||
|
};
|
||||||
|
|
||||||
|
showForm = (info = {}) => {
|
||||||
|
this.formVisible = true;
|
||||||
|
this.record = info
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default new Store()
|
Loading…
Reference in New Issue