1 // 加载配置文件
2 const config = require('config.js');
3 var app=getApp();
4 module.exports = {
5 62 /*
63 *时间戳格式修改公共函数
64 *timestamp为后台传递的时间戳
65 *type为时间显示的不同方式
66 *bol:判断是否需要时分秒默认不要
67 *主要用来分割年月日
68 *后期可以扩展年月日时分秒。
69 *by:张涛 20180305
70 */
71
72 setTime:function(timestamp,type,bol){
73 var unixTimestamp = new Date(timestamp) ;
74 // 首先判断是否需要时分秒
75 if (bol) {
76 //设置不同的格式
77 Date.prototype.toLocaleString = function() {
78 return this.getFullYear() + type + (this.getMonth() + 1) + type + this.getDate()+' '+ this.getHours() + ":" + this.getMinutes();
79 };
80 }else{
81 //设置不同的格式
82 Date.prototype.toLocaleString = function() {
83 return this.getFullYear() + type + (this.getMonth() + 1) + type + this.getDate();
84 };
85 }
86 return unixTimestamp.toLocaleString();
87 },
88 // 时间戳倒计时函数,根据时间戳差值计算剩余时间
89 /*
90 *时间:timestamp(非毫秒级),fn回调函数,参数可定义
91 *暂时为天小时分钟秒,后期可拓展by:张涛20180305
92 *
93 *第一种只进行倒计时解析
94 *第二种倒计时实时显示
95 */
96 downTime:function(timestamp,type,fn){
97 // 只解析剩余时间
98 if (type==1) {
99 var time={
100 day:'',
101 hour:'',
102 minute:'',
103 second:''
104 }
105 time.day=Math.floor(timestamp / (24*3600));
106 time.hour=Math.floor((timestamp-time.day*24*3600)/3600);
107 time.minute=Math.floor((timestamp-time.day*24*3600-time.hour*3600)/60);
108 time.second=Math.floor(timestamp-time.day*24*3600-time.hour*3600-time.minute*60);
109 return time;
110 }else if (type==2) {
111 var day,hour,minute,second,time;
112 // 解析剩余时间,并进行动态显示
113 var timer = setInterval(function () {
114 timestamp--;
115 if (time == 0) {
116 clearInterval(timer)
117 }else{
118 day=Math.floor(timestamp / (24*3600));
119 hour=Math.floor((timestamp-day*24*3600)/3600);
120 minute=Math.floor((timestamp-day*24*3600-hour*3600)/60);
121 second=Math.floor(timestamp-day*24*3600-hour*3600-minute*60);
122 }
123 time={
124 day:day,
125 hour:hour,
126 minute:minute,
127 second:second
128 }
129 //倒计时的回调函数(参数)天,时,分,秒
130 fn(time);
131 }, 1000)
132 }
133 },
134 /*
135 *检测用户是否登录的函数
136 *
137 */
138 checkLogin:function(){
139 if (app.globalData.loginInfo==''||app.globalData.loginInfo=='underfind'||app.globalData.loginInfo==null) {
140 wx.navigateTo({
141 url:'/pages/login/login'
142 })
143 // 阻止页面逻辑继续执行
144 return false;
145 }
146 return true;
147 }
148
149 }