Merge pull request #1016 from iview/2.0

首页改为响应式布局,优化图表
This commit is contained in:
Lison 2018-10-10 16:21:23 +08:00 committed by GitHub
commit e885e77a54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 41 additions and 23 deletions

View File

@ -5,6 +5,7 @@
<script> <script>
import echarts from 'echarts' import echarts from 'echarts'
import tdTheme from './theme.json' import tdTheme from './theme.json'
import { on, off } from '@/libs/tools'
echarts.registerTheme('tdTheme', tdTheme) echarts.registerTheme('tdTheme', tdTheme)
export default { export default {
name: 'ChartBar', name: 'ChartBar',
@ -13,6 +14,16 @@ export default {
text: String, text: String,
subtext: String subtext: String
}, },
data () {
return {
dom: null
}
},
methods: {
resize () {
this.dom.resize()
}
},
mounted () { mounted () {
this.$nextTick(() => { this.$nextTick(() => {
let xAxisData = Object.keys(this.value) let xAxisData = Object.keys(this.value)
@ -35,15 +46,13 @@ export default {
type: 'bar' type: 'bar'
}] }]
} }
let dom = echarts.init(this.$refs.dom, 'tdTheme') this.dom = echarts.init(this.$refs.dom, 'tdTheme')
dom.setOption(option) this.dom.setOption(option)
on(window, 'resize', this.resize)
}) })
},
beforeDestroy () {
off(window, 'resize', this.resize)
} }
} }
</script> </script>
<style lang="less">
.charts{
//
}
</style>

View File

@ -5,6 +5,7 @@
<script> <script>
import echarts from 'echarts' import echarts from 'echarts'
import tdTheme from './theme.json' import tdTheme from './theme.json'
import { on, off } from '@/libs/tools'
echarts.registerTheme('tdTheme', tdTheme) echarts.registerTheme('tdTheme', tdTheme)
export default { export default {
name: 'ChartPie', name: 'ChartPie',
@ -13,6 +14,16 @@ export default {
text: String, text: String,
subtext: String subtext: String
}, },
data () {
return {
dom: null
}
},
methods: {
resize () {
this.dom.resize()
}
},
mounted () { mounted () {
this.$nextTick(() => { this.$nextTick(() => {
let legend = this.value.map(_ => _.name) let legend = this.value.map(_ => _.name)
@ -47,15 +58,13 @@ export default {
} }
] ]
} }
let dom = echarts.init(this.$refs.dom, 'tdTheme') this.dom = echarts.init(this.$refs.dom, 'tdTheme')
dom.setOption(option) this.dom.setOption(option)
on(window, 'resize', this.resize)
}) })
},
beforeDestroy () {
off(window, 'resize', this.resize)
} }
} }
</script> </script>
<style lang="less">
.charts{
//
}
</style>

View File

@ -104,11 +104,11 @@ export default {
this.$nextTick(() => { this.$nextTick(() => {
this.dom = echarts.init(this.$refs.dom) this.dom = echarts.init(this.$refs.dom)
this.dom.setOption(option) this.dom.setOption(option)
on(window, 'resize', this.resize()) on(window, 'resize', this.resize)
}) })
}, },
beforeDestroy () { beforeDestroy () {
off(window, 'resize', this.resize()) off(window, 'resize', this.resize)
} }
} }
</script> </script>

View File

@ -1,26 +1,26 @@
<template> <template>
<div> <div>
<Row :gutter="20"> <Row :gutter="20">
<i-col span="4" v-for="(infor, i) in inforCardData" :key="`infor-${i}`" style="height: 120px;"> <i-col :xs="12" :md="8" :lg="4" v-for="(infor, i) in inforCardData" :key="`infor-${i}`" style="height: 120px;padding-bottom: 10px;">
<infor-card shadow :color="infor.color" :icon="infor.icon" :icon-size="36"> <infor-card shadow :color="infor.color" :icon="infor.icon" :icon-size="36">
<count-to :end="infor.count" count-class="count-style"/> <count-to :end="infor.count" count-class="count-style"/>
<p>{{ infor.title }}</p> <p>{{ infor.title }}</p>
</infor-card> </infor-card>
</i-col> </i-col>
</Row> </Row>
<Row :gutter="20" style="margin-top: 20px;"> <Row :gutter="20" style="margin-top: 10px;">
<i-col span="8"> <i-col :md="24" :lg="8" style="margin-bottom: 20px;">
<Card shadow> <Card shadow>
<chart-pie style="height: 300px;" :value="pieData" text="用户访问来源"></chart-pie> <chart-pie style="height: 300px;" :value="pieData" text="用户访问来源"></chart-pie>
</Card> </Card>
</i-col> </i-col>
<i-col span="16"> <i-col :md="24" :lg="16" style="margin-bottom: 20px;">
<Card shadow> <Card shadow>
<chart-bar style="height: 300px;" :value="barData" text="每周用户活跃量"/> <chart-bar style="height: 300px;" :value="barData" text="每周用户活跃量"/>
</Card> </Card>
</i-col> </i-col>
</Row> </Row>
<Row style="margin-top: 20px;"> <Row>
<Card shadow> <Card shadow>
<example style="height: 310px;"/> <example style="height: 310px;"/>
</Card> </Card>