news-page.nvue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  1. <template>
  2. <view class="page-news">
  3. <uni-list class="listview" :enableBackToTop="true" :scroll-y="true" @scrolltolower="loadMore()">
  4. <!-- 下拉刷新 -->
  5. <uni-refresh class="refresh" @refresh="onrefresh" @pullingdown="onpullingdown"
  6. :display="refreshing ? 'show' : 'hide'">
  7. <div class="refresh-view">
  8. <image class="refresh-icon" :src="refreshIcon" :style="{width: (refreshing || pulling) ? 0: '32px'}"
  9. :class="{'refresh-icon-active': refreshFlag}"></image>
  10. <uni-load-more v-if="refreshing" class="loading-icon" status="loading"
  11. :contentText="loadingMoreText"></uni-load-more>
  12. <text class="loading-text">{{refreshText}}</text>
  13. </div>
  14. </uni-refresh>
  15. <!-- 轮播图 -->
  16. <uni-cell v-if="!pageItem.dictTypeId">
  17. <view class="uni-margin-wrap">
  18. <swiper class="swiper" circular :indicator-dots="true" indicator-active-color="#333"
  19. :autoplay="true" :interval="2000" :duration="1000">
  20. <swiper-item v-for="(banner,index) in bannerList" :key="index">
  21. <navigator :url="'./components/rankDetail?key=' + banner.baseEntityId">
  22. <image class="swiper-img" v-if="banner.pictureUrl!==null"
  23. :src="'https://m.geidcp.com/api/file/pub/' + banner.pictureUrl" mode=""></image>
  24. <image class="swiper-img" v-else src="../../static/errorImage.jpg" mode=""></image>
  25. </navigator>
  26. </swiper-item>
  27. </swiper>
  28. </view>
  29. </uni-cell>
  30. <!-- 点击排行 -->
  31. <uni-cell v-if="!pageItem.dictTypeId">
  32. <view class="rank">
  33. <view class="rank-title">
  34. <text class="title">{{ i18n.ClickRank }}</text>
  35. <view class="top10" @tap="toRankTop">
  36. <text class="vert">TOP10</text>
  37. <uni-icons class="vert arrowright" type="arrowright" color="#666666" size="16" />
  38. </view>
  39. </view>
  40. <view class="rank-list-box">
  41. <view class="rank-list" v-for="(list,index) in hitsList" v-if="informationMap[list] && index<3"
  42. :key="informationMap[list].baseEntityId" @tap="toRankDetail"
  43. :data-key="informationMap[list].baseEntityId">
  44. <view class="order">
  45. <text class="order-text"
  46. :class="index == 1? 'order-text2': index == 2? 'order-text3': '' ">{{ index+1 }}</text>
  47. </view>
  48. <view class="cont" :style="{width: informationMap[list].pictureUrl? '420rpx': '628rpx'}">
  49. <view>
  50. <text
  51. class="cont-title">{{informationMap[list]?informationMap[list].title:''}}</text>
  52. </view>
  53. <view class="cont-sm">
  54. <text
  55. class="cont-text">{{ informationMap[list]?informationMap[list].auther:'' }}</text>
  56. <text
  57. class="time">{{ formatDate(informationMap[list]?informationMap[list].publishDate:'') }}</text>
  58. </view>
  59. </view>
  60. <view class="cont-img" v-if="informationMap[list].pictureUrl">
  61. <image class="img"
  62. :src="informationMap[list]?'https://m.geidcp.com/api/file/pub/' + informationMap[list].pictureUrl:''"
  63. mode="">
  64. </image>
  65. </view>
  66. </view>
  67. </view>
  68. </view>
  69. </uni-cell>
  70. <!-- 资讯 -->
  71. <uni-cell class="cellList" v-if="!pageItem.dictTypeId">
  72. <text class="title">{{ i18n.LatestNews }}</text>
  73. </uni-cell>
  74. <uni-cell v-for="(item, index) in dataList" :key="item.id">
  75. <news-item :newsItem="item"></news-item>
  76. </uni-cell>
  77. <uni-cell v-if="isLoading || dataList.length > 4">
  78. <view class="loading-more">
  79. <text class="loading-more-text">{{loadingText}}</text>
  80. </view>
  81. </uni-cell>
  82. </uni-list>
  83. <no-data class="no-data" v-if="isNoData" @retry="loadMore"></no-data>
  84. </view>
  85. </template>
  86. <script>
  87. import moment from "moment";
  88. import uniList from './components/uni-list.vue';
  89. import uniCell from './components/uni-cell.vue';
  90. import uniRefresh from './components/uni-refresh.vue';
  91. import uniLoadMore from './components/uni-load-more.vue';
  92. import noData from './components/nodata.nvue';
  93. import newsItem from './news-item.nvue';
  94. export default {
  95. components: {
  96. uniList,
  97. uniCell,
  98. uniRefresh,
  99. uniLoadMore,
  100. noData,
  101. newsItem
  102. },
  103. props: ['pageItem'],
  104. data() {
  105. return {
  106. bannerList: [],
  107. hitsList: [],
  108. dataList: [],
  109. navigateFlag: false,
  110. pulling: false,
  111. refreshing: false,
  112. refreshFlag: false,
  113. refreshText: "",
  114. isLoading: false,
  115. loadingText: getApp().$i18n.locale == 'zh' ? '加载中...' : 'Loading...',
  116. isNoData: false,
  117. pulling: false,
  118. angle: 0,
  119. topClickList: {},
  120. informationMap: {},
  121. loadingMoreText: {
  122. contentdown: '',
  123. contentrefresh: '',
  124. contentnomore: ''
  125. },
  126. page: {
  127. typeDict: null,
  128. language: getApp().$i18n.locale.toUpperCase(),
  129. pageSize: 10,
  130. pageNo: 1,
  131. businessType: "information",
  132. title: ''
  133. },
  134. refreshIcon: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAMAAABg3Am1AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAB5QTFRFcHBw3Nzct7e39vb2ycnJioqK7e3tpqam29vb////D8oK7wAAAAp0Uk5T////////////ALLMLM8AAABxSURBVHja7JVBDoAgDASrjqj//7CJBi90iyYeOHTPMwmFZrHjYyyFYYUy1bwUZqtJIYVxhf1a6u0R7iUvWsCcrEtwJHp8MwMdvh2amHduiZD3rpWId9+BgPd7Cc2LIkPyqvlQvKxKBJ//Qwq/CacAAwDUv0a0YuKhzgAAAABJRU5ErkJggg=="
  135. }
  136. },
  137. created() {
  138. if (!this.pageItem.dictTypeId) {
  139. this.getBanner();
  140. this.getHitsList();
  141. }
  142. this.pullTimer = null;
  143. this._isWidescreen = false;
  144. // #ifdef H5
  145. var mediaQueryOb = uni.createMediaQueryObserver(this)
  146. mediaQueryOb.observe({
  147. minWidth: 768
  148. }, matches => {
  149. this._isWidescreen = matches;
  150. })
  151. // #endif
  152. },
  153. watch: {
  154. i18n() {
  155. //置空,清除缓存
  156. this.hitsList = [];
  157. this.dataList = [];
  158. this.page.pageNo = 1;
  159. if (!this.pageItem.dictTypeId) {
  160. this.getHitsList();
  161. };
  162. this.loadMore();
  163. this.loadingText = getApp().$i18n.locale == 'zh' ? '加载中...' : 'Loading...';
  164. }
  165. },
  166. computed: {
  167. i18n() {
  168. return getApp().$t('common');
  169. }
  170. },
  171. methods: {
  172. BBBB() {
  173. console.log(getApp().globalData, '----')
  174. },
  175. formatDate(value, formatString, defaultString) {
  176. if (value == null) {
  177. return defaultString ? defaultString : "";
  178. }
  179. formatString = formatString || 'YYYY-MM-DD';
  180. return moment(value).format(formatString);
  181. },
  182. async getBanner() {
  183. const res = await getApp().$myRequest({
  184. url: '/cms/cmsInformationViews/appBannerInformations/',
  185. data: {
  186. language: getApp().$i18n.locale.toUpperCase()
  187. }
  188. });
  189. this.bannerList = res.data.bannerList;
  190. // this.bannerList.forEach((item, index) => {
  191. // if (item.pictureUrl==null)
  192. // })
  193. console.log(this.bannerList, "图片数据");
  194. },
  195. async loadData(refresh, index) {
  196. if (this.isLoading) {
  197. return;
  198. }
  199. this.isLoading = true;
  200. this.isNoData = false;
  201. if (index == 0) {
  202. this.page.typeDict = null;
  203. } else {
  204. this.page.typeDict = index;
  205. }
  206. this.page.language = getApp().$i18n.locale.toUpperCase();
  207. const res = await getApp().$myRequest({
  208. url: '/cms/cmsInformationViews/appGetInformationList/',
  209. data: this.page,
  210. });
  211. // console.log(res);
  212. if (res.data && res.data.page) {
  213. if (refresh) {
  214. this.dataList = res.data.page.list || [];
  215. this.page.pageNo = 1;
  216. this.dataList.forEach(element => {
  217. element.content = element.content.replace(/<[^>]+>|&[^>]+;/g, "")
  218. });
  219. } else {
  220. if (this.page.pageNo <= res.data.page.totalPage) {
  221. this.dataList = this.dataList.concat(res.data.page.list);
  222. this.page.pageNo += 1;
  223. this.isLoading = false;
  224. } else {
  225. this.isLoading = true;
  226. this.loadingText = getApp().$i18n.locale == 'zh' ? '到底啦!' : 'It is the end!';
  227. }
  228. }
  229. } else {
  230. if (this.dataList.length == 0) {
  231. this.isNoData = true;
  232. }
  233. }
  234. if (refresh) {
  235. this.isLoading = false;
  236. this.refreshing = false;
  237. this.refreshFlag = false;
  238. this.refreshText = getApp().$i18n.locale == 'zh' ? '已刷新' : 'Refreshed';
  239. if (this.pullTimer) {
  240. clearTimeout(this.pullTimer);
  241. }
  242. this.pullTimer = setTimeout(() => {
  243. this.pulling = false;
  244. }, 1000);
  245. }
  246. },
  247. async getHitsList() { //点击排行
  248. let that = this;
  249. let list = {
  250. pageSize: 3,
  251. language: getApp().$i18n.locale.toUpperCase(),
  252. businessType: "information",
  253. }
  254. const res = await getApp().$myRequest({
  255. url: '/cms/cmsInformationClicks/topClickList',
  256. data: {
  257. ...list
  258. }
  259. });
  260. // console.log(res);
  261. that.topClickList = res.data.topClickList;
  262. that.hitsList = that.topClickList[1];
  263. that.informationMap = res.data.informationMap;
  264. // this.hitsList = res.data.cmsInformationView;
  265. },
  266. toRankDetail(e) { //去点击详情
  267. let key = e.currentTarget.dataset.key;
  268. uni.navigateTo({
  269. url: './components/rankDetail?key=' + key
  270. });
  271. },
  272. loadMore(e) {
  273. this.loadData(false, Number(this.pageItem.value));
  274. },
  275. refreshData() {
  276. if (this.isLoading) {
  277. return;
  278. }
  279. this.pulling = true;
  280. this.refreshing = true;
  281. this.refreshText = getApp().$i18n.locale == 'zh' ? "正在刷新..." : 'Refreshing...';
  282. this.loadData(true, Number(this.pageItem.value));
  283. },
  284. onrefresh(e) {
  285. this.refreshData();
  286. },
  287. onpullingdown(e) {
  288. if (this.refreshing) {
  289. return;
  290. }
  291. this.pulling = false;
  292. if (Math.abs(e.pullingDistance) > Math.abs(e.viewHeight)) {
  293. this.refreshFlag = true;
  294. this.refreshText = getApp().$i18n.locale == 'zh' ? '释放立即刷新' : 'Release refresh now';
  295. } else {
  296. this.refreshFlag = false;
  297. this.refreshText = getApp().$i18n.locale == 'zh' ? '下拉可以刷新' : 'Drop down to refresh';
  298. }
  299. },
  300. toRankTop() {
  301. uni.navigateTo({
  302. url: './components/rankTop'
  303. })
  304. }
  305. }
  306. }
  307. </script>
  308. <style scoped>
  309. .uni-margin-wrap {
  310. margin-top: 20upx;
  311. }
  312. .swiper {
  313. width: 750upx;
  314. height: 310upx;
  315. }
  316. .swiper-img {
  317. width: 750upx;
  318. height: 310upx;
  319. }
  320. .rank {
  321. background-color: #FFFFFF;
  322. padding: 20upx 30upx 0;
  323. margin: 20upx 0;
  324. }
  325. .rank-title {
  326. /* #ifndef APP-PLUS-NVUE */
  327. display: flex;
  328. /* #endif */
  329. flex-direction: row;
  330. justify-content: space-between;
  331. }
  332. .title {
  333. font-size: 32upx;
  334. font-weight: 700;
  335. color: #333333;
  336. }
  337. .top10 {
  338. font-size: 28upx;
  339. flex-direction: row;
  340. }
  341. .vert {
  342. font-size: 28upx;
  343. flex-direction: row;
  344. color: #666666;
  345. }
  346. .arrowright {
  347. margin-top: 3rpx;
  348. }
  349. .rank-list-box {
  350. margin-top: 18upx;
  351. }
  352. .rank-list {
  353. padding: 30upx 0;
  354. border-bottom-width: 1px;
  355. border-bottom-style: solid;
  356. border-bottom-color: #f1f1f1;
  357. /* #ifndef APP-PLUS-NVUE */
  358. display: flex;
  359. /* #endif */
  360. flex-direction: row;
  361. justify-content: space-between;
  362. }
  363. .order-text {
  364. width: 40upx;
  365. height: 40upx;
  366. line-height: 40upx;
  367. text-align: center;
  368. color: #FFFFFF;
  369. border-radius: 8upx;
  370. background-color: #f66600;
  371. margin-top: 4upx;
  372. font-size: 26upx;
  373. }
  374. .order-text2 {
  375. background-color: #ff995f;
  376. }
  377. .order-text3 {
  378. background-color: #ffcd5d;
  379. }
  380. .cont {
  381. width: 420upx;
  382. }
  383. .cont-title {
  384. color: #333333;
  385. font-size: 32upx;
  386. font-weight: 700;
  387. text-align: left;
  388. lines: 2;
  389. text-overflow: ellipsis;
  390. /* #ifndef APP-PLUS-NVUE */
  391. overflow: hidden;
  392. display: -webkit-box;
  393. -webkit-line-clamp: 2;
  394. -webkit-box-orient: vertical;
  395. /* #endif */
  396. }
  397. .cont-sm {
  398. margin-top: 16upx;
  399. flex-direction: row;
  400. }
  401. .cont-text {
  402. font-size: 28upx;
  403. color: #999999;
  404. }
  405. .time {
  406. margin-left: 30upx;
  407. font-size: 28upx;
  408. color: #999999;
  409. }
  410. .img {
  411. width: 185upx;
  412. height: 140upx;
  413. }
  414. .cellList {
  415. background-color: #FFFFFF;
  416. padding: 20upx 30upx;
  417. }
  418. .uni-list {
  419. background-color: transparent;
  420. }
  421. .uni-list::before {
  422. background-color: transparent;
  423. }
  424. .no-data {
  425. flex: 1;
  426. position: absolute;
  427. left: 0;
  428. top: 0;
  429. right: 0;
  430. bottom: 0;
  431. z-index: 10;
  432. }
  433. .page-news {
  434. flex: 1;
  435. flex-direction: column;
  436. }
  437. .listview {
  438. flex: 1;
  439. position: absolute;
  440. left: 0;
  441. top: 0;
  442. right: 0;
  443. bottom: 0;
  444. /* #ifndef APP-NVUE */
  445. display: flex;
  446. flex-direction: column;
  447. /* #endif */
  448. /* #ifndef MP-ALIPAY */
  449. flex-direction: column;
  450. /* #endif */
  451. }
  452. .refresh {
  453. justify-content: center;
  454. }
  455. .refresh-view {
  456. /* #ifndef APP-NVUE */
  457. display: flex;
  458. /* #endif */
  459. width: 750upx;
  460. height: 64px;
  461. flex-direction: row;
  462. flex-wrap: nowrap;
  463. align-items: center;
  464. justify-content: center;
  465. }
  466. .refresh-icon {
  467. width: 32px;
  468. height: 32px;
  469. transition-duration: .5s;
  470. transition-property: transform;
  471. transform: rotate(0deg);
  472. transform-origin: 15px 15px;
  473. }
  474. .refresh-icon-active {
  475. transform: rotate(180deg);
  476. }
  477. .loading-icon {
  478. width: 28px;
  479. height: 28px;
  480. margin-right: 5px;
  481. color: gray;
  482. }
  483. .loading-text {
  484. margin-left: 2px;
  485. font-size: 16px;
  486. color: #999999;
  487. }
  488. .loading-more {
  489. align-items: center;
  490. justify-content: center;
  491. padding-top: 14px;
  492. padding-bottom: 14px;
  493. text-align: center;
  494. }
  495. .loading-more-text {
  496. font-size: 28upx;
  497. color: #999;
  498. }
  499. </style>