You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
127 lines
3.2 KiB
127 lines
3.2 KiB
const formatTime = date => {
|
|
const year = date.getFullYear()
|
|
const month = date.getMonth() + 1
|
|
const day = date.getDate()
|
|
const hour = date.getHours()
|
|
const minute = date.getMinutes()
|
|
const second = date.getSeconds()
|
|
return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
|
|
}
|
|
|
|
const formatNumber = n => {
|
|
n = n.toString()
|
|
return n[1] ? n : '0' + n
|
|
}
|
|
|
|
function beforeDay(day, format) {
|
|
var date = new Date()
|
|
var formateArr = ['Y', 'M', 'D', 'h', 'm', 's'];
|
|
var returnArr = [];
|
|
returnArr.push(date.getFullYear());
|
|
returnArr.push(formatNumber(date.getMonth() + 1));
|
|
returnArr.push(formatNumber(date.getDate() - day));
|
|
returnArr.push(formatNumber(date.getHours()));
|
|
returnArr.push(formatNumber(date.getMinutes()));
|
|
returnArr.push(formatNumber(date.getSeconds()));
|
|
for (var i in returnArr) {
|
|
format = format.replace(formateArr[i], returnArr[i]);
|
|
}
|
|
return format;
|
|
}
|
|
|
|
function formatDate(date, format) {
|
|
var formateArr = ['Y', 'M', 'D', 'h', 'm', 's'];
|
|
var returnArr = [];
|
|
returnArr.push(date.getFullYear());
|
|
returnArr.push(formatNumber(date.getMonth() + 1));
|
|
returnArr.push(formatNumber(date.getDate()));
|
|
returnArr.push(formatNumber(date.getHours()));
|
|
returnArr.push(formatNumber(date.getMinutes()));
|
|
returnArr.push(formatNumber(date.getSeconds()));
|
|
for (var i in returnArr) {
|
|
format = format.replace(formateArr[i], returnArr[i]);
|
|
}
|
|
return format;
|
|
}
|
|
|
|
function json2Form(json) {
|
|
var str = [];
|
|
for (var p in json) {
|
|
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(json[p]));
|
|
}
|
|
return str.join("&");
|
|
}
|
|
|
|
function isEmpty(val) {
|
|
return typeof val === 'undefined' || val === '' || val === null
|
|
}
|
|
|
|
function showTip(content) {
|
|
wx.showModal({
|
|
content: content,
|
|
showCancel: false
|
|
})
|
|
}
|
|
|
|
function showToast(content) {
|
|
if(isEmpty(content)){
|
|
return
|
|
}
|
|
wx.showToast({ title: content, icon: 'none' });
|
|
}
|
|
|
|
function extend(obj) {
|
|
var o = {},
|
|
attr = Array.prototype.slice.call(arguments).slice(1);
|
|
attr.forEach(function (val, index) {
|
|
if (val in obj) { o[val] = obj[val]; }
|
|
});
|
|
return o;
|
|
}
|
|
|
|
function playDing() {
|
|
const innerAudioContext = wx.createInnerAudioContext();//新建一个createInnerAudioContext();
|
|
innerAudioContext.autoplay = true;//音频自动播放设置
|
|
innerAudioContext.src = '/assets/raw/ptt_playfinish.mp3';//链接到音频的地址
|
|
innerAudioContext.onPlay(() => { });//播放音效
|
|
innerAudioContext.onError((res) => {//打印错误
|
|
console.log(res.errMsg);//错误信息
|
|
console.log(res.errCode);//错误码
|
|
})
|
|
}
|
|
|
|
function showBackToast(content) {
|
|
if (isEmpty(content)) {
|
|
return
|
|
}
|
|
wx.showToast({
|
|
title: content,
|
|
icon: 'none',
|
|
duration: 1000,
|
|
success: function () {
|
|
setTimeout(function () {
|
|
wx.navigateBack()
|
|
}, 1000)
|
|
}
|
|
})
|
|
}
|
|
|
|
/* 验证手机号 */
|
|
function checkPhone(phone) {
|
|
var re = /^1\d{10}$/
|
|
return re.test(phone) && phone.length === 11
|
|
}
|
|
|
|
module.exports = {
|
|
isEmpty: isEmpty,
|
|
extend: extend,
|
|
formatTime: formatTime,
|
|
beforeDay: beforeDay,
|
|
formatDate: formatDate,
|
|
json2Form: json2Form,
|
|
showToast: showToast,
|
|
showTip: showTip,
|
|
playDing: playDing,
|
|
showBackToast: showBackToast,
|
|
checkPhone: checkPhone
|
|
}
|