From 80657d4649aa44037a229b92abd9817607fc8df9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E4=BA=8C=E7=8C=9B?= Date: Sun, 8 Dec 2019 01:19:32 +0800 Subject: [PATCH] A web update --- spug_api/apps/config/models.py | 1 + spug_web/src/components/ACEditor.js | 4 -- spug_web/src/pages/config/setting/JSONView.js | 42 +++++++++++++++++++ .../config/setting/{Table.js => TableView.js} | 6 +-- spug_web/src/pages/config/setting/TextView.js | 32 ++++++++++++++ spug_web/src/pages/config/setting/index.js | 25 ++++++++--- 6 files changed, 97 insertions(+), 13 deletions(-) create mode 100644 spug_web/src/pages/config/setting/JSONView.js rename spug_web/src/pages/config/setting/{Table.js => TableView.js} (90%) create mode 100644 spug_web/src/pages/config/setting/TextView.js diff --git a/spug_api/apps/config/models.py b/spug_api/apps/config/models.py index 609b766..87d37fd 100644 --- a/spug_api/apps/config/models.py +++ b/spug_api/apps/config/models.py @@ -53,6 +53,7 @@ class Config(models.Model, ModelMixin): class Meta: db_table = 'configs' + ordering = ('-id',) class ConfigHistory(models.Model, ModelMixin): diff --git a/spug_web/src/components/ACEditor.js b/spug_web/src/components/ACEditor.js index ffd962b..78c209b 100644 --- a/spug_web/src/components/ACEditor.js +++ b/spug_web/src/components/ACEditor.js @@ -2,12 +2,8 @@ import React from "react"; import Editor from 'react-ace'; import 'ace-builds/src-noconflict/ext-language_tools'; import 'ace-builds/src-noconflict/mode-sh'; -import 'ace-builds/src-noconflict/mode-json'; -import 'ace-builds/src-noconflict/mode-text'; import 'ace-builds/src-noconflict/theme-tomorrow'; import 'ace-builds/src-noconflict/snippets/sh'; -import 'ace-builds/src-noconflict/snippets/json'; -import 'ace-builds/src-noconflict/snippets/text'; export default function (props) { return ( diff --git a/spug_web/src/pages/config/setting/JSONView.js b/spug_web/src/pages/config/setting/JSONView.js new file mode 100644 index 0000000..49dea8f --- /dev/null +++ b/spug_web/src/pages/config/setting/JSONView.js @@ -0,0 +1,42 @@ +import React from 'react'; +import { observer } from 'mobx-react'; +import Editor from 'react-ace'; +import 'ace-builds/src-noconflict/mode-json'; +import 'ace-builds/src-noconflict/theme-tomorrow'; +import store from './store'; + +@observer +class JSONView extends React.Component { + constructor(props) { + super(props); + this.state = { + body: '' + } + } + + componentDidMount() { + const body = {}; + for (let item of store.records) { + body[item.key] = item.value + } + this.setState({body: JSON.stringify(body, null, 2)}) + } + + render() { + return ( + this.setState({body: v})} + /> + ) + } +} + +export default JSONView \ No newline at end of file diff --git a/spug_web/src/pages/config/setting/Table.js b/spug_web/src/pages/config/setting/TableView.js similarity index 90% rename from spug_web/src/pages/config/setting/Table.js rename to spug_web/src/pages/config/setting/TableView.js index b0d3e16..2406147 100644 --- a/spug_web/src/pages/config/setting/Table.js +++ b/spug_web/src/pages/config/setting/TableView.js @@ -7,7 +7,7 @@ import http from 'libs/http'; import store from './store'; @observer -class ComTable extends React.Component { +class TableView extends React.Component { columns = [{ title: 'Key', key: 'key', @@ -57,11 +57,11 @@ class ComTable extends React.Component { } return ( - +
{store.formVisible && } ) } } -export default ComTable \ No newline at end of file +export default TableView \ No newline at end of file diff --git a/spug_web/src/pages/config/setting/TextView.js b/spug_web/src/pages/config/setting/TextView.js new file mode 100644 index 0000000..84a66a4 --- /dev/null +++ b/spug_web/src/pages/config/setting/TextView.js @@ -0,0 +1,32 @@ +import React from 'react'; +import { observer } from 'mobx-react'; +import Editor from 'react-ace'; +import 'ace-builds/src-noconflict/mode-space'; +import 'ace-builds/src-noconflict/theme-tomorrow'; +import store from './store'; + +@observer +class TextView extends React.Component { + constructor(props) { + super(props); + this.state = { + body: '' + } + } + + componentDidMount() { + let body = ''; + for (let item of store.records) { + body += `${item.key} = ${item.value}\n` + } + this.setState({body}) + } + + render() { + return ( + + ) + } +} + +export default TextView \ No newline at end of file diff --git a/spug_web/src/pages/config/setting/index.js b/spug_web/src/pages/config/setting/index.js index 49bbfef..71400a4 100644 --- a/spug_web/src/pages/config/setting/index.js +++ b/spug_web/src/pages/config/setting/index.js @@ -1,10 +1,12 @@ import React from 'react'; import { observer } from 'mobx-react'; -import { Menu, Input, Button } from 'antd'; +import { Menu, Input, Button, Select, Icon } from 'antd'; import envStore from '../environment/store'; import styles from './index.module.css'; import { SearchForm } from 'components'; -import ComTable from './Table'; +import TableView from './TableView'; +import TextView from './TextView'; +import JSONView from './JSONView'; import Record from './Record'; import store from './store'; @@ -13,7 +15,7 @@ class Index extends React.Component { constructor(props) { super(props); this.state = { - // envId: 0 + view: '1' } } @@ -34,6 +36,7 @@ class Index extends React.Component { }; render() { + const {view} = this.state; return (
@@ -49,7 +52,14 @@ class Index extends React.Component {
- + + + + store.f_name = e.target.value} placeholder="请输入"/> @@ -59,11 +69,14 @@ class Index extends React.Component { - + - + + {view === '1' && } + {view === '2' && } + {view === '3' && }
{store.recordVisible && }