mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-05-04 05:19:12 -04:00
Merge 3e95060622
into 87984e2081
This commit is contained in:
commit
9991fc4fdd
2 changed files with 20 additions and 2 deletions
|
@ -19,6 +19,7 @@
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/CorentinTh/it-tools"
|
"url": "https://github.com/CorentinTh/it-tools"
|
||||||
},
|
},
|
||||||
|
"packageManager": "pnpm@9.3.0",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"build": "vue-tsc --noEmit && NODE_OPTIONS=--max_old_space_size=4096 vite build",
|
"build": "vue-tsc --noEmit && NODE_OPTIONS=--max_old_space_size=4096 vite build",
|
||||||
|
|
|
@ -22,7 +22,7 @@ type TemperatureScale = 'kelvin' | 'celsius' | 'fahrenheit' | 'rankine' | 'delis
|
||||||
const units = reactive<
|
const units = reactive<
|
||||||
Record<
|
Record<
|
||||||
string | TemperatureScale,
|
string | TemperatureScale,
|
||||||
{ title: string; unit: string; ref: number; toKelvin: (v: number) => number; fromKelvin: (v: number) => number }
|
{ title: string; unit: string; ref: number; toKelvin: (v: number) => number; fromKelvin: (v: number) => number; min?: number; max?: number; maxLimit?: boolean }
|
||||||
>
|
>
|
||||||
>({
|
>({
|
||||||
kelvin: {
|
kelvin: {
|
||||||
|
@ -59,6 +59,7 @@ const units = reactive<
|
||||||
ref: 0,
|
ref: 0,
|
||||||
toKelvin: convertDelisleToKelvin,
|
toKelvin: convertDelisleToKelvin,
|
||||||
fromKelvin: convertKelvinToDelisle,
|
fromKelvin: convertKelvinToDelisle,
|
||||||
|
maxLimit: true,
|
||||||
},
|
},
|
||||||
newton: {
|
newton: {
|
||||||
title: 'Newton',
|
title: 'Newton',
|
||||||
|
@ -86,7 +87,9 @@ const units = reactive<
|
||||||
function update(key: TemperatureScale) {
|
function update(key: TemperatureScale) {
|
||||||
const { ref: value, toKelvin } = units[key];
|
const { ref: value, toKelvin } = units[key];
|
||||||
|
|
||||||
const kelvins = toKelvin(value) ?? 0;
|
let kelvins = toKelvin(value) ?? 0;
|
||||||
|
|
||||||
|
kelvins = kelvins < 0 ? 0 : kelvins;
|
||||||
|
|
||||||
_.chain(units)
|
_.chain(units)
|
||||||
.omit(key)
|
.omit(key)
|
||||||
|
@ -96,6 +99,18 @@ function update(key: TemperatureScale) {
|
||||||
.value();
|
.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setupLimit() {
|
||||||
|
_.forEach(units, (unit) => {
|
||||||
|
if (unit.maxLimit) {
|
||||||
|
unit.max = Math.ceil(unit.fromKelvin(0) * 100) / 100;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
unit.min = Math.floor(unit.fromKelvin(0) * 100) / 100;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
setupLimit();
|
||||||
update('kelvin');
|
update('kelvin');
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -109,6 +124,8 @@ update('kelvin');
|
||||||
<n-input-number
|
<n-input-number
|
||||||
v-model:value="units[key].ref"
|
v-model:value="units[key].ref"
|
||||||
style="flex: 1"
|
style="flex: 1"
|
||||||
|
:min="units[key].min"
|
||||||
|
:max="units[key].max"
|
||||||
@update:value="() => update(key as TemperatureScale)"
|
@update:value="() => update(key as TemperatureScale)"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue