chat Html 代码
<template>
<el-dialog :title="id" v-model="open" width="50vw" append-to-body destroy-on-close>
<div class="time">
<el-date-picker v-model="timeArr" type="daterange" range-separator="至" format="YYYY年MM月DD日"
value-format="YYYY-MM-DD" @change="changeTime"/>
</div>
<div style="height: 55vh">
<v-charts ref="chart" :option="getOption()" height="55" width="48"/>
</div>
</el-dialog>
</template>
<script setup>
import {listDeviceReport} from "@/api/cover/deviceReport.js"
import VCharts from "@/components/chart/V-Charts.vue"
import {ElMessage} from "element-plus"
defineOptions({
name: "showLineChartComponent"
})
const open = ref(false)
const chart = ref(null)
const id = ref('')
const dateTime = ref([])
const signal = ref([])
const voltage = ref([])
const timeArr = ref([])
const changeTime = async (arr) => {
const data = await getList(id.value, {time: arr.toString()})
if (data.length === 0) {
ElMessage.error('当前时间段无数据!')
return
}
dateTime.value = data.map(o => o.reportTime)
timeArr.value[0] = dateTime.value[0].split(' ')[0]
timeArr.value[1] = dateTime.value[dateTime.value.length - 1].split(' ')[0]
}
const openChart = async (productCode) => {
const data = await getList(productCode, null)
if (data.length === 0) {
ElMessage.error('当前无数据!')
return
}
dateTime.value = data.map(o => o.reportTime)
timeArr.value[0] = dateTime.value[0].split(' ')[0]
timeArr.value[1] = dateTime.value[dateTime.value.length - 1].split(' ')[0]
open.value = true
}
const getList = async (id, time) => {
return data
}
const getOption = () => {
return {}
}
defineExpose({
openChart
})
</script>
<style lang="scss" scoped>
.time {
position: absolute;
top: 5vh;
right: 5vw;
}
</style>
vue3 的 chat 底层模板
<template>
<div class="echarts" :style="{width: widthC, height: heightC}">
<div class="main" :style="{height: heightC, width: widthC}" ref="main"></div>
</div>
</template>
<script setup>
defineOptions({
name: "V-Charts"
})
const props = defineProps({
option: {
required: true,
type: Object
},
width: {
required: true,
type: String
},
height: {
required: true,
type: String
}
})
const {proxy} = getCurrentInstance()
const main = ref(null)
const widthC = computed(() => props.width + 'vw')
const heightC = computed(() => props.height + 'vh')
onMounted(() => init())
const init = () => {
const chart = proxy.$echarts.init(main.value)
chart.setOption(props.option)
}
</script>