Skip to content

Commit

Permalink
Merge pull request #1016 from iview/2.0
Browse files Browse the repository at this point in the history
首页改为响应式布局,优化图表
  • Loading branch information
Lison committed Oct 10, 2018
2 parents 29b9569 + c21cf1b commit e885e77
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 23 deletions.
25 changes: 17 additions & 8 deletions src/components/charts/bar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<script>
import echarts from 'echarts'
import tdTheme from './theme.json'
import { on, off } from '@/libs/tools'
echarts.registerTheme('tdTheme', tdTheme)
export default {
name: 'ChartBar',
Expand All @@ -13,6 +14,16 @@ export default {
text: String,
subtext: String
},
data () {
return {
dom: null
}
},
methods: {
resize () {
this.dom.resize()
}
},
mounted () {
this.$nextTick(() => {
let xAxisData = Object.keys(this.value)
Expand All @@ -35,15 +46,13 @@ export default {
type: 'bar'
}]
}
let dom = echarts.init(this.$refs.dom, 'tdTheme')
dom.setOption(option)
this.dom = echarts.init(this.$refs.dom, 'tdTheme')
this.dom.setOption(option)
on(window, 'resize', this.resize)
})
},
beforeDestroy () {
off(window, 'resize', this.resize)
}
}
</script>

<style lang="less">
.charts{
//
}
</style>
25 changes: 17 additions & 8 deletions src/components/charts/pie.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<script>
import echarts from 'echarts'
import tdTheme from './theme.json'
import { on, off } from '@/libs/tools'
echarts.registerTheme('tdTheme', tdTheme)
export default {
name: 'ChartPie',
Expand All @@ -13,6 +14,16 @@ export default {
text: String,
subtext: String
},
data () {
return {
dom: null
}
},
methods: {
resize () {
this.dom.resize()
}
},
mounted () {
this.$nextTick(() => {
let legend = this.value.map(_ => _.name)
Expand Down Expand Up @@ -47,15 +58,13 @@ export default {
}
]
}
let dom = echarts.init(this.$refs.dom, 'tdTheme')
dom.setOption(option)
this.dom = echarts.init(this.$refs.dom, 'tdTheme')
this.dom.setOption(option)
on(window, 'resize', this.resize)
})
},
beforeDestroy () {
off(window, 'resize', this.resize)
}
}
</script>

<style lang="less">
.charts{
//
}
</style>
4 changes: 2 additions & 2 deletions src/view/single-page/home/example.vue
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ export default {
this.$nextTick(() => {
this.dom = echarts.init(this.$refs.dom)
this.dom.setOption(option)
on(window, 'resize', this.resize())
on(window, 'resize', this.resize)
})
},
beforeDestroy () {
off(window, 'resize', this.resize())
off(window, 'resize', this.resize)
}
}
</script>
10 changes: 5 additions & 5 deletions src/view/single-page/home/home.vue
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
<template>
<div>
<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">
<count-to :end="infor.count" count-class="count-style"/>
<p>{{ infor.title }}</p>
</infor-card>
</i-col>
</Row>
<Row :gutter="20" style="margin-top: 20px;">
<i-col span="8">
<Row :gutter="20" style="margin-top: 10px;">
<i-col :md="24" :lg="8" style="margin-bottom: 20px;">
<Card shadow>
<chart-pie style="height: 300px;" :value="pieData" text="用户访问来源"></chart-pie>
</Card>
</i-col>
<i-col span="16">
<i-col :md="24" :lg="16" style="margin-bottom: 20px;">
<Card shadow>
<chart-bar style="height: 300px;" :value="barData" text="每周用户活跃量"/>
</Card>
</i-col>
</Row>
<Row style="margin-top: 20px;">
<Row>
<Card shadow>
<example style="height: 310px;"/>
</Card>
Expand Down

0 comments on commit e885e77

Please sign in to comment.