|
2 | 2 | <view> |
3 | 3 | <view class="banner" @click="goDetail(banner)"> |
4 | 4 | <image class="banner-img" :src="banner.cover"></image> |
5 | | - <view class="banner-title">{{banner.title}}</view> |
| 5 | + <view class="banner-title">{{ banner.title }}</view> |
6 | 6 | </view> |
7 | 7 | <view class="uni-list"> |
8 | | - <view class="uni-list-cell" hover-class="uni-list-cell-hover" v-for="(value,key) in listData" :key="key" @click="goDetail(value)"> |
| 8 | + <view class="uni-list-cell" hover-class="uni-list-cell-hover" v-for="(value, key) in listData" :key="key" @click="goDetail(value)"> |
9 | 9 | <view class="uni-media-list"> |
10 | 10 | <image class="uni-media-list-logo" :src="value.cover"></image> |
11 | 11 | <view class="uni-media-list-body"> |
12 | | - <view class="uni-media-list-text-top">{{value.title}}</view> |
| 12 | + <view class="uni-media-list-text-top">{{ value.title }}</view> |
13 | 13 | <view class="uni-media-list-text-bottom"> |
14 | | - <text>{{value.author_name}}</text> |
15 | | - <text>{{value.published_at}}</text> |
| 14 | + <text>{{ value.author_name }}</text> |
| 15 | + <text>{{ value.published_at }}</text> |
16 | 16 | </view> |
17 | 17 | </view> |
18 | 18 | </view> |
19 | 19 | </view> |
20 | 20 | </view> |
| 21 | + <uni-load-more :status="status" :content-text="contentText" /> |
21 | 22 | </view> |
22 | 23 | </template> |
23 | 24 |
|
24 | 25 | <script> |
25 | | - var dateUtils = require('../../../common/util.js').dateUtils; |
| 26 | +import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue'; |
| 27 | +var dateUtils = require('../../../common/util.js').dateUtils; |
26 | 28 |
|
27 | | - export default { |
28 | | - data() { |
29 | | - return { |
30 | | - banner: {}, |
31 | | - listData: [], |
32 | | - last_id: "", |
33 | | - reload: false |
| 29 | +export default { |
| 30 | + components: { |
| 31 | + uniLoadMore |
| 32 | + }, |
| 33 | + data() { |
| 34 | + return { |
| 35 | + banner: {}, |
| 36 | + listData: [], |
| 37 | + last_id: '', |
| 38 | + reload: false, |
| 39 | + status: 'more', |
| 40 | + contentText: { |
| 41 | + contentdown: '上拉加载更多', |
| 42 | + contentrefresh: '加载中', |
| 43 | + contentnomore: '没有更多' |
34 | 44 | } |
35 | | - }, |
36 | | - onLoad() { |
37 | | - this.getBanner(); |
38 | | - this.getList(); |
39 | | - }, |
40 | | - onPullDownRefresh() { |
41 | | - this.reload = true; |
42 | | - this.last_id = ""; |
43 | | - this.getBanner(); |
44 | | - this.getList(); |
45 | | - }, |
46 | | - onReachBottom() { |
47 | | - this.getList(); |
48 | | - }, |
49 | | - methods: { |
50 | | - getBanner() { |
51 | | - let data = { |
52 | | - column: "id,post_id,title,author_name,cover,published_at" //需要的字段名 |
53 | | - }; |
54 | | - uni.request({ |
55 | | - url: 'https://unidemo.dcloud.net.cn/api/banner/36kr', |
56 | | - data: data, |
57 | | - success: (data) => { |
58 | | - uni.stopPullDownRefresh(); |
59 | | - if (data.statusCode == 200) { |
60 | | - this.banner = data.data; |
61 | | - } |
62 | | - }, |
63 | | - fail: (data, code) => { |
64 | | - console.log('fail' + JSON.stringify(data)); |
| 45 | + }; |
| 46 | + }, |
| 47 | + onLoad() { |
| 48 | + this.getBanner(); |
| 49 | + this.getList(); |
| 50 | + }, |
| 51 | + onPullDownRefresh() { |
| 52 | + this.reload = true; |
| 53 | + this.last_id = ''; |
| 54 | + this.getBanner(); |
| 55 | + this.getList(); |
| 56 | + }, |
| 57 | + onReachBottom() { |
| 58 | + this.status = 'more'; |
| 59 | + this.getList(); |
| 60 | + }, |
| 61 | + methods: { |
| 62 | + getBanner() { |
| 63 | + let data = { |
| 64 | + column: 'id,post_id,title,author_name,cover,published_at' //需要的字段名 |
| 65 | + }; |
| 66 | + uni.request({ |
| 67 | + url: 'https://unidemo.dcloud.net.cn/api/banner/36kr', |
| 68 | + data: data, |
| 69 | + success: data => { |
| 70 | + uni.stopPullDownRefresh(); |
| 71 | + if (data.statusCode == 200) { |
| 72 | + this.banner = data.data; |
65 | 73 | } |
66 | | - }) |
67 | | - }, |
68 | | - getList() { |
69 | | - var data = { |
70 | | - column: "id,post_id,title,author_name,cover,published_at" //需要的字段名 |
71 | | - }; |
72 | | - if (this.last_id) { //说明已有数据,目前处于上拉加载 |
73 | | - data.minId = this.last_id; |
74 | | - data.time = new Date().getTime() + ""; |
75 | | - data.pageSize = 10; |
| 74 | + }, |
| 75 | + fail: (data, code) => { |
| 76 | + console.log('fail' + JSON.stringify(data)); |
76 | 77 | } |
77 | | - uni.request({ |
78 | | - url: 'https://unidemo.dcloud.net.cn/api/news', |
79 | | - data: data, |
80 | | - success: (data) => { |
81 | | - if (data.statusCode == 200) { |
82 | | - let list = this.setTime(data.data); |
83 | | - this.listData = this.reload ? list : this.listData.concat(list); |
84 | | - this.last_id = list[list.length - 1].id; |
85 | | - this.reload = false; |
86 | | - } |
87 | | - }, |
88 | | - fail: (data, code) => { |
89 | | - console.log('fail' + JSON.stringify(data)); |
| 78 | + }); |
| 79 | + }, |
| 80 | + getList() { |
| 81 | + var data = { |
| 82 | + column: 'id,post_id,title,author_name,cover,published_at' //需要的字段名 |
| 83 | + }; |
| 84 | + if (this.last_id) { |
| 85 | + //说明已有数据,目前处于上拉加载 |
| 86 | + this.status = 'loading'; |
| 87 | + data.minId = this.last_id; |
| 88 | + data.time = new Date().getTime() + ''; |
| 89 | + data.pageSize = 10; |
| 90 | + } |
| 91 | + uni.request({ |
| 92 | + url: 'https://unidemo.dcloud.net.cn/api/news', |
| 93 | + data: data, |
| 94 | + success: data => { |
| 95 | + if (data.statusCode == 200) { |
| 96 | + let list = this.setTime(data.data); |
| 97 | + this.listData = this.reload ? list : this.listData.concat(list); |
| 98 | + this.last_id = list[list.length - 1].id; |
| 99 | + this.reload = false; |
90 | 100 | } |
91 | | - }) |
92 | | - }, |
93 | | - goDetail: function (e) { |
94 | | -// if (!/前|刚刚/.test(e.published_at)) { |
95 | | -// e.published_at = dateUtils.format(e.published_at); |
96 | | -// } |
97 | | - let detail = { |
| 101 | + }, |
| 102 | + fail: (data, code) => { |
| 103 | + console.log('fail' + JSON.stringify(data)); |
| 104 | + } |
| 105 | + }); |
| 106 | + }, |
| 107 | + goDetail: function(e) { |
| 108 | + // if (!/前|刚刚/.test(e.published_at)) { |
| 109 | + // e.published_at = dateUtils.format(e.published_at); |
| 110 | + // } |
| 111 | + let detail = { |
| 112 | + author_name: e.author_name, |
| 113 | + cover: e.cover, |
| 114 | + id: e.id, |
| 115 | + post_id: e.post_id, |
| 116 | + published_at: e.published_at, |
| 117 | + title: e.title |
| 118 | + }; |
| 119 | + uni.navigateTo({ |
| 120 | + url: '../list2detail-detail/list2detail-detail?detailDate=' + encodeURIComponent(JSON.stringify(detail)) |
| 121 | + }); |
| 122 | + }, |
| 123 | + setTime: function(items) { |
| 124 | + var newItems = []; |
| 125 | + items.forEach(e => { |
| 126 | + newItems.push({ |
98 | 127 | author_name: e.author_name, |
99 | 128 | cover: e.cover, |
100 | 129 | id: e.id, |
101 | 130 | post_id: e.post_id, |
102 | | - published_at: e.published_at, |
| 131 | + published_at: dateUtils.format(e.published_at), |
103 | 132 | title: e.title |
104 | | - } |
105 | | - uni.navigateTo({ |
106 | | - url: "../list2detail-detail/list2detail-detail?detailDate=" + encodeURIComponent(JSON.stringify(detail)) |
107 | | - }) |
108 | | - }, |
109 | | - setTime: function (items) { |
110 | | - var newItems = []; |
111 | | - items.forEach((e) => { |
112 | | - newItems.push({ |
113 | | - author_name: e.author_name, |
114 | | - cover: e.cover, |
115 | | - id: e.id, |
116 | | - post_id: e.post_id, |
117 | | - published_at: dateUtils.format(e.published_at), |
118 | | - title: e.title |
119 | | - }); |
120 | 133 | }); |
121 | | - return newItems; |
122 | | - } |
123 | | - }, |
| 134 | + }); |
| 135 | + return newItems; |
| 136 | + } |
124 | 137 | } |
| 138 | +}; |
125 | 139 | </script> |
126 | 140 |
|
127 | 141 | <style> |
128 | | - .banner { |
129 | | - height: 360upx; |
130 | | - overflow: hidden; |
131 | | - position: relative; |
132 | | - background-color: #ccc; |
133 | | - } |
| 142 | +.banner { |
| 143 | + height: 360upx; |
| 144 | + overflow: hidden; |
| 145 | + position: relative; |
| 146 | + background-color: #ccc; |
| 147 | +} |
134 | 148 |
|
135 | | - .banner-img { |
136 | | - width: 100%; |
137 | | - } |
| 149 | +.banner-img { |
| 150 | + width: 100%; |
| 151 | +} |
138 | 152 |
|
139 | | - .banner-title { |
140 | | - max-height: 84upx; |
141 | | - overflow: hidden; |
142 | | - position: absolute; |
143 | | - left: 30upx; |
144 | | - bottom: 30upx; |
145 | | - width: 90%; |
146 | | - font-size: 32upx; |
147 | | - font-weight: 400; |
148 | | - line-height: 42upx; |
149 | | - color: white; |
150 | | - z-index: 11; |
151 | | - } |
| 153 | +.banner-title { |
| 154 | + max-height: 84upx; |
| 155 | + overflow: hidden; |
| 156 | + position: absolute; |
| 157 | + left: 30upx; |
| 158 | + bottom: 30upx; |
| 159 | + width: 90%; |
| 160 | + font-size: 32upx; |
| 161 | + font-weight: 400; |
| 162 | + line-height: 42upx; |
| 163 | + color: white; |
| 164 | + z-index: 11; |
| 165 | +} |
152 | 166 |
|
153 | | - .uni-media-list-logo { |
154 | | - width: 180upx; |
155 | | - height: 140upx; |
156 | | - } |
| 167 | +.uni-media-list-logo { |
| 168 | + width: 180upx; |
| 169 | + height: 140upx; |
| 170 | +} |
157 | 171 |
|
158 | | - .uni-media-list-body { |
159 | | - height: auto; |
160 | | - justify-content: space-around; |
161 | | - } |
| 172 | +.uni-media-list-body { |
| 173 | + height: auto; |
| 174 | + justify-content: space-around; |
| 175 | +} |
162 | 176 |
|
163 | | - .uni-media-list-text-top { |
164 | | - height: 74upx; |
165 | | - font-size: 28upx; |
166 | | - overflow: hidden; |
167 | | - } |
| 177 | +.uni-media-list-text-top { |
| 178 | + height: 74upx; |
| 179 | + font-size: 28upx; |
| 180 | + overflow: hidden; |
| 181 | +} |
168 | 182 |
|
169 | | - .uni-media-list-text-bottom { |
170 | | - display: flex; |
171 | | - flex-direction: row; |
172 | | - justify-content: space-between; |
173 | | - } |
174 | | -</style> |
| 183 | +.uni-media-list-text-bottom { |
| 184 | + display: flex; |
| 185 | + flex-direction: row; |
| 186 | + justify-content: space-between; |
| 187 | +} |
| 188 | +</style> |
0 commit comments