UNPKG

app-base-web

Version:
388 lines (382 loc) 15.4 kB
import React from 'react'; import { Table, Form, Row, Col, Button, Input, message } from 'antd'; import UtilDate from '../../../library/util-date'; import UtilDic from '../../../library/util-dic'; import File from '../../../library/file'; import Dic from '../../../library/dic'; import UtilModal from '../../../library/util-modal'; import api from '../../../library/util-axios'; // 发布管理-图片发布 const title = "图片发布"; const url = "IssueImage/"; export default class IssueImageList extends React.Component { constructor(props) { super(props); this.state = { params: {}, data: [], pagination: {}, loading: false, selected: [],//Table checked //显藏控制 showView: false, showEdit: false, //values values: {}, }; this.columns = [{ title: "图片名称", dataIndex: "name", width: 100, render: (text, record) => (<a className="btn-detail" onClick={() => this.onView(record)}>{text}</a>) }, { title: "图片类型", dataIndex: "fileType", width: 100, render: (text, record) => (<a className="btn-detail" onClick={() => this.onView(record)}>{text}</a>) }, { title: "业务类型", dataIndex: "type", width: 100, render: (text, record) => { return UtilDic.json("app", "imageType")[text] } }, { title: "业务子类型", dataIndex: "subType", width: 100 }, { title: "图片链接", dataIndex: "url", width: 100, render: (text, record) => { return <File cls="simpleFile" fileList={text} hide="true" /> } }, { title: "排序时间", dataIndex: "time", width: 100, render: (text, record) => { return UtilDate.getDate(text) } }]; } componentDidMount() { this.onLoad(this.state.params); } /*** Table ***/ async onLoad(params) { this.setState({ loading: true }); let rs = await api.get(url + "getList", params); let pagination = { pageSizeOptions: ["20", "100", "200", "500", "1000"], pageSize: params.pageSize || 20, defaultPageSize: params.pageSize || 20, showSizeChanger: true, showQuickJumper: true, total: rs.total, showTotal: (total) => { return `总记录 ${total} ` } }; this.setState({ loading: false, showEdit: false, params, data: rs.data, pagination }); } onChange = (pagination, filters, sorter) => { let params = this.state.params; params.pageSize = pagination.pageSize; params.pageIndex = pagination.current; this.onLoad(params); } onSearch = (value) => { let params = this.state.params; params.name = value; this.onLoad(params); } onAdd = () => { let values = {}; Object.keys(this.state.values).forEach(key => values[key] = undefined); this.setState({ showView: false, showEdit: true, values }); } onView = (values) => { this.setState({ showView: true, loading: false, values }); } onEdit = (values) => { let me = this; api.get(url + "getModel?id=" + values.id, {}, function (rs) { me.setState({ showEdit: true, showView: false, values: rs.data }); }); } onSave = (values) => { this.onLoad(this.state.params); } onDel = () => { let me = this; if (me.state.selected.length == 0) { message.error('请选择记录!'); return; } UtilModal.confirm({ content: '确定删除?', onOk: function () { api.delete(url + "delete?id=" + me.state.selected).then(function (rs) { if (rs.success) { message.info(rs.msg); me.onLoad(me.state.params || {}); } else { message.error(rs.msg); } }); } }) } /*** ****/ render() { var tableCfg = { scroll: { y: this.props.height - 210 }, size: "middle", rowKey: "id", columns: this.columns, rowSelection: { selectedRowKeys: this.state.selected, onChange: (selectedRowKeys, selectedRows) => { this.setState({ selected: selectedRowKeys }); } }, rowClassName: (record) => { return record.id === this.state.selectedRowId ? 'row-selected' : ''; }, onRow: (record) => { return { onClick: event => { this.setState({ selectedRowId: record.id }); } } }, dataSource: this.state.data, pagination: this.state.pagination, loading: this.state.loading, onChange: this.onChange } return <div className="app-admin"> <div className={this.state.showView || this.state.showEdit ? "hide" : ""}> <Row> <Col className="main-title" ><i className="iconfont icon-title"></i>{title}</Col> </Row> <Row className="main-toolbar"> <Col className="text-left" xs={16}> <Button className="btn-add" onClick={this.onAdd}><i className="iconfont icon-add"></i>录入</Button> <Button className="btn-del" onClick={this.onDel}><i className="iconfont icon-del"></i>删除</Button> </Col> <Col className="text-right" xs={8}> <Input.Search placeholder="请输入名称" onSearch={value => this.onSearch(value)} enterButton /> </Col> </Row> <Table {...tableCfg} /> </div> {this.state.showView ? <FormView height={this.props.height - 140} values={this.state.values} onEdit={this.onEdit} onReturn={() => { this.setState({ showView: false }) }} /> : ""} {this.state.showEdit ? <FormEdit height={this.props.height - 140} values={this.state.values} onSave={this.onSave} onCancel={() => { this.setState({ showEdit: false }) }} onEditReturn={() => { this.setState({ showEdit: false, showView: true }) }} /> : ""} </div>; } } class FormView extends React.Component { constructor(props) { super(props); this.state = { ...props.values }; } componentDidMount() { let me = this; api.get(url + "getModel?id=" + this.state.id, {}, function (rs) { me.setState({ ...rs.data }) }); } render() { return ( <Form className="form-view"> <div className="form-title"> <i>{title} - 详情</i> <span><Button className="btn-edit" onClick={(e) => { this.props.onEdit(this.state) }}><i className="iconfont icon-edit"></i>编辑</Button></span> </div> <div className="form-content" style={{ height: this.props.height }}> <Row> <Col xs={{ span: 22, offset: 2 }}><label className="label">图片名称</label><span>{this.state.name}</span></Col> {/* <Col xs={{ span: 10, offset: 2 }}><label className="label">系统名称</label><span>{this.state.systemName}</span></Col> */} <Col xs={{ span: 10, offset: 2 }}><label className="label">图片类型</label><span>{this.state.fileType}</span></Col> </Row> <Row> <Col xs={{ span: 10, offset: 2 }}><label className="label">业务类型</label><span>{UtilDic.json("app", "imageType")[this.state.type]}</span></Col> <Col xs={{ span: 10, offset: 2 }}><label className="label">业务子类型</label><span>{this.state.subType}</span></Col> </Row> <Row> <Col xs={{ span: 22, offset: 2 }}><label className="label">图片链接</label><span><File cls="simpleFile" fileList={this.state.url} hide="true" /></span></Col> </Row> <Row> <Col xs={{ span: 22, offset: 2 }}><label className="label">图片描述</label><span>{this.state.memo}</span></Col> </Row> <Row> <Col xs={{ span: 10, offset: 2 }}><label className="label">排序时间</label><span>{UtilDate.getDate(this.state.time)}</span></Col> {/* <Col xs={{ span: 10, offset: 2 }}><label className="label">图片高度</label><span>{this.state.height}</span></Col> <Col xs={{ span: 10, offset: 2 }}><label className="label">图片宽度</label><span>{this.state.width}</span></Col> */} </Row> </div> <div className="form-toolbar"> <Button className="btn-return" onClick={this.props.onReturn}><i className="iconfont icon-return"></i>返回</Button> </div> </Form> ); } } class FormEdit extends React.Component { constructor(props) { super(props); this.state = { ...props.values }; this.formRef = React.createRef(); } onSave = (values) => { let me = this; values.id = this.state.id; api.post(url + "save", values).then(function (rs) { if (rs.success) { message.info(rs.msg); me.props.onSave(values); } else { message.error(rs.msg); } }); } render() { return ( <Form ref={this.formRef} className="form-edit" layout="vertical" onFinish={this.onSave}> <div className="form-title"> <i> {title} - {this.state.id ? "编辑" : "录入"}</i> {this.state.id ? <span><Button className="btn-return" onClick={this.props.onEditReturn}><i className="iconfont icon-return"></i>返回</Button></span> : ""} </div> <div className="form-content" style={{ height: this.props.height }}> <Row> <Col xs={12}> <Form.Item labelCol={{ span: 6 }} wrapperCol={{ span: 18 }} name="name" label="图片名称" initialValue={this.state.name} rules={[{ required: true, message: '请输入图片名称' }]} > <Input /> </Form.Item> </Col> <Col xs={12}> <Form.Item labelCol={{ span: 6 }} wrapperCol={{ span: 18 }} name="fileType" label="图片类型" initialValue={this.state.fileType}> <Input /> </Form.Item> </Col> </Row> <Row> <Col xs={12}> <Form.Item labelCol={{ span: 6 }} wrapperCol={{ span: 18 }} name="type" label="业务类型" initialValue={String(this.state.type || "")} rules={[{ required: true, message: '请输入业务类型' }]} > <Dic params={{ app: "app", type: "imageType" }} /> </Form.Item> </Col> <Col xs={12}> <Form.Item labelCol={{ span: 6 }} wrapperCol={{ span: 18 }} name="subType" label="业务子类型" initialValue={this.state.subType}> <Input /> </Form.Item> </Col> </Row> <Row> <Col xs={24}> <Form.Item name="url" label="图片链接" initialValue={this.state.url} valuePropName="fileList" > <File multiple={true} onChange={(fileList) => { let state = this.state; state.url = fileList; this.setState(state); }} /> </Form.Item> </Col> </Row> <Row> <Col xs={24}> <Form.Item name="memo" label="图片描述" initialValue={this.state.memo} > <Input.TextArea /> </Form.Item> </Col> </Row> <Row> <Col xs={24}> <Form.Item name="ord" label="排序号" initialValue={this.state.ord} > <Input /> </Form.Item> </Col> </Row> </div> <div className="form-toolbar"> <Button className="btn-cancel" onClick={this.props.onCancel}><i className="iconfont icon-cancel"></i>取消</Button> <Button className="btn-submit" htmlType="submit"><i className="iconfont icon-submit"></i>提交</Button> </div> </Form > ); } }