import React from 'react'; // import { Link } from 'react-router-dom'; import { Button, Switch, Modal } from 'antd'; import './index.less'; import Page from '@src/containers/Page'; import Block from '@src/components/Block'; import EditTableCell from '@src/components/EditTableCell'; // import FilterLayout from '@src/layouts/FilterLayout'; import ActionLayout from '@src/layouts/ActionLayout'; import TableLayout from '@src/layouts/TableLayout'; import { formatDate, getMap } from '@src/services/Tools'; import { asyncSMessage, asyncDelConfirm, asyncForm } from '@src/services/AsyncTools'; // import { SwitchSelect } from '../../../../Constant'; import { Ready } from '../../../stores/ready'; export default class extends Page { init() { this.structMap = {}; this.actionList = [{ key: 'add', type: 'primary', name: '创建', // render: (item) => { // return ; // }, }, { key: 'struct', name: '管理板块', }]; this.columns = [{ title: '板块', dataIndex: 'plate', render: (text) => { return this.structMap[text] || ''; }, }, { title: '文章标题', dataIndex: 'title', }, { title: '更新时间', dataIndex: 'updateTime', render: (text) => { return formatDate(text, 'YYYY-MM-DD HH:mm:ss'); }, }, { title: '操作', dataIndex: 'handler', render: (text, record) => { return
{ { this.editAction(record); }}>编辑} { { this.deleteAction(record); }}>删除}
; }, }]; this.itemList = [{ key: 'id', type: 'hidden', }, { key: 'plate', type: 'select', name: '板块', select: [], required: true, }, { key: 'title', type: 'input', name: '标题', required: true, }, { key: 'link', type: 'input', name: '链接', required: true, }]; this.structColumns = [{ title: '板块名称', dataIndex: 'plate', render: (text, record, index) => { return { this.changeStruct(index, 'plate', v); }} />; }, }, { title: '增加跳转', dataIndex: 'jump', render: (text, record, index) => { return { this.changeStruct(index, 'jump', value ? 1 : 0); }} checked={!!text} />; }, }, { title: '跳转地址', dataIndex: 'link', render: (text, record, index) => { return { this.changeStruct(index, 'link', v); }} />; }, }, { title: '按钮名称', dataIndex: 'text', render: (text, record, index) => { return { this.changeStruct(index, 'text', v); }} />; }, }]; Ready.getReadyRead().then(result => { return this.refreshStruct(result); }).then(() => { this.initData(); }); } initData() { Ready.listRead(this.state.search).then(result => { this.setTableData(result.list, result.total); }); } refreshStruct(result) { result = result || {}; result.plates = (result.plates || []).map((row, index) => { row.title = row.plate; row.value = `${index + 1}`; return row; }); this.structMap = getMap(result.plates, 'value', 'plate'); this.setState({ struct: result }); } structAction() { const { struct = {} } = this.state; this.open(struct); } changeStruct(index, field, value, other) { const { detail } = this.state; if (other !== undefined) { detail.plates.forEach((row) => { row[field] = other; }); } detail.plates[index][field] = value; this.setState({ detail }); } submitStruct() { const { detail } = this.state; Ready.setReadyRead(detail).then(() => { asyncSMessage('保存成功'); this.close(false, 'detail'); return this.refreshStruct(detail); }).then(() => { return this.initData(); }); } addAction() { this.itemList[1].select = this.state.struct.plates; asyncForm('创建', this.itemList, {}, data => { return Ready.addRead(data).then(() => { asyncSMessage('添加成功!'); this.refresh(); }); }).then(component => { this.formF = component; }); } editAction(row) { this.itemList[1].select = this.state.struct.plates; asyncForm('编辑', this.itemList, row, data => { return Ready.editRead(data).then(() => { asyncSMessage('编辑成功!'); this.refresh(); }); }).then(component => { this.formF = component; }); } deleteAction(row) { asyncDelConfirm('删除确认', '是否删除选中?', () => { const handler = Ready.delRead({ id: row.id }); return handler.then(() => { asyncSMessage('删除成功!'); this.refresh(); }); }); } renderView() { return {/* { this.search(data); }} /> */} this.onAction(key)} /> this.tableChange(pagination, filters, sorter)} onSelect={(keys, rows) => this.tableSelect(keys, rows)} selectedKeys={this.state.selectedKeys} /> {this.state.detail && { this.close(false, 'detail'); }} onOk={() => { this.submitStruct(); }}> } ; } }