|
@@ -0,0 +1,125 @@
|
|
|
|
+<template>
|
|
|
|
+ <div class="select-device">
|
|
|
|
+ 选择时间:
|
|
|
|
+ <el-date-picker
|
|
|
|
+ class="date-picker-wrap"
|
|
|
|
+ v-model="params.timeRange"
|
|
|
|
+ :clearable="false"
|
|
|
|
+ type="datetimerange"
|
|
|
|
+ range-separator="至"
|
|
|
|
+ start-placeholder="开始时间"
|
|
|
|
+ end-placeholder="结束时间"
|
|
|
|
+ format="MM-DD HH:mm"
|
|
|
|
+ value-format="YYYY-MM-DD HH:mm:00"
|
|
|
|
+ date-format="YYYY/MM/DD"
|
|
|
|
+ time-format="hh:mm"
|
|
|
|
+ @change="getChartData"
|
|
|
|
+ style="width: 12.5vw; margin-right: 1vw"
|
|
|
|
+ />
|
|
|
|
+ 选择参数:
|
|
|
|
+ <el-select style="width: 12vw" v-model="params.properties" multiple collapse-tags @change="getChartData" placeholder="">
|
|
|
|
+ <el-option v-for="row in options" :key="row.key" :label="row.name" :value="row.key"></el-option>
|
|
|
|
+ </el-select>
|
|
|
|
+ </div>
|
|
|
|
+ <section class="line">
|
|
|
|
+ <Chart height="22.5vh" ref="chartRef"></Chart>
|
|
|
|
+ </section>
|
|
|
|
+</template>
|
|
|
|
+<script setup lang="ts">
|
|
|
|
+import { onMounted, reactive, ref, watch } from 'vue'
|
|
|
|
+import { getLineMultiOption } from '/@/components/chart/options'
|
|
|
|
+import Chart from '/@/components/chart/index.vue'
|
|
|
|
+import api from '/@/api/projects'
|
|
|
|
+import { dayjs } from 'element-plus'
|
|
|
|
+
|
|
|
|
+const props = defineProps({
|
|
|
|
+ index: {
|
|
|
|
+ type: [String, Number],
|
|
|
|
+ dafault: 0,
|
|
|
|
+ },
|
|
|
|
+ deviceKey: {
|
|
|
|
+ type: String,
|
|
|
|
+ dafault: '',
|
|
|
|
+ },
|
|
|
|
+})
|
|
|
|
+
|
|
|
|
+let deviceCode = ''
|
|
|
|
+const chartRef = ref()
|
|
|
|
+const options = ref<any[]>([])
|
|
|
|
+const params = reactive({
|
|
|
|
+ timeRange: [dayjs().subtract(1, 'hour').format('YYYY-MM-DD HH:mm:00'), dayjs().format('YYYY-MM-DD HH:mm:00')],
|
|
|
|
+ properties: [] as string[],
|
|
|
|
+})
|
|
|
|
+
|
|
|
|
+watch(() => props.deviceKey!, getData)
|
|
|
|
+
|
|
|
|
+onMounted(() => {
|
|
|
|
+ chartRef.value?.loading()
|
|
|
|
+})
|
|
|
|
+
|
|
|
|
+function getData(code: string) {
|
|
|
|
+ params.properties = []
|
|
|
|
+ options.value = []
|
|
|
|
+
|
|
|
|
+ deviceCode = code
|
|
|
|
+
|
|
|
|
+ if (!code) return chartRef.value.draw()
|
|
|
|
+
|
|
|
|
+ chartRef.value?.loading()
|
|
|
|
+
|
|
|
|
+ api.screen.propertyList(code).then((res: any) => {
|
|
|
|
+ const list = res?.Data || []
|
|
|
|
+ options.value = list
|
|
|
|
+
|
|
|
|
+ if (!list.length) return chartRef.value.draw()
|
|
|
|
+
|
|
|
|
+ const i = Number(props.index)
|
|
|
|
+ if (list[i]) {
|
|
|
|
+ params.properties = [list[i].key]
|
|
|
|
+ } else {
|
|
|
|
+ params.properties = [list[0].key]
|
|
|
|
+ }
|
|
|
|
+ getChartData()
|
|
|
|
+ })
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+function getChartData() {
|
|
|
|
+ chartRef.value.loading()
|
|
|
|
+ if (!params.properties.length) return chartRef.value.draw()
|
|
|
|
+ api.screen
|
|
|
|
+ .chartData({
|
|
|
|
+ deviceKey: deviceCode,
|
|
|
|
+ dateRange: params.timeRange,
|
|
|
|
+ properties: params.properties,
|
|
|
|
+ })
|
|
|
|
+ .then((res: any) => {
|
|
|
|
+ if (!res) return chartRef.value.draw()
|
|
|
|
+
|
|
|
|
+ const values = Object.values(res) as any[]
|
|
|
|
+
|
|
|
|
+ const legend = Object.keys(res).map((key) => options.value.find((item) => item.key === key)?.name)
|
|
|
|
+
|
|
|
|
+ chartRef.value?.draw(
|
|
|
|
+ getLineMultiOption({
|
|
|
|
+ datas: values.map((arr: any) => (arr || []).map((item: any) => item.dataValue)),
|
|
|
|
+ legend,
|
|
|
|
+ xAxis: (values[0] || []).map((item: any) => item.dataTime),
|
|
|
|
+ })
|
|
|
|
+ )
|
|
|
|
+ })
|
|
|
|
+}
|
|
|
|
+</script>
|
|
|
|
+
|
|
|
|
+<style lang="scss" scoped>
|
|
|
|
+.select-device {
|
|
|
|
+ color: var(--primary-color);
|
|
|
|
+ display: flex;
|
|
|
|
+ align-items: center;
|
|
|
|
+ white-space: nowrap;
|
|
|
|
+ font-size: 1.5vh;
|
|
|
|
+ font-weight: 500;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+.line {
|
|
|
|
+}
|
|
|
|
+</style>
|