File tree Expand file tree Collapse file tree 3 files changed +36
-0
lines changed Expand file tree Collapse file tree 3 files changed +36
-0
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 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 >
Original file line number Diff line number Diff line change 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 >
You can’t perform that action at this time.
0 commit comments