diff --git a/spug_web/src/components/index.module.less b/spug_web/src/components/index.module.less index 22ea0ee..c5ca352 100644 --- a/spug_web/src/components/index.module.less +++ b/spug_web/src/components/index.module.less @@ -2,6 +2,7 @@ padding: 24px 24px 0 24px; background-color: #fff; border-radius: 2px; + margin-bottom: 16px; } .searchForm :global(.ant-form-item) { diff --git a/spug_web/src/pages/exec/template/Form.js b/spug_web/src/pages/exec/template/Form.js index 8e3849b..212fcf9 100644 --- a/spug_web/src/pages/exec/template/Form.js +++ b/spug_web/src/pages/exec/template/Form.js @@ -3,107 +3,90 @@ * Copyright (c) * Released under the AGPL-3.0 License. */ -import React from 'react'; +import React, { useState } from 'react'; import { observer } from 'mobx-react'; -import { Modal, Form, Input, Select, Col, Button, message } from 'antd'; +import { ExclamationCircleOutlined } from '@ant-design/icons'; +import { Modal, Form, Input, Select, Button, message } from 'antd'; import { ACEditor } from 'components'; import { http, cleanCommand } from 'libs'; import store from './store'; -@observer -class ComForm extends React.Component { - constructor(props) { - super(props); - this.state = { - loading: false, - type: null, - body: store.record['body'], - } - } +export default observer(function () { + const [form] = Form.useForm(); + const [loading, setLoading] = useState(false); + const [body, setBody] = useState(store.record.body); - handleSubmit = () => { - this.setState({loading: true}); - const formData = this.props.form.getFieldsValue(); + function handleSubmit() { + setLoading(true); + const formData = form.getFieldsValue(); formData['id'] = store.record.id; - formData['body'] = cleanCommand(this.state.body); + formData['body'] = cleanCommand(body); http.post('/api/exec/template/', formData) .then(res => { message.success('操作成功'); store.formVisible = false; store.fetchRecords() - }, () => this.setState({loading: false})) - }; + }, () => setLoading(false)) + } - handleAddZone = () => { + function handleAddZone() { + let type; Modal.confirm({ - icon: 'exclamation-circle', + icon: , title: '添加模板类型', - content: this.addZoneForm, + content: ( +
+ + type = e.target.value}/> + +
+ ), onOk: () => { - if (this.state.type) { - store.types.push(this.state.type); - this.props.form.setFieldsValue({'type': this.state.type}) + if (type) { + store.types.push(type); + form.setFieldsValue({type}) } }, }) - }; - - addZoneForm = ( -
- - this.setState({type: val.target.value})}/> - -
- ); - - render() { - const info = store.record; - const {getFieldDecorator} = this.props.form; - return ( - store.formVisible = false} - confirmLoading={this.state.loading} - onOk={this.handleSubmit}> -
- - - {getFieldDecorator('type', {initialValue: info['type']})( - - )} - - - - - - - {getFieldDecorator('name', {initialValue: info['name']})( - - )} - - - this.setState({body: val})} - height="300px"/> - - - {getFieldDecorator('desc', {initialValue: info['desc']})( - - )} - -
-
- ) } -} -export default Form.create()(ComForm) + const info = store.record; + return ( + store.formVisible = false} + confirmLoading={loading} + onOk={handleSubmit}> +
+ + + + + + + + + + + + + setBody(val)} + height="300px"/> + + + + +
+
+ ) +}) \ No newline at end of file diff --git a/spug_web/src/pages/exec/template/Table.js b/spug_web/src/pages/exec/template/Table.js index 964f0b0..c8a8cfe 100644 --- a/spug_web/src/pages/exec/template/Table.js +++ b/spug_web/src/pages/exec/template/Table.js @@ -6,9 +6,9 @@ import React from 'react'; import { observer } from 'mobx-react'; import { Table, Modal, message } from 'antd'; -import ComForm from './Form'; +import { PlusOutlined } from '@ant-design/icons'; import { http, hasPermission } from 'libs'; -import { Action } from "components"; +import { Action, TableCard, AuthButton } from "components"; import store from './store'; @observer @@ -40,33 +40,39 @@ class ComTable extends React.Component { data = data.filter(item => item['type'].toLowerCase().includes(store.f_type.toLowerCase())) } return ( - - `共 ${total} 条`, - pageSizeOptions: ['10', '20', '50', '100'] - }}> - - - - - {hasPermission('exec.template.edit|exec.template.del') && ( - ( - - store.showForm(info)}>编辑 - this.handleDelete(info)}>删除 - - )}/> - )} -
- {store.formVisible && } -
+ } + onClick={() => store.showForm()}>新建 + ]} + pagination={{ + showSizeChanger: true, + showLessItems: true, + hideOnSinglePage: true, + showTotal: total => `共 ${total} 条`, + pageSizeOptions: ['10', '20', '50', '100'] + }}> + + + + + {hasPermission('exec.template.edit|exec.template.del') && ( + ( + + store.showForm(info)}>编辑 + this.handleDelete(info)}>删除 + + )}/> + )} + ) } } diff --git a/spug_web/src/pages/exec/template/index.js b/spug_web/src/pages/exec/template/index.js index 4ea9598..472dc99 100644 --- a/spug_web/src/pages/exec/template/index.js +++ b/spug_web/src/pages/exec/template/index.js @@ -5,14 +5,20 @@ */ import React from 'react'; import { observer } from 'mobx-react'; -import { Input, Select, Button } from 'antd'; -import { SearchForm, AuthDiv, AuthCard } from 'components'; +import { Input, Select } from 'antd'; +import { SearchForm, AuthDiv, Breadcrumb } from 'components'; import ComTable from './Table'; +import ComForm from './Form'; import store from './store'; export default observer(function () { return ( - + + + 首页 + 批量执行 + 模版管理 + store.f_name = e.target.value} placeholder="请输入"/> - - - - - - - - ) + {store.formVisible && } + + ); })