2023-05-28 23:13:24 +02:00
|
|
|
<script setup lang="ts">
|
|
|
|
import InputCopyable from '../../components/InputCopyable.vue';
|
|
|
|
import { convertBase } from './integer-base-converter.model';
|
|
|
|
import { useStyleStore } from '@/stores/style.store';
|
|
|
|
import { getErrorMessageIfThrows } from '@/utils/error';
|
|
|
|
|
|
|
|
const styleStore = useStyleStore();
|
|
|
|
|
|
|
|
const inputProps = {
|
|
|
|
'labelPosition': 'left',
|
|
|
|
'labelWidth': '170px',
|
|
|
|
'labelAlign': 'right',
|
|
|
|
'readonly': true,
|
|
|
|
'mb-2': '',
|
|
|
|
} as const;
|
|
|
|
|
|
|
|
const input = ref('42');
|
|
|
|
const inputBase = ref(10);
|
|
|
|
const outputBase = ref(42);
|
|
|
|
|
|
|
|
function errorlessConvert(...args: Parameters<typeof convertBase>) {
|
|
|
|
try {
|
|
|
|
return convertBase(...args);
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const error = computed(() =>
|
|
|
|
getErrorMessageIfThrows(() =>
|
|
|
|
convertBase({ value: input.value, fromBase: inputBase.value, toBase: outputBase.value }),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
</script>
|
|
|
|
|
2022-04-12 14:27:52 +02:00
|
|
|
<template>
|
2022-04-15 23:10:47 +02:00
|
|
|
<div>
|
2023-04-20 20:49:28 +02:00
|
|
|
<c-card>
|
2022-04-24 23:22:52 +02:00
|
|
|
<div v-if="styleStore.isSmallScreen">
|
|
|
|
<n-input-group>
|
2023-05-28 23:13:24 +02:00
|
|
|
<n-input-group-label style="flex: 0 0 120px">
|
|
|
|
Input number:
|
|
|
|
</n-input-group-label>
|
2023-04-06 19:36:30 +02:00
|
|
|
<n-input v-model:value="input" w-full :status="error ? 'error' : undefined" />
|
2022-04-24 23:22:52 +02:00
|
|
|
</n-input-group>
|
|
|
|
<n-input-group>
|
2023-05-28 23:13:24 +02:00
|
|
|
<n-input-group-label style="flex: 0 0 120px">
|
|
|
|
Input base:
|
|
|
|
</n-input-group-label>
|
2023-04-06 19:36:30 +02:00
|
|
|
<n-input-number v-model:value="inputBase" max="64" min="2" w-full />
|
2022-04-24 23:22:52 +02:00
|
|
|
</n-input-group>
|
|
|
|
</div>
|
2022-04-12 14:27:52 +02:00
|
|
|
|
2022-04-24 23:22:52 +02:00
|
|
|
<n-input-group v-else>
|
2023-05-28 23:13:24 +02:00
|
|
|
<n-input-group-label style="flex: 0 0 120px">
|
|
|
|
Input number:
|
|
|
|
</n-input-group-label>
|
2022-12-07 21:52:24 +01:00
|
|
|
<n-input v-model:value="input" :status="error ? 'error' : undefined" />
|
2023-05-28 23:13:24 +02:00
|
|
|
<n-input-group-label style="flex: 0 0 120px">
|
|
|
|
Input base:
|
|
|
|
</n-input-group-label>
|
2022-04-24 23:22:52 +02:00
|
|
|
<n-input-number v-model:value="inputBase" max="64" min="2" />
|
2022-04-15 23:10:47 +02:00
|
|
|
</n-input-group>
|
2022-12-07 21:52:24 +01:00
|
|
|
|
2023-05-28 23:13:24 +02:00
|
|
|
<n-alert v-if="error" style="margin-top: 25px" type="error">
|
|
|
|
{{ error }}
|
|
|
|
</n-alert>
|
2022-04-15 23:10:47 +02:00
|
|
|
<n-divider />
|
2022-04-12 14:27:52 +02:00
|
|
|
|
2023-05-28 23:13:24 +02:00
|
|
|
<InputCopyable
|
2023-05-14 21:26:18 +02:00
|
|
|
label="Binary (2)"
|
|
|
|
v-bind="inputProps"
|
|
|
|
:value="errorlessConvert({ value: input, fromBase: inputBase, toBase: 2 })"
|
|
|
|
placeholder="Binary version will be here..."
|
|
|
|
/>
|
2022-04-12 14:27:52 +02:00
|
|
|
|
2023-05-28 23:13:24 +02:00
|
|
|
<InputCopyable
|
2023-05-14 21:26:18 +02:00
|
|
|
label="Octal (8)"
|
|
|
|
v-bind="inputProps"
|
|
|
|
:value="errorlessConvert({ value: input, fromBase: inputBase, toBase: 8 })"
|
|
|
|
placeholder="Octal version will be here..."
|
|
|
|
/>
|
2022-04-12 14:27:52 +02:00
|
|
|
|
2023-05-28 23:13:24 +02:00
|
|
|
<InputCopyable
|
2023-05-14 21:26:18 +02:00
|
|
|
label="Decimal (10)"
|
|
|
|
v-bind="inputProps"
|
|
|
|
:value="errorlessConvert({ value: input, fromBase: inputBase, toBase: 10 })"
|
|
|
|
placeholder="Decimal version will be here..."
|
|
|
|
/>
|
2022-04-12 14:27:52 +02:00
|
|
|
|
2023-05-28 23:13:24 +02:00
|
|
|
<InputCopyable
|
2023-05-14 21:26:18 +02:00
|
|
|
label="Hexadecimal (16)"
|
|
|
|
v-bind="inputProps"
|
|
|
|
:value="errorlessConvert({ value: input, fromBase: inputBase, toBase: 16 })"
|
|
|
|
placeholder="Hexadecimal version will be here..."
|
|
|
|
/>
|
|
|
|
|
2023-05-28 23:13:24 +02:00
|
|
|
<InputCopyable
|
2023-05-14 21:26:18 +02:00
|
|
|
label="Base64 (64)"
|
|
|
|
v-bind="inputProps"
|
|
|
|
:value="errorlessConvert({ value: input, fromBase: inputBase, toBase: 64 })"
|
|
|
|
placeholder="Base64 version will be here..."
|
|
|
|
/>
|
|
|
|
|
|
|
|
<div flex items-baseline>
|
|
|
|
<n-input-group style="width: 160px; margin-right: 10px">
|
|
|
|
<n-input-group-label> Custom: </n-input-group-label>
|
|
|
|
<n-input-number v-model:value="outputBase" max="64" min="2" />
|
|
|
|
</n-input-group>
|
2022-04-12 14:27:52 +02:00
|
|
|
|
2023-05-28 23:13:24 +02:00
|
|
|
<InputCopyable
|
2023-05-14 21:26:18 +02:00
|
|
|
flex-1
|
|
|
|
v-bind="inputProps"
|
2022-12-07 21:52:24 +01:00
|
|
|
:value="errorlessConvert({ value: input, fromBase: inputBase, toBase: outputBase })"
|
|
|
|
:placeholder="`Base ${outputBase} will be here...`"
|
2022-04-15 23:10:47 +02:00
|
|
|
/>
|
2023-05-14 21:26:18 +02:00
|
|
|
</div>
|
2023-04-20 20:49:28 +02:00
|
|
|
</c-card>
|
2022-04-15 23:10:47 +02:00
|
|
|
</div>
|
2022-04-12 14:27:52 +02:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<style lang="less" scoped>
|
|
|
|
.n-input-group:not(:first-child) {
|
2022-04-22 23:31:40 +02:00
|
|
|
margin-top: 5px;
|
2022-04-12 14:27:52 +02:00
|
|
|
}
|
2022-04-22 23:31:40 +02:00
|
|
|
</style>
|