123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317 |
- <template>
- <div
- class="temChart"
- :class="[screenType === 'hor' ? 'horiCompClass' : 'verCompClass ']"
- >
- <div class="temChartCont">
- <div
- class="subhead-title"
- v-show="screenType === 'ver'"
- >
- <span>实时温度</span>
- </div>
- <div
- id="tempChartBox"
- class="tempChartBox"
- ref="tempChartRef"
- ></div>
- </div>
- </div>
- </template>
- <script lang="ts">
- import {
- ref,
- defineComponent,
- reactive,
- toRefs,
- onMounted,
- nextTick,
- } from "vue";
- import { queryIndoorTempList } from "@/api";
- import { Chart, registerShape } from "@antv/g2";
- import moment from "moment";
- export default defineComponent({
- props: {
- screenType: {
- type: String,
- },
- },
- setup(props, contx) {
-
- const { screenType } = props;
- const allData = reactive({});
- const tempChartRef = ref();
- const cInitChart = (cdata, minTemp, maxTemp) => {
- registerShape("point", "breath-point", {
- draw(cfg, container) {
- const data = cfg.data;
- const point = { x: cfg.x, y: cfg.y };
- const group = container.addGroup();
- if (
- data.time === cdata[cdata.length - 1].time &&
- data.temp === cdata[cdata.length - 1].temp
- ) {
- const decorator1 = group.addShape("circle", {
- attrs: {
- x: point.x,
- y: point.y,
- r: 8,
- fill: "#F2E2CC",
-
- },
- });
-
-
-
-
-
-
-
-
-
-
-
- group.addShape("circle", {
- attrs: {
- x: point.x,
- y: point.y,
- r: 4,
- fill: "#ffffff",
- filter: "blur(2px)",
- opacity: 0.5,
- },
- });
-
-
-
-
-
-
-
-
- }
- return group;
- },
- });
- var chartWidth =
- (tempChartRef.value && tempChartRef.value.offsetWidth) || 0;
- var chartHeight =
- (tempChartRef.value && tempChartRef.value.offsetHeight) || 0;
-
-
-
-
- var chart = new Chart({
- container: "tempChartBox",
- autoFit: true,
-
-
- padding: [70, 50, 46, 60],
- });
-
- chart.data(cdata);
- chart.scale("time", {
-
-
-
-
- });
- chart.scale("temp", {
- type: "linear",
- minTickInterval: 1,
- min: minTemp,
- max: maxTemp,
-
- });
- chart.axis("time", {
- line: {
- style: {
- lineWidth: 1,
- stroke: "rgba(224,194,155,0.2)",
- lineDash: [3, 3],
- },
- },
- label: {
- style: {
- fill: "#E0C29B",
- fontSize: 12,
- },
- },
- tickLine: null,
- });
- chart.axis("temp", {
- tickLine: null,
- grid: {
- line: {
- style: {
- lineWidth: 1,
- stroke: "rgba(224,194,155,0.2)",
- lineDash: [3, 3],
- },
- },
- },
- label: {
- style: {
- fill: "#E0C29B",
- fontSize: 12,
- },
-
-
-
- },
- });
- chart.legend(false);
- chart
- .line()
- .animate({
- appear: {
-
- easing: "easeQuadIn",
- delay: 100,
- duration: 1500,
- },
- })
- .position("time*temp")
- .color("#F2E3CD")
- .shape("smooth")
- .tooltip(false)
- .style({
- lineWidth: 3,
- });
- chart
- .area()
- .animate({
- appear: {
-
- easing: "easeQuadIn",
- delay: 100,
- duration: 1500,
- },
- })
- .position("time*temp")
- .color(
- "l(90) 0:rgba(237,217,190,0.8) 0.6:rgb(149, 162, 194, 0.01)"
- )
- .tooltip(false)
- .shape("smooth");
- chart
- .point()
- .tooltip(false)
- .position("time*temp")
- .shape("breath-point");
- var lastpoint = cdata[cdata.length - 1];
- var nowtime = moment();
- var timestr = nowtime.format("YYYY.MM.DD");
- const tooltipHtml = `<div style='line-height:22px;color:#321D0A;background: linear-gradient(105.46deg, #F2E3CD 8.6%, #D9B991 62.71%);padding:16px 17px;border-radius:5px;white-space:nowrap;'>
- <div style='font-size:12px;font-weight:600;'><span style='margin-right:5px;line-height:17px;'>${timestr}</span>${lastpoint &&
- lastpoint.time}</div>
- <div style='font-size:16px;font-weight:600;margin-top:4px;'>室内温度:${lastpoint &&
- lastpoint.temp &&
- Number(lastpoint.temp).toFixed(1)}℃</div></div>`;
- chart.annotation().html({
- position: lastpoint,
- html: tooltipHtml,
- alignX: "right",
- alignY: "bottom",
- offsetX: 60,
- offsetY: -15,
- });
- chart.annotation().text({
-
- position: function(xScale, yScale) {
-
- return ["0%", "0%"];
- },
- content: "温度/℃",
- style: {
- fill: "#E0C29B",
- fontSize: "12",
-
-
- },
- offsetX: -40,
- offsetY: -46,
- });
- chart.render();
- return chart;
- };
- onMounted(() => {
- queryIndoorTempList()
- .then((res) => {
- var cdata = res.data.data || [];
- var tempArr = [];
- cdata.forEach((element) => {
- var timestr = element.time || "";
- var hour = timestr.substr(8, 2);
- var minute = timestr.substr(10, 2);
- element.time = hour + ":" + minute;
- element.temp =
- element && element.temp
- ? Number(element.temp).toFixed(1)
- : element.temp;
- element.temp && tempArr.push(element.temp);
- });
- var minTemp = Math.floor(Math.min(...tempArr));
- var maxTemp = Math.ceil(Math.max(...tempArr));
-
- nextTick(() => {
- cInitChart(cdata, minTemp, maxTemp);
- });
- })
- .catch((err) => {});
- });
- return { ...toRefs(allData), tempChartRef };
- },
- });
- </script>
- <style scoped lang="scss">
- .temChart {
- .temChartCont {
- width: 100%;
- height: 100%;
- box-sizing: border-box;
- font-size: 0;
- }
- .tempChartBox {
- width: 100%;
- height: 100%;
- box-sizing: border-box;
-
- }
- }
- .horiCompClass {
- height: 100%;
- box-sizing: border-box;
- padding: 50px 20px 20px;
- }
- .verCompClass {
-
-
- height: 31%;
- padding: 28px 0;
- box-sizing: border-box;
- .temChartCont {
- padding: 0 36px;
- background: rgba(149, 162, 194, 0.1);
- backdrop-filter: blur(40px);
- border-radius: 20px;
- }
- .tempChartBox {
- height: calc(100% - 60px);
- padding-top: 30px;
- box-sizing: border-box;
- }
- }
- </style>
|