| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- import convert from '../convert'
- export default {
- getDateRange(n = 30, endn = 0) {
- // 获取当前日期
- var myDate = new Date(Date.now() - 1000 * 60 * 60 * 24 * endn)
- var nowY = myDate.getFullYear()
- var nowM = myDate.getMonth() + 1
- var nowD = myDate.getDate()
- var nowH = myDate.getHours() < 10 ? '0' + myDate.getHours() : myDate.getHours()
- var nowMi = myDate.getMinutes() < 10 ? '0' + myDate.getMinutes() : myDate.getMinutes()
- var nowS = myDate.getSeconds() < 10 ? '0' + myDate.getSeconds() : myDate.getSeconds()
- var enddate = nowY + '-' + (nowM < 10 ? '0' + nowM : nowM) + '-' + (nowD < 10 ? '0' + nowD : nowD) + ' ' + nowH + ':' + nowMi + ':' + nowS
- // 获取三十天前日期
- var lw = new Date(myDate - 1000 * 60 * 60 * 24 * n)
- var lastY = lw.getFullYear()
- var lastM = lw.getMonth() + 1
- var lastD = lw.getDate()
- var lastH = lw.getHours() < 10 ? '0' + lw.getHours() : lw.getHours()
- var lastMi = lw.getMinutes() < 10 ? '0' + lw.getMinutes() : lw.getMinutes()
- var lastS = lw.getSeconds() < 10 ? '0' + lw.getSeconds() : lw.getSeconds()
- var startdate = lastY + '-' + (lastM < 10 ? '0' + lastM : lastM) + '-' + (lastD < 10 ? '0' + lastD : lastD) + ' ' + lastH + ':' + lastMi + ':' + lastS
- return { startdate, enddate }
- },
- getFullFileUrl(url) {
- return url ? process.env.VUE_APP_FILE_URL + url : ''
- },
- isTypeof(option) {
- var value = Object.prototype.toString.call(option)
- if (value === '[object Undefined]') return 'undefined'
- else if (value === '[object String]') return 'string'
- else if (value === '[object Boolean]') return 'boolean'
- else if (value === '[object Number]') return 'number'
- else if (value === '[object Null]') return 'null'
- else if (value === '[object Object]') return 'object'
- else if (value === '[object Array]') return 'array'
- else if (value === '[object Date]') return 'date'
- else if (value === '[object RegExp]') return 'regexp'
- else if (value === '[object Function]') return 'function'
- },
- formateTData(date, fmt) { // 字符串
- if (date) {
- if (fmt == 'date') {
- return this.formatDate(date, 'yyyy-MM-dd')
- } else if (fmt == 'all') {
- return this.formatDate(date, 'yyyy-MM-dd hh:mm:ss')
- } else if (fmt == 'hour') {
- return this.formatDate(date, 'yyyy-MM-dd hh')
- } else if (fmt == 'time') {
- return this.formatDate(date, 'hh:mm')
- } else {
- return this.formatDate(date, 'yyyy-MM-dd hh:mm')
- }
- }
- return ''
- },
- formatDate(date, fmt = 'yyyy-MM-dd hh:mm:ss') { // date对象
- if (convert.isNull(date)) return date
- var padLeftZero = function (str) {
- return ('00' + str).substr(str.length)
- }
- if (this.isTypeof(date) === 'string') {
- let tmpDate = date.replace(/-/g, '/')
- tmpDate = tmpDate.replace(/T/g, ' ')
- date = new Date(tmpDate)
- } else if (this.isTypeof(date) == 'number') {
- date = new Date(date)
- }
- if (/(y+)/.test(fmt)) {
- fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length))
- }
- const o = {
- 'M+': date.getMonth() + 1,
- 'd+': date.getDate(),
- 'h+': date.getHours(),
- 'm+': date.getMinutes(),
- 's+': date.getSeconds()
- }
- for (var k in o) {
- if (new RegExp(`(${k})`).test(fmt)) {
- var str = o[k] + ''
- fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? str : padLeftZero(str))
- }
- }
- return fmt
- }
- }
|