diff --git a/spug_web/src/pages/config/setting/DiffConfig.js b/spug_web/src/pages/config/setting/DiffConfig.js new file mode 100644 index 0000000..672040b --- /dev/null +++ b/spug_web/src/pages/config/setting/DiffConfig.js @@ -0,0 +1,92 @@ +import React from 'react'; +import { observer } from 'mobx-react'; +import { Modal, Table, Row, Col, Checkbox, Form, Button, Alert } from 'antd'; +import http from 'libs/http'; +import envStore from '../environment/store'; +import store from './store'; + +@observer +class Record extends React.Component { + constructor(props) { + super(props); + this.state = { + loading: false, + records: [], + envs: [], + page: 0, + hideSame: false + } + } + + handleEnvCheck = (env) => { + const index = this.state.envs.indexOf(env); + if (index !== -1) { + this.state.envs.splice(index, 1); + } else { + this.state.envs.push(env); + } + this.setState({envs: this.state.envs}) + }; + + handleNext = () => { + this.setState({page: this.state.page + 1, loading: true}); + const envs = this.state.envs.map(x => x.id); + http.post('/api/config/diff/', {type: store.type, o_id: store.id, envs}) + .then(res => this.setState({records: res})) + .finally(() => this.setState({loading: false})) + }; + + getColumns = () => { + const columns = [{title: 'Key', dataIndex: 'key'}]; + for (let env of this.state.envs) { + columns.push({title: `${env.name} (${env.key})`, dataIndex: env.id}) + } + return columns + }; + + render() { + let records = this.state.records; + const {loading, envs, page, hideSame} = this.state; + if (hideSame) { + records = records.filter(item => new Set(envs.map(x => item[x.id])).size !== 1) + } + return ( + store.diffVisible = false} + footer={null}> +
+ + + {envStore.records.map((item, index) => ( + this.handleEnvCheck(item)} + style={{cursor: 'pointer', borderTop: index ? '1px solid #e8e8e8' : ''}}> + x.id).includes(item.id)}/> + {item.key} + {item.name} + {item.desc} + + ))} + + + + +
+
+ + this.setState({hideSame: !hideSame})}>隐藏相同配置 + + + + ) + } +} + +export default Record \ No newline at end of file diff --git a/spug_web/src/pages/config/setting/Record.js b/spug_web/src/pages/config/setting/Record.js index ebea2d4..f338987 100644 --- a/spug_web/src/pages/config/setting/Record.js +++ b/spug_web/src/pages/config/setting/Record.js @@ -16,7 +16,7 @@ class Record extends React.Component { } componentDidMount() { - const formData = {type: store.type, id: store.id, env_id: store.env.id}; + const formData = {type: store.type, o_id: store.id, env_id: store.env.id}; http.post('/api/config/history/', formData) .then(res => this.setState({records: res})) .finally(() => this.setState({loading: false})) diff --git a/spug_web/src/pages/config/setting/index.js b/spug_web/src/pages/config/setting/index.js index 5da3a50..d03e9b1 100644 --- a/spug_web/src/pages/config/setting/index.js +++ b/spug_web/src/pages/config/setting/index.js @@ -1,9 +1,11 @@ import React from 'react'; import { observer } from 'mobx-react'; -import { Menu, Input, Button, Select, Icon } from 'antd'; +import { Menu, Input, Button, Select, PageHeader, Icon } from 'antd'; import envStore from '../environment/store'; import styles from './index.module.css'; +import history from 'libs/history'; import { SearchForm } from 'components'; +import DiffConfig from './DiffConfig'; import TableView from './TableView'; import TextView from './TextView'; import JSONView from './JSONView'; @@ -38,7 +40,7 @@ class Index extends React.Component { }; handleRefresh = () => { - store.fetchRecords().then(() => { + store.fetchRecords().then(() => { if (this.textView) this.textView.updateValue(); if (this.JSONView) this.JSONView.updateValue(); }) @@ -49,6 +51,11 @@ class Index extends React.Component { return (
+ history.goBack()} + extra={}/> @@ -83,11 +90,12 @@ class Index extends React.Component { - {view === '1' && } - {view === '2' && this.textView = ref} />} - {view === '3' && this.JSONView = ref} />} + {view === '1' && } + {view === '2' && this.textView = ref}/>} + {view === '3' && this.JSONView = ref}/>}
- {store.recordVisible && } + {store.recordVisible && } + {store.diffVisible && }
) } diff --git a/spug_web/src/pages/config/setting/index.module.css b/spug_web/src/pages/config/setting/index.module.css index 802ed8c..f929e6c 100644 --- a/spug_web/src/pages/config/setting/index.module.css +++ b/spug_web/src/pages/config/setting/index.module.css @@ -4,11 +4,11 @@ padding: 16px 0; } .left { - flex: 2; + width: 250px; border-right: 1px solid #e8e8e8; } .right { - flex: 9; + flex: 1; padding: 8px 40px; } diff --git a/spug_web/src/pages/config/setting/store.js b/spug_web/src/pages/config/setting/store.js index 6611766..2b46d73 100644 --- a/spug_web/src/pages/config/setting/store.js +++ b/spug_web/src/pages/config/setting/store.js @@ -10,6 +10,7 @@ class Store { @observable isFetching = false; @observable formVisible = false; @observable recordVisible = false; + @observable diffVisible = false; @observable f_name; @@ -28,6 +29,10 @@ class Store { showRecord = () => { this.recordVisible = true + }; + + showDiff = () => { + this.diffVisible = true } }