微信小程序实现倒计时,苹果手机不显示

2018-8-30    seo达人

如果您想订阅本博客内容,每天自动发到您的邮箱中, 请点这里

JS页面代码段:


    
  1. const app = getApp()
  2. let goodsList = [
  3. { actEndTime: '2018-07-21 21:00:34' },
  4. { actEndTime: '2028-07-17 21:00:37' },
  5. { actEndTime: '2018-09-21 05:00:59' },
  6. { actEndTime: '2018-08-19 07:00:48' },
  7. { actEndTime: '2018-08-28 03:00:11' }
  8. ]
  9. Page({
  10. data: {
  11. countDownList: [],
  12. actEndTimeList: []
  13. },
  14. onLoad: function () {
  15. let endTimeList = [];
  16. // 将活动的结束时间参数提成一个单独的数组,方便操作
  17. goodsList.forEach(o => { endTimeList.push(o.actEndTime) })
  18. this.setData({ actEndTimeList: endTimeList });
  19. // 执行倒计时函数
  20. this.countDown();
  21. },
  22. //当时间小于两位数时十位数补零。
  23. timeFormat: function (param) {//小于10的格式化函数
  24. return param < 10 ? '0' + param : param;
  25. },
  26. //倒计时函数
  27. countDown: function () {
  28. // 获取当前时间,同时得到活动结束时间数组
  29. let newTime = new Date().getTime();//当前时间
  30. let endTimeList = this.data.actEndTimeList;//结束时间的数组集合
  31. let countDownArr = [];//初始化倒计时数组
  32. // 对结束时间进行处理渲染到页面
  33. endTimeList.forEach(o => {
  34. let endTime = new Date(o).getTime();
  35. let obj = null;
  36. // 如果活动未结束,对时间进行处理
  37. if (endTime - newTime > 0) {
  38. let time = (endTime - newTime) / 1000;
  39. // 获取天、时、分、秒
  40. let day = parseInt(time / (60 * 60 * 24));
  41. let hou = parseInt(time % (60 * 60 * 24) / 3600);
  42. let min = parseInt(time % (60 * 60 * 24) % 3600 / 60);
  43. let sec = parseInt(time % (60 * 60 * 24) % 3600 % 60);
  44. obj = {
  45. day: this.timeFormat(day),
  46. hou: this.timeFormat(hou),
  47. min: this.timeFormat(min),
  48. sec: this.timeFormat(sec)
  49. }
  50. } else {//活动已结束,全部设置为'00'
  51. obj = {
  52. day: '00',
  53. hou: '00',
  54. min: '00',
  55. sec: '00'
  56. }
  57. }
  58. countDownArr.push(obj);
  59. })
  60. //每隔一秒执行一次倒计时函数, 渲染
  61. this.setData({ countDownList: countDownArr })
  62. setTimeout(this.countDown, 1000);
  63. }
  64. })

wxml页面代码段


    
  1. <view class='tui-countdown-content' wx:for="{{countDownList}}" wx:key="countDownList">
  2. 距结束
  3. <text class='tui-conutdown-box'>{{item.day}}</text>天
  4. <text class='tui-conutdown-box'>{{item.hou}}</text>时
  5. <text class='tui-conutdown-box'>{{item.min}}</text>分
  6. <text class='tui-conutdown-box tui-countdown-bg'>{{item.sec}}</text>秒
  7. </view>

 

wxss页面代码段


    
  1. page{
  2. background: #f5f5f5;
  3. }
  4. .tui-countdown-content{
  5. height: 50px;
  6. line-height: 50px;
  7. text-align: center;
  8. background-color: #fff;
  9. margin-top: 15px;
  10. padding: 0 15px;
  11. font-size: 18px;
  12. }
  13. .tui-conutdown-box{
  14. display: inline-block;
  15. height: 26px;
  16. width: 26px;
  17. line-height: 26px;
  18. text-align: center;
  19. background:#ccc;
  20. color: #000;
  21. margin: 0 5px;
  22. }
  23. .tui-countdown-bg{
  24. background: red;
  25. color: #fff;
  26. }
  27. .container{
  28. width: 100%;
  29. display: flex;
  30. justify-content: center;
  31. }
  32. .backView{
  33. width:690rpx;
  34. background: #fff;
  35. display: flex;
  36. flex-direction: column;
  37. margin-bottom: 30rpx;
  38. }
  39. .createDate
  40. {
  41. background: #f5f5f5;
  42. padding:15rpx 15rpx 10rpx 15rpx;
  43. line-height: 50rpx;
  44. font-size: 28rpx;
  45. color: gainsboro;
  46. text-align: center;
  47. }
  48. .backViewitem1{
  49. display: flex;
  50. flex-direction: row;
  51. height: 55rpx;
  52. align-items: center;
  53. padding:8rpx 40rpx;
  54. border-bottom: 2rpx solid #f5f5f5;
  55. }
  56. .ico
  57. {
  58. width:35rpx;
  59. height:35rpx;
  60. }
  61. .name
  62. {
  63. color: #c13176;
  64. margin-left: 20rpx;
  65. font-size: 28rpx;
  66. }
  67. .details
  68. {
  69. font-size:24rpx;
  70. letter-spacing: 2rpx;
  71. }
  72. .backViewitem2{
  73. display: flex;
  74. flex-direction: row;
  75. line-height: 35rpx;
  76. min-height: 70rpx;
  77. padding: 15rpx 40rpx 10rpx 40rpx;
  78. border-bottom: 2rpx solid #f5f5f5;
  79. }
  80. .details1
  81. {
  82. color:#888;
  83. font-size:23rpx;
  84. letter-spacing: 2rpx;
  85. }

 蓝蓝设计www.lanlanwork.com )是一家专注而深入的界面设计公司,为期望卓越的国内外企业提供卓越的UI界面设计、BS界面设计 、 cs界面设计 、 ipad界面设计 、 包装设计 、 图标定制 、 用户体验 、交互设计、 网站建设 平面设计服务

分享本文至:

日历

链接

blogger

蓝蓝 http://www.lanlanwork.com

存档