| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286 |
- <!-- -->
- <template>
- <div class="chart-template chart-template-withperiod">
- <p>
- <span>预案演练</span>
- </p>
- <div>
- <el-tabs v-model="activeName" @tab-click="handleClick">
- <el-tab-pane
- v-for="t in types"
- :key="t.value"
- :label="t.text"
- :name="t.value"
- ></el-tab-pane>
- </el-tabs>
- </div>
- <div ref="chart"></div>
- </div>
- </template>
- <script>
- import "./../../board.scss";
- import * as echarts from "echarts";
- import { drill } from "@/api/board/cockpit.js";
- import {
- findMaxIndex,
- getChartDOMSize,
- getNextPeriod,
- getPeriodText,
- } from "../../utils.js";
- const types = [
- {
- text: "今天",
- value: "1",
- },
- {
- text: "近7天",
- value: "2",
- },
- {
- text: "近30天",
- value: "3",
- },
- {
- text: "近90天",
- value: "4",
- },
- {
- text: "本年",
- value: "5",
- },
- ];
- export default {
- props: {
- orgId: {
- type: String,
- isRequired: true,
- },
- },
- data() {
- return {
- data: {
- all: [],
- completed: [],
- name: [],
- },
- activeName: types[0].value,
- };
- },
- components: {},
- computed: {},
- watch: {
- orgId: {
- deep: true,
- handler(val) {
- this.resetTimer();
- this.getData();
- },
- },
- data: {
- deep: true,
- handler() {
- this.initMap();
- },
- },
- },
- created() {
- this.types = types;
- this.maxDisplay = 16;
- this.refreshTime = 1 * 10 * 1000;
- this.isMouseOver = false;
- },
- async mounted() {
- window.addEventListener("resize", this.windowResize);
- },
- beforeDestroy() {
- this.timer && clearInterval(this.timer);
- this.timer = null;
- window.removeEventListener("resize", this.windowResize);
- },
- methods: {
- handleClick() {
- this.resetTimer();
- this.getData();
- },
- handleMouseEnter() {
- this.isMouseOver = true;
- },
- handleMouseLeave() {
- this.isMouseOver = false;
- },
- async getData() {
- let r = (await drill({ orgId: this.orgId, period: this.activeName }))
- .data;
- let data = {
- all: [],
- completed: [],
- rate: [],
- name: [],
- };
- for (let item of r) {
- if (data.all.length >= 16) {
- break;
- }
- data.all.push(item.total);
- data.completed.push(item.completed);
- data.rate.push((item.completedRate * 100).toFixed(0));
- data.name.push(item.orgName);
- }
- this.data = data;
- // console.info(this.data);
- },
- windowResize() {
- this.myChart && this.myChart.resize();
- },
- initMap() {
- this.myChart && this.myChart.dispose();
- let c = this.$refs["chart"];
- // 基于准备好的dom,初始化echarts实例
- this.myChart = echarts.init(
- c
- // document.getElementById("commAlarmEvent_Chart")
- );
- let t = this;
- // 指定图表的配置项和数据
- var option = {
- // color: ["#82D5AE"],
- tooltip: {
- trigger: "axis",
- confine: true,
- axisPointer: {
- type: "shadow",
- },
- // formatter: "完成率:{c}%",
- },
- legend: {
- show: true,
- textStyle: {
- color: "rgb(245, 245, 245)",
- },
- },
- grid: {
- left: "3%",
- right: "4%",
- bottom: "2%",
- top: "20px",
- containLabel: true,
- },
- xAxis: [
- {
- type: "category",
- data: this.data.name,
- // data: this.mapdata.totalDataVo.xlist,
- axisTick: {
- alignWithLabel: true,
- },
- axisLine: {
- show: true,
- lineStyle: {
- type: "solid",
- color: "rgb(245, 245, 245)", //左边线的颜⾊
- },
- },
- axisLabel: {
- interval: 0,
- rotate: -45,
- fontSize: 12,
- color: "#fff",
- },
- },
- ],
- yAxis: [
- {
- type: "value",
- minInterval: 1,
- // max: function (value) {
- // let m = value.max == Math.ceil(value.max) ? Math.ceil(value.max * 1.0001) : Math.ceil(value.max);
- // return m
- // },
- },
- ],
- series: [
- // {
- // name: "总数",
- // type: "bar",
- // barWidth: "14",
- // // label: {
- // // show: true,
- // // position: 'top',
- // // },
- // data: this.data.all,
- // },
- {
- name: "应完成",
- type: "bar",
- barWidth: "14",
- // label: {
- // show: true,
- // position: 'top',
- // },
- data: this.data.all,
- // itemStyle: {
- // normal: {
- // label: {
- // formatter: function (param) {
- // if (t.data.all[param.dataIndex]) {
- // let rate = param.value / t.data.all[param.dataIndex];
- // return (Math.floor(rate * 1000) / 10).toFixed(1) + "%";
- // } else {
- // return "";
- // }
- // return param.value + "%";
- // },
- // show: false,
- // position: "top",
- // textStyle: {
- // fontWeight: "bolder",
- // fontSize: "10",
- // color: "rgb(245, 245, 245)",
- // },
- // },
- // },
- // },
- },
- {
- name: "已完成",
- type: "line",
- data: this.data.completed,
- },
- ],
- };
- if (option && typeof option === "object") {
- this.myChart.setOption(option);
- }
- },
- resetTimer() {
- this.timer && clearInterval(this.timer);
- this.timer = setInterval(() => {
- if (this.isMouseOver) {
- return;
- }
- this.activeName = getNextPeriod(this.types, this.activeName);
- this.getData();
- }, this.refreshTime);
- },
- },
- };
- </script>
- <style lang="less" scoped></style>
|