123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- <template>
- <view class="content">
-
- <view class="title"
- :style="`background-color: ${isYellow ? fuzhuColor50 : themeColor25};`">
- {{title}}
- </view>
- <view class="count">
- {{count}}
- </view>
-
- <view :prop="option" :change:prop="echarts.updateEcharts" ref="chartId" :id="chartId" class="echarts" v-show="fuzhuColor50!=null && dataList.length > 0"></view>
-
-
- <view>非 APP、H5 环境不支持</view>
-
- </view>
- </template>
- <script>
- import echarts from '../../static/echarts.js'
-
- export default {
- props: {
- chartId: String,
- title: String,
- count: Number,
- dataList: Array,
-
-
-
-
-
-
- isYellow: Boolean,
- themeColor25: String,
- fuzhuColor50: String,
- },
- data() {
- return {
- option: {
- xAxis: {
- show: false,
- type: 'category',
-
- boundaryGap: ['20%', '20%']
- },
- yAxis: {
- show: false,
- type: 'value',
- boundaryGap: ['70%', '70%']
-
- },
- series: [
- {
- type: 'line',
- smooth: 0.5,
- symbol: 'none',
- lineStyle: {
- color: null,
-
- width: 3
- },
- data: []
- }
- ]
- }
- }
- },
-
- created() {
-
- },
-
- methods: {
- getDataAction() {
- this.option.series[0].data = this.dataList
-
- this.option.series[0].lineStyle.color = this.isYellow ? this.fuzhuColor50 : this.themeColor25
-
- },
- clickAction() {
-
- this.$emit('homeChartItemAction', this.title)
- },
- changeOption() {
- const data = this.option.series[0].data
-
- data.forEach((item, index) => {
- data.splice(index, 1, Math.random() * 40)
- })
- },
- onViewClick(options) {
-
- }
- },
- watch: {
- chartId: {
- handler(e1, e2) {
- if (e1 != e2) {
- this.getDataAction()
- }
- },
- immediate: true
- },
- dataList: {
- handler(e1, e2) {
- var e1Str = JSON.stringify(e1)
- var e2Str = JSON.stringify(e2)
- if (e1Str && e1Str != e2Str) {
- this.getDataAction()
- }
- },
- deep: true,
- immediate: true
- },
- themeColor25: {
- handler(e) {
- if (e) {
- this.option.series[0].lineStyle.color = this.isYellow ? this.fuzhuColor50 : this.themeColor25
- }
- },
- immediate: true
- }
- }
-
- }
- </script>
- <script module="echarts" lang="renderjs">
- let myChart
- export default {
-
-
-
- created() {
- this.initAction()
- },
- mounted() {
-
- },
- methods: {
- initAction() {
- if (typeof window.echarts === 'function') {
- this.initEcharts()
- } else {
-
- const script = document.createElement('script')
-
- script.src = 'static/echarts.js'
- script.onload = this.initEcharts.bind(this)
- document.head.appendChild(script)
- }
- },
- initEcharts() {
-
- if (document.getElementById(this.$refs.chartId.$el.id)) {
- myChart = echarts.init(document.getElementById(this.$refs.chartId.$el.id))
-
- if (myChart) {
- myChart.setOption(this.option)
- }
- else {
-
- this.initAction()
- }
- }
- },
- updateEcharts(newValue, oldValue, ownerInstance, instance) {
- if (myChart) {
-
- myChart.setOption(newValue)
- }
- else {
-
- this.initAction()
- }
- },
- onClick(event, ownerInstance) {
-
- ownerInstance.callMethod('onViewClick', {
- test: 'test'
- })
- }
- }
- }
- </script>
- <style>
- .content {
- width: 100%;
- height: 100%;
- }
-
- .title {
- font-size: 32rpx;
- font-family: Verdana;
- text-align: center;
- width: 176rpx;
- margin-left: calc((100% - 176rpx) / 2);
- line-height: 46rpx;
-
- color: rgba(0, 0, 0, 0.65);
- margin-top: 28rpx;
- margin-left: 20rpx;
- border-radius: 8rpx;
- }
-
- .count {
- width: 100%;
- margin-top: 24rpx;
- height: 48rpx;
- line-height: 48rpx;
- text-align: center;
- font-family: Verdana;
- font-size: 40rpx;
- color: rgba(32, 38, 56, 1);
- }
-
- .echarts {
- margin-top: 10rpx;
- width: 100%;
- height: 80rpx;
- }
- </style>
|