refactor: 优化代码

This commit is contained in:
Bunny 2025-03-12 09:42:48 +08:00
parent 39afb91f8f
commit 47d4d1055c
22 changed files with 90 additions and 82 deletions

View File

@ -7,10 +7,16 @@ export const css = (mode): CSSOptions => {
const plugins: Plugin[] = [usePostCssPxToViewport8plugin(mode)]; const plugins: Plugin[] = [usePostCssPxToViewport8plugin(mode)];
return { return {
preprocessorOptions: {
scss: {
additionalData: `@use "@/assets/styles/minix/sidebar" as *;`,
api: 'modern-compiler',
},
},
postcss: { postcss: {
plugins: plugins.filter(Boolean), plugins: plugins.filter(Boolean),
}, },
}; } as CSSOptions;
}; };
/** 是否启用px转换vw插件 */ /** 是否启用px转换vw插件 */

View File

@ -1,11 +1,11 @@
@mixin sidebar-1() { @mixin view-style-default($sidebar-width,$content-width) {
&__sidebar { &__sidebar {
display: flex; display: flex;
flex-wrap: wrap; flex-wrap: wrap;
flex-direction: column; flex-direction: column;
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
width: 530px; width: $sidebar-width;
height: 100%; height: 100%;
color: #fff; color: #fff;
@ -42,4 +42,9 @@
color: var(--color-info-secondary-1); color: var(--color-info-secondary-1);
} }
} }
&__content {
width: $content-width;
height: 100%;
}
} }

View File

@ -1,5 +1,5 @@
<script lang="ts" setup> <script lang="ts" setup>
import { TimeSelectType } from '@/components/TimeSelect/type'; import { TimeSelectType } from '@/components/PanelItem/TimeSelect/type';
defineProps({ defineProps({
timeList: Array<TimeSelectType>, timeList: Array<TimeSelectType>,

14
src/utils/chart.ts Normal file
View File

@ -0,0 +1,14 @@
import { useEventListener } from '@vueuse/core';
import type { EChartsType } from 'echarts';
/** 通用重置图表样式 */
export const debounceChart = (myChart: EChartsType) => {
useEventListener(
window,
'resize',
() => {
myChart.resize();
},
500
);
};

View File

@ -1,8 +1,8 @@
<script lang="ts" setup> <script lang="ts" setup>
import { ref } from 'vue'; import { ref } from 'vue';
import TimeSelect from '@/components/TimeSelect/index.vue'; import TimeSelect from '@/components/PanelItem/TimeSelect/index.vue';
import { TimeSelectType } from '@/components/TimeSelect/type'; import { TimeSelectType } from '@/components/PanelItem/TimeSelect/type';
const timeList = ref<TimeSelectType[]>([ const timeList = ref<TimeSelectType[]>([
{ label: '2020.09', value: '2021' }, { label: '2020.09', value: '2021' },
@ -22,9 +22,10 @@ const timeList = ref<TimeSelectType[]>([
<TimeSelect :time-list="timeList" /> <TimeSelect :time-list="timeList" />
</div> </div>
</div> </div>
<ul>
<li> <ul class="big-data__body">
<div class="big-data__left-main-title"> <li class="big-data__body-item">
<div class="big-data__body-title">
<h1>进出口总值</h1> <h1>进出口总值</h1>
<span> <span>
总值增幅 总值增幅
@ -37,22 +38,29 @@ const timeList = ref<TimeSelectType[]>([
</template> </template>
<style lang="scss" scoped> <style lang="scss" scoped>
ul { .big-data__body {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
justify-content: center; justify-content: center;
width: 100%; width: 100%;
height: 100%;
li { &-item {
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center;
margin: 18px 15px;
width: 100%; width: 100%;
} }
.big-data__left-main-title { &-title {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
width: 100%; width: 100%;
em {
font-style: normal;
}
} }
} }
</style> </style>

View File

@ -1,8 +1,8 @@
<script lang="ts" setup> <script lang="ts" setup>
import { ref } from 'vue'; import { ref } from 'vue';
import TimeSelect from '@/components/TimeSelect/index.vue'; import TimeSelect from '@/components/PanelItem/TimeSelect/index.vue';
import { TimeSelectType } from '@/components/TimeSelect/type'; import { TimeSelectType } from '@/components/PanelItem/TimeSelect/type';
const timeList = ref<TimeSelectType[]>([ const timeList = ref<TimeSelectType[]>([
{ label: '2020.09', value: '2021' }, { label: '2020.09', value: '2021' },

View File

@ -13,5 +13,14 @@ import BigDataRight from '@/views/big-data/components/big-data-right/index.vue';
</template> </template>
<style lang="scss"> <style lang="scss">
@use 'style'; .big-data {
display: flex;
justify-content: space-between;
align-items: center;
padding: 19px 25px;
width: 100%;
height: 100%;
@include view-style-default(530px, 748px);
}
</style> </style>

View File

@ -1,17 +0,0 @@
@use "@/assets/styles/common/src/sidebar" as *;
.big-data {
display: flex;
justify-content: space-between;
align-items: center;
padding: 19px 25px;
width: 100%;
height: 100%;
@include sidebar-1();
&__content {
width: 748px;
height: 100%;
}
}

View File

@ -1,10 +1,10 @@
import 'echarts/lib/component/dataZoom'; import 'echarts/lib/component/dataZoom';
import { useDebounceFn, useEventListener } from '@vueuse/core';
import type { EChartsOption } from 'echarts'; import type { EChartsOption } from 'echarts';
import { type Ref, ref } from 'vue'; import { type Ref, ref } from 'vue';
import echarts from '@/plugins/echarts'; import echarts from '@/plugins/echarts';
import { debounceChart } from '@/utils/chart';
const option = ref<EChartsOption>(); const option = ref<EChartsOption>();
option.value = { option.value = {
@ -69,10 +69,7 @@ export const renderEcharts = (element: Ref<HTMLDivElement>) => {
devicePixelRatio: window.devicePixelRatio, devicePixelRatio: window.devicePixelRatio,
}); });
const debouncedFn = useDebounceFn(() => { debounceChart(myChart);
myChart.resize();
}, 1000);
useEventListener(window, 'resize', debouncedFn);
myChart.setOption(option.value); myChart.setOption(option.value);
}; };

View File

@ -1,10 +1,10 @@
import 'echarts/lib/component/dataZoom'; import 'echarts/lib/component/dataZoom';
import { useDebounceFn, useEventListener } from '@vueuse/core';
import type { EChartsOption } from 'echarts'; import type { EChartsOption } from 'echarts';
import { type Ref, ref } from 'vue'; import { type Ref, ref } from 'vue';
import echarts from '@/plugins/echarts'; import echarts from '@/plugins/echarts';
import { debounceChart } from '@/utils/chart';
const option = ref<EChartsOption>(); const option = ref<EChartsOption>();
option.value = { option.value = {
@ -90,10 +90,7 @@ export const renderEcharts = (element: Ref<HTMLDivElement>) => {
devicePixelRatio: window.devicePixelRatio, devicePixelRatio: window.devicePixelRatio,
}); });
const debouncedFn = useDebounceFn(() => { debounceChart(myChart);
myChart.resize();
}, 1000);
useEventListener(window, 'resize', debouncedFn);
myChart.setOption(option.value); myChart.setOption(option.value);
}; };

View File

@ -1,10 +1,10 @@
import 'echarts/lib/component/dataZoom'; import 'echarts/lib/component/dataZoom';
import { useDebounceFn, useEventListener } from '@vueuse/core';
import type { EChartsOption } from 'echarts'; import type { EChartsOption } from 'echarts';
import { type Ref, ref } from 'vue'; import { type Ref, ref } from 'vue';
import echarts from '@/plugins/echarts'; import echarts from '@/plugins/echarts';
import { debounceChart } from '@/utils/chart';
const option = ref<EChartsOption>(); const option = ref<EChartsOption>();
option.value = { option.value = {
@ -50,10 +50,7 @@ export const renderEcharts = (element: Ref<HTMLDivElement>) => {
devicePixelRatio: window.devicePixelRatio, devicePixelRatio: window.devicePixelRatio,
}); });
const debouncedFn = useDebounceFn(() => { debounceChart(myChart);
myChart.resize();
}, 1000);
useEventListener(window, 'resize', debouncedFn);
myChart.setOption(option.value); myChart.setOption(option.value);
}; };

View File

@ -1,9 +1,9 @@
<script lang="ts" setup> <script lang="ts" setup>
import { onMounted, ref } from 'vue'; import { onMounted, ref } from 'vue';
import TimeSelect from '@/components/TimeSelect/index.vue'; import TimeSelect from '@/components/PanelItem/TimeSelect/index.vue';
import { TimeSelectType } from '@/components/TimeSelect/type'; import { TimeSelectType } from '@/components/PanelItem/TimeSelect/type';
import { renderEcharts } from '@/views/business-supervision/components/business-supervision-content/charts/contentBottom'; import { renderEcharts } from '@/views/business-supervision/charts/contentBottom';
const chartYear = ref(); const chartYear = ref();

View File

@ -1,7 +1,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import { onMounted, ref } from 'vue'; import { onMounted, ref } from 'vue';
import { renderEcharts } from '@/views/business-supervision/components/business-supervision-left/charts/sidebarMiddle'; import { renderEcharts } from '@/views/business-supervision/charts/leftSidebarMiddle';
const chartPie = ref<HTMLDivElement>(); const chartPie = ref<HTMLDivElement>();

View File

@ -2,9 +2,9 @@
import { onMounted, ref } from 'vue'; import { onMounted, ref } from 'vue';
import { displayContent } from '@/components/PanelItem/DigitalNumber'; import { displayContent } from '@/components/PanelItem/DigitalNumber';
import TimeSelect from '@/components/TimeSelect/index.vue'; import TimeSelect from '@/components/PanelItem/TimeSelect/index.vue';
import { TimeSelectType } from '@/components/TimeSelect/type'; import { TimeSelectType } from '@/components/PanelItem/TimeSelect/type';
import { renderEcharts } from '@/views/business-supervision/components/business-supervision-left/charts/sidebarTop'; import { renderEcharts } from '@/views/business-supervision/charts/leftSidebarTop';
const chartProgress = ref<HTMLDivElement>(); const chartProgress = ref<HTMLDivElement>();
const money = '1386114'; const money = '1386114';

View File

@ -1,7 +1,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import { onMounted, ref } from 'vue'; import { onMounted, ref } from 'vue';
import BottomChart from '@/views/business-supervision/components/business-supervision-right/chart/bottom-chart.vue'; import BottomChart from '@/views/business-supervision/charts/right-bottom-chart.vue';
const charData1 = ref(Math.round(Math.random() * 100)); const charData1 = ref(Math.round(Math.random() * 100));
const charData2 = ref(Math.round(Math.random() * 100)); const charData2 = ref(Math.round(Math.random() * 100));
@ -99,6 +99,10 @@ onMounted(() => {
&-change { &-change {
display: flex; display: flex;
p {
font-size: 13px;
}
span { span {
display: inline-block; display: inline-block;
margin: 0 0 0 9px; margin: 0 0 0 9px;

View File

@ -1,8 +1,8 @@
<script lang="ts" setup> <script lang="ts" setup>
import { ref } from 'vue'; import { ref } from 'vue';
import TimeSelect from '@/components/TimeSelect/index.vue'; import TimeSelect from '@/components/PanelItem/TimeSelect/index.vue';
import { TimeSelectType } from '@/components/TimeSelect/type'; import { TimeSelectType } from '@/components/PanelItem/TimeSelect/type';
const timeList = ref<TimeSelectType[]>([ const timeList = ref<TimeSelectType[]>([
{ label: '2020.09', value: '2021' }, { label: '2020.09', value: '2021' },

View File

@ -13,5 +13,14 @@ import BusinessSupervisionRight from '@/views/business-supervision/components/bu
</template> </template>
<style lang="scss"> <style lang="scss">
@use 'style.scss'; .business-supervision {
display: flex;
justify-content: space-between;
align-items: center;
padding: 19px 25px;
width: 100%;
height: 100%;
@include view-style-default(530px, 759px);
}
</style> </style>

View File

@ -1,18 +0,0 @@
@use "@/assets/styles/common/src/sidebar" as *;
.business-supervision {
display: flex;
justify-content: space-between;
align-items: center;
padding: 19px 25px;
width: 100%;
height: 100%;
@include sidebar-1();
&__content {
width: 759px;
height: 100%;
}
}

View File

@ -1,10 +1,10 @@
import 'echarts/lib/component/dataZoom'; import 'echarts/lib/component/dataZoom';
import { useDebounceFn, useEventListener } from '@vueuse/core';
import type { EChartsOption } from 'echarts'; import type { EChartsOption } from 'echarts';
import { type Ref, ref } from 'vue'; import { type Ref, ref } from 'vue';
import echarts from '@/plugins/echarts'; import echarts from '@/plugins/echarts';
import { debounceChart } from '@/utils/chart';
const option = ref<EChartsOption>(); const option = ref<EChartsOption>();
option.value = { option.value = {
@ -102,10 +102,7 @@ export const renderEcharts = (element: Ref<HTMLDivElement>) => {
devicePixelRatio: window.devicePixelRatio, devicePixelRatio: window.devicePixelRatio,
}); });
const debouncedFn = useDebounceFn(() => { debounceChart(myChart);
myChart.resize();
}, 1000);
useEventListener(window, 'resize', debouncedFn);
myChart.setOption(option.value); myChart.setOption(option.value);
}; };

View File

@ -1,7 +1,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import { onMounted, ref } from 'vue'; import { onMounted, ref } from 'vue';
import { renderEcharts } from '@/views/smart-park/components/smart-park-content/components/smart-park-sidebar-right/charts/charts'; import { renderEcharts } from '@/views/smart-park/charts/right-sidebar';
const weekDataChart = ref<HTMLDivElement>(); const weekDataChart = ref<HTMLDivElement>();