import { computed, defineComponent, onBeforeUnmount, onMounted, reactive, ref } from "vue"; // 引入 echarts 核心模块,核心模块提供了 echarts 使用必须要的接口。 import * as echarts from 'echarts/core'; import { LineChart, PieChart, } from 'echarts/charts'; // 引入柱状图图表,图表后缀都为 Chart import { BarChart } from 'echarts/charts'; // 引入标题,提示框,直角坐标系,数据集,内置数据转换器组件,组件后缀都为 Component import { TitleComponent, TooltipComponent, GridComponent, DatasetComponent, TransformComponent } from 'echarts/components'; // 标签自动布局、全局过渡动画等特性 import { LabelLayout, UniversalTransition } from 'echarts/features'; // 引入 Canvas 渲染器,注意引入 CanvasRenderer 或者 SVGRenderer 是必须的一步 import { CanvasRenderer } from 'echarts/renderers'; import useTomatoStore from "../useTomatoStore"; import dayjs from "dayjs"; import gsap from 'gsap' import { Progress } from "ant-design-vue"; // 注册必须的组件 echarts.use([ PieChart, TitleComponent, LineChart, TooltipComponent, GridComponent, DatasetComponent, TransformComponent, BarChart, LabelLayout, UniversalTransition, CanvasRenderer ]); // 接下来的使用就跟之前一样,初始化图表,设置配置项 export default defineComponent(() => { const chart = ref(null); const leftChat = ref(null) const store = useTomatoStore() const precent1 = reactive({ number: 0 }) const precent2 = reactive({ number: 0 }) let myChart: echarts.ECharts | null = null; const initChart = () => { myChart = echarts.init(chart.value); const option = { tooltip: { trigger: 'axis', formatter: (params: any) => { const dataPoint = params[0]; const timeInMinutes = dataPoint.value; // 使用 HTML 标签格式化 tooltip 内容 return `${dataPoint.name}
${timeInMinutes} 分钟`; }, }, xAxis: { type: 'category', data: Array.from({ length: 7 }).map((_, idx) => (dayjs().subtract(idx, 'day').format('MM月DD日'))).reverse(), }, yAxis: { type: 'value', }, series: [ { type: 'line', data: Array.from({ length: 7 }).map((_, idx) => (dayjs().subtract(idx, 'day').format('MM月DD日'))) .reverse() .map(item => store.state.timeList.reduce((pre, cur) => { if (dayjs(cur).isSame(dayjs(item, "MM月DD日"), 'day')) { return pre + 1 } return 0 }, 0) * 15), lineStyle: { color: '#C876FB', // 线条的颜色 width: 2, // 线条宽度 }, itemStyle: { color: '#FF8688', // 数据点的颜色 }, showSymbol: false, // 默认不显示数据点 // hover 时显示数据点 emphasis: { itemStyle: { color: '#FF8688', // 悬停时数据点的颜色 }, showSymbol: true, // 悬停时显示数据点 }, }, ], }; myChart.setOption(option); }; onMounted(() => { initChart(); window.addEventListener('resize', myChart?.resize as any); setTimeout(() => { }, 1000) gsap.to(precent1, { duration: 1, number: Number(100) || 0 }) gsap.to(precent2, { duration: 1, number: Number(100) || 0 }) }); onBeforeUnmount(() => { window.removeEventListener('resize', myChart?.resize as any); myChart?.dispose(); }); return () => (
相比昨天 {(store.todayHour - store.yestodayHour) >= 0 ? "+" : ''}{(store.todayHour - store.yestodayHour) * 100}%
今日专注时长 {(store.todayHour * 0.15).toFixed(2)} h
相比昨天 {(store.todayFinishTarget - store.yesFinishTarget) >= 0 ? "+" : ''}{(store.todayFinishTarget - store.yesFinishTarget) * 100}%
今日完成目标数 {store.todayFinishTarget}
专注时长历史趋势
您的趋势向上,为了美好的明天,继续努力吧!
) })