<!--报警时间-->
<div class="center_box">
<div class="center_top_text">报警时间</div>
<el-date-picker
style="width: 400px"
v-model="date_array"
type="daterange"
range-separator="-"
value-format="yyyy-MM-dd"
start-placeholder="开始日期"
end-placeholder="结束日期">
</el-date-picker>
</div>
引入DateUtil文件
function dateFtt(fmt,date)
{ //author: meizz
var o = {
"M+" : date.getMonth()+1, //月份
"d+" : date.getDate(), //日
"h+" : date.getHours(), //小时
"m+" : date.getMinutes(), //分
"s+" : date.getSeconds(), //秒
"q+" : Math.floor((date.getMonth()+3)/3), //季度
"S" : date.getMilliseconds() //毫秒
};
if(/(y+)/.test(fmt))
fmt=fmt.replace(RegExp.$1, (date.getFullYear()+"").substr(4 - RegExp.$1.length));
for(var 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 compare_date(start_date, end_date) {
let format_start_date = new Date(start_date);
let format_end_date = new Date(end_date);
if (format_start_date > format_end_date) {
return "big";
} else if (format_start_date < format_end_date) {
return "small";
} else {
return "equal";
}
}
export {
dateFtt,
compare_date
}
在需要编辑的页面引入{dataFtt},否则当前时间无法获取
import {httpUrl} from "../../HttpUtil/HttpUtil";
import axios from "axios/index";
import {dateFtt} from "../../DateUtil";
let unit_login = "";
var date_array = '';
export default {
name: "SettingExceptions",
data() {
return {
date_array:'',
}
},
mounted: function(){
this.init_group_date_time_week();//操作时间
},
methods:{
//获取当前时间
init_group_date_time_week: function () {
var date = new Date();
var now_date = dateFtt("yyyy-MM-dd", date);
date.setMonth(date.getMonth()-1);
var last_date = dateFtt("yyyy-MM-dd", date);
this.date_array = [last_date, now_date];
date_array = [last_date, now_date];
},
}
}
效果: