diff --git a/src/utils/formatDate.js b/src/utils/formatDate.js new file mode 100644 index 0000000..3846f28 --- /dev/null +++ b/src/utils/formatDate.js @@ -0,0 +1,63 @@ +export function formatDateYMD (time) { + let date = new Date(time * 1000) + let m = (date.getMonth() + 1) < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1 + let d = date.getDate() < 10 ? '0' + date.getDate() : date.getDate() + return date.getFullYear() + '-' + m + '-' + d +} +// new Date() 格式化为 ’2018-10-11‘ +export function dateToString (date, format) { + if (!date) return '' + format = format || 'y-m-d' + switch (format) { + case 'y-m': + return date.getFullYear() + '-' + datePad(date.getMonth() + 1, 2) + case 'y-m-d': + return date.getFullYear() + '-' + datePad(date.getMonth() + 1, 2) + '-' + datePad(date.getDate(), 2) + case 'h-m-s': + return datePad(date.getHours(), 2) + ':' + datePad(date.getMinutes(), 2) + ':' + datePad(date.getSeconds(), 2) + case 'y-m-d-h-m-s': + return date.getFullYear() + '-' + datePad(date.getMonth() + 1, 2) + '-' + datePad(date.getDate(), 2) + ' ' + datePad(date.getHours(), 2) + ':' + datePad(date.getMinutes(), 2) + ':' + datePad(date.getSeconds(), 2) + } +} +function datePad (num, n) { + if ((num + '').length >= n) { return num } // 一位数 + return '0' + num // 两位数 +} + +export function getYesterDay () { // 默认显示昨天 + const ctmonth = new Date() + ctmonth.setTime(ctmonth.getTime() - 3600 * 1000 * 24) + return ctmonth +} + +export function getToday () { + var date = new Date() + var year = date.getFullYear() + var month = date.getMonth() + 1 + var day = date.getDate() + if (month < 10) { + month = '0' + month + } + if (day < 10) { + day = '0' + day + } + var nowDate = year + '-' + month + '-' + day + return nowDate +} + +export function getLastWeek () { // 默认显示上周 + const ctmonth = new Date() + ctmonth.setTime(ctmonth.getTime() - 3600 * 1000 * 24 * 7) + return ctmonth +} +export function getLastMonth () { // 默认显示上个月 + const ctmonth = new Date() + ctmonth.setTime(ctmonth.getTime() - 3600 * 1000 * 24 * 30) + return ctmonth +} + +export function getYear () { + const year = new Date().getFullYear() + return year + // return 2020 +} diff --git a/src/utils/formatDate.js b/src/utils/formatDate.js new file mode 100644 index 0000000..3846f28 --- /dev/null +++ b/src/utils/formatDate.js @@ -0,0 +1,63 @@ +export function formatDateYMD (time) { + let date = new Date(time * 1000) + let m = (date.getMonth() + 1) < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1 + let d = date.getDate() < 10 ? '0' + date.getDate() : date.getDate() + return date.getFullYear() + '-' + m + '-' + d +} +// new Date() 格式化为 ’2018-10-11‘ +export function dateToString (date, format) { + if (!date) return '' + format = format || 'y-m-d' + switch (format) { + case 'y-m': + return date.getFullYear() + '-' + datePad(date.getMonth() + 1, 2) + case 'y-m-d': + return date.getFullYear() + '-' + datePad(date.getMonth() + 1, 2) + '-' + datePad(date.getDate(), 2) + case 'h-m-s': + return datePad(date.getHours(), 2) + ':' + datePad(date.getMinutes(), 2) + ':' + datePad(date.getSeconds(), 2) + case 'y-m-d-h-m-s': + return date.getFullYear() + '-' + datePad(date.getMonth() + 1, 2) + '-' + datePad(date.getDate(), 2) + ' ' + datePad(date.getHours(), 2) + ':' + datePad(date.getMinutes(), 2) + ':' + datePad(date.getSeconds(), 2) + } +} +function datePad (num, n) { + if ((num + '').length >= n) { return num } // 一位数 + return '0' + num // 两位数 +} + +export function getYesterDay () { // 默认显示昨天 + const ctmonth = new Date() + ctmonth.setTime(ctmonth.getTime() - 3600 * 1000 * 24) + return ctmonth +} + +export function getToday () { + var date = new Date() + var year = date.getFullYear() + var month = date.getMonth() + 1 + var day = date.getDate() + if (month < 10) { + month = '0' + month + } + if (day < 10) { + day = '0' + day + } + var nowDate = year + '-' + month + '-' + day + return nowDate +} + +export function getLastWeek () { // 默认显示上周 + const ctmonth = new Date() + ctmonth.setTime(ctmonth.getTime() - 3600 * 1000 * 24 * 7) + return ctmonth +} +export function getLastMonth () { // 默认显示上个月 + const ctmonth = new Date() + ctmonth.setTime(ctmonth.getTime() - 3600 * 1000 * 24 * 30) + return ctmonth +} + +export function getYear () { + const year = new Date().getFullYear() + return year + // return 2020 +} diff --git a/src/views/alarmManage/listAlarmNow.vue b/src/views/alarmManage/listAlarmNow.vue index 6312059..7234b37 100644 --- a/src/views/alarmManage/listAlarmNow.vue +++ b/src/views/alarmManage/listAlarmNow.vue @@ -3,41 +3,42 @@ - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + +
@@ -93,7 +94,7 @@ import { getAlarmList, batchExportAlarm, getAlarmType, getAlarmContentType } from '@/api/alarm' import HandlePrompt from './components/HandlePrompt' import { isOperation } from '@/utils/permission' - +import { dateToString, getLastWeek } from '@/utils/formatDate' export default { name: 'ListAlarmNow', components: { HandlePrompt, infoWell }, @@ -219,6 +220,9 @@ }, created() { console.log('now created') + this.listQuery.endTime = dateToString(new Date(), 'y-m-d') + ' 23:59:59' + this.listQuery.beginTime = dateToString(getLastWeek(), 'y-m-d') + ' 00:00:00' + this.timeRange = [this.listQuery.beginTime, this.listQuery.endTime] this.fetchAlarmType() this.fetchData()// 获取数据 }, @@ -227,9 +231,9 @@ this.listQuery.keywords = '' this.listQuery.alarmType = '' this.listQuery.alarmContentType = '' - this.listQuery.beginTime = '' - this.listQuery.endTime = '' - this.timeRange = [] + this.listQuery.endTime = dateToString(new Date(), 'y-m-d') + ' 23:59:59' + this.listQuery.beginTime = dateToString(getLastWeek(), 'y-m-d') + ' 00:00:00' + this.timeRange = [this.listQuery.beginTime, this.listQuery.endTime] this.fetchData(false) }, methods: { diff --git a/src/utils/formatDate.js b/src/utils/formatDate.js new file mode 100644 index 0000000..3846f28 --- /dev/null +++ b/src/utils/formatDate.js @@ -0,0 +1,63 @@ +export function formatDateYMD (time) { + let date = new Date(time * 1000) + let m = (date.getMonth() + 1) < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1 + let d = date.getDate() < 10 ? '0' + date.getDate() : date.getDate() + return date.getFullYear() + '-' + m + '-' + d +} +// new Date() 格式化为 ’2018-10-11‘ +export function dateToString (date, format) { + if (!date) return '' + format = format || 'y-m-d' + switch (format) { + case 'y-m': + return date.getFullYear() + '-' + datePad(date.getMonth() + 1, 2) + case 'y-m-d': + return date.getFullYear() + '-' + datePad(date.getMonth() + 1, 2) + '-' + datePad(date.getDate(), 2) + case 'h-m-s': + return datePad(date.getHours(), 2) + ':' + datePad(date.getMinutes(), 2) + ':' + datePad(date.getSeconds(), 2) + case 'y-m-d-h-m-s': + return date.getFullYear() + '-' + datePad(date.getMonth() + 1, 2) + '-' + datePad(date.getDate(), 2) + ' ' + datePad(date.getHours(), 2) + ':' + datePad(date.getMinutes(), 2) + ':' + datePad(date.getSeconds(), 2) + } +} +function datePad (num, n) { + if ((num + '').length >= n) { return num } // 一位数 + return '0' + num // 两位数 +} + +export function getYesterDay () { // 默认显示昨天 + const ctmonth = new Date() + ctmonth.setTime(ctmonth.getTime() - 3600 * 1000 * 24) + return ctmonth +} + +export function getToday () { + var date = new Date() + var year = date.getFullYear() + var month = date.getMonth() + 1 + var day = date.getDate() + if (month < 10) { + month = '0' + month + } + if (day < 10) { + day = '0' + day + } + var nowDate = year + '-' + month + '-' + day + return nowDate +} + +export function getLastWeek () { // 默认显示上周 + const ctmonth = new Date() + ctmonth.setTime(ctmonth.getTime() - 3600 * 1000 * 24 * 7) + return ctmonth +} +export function getLastMonth () { // 默认显示上个月 + const ctmonth = new Date() + ctmonth.setTime(ctmonth.getTime() - 3600 * 1000 * 24 * 30) + return ctmonth +} + +export function getYear () { + const year = new Date().getFullYear() + return year + // return 2020 +} diff --git a/src/views/alarmManage/listAlarmNow.vue b/src/views/alarmManage/listAlarmNow.vue index 6312059..7234b37 100644 --- a/src/views/alarmManage/listAlarmNow.vue +++ b/src/views/alarmManage/listAlarmNow.vue @@ -3,41 +3,42 @@ - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + +
@@ -93,7 +94,7 @@ import { getAlarmList, batchExportAlarm, getAlarmType, getAlarmContentType } from '@/api/alarm' import HandlePrompt from './components/HandlePrompt' import { isOperation } from '@/utils/permission' - +import { dateToString, getLastWeek } from '@/utils/formatDate' export default { name: 'ListAlarmNow', components: { HandlePrompt, infoWell }, @@ -219,6 +220,9 @@ }, created() { console.log('now created') + this.listQuery.endTime = dateToString(new Date(), 'y-m-d') + ' 23:59:59' + this.listQuery.beginTime = dateToString(getLastWeek(), 'y-m-d') + ' 00:00:00' + this.timeRange = [this.listQuery.beginTime, this.listQuery.endTime] this.fetchAlarmType() this.fetchData()// 获取数据 }, @@ -227,9 +231,9 @@ this.listQuery.keywords = '' this.listQuery.alarmType = '' this.listQuery.alarmContentType = '' - this.listQuery.beginTime = '' - this.listQuery.endTime = '' - this.timeRange = [] + this.listQuery.endTime = dateToString(new Date(), 'y-m-d') + ' 23:59:59' + this.listQuery.beginTime = dateToString(getLastWeek(), 'y-m-d') + ' 00:00:00' + this.timeRange = [this.listQuery.beginTime, this.listQuery.endTime] this.fetchData(false) }, methods: { diff --git a/src/views/alarmManage/listAlarmRecords.vue b/src/views/alarmManage/listAlarmRecords.vue index 3f9c72a..9a51036 100644 --- a/src/views/alarmManage/listAlarmRecords.vue +++ b/src/views/alarmManage/listAlarmRecords.vue @@ -82,6 +82,7 @@