mirror of https://github.com/openspug/spug
75 lines
2.3 KiB
JavaScript
75 lines
2.3 KiB
JavaScript
/**
|
|
* Copyright (c) OpenSpug Organization. https://github.com/openspug/spug
|
|
* Copyright (c) <spug.dev@gmail.com>
|
|
* Released under the AGPL-3.0 License.
|
|
*/
|
|
import React from 'react';
|
|
import { observer } from 'mobx-react';
|
|
import { Table, Modal, message } from 'antd';
|
|
import ComForm from './Form';
|
|
import { http, hasPermission } from 'libs';
|
|
import { Action } from "components";
|
|
import store from './store';
|
|
|
|
@observer
|
|
class ComTable extends React.Component {
|
|
componentDidMount() {
|
|
store.fetchRecords()
|
|
}
|
|
|
|
handleDelete = (text) => {
|
|
Modal.confirm({
|
|
title: '删除确认',
|
|
content: `确定要删除【${text['name']}】?`,
|
|
onOk: () => {
|
|
return http.delete('/api/exec/template/', {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()))
|
|
}
|
|
if (store.f_type) {
|
|
data = data.filter(item => item['type'].toLowerCase().includes(store.f_type.toLowerCase()))
|
|
}
|
|
return (
|
|
<React.Fragment>
|
|
<Table
|
|
rowKey="id"
|
|
loading={store.isFetching}
|
|
dataSource={data}
|
|
pagination={{
|
|
showSizeChanger: true,
|
|
showLessItems: true,
|
|
hideOnSinglePage: true,
|
|
showTotal: total => `共 ${total} 条`,
|
|
pageSizeOptions: ['10', '20', '50', '100']
|
|
}}>
|
|
<Table.Column title="模版名称" dataIndex="name"/>
|
|
<Table.Column title="模版类型" dataIndex="type"/>
|
|
<Table.Column ellipsis title="模版内容" dataIndex="body"/>
|
|
<Table.Column ellipsis title="描述信息" dataIndex="desc"/>
|
|
{hasPermission('exec.template.edit|exec.template.del') && (
|
|
<Table.Column title="操作" render={info => (
|
|
<Action>
|
|
<Action.Button auth="exec.template.edit" onClick={() => store.showForm(info)}>编辑</Action.Button>
|
|
<Action.Button auth="exec.template.del" onClick={() => this.handleDelete(info)}>删除</Action.Button>
|
|
</Action>
|
|
)}/>
|
|
)}
|
|
</Table>
|
|
{store.formVisible && <ComForm/>}
|
|
</React.Fragment>
|
|
)
|
|
}
|
|
}
|
|
|
|
export default ComTable
|