diff --git a/src/api/production/index.ts b/src/api/production/index.ts index 5159a3d..2d07362 100644 --- a/src/api/production/index.ts +++ b/src/api/production/index.ts @@ -60,7 +60,7 @@ export function queryJldDataByJldID(params : object) { // 获取计量点五分 export function queryJldRbDataByJldID(params : object) { // 获取计量点日报数据 return http({ - url: 'http://10.75.166.6:9999/Gyk/jldls/cxcSssjLssjJldls/getLssjByJldId', + url: '/tbqr/cxcScdtRbTbqr/listJldZongHe', method: 'GET', data: params }) diff --git a/src/pages-production/shishishuju/chart/lssjChart.vue b/src/pages-production/shishishuju/chart/lssjChart.vue index 48a128f..bd002e6 100644 --- a/src/pages-production/shishishuju/chart/lssjChart.vue +++ b/src/pages-production/shishishuju/chart/lssjChart.vue @@ -12,15 +12,19 @@ + {{startTime}} - + + + - 前一天 - 后一天 + 上一月 + 本月 + 后一月 查询数据 生成曲线 @@ -29,15 +33,15 @@ - - - + + + - @@ -65,10 +69,10 @@ { name: '日流量', - field: 'jrl', + field: 'ljql', min: '0', - max: '50000', - unit: 'm³' + max: '500000', + unit: '10^4m³' } ]) @@ -82,19 +86,21 @@ const drawLineFlag = ref(false) function handleQuery() { - - const jldid = props.jldData.id; + const dwmc = props.jldData.qu; + const zcmc = props.jldData.zhan; + const jldmc = props.jldData.jldname; + console.log(dwmc, zcmc, jldmc) queryJldRbDataByJldID({ - jldId: jldid, + fenzu: 'a.scrq', + dwmc: dwmc, + zcmc: zcmc, + jldname: jldmc, startTime: startTime.value, endTime: endTime.value }).then(res => { - chartData.value = JSON.parse(res.result) + console.log(res) + chartData.value = res.result - chartData.value.forEach(item => { - item.createTime = formatDate(item.createTime, "YYYY-MM-DD HH:mm ss") - }) - console.log(123, chartData.value) }) @@ -105,58 +111,60 @@ } // 前一天 - 以当前选择的起始日期为基准计算 function handleForward() { - // 使用当前选择的开始时间作为基准,而不是系统当前时间 - lssjTimeRange.value = getDefaultTimeRange(-1); + const now = new Date(startTime.value); + now.setMonth(now.getMonth() - 1); + + const year = now.getFullYear(); + const month = now.getMonth(); + + const firstDay = new Date(year, month, 1); + const lastDay = new Date(year, month + 1, 0); + + startTime.value = formatDate(firstDay, "YYYY-MM-DD"); + endTime.value = formatDate(lastDay, "YYYY-MM-DD"); + + lssjTimeRange.value = [formatDate(firstDay, "YYYY-MM-DD"), formatDate(lastDay, "YYYY-MM-DD")]; + getTime(); // 触发时间变更事件 + } + + // 本月 + function handleThis() { + + lssjTimeRange.value = getDefaultTimeRange() + getTime(); // 触发时间变更事件 } // 后一天 function handleNext() { - // 获取当前选择的开始时间 - const currentStart = new Date(startTime.value); - // 获取今天8点的时间对象 - const today8AM = new Date(); - today8AM.setHours(8, 0, 0, 0); + const now = new Date(startTime.value); + now.setMonth(now.getMonth() + 1); - // 允许切换到今天及之前的日期范围 - if (currentStart < today8AM || isSameDay(currentStart, today8AM)) { - lssjTimeRange.value = getDefaultTimeRange(1); - } else { - // 可添加提示:已经是最新数据 - uni.showToast({ - title: '已是最新数据', - icon: 'none', - duration: 1500 - }); - } + const year = now.getFullYear(); + const month = now.getMonth(); + + const firstDay = new Date(year, month, 1); + const lastDay = new Date(year, month + 1, 0); + startTime.value = formatDate(firstDay, "YYYY-MM-DD"); + endTime.value = formatDate(lastDay, "YYYY-MM-DD"); + + lssjTimeRange.value = [formatDate(firstDay, "YYYY-MM-DD"), formatDate(lastDay, "YYYY-MM-DD")]; + getTime(); // 触发时间变更事件 } // 获取指定日期偏移的时间范围(每天8:00至次日7:59) - const getDefaultTimeRange = (days) => { - // 防止原日期对象被污染,使用当前选择的开始时间作为基准 - var baseDate; - if (startTime.value && new Date(startTime.value).toString() !== 'Invalid Date') { - baseDate = new Date(startTime.value); - } else { - // 如果选择的时间无效,则使用当前时间作为 fallback - baseDate = new Date(); - } + const getDefaultTimeRange = () => { + const now = new Date(); + const year = now.getFullYear(); + const month = now.getMonth(); - // 计算目标日期(基础日期 + 偏移天数) - const targetDate = new Date(baseDate); - targetDate.setDate(baseDate.getDate() + days); - - // 构建开始时间:目标日期的8:00:00 - const start = new Date(targetDate); - start.setHours(8, 0, 0, 0); - - // 构建结束时间:目标日期+1天的7:59:59 - const end = new Date(targetDate); - end.setDate(targetDate.getDate() + 1); - end.setHours(7, 59, 59, 0); + // 当月第一天 + const start = new Date(year, month, 1); + // 当月最后一天 + const end = new Date(year, month + 1, 0); // 格式化时间字符串 - const formattedStart = formatDate(start, 'YYYY-MM-DD HH:mm:ss'); - const formattedEnd = formatDate(end, 'YYYY-MM-DD HH:mm:ss'); + const formattedStart = formatDate(start, 'YYYY-MM-DD'); + const formattedEnd = formatDate(end, 'YYYY-MM-DD'); // 更新响应式变量 startTime.value = formattedStart; @@ -165,12 +173,7 @@ return [formattedStart, formattedEnd]; }; - // 辅助函数:判断两个日期是否是同一天 - const isSameDay = (date1, date2) => { - return date1.getFullYear() === date2.getFullYear() && - date1.getMonth() === date2.getMonth() && - date1.getDate() === date2.getDate(); - }; + onMounted(() => { // 设置默认时间范围 需要延时等控件渲染好 @@ -188,8 +191,8 @@ // 时间选择变化 const getTime = (e) => { if (e && e.length === 2) { - startTime.value = formatDate(e[0], 'YYYY-MM-DD HH:mm:ss') - endTime.value = formatDate(e[1], 'YYYY-MM-DD HH:mm:ss') + startTime.value = formatDate(e[0], 'YYYY-MM-DD') + endTime.value = formatDate(e[1], 'YYYY-MM-DD') // updateChart() } }