| | |
| | | const formatTime = (dateString: Date) => { |
| | | let date = new Date(dateString); |
| | | 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(':') |
| | | ) |
| | | import * as dayjs from "dayjs"; |
| | | const formatTime = (dateString: Date,format: string ='YYYY-MM-DD HH:mm') => { |
| | | return dayjs(dateString).format(format); |
| | | } |
| | | |
| | | const formatNumber = (n: number) => { |
| | | const s = n.toString() |
| | | return s[1] ? s : '0' + s |
| | | } |
| | | // const formatTime2 = (dateString: Date) => { |
| | | // let date = new Date(dateString); |
| | | // 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: number) => { |
| | | // const s = n.toString() |
| | | // return s[1] ? s : '0' + s |
| | | // } |
| | | |
| | | const to = (promise:Promise<any>)=>{ |
| | | return promise.then((res:any)=>{ |
| | |
| | | }); |
| | | } |
| | | |
| | | const debounce = (fn:()=>{},delay:number = 500)=>{ |
| | | const debounce = (fn:()=>{},delay:number = 200)=>{ |
| | | let timer:any = null; |
| | | return function () { |
| | | if (timer) clearTimeout(timer); |
| | |
| | | return new Proxy(target, handler) |
| | | |
| | | } |
| | | |
| | | const scrollToError = (selector:string, errorMsg:string, duration:number = 3000)=>{ |
| | | wx.pageScrollTo({ |
| | | selector, |
| | | duration: 300 |
| | | }) |
| | | wx.showToast({ |
| | | title: errorMsg, |
| | | icon: 'none', |
| | | duration |
| | | }) |
| | | } |
| | | export default{ |
| | | formatTime, |
| | | to, |
| | |
| | | getLocation, |
| | | getAuthorizeInfo, |
| | | setShopName, |
| | | watchObj |
| | | watchObj, |
| | | scrollToError |
| | | } |