it-tools/src/tools/uuid-generator/uuid-generator.vue

50 lines
1.2 KiB
Vue
Raw Normal View History

2022-04-04 21:46:35 +02:00
<template>
2022-04-15 23:10:47 +02:00
<div>
<n-card>
2022-04-22 23:31:40 +02:00
<n-space align="center" justify="center">
2022-04-15 23:10:47 +02:00
Quantity :
2022-04-22 23:31:40 +02:00
<n-input-number v-model:value="count" :min="1" :max="50" />
2022-04-15 23:10:47 +02:00
</n-space>
2022-04-22 23:31:40 +02:00
<br />
2022-04-15 23:10:47 +02:00
<n-input
2022-04-22 23:31:40 +02:00
style="text-align: center; font-family: monospace"
2022-04-15 23:10:47 +02:00
:value="uuids"
type="textarea"
placeholder="Your uuids"
:autosize="{ minRows: 1 }"
readonly
autocomplete="off"
autocorrect="off"
autocapitalize="off"
spellcheck="false"
/>
2022-04-22 23:31:40 +02:00
<br />
<br />
2022-04-15 23:10:47 +02:00
<n-space justify="center">
2022-04-22 23:31:40 +02:00
<n-button secondary autofocus @click="copy"> Copy </n-button>
<n-button secondary @click="refreshUUIDs"> Refresh </n-button>
2022-04-15 23:10:47 +02:00
</n-space>
</n-card>
</div>
2022-04-04 21:46:35 +02:00
</template>
<script setup lang="ts">
import { useCopy } from '@/composable/copy';
2022-04-22 23:31:40 +02:00
import { ref, watch } from 'vue';
2022-04-04 21:46:35 +02:00
import { v4 as generateUUID } from 'uuid';
2022-04-22 23:31:40 +02:00
const count = ref(1);
2022-04-04 21:46:35 +02:00
2022-04-22 23:31:40 +02:00
const uuids = ref('');
2022-04-04 21:46:35 +02:00
function refreshUUIDs() {
2022-04-22 23:31:40 +02:00
uuids.value = Array.from({ length: count.value }, () => generateUUID()).join('\n');
2022-04-04 21:46:35 +02:00
}
2022-04-22 23:31:40 +02:00
watch([count], refreshUUIDs);
2022-04-04 21:46:35 +02:00
2022-04-22 23:31:40 +02:00
const { copy } = useCopy({ source: uuids, text: 'UUIDs copied to the clipboard' });
2022-04-04 21:46:35 +02:00
2022-04-22 23:31:40 +02:00
refreshUUIDs();
2022-04-04 21:46:35 +02:00
</script>