Commit 78a3ba7b7c3f5de7e6147a3f49aae08b0f7149c2
1 parent
a390d377
泊位
Showing
6 changed files
with
178 additions
and
9 deletions
src/components/halfPieChart.vue
0 → 100644
| 1 | +<template> | ||
| 2 | + <div :class="className" :style="{height:height,width:width}"></div> | ||
| 3 | +</template> | ||
| 4 | + | ||
| 5 | +<script> | ||
| 6 | +import echarts from 'echarts' | ||
| 7 | + | ||
| 8 | +require('echarts/theme/macarons') // echarts theme | ||
| 9 | +import {debounce} from '../utils/debounce' | ||
| 10 | + | ||
| 11 | +export default { | ||
| 12 | + name: 'halfPieChart', | ||
| 13 | + props: { | ||
| 14 | + className: { | ||
| 15 | + type: String, | ||
| 16 | + default: 'chart' | ||
| 17 | + }, | ||
| 18 | + width: { | ||
| 19 | + type: String, | ||
| 20 | + default: '100%' | ||
| 21 | + }, | ||
| 22 | + height: { | ||
| 23 | + type: String, | ||
| 24 | + default: '135px' | ||
| 25 | + }, | ||
| 26 | + autoResize: { | ||
| 27 | + type: Boolean, | ||
| 28 | + default: true | ||
| 29 | + }, | ||
| 30 | + chartData: { | ||
| 31 | + type: Object, | ||
| 32 | + required: true | ||
| 33 | + } | ||
| 34 | + }, | ||
| 35 | + data() { | ||
| 36 | + return { | ||
| 37 | + chart: null, | ||
| 38 | + sidebarElm: null | ||
| 39 | + } | ||
| 40 | + }, | ||
| 41 | + watch: { | ||
| 42 | + chartData: { | ||
| 43 | + deep: true, | ||
| 44 | + } | ||
| 45 | + }, | ||
| 46 | + mounted() { | ||
| 47 | + this.initChart() | ||
| 48 | + if (this.autoResize) { | ||
| 49 | + this.__resizeHandler = debounce(() => { | ||
| 50 | + if (this.chart) { | ||
| 51 | + this.chart.resize() | ||
| 52 | + } | ||
| 53 | + }, 100) | ||
| 54 | + window.addEventListener('resize', this.__resizeHandler) | ||
| 55 | + } | ||
| 56 | + }, | ||
| 57 | + beforeDestroy() { | ||
| 58 | + if (!this.chart) { | ||
| 59 | + return | ||
| 60 | + } | ||
| 61 | + if (this.autoResize) { | ||
| 62 | + window.removeEventListener('resize', this.__resizeHandler) | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + this.chart.dispose() | ||
| 66 | + this.chart = null | ||
| 67 | + }, | ||
| 68 | + methods: { | ||
| 69 | + setOptions({xData, yData} = {}) { | ||
| 70 | + this.chart.setOption({ | ||
| 71 | + tooltip: { | ||
| 72 | + trigger: 'item', | ||
| 73 | + formatter: "{b} : {c} ({d}%)" | ||
| 74 | + }, | ||
| 75 | + series: [ | ||
| 76 | + | ||
| 77 | + { | ||
| 78 | + name: '半径模式', | ||
| 79 | + type: 'pie', | ||
| 80 | + radius: ['75%', '90%'], | ||
| 81 | + center: ['50%', '50%'], | ||
| 82 | + label: { | ||
| 83 | + show: false | ||
| 84 | + }, | ||
| 85 | + lableLine: { | ||
| 86 | + show: false | ||
| 87 | + }, | ||
| 88 | + data: [ | ||
| 89 | + { | ||
| 90 | + value: 35, | ||
| 91 | + name: '诱导屏', | ||
| 92 | + itemStyle: { | ||
| 93 | + normal: { | ||
| 94 | + color: { | ||
| 95 | + colorStops: [{ | ||
| 96 | + offset: 0, | ||
| 97 | + color: '#FFBA00' // 0% 处的颜色 | ||
| 98 | + }, { | ||
| 99 | + offset: 1, | ||
| 100 | + color: '#FF8100' // 100% 处的颜色 | ||
| 101 | + }] | ||
| 102 | + }, | ||
| 103 | + } | ||
| 104 | + } | ||
| 105 | + }, | ||
| 106 | + { | ||
| 107 | + value: 55, | ||
| 108 | + name: '道闸', | ||
| 109 | + itemStyle: { | ||
| 110 | + normal: { | ||
| 111 | + color: { | ||
| 112 | + colorStops: [{ | ||
| 113 | + offset: 0, | ||
| 114 | + color: '#00CAFE' // 0% 处的颜色 | ||
| 115 | + }, { | ||
| 116 | + offset: 1, | ||
| 117 | + color: '#2772F4' // 100% 处的颜色 | ||
| 118 | + }] | ||
| 119 | + }, | ||
| 120 | + } | ||
| 121 | + } | ||
| 122 | + }, | ||
| 123 | + | ||
| 124 | + ], | ||
| 125 | + animationType: 'scale', | ||
| 126 | + animationEasing: 'elasticOut', | ||
| 127 | + animationDelay: function(idx) { | ||
| 128 | + return Math.random() * 200; | ||
| 129 | + } | ||
| 130 | + } | ||
| 131 | + | ||
| 132 | + ] | ||
| 133 | + }) | ||
| 134 | + }, | ||
| 135 | + initChart() { | ||
| 136 | + this.chart = echarts.init(this.$el, 'macarons') | ||
| 137 | + this.setOptions(this.chartData) | ||
| 138 | + } | ||
| 139 | + } | ||
| 140 | +} | ||
| 141 | +</script> |
src/styles/reset.css
src/views/berthsection.vue
| @@ -3,12 +3,18 @@ | @@ -3,12 +3,18 @@ | ||
| 3 | <titlesection title="泊位"></titlesection> | 3 | <titlesection title="泊位"></titlesection> |
| 4 | <totalsection :totalNum="totalVal"></totalsection> | 4 | <totalsection :totalNum="totalVal"></totalsection> |
| 5 | <ul class="flexfm berth-wrap"> | 5 | <ul class="flexfm berth-wrap"> |
| 6 | - <li></li> | 6 | + <li class="pos-rel"> |
| 7 | + <halfPieChart></halfPieChart> | ||
| 8 | + <div class="pos-abs halfPieText"> | ||
| 9 | + <p>78%</p> | ||
| 10 | + <p>占有</p> | ||
| 11 | + </div> | ||
| 12 | + </li> | ||
| 7 | <li> | 13 | <li> |
| 8 | - <div> | 14 | + <div class="berth-main"> |
| 9 | <p><span class="free">{{ free|formatNum }}</span> <span>空余</span></p> | 15 | <p><span class="free">{{ free|formatNum }}</span> <span>空余</span></p> |
| 10 | </div> | 16 | </div> |
| 11 | - <div> | 17 | + <div class="berth-main"> |
| 12 | <p><span class="nofree">{{ nofree|formatNum }}</span> <span>占有</span></p> | 18 | <p><span class="nofree">{{ nofree|formatNum }}</span> <span>占有</span></p> |
| 13 | </div> | 19 | </div> |
| 14 | 20 | ||
| @@ -20,14 +26,15 @@ | @@ -20,14 +26,15 @@ | ||
| 20 | <script> | 26 | <script> |
| 21 | import titlesection from '../components/titlesection' | 27 | import titlesection from '../components/titlesection' |
| 22 | import totalsection from '../components/total' | 28 | import totalsection from '../components/total' |
| 23 | -import { formatNum } from '../filters/filters' | 29 | +import halfPieChart from '../components/halfPieChart' |
| 24 | import {fetchList} from '../api/api' | 30 | import {fetchList} from '../api/api' |
| 25 | 31 | ||
| 26 | export default { | 32 | export default { |
| 27 | name: 'berthsection', | 33 | name: 'berthsection', |
| 28 | components: { | 34 | components: { |
| 29 | titlesection, | 35 | titlesection, |
| 30 | - totalsection | 36 | + totalsection, |
| 37 | + halfPieChart | ||
| 31 | }, | 38 | }, |
| 32 | data() { | 39 | data() { |
| 33 | return { | 40 | return { |
| @@ -55,7 +62,24 @@ export default { | @@ -55,7 +62,24 @@ export default { | ||
| 55 | display: flex; | 62 | display: flex; |
| 56 | li{ | 63 | li{ |
| 57 | flex: 1; | 64 | flex: 1; |
| 58 | - div{ | 65 | + .halfPieText{ |
| 66 | + width: 100%; | ||
| 67 | + text-align: center; | ||
| 68 | + top:50%; | ||
| 69 | + transform:translateY(-50%) ; | ||
| 70 | + p{ | ||
| 71 | + &:nth-of-type(1){ | ||
| 72 | + @include fonttextStyle(24px); | ||
| 73 | + background-image: $fontOrange; | ||
| 74 | + } | ||
| 75 | + &:nth-of-type(2){ | ||
| 76 | + padding-top: 5px; | ||
| 77 | + font-size: 12px; | ||
| 78 | + color: #fff; | ||
| 79 | + } | ||
| 80 | + } | ||
| 81 | + } | ||
| 82 | + .berth-main{ | ||
| 59 | height: 50%; | 83 | height: 50%; |
| 60 | display: flex; | 84 | display: flex; |
| 61 | align-items:center; | 85 | align-items:center; |
src/views/dicisection.vue
| @@ -15,7 +15,6 @@ | @@ -15,7 +15,6 @@ | ||
| 15 | <script> | 15 | <script> |
| 16 | import titlesection from '../components/titlesection' | 16 | import titlesection from '../components/titlesection' |
| 17 | import totalsection from '../components/total' | 17 | import totalsection from '../components/total' |
| 18 | -import { formatNum } from '../filters/filters' | ||
| 19 | import {fetchList} from '../api/api' | 18 | import {fetchList} from '../api/api' |
| 20 | 19 | ||
| 21 | export default { | 20 | export default { |
src/views/sfysection.vue
| @@ -22,7 +22,6 @@ | @@ -22,7 +22,6 @@ | ||
| 22 | <script> | 22 | <script> |
| 23 | import titlesection from '../components/titlesection' | 23 | import titlesection from '../components/titlesection' |
| 24 | import totalsection from '../components/total' | 24 | import totalsection from '../components/total' |
| 25 | -import { formatNum } from '../filters/filters' | ||
| 26 | import {fetchList} from '../api/api' | 25 | import {fetchList} from '../api/api' |
| 27 | 26 | ||
| 28 | export default { | 27 | export default { |
src/views/youdaopingsection.vue
| @@ -26,7 +26,6 @@ | @@ -26,7 +26,6 @@ | ||
| 26 | <script> | 26 | <script> |
| 27 | import titlesection from '../components/titlesection' | 27 | import titlesection from '../components/titlesection' |
| 28 | import allPieChart from '../components/allPieChart' | 28 | import allPieChart from '../components/allPieChart' |
| 29 | -import { formatNum } from '../filters/filters' | ||
| 30 | import {fetchList} from '../api/api' | 29 | import {fetchList} from '../api/api' |
| 31 | 30 | ||
| 32 | const lineChartData = { | 31 | const lineChartData = { |