1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- // 处理多次点击
- function noMultipleClicks(methods) {
- //复制this对象为that指向当时的this,防止找不到所需调用页面的页面对象
- let that = this;
- if (that.noClick) {
- that.noClick = false;
- //点击方法
- methods();
- setTimeout(function() {
- that.noClick = true;
- }, 2000)
- } else {
- console.log("请稍后点击")
- }
- }
- //格式化时间方法
- function dateUtil(fmt) {
- let o = {
- "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+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
- for (let k in o)
- if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) :
- (("00" + o[k]).substr(("" + o[k]).length)));
- return fmt;
- }
- //获取近几天时间数组
- function getRecentDateArray(day) {
- let recentDate = new Array();
- for (let i = day; i > 0; i--) {
- let dayTime = new Date();
- dayTime.setDate(dayTime.getDate() - i + 1);
- recentDate.push(dayTime.format("M-dd"));
- }
- return recentDate
- }
- //时间戳转换为时间
- function timeStampToTime(timestamp) {
- timestamp = timestamp ? timestamp : null;
- let date = new Date(timestamp); //时间戳为10位需*1000,时间戳为13位的话不需乘1000
- let Y = date.getFullYear() + '-';
- let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
- let D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' ';
- let h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
- let m = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes();
- let s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
- // return Y + M + D + h + m + s;
- return M + D + h + m;
- }
- export default {
- noMultipleClicks,
- dateUtil,
- getRecentDateArray,
- timeStampToTime
- }
|