魏超 il y a 5 ans
Parent
révision
9d17632b91

+ 210
- 0
src/pages/news/list/NewsList.jsx Voir le fichier

@@ -0,0 +1,210 @@
1
+import React, { useState, useEffect } from 'react';
2
+import { Form, Icon, Input, Button, DatePicker, Select, Card, Row, Col, Pagination, Alert } from 'antd';
3
+import moment from 'moment';
4
+import request from '../../../utils/request';
5
+import apis from '../../../services/apis';
6
+import Styles from './style.less';
7
+
8
+
9
+const { Option } = Select;
10
+// eslint-disable-next-line @typescript-eslint/no-unused-vars
11
+const { Meta } = Card;
12
+
13
+const tempDate = [{ code: 's101' }]
14
+
15
+/**
16
+ *卡片
17
+ *
18
+ * @returns
19
+ */
20
+function CartBody(props) {
21
+  const { data } = props
22
+  console.log(props);
23
+  return (
24
+          <Card
25
+            hoverable
26
+            style={{ minWidth: '400px', borderRadius: '12px', margin: '10px', boxShadow: '0px 0px 16px 2px rgba(0,0,0,0.12)' }}
27
+            cover={<img alt="example" src={ data.newsImg } style={{ borderRadius: '12px 12px 0 0', width: '100%', height: '14vw' }}></img>}
28
+            bodyStyle={{ padding: '10px 20px' }}
29
+          >
30
+            <p className={Styles.cardText}>
31
+              <span className={Styles.title}>资讯类型</span>
32
+              <span >:{ data.newsType.newsTypeName }</span>
33
+              <span className={Styles.ediText}>
34
+                编辑
35
+                <Icon type="form" style={{ color: '#C0C4CC', marginLeft: '10px' }} />
36
+              </span>
37
+            </p>
38
+            <p className={Styles.cardText}>
39
+              <span className={Styles.title}>状态</span>
40
+              <span >:{ data.status == '0' ? "已发布" : "未发布" }</span>
41
+            </p>
42
+            <p className={Styles.cardItem}>
43
+              <span className={Styles.title}>阅读数量</span>
44
+              <span > :{ data.pvNum }</span>
45
+            </p>
46
+            <p className={Styles.cardItem}>
47
+              <span className={Styles.title}>转发数量</span>
48
+              <span className={ Styles.address }>:{ data.shareNum }</span>
49
+            </p>
50
+            <p className={Styles.cardItem}>
51
+              <span className={Styles.title}>点赞数量</span>     
52
+              <span >:{ data.favorNum }</span>         
53
+            </p>
54
+            <p className={Styles.cardItem}>
55
+              <span className={Styles.title}>收藏数量</span>
56
+              <span >:{ data.saveNum }</span>
57
+            </p>
58
+            <p className={Styles.cardItem}>
59
+              <span className={Styles.title}>录入时间</span>
60
+              <span >:{ data.createDate }</span>
61
+            </p>
62
+            <p style={{ margin: '15px 0', position: 'relative', fontSize: '18px' }}>
63
+              <span style={{ color: '#1990FF' }}>
64
+                取消发布
65
+                <Icon type="close-circle" style={{ color: '#C0C4CC', marginLeft: '8px' }} />
66
+              </span>
67
+              <span style={{
68
+                color: '#FF4A4A', position: 'absolute', right: '0',
69
+              }} >
70
+                删除
71
+                <Icon type="rest" style={{ color: '#C0C4CC', marginLeft: '8px' }} />
72
+              </span>
73
+            </p>
74
+          </Card>
75
+  )
76
+}
77
+
78
+/**
79
+ *
80
+ *
81
+ * @param {*} props
82
+ * @returns
83
+ */
84
+function body(props) {
85
+  const { getFieldDecorator } = props.form
86
+
87
+  // eslint-disable-next-line react-hooks/rules-of-hooks
88
+  const [dataSource, setDataSource] = useState({ records: [] })
89
+
90
+  // eslint-disable-next-line react-hooks/rules-of-hooks
91
+  useEffect(() => {
92
+    getList({ pageNum: 1, pageSize: 6 })
93
+  }, [])
94
+
95
+  function getList(params) {
96
+    // 网路请求
97
+    request({ ...apis.news.getList, params: { ...params } }).then(res => {
98
+      setDataSource(res)
99
+    }).catch(err => {
100
+      // eslint-disable-next-line no-unused-expressions
101
+      <Alert
102
+        style={{
103
+          marginBottom: 24,
104
+        }}
105
+        message={err}
106
+        type="error"
107
+        showIcon
108
+      />
109
+    })
110
+  }
111
+
112
+  // 提交事件
113
+  function handleSubmit(e) {
114
+    e.preventDefault();
115
+    props.form.validateFields((err, values) => {
116
+      if (!err) {
117
+        // eslint-disable-next-line no-console
118
+        console.log('提交数据: ', values)
119
+        const { startDate } = values
120
+        getList({ pageNum: 1, pageSize: 9, ...values })
121
+      }
122
+    });
123
+  }
124
+
125
+  // Change 事件
126
+  function handleSelectChange(e) {
127
+    // eslint-disable-next-line no-console
128
+    console.log(e)
129
+  }
130
+
131
+  // 分页
132
+  function onChange(pageNumber) {
133
+    // eslint-disable-next-line react-hooks/rules-of-hooks
134
+      getList({ pageNum: pageNumber, pageSize: 9 })
135
+  }
136
+
137
+  function getDate(value, dateString) {
138
+    // moment(value).format('YYYY-MM-DD HH:mm:ss')
139
+    console.log(value, dateString)
140
+  }
141
+
142
+  return (
143
+    <>
144
+      <Form layout="inline" onSubmit={e => handleSubmit(e, props)}>
145
+
146
+        <Form.Item>
147
+          {getFieldDecorator('city')(
148
+            <Select style={{ width: '180px' }} placeholder="请选择城市" onChange={handleSelectChange}>
149
+            </Select>,
150
+          )}
151
+        </Form.Item>
152
+
153
+        <Form.Item>
154
+          {getFieldDecorator('project')(
155
+            <Select style={{ width: '180px' }} placeholder="请选择项目" onChange={handleSelectChange}>
156
+            </Select>,
157
+          )}
158
+        </Form.Item>
159
+        <Form.Item>
160
+          {getFieldDecorator('title')(
161
+            <Input
162
+              prefix={<Icon type="text" style={{ color: 'rgba(0,0,0,.25)' }} />}
163
+              placeholder="请输入标题"
164
+            />,
165
+          )}
166
+        </Form.Item>
167
+        <Form.Item>
168
+          {getFieldDecorator('type')(
169
+            <Select style={{ width: '180px' }} placeholder="咨询类型" onChange={handleSelectChange}>
170
+            </Select>,
171
+          )}
172
+        </Form.Item>       
173
+        <Form.Item>
174
+          {getFieldDecorator('newsStatus')(
175
+            <Select style={{ width: '180px' }} placeholder="状态" onChange={handleSelectChange}>
176
+              <Option value="1">已发布</Option>
177
+              <Option value="0">未发布</Option>
178
+            </Select>,
179
+          )}
180
+        </Form.Item>
181
+        <Form.Item>
182
+          <Button type="primary" htmlType="submit" className={Styles.SubmitButton}>
183
+            搜索
184
+          </Button>
185
+        </Form.Item>
186
+      </Form>
187
+      <Button type="primary" className={Styles.addButton}>
188
+        新增
189
+      </Button>
190
+
191
+      {/* 卡片内容,显示楼盘项目  */}
192
+      <Row style={{ padding: ' 0 10px' }}>
193
+        {
194
+          dataSource.records.map((item, index) => (
195
+              <Col span={8}>
196
+                <CartBody data={item} key={item.buildingId}/>
197
+              </Col>
198
+            ))
199
+        }
200
+      </Row>
201
+      {/* 分页 */}
202
+      <div style={{ display: 'flex', justifyContent: 'flex-end', marginTop: '30px' }}>
203
+        <Pagination showQuickJumper defaultCurrent={1} total={dataSource.total} onChange={onChange} />
204
+      </div>
205
+    </>
206
+  );
207
+}
208
+const WrappedBody = Form.create({ name: 'body' })(body);
209
+
210
+export default WrappedBody

+ 58
- 0
src/pages/news/list/style.less Voir le fichier

@@ -0,0 +1,58 @@
1
+.SubmitButton {
2
+    background: #3a91d5;
3
+    border-radius: 7px;
4
+    border: 0px;
5
+  }
6
+  .SelectFrom {
7
+    width: 180px;
8
+    background: #ffffff;
9
+    border-radius: 7px;
10
+    border: 1px solid #dbdbdb;
11
+  }
12
+  .addButton {
13
+    background: #50be00;
14
+    border-radius: 4px;
15
+    border: 0px;
16
+    margin: 10px 0px;
17
+  }
18
+  .cardText {
19
+    font-size: 18px;
20
+    color: #333;
21
+    line-height: 24px;
22
+    display: flex;
23
+    align-items: center;
24
+    position: relative;
25
+  
26
+  }
27
+  .cardItem{
28
+    font-size: 18px;
29
+    font-weight: 400;
30
+    color: #666;
31
+    line-height: 24px;
32
+    display: flex;
33
+    align-items: center;  
34
+  }
35
+  .ediText {
36
+    font-size: 18px;
37
+    color: #ff925c;
38
+    line-height: 24px;
39
+    position: absolute;
40
+    right: 0;
41
+  }
42
+  .title{
43
+    display: inline-block;
44
+    width: 84px;
45
+    justify-content: space-between;
46
+    text-align: justify;
47
+    text-align-last:justify
48
+  }
49
+  
50
+  .address { 
51
+    width: 400px;
52
+    height: 24px; 
53
+    text-overflow: ellipsis; 
54
+    white-space: nowrap;
55
+    overflow: hidden;
56
+  }
57
+  
58
+  

+ 1
- 1
src/pages/news/type/NewsType.jsx Voir le fichier

@@ -59,7 +59,7 @@ const columns = [
59 59
     title: '类型图片',
60 60
     dataIndex: 'img',
61 61
     key: 'img',
62
-    align: 'center',
62
+    align: 'left',
63 63
     render: (text, record) => <img src={record.img} className={styles.touxiang} />,
64 64
   },
65 65
   {

+ 6
- 0
src/services/apis.js Voir le fichier

@@ -39,6 +39,12 @@ export default {
39 39
       url: `${prefix}/tdBuildingType/id`,
40 40
     },
41 41
   },
42
+  news: {
43
+    getList: {
44
+      method: 'GET',
45
+      url: `${prefix}/taNews`,
46
+    },
47
+  },
42 48
   customer: {
43 49
     drift: {
44 50
       method: 'GET',

+ 12
- 0
src/services/news.js Voir le fichier

@@ -0,0 +1,12 @@
1
+import request from '@/utils/request';
2
+
3
+/**
4
+ * 项目
5
+ */
6
+
7
+/**
8
+ * 获取列表
9
+ */
10
+export async function getList() {
11
+  return request('/api/admin/taNews')
12
+}