123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- import React from 'react';
- import { Tabs } from 'antd';
- import './index.less';
- import Page from '@src/containers/Page';
- import Block from '@src/components/Block';
- import ShowImage from '@src/components/ShowImage';
- import ActionLayout from '@src/layouts/ActionLayout';
- import TableLayout from '@src/layouts/TableLayout';
- // import { formatDate } from '@src/services/Tools';
- import { asyncSMessage, asyncForm, asyncDelConfirm } from '@src/services/AsyncTools';
- import { Ready } from '../../../stores/ready';
- import { System } from '../../../stores/system';
- export default class extends Page {
- init() {
- this.itemList = [{
- key: 'id',
- type: 'hidden',
- }, {
- key: 'title',
- type: 'input',
- name: '标题',
- }, {
- key: 'content',
- type: 'textarea',
- name: '内容',
- }, {
- key: 'cover',
- type: 'image',
- name: '封面图片',
- onUpload: ({ file }) => {
- return System.uploadImage(file).then(result => { return result; });
- },
- }];
- this.columns = [{
- title: '资料封面',
- dataIndex: 'cover',
- render: (text) => {
- return <ShowImage src={text} />;
- },
- }, {
- title: '资料标题',
- dataIndex: 'title',
- }, {
- title: '内容',
- dataIndex: 'content',
- }, {
- title: '操作',
- dataIndex: 'handler',
- render: (text, record) => {
- return <div className="table-button">
- {(
- <a onClick={() => {
- this.editAction(record);
- }}>编辑</a>
- )}
- {(
- <a onClick={() => {
- this.deleteAction(record);
- }}>删除</a>
- )}
- </div>;
- },
- }];
- this.actionList = [{
- key: 'add',
- name: '增加',
- }];
- }
- initData() {
- this.refreshTab(this.state.search.tab || 'official');
- }
- refreshTab(tab) {
- const { search } = this.state;
- search.tab = tab;
- this.setState({ search });
- if (tab === 'official') {
- return this.refreshOfficial();
- }
- if (tab === 'unofficial') {
- return this.refreshUnofficial();
- }
- return Promise.reject();
- }
- refreshOfficial() {
- return Ready.listData({ isOfficial: true }).then((result) => {
- this.setState({ list: result.list, total: result.total });
- });
- }
- refreshUnofficial() {
- return Ready.listData({ isOfficial: false }).then((result) => {
- this.setState({ list: result.list, total: result.total });
- });
- }
- addAction() {
- asyncForm('创建资料', this.itemList, {}, data => {
- data.isOfficial = this.state.search.tab === 'official' ? 1 : 0;
- return Ready.addData(data).then(() => {
- asyncSMessage('添加成功!');
- this.refresh();
- });
- });
- }
- editAction(row) {
- asyncForm('编辑资料', this.itemList, row, data => {
- return Ready.editData(data).then(() => {
- asyncSMessage('编辑成功!');
- this.refresh();
- });
- });
- }
- deleteAction(row) {
- asyncDelConfirm('删除确认', '是否删除选中?', () => {
- const handler = Ready.delData({ id: row.id });
- return handler.then(() => {
- asyncSMessage('删除成功!');
- this.refresh();
- });
- });
- }
- renderOfficial() {
- return <Block flex>
- <ActionLayout
- itemList={this.actionList}
- selectedKeys={this.state.selectedKeys}
- onAction={key => this.onAction(key)}
- />
- <TableLayout
- columns={this.tableSort(this.columns)}
- list={this.state.list}
- pagination={false}
- loading={this.props.core.loading}
- />
- </Block>;
- }
- renderUnofficial() {
- return this.renderOfficial();
- }
- renderView() {
- const { search } = this.state;
- const { tab } = search;
- return <div>
- <Tabs activeKey={tab || 'official'} onChange={(value) => {
- this.search({ tab: value });
- }}>
- <Tabs.TabPane tab="官方资料" key="official">
- {this.renderOfficial()}
- </Tabs.TabPane>
- <Tabs.TabPane tab="非官方资料" key="unofficial">
- {this.renderUnofficial()}
- </Tabs.TabPane>
- </Tabs>
- </div>;
- }
- }
|