Commit bc005bb2 authored by superman's avatar superman

列表的接口全部改成list

parent 688aa87b
This diff is collapsed.
This diff is collapsed.
...@@ -26,7 +26,8 @@ import { ...@@ -26,7 +26,8 @@ import {
smallFormItemLayout, smallFormItemLayout,
footerFormSubmitLayout, footerFormSubmitLayout,
handleUpload, handleUpload,
leftRightFormItemLayout leftRightFormItemLayout,
FILE_UPLOAD
} from '../../utils'; } from '../../utils';
...@@ -204,7 +205,7 @@ export default class BaseInfoForm extends Component { ...@@ -204,7 +205,7 @@ export default class BaseInfoForm extends Component {
<Form.Item label="产品主图" {...leftRightFormItemLayout}> <Form.Item label="产品主图" {...leftRightFormItemLayout}>
{ {
isEdit ? isEdit ?
<Upload action="/api/fileUpload/upload" listType="picture-card" <Upload {...FILE_UPLOAD} listType="picture-card"
multiple={true} multiple={true}
headers={{ headers={{
authorization: user && user.token, authorization: user && user.token,
......
...@@ -27,7 +27,8 @@ import { ...@@ -27,7 +27,8 @@ import {
formItemLayout, formItemLayout,
smallFormItemLayout, smallFormItemLayout,
footerFormSubmitLayout, footerFormSubmitLayout,
handleUpload handleUpload,
FILE_UPLOAD
} from '../../utils'; } from '../../utils';
import Copy from '../../components/CopyToClipboard/CopyToClipboard'; import Copy from '../../components/CopyToClipboard/CopyToClipboard';
...@@ -88,15 +89,15 @@ export default class DocumentsForm extends Component { ...@@ -88,15 +89,15 @@ export default class DocumentsForm extends Component {
<Form.Item> <Form.Item>
{ {
isEdit ? isEdit ?
<Upload.Dragger action="/api/fileUpload/upload" <Upload.Dragger {...FILE_UPLOAD}
multiple={true} multiple={true}
headers={{ headers={{
authorization: user && user.token, authorization: user && user.token,
}} }}
onChange={info=>this.setState({fileList: handleUpload(info)})} onChange={info=>this.setState({fileList: handleUpload(info)})}
//showUploadList={false} //showUploadList={false}
onPreview={(e)=>console.log(e)} onPreview={(e)=>console.log(e)}
fileList={this.state.fileList} fileList={this.state.fileList}
> >
<p className="ant-upload-drag-icon"> <p className="ant-upload-drag-icon">
<Icon type="inbox"/> <Icon type="inbox"/>
......
...@@ -33,7 +33,7 @@ export default class List extends Component { ...@@ -33,7 +33,7 @@ export default class List extends Component {
}; };
handleRowClick({id}) { handleRowClick({id}) {
this.props.history.push('/announcement/' + id ); this.props.history.push('/announcement/' + id);
} }
handleFilterVisible() { handleFilterVisible() {
...@@ -46,9 +46,11 @@ export default class List extends Component { ...@@ -46,9 +46,11 @@ export default class List extends Component {
const pagination = { const pagination = {
total: total, total: total,
pageSize: parseInt(query.s, 10) || 10, pageSize: parseInt(query.s, 10) || 30,
current: parseInt(query.p, 10) || 1, current: parseInt(query.p, 10) || 1,
showSizeChanger: true, showSizeChanger: true,
showTotal: total => `共 ${total} 条`,
pageSizeOptions:['10', '30', '50', '100'],
onShowSizeChange: (current, pageSize)=> { onShowSizeChange: (current, pageSize)=> {
console.log('Current: ', current, '; PageSize: ', pageSize); console.log('Current: ', current, '; PageSize: ', pageSize);
query.p = current; query.p = current;
...@@ -148,18 +150,19 @@ export default class List extends Component { ...@@ -148,18 +150,19 @@ export default class List extends Component {
const footer = ( const footer = (
<div style={{margin:'10px 0'}}> <div style={{margin:'10px 0'}}>
<Link to={'/announcement/create?itemId='+ query.itemId + '&title='+ query.title}> <Link to={'/announcement/create?itemId='+ query.itemId + '&title='+ query.title}>
<Button type="primary"> <Button type="primary">
<Icon type="plus"/>添加 <Icon type="plus"/>添加
</Button> </Button>
</Link> </Link>
<Button style={{margin:'0 1em'}} type="ghost" onClick={e=>{e.preventDefault(); this.props.history.goBack();}}> <Button style={{margin:'0 1em'}} type="ghost"
onClick={e=>{e.preventDefault(); this.props.history.goBack();}}>
<Icon type="rollback"/>返回 <Icon type="rollback"/>返回
</Button> </Button>
</div> </div>
); );
return ( return (
<Layout header={header} > <Layout header={header}>
<Table className="list-table" columns={columns} <Table className="list-table" columns={columns}
dataSource={Array.isArray(items)?items:[]} dataSource={Array.isArray(items)?items:[]}
loading={loading} loading={loading}
......
This diff is collapsed.
:global {
.resource-category {
}
.resource-item {
& > .ant-tree-child-tree {
&:before,
&:after {
content: '';
display: block;
clear: both;
}
}
}
.resource-action {
float: left;
}
.ant-tree-checkbox-indeterminate .ant-tree-checkbox-inner {
background-color: #1DA57A;
border-color: #1DA57A
}
}
...@@ -13,7 +13,8 @@ import { ...@@ -13,7 +13,8 @@ import {
handleUpload, handleUpload,
filterFormItemLayout, filterFormItemLayout,
PRODUCT_STATUS, PRODUCT_STATUS,
filterFormItemStyle filterFormItemStyle,
enableStatusToString
} from '../../utils'; } from '../../utils';
import {Link} from 'react-router'; import {Link} from 'react-router';
...@@ -21,7 +22,6 @@ import Layout from '../../components/Layout/Layout'; ...@@ -21,7 +22,6 @@ import Layout from '../../components/Layout/Layout';
import MainHeader from '../../components/MainHeader/MainHeader'; import MainHeader from '../../components/MainHeader/MainHeader';
@connect(state=>({ @connect(state=>({
items: state.authority.items, items: state.authority.items,
loading: state.authority.loading, loading: state.authority.loading,
...@@ -93,12 +93,12 @@ export default class List extends Component { ...@@ -93,12 +93,12 @@ export default class List extends Component {
const columns = [ const columns = [
{ {
title: '名称', title: '角色ID',
dataIndex: 'name', dataIndex: 'name',
key: 'name', key: 'name',
width: 150, width: 150,
}, { }, {
title: '描述', title: '名称',
dataIndex: 'description', dataIndex: 'description',
key: 'description', key: 'description',
width: 100 width: 100
...@@ -119,6 +119,9 @@ export default class List extends Component { ...@@ -119,6 +119,9 @@ export default class List extends Component {
key: 'status', key: 'status',
width: 80, width: 80,
className: 'tac', className: 'tac',
render: (status)=>(
<span>{enableStatusToString(status)}</span>
)
}, { }, {
title: '操作', title: '操作',
key: 'operation', key: 'operation',
...@@ -135,9 +138,11 @@ export default class List extends Component { ...@@ -135,9 +138,11 @@ export default class List extends Component {
const pagination = { const pagination = {
total: total, total: total,
pageSize: parseInt(query.s, 10) || 10, pageSize: parseInt(query.s, 10) || 30,
current: parseInt(query.p, 10) || 1, current: parseInt(query.p, 10) || 1,
showSizeChanger: true, showSizeChanger: true,
showTotal: total => `共 ${total} 条`,
pageSizeOptions: ['10', '30', '50', '100'],
onShowSizeChange: (current, pageSize)=> { onShowSizeChange: (current, pageSize)=> {
console.log('Current: ', current, '; PageSize: ', pageSize); console.log('Current: ', current, '; PageSize: ', pageSize);
query.p = current; query.p = current;
......
...@@ -27,7 +27,8 @@ import Layout from '../../components/Layout/Layout'; ...@@ -27,7 +27,8 @@ import Layout from '../../components/Layout/Layout';
import MainHeader from '../../components/MainHeader/MainHeader'; import MainHeader from '../../components/MainHeader/MainHeader';
import { import {
handleUpload handleUpload,
FILE_UPLOAD
} from '../../utils'; } from '../../utils';
@connect(state=>({ @connect(state=>({
...@@ -52,14 +53,14 @@ export default class BaseUpload extends Component { ...@@ -52,14 +53,14 @@ export default class BaseUpload extends Component {
<Layout header={header}> <Layout header={header}>
<Row style={{padding:'20px 20px 20px'}}> <Row style={{padding:'20px 20px 20px'}}>
<Col span="24"> <Col span="24">
<Upload.Dragger action="/api/fileUpload/upload" <Upload.Dragger {...FILE_UPLOAD}
multiple={true} multiple={true}
headers={{ headers={{
authorization: user && user.token, authorization: user && user.token,
}} }}
onChange={info=>this.setState({fileList: handleUpload(info)})} onChange={info=>this.setState({fileList: handleUpload(info)})}
showUploadList={false} showUploadList={false}
onPreview={(e)=>console.log(e)} onPreview={(e)=>console.log(e)}
> >
<p className="ant-upload-drag-icon"> <p className="ant-upload-drag-icon">
<Icon type="inbox"/> <Icon type="inbox"/>
......
...@@ -144,7 +144,7 @@ export default class AddItem extends Component { ...@@ -144,7 +144,7 @@ export default class AddItem extends Component {
<Form.Item label="消息正文" help={ <Form.Item label="消息正文" help={
<div dangerouslySetInnerHTML={{__html: channelType === 1 ? '微信跳转链接模板: &lt;a href="此处替换跳转链接"&gt;此处替换显示内容&lt;/a&gt;' : '最多50个字符' }} /> <div dangerouslySetInnerHTML={{__html: channelType === 1 ? '微信跳转链接模板: &lt;a href="此处替换跳转链接"&gt;此处替换显示内容&lt;/a&gt;' : '最多50个字符' }} />
} {...formItemLayout}> } {...formItemLayout}>
<Input placeholder="消息正文" type="textarea" maxLength="50" <Input placeholder="消息正文" type="textarea" maxLength={ channelType === 1 ? 10000:50}
autosize={{minRows:3, maxRows:10}} {...getFieldProps('customMessage.contents')} /> autosize={{minRows:3, maxRows:10}} {...getFieldProps('customMessage.contents')} />
</Form.Item> </Form.Item>
......
...@@ -43,9 +43,11 @@ export default class List extends Component { ...@@ -43,9 +43,11 @@ export default class List extends Component {
const pagination = { const pagination = {
total: total, total: total,
pageSize: parseInt(query.s, 10) || 10, pageSize: parseInt(query.s, 10) || 30,
current: parseInt(query.p, 10) || 1, current: parseInt(query.p, 10) || 1,
showSizeChanger: true, showSizeChanger: true,
showTotal: total => `共 ${total} 条`,
pageSizeOptions:['10', '30', '50', '100'],
onShowSizeChange: (current, pageSize)=> { onShowSizeChange: (current, pageSize)=> {
console.log('Current: ', current, '; PageSize: ', pageSize); console.log('Current: ', current, '; PageSize: ', pageSize);
query.p = current; query.p = current;
......
...@@ -40,6 +40,7 @@ const columns = [ ...@@ -40,6 +40,7 @@ const columns = [
title: '标题', title: '标题',
dataIndex: 'shortTitle', dataIndex: 'shortTitle',
key: 'shortTitle', key: 'shortTitle',
width: 200,
render: (shortTitle, record)=>(<span title={shortTitle}>{(shortTitle + '').substring(0, 15)}</span>) render: (shortTitle, record)=>(<span title={shortTitle}>{(shortTitle + '').substring(0, 15)}</span>)
}, { }, {
title: '募集比率', title: '募集比率',
...@@ -170,9 +171,11 @@ export default class List extends Component { ...@@ -170,9 +171,11 @@ export default class List extends Component {
const pagination = { const pagination = {
total: total, total: total,
pageSize: parseInt(query.s, 10) || 10, pageSize: parseInt(query.s, 10) || 30,
current: parseInt(query.p, 10) || 1, current: parseInt(query.p, 10) || 1,
showSizeChanger: true, showSizeChanger: true,
showTotal: total => `共 ${total} 条`,
pageSizeOptions:['10', '30', '50', '100'],
onShowSizeChange: (current, pageSize)=> { onShowSizeChange: (current, pageSize)=> {
console.log('Current: ', current, '; PageSize: ', pageSize); console.log('Current: ', current, '; PageSize: ', pageSize);
query.p = current; query.p = current;
......
...@@ -101,9 +101,11 @@ export default class List extends Component { ...@@ -101,9 +101,11 @@ export default class List extends Component {
const pagination = { const pagination = {
total: total, total: total,
pageSize: parseInt(query.s, 10) || 10, pageSize: parseInt(query.s, 10) || 30,
current: parseInt(query.p, 10) || 1, current: parseInt(query.p, 10) || 1,
showSizeChanger: true, showSizeChanger: true,
showTotal: total => `共 ${total} 条`,
pageSizeOptions:['10', '30', '50', '100'],
onShowSizeChange: (current, pageSize)=> { onShowSizeChange: (current, pageSize)=> {
console.log('Current: ', current, '; PageSize: ', pageSize); console.log('Current: ', current, '; PageSize: ', pageSize);
query.p = current; query.p = current;
......
...@@ -29,15 +29,12 @@ import { ...@@ -29,15 +29,12 @@ import {
footerFormSubmitLayout, footerFormSubmitLayout,
userStatusToString, userStatusToString,
formatDateTime, formatDateTime,
NULL NULL,
resourceActions,
enableStatusToString,
ENABLE_STATUS_LIST
} from '../../utils'; } from '../../utils';
import {
STATUS_LIST,
statusToString
} from './utils';
@connect(state=>({ @connect(state=>({
loading: state.resource.loading, loading: state.resource.loading,
item: state.resource.item, item: state.resource.item,
...@@ -74,7 +71,7 @@ export default class EditItem extends Component { ...@@ -74,7 +71,7 @@ export default class EditItem extends Component {
data = this.props.form.getFieldsValue(); data = this.props.form.getFieldsValue();
data.id = this.props.params.id; data.id = this.props.params.id;
if (isNaN(data.status)) { if (isNaN(data.status)) {
STATUS_LIST.forEach(item=> { ENABLE_STATUS_LIST.forEach(item=> {
if (item.text === data.status) { if (item.text === data.status) {
data.status = item.value data.status = item.value
} }
...@@ -134,15 +131,20 @@ export default class EditItem extends Component { ...@@ -134,15 +131,20 @@ export default class EditItem extends Component {
item && item &&
<Form className="main-form" horizontal> <Form className="main-form" horizontal>
<Form.Item label="分组" {...smallFormItemLayout}> <Form.Item label="类别" {...smallFormItemLayout}>
{ {
isEdit ? isEdit ?
<Input {...getFieldProps('category', {initialValue: item.category})} /> <Select
style={{width:200}} {...getFieldProps('category', {initialValue: item.category})}>
<Select.Option value="业务管理">业务管理</Select.Option>
<Select.Option value="基础功能">基础功能</Select.Option>
<Select.Option value="系统管理">系统管理</Select.Option>
</Select>
: :
item.category || NULL item.category || NULL
} }
</Form.Item> </Form.Item>
<Form.Item label="描述" {...smallFormItemLayout}> <Form.Item label="名称" {...smallFormItemLayout}>
{ {
isEdit ? isEdit ?
<Input {...getFieldProps('description', {initialValue: item.description})} /> <Input {...getFieldProps('description', {initialValue: item.description})} />
...@@ -154,29 +156,26 @@ export default class EditItem extends Component { ...@@ -154,29 +156,26 @@ export default class EditItem extends Component {
{ {
isEdit ? isEdit ?
<Select <Select
placeholder="请选择状态" {...getFieldProps('status', {initialValue: statusToString(item.status)})} > placeholder="请选择状态" {...getFieldProps('status', {initialValue: enableStatusToString(item.status)})} >
<Select.Option value="1">系统</Select.Option> <Select.Option value="1">系统</Select.Option>
<Select.Option value="5">禁用</Select.Option> <Select.Option value="5">禁用</Select.Option>
<Select.Option value="9">启用</Select.Option> <Select.Option value="9">启用</Select.Option>
</Select> </Select>
: :
(typeof item.status !== 'undefined' ? statusToString(item.status) : NULL) (typeof item.status !== 'undefined' ? enableStatusToString(item.status) : NULL)
} }
</Form.Item> </Form.Item>
<Form.Item label="method" {...smallFormItemLayout}>
{ item.httpMethod }
</Form.Item>
<Form.Item label="url" {...smallFormItemLayout}>
{ item.url }
</Form.Item>
<Form.Item label="controllerName" {...smallFormItemLayout}> <Form.Item label="controllerName" {...smallFormItemLayout}>
{ item.controllerName } { item.controllerName }
</Form.Item> </Form.Item>
<Form.Item label="actionName" {...smallFormItemLayout}> <Form.Item label="Actions" {...smallFormItemLayout}>
{ item.actionName } {
resourceActions(item.actionMask).map(({title, mask})=>
<span key={mask} style={{marginRight:'1em'}}>{title}</span>
)
}
</Form.Item> </Form.Item>
<Form.Item label="注册时间" {...smallFormItemLayout}> <Form.Item label="创建时间" {...smallFormItemLayout}>
{item.dateCreated && formatDateTime(item.dateCreated)} {item.dateCreated && formatDateTime(item.dateCreated)}
</Form.Item> </Form.Item>
<Form.Item {...footerFormSubmitLayout} style={{marginTop:30}}> <Form.Item {...footerFormSubmitLayout} style={{marginTop:30}}>
......
...@@ -13,17 +13,15 @@ import { ...@@ -13,17 +13,15 @@ import {
handleUpload, handleUpload,
filterFormItemLayout, filterFormItemLayout,
PRODUCT_STATUS, PRODUCT_STATUS,
filterFormItemStyle filterFormItemStyle,
ENABLE_STATUS_LIST,
enableStatusToString
} from '../../utils'; } from '../../utils';
import {Link} from 'react-router'; import {Link} from 'react-router';
import Layout from '../../components/Layout/Layout'; import Layout from '../../components/Layout/Layout';
import MainHeader from '../../components/MainHeader/MainHeader'; import MainHeader from '../../components/MainHeader/MainHeader';
import {
STATUS_LIST,
statusToString
} from './utils';
@connect(state=>({ @connect(state=>({
...@@ -102,37 +100,26 @@ export default class List extends Component { ...@@ -102,37 +100,26 @@ export default class List extends Component {
key: 'id', key: 'id',
width: 60 width: 60
}, { }, {
title: 'category', title: '类别',
dataIndex: 'category', dataIndex: 'category',
key: 'category', key: 'category',
width: 80, width: 80,
}, { }, {
title: 'description', title: '名称',
dataIndex: 'description', dataIndex: 'description',
key: 'description', key: 'description',
width: 100
}, {
title: 'Method',
dataIndex: 'httpMethod',
key: 'httpMethod',
width: 60,
className: 'tac'
}, {
title: 'url',
dataIndex: 'url',
key: 'url',
width: 200 width: 200
}, { }, {
title: 'actionName', title: '资源',
dataIndex: 'controllerName',
key: 'controllerName',
width: 180,
}, {
title: '权限值',
dataIndex: 'actionName', dataIndex: 'actionName',
key: 'actionName', key: 'actionName',
width: 80, width: 80,
className: 'tac' className: 'tac'
}, {
title: 'controllerName',
dataIndex: 'controllerName',
key: 'controllerName',
width: 180,
}, { }, {
title: '创建时间', title: '创建时间',
dataIndex: 'dateCreated', dataIndex: 'dateCreated',
...@@ -145,13 +132,13 @@ export default class List extends Component { ...@@ -145,13 +132,13 @@ export default class List extends Component {
</span> </span>
) )
}, { }, {
title: 'status', title: '状态',
dataIndex: 'status', dataIndex: 'status',
key: 'status', key: 'status',
width: 80, width: 80,
className: 'tac', className: 'tac',
render: (status)=> ( render: (status)=> (
<span>{statusToString(status)}</span> <span>{enableStatusToString(status)}</span>
) )
}, { }, {
title: '操作', title: '操作',
...@@ -169,9 +156,11 @@ export default class List extends Component { ...@@ -169,9 +156,11 @@ export default class List extends Component {
const pagination = { const pagination = {
total: total, total: total,
pageSize: parseInt(query.s, 10) || 10, pageSize: parseInt(query.s, 10) || 30,
current: parseInt(query.p, 10) || 1, current: parseInt(query.p, 10) || 1,
showSizeChanger: true, showSizeChanger: true,
showTotal: total => `共 ${total} 条`,
pageSizeOptions:['10', '30', '50', '100'],
onShowSizeChange: (current, pageSize)=> { onShowSizeChange: (current, pageSize)=> {
console.log('Current: ', current, '; PageSize: ', pageSize); console.log('Current: ', current, '; PageSize: ', pageSize);
query.p = current; query.p = current;
......
export const STATUS = {
1: '系统',
5: '禁用',
9: '启用'
};
export function statusToString(status) {
return STATUS[status] || '未定义('+ status+')';
}
export const STATUS_LIST = Object.keys(STATUS).map(key=> {
return {value: key, text: STATUS[key]}
});
...@@ -148,9 +148,11 @@ export default class List extends Component { ...@@ -148,9 +148,11 @@ export default class List extends Component {
const pagination = { const pagination = {
total: total, total: total,
pageSize: parseInt(query.s, 10) || 10, pageSize: parseInt(query.s, 10) || 30,
current: parseInt(query.p, 10) || 1, current: parseInt(query.p, 10) || 1,
showSizeChanger: true, showSizeChanger: true,
showTotal: total => `共 ${total} 条`,
pageSizeOptions:['10', '30', '50', '100'],
onShowSizeChange: (current, pageSize)=> { onShowSizeChange: (current, pageSize)=> {
console.log('Current: ', current, '; PageSize: ', pageSize); console.log('Current: ', current, '; PageSize: ', pageSize);
query.p = current; query.p = current;
......
...@@ -128,9 +128,11 @@ export default class List extends Component { ...@@ -128,9 +128,11 @@ export default class List extends Component {
const pagination = { const pagination = {
total: total, total: total,
pageSize: parseInt(query.s, 10) || 10, pageSize: parseInt(query.s, 10) || 30,
current: parseInt(query.p, 10) || 1, current: parseInt(query.p, 10) || 1,
showSizeChanger: true, showSizeChanger: true,
showTotal: total => `共 ${total} 条`,
pageSizeOptions:['10', '30', '50', '100'],
onShowSizeChange: (current, pageSize)=> { onShowSizeChange: (current, pageSize)=> {
console.log('Current: ', current, '; PageSize: ', pageSize); console.log('Current: ', current, '; PageSize: ', pageSize);
query.p = current; query.p = current;
......
...@@ -97,9 +97,11 @@ export default class List extends Component { ...@@ -97,9 +97,11 @@ export default class List extends Component {
const pagination = { const pagination = {
total: total, total: total,
pageSize: parseInt(query.s, 10) || 10, pageSize: parseInt(query.s, 10) || 30,
current: parseInt(query.p, 10) || 1, current: parseInt(query.p, 10) || 1,
showSizeChanger: true, showSizeChanger: true,
showTotal: total => `共 ${total} 条`,
pageSizeOptions:['10', '30', '50', '100'],
onShowSizeChange: (current, pageSize)=> { onShowSizeChange: (current, pageSize)=> {
console.log('Current: ', current, '; PageSize: ', pageSize); console.log('Current: ', current, '; PageSize: ', pageSize);
query.p = current; query.p = current;
......
import {takeLatest} from 'redux-saga'; /*import {takeLatest} from 'redux-saga';
import {take, call, put, fork, cancel, select} from 'redux-saga/effects'; import {take, call, put, fork, cancel, select, race} from 'redux-saga/effects';
import {message} from 'antd'; import {message} from 'antd';
export default class RESTful { export default class RESTful {
constructor() { constructor(id) {
this.id = id;
} }
index() { index() {
...@@ -27,26 +27,48 @@ export default class RESTful { ...@@ -27,26 +27,48 @@ export default class RESTful {
} }
} }
watchIndex() {
const self = this;
return function*() {
while (true) {
const {query} = yield take('FETCH_' + self.id + '_LIST');
yield fork(self.index(), query);
}
};
}
show() { show() {
const {api, id} = this; const self = this;
const {api} = this;
return function*(id) { return function*(id) {
try { try {
const result = yield call(api.show, id); const result = yield call(api.show, id);
yield put({ yield put({
type: 'FETCH_' + id + '_ITEM_SUCCESS', type: 'FETCH_' + self.id + '_ITEM_SUCCESS',
result result
}); });
} catch (err) { } catch (err) {
console.log(err); console.log(err);
message.error(err); message.error(err);
yield put({ yield put({
type: 'FETCH_' + id + '_ITEM_FAILED', type: 'FETCH_' + self.id + '_ITEM_FAILED',
err err
}); });
} }
} }
} }
watchShow() {
const self = this;
return function*() {
while (true) {
const {id} = yield take('FETCH_' + self.id + '_ITEM');
yield fork(self.show(), id);
}
}
}
create() { create() {
const {api, id} = this; const {api, id} = this;
return function*(data) { return function*(data) {
...@@ -66,4 +88,191 @@ export default class RESTful { ...@@ -66,4 +88,191 @@ export default class RESTful {
} }
} }
} }
watchCreate() {
const self = this;
return function*() {
while (true) {
const {data} = yield take('CREATE_' + self.id + '_ITEM');
yield fork(self.create(), data);
}
}
}
update() {
const {api, id} = this;
return function*(data) {
try {
yield call(api.update, data);
message.success('修改成功!');
yield put({
type: 'UPDATE_' + id + '_ITEM_SUCCESS',
item: data
});
} catch (err) {
console.log(err);
message.error(err);
yield put({
type: 'UPDATE_' + id + '_ITEM_FAILED',
err
});
}
}
}
watchUpdate() {
const self = this;
return function*() {
while (true) {
yield take('UPDATE_' + self.id);
yield put({
type: 'UPDATE_' + self.id + '_START'
});
const {data} = yield race({
data: take('UPDATE_' + self.id + '_ITEM'),
canceled: take('CANCEL_UPDATE_' + self.id)
});
if (data && data.item) {
yield fork(self.update(), data.item);
}
yield put({
type: 'UPDATE_' + self.id + '_END'
});
}
}
}
delete() {
const self = this;
const {api} = this;
return function*(id) {
try {
const result = yield call(api.show, id);
yield put({
type: 'DELETE_' + self.id + '_ITEM_SUCCESS',
result
});
} catch (err) {
console.log(err);
message.error(err);
yield put({
type: 'DELETE_' + self.id + '_ITEM_FAILED',
err
});
}
}
}
watchDelete() {
const self = this;
return function*() {
while (true) {
const {id} = yield take('DELETE_' + self.id + '_ITEM');
yield fork(self.delete(), id);
}
}
}
patch() {
const {api, id} = this;
return function*(data) {
try {
yield call(api.update, data);
message.success('操作成功!');
yield put({
type: 'PATCH_' + id + '_ITEM_SUCCESS',
item: data
});
} catch (err) {
console.log(err);
message.error(err);
yield put({
type: 'PATCH_' + id + '_ITEM_FAILED',
err
});
}
}
}
watchPatch() {
const self = this;
return function*() {
while (true) {
const {id} = yield take('PATCH_' + self.id + '_ITEM');
yield fork(self.patch(), id);
}
}
}
watch() {
const self = this;
const mask = this.mask;
const tasks = [
self.watchIndex,
self.watchCreate,
//savenull,
self.watchShow,
//editnull,
self.watchUpdate,
self.watchDelete,
self.watchPatch
];
return function*() {
tasks.forEach((task, index)=> {
const mi = 1 << index;
if (task && ((mask & mi ) === mi)) {
yield fork(task());
}
});
}
}
actions() {
const loadingFn = function (state) {
return {...state, loading: true};
};
const failedFn = function (state, action) {
return {...state, loading: false, err: action.err}
};
const editStartFn = function (state) {
return {...state, isEdit: true}
};
const editEndFn = function (state) {
return {...state, isEdit: false};
};
const itemsFn = function (state, action) {
return {...state, loading: false, items: action.items, total: action.total}
};
const itemFn = function (state, action) {
return {...state, loading: false, item: {...state.item, ...action.item}}
};
const id = this.id;
return {
['INDEX_' + id ]: loadingFn,
['INDEX_' + id + '_SUCCESS']: itemsFn,
['INDEX_' + id + '_FAILED']: failedFn,
['SHOW_' + id]: loadingFn,
['SHOW_' + id + '_SUCCESS']: itemFn,
['SHOW_' + id + '_FAILED']: failedFn,
['CREATE_' + id]: loadingFn,
['CREATE_' + id + '_SUCCESS']: itemFn,
['CREATE_' + id + '_FAILED']: failedFn,
['UPDATE_' + id]: loadingFn,
['UPDATE_' + id + '_SUCCESS']: itemFn,
['UPDATE_' + id + '_FAILED']: failedFn,
['ENTER_EDIT' + id]: editStartFn,
['EXIT_EDIT_' + id]: editEndFn,
['DELETE_' + id]: loadingFn,
['DELETE_' + id + '_SUCCESS']: itemFn,
['DELETE_' + id + '_FAILED']: failedFn,
['PATCH_' + id]: loadingFn,
['PATCH_' + id + '_SUCCESS']: itemFn,
['PATCH_' + id + '_FAILED']: failedFn,
}
}
} }
*/
...@@ -5,11 +5,11 @@ import {message} from 'antd'; ...@@ -5,11 +5,11 @@ import {message} from 'antd';
function* getList(query) { function* getList(query) {
try { try {
const {total, announcements} = yield call(fetchList, query); const {total, list} = yield call(fetchList, query);
yield put({ yield put({
type: 'FETCH_ANNOUNCEMENT_LIST_SUCCESS', type: 'FETCH_ANNOUNCEMENT_LIST_SUCCESS',
total, total,
items: announcements items: list
}); });
} catch (err) { } catch (err) {
console.log(err); console.log(err);
......
...@@ -5,11 +5,11 @@ import {message} from 'antd'; ...@@ -5,11 +5,11 @@ import {message} from 'antd';
function* getList(query) { function* getList(query) {
try { try {
const {total, authorities} = yield call(fetchList, query); const {total, list} = yield call(fetchList, query);
yield put({ yield put({
type: 'FETCH_AUTHORITY_LIST_SUCCESS', type: 'FETCH_AUTHORITY_LIST_SUCCESS',
total, total,
items: authorities items: list
}); });
} catch (err) { } catch (err) {
console.log(err); console.log(err);
......
...@@ -5,11 +5,11 @@ import {message} from 'antd'; ...@@ -5,11 +5,11 @@ import {message} from 'antd';
function* getList(query) { function* getList(query) {
try { try {
const {total, customMessageViewDOs} = yield call(fetchList, query); const {total, list} = yield call(fetchList, query);
yield put({ yield put({
type: 'FETCH_MESSAGE_LIST_SUCCESS', type: 'FETCH_MESSAGE_LIST_SUCCESS',
total, total,
items: customMessageViewDOs items: list
}); });
} catch (err) { } catch (err) {
console.log(err); console.log(err);
......
...@@ -5,11 +5,11 @@ import {message} from 'antd'; ...@@ -5,11 +5,11 @@ import {message} from 'antd';
function* getList(query) { function* getList(query) {
try { try {
const {total, items} = yield call(fetchList, query); const {total, list} = yield call(fetchList, query);
yield put({ yield put({
type: 'FETCH_PRODUCT_LIST_SUCCESS', type: 'FETCH_PRODUCT_LIST_SUCCESS',
total, total,
items items:list
}); });
} catch (err) { } catch (err) {
console.log(err); console.log(err);
......
...@@ -7,11 +7,11 @@ import {message} from 'antd'; ...@@ -7,11 +7,11 @@ import {message} from 'antd';
function* getList(query) { function* getList(query) {
try { try {
const {total, audits} = yield call(fetchList, query); const {total, list} = yield call(fetchList, query);
yield put({ yield put({
type: 'FETCH_REMITTANCE_LIST_SUCCESS', type: 'FETCH_REMITTANCE_LIST_SUCCESS',
total, total,
items: audits items: list
}); });
} catch (err) { } catch (err) {
console.log(err); console.log(err);
......
...@@ -5,11 +5,11 @@ import {message} from 'antd'; ...@@ -5,11 +5,11 @@ import {message} from 'antd';
function* getList(query) { function* getList(query) {
try { try {
const {total, resources} = yield call(fetchList, query); const {total, list} = yield call(fetchList, query);
yield put({ yield put({
type: 'FETCH_RESOURCE_LIST_SUCCESS', type: 'FETCH_RESOURCE_LIST_SUCCESS',
total, total,
items: resources items: list
}); });
} catch (err) { } catch (err) {
console.log(err); console.log(err);
......
...@@ -5,11 +5,11 @@ import {message} from 'antd'; ...@@ -5,11 +5,11 @@ import {message} from 'antd';
function* getList(query) { function* getList(query) {
try { try {
const {total, trades} = yield call(fetchList, query); const {total, list} = yield call(fetchList, query);
yield put({ yield put({
type: 'FETCH_TRADE_LIST_SUCCESS', type: 'FETCH_TRADE_LIST_SUCCESS',
total, total,
items: trades items: list
}); });
} catch (err) { } catch (err) {
console.log(err); console.log(err);
......
...@@ -45,10 +45,10 @@ function* watchAddItem() { ...@@ -45,10 +45,10 @@ function* watchAddItem() {
function* getList(query) { function* getList(query) {
try { try {
const {users, total} = yield call(fetchList, query); const {list, total} = yield call(fetchList, query);
yield put({ yield put({
type: 'FETCH_USER_LIST_SUCCESS', type: 'FETCH_USER_LIST_SUCCESS',
items: users, items: list,
total total
}); });
} catch (err) { } catch (err) {
......
...@@ -5,11 +5,11 @@ import {message} from 'antd'; ...@@ -5,11 +5,11 @@ import {message} from 'antd';
function* getList(query) { function* getList(query) {
try { try {
const {total, audits} = yield call(fetchList, query); const {total, list} = yield call(fetchList, query);
yield put({ yield put({
type: 'FETCH_WITHDRAW_LIST_SUCCESS', type: 'FETCH_WITHDRAW_LIST_SUCCESS',
total, total,
items: audits items: list
}); });
} catch (err) { } catch (err) {
console.log(err); console.log(err);
......
...@@ -2,7 +2,7 @@ import xFetch from '../xFetch'; ...@@ -2,7 +2,7 @@ import xFetch from '../xFetch';
import {serialize} from '../../utils'; import {serialize} from '../../utils';
export async function fetchList(query) { export async function fetchList(query) {
return xFetch('/api/admin/authorities' + '?' +serialize(query)); return xFetch('/api/admin/authorities' + '?' + serialize({s:30, ...query}));
} }
export async function fetchItem(id) { export async function fetchItem(id) {
......
...@@ -2,7 +2,7 @@ import xFetch from '../xFetch'; ...@@ -2,7 +2,7 @@ import xFetch from '../xFetch';
import {serialize} from '../../utils'; import {serialize} from '../../utils';
export async function fetchList(query) { export async function fetchList(query) {
return xFetch('/api/admin/resources' + '?' +serialize(query)); return xFetch('/api/admin/resources' + '?' + serialize({s:30, ...query}));
} }
export async function fetchItem(id) { export async function fetchItem(id) {
......
...@@ -4,7 +4,7 @@ import {serialize} from '../utils'; ...@@ -4,7 +4,7 @@ import {serialize} from '../utils';
export async function fetchList(query) { export async function fetchList(query) {
const data = {...query}; const data = {...query};
delete data.title; delete data.title;
return xFetch('/api/announcements' + '?' + serialize(data)); return xFetch('/api/announcements' + '?' + serialize({s:30, ...data}));
} }
export async function fetchItem(id) { export async function fetchItem(id) {
......
...@@ -2,8 +2,7 @@ import xFetch from './xFetch'; ...@@ -2,8 +2,7 @@ import xFetch from './xFetch';
import {serialize} from '../utils'; import {serialize} from '../utils';
export async function fetchList(query) { export async function fetchList(query) {
const data = {...query}; return xFetch('/api/customMessages' + '?' +serialize({s:30, ...query}));
return xFetch('/api/customMessages' + '?' + serialize(data));
} }
export async function fetchItem(id) { export async function fetchItem(id) {
......
...@@ -2,7 +2,7 @@ import xFetch from './xFetch'; ...@@ -2,7 +2,7 @@ import xFetch from './xFetch';
import {serialize} from '../utils'; import {serialize} from '../utils';
export async function fetchList(query) { export async function fetchList(query) {
return xFetch('/api/products' + '?' + serialize(query)); return xFetch('/api/products' + '?' + serialize({s:30, ...query}));
} }
export async function fetchCates() { export async function fetchCates() {
......
...@@ -2,7 +2,7 @@ import xFetch from './xFetch'; ...@@ -2,7 +2,7 @@ import xFetch from './xFetch';
import {serialize} from '../utils'; import {serialize} from '../utils';
export async function fetchList(query) { export async function fetchList(query) {
return xFetch('/api/remittance/audits' + '?' + serialize(query)); return xFetch('/api/remittance/audits' + '?' + serialize({s:30, ...query}));
} }
export async function fetchItem(id) { export async function fetchItem(id) {
return xFetch('/api/remittance/audits/' + id); return xFetch('/api/remittance/audits/' + id);
......
...@@ -2,7 +2,7 @@ import xFetch from './xFetch'; ...@@ -2,7 +2,7 @@ import xFetch from './xFetch';
import {serialize} from '../utils'; import {serialize} from '../utils';
export async function fetchList(query) { export async function fetchList(query) {
return xFetch('/api/trades' + '?' + serialize(query)); return xFetch('/api/trades' + '?' + serialize({s:30, ...query}));
} }
export async function fetchItem(id) { export async function fetchItem(id) {
return xFetch('/api/trades/' + id); return xFetch('/api/trades/' + id);
......
...@@ -16,7 +16,7 @@ export async function create(data) { ...@@ -16,7 +16,7 @@ export async function create(data) {
} }
export async function fetchList(query) { export async function fetchList(query) {
return xFetch('/api/admin/users' + '?' + serialize(query)); return xFetch('/api/admin/users' + '?' + serialize({s:30, ...query}));
} }
export async function fetchItem(id) { export async function fetchItem(id) {
......
...@@ -2,7 +2,7 @@ import xFetch from './xFetch'; ...@@ -2,7 +2,7 @@ import xFetch from './xFetch';
import {serialize} from '../utils'; import {serialize} from '../utils';
export async function fetchList(query) { export async function fetchList(query) {
return xFetch('/api/withdraw/audits' + '?' + serialize(query)); return xFetch('/api/withdraw/audits' + '?' + serialize({s:30, ...query}));
} }
export async function fetchItem(id) { export async function fetchItem(id) {
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
export const NULL = '_____?_____'; export const NULL = '_____?_____';
export const FILE_UPLOAD = {action: '/api/fileUpload'};
export function serialize(obj, prefix) { export function serialize(obj, prefix) {
if (obj) { if (obj) {
var str = []; var str = [];
...@@ -259,13 +261,32 @@ export function cr2br(text) { ...@@ -259,13 +261,32 @@ export function cr2br(text) {
} }
export const ACTIONPERMISSION = {
index: 1 << 0,
create: 1 << 1,
save: 1 << 2, export function resourceActions(mask) {
show: 1 << 3, return resourceActions.enum.reduce((arr, action, index)=> {
edit: 1 << 4, const value = 1 << index;
update: 1 << 5, if ((mask & value) === value) {
'delete': 1 << 6, arr.push({title: action, mask: value});
patch: 1 << 7 }
return arr;
}, []);
}
resourceActions.enum = ['列表index', '创建create', 'save', '详情show', 'edit', '编辑update', '删除delete', '审核patch'];
export const ENABLE_STATUS = {
1: '系统',
5: '禁用',
9: '启用'
}; };
export function enableStatusToString(status) {
return ENABLE_STATUS[status] || '未定义('+ status+')';
}
export const ENABLE_STATUS_LIST = Object.keys(ENABLE_STATUS).map(key=> {
return {value: key, text: ENABLE_STATUS[key]}
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment