123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- var businessType = require('../public/business-type.js')
- var _debug = false
- function isDebug() {
- return _debug
- }
- function debugLog(e) {
- if (_debug) {
- console.log(e)
- }
- }
- function action(f, t) {
- var after = t || 500
- return function () {
- var app = getApp()
- if (app.globalData.isClicked) {
- return
- }
- app.globalData.isClicked = true
- f.apply(this, arguments)
- setTimeout(function() {
- app.globalData.isClicked = false
- }, after)
- }
- }
- function getPhone() {
- var tel
- try {
- tel = wx.getStorageSync(key.StorageKey.servicePhone)
- } catch (e) {
- }
- if (!tel) {
- tel = '400-881-9211'
- }
- return tel
- }
- function changeTimeToNumber(t) {
- return t.slice(0, 4) + t.slice(5, 7)
- }
- Date.prototype.format = function (format) {
- var date = {
- "M+": this.getMonth() + 1,
- "d+": this.getDate(),
- "h+": this.getHours(),
- "m+": this.getMinutes(),
- "s+": this.getSeconds(),
- "q+": Math.floor((this.getMonth() + 3) / 3),
- "S+": this.getMilliseconds()
- };
- if (/(y+)/i.test(format)) {
- format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
- }
- for (var k in date) {
- if (new RegExp("(" + k + ")").test(format)) {
- format = format.replace(RegExp.$1, RegExp.$1.length == 1
- ? date[k] : ("00" + date[k]).substr(("" + date[k]).length));
- }
- }
- return format;
- }
- /*时间差比较
- *interval :D表示查询精确到天数的之差
- interval :H表示查询精确到小时之差
- interval :M表示查询精确到分钟之差
- interval :S表示查询精确到秒之差
- interval :T表示查询精确到毫秒之差
- */
- function dateDiff(interval, date1, date2) {
- var objInterval = { 'D': 1000 * 60 * 60 * 24, 'H': 1000 * 60 * 60, 'M': 1000 * 60, 'S': 1000, 'T': 1 };
- interval = interval.toUpperCase();
- var dt1 = new Date(Date.parse(date1.replace(/-/g, '/')));
- var dt2 = new Date(Date.parse(date2.replace(/-/g, '/')));
- try {
- // debugLog(dt2.getTime() - dt1.getTime());
- // debugLog('objInterval.'+interval);
- // debugLog((dt2.getTime() - dt1.getTime()) / eval_r('objInterval.'+interval));
- var d = (dt2.getTime() - dt1.getTime()) / objInterval[interval]
- var _d = d | 0
- if (d != _d) {
- return _d + 1;
- }
- return _d;
- }
- catch (e) {
- return 0;
- }
- }
- function showFailTips (err, p) {
- if (err.code == businessType.NetworkErrorCode.netwrokMiss) {
- wx.showToast({
- title: err.msg,
- icon: 'none'
- })
- } else if (err.code == businessType.NetworkErrorCode.connectErrorMessage) {
- wx.showToast({
- title: err.msg,
- icon: 'none'
- })
- } else if (p) {
- wx.showToast({
- title: p,
- icon: 'none'
- })
- }
- }
- function selectFrom(lowerValue, upperValue) {
- var choice = upperValue - lowerValue + 1;
- return Math.floor(Math.random() * choice + lowerValue);
- }
- module.exports = {
- debugLog: debugLog,
- action: action,
- isDebug: isDebug,
- getPhone: getPhone,
- changeTimeToNumber: changeTimeToNumber,
- showFailTips: showFailTips,
- dateDiff: dateDiff,
- selectFrom: selectFrom
- }
|