123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- <template>
- <a-spin :loading="loading" style="width: 100%; height: 100%">
- <a-card
- class="general-card"
- :header-style="{ paddingBottom: '0' }"
- :body-style="{
- padding: '20px',
- height: 'calc(100% - 40px)',
- }"
- :style="{ height: '100%' }"
- >
- <template #title>
- {{ $t('workplace.channelChart') }}
- </template>
- <div class="chart-box" style="height: 100%">
- <Chart :option="chartOptionOne" />
- <!-- <Chart width="50%" :option="chartOptionTwo" /> -->
- </div>
- </a-card>
- </a-spin>
- </template>
- <script lang="ts" setup>
- import useLoading from '@/hooks/loading';
- import useChartOption from '@/hooks/chart-option';
- import { ref } from 'vue';
- import { useI18n } from 'vue-i18n';
- import { queryPolicyList, PolicyParams } from '@/api/list';
- const { t } = useI18n();
- const { loading, setLoading } = useLoading();
- const chartData1 = ref<number>(0);
- const chartData2 = ref<number>(0);
- const countSB = ref<number>(0);
- const countTD = ref<number>(0);
- const splitLineLength = '30%';
- const splitLineDistance = -2;
- const splitLineWidth = 10;
- function toPercentage(hold: number, total: number) {
- if (total === 0) {
- return 0; // 避免除以零的情况
- }
- return ((hold / total) * 100).toFixed(0); // 四舍五入保留两位小数
- }
- const chartOptionFn = (count: any, label: string, data: any) => {
- return (isDark: any) => {
- const fontColor = isDark ? '#ccc' : '#fff';
- return {
- title: {
- text: `{a|${toPercentage(data.value, count.value)}%}\n{b|${t(
- 'workplace.zxs'
- )}: }{d|${data.value} }\n{c|${t(label)}: }{d|${count.value} }`,
- x: 'center',
- y: 'center',
- textStyle: {
- rich: {
- a: {
- fontSize: 30,
- color: fontColor,
- fontWeight: 'bold',
- },
- b: {
- fontSize: 12,
- color: fontColor,
- padding: [10, 0, 0, 0],
- },
- c: {
- fontSize: 12,
- color: fontColor,
- padding: [6, 0, 0, 0],
- },
- d: {
- fontSize: 12,
- color: 'rgb(51, 122, 183)',
- fontWeight: 'bold',
- padding: [6, 0, 0, 0],
- },
- },
- },
- },
- series: [
- {
- type: 'pie',
- radius: ['86%', '70%'],
- silent: true,
- clockwise: true,
- startAngle: -90,
- z: 0,
- zlevel: 0,
- data: [
- {
- value: data.value,
- itemStyle: {
- color: {
- type: 'linear',
- x: 0,
- y: 0,
- x2: 0,
- y2: 1,
- colorStops: [
- {
- offset: 0,
- color: 'rgba(89, 113, 196, 0.6)', // 0% 处的颜色
- },
- {
- offset: 1,
- color: 'rgba(89, 113, 196, 1)', // 100% 处的颜色
- },
- ],
- global: false, // 缺省为 false
- },
- },
- label: {
- show: false,
- },
- },
- {
- value:
- count.value - data.value === 0 ? 0 : count.value - data.value,
- label: {
- show: false,
- },
- itemStyle: {
- color: isDark ? 'rgba(197, 197, 197, 1)' : '#0c336b',
- },
- },
- ],
- },
- {
- name: '',
- type: 'gauge',
- radius: '95%',
- center: ['50%', '50%'],
- startAngle: 0,
- endAngle: 360,
- splitNumber: 30,
- axisTick: {
- show: false,
- },
- splitLine: {
- length: splitLineLength,
- distance: splitLineDistance,
- lineStyle: {
- width: splitLineWidth,
- color: isDark ? 'rgba(35, 35, 36, 1)' : '#051F44',
- },
- },
- axisLabel: {
- show: false,
- },
- pointer: {
- show: false,
- },
- axisLine: {
- show: false,
- },
- },
- ],
- };
- };
- };
- const { chartOption: chartOptionOne } = useChartOption(
- chartOptionFn(countSB, 'workplace.zsb', chartData1)
- );
- // const { chartOption: chartOptionTwo } = useChartOption(
- // chartOptionFn(countTD, 'workplace.ztd', chartData2)
- // );
- const fetchData = async (
- params: PolicyParams = {
- current: 1,
- pageSize: 20,
- Status: 'All',
- }
- ) => {
- setLoading(true);
- try {
- const { data } = await queryPolicyList(params);
- const res = Array.isArray(data) ? data : [];
- countSB.value = res.length;
- countTD.value = res.length;
- const zxs = res.filter((item) => item.status === 'Online').length;
- chartData1.value = zxs;
- chartData2.value = zxs;
- setLoading(false);
- } catch (err) {
- // you can report use errorHandler or other
- } finally {
- setLoading(false);
- }
- };
- fetchData();
- </script>
- <style scoped lang="scss"></style>
|