-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
104 changed files
with
1,850 additions
and
2,142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* Copyright (c) 2023 Hengyang Zhang | ||
* | ||
* This software is released under the MIT License. | ||
* https://opensource.org/licenses/MIT | ||
*/ | ||
|
||
import { Ref, defineComponent } from "vue" | ||
import { computedAsync } from "@vueuse/core" | ||
import { labelOfHostInfo } from "../../util" | ||
import { t } from "@app/locale" | ||
import { useAnalysisSite } from "../../context" | ||
import siteService from "@service/site-service" | ||
|
||
const EMPTY_DESC = t(msg => msg.analysis.common.emptyDesc) | ||
|
||
function renderChildren(site: timer.site.SiteInfo) { | ||
if (!site) return <h1 class="site-alias">{EMPTY_DESC}</h1> | ||
|
||
const { iconUrl, alias } = site | ||
const label = labelOfHostInfo(site) | ||
const title: string = alias ? alias : label | ||
const subtitle: string = alias ? label : undefined | ||
return <> | ||
{iconUrl && <img src={iconUrl} width={24} height={24} />} | ||
<h1 class="site-alias">{title}</h1> | ||
{subtitle && <p class="site-host">{subtitle}</p>} | ||
</> | ||
} | ||
|
||
const computedSiteInfo = async (siteKey: timer.site.SiteKey): Promise<timer.site.SiteInfo> => { | ||
if (!siteKey) return undefined | ||
return await siteService.get(siteKey) | ||
} | ||
|
||
const _default = defineComponent(() => { | ||
const site = useAnalysisSite() | ||
const siteInfo: Ref<timer.site.SiteInfo> = computedAsync(() => computedSiteInfo(site.value)) | ||
return () => ( | ||
<div class="site-container"> | ||
{renderChildren(siteInfo.value)} | ||
</div> | ||
) | ||
}) | ||
|
||
export default _default |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/** | ||
* Copyright (c) 2023 Hengyang Zhang | ||
* | ||
* This software is released under the MIT License. | ||
* https://opensource.org/licenses/MIT | ||
*/ | ||
import type { Ref } from "vue" | ||
|
||
import { computed, defineComponent } from "vue" | ||
import Site from "./Site" | ||
import { KanbanIndicatorCell, KanbanCard, KanbanIndicatorRow } from "@app/components/common/kanban" | ||
import "./summary.sass" | ||
import { ElCol } from "element-plus" | ||
import { t } from "@app/locale" | ||
import { cvt2LocaleTime, periodFormatter } from "@app/util/time" | ||
import { useAnalysisRows, useAnalysisSite, useAnalysisTimeFormat } from "../../context" | ||
|
||
type Summary = { | ||
focus: number | ||
visit: number | ||
day: number | ||
firstDay?: string | ||
} | ||
|
||
function computeSummary(site: timer.site.SiteKey, rows: timer.stat.Row[]): Summary { | ||
if (!site) return undefined | ||
|
||
const summary: Summary = { focus: 0, visit: 0, day: 0 } | ||
summary.firstDay = rows?.[0]?.date | ||
rows?.forEach(({ focus, time: visit }) => { | ||
summary.focus += focus | ||
summary.visit += visit | ||
focus && (summary.day += 1) | ||
}) | ||
return summary | ||
} | ||
|
||
const DAYS_LABEL = t(msg => msg.analysis.summary.day) | ||
const FOCUS_LABEL = t(msg => msg.analysis.common.focusTotal) | ||
const VISIT_LABEL = t(msg => msg.analysis.common.visitTotal) | ||
|
||
const _default = defineComponent(() => { | ||
const site = useAnalysisSite() | ||
const timeFormat = useAnalysisTimeFormat() | ||
const rows = useAnalysisRows() | ||
|
||
const summary: Ref<Summary> = computed(() => computeSummary(site.value, rows.value)) | ||
|
||
return () => ( | ||
<KanbanCard title={t(msg => msg.analysis.summary.title)}> | ||
<KanbanIndicatorRow> | ||
<ElCol span={6}> | ||
<Site /> | ||
</ElCol> | ||
<ElCol span={6}> | ||
<KanbanIndicatorCell | ||
mainName={DAYS_LABEL} | ||
mainValue={summary.value?.day?.toString?.() || '-'} | ||
subTips={msg => msg.analysis.summary.firstDay} | ||
subValue={summary.value?.firstDay ? `@${cvt2LocaleTime(summary.value?.firstDay)}` : ''} | ||
/> | ||
</ElCol> | ||
<ElCol span={6}> | ||
<KanbanIndicatorCell | ||
mainName={FOCUS_LABEL} | ||
mainValue={summary.value?.focus === undefined ? '-' : periodFormatter(summary.value?.focus, timeFormat.value, false)} | ||
/> | ||
</ElCol> | ||
<ElCol span={6}> | ||
<KanbanIndicatorCell mainName={VISIT_LABEL} mainValue={summary.value?.visit?.toString?.() || '-'} /> | ||
</ElCol> | ||
</KanbanIndicatorRow> | ||
</KanbanCard> | ||
) | ||
}) | ||
|
||
export default _default |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.