提交 8e547f4f authored 作者: lidongxu's avatar lidongxu

style(首页): 样式重构

解决侧边栏开关,首页 ECharts 图表适配问题
上级 218e6867
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
"@vueuse/core": "10.11.0", "@vueuse/core": "10.11.0",
"axios": "0.28.1", "axios": "0.28.1",
"clipboard": "2.0.11", "clipboard": "2.0.11",
"echarts": "5.5.1", "echarts": "^5.4.0",
"element-plus": "2.7.6", "element-plus": "2.7.6",
"file-saver": "2.0.5", "file-saver": "2.0.5",
"fuse.js": "6.6.2", "fuse.js": "6.6.2",
......
...@@ -98,3 +98,19 @@ ...@@ -98,3 +98,19 @@
.el-select{ .el-select{
width: 215px; width: 215px;
} }
.el-tabs{
flex: 1;
}
.el-row{
margin-left: 0 !important;
margin-right: 0 !important;
.el-col:nth-child(1){
padding-left: 0 !important;
}
.el-col:nth-last-child(1){
padding-right: 0 !important;
}
}
\ No newline at end of file
...@@ -121,9 +121,11 @@ aside { ...@@ -121,9 +121,11 @@ aside {
} }
} }
//main-container全局样式 // main-container全局样式
.app-container { .app-container {
padding: 20px; flex: 1;
display: flex;
flex-direction: column;
} }
.components-container { .components-container {
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
transition: margin-left .28s; transition: margin-left .28s;
margin-left: $base-sidebar-width; margin-left: $base-sidebar-width;
position: relative; position: relative;
box-sizing: border-box;
} }
.sidebarHide { .sidebarHide {
......
...@@ -243,6 +243,6 @@ html.dark { ...@@ -243,6 +243,6 @@ html.dark {
/* 主页背景 */ /* 主页背景 */
.app-main { .app-main {
background-color: var(--el-bg-color) !important; background-color: #141414 !important;
} }
} }
\ No newline at end of file
import { onMounted, onBeforeUnmount } from 'vue'; import { onMounted, onBeforeUnmount } from 'vue';
import useAppStore from '@/store/modules/app';
const sidebar = computed(() => useAppStore().sidebar);
export function useWindowResize(callback) { export function useWindowResize(callback) {
let resizeTimer = null watch(sidebar, () => {
let handleResize = () => { // 等待侧边栏导航动画完成,右侧才有最新宽度再 resize
clearTimeout(resizeTimer) setTimeout(() => {
resizeTimer = setTimeout(() => {
callback() callback()
}, 200) }, 300)
} }, { deep: true })
let observer = new ResizeObserver(handleResize);
onMounted(() => { onMounted(() => {
// 监听侧边栏宽度改变,右边图表要重新绘制
observer.observe(document.querySelector('.sidebar-container'))
window.addEventListener('resize', callback); window.addEventListener('resize', callback);
}); });
onBeforeUnmount(() => { onBeforeUnmount(() => {
if (observer) {
observer.disconnect();
clearTimeout(resizeTimer)
resizeTimer = null
observer = null
handleResize = null
}
window.removeEventListener('resize', callback); window.removeEventListener('resize', callback);
}); });
} }
\ No newline at end of file
<template> <template>
<section class="app-main"> <section class="app-main">
<router-view v-slot="{ Component, route }"> <router-view v-slot="{ Component, route }">
<transition name="fade-transform" mode="out-in"> <transition name="fade-transform"
mode="out-in">
<keep-alive :include="tagsViewStore.cachedViews"> <keep-alive :include="tagsViewStore.cachedViews">
<component v-if="!route.meta.link" :is="Component" :key="route.path"/> <component v-if="!route.meta.link"
:is="Component"
:key="route.path" />
</keep-alive> </keep-alive>
</transition> </transition>
</router-view> </router-view>
...@@ -33,30 +36,20 @@ function addIframe() { ...@@ -33,30 +36,20 @@ function addIframe() {
} }
</script> </script>
<style lang="scss" scoped> <style lang="scss"
.app-main { scoped>
.app-main {
/* 50= navbar 50 */ /* 50= navbar 50 */
min-height: calc(100vh - 50px); min-height: calc(100vh - 50px);
padding: 20px;
width: 100%; width: 100%;
position: relative; position: relative;
overflow: hidden; overflow: hidden;
background-color: var(--el-bg-color); background-color: var(--el-bg-color);
} display: flex;
flex-direction: column;
.fixed-header + .app-main {
padding-top: 50px;
}
.hasTagsView {
.app-main {
/* 84 = navbar + tags-view = 50 + 34 */
min-height: calc(100vh - 84px);
} }
.fixed-header + .app-main {
padding-top: 84px;
}
}
</style> </style>
<style lang="scss"> <style lang="scss">
...@@ -81,4 +74,3 @@ function addIframe() { ...@@ -81,4 +74,3 @@ function addIframe() {
border-radius: 3px; border-radius: 3px;
} }
</style> </style>
...@@ -23,7 +23,6 @@ ...@@ -23,7 +23,6 @@
import { useWindowSize } from '@vueuse/core' import { useWindowSize } from '@vueuse/core'
import Sidebar from './components/Sidebar/index.vue' import Sidebar from './components/Sidebar/index.vue'
import { AppMain, Navbar, Settings, TagsView } from './components' import { AppMain, Navbar, Settings, TagsView } from './components'
import useAppStore from '@/store/modules/app' import useAppStore from '@/store/modules/app'
import useSettingsStore from '@/store/modules/settings' import useSettingsStore from '@/store/modules/settings'
...@@ -43,7 +42,7 @@ const classObj = computed(() => ({ ...@@ -43,7 +42,7 @@ const classObj = computed(() => ({
})) }))
const { width, height } = useWindowSize(); const { width, height } = useWindowSize();
const WIDTH = 992; // refer to Bootstrap's responsive design const WIDTH = 992;
watch(() => device.value, () => { watch(() => device.value, () => {
if (device.value === 'mobile' && sidebar.value.opened) { if (device.value === 'mobile' && sidebar.value.opened) {
...@@ -109,8 +108,24 @@ function setLayout() { ...@@ -109,8 +108,24 @@ function setLayout() {
// 开启头部固定以后,main的高度需要设置为100vh // 开启头部固定以后,main的高度需要设置为100vh
.fixed-header+.app-main { .fixed-header+.app-main {
min-height: 100vh; min-height: 100vh;
padding-top: 50px + 20px;
}
// 有头部标签导航时
.hasTagsView {
.app-main {
/* 84 = navbar + tags-view = 50 + 34 */
// min-height: calc(100vh - 84px);
min-height: 100vh;
}
.fixed-header+.app-main {
padding-top: 84px + 20px;
}
} }
// 侧边栏导航隐藏时
.hideSidebar .fixed-header { .hideSidebar .fixed-header {
width: calc(100% - 54px); width: calc(100% - 54px);
} }
......
...@@ -267,7 +267,7 @@ const reset = async () => { ...@@ -267,7 +267,7 @@ const reset = async () => {
flex-direction: column; flex-direction: column;
.chart_wrap { .chart_wrap {
padding: 20px 0; /* padding: 20px 0; */
flex: 1; flex: 1;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
......
...@@ -30,14 +30,12 @@ const activeName = ref(list.value[0].name) ...@@ -30,14 +30,12 @@ const activeName = ref(list.value[0].name)
<style scoped <style scoped
lang="scss"> lang="scss">
.app-container { .app-container {
min-height: calc(100vh - 84px);
.tabs { .tabs {
background: var(--el-bg-color-overlay); background: var(--el-bg-color-overlay);
padding: 20px; padding: 20px;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
min-height: 100%;
::v-deep(.el-tabs__content) { ::v-deep(.el-tabs__content) {
flex: 1; flex: 1;
......
...@@ -61,18 +61,27 @@ const initChart = () => { ...@@ -61,18 +61,27 @@ const initChart = () => {
stack: 'vistors', stack: 'vistors',
barWidth: '60%', barWidth: '60%',
data: [79, 52, 200, 334, 390, 330, 220], data: [79, 52, 200, 334, 390, 330, 220],
animation: true,
animationDuration: 2000,
animationEasing: 'cubicInOut'
}, { }, {
name: '冷热双吃', name: '冷热双吃',
type: 'bar', type: 'bar',
stack: 'vistors', stack: 'vistors',
barWidth: '60%', barWidth: '60%',
data: [80, 52, 200, 334, 390, 330, 220], data: [80, 52, 200, 334, 390, 330, 220],
animation: true,
animationDuration: 2000,
animationEasing: 'cubicInOut'
}, { }, {
name: '去骨凤爪', name: '去骨凤爪',
type: 'bar', type: 'bar',
stack: 'vistors', stack: 'vistors',
barWidth: '60%', barWidth: '60%',
data: [30, 52, 200, 334, 390, 330, 220], data: [30, 52, 200, 334, 390, 330, 220],
animation: true,
animationDuration: 2000,
animationEasing: 'cubicInOut'
}] }]
}) })
} }
...@@ -80,6 +89,7 @@ const resize = () => { ...@@ -80,6 +89,7 @@ const resize = () => {
chart.resize() chart.resize()
} }
useWindowResize(resize) useWindowResize(resize)
onMounted(() => { onMounted(() => {
nextTick(() => { nextTick(() => {
initChart() initChart()
......
...@@ -21,10 +21,6 @@ const props = defineProps({ ...@@ -21,10 +21,6 @@ const props = defineProps({
type: String, type: String,
default: '350px' default: '350px'
}, },
autoResize: {
type: Boolean,
default: true
},
chartData: { chartData: {
type: Object, type: Object,
required: true required: true
...@@ -69,7 +65,8 @@ const setOptions = () => { ...@@ -69,7 +65,8 @@ const setOptions = () => {
} }
}, },
series: [{ series: [{
name: '今年销量', itemStyle: { name: '今年销量',
itemStyle: {
// normal: { // normal: {
color: '#FF005A', color: '#FF005A',
lineStyle: { lineStyle: {
...@@ -81,7 +78,8 @@ const setOptions = () => { ...@@ -81,7 +78,8 @@ const setOptions = () => {
smooth: true, smooth: true,
type: 'line', type: 'line',
data: props.chartData.expectedData, data: props.chartData.expectedData,
animationEasing: 'cubicInOut' // animationEasing: 'cubicInOut',
animationDuration: 2000
}, },
{ {
name: '去年销量', name: '去年销量',
...@@ -100,7 +98,8 @@ const setOptions = () => { ...@@ -100,7 +98,8 @@ const setOptions = () => {
// } // }
}, },
data: props.chartData.actualData, data: props.chartData.actualData,
animationEasing: 'quadraticOut' // animationEasing: 'quadraticOut'
animationDuration: 2000
}] }]
}) })
} }
...@@ -109,20 +108,15 @@ watch(() => props.chartData, (newData, oldData) => { ...@@ -109,20 +108,15 @@ watch(() => props.chartData, (newData, oldData) => {
setOptions(); setOptions();
}, { deep: true }); }, { deep: true });
const initChart = () => { onMounted(() => {
nextTick(() => {
chart = echarts.init(chartRef.value) chart = echarts.init(chartRef.value)
setOptions() setOptions()
} })
})
const resize = () => { useWindowResize(() => {
chart.resize() chart.resize()
}
useWindowResize(resize)
onMounted(() => {
nextTick(() => {
initChart()
})
}) })
onBeforeUnmount(() => { onBeforeUnmount(() => {
......
<template> <template>
<el-row :gutter="40" <el-row class="panel-group" :gutter="20">
class="panel-group">
<el-col :xs="12" <el-col :xs="12"
:sm="12" :sm="12"
:lg="6" :lg="6"
...@@ -100,11 +99,8 @@ const handleSetLineChartData = (type) => { ...@@ -100,11 +99,8 @@ const handleSetLineChartData = (type) => {
<style lang="scss" <style lang="scss"
scoped> scoped>
.panel-group { .panel-group {
margin-top: 18px;
.card-panel-col { .card-panel-col {
margin-bottom: 32px;
}
.card-panel { .card-panel {
height: 108px; height: 108px;
...@@ -187,6 +183,7 @@ const handleSetLineChartData = (type) => { ...@@ -187,6 +183,7 @@ const handleSetLineChartData = (type) => {
} }
} }
} }
}
@media (max-width:550px) { @media (max-width:550px) {
.card-panel-description { .card-panel-description {
......
...@@ -56,6 +56,7 @@ const initChart = () => { ...@@ -56,6 +56,7 @@ const initChart = () => {
{ value: 59, name: '杭州' } { value: 59, name: '杭州' }
], ],
animationEasing: 'cubicInOut', animationEasing: 'cubicInOut',
animationDuration: 2000,
} }
] ]
}) })
......
...@@ -6,10 +6,9 @@ ...@@ -6,10 +6,9 @@
<script setup> <script setup>
import * as echarts from 'echarts' import * as echarts from 'echarts'
import { onBeforeUnmount } from 'vue'
import { useWindowResize } from '@/hooks' import { useWindowResize } from '@/hooks'
defineProps({ const props = defineProps({
className: { className: {
type: String, type: String,
default: 'chart' default: 'chart'
...@@ -24,12 +23,10 @@ defineProps({ ...@@ -24,12 +23,10 @@ defineProps({
} }
}) })
let chart = null let chart = {}
const chartRef = ref(null) const chartRef = ref(null)
const initChart = () => { const setOptions = () => {
chart = echarts.init(chartRef.value)
chart.setOption({ chart.setOption({
tooltip: { tooltip: {
trigger: 'axis', trigger: 'axis',
...@@ -83,32 +80,35 @@ const initChart = () => { ...@@ -83,32 +80,35 @@ const initChart = () => {
data: [ data: [
{ {
value: [5000, 7000, 12000, 11000, 15000, 14000], value: [5000, 7000, 12000, 11000, 15000, 14000],
name: '营销中心' name: '营销中心',
animationDuration: 2000
}, },
{ {
value: [4000, 9000, 15000, 15000, 13000, 11000], value: [4000, 9000, 15000, 15000, 13000, 11000],
name: '人力资源中心' name: '人力资源中心',
animationDuration: 2000
}, },
{ {
value: [5500, 11000, 12000, 15000, 12000, 12000], value: [5500, 11000, 12000, 15000, 12000, 12000],
name: '财务中心' name: '财务中心',
animationDuration: 2000
} }
] ]
}] }]
}) })
} }
const resize = () => {
chart.resize()
}
useWindowResize(resize)
onMounted(() => { onMounted(() => {
nextTick(() => { nextTick(() => {
initChart() chart = echarts.init(chartRef.value)
setOptions()
}) })
}) })
useWindowResize(() => {
chart.resize()
})
onBeforeUnmount(() => { onBeforeUnmount(() => {
if (!chart) { if (!chart) {
return return
......
<template> <template>
<div class="dashboard-editor-container"> <div class="dashboard-editor-container app-container">
<panel-group @handleSetLineChartData="handleSetLineChartData" /> <panel-group @handleSetLineChartData="handleSetLineChartData" />
<div class="row">
<common-menu></common-menu> <common-menu></common-menu>
<el-row :gutter="32"> </div>
<el-row :gutter="32" class="row">
<el-col :xs="24" <el-col :xs="24"
:sm="24" :sm="24"
:lg="8"> :lg="8">
...@@ -25,8 +28,8 @@ ...@@ -25,8 +28,8 @@
</div> </div>
</el-col> </el-col>
</el-row> </el-row>
<el-row class="line-chart"> <el-row class="line-chart row">
<line-chart :chart-data="lineChartData" /> <line-chart :chartData="lineChartData"/>
</el-row> </el-row>
</div> </div>
</template> </template>
...@@ -66,18 +69,22 @@ const handleSetLineChartData = (type) => { ...@@ -66,18 +69,22 @@ const handleSetLineChartData = (type) => {
<style lang="scss" <style lang="scss"
scoped> scoped>
.dashboard-editor-container { .dashboard-editor-container {
padding: 32px; .row{
margin-top: 20px;
}
.chart-wrapper { .chart-wrapper {
background: var(--el-bg-color-overlay); background: var(--el-bg-color-overlay);
padding: 16px 16px 0; padding: 16px 16px 0;
margin: 32px 0;
} }
.line-chart { .line-chart {
background: var(--el-bg-color-overlay); background: var(--el-bg-color-overlay);
padding: 16px 16px 0; padding: 16px 16px 0;
margin-bottom: 32px; }
::v-deep(.el-row) {
width: 100%;
} }
} }
</style> </style>
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论