|
@@ -5,23 +5,35 @@ Page({
|
|
|
* 页面的初始数据
|
|
|
*/
|
|
|
data: {
|
|
|
-
|
|
|
+ newsList: []
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面加载
|
|
|
*/
|
|
|
- onLoad: function (options) {
|
|
|
+ onLoad: async function (options) {
|
|
|
console.log(options.type)
|
|
|
- if(options.type == "news"){
|
|
|
+ if (options.type == "news") {
|
|
|
wx.setNavigationBarTitle({
|
|
|
- title: '新闻列表'
|
|
|
+ title: '新闻列表'
|
|
|
})
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
wx.setNavigationBarTitle({
|
|
|
- title: '视频列表'
|
|
|
+ title: '视频列表'
|
|
|
})
|
|
|
}
|
|
|
+ const db = wx.cloud.database();
|
|
|
+ let list = await db.collection('data_news').where({
|
|
|
+ type: 1
|
|
|
+ }).get();
|
|
|
+ for (let i = 0; i < list.data.length; i++) {
|
|
|
+ const v = list.data[i];
|
|
|
+ if (v.creat_time) v.creat_time = this.format(v.creat_time || 0)
|
|
|
+ }
|
|
|
+ console.log(list.data)
|
|
|
+ this.setData({
|
|
|
+ newsList: list.data || []
|
|
|
+ })
|
|
|
},
|
|
|
|
|
|
/**
|
|
@@ -73,7 +85,27 @@ Page({
|
|
|
|
|
|
},
|
|
|
|
|
|
- tolist:function(e){
|
|
|
+ tolist: function (e) {
|
|
|
console.log(e)
|
|
|
+ },
|
|
|
+
|
|
|
+ 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);
|
|
|
+ },
|
|
|
+ toDetail:function(e){
|
|
|
+ let title = e.currentTarget.dataset.title, id = e.currentTarget.dataset.id;
|
|
|
+ wx.navigateTo({
|
|
|
+ url: '/pages/detail/detail?title=' + title + "&id=" + id,
|
|
|
+ })
|
|
|
}
|
|
|
})
|