mirror of https://github.com/openspug/spug
style migrate v3
parent
3128fbfc7e
commit
a1a9792f1d
|
@ -2,6 +2,7 @@
|
||||||
padding: 24px 24px 0 24px;
|
padding: 24px 24px 0 24px;
|
||||||
background-color: #fff;
|
background-color: #fff;
|
||||||
border-radius: 2px;
|
border-radius: 2px;
|
||||||
|
margin-bottom: 16px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.searchForm :global(.ant-form-item) {
|
.searchForm :global(.ant-form-item) {
|
||||||
|
|
|
@ -3,62 +3,54 @@
|
||||||
* Copyright (c) <spug.dev@gmail.com>
|
* Copyright (c) <spug.dev@gmail.com>
|
||||||
* Released under the AGPL-3.0 License.
|
* Released under the AGPL-3.0 License.
|
||||||
*/
|
*/
|
||||||
import React from 'react';
|
import React, { useState } from 'react';
|
||||||
import { observer } from 'mobx-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 { ACEditor } from 'components';
|
||||||
import { http, cleanCommand } from 'libs';
|
import { http, cleanCommand } from 'libs';
|
||||||
import store from './store';
|
import store from './store';
|
||||||
|
|
||||||
@observer
|
export default observer(function () {
|
||||||
class ComForm extends React.Component {
|
const [form] = Form.useForm();
|
||||||
constructor(props) {
|
const [loading, setLoading] = useState(false);
|
||||||
super(props);
|
const [body, setBody] = useState(store.record.body);
|
||||||
this.state = {
|
|
||||||
loading: false,
|
|
||||||
type: null,
|
|
||||||
body: store.record['body'],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
handleSubmit = () => {
|
function handleSubmit() {
|
||||||
this.setState({loading: true});
|
setLoading(true);
|
||||||
const formData = this.props.form.getFieldsValue();
|
const formData = form.getFieldsValue();
|
||||||
formData['id'] = store.record.id;
|
formData['id'] = store.record.id;
|
||||||
formData['body'] = cleanCommand(this.state.body);
|
formData['body'] = cleanCommand(body);
|
||||||
http.post('/api/exec/template/', formData)
|
http.post('/api/exec/template/', formData)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
message.success('操作成功');
|
message.success('操作成功');
|
||||||
store.formVisible = false;
|
store.formVisible = false;
|
||||||
store.fetchRecords()
|
store.fetchRecords()
|
||||||
}, () => this.setState({loading: false}))
|
}, () => setLoading(false))
|
||||||
};
|
}
|
||||||
|
|
||||||
handleAddZone = () => {
|
function handleAddZone() {
|
||||||
|
let type;
|
||||||
Modal.confirm({
|
Modal.confirm({
|
||||||
icon: 'exclamation-circle',
|
icon: <ExclamationCircleOutlined/>,
|
||||||
title: '添加模板类型',
|
title: '添加模板类型',
|
||||||
content: this.addZoneForm,
|
content: (
|
||||||
|
<Form layout="vertical" style={{marginTop: 24}}>
|
||||||
|
<Form.Item required label="模板类型">
|
||||||
|
<Input onChange={e => type = e.target.value}/>
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
),
|
||||||
onOk: () => {
|
onOk: () => {
|
||||||
if (this.state.type) {
|
if (type) {
|
||||||
store.types.push(this.state.type);
|
store.types.push(type);
|
||||||
this.props.form.setFieldsValue({'type': this.state.type})
|
form.setFieldsValue({type})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
};
|
}
|
||||||
|
|
||||||
addZoneForm = (
|
|
||||||
<Form>
|
|
||||||
<Form.Item required label="模板类型">
|
|
||||||
<Input onChange={val => this.setState({type: val.target.value})}/>
|
|
||||||
</Form.Item>
|
|
||||||
</Form>
|
|
||||||
);
|
|
||||||
|
|
||||||
render() {
|
|
||||||
const info = store.record;
|
const info = store.record;
|
||||||
const {getFieldDecorator} = this.props.form;
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
visible
|
visible
|
||||||
|
@ -66,44 +58,35 @@ class ComForm extends React.Component {
|
||||||
maskClosable={false}
|
maskClosable={false}
|
||||||
title={store.record.id ? '编辑模板' : '新建模板'}
|
title={store.record.id ? '编辑模板' : '新建模板'}
|
||||||
onCancel={() => store.formVisible = false}
|
onCancel={() => store.formVisible = false}
|
||||||
confirmLoading={this.state.loading}
|
confirmLoading={loading}
|
||||||
onOk={this.handleSubmit}>
|
onOk={handleSubmit}>
|
||||||
<Form labelCol={{span: 6}} wrapperCol={{span: 14}}>
|
<Form form={form} initialValues={info} labelCol={{span: 6}} wrapperCol={{span: 14}}>
|
||||||
<Form.Item required label="模板类型">
|
<Form.Item required label="模板类型" style={{marginBottom: 0}}>
|
||||||
<Col span={16}>
|
<Form.Item name="type" style={{display: 'inline-block', width: 'calc(75%)', marginRight: 8}}>
|
||||||
{getFieldDecorator('type', {initialValue: info['type']})(
|
|
||||||
<Select placeholder="请选择模板类型">
|
<Select placeholder="请选择模板类型">
|
||||||
{store.types.map(item => (
|
{store.types.map(item => (
|
||||||
<Select.Option value={item} key={item}>{item}</Select.Option>
|
<Select.Option value={item} key={item}>{item}</Select.Option>
|
||||||
))}
|
))}
|
||||||
</Select>
|
</Select>
|
||||||
)}
|
|
||||||
</Col>
|
|
||||||
<Col span={6} offset={2}>
|
|
||||||
<Button type="link" onClick={this.handleAddZone}>添加类型</Button>
|
|
||||||
</Col>
|
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item required label="模板名称">
|
<Form.Item style={{display: 'inline-block', width: 'calc(25%-8px)'}}>
|
||||||
{getFieldDecorator('name', {initialValue: info['name']})(
|
<Button type="link" onClick={handleAddZone}>添加类型</Button>
|
||||||
|
</Form.Item>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item required name="name" label="模板名称">
|
||||||
<Input placeholder="请输入模板名称"/>
|
<Input placeholder="请输入模板名称"/>
|
||||||
)}
|
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item required label="模板内容">
|
<Form.Item required label="模板内容">
|
||||||
<ACEditor
|
<ACEditor
|
||||||
mode="sh"
|
mode="sh"
|
||||||
value={this.state.body}
|
value={body}
|
||||||
onChange={val => this.setState({body: val})}
|
onChange={val => setBody(val)}
|
||||||
height="300px"/>
|
height="300px"/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item label="备注信息">
|
<Form.Item name="desc" label="备注信息">
|
||||||
{getFieldDecorator('desc', {initialValue: info['desc']})(
|
|
||||||
<Input.TextArea placeholder="请输入模板备注信息"/>
|
<Input.TextArea placeholder="请输入模板备注信息"/>
|
||||||
)}
|
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
</Form>
|
</Form>
|
||||||
</Modal>
|
</Modal>
|
||||||
)
|
)
|
||||||
}
|
})
|
||||||
}
|
|
||||||
|
|
||||||
export default Form.create()(ComForm)
|
|
|
@ -6,9 +6,9 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { observer } from 'mobx-react';
|
import { observer } from 'mobx-react';
|
||||||
import { Table, Modal, message } from 'antd';
|
import { Table, Modal, message } from 'antd';
|
||||||
import ComForm from './Form';
|
import { PlusOutlined } from '@ant-design/icons';
|
||||||
import { http, hasPermission } from 'libs';
|
import { http, hasPermission } from 'libs';
|
||||||
import { Action } from "components";
|
import { Action, TableCard, AuthButton } from "components";
|
||||||
import store from './store';
|
import store from './store';
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
|
@ -40,11 +40,19 @@ class ComTable extends React.Component {
|
||||||
data = data.filter(item => item['type'].toLowerCase().includes(store.f_type.toLowerCase()))
|
data = data.filter(item => item['type'].toLowerCase().includes(store.f_type.toLowerCase()))
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<React.Fragment>
|
<TableCard
|
||||||
<Table
|
title="模板列表"
|
||||||
rowKey="id"
|
rowKey="id"
|
||||||
loading={store.isFetching}
|
loading={store.isFetching}
|
||||||
dataSource={data}
|
dataSource={data}
|
||||||
|
onReload={store.fetchRecords}
|
||||||
|
actions={[
|
||||||
|
<AuthButton
|
||||||
|
auth="exec.template.add"
|
||||||
|
type="primary"
|
||||||
|
icon={<PlusOutlined/>}
|
||||||
|
onClick={() => store.showForm()}>新建</AuthButton>
|
||||||
|
]}
|
||||||
pagination={{
|
pagination={{
|
||||||
showSizeChanger: true,
|
showSizeChanger: true,
|
||||||
showLessItems: true,
|
showLessItems: true,
|
||||||
|
@ -64,9 +72,7 @@ class ComTable extends React.Component {
|
||||||
</Action>
|
</Action>
|
||||||
)}/>
|
)}/>
|
||||||
)}
|
)}
|
||||||
</Table>
|
</TableCard>
|
||||||
{store.formVisible && <ComForm/>}
|
|
||||||
</React.Fragment>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,14 +5,20 @@
|
||||||
*/
|
*/
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { observer } from 'mobx-react';
|
import { observer } from 'mobx-react';
|
||||||
import { Input, Select, Button } from 'antd';
|
import { Input, Select } from 'antd';
|
||||||
import { SearchForm, AuthDiv, AuthCard } from 'components';
|
import { SearchForm, AuthDiv, Breadcrumb } from 'components';
|
||||||
import ComTable from './Table';
|
import ComTable from './Table';
|
||||||
|
import ComForm from './Form';
|
||||||
import store from './store';
|
import store from './store';
|
||||||
|
|
||||||
export default observer(function () {
|
export default observer(function () {
|
||||||
return (
|
return (
|
||||||
<AuthCard auth="exec.template.view">
|
<AuthDiv auth="exec.template.view">
|
||||||
|
<Breadcrumb>
|
||||||
|
<Breadcrumb.Item>首页</Breadcrumb.Item>
|
||||||
|
<Breadcrumb.Item>批量执行</Breadcrumb.Item>
|
||||||
|
<Breadcrumb.Item>模版管理</Breadcrumb.Item>
|
||||||
|
</Breadcrumb>
|
||||||
<SearchForm>
|
<SearchForm>
|
||||||
<SearchForm.Item span={8} title="模板类型">
|
<SearchForm.Item span={8} title="模板类型">
|
||||||
<Select allowClear value={store.f_type} onChange={v => store.f_type = v} placeholder="请选择">
|
<Select allowClear value={store.f_type} onChange={v => store.f_type = v} placeholder="请选择">
|
||||||
|
@ -24,14 +30,9 @@ export default observer(function () {
|
||||||
<SearchForm.Item span={8} title="模版名称">
|
<SearchForm.Item span={8} title="模版名称">
|
||||||
<Input allowClear value={store.f_name} onChange={e => store.f_name = e.target.value} placeholder="请输入"/>
|
<Input allowClear value={store.f_name} onChange={e => store.f_name = e.target.value} placeholder="请输入"/>
|
||||||
</SearchForm.Item>
|
</SearchForm.Item>
|
||||||
<SearchForm.Item span={8}>
|
|
||||||
<Button type="primary" icon="sync" onClick={store.fetchRecords}>刷新</Button>
|
|
||||||
</SearchForm.Item>
|
|
||||||
</SearchForm>
|
</SearchForm>
|
||||||
<AuthDiv auth="exec.template.add" style={{marginBottom: 16}}>
|
|
||||||
<Button type="primary" icon="plus" onClick={() => store.showForm()}>新建</Button>
|
|
||||||
</AuthDiv>
|
|
||||||
<ComTable/>
|
<ComTable/>
|
||||||
</AuthCard>
|
{store.formVisible && <ComForm/>}
|
||||||
)
|
</AuthDiv>
|
||||||
|
);
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue