提交 3f682937da1e153cb910411bb1fe571c2e8c1bf2

作者 愚道
1 个父辈 109e71ef

improve cardlist block code

@@ -14,11 +14,6 @@ @@ -14,11 +14,6 @@
14 "ant-design-pro": "^2.1.1", 14 "ant-design-pro": "^2.1.1",
15 "antd": "^3.10.9", 15 "antd": "^3.10.9",
16 "dva": "^2.4.0", 16 "dva": "^2.4.0",
17 - "hash.js": "^1.1.5",  
18 - "mockjs": "*",  
19 - "moment": "^2.22.2",  
20 - "nzh": "^1.0.3",  
21 - "qs": "^6.6.0",  
22 "react": "^16.6.3", 17 "react": "^16.6.3",
23 "umi-request": "^1.0.0" 18 "umi-request": "^1.0.0"
24 }, 19 },
1 -let sourceData;  
2 -  
3 const titles = [ 1 const titles = [
4 'Alipay', 2 'Alipay',
5 'Angular', 3 'Angular',
@@ -21,19 +19,6 @@ const avatars = [ @@ -21,19 +19,6 @@ const avatars = [
21 'https://gw.alipayobjects.com/zos/rmsportal/nxkuOJlFJuAUhzlMTCEe.png', // Webpack 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 const covers = [ 22 const covers = [
38 'https://gw.alipayobjects.com/zos/rmsportal/uMfMFlvUuceEyPpotzlq.png', 23 'https://gw.alipayobjects.com/zos/rmsportal/uMfMFlvUuceEyPpotzlq.png',
39 'https://gw.alipayobjects.com/zos/rmsportal/iZBVOIhGJiAnhplqjvZW.png', 24 'https://gw.alipayobjects.com/zos/rmsportal/iZBVOIhGJiAnhplqjvZW.png',
@@ -114,43 +99,9 @@ function getFakeList(req, res) { @@ -114,43 +99,9 @@ function getFakeList(req, res) {
114 const count = params.count * 1 || 20; 99 const count = params.count * 1 || 20;
115 100
116 const result = fakeList(count); 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 return res.json(result); 102 return res.json(result);
151 } 103 }
152 104
153 export default { 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 };
@@ -7,15 +7,15 @@ import PageHeaderWrapper from './components/PageHeaderWrapper'; @@ -7,15 +7,15 @@ import PageHeaderWrapper from './components/PageHeaderWrapper';
7 7
8 import styles from './style.less'; 8 import styles from './style.less';
9 9
10 -@connect(({ list, loading }) => ({  
11 - list, 10 +@connect(({ BLOCK_NAME, loading }) => ({
  11 + BLOCK_NAME,
12 loading: loading.models.list, 12 loading: loading.models.list,
13 })) 13 }))
14 -class CardList extends PureComponent { 14 +class PAGE_NAME_UPPER_CAMEL_CASE extends PureComponent {
15 componentDidMount() { 15 componentDidMount() {
16 const { dispatch } = this.props; 16 const { dispatch } = this.props;
17 dispatch({ 17 dispatch({
18 - type: 'list/fetch', 18 + type: 'BLOCK_NAME/fetch',
19 payload: { 19 payload: {
20 count: 8, 20 count: 8,
21 }, 21 },
@@ -24,7 +24,7 @@ class CardList extends PureComponent { @@ -24,7 +24,7 @@ class CardList extends PureComponent {
24 24
25 render() { 25 render() {
26 const { 26 const {
27 - list: { list }, 27 + BLOCK_NAME: { list },
28 loading, 28 loading,
29 } = this.props; 29 } = this.props;
30 30
@@ -98,4 +98,4 @@ class CardList extends PureComponent { @@ -98,4 +98,4 @@ class CardList extends PureComponent {
98 } 98 }
99 } 99 }
100 100
101 -export default CardList; 101 +export default PAGE_NAME_UPPER_CAMEL_CASE;
1 -import { queryFakeList, removeFakeList, addFakeList, updateFakeList } from './service'; 1 +import { queryFakeList } from './service';
2 2
3 export default { 3 export default {
4 - namespace: 'list', 4 + namespace: 'BLOCK_NAME',
5 5
6 state: { 6 state: {
7 list: [], 7 list: [],
@@ -15,26 +15,6 @@ export default { @@ -15,26 +15,6 @@ export default {
15 payload: Array.isArray(response) ? response : [], 15 payload: Array.isArray(response) ? response : [],
16 }); 16 });
17 }, 17 },
18 - *appendFetch({ payload }, { call, put }) {  
19 - const response = yield call(queryFakeList, payload);  
20 - yield put({  
21 - type: 'appendList',  
22 - payload: Array.isArray(response) ? response : [],  
23 - });  
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 }, 18 },
39 19
40 reducers: { 20 reducers: {
@@ -44,11 +24,5 @@ export default { @@ -44,11 +24,5 @@ export default {
44 list: action.payload, 24 list: action.payload,
45 }; 25 };
46 }, 26 },
47 - appendList(state, action) {  
48 - return {  
49 - ...state,  
50 - list: state.list.concat(action.payload),  
51 - };  
52 - },  
53 }, 27 },
54 }; 28 };
1 import request from 'umi-request'; 1 import request from 'umi-request';
2 2
3 export async function queryFakeList(params) { 3 export async function queryFakeList(params) {
4 - return request(`/api/fake_list`, { 4 + return request(`/api/BLOCK_NAME/fake_list`, {
5 params, 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 -}  
1 @import '~antd/lib/style/themes/default.less'; 1 @import '~antd/lib/style/themes/default.less';
2 -@import '~@/utils/utils.less'; 2 +@import './utils/utils.less';
3 3
4 .cardList { 4 .cardList {
5 margin-bottom: -24px; 5 margin-bottom: -24px;
注册登录 后发表评论