it-tools/src/tools/base64-converter/base64-converter.vue

62 lines
1.9 KiB
Vue
Raw Normal View History

2022-04-14 02:30:25 +02:00
<template>
<n-card title="Text to base64">
2022-04-22 23:31:40 +02:00
<n-input v-model:value="textInput" type="textarea" placeholder="Put your string here..." />
<n-input :value="textBase64" type="textarea" readonly />
2022-04-14 02:30:25 +02:00
<n-space justify="center">
2022-04-22 23:31:40 +02:00
<n-button secondary @click="copyTextBase64()"> Copy </n-button>
2022-04-14 02:30:25 +02:00
</n-space>
</n-card>
<n-card title="File to base64">
2022-04-22 23:31:40 +02:00
<n-upload v-model:file-list="fileList" :show-file-list="true" :on-before-upload="onUpload" list-type="image">
2022-04-14 02:30:25 +02:00
<n-upload-dragger>
<div style="margin-bottom: 12px">
2022-04-22 23:31:40 +02:00
<n-icon size="35" :depth="3" :component="Upload" />
2022-04-14 02:30:25 +02:00
</div>
2022-04-22 23:31:40 +02:00
<n-text style="font-size: 14px"> Click or drag a file to this area to upload </n-text>
2022-04-14 02:30:25 +02:00
</n-upload-dragger>
</n-upload>
2022-04-22 23:31:40 +02:00
<n-input :value="fileBase64" type="textarea" readonly />
2022-04-14 02:30:25 +02:00
<n-space justify="center">
2022-04-22 23:31:40 +02:00
<n-button secondary @click="copyFileBase64()"> Copy </n-button>
2022-04-14 02:30:25 +02:00
</n-space>
</n-card>
</template>
<script setup lang="ts">
2022-04-22 23:31:40 +02:00
import { useCopy } from '@/composable/copy';
import { useBase64 } from '@vueuse/core';
import { Upload } from '@vicons/tabler';
import { ref, type Ref } from 'vue';
2022-04-14 02:30:25 +02:00
import type { UploadFileInfo } from 'naive-ui';
2022-04-22 23:31:40 +02:00
const textInput = ref('');
const { base64: textBase64 } = useBase64(textInput);
const { copy: copyTextBase64 } = useCopy({ source: textBase64, text: 'Base64 string copied to the clipboard' });
2022-04-14 02:30:25 +02:00
2022-04-22 23:31:40 +02:00
const fileList = ref();
const fileInput = ref() as Ref<File>;
const { base64: fileBase64 } = useBase64(fileInput);
const { copy: copyFileBase64 } = useCopy({ source: fileBase64, text: 'Base64 string copied to the clipboard' });
2022-04-14 02:30:25 +02:00
2022-04-22 23:31:40 +02:00
function onUpload({ file: { file } }: { file: UploadFileInfo }) {
2022-04-14 02:30:25 +02:00
if (file) {
2022-04-22 23:31:40 +02:00
fileList.value = [];
fileInput.value = file;
2022-04-14 02:30:25 +02:00
}
}
</script>
<style lang="less" scoped>
.n-input,
.n-upload,
.n-card {
margin-bottom: 15px;
}
::v-deep(.n-upload-trigger) {
width: 100%;
}
2022-04-22 23:31:40 +02:00
</style>