张延森 5 år sedan
förälder
incheckning
ac60e393b8

+ 1
- 0
package.json Visa fil

@@ -43,6 +43,7 @@
43 43
   "dependencies": {
44 44
     "@ant-design/pro-layout": "^4.5.9",
45 45
     "@antv/data-set": "^0.10.2",
46
+    "@zjxpcyc/xrc-form2": "^2.2.1",
46 47
     "ant": "^0.2.0",
47 48
     "antd": "^3.26.0",
48 49
     "classnames": "^2.2.6",

src/layouts/SearchList/BodyBodyPagination.jsx → src/layouts/SearchList/BodyPagination.jsx Visa fil

@@ -6,7 +6,7 @@ import Style from './style.less'
6 6
 
7 7
 export default class BodyPagination extends PureComponent {
8 8
   static propTypes = {
9
-    storage: PropTypes.func,
9
+    storage: PropTypes.object,
10 10
     onChange: PropTypes.func,
11 11
     configs: PropTypes.object,
12 12
   }

+ 2
- 2
src/layouts/SearchList/SearchBody.jsx Visa fil

@@ -6,7 +6,7 @@ import { isFunction } from './utils'
6 6
 
7 7
 export default class SearchBody extends PureComponent {
8 8
   static propTypes = {
9
-    storage: PropTypes.func,
9
+    storage: PropTypes.object,
10 10
     dataSource: PropTypes.array,
11 11
     configs: PropTypes.object,
12 12
   }
@@ -22,7 +22,7 @@ export default class SearchBody extends PureComponent {
22 22
     }
23 23
 
24 24
     return (
25
-      <Table dataSource={dataSource} {...leftProps} />
25
+      <Table pagination={false} dataSource={dataSource} {...leftProps} />
26 26
     )
27 27
   }
28 28
 }

+ 24
- 3
src/layouts/SearchList/SearchForm.jsx Visa fil

@@ -1,11 +1,32 @@
1 1
 import React, { PureComponent } from 'react'
2
+import PropTypes from 'prop-types'
3
+import createForm from '@zjxpcyc/xrc-form2'
4
+
5
+const Form = createForm()
2 6
 
3 7
 export default class SearchForm extends PureComponent {
8
+  static propTypes = {
9
+    storage: PropTypes.object,
10
+    onSubmit: PropTypes.func,
11
+    configs: PropTypes.object,
12
+  }
13
+
14
+  form = null
15
+  storage = this.props.storage
16
+
17
+  componentDidMount() {
18
+    const conditions = this.storage.get('form.values')
19
+
20
+    if (this.form && conditions) {
21
+      this.form.setFieldsValue(conditions)
22
+    }
23
+  }
24
+
4 25
   render() {
26
+    const { fields, ...leftProps } = this.props.configs || {}
27
+
5 28
     return (
6
-      <div>
7
-        
8
-      </div>
29
+      <Form wrappedComponentRef={f => this.form = f} layout="inline" fields={fields} onSubmit={this.props.onSubmit} {...leftProps} />
9 30
     )
10 31
   }
11 32
 }

+ 24
- 9
src/layouts/SearchList/index.jsx Visa fil

@@ -6,22 +6,23 @@ import { notification } from 'antd'
6 6
 import SearchForm from './SearchForm'
7 7
 import SearchBody from './SearchBody'
8 8
 import BodyHeader from './BodyHeader'
9
-import BodyPagination from './BodyBodyPaginationation'
9
+import BodyPagination from './BodyPagination'
10 10
 import { getStorageBuilder } from './utils'
11 11
 import Style from './style.less'
12 12
 
13 13
 class SearchList extends React.PureComponent {
14 14
   static propTypes = {
15
-    title: PropTypes.element,
16
-    actions: PropTypes.element,
15
+    storage: PropTypes.object,
16
+    title: PropTypes.any,
17
+    actions: PropTypes.any,
17 18
     search: PropTypes.object,
18 19
     body: PropTypes.object,
19 20
     pagination: PropTypes.object,
21
+    service: PropTypes.func,
20 22
   }
21 23
 
22
-  storage = getStorageBuilder(window.Math.random().toString(36).substr(2))
23
-
24 24
   state = {
25
+    defaultStorage: getStorageBuilder(window.Math.random().toString(36).substr(2)),
25 26
     dataSource: [],
26 27
     conditions: {},
27 28
     pageConfig: {
@@ -36,7 +37,7 @@ class SearchList extends React.PureComponent {
36 37
       (state) => ({
37 38
         ...state,
38 39
         pageConfig: {
39
-          ...pageConfig,
40
+          ...state.pageConfig,
40 41
           current: page,
41 42
           pageSize,
42 43
         }
@@ -77,7 +78,7 @@ class SearchList extends React.PureComponent {
77 78
           ...state,
78 79
           dataSource,
79 80
           pageConfig: {
80
-            ...pageConfig,
81
+            ...state.pageConfig,
81 82
             total: pageParams[keyOfTotalSize],
82 83
           },
83 84
         }))
@@ -87,12 +88,12 @@ class SearchList extends React.PureComponent {
87 88
     }
88 89
   }
89 90
 
90
-  render() {    
91
+  render() {
91 92
     const {
92 93
       keyOfPageNumber,
93 94
       keyOfPageSize,
94 95
       keyOfTotalSize,
95
-      ...leftPageParams,
96
+      ...leftPageParams
96 97
     } = this.props.pagination || {}
97 98
 
98 99
     const pageConfig = {
@@ -100,6 +101,8 @@ class SearchList extends React.PureComponent {
100 101
       ...this.state.pageConfig,
101 102
     }
102 103
 
104
+    const storage = this.props.storage || this.state.defaultStorage
105
+
103 106
     return (
104 107
       <div className={Style['search-list']}>
105 108
         <div className={Style['head']}>
@@ -114,3 +117,15 @@ class SearchList extends React.PureComponent {
114 117
     )
115 118
   }
116 119
 }
120
+
121
+function withSearchList (configs = {}) {
122
+  const cacheKey = `${configs.name || 'SearchList'}-${window.Math.random().toString(36).substr(2)}`
123
+  const storage = getStorageBuilder(cacheKey)
124
+
125
+  return React.forwardRef((props, ref) => {
126
+    return <SearchList storage={storage} {...props} ref={ref} />
127
+  })
128
+}
129
+
130
+export default SearchList;
131
+export { withSearchList }

+ 159
- 0
src/pages/news/type/NewsType copy.jsx Visa fil

@@ -0,0 +1,159 @@
1
+import React, { useState, useEffect } from 'react';
2
+import { Form, Input, Button, Icon, Select, message, Table, Divider, Tag, Pagination, Modal,Breadcrumb } from 'antd';
3
+import { FormattedMessage } from 'umi-plugin-react/locale';
4
+import styles from '../../style/GoodsList.less';
5
+import router from 'umi/router';
6
+import BuildSelect from '../../../components/SelectButton/BuildSelect';
7
+import AuthButton from '@/components/AuthButton';
8
+import apis from '../../../services/apis';
9
+import request from '../../../utils/request'
10
+
11
+const { Option } = Select;
12
+
13
+
14
+function header(props) {
15
+  // 获取初始化数据
16
+  const [ data, setData ] = useState({})
17
+
18
+  useEffect(() => {
19
+    getList({ pageNum: 1, pageSize: 10 });
20
+  },[])
21
+
22
+  // 查询列表
23
+  const getList = (params) => {
24
+    request({ ...apis.newsType.list, params: { ...params } }).then((data) => {
25
+        console.log(data)
26
+        setData(data)
27
+    })
28
+  }
29
+
30
+  
31
+  // 提交事件
32
+  const handleSubmit = (e, props) => {
33
+    e.preventDefault();
34
+    props.form.validateFields((err, values) => {
35
+      if (!err) {
36
+        getList({ pageNum: 1, pageSize: 10, ...values })
37
+      }
38
+    });
39
+  }
40
+
41
+  const changePageNum = (pageNumber) => {
42
+    props.form.validateFields((err, values) => {
43
+      if (!err) {
44
+        getList({ pageNum: pageNumber, pageSize: 10, ...values })
45
+      }
46
+    });
47
+  }
48
+
49
+
50
+  // 跳转到编辑资讯
51
+  const toEditNews = (id) => () => {
52
+    router.push({
53
+      pathname: '/news/type/editNews',
54
+      query: {
55
+        id
56
+      },
57
+    });
58
+  }
59
+
60
+  
61
+  const changeNewsStatus = (row, newsId) => () => {
62
+    Modal.confirm({
63
+      title: '确认删除?',
64
+      okText: '确认',
65
+      cancelText: '取消',
66
+      onOk() {
67
+
68
+        request({ ...apis.newsType.put, urlData: { id: newsId }, data: { ...row, status: -1 } }).then((data) => {
69
+          message.info('操作成功!')
70
+          getList({ pageNum: 1, pageSize: 10 });
71
+        }).catch((err) => {
72
+          console.log(err)
73
+          message.info(err.msg || err.message)
74
+        })
75
+
76
+      }
77
+    });
78
+  }
79
+  /**
80
+   *
81
+   *
82
+   * @param {*} props
83
+   * @returns
84
+   */
85
+  const columns = [
86
+    {
87
+      title: '类型图',
88
+      dataIndex: 'newsTypeImg',
89
+      key: 'newsTypeImg',
90
+      align: 'center',
91
+      render: (text, record) => <img src={record.newsTypeImg} style={{ width: '165px',height: '104px' }} className={styles.touxiang} />,
92
+    },
93
+    {
94
+      title: '名称',
95
+      dataIndex: 'newsTypeName',
96
+      key: 'newsTypeName',
97
+      align: 'center',
98
+
99
+    },
100
+    {
101
+      title: '操作',
102
+      dataIndex: 'handle',
103
+      key: 'handle',
104
+      align: 'center',
105
+      render: (x, row) => (
106
+        <>
107
+          <AuthButton name="admin.taNewsType.id.delete" noRight={null}>
108
+            <span style={{ color: '#EF273A', marginRight: '20px', cursor: 'pointer' }} onClick={changeNewsStatus(row, row.newsTypeId)}>
109
+              {row.status == 1 ? '删除' : '上架'}<Icon type="shopping-cart" className={styles.shoppingCart} />
110
+            </span>
111
+          </AuthButton>
112
+          <AuthButton name="admin.taNewsType.id.put" noRight={null}>
113
+            <span style={{ color: '#FF925C', cursor: 'pointer' }} onClick={toEditNews(row.newsTypeId)}>
114
+              编辑<Icon type="form" className={styles.edit} />
115
+            </span>
116
+          </AuthButton>
117
+        </>
118
+      ),
119
+    },
120
+  ];
121
+  function handleReset() {
122
+    props.form.resetFields();
123
+    getList({ pageNum: 1, pageSize: 10 })
124
+  }
125
+
126
+  const { getFieldDecorator } = props.form
127
+  return (
128
+
129
+    <>
130
+      <Form layout="inline" onSubmit={e => handleSubmit(e, props)}>
131
+        <Form.Item>
132
+          {getFieldDecorator('buildingId')(
133
+            <BuildSelect />,
134
+          )}
135
+        </Form.Item>
136
+        <Form.Item>
137
+            <AuthButton name="admin.taNewsType.search" noRight={null}>
138
+              <Button type="primary" htmlType="submit" >
139
+                查询
140
+              </Button>
141
+            </AuthButton>
142
+            <Button style={{ marginLeft: 8 }} onClick={handleReset}>
143
+              重置
144
+            </Button>
145
+        </Form.Item>
146
+      </Form>
147
+      <AuthButton name="admin.taNewsType.post" noRight={null}>
148
+        <Button type="danger" className={styles.addBtn} onClick={toEditNews()}>新增</Button>
149
+      </AuthButton>
150
+      <Table rowKey="newsType" dataSource={data.records} columns={columns} pagination={false} />
151
+      <div style={{ display: 'flex', justifyContent: 'flex-end', marginTop: '30px' }}>
152
+        <Pagination showQuickJumper defaultCurrent={1} total={data.total} onChange={changePageNum} current={data.current}/>
153
+      </div>
154
+    </>
155
+  )
156
+}
157
+const WrappedHeader = Form.create({ name: 'header' })(header);
158
+
159
+export default WrappedHeader

+ 177
- 108
src/pages/news/type/NewsType.jsx Visa fil

@@ -5,83 +5,22 @@ import styles from '../../style/GoodsList.less';
5 5
 import router from 'umi/router';
6 6
 import BuildSelect from '../../../components/SelectButton/BuildSelect';
7 7
 import AuthButton from '@/components/AuthButton';
8
-import apis from '../../../services/apis';
9
-import request from '../../../utils/request'
8
+// import apis from '../../../services/apis';
9
+import { fetchList, apis } from '../../../utils/request'
10
+import { withSearchList } from '@/layouts/SearchList'
10 11
 
11 12
 const { Option } = Select;
13
+const SearchList = withSearchList()
14
+const getNewsTypeList = fetchList(apis.newsType.list)
12 15
 
13
-
14
-function header(props) {
15
-  // 获取初始化数据
16
-  const [ data, setData ] = useState({})
17
-
18
-  useEffect(() => {
19
-    getList({ pageNum: 1, pageSize: 10 });
20
-  },[])
21
-
22
-  // 查询列表
23
-  const getList = (params) => {
24
-    request({ ...apis.newsType.list, params: { ...params } }).then((data) => {
25
-        console.log(data)
26
-        setData(data)
27
-    })
28
-  }
29
-
30
-  
31
-  // 提交事件
32
-  const handleSubmit = (e, props) => {
33
-    e.preventDefault();
34
-    props.form.validateFields((err, values) => {
35
-      if (!err) {
36
-        getList({ pageNum: 1, pageSize: 10, ...values })
37
-      }
38
-    });
39
-  }
40
-
41
-  const changePageNum = (pageNumber) => {
42
-    props.form.validateFields((err, values) => {
43
-      if (!err) {
44
-        getList({ pageNum: pageNumber, pageSize: 10, ...values })
45
-      }
46
-    });
47
-  }
48
-
49
-
50
-  // 跳转到编辑资讯
51
-  const toEditNews = (id) => () => {
52
-    router.push({
53
-      pathname: '/news/type/editNews',
54
-      query: {
55
-        id
56
-      },
57
-    });
58
-  }
59
-
16
+export default function NewsType(props) {
17
+  const conditions = [
18
+    {
19
+      name: 'buildingId',
20
+      node: BuildSelect,
21
+    }
22
+  ]
60 23
   
61
-  const changeNewsStatus = (row, newsId) => () => {
62
-    Modal.confirm({
63
-      title: '确认删除?',
64
-      okText: '确认',
65
-      cancelText: '取消',
66
-      onOk() {
67
-
68
-        request({ ...apis.newsType.put, urlData: { id: newsId }, data: { ...row, status: -1 } }).then((data) => {
69
-          message.info('操作成功!')
70
-          getList({ pageNum: 1, pageSize: 10 });
71
-        }).catch((err) => {
72
-          console.log(err)
73
-          message.info(err.msg || err.message)
74
-        })
75
-
76
-      }
77
-    });
78
-  }
79
-  /**
80
-   *
81
-   *
82
-   * @param {*} props
83
-   * @returns
84
-   */
85 24
   const columns = [
86 25
     {
87 26
       title: '类型图',
@@ -105,12 +44,12 @@ function header(props) {
105 44
       render: (x, row) => (
106 45
         <>
107 46
           <AuthButton name="admin.taNewsType.id.delete" noRight={null}>
108
-            <span style={{ color: '#EF273A', marginRight: '20px', cursor: 'pointer' }} onClick={changeNewsStatus(row, row.newsTypeId)}>
47
+            <span style={{ color: '#EF273A', marginRight: '20px', cursor: 'pointer' }}>
109 48
               {row.status == 1 ? '删除' : '上架'}<Icon type="shopping-cart" className={styles.shoppingCart} />
110 49
             </span>
111 50
           </AuthButton>
112 51
           <AuthButton name="admin.taNewsType.id.put" noRight={null}>
113
-            <span style={{ color: '#FF925C', cursor: 'pointer' }} onClick={toEditNews(row.newsTypeId)}>
52
+            <span style={{ color: '#FF925C', cursor: 'pointer' }}>
114 53
               编辑<Icon type="form" className={styles.edit} />
115 54
             </span>
116 55
           </AuthButton>
@@ -118,42 +57,172 @@ function header(props) {
118 57
       ),
119 58
     },
120 59
   ];
121
-  function handleReset() {
122
-    props.form.resetFields();
123
-    getList({ pageNum: 1, pageSize: 10 })
124
-  }
125
-
126
-  const { getFieldDecorator } = props.form
127
-  return (
60
+  
128 61
 
129
-    <>
130
-      <Form layout="inline" onSubmit={e => handleSubmit(e, props)}>
131
-        <Form.Item>
132
-          {getFieldDecorator('buildingId')(
133
-            <BuildSelect />,
134
-          )}
135
-        </Form.Item>
136
-        <Form.Item>
137
-            <AuthButton name="admin.taNewsType.search" noRight={null}>
138
-              <Button type="primary" htmlType="submit" >
139
-                查询
140
-              </Button>
141
-            </AuthButton>
142
-            <Button style={{ marginLeft: 8 }} onClick={handleReset}>
143
-              重置
144
-            </Button>
145
-        </Form.Item>
146
-      </Form>
62
+  const renderActions = () => {
63
+    return (
147 64
       <AuthButton name="admin.taNewsType.post" noRight={null}>
148
-        <Button type="danger" className={styles.addBtn} onClick={toEditNews()}>新增</Button>
65
+        <Button type="danger" className={styles.addBtn}>新增</Button>
149 66
       </AuthButton>
150
-      <Table rowKey="newsType" dataSource={data.records} columns={columns} pagination={false} />
151
-      <div style={{ display: 'flex', justifyContent: 'flex-end', marginTop: '30px' }}>
152
-        <Pagination showQuickJumper defaultCurrent={1} total={data.total} onChange={changePageNum} current={data.current}/>
153
-      </div>
154
-    </>
67
+    );
68
+  }
69
+
70
+  return (
71
+    <SearchList
72
+      title="资讯类型"
73
+      actions={renderActions()}
74
+      service={getNewsTypeList}
75
+      search={{ fields: conditions }}
76
+      body={{ columns }}
77
+      pagination={{}}
78
+    />
155 79
   )
156 80
 }
157
-const WrappedHeader = Form.create({ name: 'header' })(header);
158 81
 
159
-export default WrappedHeader
82
+// function header(props) {
83
+//   // 获取初始化数据
84
+//   const [ data, setData ] = useState({})
85
+
86
+//   useEffect(() => {
87
+//     getList({ pageNum: 1, pageSize: 10 });
88
+//   },[])
89
+
90
+//   // 查询列表
91
+//   const getList = (params) => {
92
+//     request({ ...apis.newsType.list, params: { ...params } }).then((data) => {
93
+//         console.log(data)
94
+//         setData(data)
95
+//     })
96
+//   }
97
+
98
+  
99
+//   // 提交事件
100
+//   const handleSubmit = (e, props) => {
101
+//     e.preventDefault();
102
+//     props.form.validateFields((err, values) => {
103
+//       if (!err) {
104
+//         getList({ pageNum: 1, pageSize: 10, ...values })
105
+//       }
106
+//     });
107
+//   }
108
+
109
+//   const changePageNum = (pageNumber) => {
110
+//     props.form.validateFields((err, values) => {
111
+//       if (!err) {
112
+//         getList({ pageNum: pageNumber, pageSize: 10, ...values })
113
+//       }
114
+//     });
115
+//   }
116
+
117
+
118
+//   // 跳转到编辑资讯
119
+//   const toEditNews = (id) => () => {
120
+//     router.push({
121
+//       pathname: '/news/type/editNews',
122
+//       query: {
123
+//         id
124
+//       },
125
+//     });
126
+//   }
127
+
128
+  
129
+//   const changeNewsStatus = (row, newsId) => () => {
130
+//     Modal.confirm({
131
+//       title: '确认删除?',
132
+//       okText: '确认',
133
+//       cancelText: '取消',
134
+//       onOk() {
135
+
136
+//         request({ ...apis.newsType.put, urlData: { id: newsId }, data: { ...row, status: -1 } }).then((data) => {
137
+//           message.info('操作成功!')
138
+//           getList({ pageNum: 1, pageSize: 10 });
139
+//         }).catch((err) => {
140
+//           console.log(err)
141
+//           message.info(err.msg || err.message)
142
+//         })
143
+
144
+//       }
145
+//     });
146
+//   }
147
+//   /**
148
+//    *
149
+//    *
150
+//    * @param {*} props
151
+//    * @returns
152
+//    */
153
+//   const columns = [
154
+//     {
155
+//       title: '类型图',
156
+//       dataIndex: 'newsTypeImg',
157
+//       key: 'newsTypeImg',
158
+//       align: 'center',
159
+//       render: (text, record) => <img src={record.newsTypeImg} style={{ width: '165px',height: '104px' }} className={styles.touxiang} />,
160
+//     },
161
+//     {
162
+//       title: '名称',
163
+//       dataIndex: 'newsTypeName',
164
+//       key: 'newsTypeName',
165
+//       align: 'center',
166
+
167
+//     },
168
+//     {
169
+//       title: '操作',
170
+//       dataIndex: 'handle',
171
+//       key: 'handle',
172
+//       align: 'center',
173
+//       render: (x, row) => (
174
+//         <>
175
+//           <AuthButton name="admin.taNewsType.id.delete" noRight={null}>
176
+//             <span style={{ color: '#EF273A', marginRight: '20px', cursor: 'pointer' }} onClick={changeNewsStatus(row, row.newsTypeId)}>
177
+//               {row.status == 1 ? '删除' : '上架'}<Icon type="shopping-cart" className={styles.shoppingCart} />
178
+//             </span>
179
+//           </AuthButton>
180
+//           <AuthButton name="admin.taNewsType.id.put" noRight={null}>
181
+//             <span style={{ color: '#FF925C', cursor: 'pointer' }} onClick={toEditNews(row.newsTypeId)}>
182
+//               编辑<Icon type="form" className={styles.edit} />
183
+//             </span>
184
+//           </AuthButton>
185
+//         </>
186
+//       ),
187
+//     },
188
+//   ];
189
+
190
+//   function handleReset() {
191
+//     props.form.resetFields();
192
+//     getList({ pageNum: 1, pageSize: 10 })
193
+//   }
194
+
195
+//   const { getFieldDecorator } = props.form
196
+//   return (
197
+
198
+//     <>
199
+//       <Form layout="inline" onSubmit={e => handleSubmit(e, props)}>
200
+//         <Form.Item>
201
+//           {getFieldDecorator('buildingId')(
202
+//             <BuildSelect />,
203
+//           )}
204
+//         </Form.Item>
205
+//         <Form.Item>
206
+//             <AuthButton name="admin.taNewsType.search" noRight={null}>
207
+//               <Button type="primary" htmlType="submit" >
208
+//                 查询
209
+//               </Button>
210
+//             </AuthButton>
211
+//             <Button style={{ marginLeft: 8 }} onClick={handleReset}>
212
+//               重置
213
+//             </Button>
214
+//         </Form.Item>
215
+//       </Form>
216
+//       <AuthButton name="admin.taNewsType.post" noRight={null}>
217
+//         <Button type="danger" className={styles.addBtn} onClick={toEditNews()}>新增</Button>
218
+//       </AuthButton>
219
+//       <Table rowKey="newsType" dataSource={data.records} columns={columns} pagination={false} />
220
+//       <div style={{ display: 'flex', justifyContent: 'flex-end', marginTop: '30px' }}>
221
+//         <Pagination showQuickJumper defaultCurrent={1} total={data.total} onChange={changePageNum} current={data.current}/>
222
+//       </div>
223
+//     </>
224
+//   )
225
+// }
226
+// const WrappedHeader = Form.create({ name: 'header' })(header);
227
+
228
+// export default WrappedHeader

+ 8
- 1
src/utils/request.js Visa fil

@@ -120,6 +120,13 @@ request.interceptors.response.use(async (response, options) => {
120 120
 
121 121
 const fetch = api => options => request(api.url, {...api, ...options || {}})
122 122
 
123
+const fetchList = api => options => new Promise((resolve, reject) => {
124
+  request(api.url, {...api, ...options || {}}).then((res) => {
125
+    const { records, ...page  } = res || {}
126
+    resolve([records, page])
127
+  }).catch(reject)
128
+})
129
+
123 130
 export default config => {
124 131
   if (typeof config === 'string') {
125 132
     return request(config);
@@ -129,4 +136,4 @@ export default config => {
129 136
   }
130 137
 };
131 138
 
132
-export { fetch, apis }
139
+export { fetch, fetchList, apis }