正在显示
9 个修改的文件
包含
13 行增加
和
112 行删除
| 1 | -let sourceData; | |
| 2 | - | |
| 3 | 1 | const titles = [ |
| 4 | 2 | 'Alipay', |
| 5 | 3 | 'Angular', |
| ... | ... | @@ -21,19 +19,6 @@ const avatars = [ |
| 21 | 19 | 'https://gw.alipayobjects.com/zos/rmsportal/nxkuOJlFJuAUhzlMTCEe.png', // Webpack |
| 22 | 20 | ]; |
| 23 | 21 | |
| 24 | -const avatars2 = [ | |
| 25 | - 'https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png', | |
| 26 | - 'https://gw.alipayobjects.com/zos/rmsportal/cnrhVkzwxjPwAaCfPbdc.png', | |
| 27 | - 'https://gw.alipayobjects.com/zos/rmsportal/gaOngJwsRYRaVAuXXcmB.png', | |
| 28 | - 'https://gw.alipayobjects.com/zos/rmsportal/ubnKSIfAJTxIgXOKlciN.png', | |
| 29 | - 'https://gw.alipayobjects.com/zos/rmsportal/WhxKECPNujWoWEFNdnJE.png', | |
| 30 | - 'https://gw.alipayobjects.com/zos/rmsportal/jZUIxmJycoymBprLOUbT.png', | |
| 31 | - 'https://gw.alipayobjects.com/zos/rmsportal/psOgztMplJMGpVEqfcgF.png', | |
| 32 | - 'https://gw.alipayobjects.com/zos/rmsportal/ZpBqSxLxVEXfcUNoPKrz.png', | |
| 33 | - 'https://gw.alipayobjects.com/zos/rmsportal/laiEnJdGHVOhJrUShBaJ.png', | |
| 34 | - 'https://gw.alipayobjects.com/zos/rmsportal/UrQsqscbKEpNuJcvBZBu.png', | |
| 35 | -]; | |
| 36 | - | |
| 37 | 22 | const covers = [ |
| 38 | 23 | 'https://gw.alipayobjects.com/zos/rmsportal/uMfMFlvUuceEyPpotzlq.png', |
| 39 | 24 | 'https://gw.alipayobjects.com/zos/rmsportal/iZBVOIhGJiAnhplqjvZW.png', |
| ... | ... | @@ -114,43 +99,9 @@ function getFakeList(req, res) { |
| 114 | 99 | const count = params.count * 1 || 20; |
| 115 | 100 | |
| 116 | 101 | const result = fakeList(count); |
| 117 | - sourceData = result; | |
| 118 | - return res.json(result); | |
| 119 | -} | |
| 120 | - | |
| 121 | -function postFakeList(req, res) { | |
| 122 | - const { /* url = '', */ body } = req; | |
| 123 | - // const params = getUrlParams(url); | |
| 124 | - const { method, id } = body; | |
| 125 | - // const count = (params.count * 1) || 20; | |
| 126 | - let result = sourceData; | |
| 127 | - | |
| 128 | - switch (method) { | |
| 129 | - case 'delete': | |
| 130 | - result = result.filter(item => item.id !== id); | |
| 131 | - break; | |
| 132 | - case 'update': | |
| 133 | - result.forEach((item, i) => { | |
| 134 | - if (item.id === id) { | |
| 135 | - result[i] = Object.assign(item, body); | |
| 136 | - } | |
| 137 | - }); | |
| 138 | - break; | |
| 139 | - case 'post': | |
| 140 | - result.unshift({ | |
| 141 | - body, | |
| 142 | - id: `fake-list-${result.length}`, | |
| 143 | - createdAt: new Date().getTime(), | |
| 144 | - }); | |
| 145 | - break; | |
| 146 | - default: | |
| 147 | - break; | |
| 148 | - } | |
| 149 | - | |
| 150 | 102 | return res.json(result); |
| 151 | 103 | } |
| 152 | 104 | |
| 153 | 105 | export default { |
| 154 | - 'GET /api/fake_list': getFakeList, | |
| 155 | - 'POST /api/fake_list': postFakeList, | |
| 106 | + 'GET /api/BLOCK_NAME/fake_list': getFakeList, | |
| 156 | 107 | }; | ... | ... |
| ... | ... | @@ -3,8 +3,8 @@ import { connect } from 'dva'; |
| 3 | 3 | import { Form, Card, Select, List, Tag, Icon, Row, Col, Button } from 'antd'; |
| 4 | 4 | |
| 5 | 5 | import TagSelect from 'ant-design-pro/lib/TagSelect'; |
| 6 | -import StandardFormRow from '@/components/StandardFormRow'; | |
| 7 | -import ArticleListContent from '@/components/ArticleListContent'; | |
| 6 | +import StandardFormRow from './components/StandardFormRow'; | |
| 7 | +import ArticleListContent from './components/ArticleListContent'; | |
| 8 | 8 | import styles from './style.less'; |
| 9 | 9 | |
| 10 | 10 | const { Option } = Select; |
| ... | ... | @@ -12,9 +12,9 @@ const FormItem = Form.Item; |
| 12 | 12 | |
| 13 | 13 | const pageSize = 5; |
| 14 | 14 | |
| 15 | -@connect(({ list, loading }) => ({ | |
| 16 | - list, | |
| 17 | - loading: loading.models.list, | |
| 15 | +@connect(({ BLOCK_NAME, loading }) => ({ | |
| 16 | + BLOCK_NAME, | |
| 17 | + loading: loading.models.BLOCK_NAME, | |
| 18 | 18 | })) |
| 19 | 19 | @Form.create({ |
| 20 | 20 | onValuesChange({ dispatch }, changedValues, allValues) { |
| ... | ... | @@ -23,7 +23,7 @@ const pageSize = 5; |
| 23 | 23 | console.log(changedValues, allValues); |
| 24 | 24 | // 模拟查询表单生效 |
| 25 | 25 | dispatch({ |
| 26 | - type: 'list/fetch', | |
| 26 | + type: 'BLOCK_NAME/fetch', | |
| 27 | 27 | payload: { |
| 28 | 28 | count: 5, |
| 29 | 29 | }, |
| ... | ... | @@ -34,7 +34,7 @@ class SearchList extends Component { |
| 34 | 34 | componentDidMount() { |
| 35 | 35 | const { dispatch } = this.props; |
| 36 | 36 | dispatch({ |
| 37 | - type: 'list/fetch', | |
| 37 | + type: 'BLOCK_NAME/fetch', | |
| 38 | 38 | payload: { |
| 39 | 39 | count: 5, |
| 40 | 40 | }, |
| ... | ... | @@ -51,7 +51,7 @@ class SearchList extends Component { |
| 51 | 51 | fetchMore = () => { |
| 52 | 52 | const { dispatch } = this.props; |
| 53 | 53 | dispatch({ |
| 54 | - type: 'list/appendFetch', | |
| 54 | + type: 'BLOCK_NAME/appendFetch', | |
| 55 | 55 | payload: { |
| 56 | 56 | count: pageSize, |
| 57 | 57 | }, |
| ... | ... | @@ -61,7 +61,7 @@ class SearchList extends Component { |
| 61 | 61 | render() { |
| 62 | 62 | const { |
| 63 | 63 | form, |
| 64 | - list: { list }, | |
| 64 | + BLOCK_NAME: { list }, | |
| 65 | 65 | loading, |
| 66 | 66 | } = this.props; |
| 67 | 67 | const { getFieldDecorator } = form; | ... | ... |
| 1 | -import { queryFakeList, removeFakeList, addFakeList, updateFakeList } from './service'; | |
| 1 | +import { queryFakeList } from './service'; | |
| 2 | 2 | |
| 3 | 3 | export default { |
| 4 | - namespace: 'list', | |
| 4 | + namespace: 'BLOCK_NAME', | |
| 5 | 5 | |
| 6 | 6 | state: { |
| 7 | 7 | list: [], |
| ... | ... | @@ -22,19 +22,6 @@ export default { |
| 22 | 22 | payload: Array.isArray(response) ? response : [], |
| 23 | 23 | }); |
| 24 | 24 | }, |
| 25 | - *submit({ payload }, { call, put }) { | |
| 26 | - let callback; | |
| 27 | - if (payload.id) { | |
| 28 | - callback = Object.keys(payload).length === 1 ? removeFakeList : updateFakeList; | |
| 29 | - } else { | |
| 30 | - callback = addFakeList; | |
| 31 | - } | |
| 32 | - const response = yield call(callback, payload); // post | |
| 33 | - yield put({ | |
| 34 | - type: 'queryList', | |
| 35 | - payload: response, | |
| 36 | - }); | |
| 37 | - }, | |
| 38 | 25 | }, |
| 39 | 26 | |
| 40 | 27 | reducers: { | ... | ... |
| 1 | 1 | import request from 'umi-request'; |
| 2 | 2 | |
| 3 | 3 | export async function queryFakeList(params) { |
| 4 | - return request(`/api/fake_list`, { | |
| 4 | + return request(`/api/BLOCK_NAME/fake_list`, { | |
| 5 | 5 | params, |
| 6 | 6 | }); |
| 7 | 7 | } |
| 8 | - | |
| 9 | -export async function removeFakeList(params) { | |
| 10 | - const { count = 5, ...restParams } = params; | |
| 11 | - return request(`/api/fake_list?count=${count}`, { | |
| 12 | - method: 'POST', | |
| 13 | - body: { | |
| 14 | - ...restParams, | |
| 15 | - method: 'delete', | |
| 16 | - }, | |
| 17 | - }); | |
| 18 | -} | |
| 19 | - | |
| 20 | -export async function addFakeList(params) { | |
| 21 | - const { count = 5, ...restParams } = params; | |
| 22 | - return request(`/api/fake_list?count=${count}`, { | |
| 23 | - method: 'POST', | |
| 24 | - body: { | |
| 25 | - ...restParams, | |
| 26 | - method: 'post', | |
| 27 | - }, | |
| 28 | - }); | |
| 29 | -} | |
| 30 | - | |
| 31 | -export async function updateFakeList(params) { | |
| 32 | - const { count = 5, ...restParams } = params; | |
| 33 | - return request(`/api/fake_list?count=${count}`, { | |
| 34 | - method: 'POST', | |
| 35 | - body: { | |
| 36 | - ...restParams, | |
| 37 | - method: 'update', | |
| 38 | - }, | |
| 39 | - }); | |
| 40 | -} | ... | ... |
请
注册
或
登录
后发表评论