mirror of
https://github.com/sharevb/it-tools.git
synced 2026-12-02 09:42:10 +03:00
367 lines
9.1 KiB
Vue
367 lines
9.1 KiB
Vue
<template>
|
|
<div>
|
|
<n-grid :cols="24" :x-gap="16">
|
|
<n-grid-item :span="6">
|
|
<n-form-item :label="t('tools.running-planner.texts.label-unit')" label-placement="left">
|
|
<n-select v-model:value="unit" :options="unitOptions" />
|
|
</n-form-item>
|
|
</n-grid-item>
|
|
|
|
<n-grid-item :span="10">
|
|
<n-form-item :label="t('tools.running-planner.texts.label-race')" label-placement="left">
|
|
<n-select :value="selectedRace" :options="raceOptions" clearable @update:value="onRaceSelect" />
|
|
</n-form-item>
|
|
</n-grid-item>
|
|
|
|
<n-grid-item :span="8">
|
|
<n-form-item :label="$t('tools.running-planner.texts.distance-unit', [unit])" label-placement="left">
|
|
<n-input-number v-model:value="distance" :min="1" :max="100" :step="0.1" style="width: 100%" />
|
|
</n-form-item>
|
|
</n-grid-item>
|
|
</n-grid>
|
|
|
|
<n-grid :cols="24" :x-gap="16">
|
|
<n-grid-item :span="12">
|
|
<n-form-item :label="$t('tools.running-planner.texts.pace-unitlabel', [unitLabel])" label-placement="left">
|
|
<n-grid :cols="2" :x-gap="8">
|
|
<n-grid-item>
|
|
<n-input-number
|
|
v-model:value="paceMinutes"
|
|
:placeholder="t('tools.running-planner.texts.placeholder-minutes')"
|
|
:min="0"
|
|
:max="30"
|
|
style="width: 100%"
|
|
/>
|
|
</n-grid-item>
|
|
|
|
<n-grid-item>
|
|
<n-input-number
|
|
v-model:value="paceSeconds"
|
|
:placeholder="t('tools.running-planner.texts.placeholder-seconds')"
|
|
:min="0"
|
|
:max="59"
|
|
style="width: 100%"
|
|
/>
|
|
</n-grid-item>
|
|
</n-grid>
|
|
</n-form-item>
|
|
</n-grid-item>
|
|
|
|
<n-grid-item :span="12">
|
|
<n-form-item :label="t('tools.running-planner.texts.label-checkpoints')" label-placement="left">
|
|
<n-select v-model:value="splitInterval" :options="intervalOptions" />
|
|
</n-form-item>
|
|
</n-grid-item>
|
|
</n-grid>
|
|
|
|
<n-space justify="center" mb-3>
|
|
<n-button v-for="race in racePresets" :key="race.value" secondary @click="applyRace(race)">
|
|
{{ race.label }}
|
|
</n-button>
|
|
</n-space>
|
|
|
|
<n-card>
|
|
<n-grid :cols="2">
|
|
<n-grid-item>
|
|
<n-statistic :label="t('tools.running-planner.texts.label-race')" :value="distanceName" />
|
|
</n-grid-item>
|
|
|
|
<n-grid-item>
|
|
<n-statistic
|
|
:label="t('tools.running-planner.texts.label-estimated-finish-time')"
|
|
:value="estimatedFinishTime"
|
|
/>
|
|
</n-grid-item>
|
|
</n-grid>
|
|
</n-card>
|
|
|
|
<n-card :title="t('tools.running-planner.texts.title-projected-checkpoints')">
|
|
<n-data-table :columns="columns" :data="rows" :pagination="{ pageSize: 20 }" :bordered="false" />
|
|
</n-card>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { useI18n } from 'vue-i18n';
|
|
const { t } = useI18n();
|
|
import { computed, h, ref } from 'vue';
|
|
import { NTag, type DataTableColumns } from 'naive-ui';
|
|
|
|
type Unit = 'km' | 'mi';
|
|
|
|
const KM_PER_MILE = 1.609344;
|
|
|
|
const unit = ref<Unit>('km');
|
|
|
|
const paceMinutes = ref(5);
|
|
const paceSeconds = ref(0);
|
|
|
|
const distance = ref(42.195);
|
|
|
|
const splitInterval = ref(5);
|
|
|
|
const selectedRace = ref<string | null>('marathon');
|
|
|
|
const unitOptions = [
|
|
{
|
|
label: t('tools.running-planner.texts.label-kilometers'),
|
|
value: 'km',
|
|
},
|
|
{
|
|
label: t('tools.running-planner.texts.label-miles'),
|
|
value: 'mi',
|
|
},
|
|
];
|
|
|
|
const racePresets = [
|
|
{
|
|
label: t('tools.running-planner.texts.label-5k'),
|
|
value: '5k',
|
|
distanceKm: 5,
|
|
},
|
|
{
|
|
label: t('tools.running-planner.texts.label-10k'),
|
|
value: '10k',
|
|
distanceKm: 10,
|
|
},
|
|
{
|
|
label: t('tools.running-planner.texts.label-15k'),
|
|
value: '15k',
|
|
distanceKm: 15,
|
|
},
|
|
{
|
|
label: t('tools.running-planner.texts.label-10-mile'),
|
|
value: '10mile',
|
|
distanceKm: 16.09344,
|
|
},
|
|
{
|
|
label: t('tools.running-planner.texts.label-20k'),
|
|
value: '20k',
|
|
distanceKm: 20,
|
|
},
|
|
{
|
|
label: t('tools.running-planner.texts.label-half-marathon'),
|
|
value: 'half',
|
|
distanceKm: 21.0975,
|
|
},
|
|
{
|
|
label: t('tools.running-planner.texts.label-25k'),
|
|
value: '25k',
|
|
distanceKm: 25,
|
|
},
|
|
{
|
|
label: t('tools.running-planner.texts.label-30k'),
|
|
value: '30k',
|
|
distanceKm: 30,
|
|
},
|
|
{
|
|
label: t('tools.running-planner.texts.label-marathon'),
|
|
value: 'marathon',
|
|
distanceKm: 42.195,
|
|
},
|
|
{
|
|
label: t('tools.running-planner.texts.label-50k-ultra'),
|
|
value: '50k',
|
|
distanceKm: 50,
|
|
},
|
|
];
|
|
|
|
const raceOptions = racePresets.map((r) => ({
|
|
label: r.label,
|
|
value: r.value,
|
|
}));
|
|
|
|
const unitLabel = computed(() => (unit.value === 'km' ? 'min/km' : 'min/mi'));
|
|
|
|
function kmToMiles(km: number) {
|
|
return km / KM_PER_MILE;
|
|
}
|
|
|
|
function milesToKm(mi: number) {
|
|
return mi * KM_PER_MILE;
|
|
}
|
|
|
|
function formatDuration(totalSeconds: number) {
|
|
const hours = Math.floor(totalSeconds / 3600);
|
|
|
|
const minutes = Math.floor((totalSeconds % 3600) / 60);
|
|
|
|
const seconds = Math.round(totalSeconds % 60);
|
|
|
|
return `${String(hours).padStart(2, '0')}:${String(minutes).padStart(2, '0')}:${String(seconds).padStart(2, '0')}`;
|
|
}
|
|
|
|
function paceToLabel(seconds: number) {
|
|
const m = Math.floor(seconds / 60);
|
|
const s = seconds % 60;
|
|
|
|
return `${m}:${String(s).padStart(2, '0')}/${unit.value}`;
|
|
}
|
|
|
|
function applyRace(race: (typeof racePresets)[number]) {
|
|
selectedRace.value = race.value;
|
|
|
|
distance.value = unit.value === 'km' ? race.distanceKm : kmToMiles(race.distanceKm);
|
|
}
|
|
|
|
function onRaceSelect(value: string | null) {
|
|
if (!value) {
|
|
return;
|
|
}
|
|
|
|
const found = racePresets.find((r) => r.value === value);
|
|
|
|
if (found) {
|
|
applyRace(found);
|
|
}
|
|
}
|
|
|
|
const intervalOptions = computed(() => {
|
|
return unit.value === 'km'
|
|
? [
|
|
{
|
|
label: t('tools.running-planner.texts.label-every-1-km'),
|
|
value: 1,
|
|
},
|
|
{
|
|
label: t('tools.running-planner.texts.label-every-2-km'),
|
|
value: 2,
|
|
},
|
|
{
|
|
label: t('tools.running-planner.texts.label-every-5-km'),
|
|
value: 5,
|
|
},
|
|
{
|
|
label: t('tools.running-planner.texts.label-every-10-km'),
|
|
value: 10,
|
|
},
|
|
]
|
|
: [
|
|
{
|
|
label: t('tools.running-planner.texts.label-every-1-mile'),
|
|
value: 1,
|
|
},
|
|
{
|
|
label: t('tools.running-planner.texts.label-every-2-miles'),
|
|
value: 2,
|
|
},
|
|
{
|
|
label: t('tools.running-planner.texts.label-every-5-miles'),
|
|
value: 5,
|
|
},
|
|
];
|
|
});
|
|
|
|
const paceInSeconds = computed(() => paceMinutes.value * 60 + paceSeconds.value);
|
|
|
|
const distanceName = computed(() => {
|
|
const currentKm = unit.value === 'km' ? distance.value : milesToKm(distance.value);
|
|
|
|
const found = racePresets.find((race) => Math.abs(race.distanceKm - currentKm) < 0.1);
|
|
|
|
return found?.label ?? t('tools.running-planner.texts.custom-distance');
|
|
});
|
|
|
|
const paceVariants = computed(() => [
|
|
{
|
|
key: 'minus60',
|
|
title: '-1:00',
|
|
seconds: Math.max(60, paceInSeconds.value - 60),
|
|
},
|
|
{
|
|
key: 'minus30',
|
|
title: '-0:30',
|
|
seconds: Math.max(60, paceInSeconds.value - 30),
|
|
},
|
|
{
|
|
key: 'target',
|
|
title: t('tools.running-planner.texts.target'),
|
|
seconds: paceInSeconds.value,
|
|
},
|
|
{
|
|
key: 'plus30',
|
|
title: '+0:30',
|
|
seconds: paceInSeconds.value + 30,
|
|
},
|
|
{
|
|
key: 'plus60',
|
|
title: '+1:00',
|
|
seconds: paceInSeconds.value + 60,
|
|
},
|
|
]);
|
|
|
|
const estimatedFinishTime = computed(() => formatDuration(distance.value * paceInSeconds.value));
|
|
|
|
const rows = computed(() => {
|
|
const data: Record<string, any>[] = [];
|
|
|
|
let current = splitInterval.value;
|
|
|
|
while (current < distance.value) {
|
|
const row: Record<string, any> = {
|
|
distance: current,
|
|
finish: false,
|
|
};
|
|
|
|
paceVariants.value.forEach((variant) => {
|
|
row[variant.key] = formatDuration(current * variant.seconds);
|
|
});
|
|
|
|
data.push(row);
|
|
|
|
current += splitInterval.value;
|
|
}
|
|
|
|
const finishRow: Record<string, any> = {
|
|
distance: distance.value,
|
|
finish: true,
|
|
};
|
|
|
|
paceVariants.value.forEach((variant) => {
|
|
finishRow[variant.key] = formatDuration(distance.value * variant.seconds);
|
|
});
|
|
|
|
data.push(finishRow);
|
|
|
|
return data;
|
|
});
|
|
|
|
const columns = computed<DataTableColumns<any>>(() => {
|
|
const result: DataTableColumns<any> = [
|
|
{
|
|
title: t('tools.running-planner.texts.distance-unit-value', [unit.value]),
|
|
key: 'distance',
|
|
width: 160,
|
|
fixed: 'left',
|
|
render(row) {
|
|
if (row.finish) {
|
|
return h(
|
|
NTag,
|
|
{
|
|
type: 'success',
|
|
},
|
|
{
|
|
default: () => `${row.distance.toFixed(2)} ${unit.value}`,
|
|
},
|
|
);
|
|
}
|
|
|
|
return `${row.distance.toFixed(1)} ${unit.value}`;
|
|
},
|
|
},
|
|
];
|
|
|
|
paceVariants.value.forEach((variant) => {
|
|
result.push({
|
|
title:
|
|
variant.title === t('tools.running-planner.texts.target-0')
|
|
? paceToLabel(variant.seconds)
|
|
: `${variant.title} (${paceToLabel(variant.seconds)})`,
|
|
key: variant.key,
|
|
});
|
|
});
|
|
|
|
return result;
|
|
});
|
|
</script>
|