Skip to content

Commit 21479e4

Browse files
author
igyfhc
committed
字节
1 parent 06d4618 commit 21479e4

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

.apps/tools/src/main.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const router = createRouter({
88
routes: [
99
{ path: '/', component: () => import('./views/Home.vue') },
1010
{ path: '/calc', component: () => import('./views/Calc.vue') },
11+
{ path: '/file-byte', component: () => import('./views/FileByte.vue') },
1112
],
1213
});
1314

.apps/tools/src/views/FileByte.vue

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<template>
2+
<input type="file" @change="handleFileChange"/>
3+
<pre>{{ b64 }}</pre>
4+
<button v-if="b64" @click="handleCopy(b64)">复制</button>
5+
<pre>{{ num }}</pre>
6+
<button v-if="num" @click="handleCopy(num)">复制</button>
7+
<pre>{{ hex }}</pre>
8+
<button v-if="hex" @click="handleCopy(hex)">复制</button>
9+
</template>
10+
11+
<script setup>
12+
import { ref } from 'vue';
13+
14+
const b64 = ref();
15+
const num = ref();
16+
const hex = ref();
17+
18+
const handleFileChange = (e) => {
19+
/** @type File */
20+
const file = e.target.files[0];
21+
file.arrayBuffer().then(buf => {
22+
const uin8 = Array.from(new Uint8Array(buf));
23+
b64.value = btoa(String.fromCharCode.apply(num, uin8));
24+
num.value = uin8.join(', ');
25+
hex.value = uin8.map(item => '0x' + item.toString(16)).join(', ');
26+
});
27+
};
28+
29+
const handleCopy = data => {
30+
navigator.clipboard.writeText(data).then(() => {
31+
alert('复制成功');
32+
});
33+
};
34+
</script>

.apps/tools/src/views/Home.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
<ol>
33
<li><a href="/">域根</a></li>
44
<li><RouterLink to="/calc">计算器</RouterLink></li>
5+
<li><RouterLink to="/file-byte">文件字节 File Byte</RouterLink></li>
56
</ol>
67
</template>

0 commit comments

Comments
 (0)