From 89f7726b45bc3102b08c0aa2b9cf62e6c331515b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=97=B6=E5=90=AF=E9=BE=99?= Date: Wed, 24 Jul 2024 16:29:19 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=A0=E5=8F=82=E6=9C=80=E8=BF=913?= =?UTF-8?q?=E4=B8=AA=E6=9C=88=E5=86=85(90=E5=A4=A9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/screen/api.js | 70 +++++++++++++++++++++++++++-------------- 1 file changed, 47 insertions(+), 23 deletions(-) diff --git a/src/views/screen/api.js b/src/views/screen/api.js index a7d884b..89398ea 100644 --- a/src/views/screen/api.js +++ b/src/views/screen/api.js @@ -1,56 +1,80 @@ import axios from 'axios' +// 获取今天以及 90 天之前的日期,以 2024-06-01 的格式返回 + +function getDatesFormatted() { + // 获取今天的日期 + const today = new Date() + + // 获取90天前的日期 + const ninetyDaysAgo = new Date(today) + ninetyDaysAgo.setDate(today.getDate() - 90) + + // 格式化日期函数 + function formatDate(date) { + const year = date.getFullYear() + const month = String(date.getMonth() + 1).padStart(2, '0') + const day = String(date.getDate()).padStart(2, '0') + return `${year}-${month}-${day}` + } + + // 返回格式化后的日期 + return { + today: formatDate(today), + ninetyDaysAgo: formatDate(ninetyDaysAgo) + } +} // 单位机时统计 export const getDepartDuration = () => axios - .post('/screen_server/hpc/findTopByOrg?startDate=2024-05-01&endDate=2024-06-30') - .then(function(response) { + .post(`/screen_server/hpc/findTopByOrg?startDate=${getDatesFormatted().today}&endDate=${getDatesFormatted().ninetyDaysAgo}`) + .then(function (response) { return response.data }) - .catch(function(error) { + .catch(function (error) { console.log(error) }) // 软件机时统计 export const getSoftwareDuration = () => axios - .post('/screen_server/hpc/findTopBySoft?startDate=2024-05-01&endDate=2024-06-30') - .then(function(response) { + .post(`/screen_server/hpc/findTopBySoft?startDate=${getDatesFormatted().today}&endDate=${getDatesFormatted().ninetyDaysAgo}`) + .then(function (response) { return response.data }) - .catch(function(error) { + .catch(function (error) { console.log(error) }) // 当前在用软件 export const getInUseSoftware = () => axios - .post('/screen_server/hpc/findTopSoftList?startDate=2024-05-01&endDate=2024-06-30') - .then(function(response) { + .post(`/screen_server/hpc/findTopSoftList?startDate=${getDatesFormatted().today}&endDate=${getDatesFormatted().ninetyDaysAgo}`) + .then(function (response) { return response.data }) - .catch(function(error) { + .catch(function (error) { console.log(error) }) // 用户机时用量 export const getUserUseTrend = () => axios - .post('/screen_server/hpc/findTopByUser?startDate=2024-05-01&endDate=2024-06-30') - .then(function(response) { + .post(`/screen_server/hpc/findTopByUser?startDate=${getDatesFormatted().today}&endDate=${getDatesFormatted().ninetyDaysAgo}`) + .then(function (response) { return response.data }) - .catch(function(error) { + .catch(function (error) { console.log(error) }) // 软件集成数量 export const getSoftwareIntegrate = () => axios - .post('/screen_server/hpc/findSoftCount?startDate=2024-05-01&endDate=2024-06-30') - .then(function(response) { + .post(`/screen_server/hpc/findSoftCount?startDate=${getDatesFormatted().today}&endDate=${getDatesFormatted().ninetyDaysAgo}`) + .then(function (response) { return response.data }) - .catch(function(error) { + .catch(function (error) { console.log(error) }) @@ -58,20 +82,20 @@ export const getSoftwareIntegrate = () => export const getHelp = () => axios .post('/screen_server/hpc/help/query') - .then(function(response) { + .then(function (response) { return response.data }) - .catch(function(error) { + .catch(function (error) { console.log(error) }) // 实时利用率 export const getRealTimeUtilization = () => axios .get('/prometheus/api/v1/query?query=avg(1 - avg(rate(node_cpu_seconds_total{mode="idle"}[2m])) by (instance)) * 100') - .then(function(response) { + .then(function (response) { return response.data }) - .catch(function(error) { + .catch(function (error) { console.log(error) }) @@ -79,10 +103,10 @@ export const getRealTimeUtilization = () => export const getAverageUtilizationTrend = () => axios .get('/prometheus/api/v1/query_range') - .then(function(response) { + .then(function (response) { return response.data }) - .catch(function(error) { + .catch(function (error) { console.log(error) }) @@ -90,9 +114,9 @@ export const getAverageUtilizationTrend = () => export const getPlateformSum = () => axios .post('/screen_server/hpc/findSum') - .then(function(response) { + .then(function (response) { return response.data }) - .catch(function(error) { + .catch(function (error) { console.log(error) })