| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- <template>
- <a-spin :loading="loading" style="min-width: 350px">
- <a-card class="general-card" :header-style="{ paddingBottom: '0' }">
- <template #title>
- <template v-if="record.accountName !== ''">
- {{ record.accountName }}
- </template>
- API调用记录 -
- {{
- dayjs(record.report_date).format(
- record.isLeaf ? 'YYYY-MM-DD HH:mm' : 'YYYY-MM-DD'
- )
- }}
- </template>
- <Chart height="200px" :option="chartOption" />
- </a-card>
- </a-spin>
- </template>
- <script lang="ts" setup>
- import dayjs from 'dayjs';
- import useLoading from '@/hooks/loading';
- import { defineProps, ref } from 'vue';
- import {
- TkReportRecord,
- TkReportParams,
- queryTkReportChartData,
- ChartDataResponse,
- } from '@/api/taobao';
- // 使用 defineProps 来定义并接收 props
- const props = defineProps<{
- record: TkReportRecord;
- }>();
- const { loading, setLoading } = useLoading(true);
- const chartOption = ref<any>(null);
- const generateCoolColor = (data: ChartDataResponse[], value: number): string => {
- const colorRange = [
- '#21CCFF', // blue-10
- '#1793FF', // blue-9
- '#1A88F6', // blue-8
- '#1D7DEB', // blue-7
- '#2172E1', // blue-6
- '#2467D6', // blue-5
- '#275CCB', // blue-4
- '#2B51BF', // blue-3
- '#2E47B4', // blue-2
- '#313CA9', // blue-1
- ];
- // 计算数据中的最大值和最小值
- const maxValue = Math.max(...data.map(item => item.value));
- const minValue = Math.min(...data.map(item => item.value));
- return colorRange[Math.round((value - minValue) / (maxValue - minValue) * (colorRange.length - 1))];
- };
- const setChartOption = (data: ChartDataResponse[]) => {
- return {
- legend: {
- left: 'center',
- data: data.map((item) => item.name),
- bottom: 0,
- icon: 'circle',
- itemWidth: 8,
- textStyle: {
- color: '#4E5969',
- },
- itemStyle: {
- borderWidth: 0,
- },
- },
- tooltip: {
- show: true,
- trigger: 'item',
- },
- series: [
- {
- type: 'pie',
- radius: ['30%', '50%'],
- center: ['50%', '40%'],
- label: {
- formatter: '{d}%',
- fontSize: 14,
- color: '#4E5969',
- },
- itemStyle: {
- borderColor: '#fff',
- borderWidth: 1,
- },
- data: data.map((item) => ({
- value: item.value,
- name: item.name,
- itemStyle: {
- color: generateCoolColor(data, item.value),
- },
- })),
- },
- ],
- };
- };
- const fetchData = async (
- params: TkReportParams = {
- current: 1,
- pageSize: 0,
- }
- ) => {
- setLoading(true);
- try {
- const { data } = await queryTkReportChartData(params);
- chartOption.value = setChartOption(data);
- } catch (err) {
- console.log(err);
- // you can report use errorHandler or other
- } finally {
- setLoading(false);
- }
- };
- const search = () => {
- fetchData({
- accountId: props.record.accountId,
- accountName: props.record.accountName,
- isLeaf: props.record.isLeaf,
- query_date: [props.record.report_date],
- } as unknown as TkReportParams);
- };
- search();
- </script>
- <style scoped lang="less">
- .popover-content {
- width: 600px;
- }
- </style>
|