Browse Source

feat: 系数逻辑修改

main
betaqi 1 week ago
parent
commit
46727a4eeb
  1. 44
      src/views/stationData/component/line-dlg.vue
  2. 50
      src/views/stationData/component/newDataChart.vue
  3. 137
      src/views/stationData/topology/components/detailDrawer.vue
  4. 156
      src/views/stationData/transfer/components/deviceDrawer.vue

44
src/views/stationData/component/line-dlg.vue

@ -11,25 +11,11 @@
<el-row> <el-row>
<div class="label">设置系数</div> <div class="label">设置系数</div>
<div class="box"> <div class="box">
<div
class="operator-btn"
:class="{ active: formData.operator === '/' }"
@click="formData.operator = '/'"
>
</div>
<div class="custom-stepper"> <div class="custom-stepper">
<div class="stepper-btn minus" @click="decrease">-</div> <div class="stepper-btn minus" @click="decrease">-</div>
<div class="stepper-input">{{ formData.coefficient }}</div> <div class="stepper-input">{{ formData.coefficient }}</div>
<div class="stepper-btn plus" @click="increase">+</div> <div class="stepper-btn plus" @click="increase">+</div>
</div> </div>
<div
class="operator-btn"
:class="{ active: formData.operator === '*' }"
@click="formData.operator = '*'"
>
</div>
</div> </div>
</el-row> </el-row>
</div> </div>
@ -46,7 +32,6 @@ const title = ref()
const createObj = { const createObj = {
id: '', id: '',
coefficient: 1, coefficient: 1,
operator: '*',
} }
const formData = ref(cloneDeep(createObj)) as any const formData = ref(cloneDeep(createObj)) as any
@ -63,19 +48,16 @@ async function onSave() {
} }
const visibility = ref(false) const visibility = ref(false)
function open(titleStr: string, id: string, coefficient: string, operator: string) { function open(titleStr: string, id: string, coefficient: string) {
title.value = titleStr title.value = titleStr
formData.value.id = id formData.value.id = id
if (coefficient) { if (coefficient) {
formData.value.coefficient = Number(coefficient) formData.value.coefficient = Number(coefficient)
} }
if (operator) {
formData.value.operator = operator
}
visibility.value = true visibility.value = true
} }
const ALLOWED_VALUES = [1, 10, 100, 1000] const ALLOWED_VALUES = [0.001, 0.01, 0.1, 1, 10, 100, 1000]
function decrease() { function decrease() {
const currentIndex = ALLOWED_VALUES.indexOf(formData.value.coefficient) const currentIndex = ALLOWED_VALUES.indexOf(formData.value.coefficient)
@ -129,27 +111,7 @@ defineExpose({
display: flex; display: flex;
gap: 10px; gap: 10px;
} }
.operator-btn {
width: 40px;
height: 32px;
line-height: 32px;
text-align: center;
border: 1px solid var(--el-border-color);
cursor: pointer;
border-radius: var(--el-border-radius-base);
color: var(--el-text-color-regular);
background-color: var(--el-bg-color);
&.active {
background-color: var(--el-color-primary);
color: var(--el-color-white);
border-color: var(--el-color-primary);
}
&:hover:not(.active) {
color: var(--el-color-primary);
border-color: var(--el-color-primary-light-7);
background-color: var(--el-color-primary-light-9);
}
}
.mx-2 { .mx-2 {
margin: 0 10px; margin: 0 10px;
} }

50
src/views/stationData/component/newDataChart.vue

@ -10,7 +10,7 @@
@click="onChartClick" @click="onChartClick"
/> />
</div> </div>
<LineChartDlg ref="LineChartDlgRef" @on-save="onChangeCoefficient"/> <LineChartDlg ref="LineChartDlgRef" @on-save="onChangeCoefficient" />
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
@ -46,7 +46,6 @@ type Legend = {
label: string label: string
unit?: string unit?: string
coefficient?: string | number coefficient?: string | number
operator?: string
} }
const autoresize = { const autoresize = {
@ -55,17 +54,22 @@ const autoresize = {
const LineChartDlgRef = ref() const LineChartDlgRef = ref()
function onChangeCoefficient(data: { id: string; coefficient: string; operator: string }) { function onChangeCoefficient(data: { id: string; coefficient: string }) {
emits('on-change-coefficient', data) emits('on-change-coefficient', data)
} }
const onChartClick = (params: any) => { const onChartClick = (params: any) => {
// 线 // 线
const [seriesName, id] = params?.seriesName?.split('|') const [seriesName, id] = params?.seriesName?.split('|')
if (params.componentType === 'series' && params.seriesType === 'line' && seriesName && id) { if (
params.componentType === 'series' &&
params.seriesType === 'line' &&
seriesName &&
id
) {
const find = props.legends.find(item => item.addr === id) as any const find = props.legends.find(item => item.addr === id) as any
if (find) { if (find) {
LineChartDlgRef.value?.open(seriesName, id, find?.coefficient, find?.operator) LineChartDlgRef.value?.open(seriesName, id, find?.coefficient)
} }
} }
} }
@ -116,13 +120,8 @@ const chartOption = computed<EChartsOption>(() => {
triggerLineEvent: true, triggerLineEvent: true,
data: entry.map(([ts, val]) => { data: entry.map(([ts, val]) => {
const coef = legend?.coefficient ? new Big(legend.coefficient) : new Big(1) const coef = legend?.coefficient ? new Big(legend.coefficient) : new Big(1)
const operator = legend?.operator || '*'
let valBig = new Big(val ?? 0) let valBig = new Big(val ?? 0)
if (operator === '/') { valBig = valBig.div(coef)
valBig = valBig.div(coef)
} else {
valBig = valBig.times(coef)
}
return [ts, valBig.toNumber()] return [ts, valBig.toNumber()]
}), }),
sampling: 'lttb', sampling: 'lttb',
@ -135,12 +134,13 @@ const chartOption = computed<EChartsOption>(() => {
} }
tmpSeries.push(lineData) tmpSeries.push(lineData)
} }
const dataLength = tmpSeries.length * tmpSeries[0]?.data?.length || 0; const dataLength = tmpSeries.length * tmpSeries[0]?.data?.length || 0
const visibleCount = Math.min(tmpSeries.length * 1000, dataLength); const visibleCount = Math.min(tmpSeries.length * 1000, dataLength)
const startPercent = dataLength === 0 ? 0 : ((dataLength - visibleCount) / dataLength) * 100; const startPercent =
const endPercent = 100; dataLength === 0 ? 0 : ((dataLength - visibleCount) / dataLength) * 100
const maxSpanPercent = dataLength === 0 ? 100 : (visibleCount / dataLength) * 100; const endPercent = 100
const maxSpanPercent = dataLength === 0 ? 100 : (visibleCount / dataLength) * 100
const option: EChartsOption = { const option: EChartsOption = {
grid: { grid: {
@ -162,16 +162,17 @@ const chartOption = computed<EChartsOption>(() => {
for (let i = 0; i < params.length; i++) { for (let i = 0; i < params.length; i++) {
const data = props.legends.find(item => item.addr === params[i].seriesId) const data = props.legends.find(item => item.addr === params[i].seriesId)
const conefficients = data?.coefficient ?? undefined const coefficient = data?.coefficient ? Number(data.coefficient) : undefined
const unit = data?.unit || '' const unit = data?.unit || ''
relVal += `<div style="display: flex; justify-content: space-between; gap: 30px;"> relVal += `<div style="display: flex; justify-content: space-between; gap: 30px;">
<div>${params[i].marker}${params[i].seriesName}:</div> <div>${params[i].marker}${params[i].seriesName.split('|')[0]}:</div>
<div>${params[i].value[1]}${conefficients ? `【系数为${conefficients}(${operatorMap[data?.operator] ?? '' <div>${params[i].value[1]}${
})` : ''}${unit}</div> coefficient ? `【系数为${coefficient}` : ''
}${unit}</div>
</div>` </div>`
} }
return relVal return relVal
} },
}, },
legend: { legend: {
type: 'scroll', type: 'scroll',
@ -209,7 +210,7 @@ const chartOption = computed<EChartsOption>(() => {
}, },
axisLabel: { axisLabel: {
show: false, show: false,
} },
}, },
yAxis: { yAxis: {
type: 'value', type: 'value',
@ -262,11 +263,6 @@ const chartOption = computed<EChartsOption>(() => {
const unCheckArr = ref<string[]>([]) const unCheckArr = ref<string[]>([])
const operatorMap = {
'*': '×',
'/': '÷',
}
function changeLegend(data: { name: string; selected: Record<string, boolean> }) { function changeLegend(data: { name: string; selected: Record<string, boolean> }) {
const { name, selected } = data const { name, selected } = data
if (!selected[name]) { if (!selected[name]) {

137
src/views/stationData/topology/components/detailDrawer.vue

@ -7,17 +7,21 @@
size="100%" size="100%"
modal-class="model-dev-opn" modal-class="model-dev-opn"
:before-close="handleBeforeClose" :before-close="handleBeforeClose"
@opened="onDrawerOpened"> @opened="onDrawerOpened"
>
<main class="wh-full flex"> <main class="wh-full flex">
<EdfsWrap
<EdfsWrap title="点位选择" title="点位选择"
isCollapse :collapsed="collapsed" @collapse="onCollapse" isCollapse
:style="{width: `${collapsed ? 0 : 340}px`}"> :collapsed="collapsed"
@collapse="onCollapse"
:style="{ width: `${collapsed ? 0 : 340}px` }"
>
<el-select <el-select
v-if="currentGroup?.customNode" v-if="currentGroup?.customNode"
v-model="selectValue" v-model="selectValue"
placeholder="单体选择" placeholder="单体选择"
style="width:240px" style="width: 240px"
@change="onchangeSelect" @change="onchangeSelect"
> >
<el-option <el-option
@ -35,8 +39,7 @@
> >
</PointCheckbox> </PointCheckbox>
</EdfsWrap> </EdfsWrap>
<div class="flex-1 p-4 h-full overflow-hidden relative" <div class="flex-1 p-4 h-full overflow-hidden relative">
>
<div class="absolute w-full h-full bg-[#ffffffe5] z-99" v-if="loadingChart"> <div class="absolute w-full h-full bg-[#ffffffe5] z-99" v-if="loadingChart">
<div class="w-full h-full flex flex-col justify-center items-center"> <div class="w-full h-full flex flex-col justify-center items-center">
<el-progress <el-progress
@ -47,11 +50,13 @@
status="success" status="success"
/> />
<div class="text-center text-gray-700 text-lg leading-relaxed"> <div class="text-center text-gray-700 text-lg leading-relaxed">
正在加载数据请稍等<br> 正在加载数据请稍等<br />
当前已查询 当前已查询
<span class="font-semibold text-green-600">{{ reqPointCount }}</span> / <span class="font-semibold text-green-600">{{ reqPointCount }}</span> /
<span class="font-semibold text-blue-600">{{ pointCount }}</span> 个点位剩余 <span class="font-semibold text-blue-600">{{ pointCount }}</span>
<span class="font-semibold text-red-500">{{ remainingPointCount }}</span> 个点位 个点位剩余
<span class="font-semibold text-red-500">{{ remainingPointCount }}</span>
个点位
</div> </div>
</div> </div>
</div> </div>
@ -70,8 +75,13 @@
</div> </div>
<el-button type="primary" @click="loadChardData">查询数据</el-button> <el-button type="primary" @click="loadChardData">查询数据</el-button>
查询最近 查询最近
<el-input-number :key="refreshKey" v-model="num" :min="1" :max="diffHours" <el-input-number
@input="handleInput"/> :key="refreshKey"
v-model="num"
:min="1"
:max="diffHours"
@input="handleInput"
/>
小时 小时
</div> </div>
<NewDataChart <NewDataChart
@ -100,15 +110,13 @@ import {
} from '@/api/module/transfer' } from '@/api/module/transfer'
import { useMessage } from '@/composables/useMessage' import { useMessage } from '@/composables/useMessage'
import dayjs from 'dayjs' import dayjs from 'dayjs'
import { nextTick } from "vue"; import { nextTick } from 'vue'
import EdfsWrap from "@/components/Edfs-wrap.vue"; import EdfsWrap from '@/components/Edfs-wrap.vue'
import PointCheckbox from "@/views/stationData/component/pointCheckbox.vue"; import PointCheckbox from '@/views/stationData/component/pointCheckbox.vue'
import { debounce } from 'lodash-es' import { debounce } from 'lodash-es'
const env = import.meta.env const env = import.meta.env
const num = ref<number>() const num = ref<number>()
const diffHours = ref<number>() const diffHours = ref<number>()
const refreshKey = ref(0) const refreshKey = ref(0)
@ -125,34 +133,39 @@ const handleInput = debounce(async (val: number) => {
} else { } else {
num.value = val num.value = val
} }
const endTime = const endTime = curDevice.value!.end_time
curDevice.value!.end_time ? ? dayjs(curDevice.value!.end_time).valueOf()
dayjs(curDevice.value!.end_time).valueOf() : dayjs().valueOf() : dayjs().valueOf()
const startTime = dayjs(endTime).subtract(num.value, 'hour').valueOf() const startTime = dayjs(endTime).subtract(num.value, 'hour').valueOf()
time.value = [dayjs(startTime).format('YYYY-MM-DD HH:mm:ss'), dayjs(endTime).format('YYYY-MM-DD HH:mm:ss')] time.value = [
dayjs(startTime).format('YYYY-MM-DD HH:mm:ss'),
dayjs(endTime).format('YYYY-MM-DD HH:mm:ss'),
]
}, 300) }, 300)
const isShowDrawer = defineModel<boolean>() const isShowDrawer = defineModel<boolean>()
const title = computed(() => const title = computed(() =>
( curDevice.value?.isonLine
curDevice.value?.isonLine ? ? '数据详情'
'数据详情' : env.VITE_APP_ENV === 'local' : env.VITE_APP_ENV === 'local'
? `已导出数据详情` : '已导入数据详情' ? `已导出数据详情`
) : '已导入数据详情'
) )
const message = useMessage() const message = useMessage()
const PointCheckboxRef = ref<InstanceType<typeof PointCheckbox>>() const PointCheckboxRef = ref<InstanceType<typeof PointCheckbox>>()
const emit = defineEmits(['on-save']) const emit = defineEmits(['on-save'])
const pointList = ref<IMyPoint[]>([]) const pointList = ref<IMyPoint[]>([])
const curDevice = ref<IDevice & { isonLine: boolean, siteName: string }>() const curDevice = ref<IDevice & { isonLine: boolean; siteName: string }>()
async function open(device: IDevice & { async function open(
isonLine: boolean, device: IDevice & {
siteName: string isonLine: boolean
}, group: IPointGroupOV) { siteName: string
},
group: IPointGroupOV
) {
curDevice.value = device curDevice.value = device
currentGroup.value = group currentGroup.value = group
onCollapse(false) onCollapse(false)
@ -179,7 +192,7 @@ async function open(device: IDevice & {
} }
const start = dayjs(deviceOff.start_time) const start = dayjs(deviceOff.start_time)
const end = dayjs(deviceOff.end_time) const end = dayjs(deviceOff.end_time)
diffHours.value = end.diff(start, "hour") + 1; diffHours.value = end.diff(start, 'hour') + 1
} }
const selectValue = ref() const selectValue = ref()
@ -188,14 +201,15 @@ function onchangeSelect(value: string) {
PointCheckboxRef.value?.clearCheck() PointCheckboxRef.value?.clearCheck()
} }
const loadingPoints = ref(false) const loadingPoints = ref(false)
const columParams = computed(() => ['ts', ...checkPointList.value.map(i => i.addr)]) const columParams = computed(() => ['ts', ...checkPointList.value.map(i => i.addr)])
const currentGroup = ref<IPointGroupOV & { const currentGroup = ref<
customNode?: boolean IPointGroupOV & {
brother?: Array<any> customNode?: boolean
}>() brother?: Array<any>
}
>()
async function loadPoints() { async function loadPoints() {
if (!currentGroup.value) { if (!currentGroup.value) {
@ -251,25 +265,19 @@ async function loadDeviceDetails() {
const chartData = reactive(new Map<string, any[]>()) const chartData = reactive(new Map<string, any[]>())
const axisData = new Set<string>() const axisData = new Set<string>()
const legends = ref<{ const legends = ref<
addr: string; label: string, unit: string, coefficient?: string | number
operator?: string
}[]>([])
function onChangeCoefficient(
{ {
id, addr: string
coefficient, label: string
operator, unit: string
}: { coefficient?: string | number
id: string }[]
coefficient: string >([])
operator: string
}) { function onChangeCoefficient({ id, coefficient }: { id: string; coefficient: string }) {
const find = legends.value.findIndex(r => r.addr === id) const find = legends.value.findIndex(r => r.addr === id)
if (find !== -1) { if (find !== -1) {
legends.value[find].coefficient = coefficient legends.value[find].coefficient = coefficient
legends.value[find].operator = operator
} }
} }
@ -279,7 +287,6 @@ const chartLimit = ref(1000)
const chartOffset = ref(0) const chartOffset = ref(0)
const progress = ref(0) const progress = ref(0)
const pointCount = computed(() => chartAllTotal.value * checkPointList.value.length) const pointCount = computed(() => chartAllTotal.value * checkPointList.value.length)
const reqPointCount = ref(0) const reqPointCount = ref(0)
@ -303,7 +310,9 @@ async function loadChardData() {
columns: columParams.value, columns: columParams.value,
isLocal: !curDevice.value?.isonLine, isLocal: !curDevice.value?.isonLine,
host: curDevice.value?.isonLine ? (curDevice.value as IOnlineDevice).clientIp : '', host: curDevice.value?.isonLine ? (curDevice.value as IOnlineDevice).clientIp : '',
name: currentGroup.value?.customNode ? selectValue.value : currentGroup.value?.name as string, name: currentGroup.value?.customNode
? selectValue.value
: (currentGroup.value?.name as string),
startTime: time.value[0], startTime: time.value[0],
endTime: time.value[1], endTime: time.value[1],
} }
@ -316,7 +325,7 @@ async function loadChardData() {
const params: IGetDeviceDataParams = { const params: IGetDeviceDataParams = {
...options, ...options,
limit, limit,
offset offset,
} }
loadingChart.value = true loadingChart.value = true
@ -352,7 +361,7 @@ async function loadChardData() {
const params: IGetDeviceDataParams = { const params: IGetDeviceDataParams = {
...options, ...options,
limit, limit,
offset: i * Number(limit) offset: i * Number(limit),
} }
const res = await getDeviceDetails(params) const res = await getDeviceDetails(params)
chartAllTotal.value = res?.data?.total ?? 0 chartAllTotal.value = res?.data?.total ?? 0
@ -370,7 +379,6 @@ async function loadChardData() {
resetChartStatus() resetChartStatus()
} }
function setChartData(pointData: any[]) { function setChartData(pointData: any[]) {
for (const addr of columParams.value.filter(i => i !== 'ts')) { for (const addr of columParams.value.filter(i => i !== 'ts')) {
const label = pointList.value.find(i => i.addr === addr)?.label || addr const label = pointList.value.find(i => i.addr === addr)?.label || addr
@ -399,10 +407,8 @@ function setChartData(pointData: any[]) {
} }
} }
}) })
} }
function handleBeforeClose(done: () => void) { function handleBeforeClose(done: () => void) {
time.value = undefined time.value = undefined
isShowDrawer.value = false isShowDrawer.value = false
@ -470,9 +476,12 @@ const disabledDate = (time: any) => {
console.log('disableDate error', e) console.log('disableDate error', e)
return current.isAfter(dayjs(), 'day') return current.isAfter(dayjs(), 'day')
} }
} }
const getBeforeMonth = dayjs().startOf('month').subtract(1, 'month').startOf('month').toDate() const getBeforeMonth = dayjs()
.startOf('month')
.subtract(1, 'month')
.startOf('month')
.toDate()
const collapsed = ref(false) const collapsed = ref(false)
function onCollapse(value?: boolean) { function onCollapse(value?: boolean) {

156
src/views/stationData/transfer/components/deviceDrawer.vue

@ -1,11 +1,22 @@
<template> <template>
<div class="fault-rule-drawer"> <div class="fault-rule-drawer">
<el-drawer v-model="isShowDrawer" :title="title" direction="rtl" size="100%" <el-drawer
modal-class="model-dev-opn" v-model="isShowDrawer"
:before-close="handleBeforeClose" @opened="onDrawerOpened"> :title="title"
direction="rtl"
size="100%"
modal-class="model-dev-opn"
:before-close="handleBeforeClose"
@opened="onDrawerOpened"
>
<main class="wh-full flex"> <main class="wh-full flex">
<EdfsWrap title="点位组" isCollapse :collapsed="collapsed" @collapse="onCollapse" <EdfsWrap
:style="{width: `${collapsed ? 0 : 600}px`}"> title="点位组"
isCollapse
:collapsed="collapsed"
@collapse="onCollapse"
:style="{ width: `${collapsed ? 0 : 600}px` }"
>
<PointGroupTree <PointGroupTree
v-if="isShowDrawer" v-if="isShowDrawer"
:data="pointGroup" :data="pointGroup"
@ -16,10 +27,13 @@
:loadingPoints="loadingPoints" :loadingPoints="loadingPoints"
:isTransfer="props.isTransfer" :isTransfer="props.isTransfer"
:siteInfo="props.siteInfo" :siteInfo="props.siteInfo"
ref="pointGroupTreeRef"/> ref="pointGroupTreeRef"
/>
</EdfsWrap> </EdfsWrap>
<div class="flex-1 p-4 h-full overflow-hidden relative" v-loading="loading" <div
element-loading-text="数据加载中请耐心等待..." class="flex-1 p-4 h-full overflow-hidden relative"
v-loading="loading"
element-loading-text="数据加载中请耐心等待..."
> >
<div <div
class="absolute inset-0 z-[99] flex items-center justify-center bg-white/80 backdrop-blur-sm transition-opacity duration-300" class="absolute inset-0 z-[99] flex items-center justify-center bg-white/80 backdrop-blur-sm transition-opacity duration-300"
@ -43,15 +57,16 @@
:percentage="deviceInfo.progress" :percentage="deviceInfo.progress"
/> />
<div class="text-gray-600 text-base">已查询 <div class="text-gray-600 text-base">
已查询
<span class="text-green-600 font-semibold"> <span class="text-green-600 font-semibold">
{{ deviceInfo.fetchLimit }} {{ deviceInfo.fetchLimit }} </span
</span>/<span class="text-blue-600 font-semibold">{{ >/<span class="text-blue-600 font-semibold">{{
deviceInfo.total deviceInfo.total
}}</span>剩余<span }}</span
class="text-red-500 font-semibold">{{ >剩余<span class="text-red-500 font-semibold">{{
deviceInfo.total - deviceInfo.fetchLimit deviceInfo.total - deviceInfo.fetchLimit
}}</span> }}</span>
</div> </div>
</div> </div>
</div> </div>
@ -74,13 +89,23 @@
</div> </div>
<el-button type="primary" @click="loadChardData2">查询数据</el-button> <el-button type="primary" @click="loadChardData2">查询数据</el-button>
查询最近 查询最近
<el-input-number :key="refreshKey" v-model="num" :min="1" :max="diffHours" <el-input-number
@input="handleInput"/> :key="refreshKey"
v-model="num"
:min="1"
:max="diffHours"
@input="handleInput"
/>
小时 小时
</div> </div>
<NewDataChart v-if="isShowChart" :chart-datas="chartData" :legends="legends" <NewDataChart
:axis-data="Array.from(axisData)" ref="chartRef" v-if="isShowChart"
@onChangeCoefficient="onChangeCoefficient"/> :chart-datas="chartData"
:legends="legends"
:axis-data="Array.from(axisData)"
ref="chartRef"
@onChangeCoefficient="onChangeCoefficient"
/>
</div> </div>
</main> </main>
</el-drawer> </el-drawer>
@ -103,13 +128,13 @@ import {
} from '@/api/module/transfer' } from '@/api/module/transfer'
import { useMessage } from '@/composables/useMessage' import { useMessage } from '@/composables/useMessage'
import dayjs from 'dayjs' import dayjs from 'dayjs'
import EdfsWrap from "@/components/Edfs-wrap.vue"; import EdfsWrap from '@/components/Edfs-wrap.vue'
import { bms_cellRewriteName } from "@/views/stationData/utils"; import { bms_cellRewriteName } from '@/views/stationData/utils'
import { debounce } from 'lodash-es' import { debounce } from 'lodash-es'
import { import {
type DeviceFetchInfo, type DeviceFetchInfo,
useFetcher useFetcher,
} from "@/views/stationData/transfer/components/useFetcher"; } from '@/views/stationData/transfer/components/useFetcher'
type ChartParamsMap = { type ChartParamsMap = {
name: string name: string
@ -138,22 +163,22 @@ const handleInput = debounce(async (val: number) => {
} }
const device = curDevice.value as IOfflineDevice const device = curDevice.value as IOfflineDevice
const endTime = const endTime = device.end_time ? dayjs(device.end_time).valueOf() : dayjs().valueOf()
device.end_time ?
dayjs(device.end_time).valueOf() : dayjs().valueOf()
const startTime = dayjs(endTime).subtract(num.value, 'hour').valueOf() const startTime = dayjs(endTime).subtract(num.value, 'hour').valueOf()
time.value = [dayjs(startTime).format('YYYY-MM-DD HH:mm:ss'), dayjs(endTime).format('YYYY-MM-DD HH:mm:ss')] time.value = [
dayjs(startTime).format('YYYY-MM-DD HH:mm:ss'),
dayjs(endTime).format('YYYY-MM-DD HH:mm:ss'),
]
}, 300) }, 300)
const isShowDrawer = defineModel<boolean>() const isShowDrawer = defineModel<boolean>()
const title = computed(() => const title = computed(() =>
( props.isTransfer
props.isTransfer ? ? '数据详情'
'数据详情' : env.VITE_APP_ENV === 'local' : env.VITE_APP_ENV === 'local'
? `已导出数据详情` : '已导入数据详情' ? `已导出数据详情`
) : '已导入数据详情'
) )
const message = useMessage() const message = useMessage()
@ -187,10 +212,9 @@ async function open(device: IOfflineDevice | IOnlineDevice) {
} }
const start = dayjs(deviceOff.start_time) const start = dayjs(deviceOff.start_time)
const end = dayjs(deviceOff.end_time) const end = dayjs(deviceOff.end_time)
diffHours.value = end.diff(start, "hour") + 1; diffHours.value = end.diff(start, 'hour') + 1
} }
const loadingPoints = ref(false) const loadingPoints = ref(false)
async function loadPoints() { async function loadPoints() {
@ -244,10 +268,14 @@ async function loadDeviceDetails() {
const chartData = reactive(new Map<string, any[]>()) const chartData = reactive(new Map<string, any[]>())
const axisData = new Set<string>() const axisData = new Set<string>()
const legends = ref<{ const legends = ref<
addr: string; label: string, unit: string, coefficient?: string | number {
operator?: string addr: string
}[]>([]) label: string
unit: string
coefficient?: string | number
}[]
>([])
const loadingChart = ref(false) const loadingChart = ref(false)
const loading = ref(false) const loading = ref(false)
@ -281,11 +309,15 @@ function buildOptions(groupId: string): Omit<IGetDeviceDataParams, 'limit' | 'of
const pointInfoData = ref<DeviceFetchInfo[]>([]) const pointInfoData = ref<DeviceFetchInfo[]>([])
const { devices, isFetching, startFetching, abortAll } = useFetcher(loadPointChartData) const { devices, isFetching, startFetching, abortAll } = useFetcher(loadPointChartData)
watch(devices, (newValue) => { watch(
if (!newValue) return devices,
pointInfoData.value = newValue newValue => {
loading.value = false if (!newValue) return
}, { deep: true }) pointInfoData.value = newValue
loading.value = false
},
{ deep: true }
)
async function loadChardData2() { async function loadChardData2() {
loading.value = true loading.value = true
@ -318,7 +350,7 @@ function setChartData2(groupName: string, data: any[]) {
legends.value.push({ legends.value.push({
addr: `${groupName}-${column.addr}`, addr: `${groupName}-${column.addr}`,
label: `${groupInfo.cnName}-${column.label}`, label: `${groupInfo.cnName}-${column.label}`,
unit: column.unit || '' unit: column.unit || '',
}) })
} }
@ -337,20 +369,10 @@ function setChartData2(groupName: string, data: any[]) {
}) })
} }
function onChangeCoefficient( function onChangeCoefficient({ id, coefficient }: { id: string; coefficient: string }) {
{
id,
coefficient,
operator,
}: {
id: string
coefficient: string
operator: string
}) {
const find = legends.value.findIndex(r => r.addr === id) const find = legends.value.findIndex(r => r.addr === id)
if (find !== -1) { if (find !== -1) {
legends.value[find].coefficient = coefficient legends.value[find].coefficient = coefficient
legends.value[find].operator = operator
} }
} }
@ -368,9 +390,7 @@ function handleBeforeClose(done: () => void) {
chartGroupMap.clear() chartGroupMap.clear()
done() done()
}) })
.catch(() => { .catch(() => {})
})
} }
function clearData() { function clearData() {
@ -445,17 +465,18 @@ function onGroupChange(item: IPointGroupOV) {
loadDeviceDetails() loadDeviceDetails()
} }
const chartParamsMap = new Map<string, ChartParamsMap>() const chartParamsMap = new Map<string, ChartParamsMap>()
const chartGroupMap = new Map<string, IPointGroupOV>() const chartGroupMap = new Map<string, IPointGroupOV>()
function onchangePoints(checkPoints: IMyPoint[]) { function onchangePoints(checkPoints: IMyPoint[]) {
if (!curGroup?.value || !curGroupName?.value) return message.error('请选择设备') if (!curGroup?.value || !curGroupName?.value) return message.error('请选择设备')
const currentCheckPoints = checkPoints.filter((r: any) => r.parentName === curGroupName.value) const currentCheckPoints = checkPoints.filter(
(r: any) => r.parentName === curGroupName.value
)
chartParamsMap.set(curGroupName.value, { chartParamsMap.set(curGroupName.value, {
name: curGroupName.value, name: curGroupName.value,
columns: currentCheckPoints columns: currentCheckPoints,
}) })
chartGroupMap.set(curGroupName.value, curGroup.value) chartGroupMap.set(curGroupName.value, curGroup.value)
@ -477,7 +498,6 @@ const disabledDate = (time: any) => {
console.log('disableDate error', e) console.log('disableDate error', e)
return current.isAfter(dayjs(), 'day') return current.isAfter(dayjs(), 'day')
} }
} }
const collapsed = ref(false) const collapsed = ref(false)
@ -486,7 +506,11 @@ function onCollapse(value?: boolean) {
collapsed.value = value ?? !collapsed.value collapsed.value = value ?? !collapsed.value
} }
const getBeforeMonth = dayjs().startOf('month').subtract(1, 'month').startOf('month').toDate() const getBeforeMonth = dayjs()
.startOf('month')
.subtract(1, 'month')
.startOf('month')
.toDate()
defineExpose({ defineExpose({
open, open,
openFullScreen, openFullScreen,

Loading…
Cancel
Save