
正文
this that 时间戳转日期 小程序 列表 与 加载
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
var gd = getApp().globalData;
var imgUrlApp = gd.imgUrlApp;
var localImgPath = gd.localImgPath;
var apiUrlApp = gd.apiUrlApp; Page({
/**
* 页面的初始数据
*/
data: {
apiUrlApp: apiUrlApp,
imgUrlApp: imgUrlApp,
localImgPath: localImgPath,
navbar: ['营销攻略', '行业资讯', '公司新闻'],
currentTab: 1,
strategy_list: {}
},
//响应点击导航栏
navbarTap: function(e) {
var that = this;
that.setData({
currentTab: e.currentTarget.dataset.idx,
TypeItem: that.data.navbar[that.data.currentTab]
})
},
add0: function(i) {
return (i < 10 ? '0' + (i) : i)
},
timestampToTime: function(timestamp) {
var date = new Date(timestamp * 1000); //时间戳为10位需*1000,时间戳为13位的话不需乘1000
var Y = date.getFullYear() + '-';
var t = this.add0;
var M = t(date.getMonth()) + '-';
var D = t(date.getDate()) + ' ';
var h = t(date.getHours()) + ':';
var m = t(date.getMinutes()) + ':';
var s = t(date.getSeconds()); return Y + M + D + h + m + s;
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function(options) {
var that = this;
console.log(
wx.getStorageSync("username")),
wx.request({
url: apiUrlApp + 'index/doc/strategy_list/',
header: {
"Content-Type": "application/x-www-form-urlencoded",
'cookie': wx.getStorageSync("username"), //读取cookie,
'cookie': wx.getStorageSync("uid"), //读取cookie,
'cookie': wx.getStorageSync("gid") //读取cookie, },
method: "GET",
data: {
page: 1,
size: 12
},
success: function(res) {
console.log(res)
if (res.data.status == 1) {
for (var i = 0; i < 12; i++) {
res.data.data[i]["modify_time"] = that.timestampToTime(res.data.data[i]["modify_time"]) } that.setData({
strategy_list: res.data.data
})
} else if (res.data.status == 0) {
wx.showToast({
title: "无数据返回",
icon: 'success',
duration: 1500
})
} else if (res.data.status == -1) {
wx.showToast({
title: "请求异常,请检查重试",
icon: 'loading',
duration: 2000
})
}
}
})
}, /**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function() { }, /**
* 生命周期函数--监听页面显示
*/
onShow: function() { }, /**
* 生命周期函数--监听页面隐藏
*/
onHide: function() { }, /**
* 生命周期函数--监听页面卸载
*/
onUnload: function() { }, /**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function() { }, /**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function() { }, /**
* 用户点击右上角分享
*/
onShareAppMessage: function() { }, onShow: function() {
// 页面显示
},
onHide: function() {
// 页面隐藏
},
onUnload: function() {
// 页面关闭
},
})
<!--导航菜单-->
<view class="navbar" style=" z-index:50">
<!--循环-->
<view wx:for="{{navbar}}" data-idx="{{index}}" wx:key="unique" class="item {{currentTab==index ? 'active' : ''}}" bindtap="navbarTap">
<view class="notice" wx:if="{{count[index]>0}}">{{count[index]}}</view>
{{item}}
</view>
</view>
<view class="page panel" wx:for="{{strategy_list}}" wx:key="*this">
<view class="weui-panel weui-panel_access">
<view class="weui-panel__bd">
<view class="weui-media-box weui-media-box_appmsg">
<view class="weui-media-box__hd">
<image class="weui-media-box__thumb" style="width:60px;height:60px;" src="{{item.main_img}}"></image>
</view>
<view class="weui-media-box__bd">
<view class="weui-media-box__title" style=" word-break:break-all;">{{item.title}}</view>
</view>
</view>
</view>
</view>
<view class="weui-panel__bd">
<view class="weui-media-box weui-media-box_text">
<ul class="weui-media-box__info">
<li class="weui-media-box__info__meta">文字来源2</li>
<li class="weui-media-box__info__meta">{{item.modify_time}}</li>
</ul>
</view>
</view>
</view>






