mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-19 01:04:25 +08:00
code refactor
This commit is contained in:
@@ -24,9 +24,7 @@ interface DesktopPieChartDataItem extends CommonPieChartDataItem {
|
|||||||
selected: boolean;
|
selected: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface DesktopPieChartProps extends CommonPieChartProps {}
|
const props = defineProps<CommonPieChartProps>();
|
||||||
|
|
||||||
const props = defineProps<DesktopPieChartProps>();
|
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
(e: 'click', value: Record<string, unknown>): void;
|
(e: 'click', value: Record<string, unknown>): void;
|
||||||
|
|||||||
@@ -85,8 +85,6 @@ import { type CommonPieChartDataItem, type CommonPieChartProps, usePieChartBase
|
|||||||
import type { ColorValue } from '@/core/color.ts';
|
import type { ColorValue } from '@/core/color.ts';
|
||||||
import { DEFAULT_ICON_COLOR } from '@/consts/color.ts';
|
import { DEFAULT_ICON_COLOR } from '@/consts/color.ts';
|
||||||
|
|
||||||
interface MobilePieChartDataItem extends CommonPieChartDataItem {}
|
|
||||||
|
|
||||||
interface MobilePieChartProps extends CommonPieChartProps {
|
interface MobilePieChartProps extends CommonPieChartProps {
|
||||||
showCenterText?: boolean;
|
showCenterText?: boolean;
|
||||||
showSelectedItemInfo?: boolean;
|
showSelectedItemInfo?: boolean;
|
||||||
@@ -161,12 +159,12 @@ function getColorStyle(color: ColorValue, additionalFieldName?: string): Record<
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getItemStrokeDash(item: MobilePieChartDataItem): string {
|
function getItemStrokeDash(item: CommonPieChartDataItem): string {
|
||||||
const length = item.actualPercent * circumference;
|
const length = item.actualPercent * circumference;
|
||||||
return `${length} ${circumference - length}`;
|
return `${length} ${circumference - length}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getItemDashOffset(item: MobilePieChartDataItem, items: MobilePieChartDataItem[], offset?: number): number {
|
function getItemDashOffset(item: CommonPieChartDataItem, items: CommonPieChartDataItem[], offset?: number): number {
|
||||||
let allPreviousPercent = 0;
|
let allPreviousPercent = 0;
|
||||||
|
|
||||||
for (let i = 0; i < items.length; i++) {
|
for (let i = 0; i < items.length; i++) {
|
||||||
@@ -193,7 +191,7 @@ function getItemDashOffset(item: MobilePieChartDataItem, items: MobilePieChartDa
|
|||||||
return circumference - allPreviousLength + offset;
|
return circumference - allPreviousLength + offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
const selectedItem = computed<MobilePieChartDataItem | null>(() => {
|
const selectedItem = computed<CommonPieChartDataItem | null>(() => {
|
||||||
if (!validItems.value || !validItems.value.length) {
|
if (!validItems.value || !validItems.value.length) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -221,7 +219,7 @@ function switchSelectedItem(offset: number): void {
|
|||||||
selectedIndex.value = newSelectedIndex % validItems.value.length;
|
selectedIndex.value = newSelectedIndex % validItems.value.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
function clickItem(item: MobilePieChartDataItem): void {
|
function clickItem(item: CommonPieChartDataItem): void {
|
||||||
if (props.enableClickItem) {
|
if (props.enableClickItem) {
|
||||||
emit('click', item.sourceItem);
|
emit('click', item.sourceItem);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user