UNPKG

yapi-plugin-pl-test-dashboard

Version:

YAPI自动化测试结果数据面板插件,支持在YAPI中通过数据可视化的方式查看自动化测试结果。

105 lines (97 loc) 2.57 kB
/** *获取当前时间 * * @export * @returns */ export function getCurrentDate() { return new Date() } /** *获取本周的起止时间 * * @export * @returns */ export function getCurrentWeek() { //起止日期数组 const startStop = new Array() //获取当前时间 const currentDate = getCurrentDate() //返回date是一周中的某一天 const week = currentDate.getDay() //返回date是一个月中的某一天 const month = currentDate.getDate() //一天的毫秒数 const millisecond = 1000 * 60 * 60 * 24 //减去的天数 const minusDay = week != 0 ? week - 1 : 6 //alert(minusDay); //本周 周一 const monday = new Date(currentDate.getTime() - minusDay * millisecond) const isoMonday = monday.toISOString() //本周 周日 const sunday = new Date(monday.getTime() + 6 * millisecond) const isoSunday = sunday.toISOString() //添加本周时间 startStop.push(isoMonday) //本周起始时间 //添加本周最后一天时间 startStop.push(isoSunday) //本周终止时间 //返回 return startStop } /** *获取本月起止时间 * * @export * @returns */ export function getCurrentMonth() { //起止日期数组 const startStop = new Array() //获取当前时间 const currentDate = getCurrentDate() //获得当前月份0-11 let currentMonth = currentDate.getMonth() //获得当前年份4位年 let currentYear = currentDate.getFullYear() //求出本月第一天 const firstDay = new Date(currentYear, currentMonth, 1) const isoFirstDay = firstDay.toISOString() //当为12月的时候年份需要加1 //月份需要更新为0 也就是下一年的第一个月 if (currentMonth == 11) { currentYear++ currentMonth = 0 //就为 } else { //否则只是月份增加,以便求的下一月的第一天 currentMonth++ } //一天的毫秒数 const millisecond = 1000 * 60 * 60 * 24 //下月的第一天 const nextMonthDayOne = new Date(currentYear, currentMonth, 1) //求出上月的最后一天 const lastDay = new Date(nextMonthDayOne.getTime() - millisecond) const isoLastDay = lastDay.toISOString() //添加至数组中返回 startStop.push(isoFirstDay) startStop.push(isoLastDay) //返回 return startStop } /** *从URL获取projectId * * @export * @returns */ export function getProjectId() { const url = window.location.href const arrUrl = url.split('//') if (arrUrl.length === 2) { const parameterUrl = arrUrl[1].split('/') return parameterUrl[parameterUrl.length - 2] } return '' }