Browse Source

新闻详情

liyongli 3 năm trước cách đây
mục cha
commit
aedde11e40

+ 17 - 1
miniprogram/pages/detail/detail.js

@@ -29,6 +29,8 @@ Page({
     if (D.type !== 2 && D.content) {
       D.content = D.content.replace(/<p>/gi, '<p style="text-indent: 2em">').replace(/<img/gi, "<img style='width:100%'")
     }
+    if (D.creat_time) D.creat_time = this.format(D.creat_time);
+    console.log(D)
     _this.setData({
       detail: D
     })
@@ -81,5 +83,19 @@ Page({
    */
   onShareAppMessage: function () {
 
-  }
+  },
+
+  format: function (res) {
+    if (!res) return "";
+    let num = (res || 0) - 0;
+    let T = new Date(num);
+    let year = T.getFullYear();
+    let month = T.getMonth() + 1;
+    let day = T.getDate();
+    let hour = T.getHours();
+    let min = T.getMinutes() + 1;
+    let sec = T.getSeconds();
+
+    return year + "-" + (month > 9 ? month : "0" + month) + "-" + day + " " + (hour > 9 ? hour : '0' + hour) + ":" + (min > 9 ? min : '0' + min) + ":" + (sec > 9 ? sec : '0' + sec);
+  },
 })

+ 2 - 0
miniprogram/pages/detail/detail.wxml

@@ -1,7 +1,9 @@
 <!--miniprogram/pages/detail/detail.wxml-->
 <import src="./template/sysDetail/index.wxml"></import>
 <import src="./template/pdfDetail/index.wxml"></import>
+<import src="./template/defaultDetail/index.wxml"></import>
 <view class="detail">
   <template wx:if="{{detail.type === 0}}" is="sysDetail" data="{{...detail}}"></template>
   <template wx:if="{{detail.type === 2}}" is="pdfDetail" data="{{...detail}}"></template>
+  <template wx:if="{{detail.type === 1}}" is="defaultDetail" data="{{...detail}}"></template>
 </view>

+ 1 - 0
miniprogram/pages/detail/detail.wxss

@@ -1,6 +1,7 @@
 /* miniprogram/pages/detail/detail.wxss */
 @import "./template/sysDetail/index.wxss";
 @import "./template/pdfDetail/index.wxss";
+@import "./template/defaultDetail/index.wxss";
 
 .detail{
   padding: 10rpx;

+ 6 - 0
miniprogram/pages/detail/template/defaultDetail/index.wxml

@@ -0,0 +1,6 @@
+<!--miniprogram/pages/detail/template/pdfDetail/index.wxml-->
+<template name="defaultDetail">
+  <video class="video" wx:if="{{headUrl}}" src="{{headUrl}}"></video>
+  <view wx:if="{{creat_time}}"> 发表日期:{{creat_time}}</view>
+  <rich-text wx:if="{{content}}" nodes="{{content}}"></rich-text>
+</template>

+ 4 - 0
miniprogram/pages/detail/template/defaultDetail/index.wxss

@@ -0,0 +1,4 @@
+/* miniprogram/pages/detail/template/pdfDetail/index.wxss */
+.video{
+  width: 750rpx;
+}

+ 35 - 7
miniprogram/pages/home/index.js

@@ -5,13 +5,28 @@ Page({
    * 页面的初始数据
    */
   data: {
+    newList: []
   },
 
   /**
    * 生命周期函数--监听页面加载
    */
-  onLoad: function (options) {
-
+  onLoad: async function (options) {
+
+    const db = wx.cloud.database();
+    const _ = db.command;
+    const _this = this;
+    let list = await db.collection('data_news').where({
+      hot: 1,
+      type: 1
+    }).get();
+    for (let i = 0; i < list.data.length; i++) {
+      const v = list.data[i];
+      v.creat_time = this.format(v.creat_time || 0)
+    }
+    this.setData({
+      newList: list.data || []
+    })
   },
 
   /**
@@ -63,21 +78,34 @@ Page({
 
   },
 
-  toDetail:function(e){
+  format: function (res) {
+    if (!res) return ""
+    let T = new Date(res || 0);
+    let year = T.getFullYear();
+    let month = T.getMonth() + 1;
+    let day = T.getDate();
+    let hour = T.getHours();
+    let min = T.getMinutes() + 1;
+    let sec = T.getSeconds();
+
+    return year + "-" + (month > 9 ? month : "0" + month) + "-" + day + " " + (hour > 9 ? hour : '0' + hour) + ":" + (min > 9 ? min : '0' + min) + ":" + (sec > 9 ? sec : '0' + sec);
+  },
+  toDetail: function (e) {
     let title = e.currentTarget.dataset.title, id = e.currentTarget.dataset.id;
     wx.navigateTo({
-      url: '/pages/detail/detail?title=' +title + "&id=" + id,
+      url: '/pages/detail/detail?title=' + title + "&id=" + id,
     })
   },
-  toRuins:function(e){
+  toRuins: function (e) {
     wx.navigateTo({
       url: '/pages/ruins/index',
     })
   },
-  toMarvellous:function(e){
+  toMarvellous: function (e) {
     wx.navigateTo({
       url: '/pages/marvellous/index?title=' + e.currentTarget.dataset.title + "&type=" + e.currentTarget.dataset.type,
     })
   }
 
-})
+})
+

+ 3 - 3
miniprogram/pages/home/index.wxml

@@ -61,10 +61,10 @@
 
   <mp-cell link hover value="新闻动态" footer="查看更多" url="/pages/interList/interList?type=news">
   </mp-cell>
-  <view class="newList" data-id="1" data-title="新华云直播:“红色文物会说话、红色遗址会发声”融媒传播发布仪式暨“党性教育基地”揭牌仪式" bindtap="toDetail">
-    <image class="newsImg" src="https://xzhsjy.hdd.jxrtv.com/imgs/hddlogo.png"></image>
+  <view class="newList" wx:key="_id" wx:for="{{newList}}" data-id="{{item._id}}" data-title="{{item.title}}" bindtap="toDetail">
+    <image class="newsImg" src="{{item.cover}}"></image>
     <view class="newsTitle">
-      <text class="top">新华云直播:“红色文物会说话、红色遗址会发声”融媒传播发布仪式暨“党性教育基地”揭牌仪式</text>
+      <text class="top">{{item.title}}</text>
       <text class="subTitle">发布日期 2021-05-15 11:25:00</text>
     </view>
   </view>

+ 1 - 1
miniprogram/pages/marvellous/index.wxml

@@ -1,6 +1,6 @@
 <!--miniprogram/pages/marvellous/index.wxml-->
 <view class="marvellous">
-  <!-- <startAn wx:if="{{pageType === 'video' && showAnVideo}}" bindclose="closeAnvido"></startAn> -->
+  <startAn wx:if="{{pageType === 'video' && showAnVideo}}" bindclose="closeAnvido"></startAn>
   <view class="htead"></view>
   <view class="bg" wx:for="{{pageList}}" wx:key="_id">
     <text>{{item.time}}</text>