Skip to content

Commit c97f1b1

Browse files
committed
feat(toolbox): added base64 tool
1 parent ccf8b5c commit c97f1b1

9 files changed

Lines changed: 164 additions & 76 deletions

File tree

src/components.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export {}
99

1010
declare module '@vue/runtime-core' {
1111
export interface GlobalComponents {
12+
Base64Tool: typeof import('./components/tools/base64-tool/base64-tool.vue')['default']
1213
CompressConfigBox: typeof import('./components/compress-config-box/compress-config-box.vue')['default']
1314
CompressTool: typeof import('./components/tools/compress-tool/compress-tool.vue')['default']
1415
CopyImageLink: typeof import('./components/copy-image-link/copy-image-link.vue')['default']
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
$left-width = 260rem
2+
3+
.base64-tool-container {
4+
position relative
5+
display flex
6+
justify-content space-between
7+
box-sizing border-box
8+
width 100%
9+
height 100%
10+
11+
.base64-tool-left {
12+
position relative
13+
box-sizing border-box
14+
width $left-width
15+
height 100%
16+
padding 10rem
17+
overflow-y auto
18+
border-right 1px solid var(--border-color)
19+
20+
.el-image {
21+
width 100%
22+
}
23+
}
24+
25+
26+
.base64-tool-right {
27+
position relative
28+
box-sizing border-box
29+
width 'calc(100% - %s)' % $left-width
30+
height 100%
31+
padding 20rem
32+
33+
&.no-img {
34+
width 100%
35+
}
36+
37+
.user-operate {
38+
display flex
39+
justify-content flex-end
40+
margin-top 20rem
41+
}
42+
}
43+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<template>
2+
<div class="base64-tool-container">
3+
<div v-if="imgList.length" class="base64-tool-left">
4+
<img-process-state-card
5+
card-type="base64"
6+
v-for="img in imgList"
7+
:img-obj="img"
8+
:key="img.uuid"
9+
@remove="remove"
10+
/>
11+
</div>
12+
<div class="base64-tool-right" :class="{ 'no-img': !imgList.length }">
13+
<getting-images ref="gettingImagesRef" @getImgList="getImgList"></getting-images>
14+
15+
<div class="user-operate">
16+
<el-button v-if="imgList.length" plain type="warning" @click="reset"> 重置 </el-button>
17+
</div>
18+
</div>
19+
</div>
20+
</template>
21+
22+
<script setup lang="ts">
23+
import { ref, watch } from 'vue'
24+
import { ImageHandleResult, ImgProcessStateModel } from '@/common/model'
25+
import { useStore } from '@/store'
26+
27+
const store = useStore()
28+
29+
const gettingImagesRef = ref<any>(null)
30+
31+
const imgList = ref<ImgProcessStateModel[]>([])
32+
33+
const getImgList = (imgs: ImageHandleResult[]) => {
34+
imgs.forEach((x) => {
35+
store.dispatch('TOOLBOX_IMG_LIST_ADD', {
36+
uuid: x.uuid,
37+
originalName: x.file.name,
38+
originalSize: x.file.size,
39+
originalBase64: x.base64
40+
})
41+
})
42+
}
43+
44+
// 重置
45+
const reset = () => {
46+
store.dispatch('TOOLBOX_IMG_LIST_RESET')
47+
gettingImagesRef.value?.reset()
48+
}
49+
50+
// 删除
51+
const remove = (uuid: string) => {
52+
store.dispatch('TOOLBOX_IMG_LIST_REMOVE', uuid)
53+
gettingImagesRef.value?.remove(uuid)
54+
}
55+
56+
watch(
57+
() => store.state.toolboxImageListModule.toolboxImageList,
58+
(newValue) => {
59+
imgList.value = newValue
60+
},
61+
{
62+
immediate: true,
63+
deep: true
64+
}
65+
)
66+
</script>
67+
68+
<style scoped lang="stylus">
69+
@import "base64-tool.styl"
70+
</style>

src/components/tools/img-process-state-card/img-process-state-card.vue

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@
2626
>
2727
点击下载
2828
</div>
29+
<div
30+
class="operate-container flex-center"
31+
v-if="cardType === 'base64' && imgObj.originalBase64"
32+
@click="copyBase64(imgObj.originalBase64)"
33+
>
34+
点击复制 Base64 编码
35+
</div>
2936
<el-tooltip placement="top" :offset="8" content="删除">
3037
<el-icon class="del-btn" @click="remove(imgObj.uuid)"><Remove /></el-icon>
3138
</el-tooltip>
@@ -34,7 +41,7 @@
3441

3542
<script setup lang="ts">
3643
import { ImgProcessStateModel } from '@/common/model'
37-
import { downloadImage, getFileSize } from '@/utils'
44+
import { copyText, downloadImage, getFileSize } from '@/utils'
3845
3946
const emit = defineEmits(['remove'])
4047
@@ -43,15 +50,27 @@ defineProps({
4350
type: Object as () => ImgProcessStateModel,
4451
require: true,
4552
default: () => ({})
53+
},
54+
cardType: {
55+
type: String,
56+
default: 'compress' // compress | base64
4657
}
4758
})
4859
60+
const remove = (uuid: string) => {
61+
emit('remove', uuid)
62+
}
63+
64+
// 下载图片到本地
4965
const download = (file: File) => {
5066
downloadImage(file)
5167
}
5268
53-
const remove = (uuid: string) => {
54-
emit('remove', uuid)
69+
// 复制 Base64 编码
70+
const copyBase64 = (base64: string) => {
71+
copyText(base64, () => {
72+
ElMessage.success({ message: ' Base64 编码复制成功' })
73+
})
5574
}
5675
</script>
5776

src/plugins/vite/src/auto-imports.d.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/plugins/vite/src/components.d.ts

Lines changed: 0 additions & 61 deletions
This file was deleted.

src/router/index.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import settings from '@/views/my-settings/my-settings.vue'
66
import toolbox from '@/views/picx-toolbox/picx-toolbox.vue'
77
import feedback from '@/views/feedback-info/feedback-info.vue'
88
import compressTool from '@/components/tools/compress-tool/compress-tool.vue'
9+
import base64Tool from '@/components/tools/base64-tool/base64-tool.vue'
910

1011
const titleSuffix = ` | PicX 图床`
1112

@@ -51,16 +52,21 @@ const routes: Array<RouteRecordRaw> = [
5152
},
5253
{
5354
path: '/toolbox',
54-
name: 'toolbox',
55+
name: 'Toolbox',
5556
component: toolbox,
5657
meta: {
5758
title: `工具箱${titleSuffix}`
5859
},
5960
children: [
6061
{
6162
path: '/toolbox/compress',
62-
name: 'compress',
63+
name: 'Compress',
6364
component: compressTool
65+
},
66+
{
67+
path: '/toolbox/base64',
68+
name: 'Base64',
69+
component: base64Tool
6470
}
6571
]
6672
},

src/styles/base.styl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,24 @@ li {
8181

8282

8383
.page-container {
84+
position relative
8485
box-sizing border-box
8586
width 100%
8687
height 100%
8788
padding 30rem
8889
overflow-y auto
8990
background var(--background-color)
9091
border-top-left-radius $box-border-radius
92+
93+
.page-content {
94+
position relative
95+
left 50%
96+
box-sizing border-box
97+
width 100%
98+
max-width 1200rem
99+
height 100%
100+
transform translateX(-50%)
101+
}
91102
}
92103

93104

src/views/picx-toolbox/picx-toolbox.vue

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { onMounted, ref, watch } from 'vue'
3232
import { useRouter } from 'vue-router'
3333
import { getUuid } from '@/utils'
3434
import { ToolItemModel } from '@/common/model'
35+
import { store } from '@/store'
3536
3637
const router = useRouter()
3738
@@ -53,12 +54,20 @@ const toolList = ref<ToolItemModel[]>([
5354
icon: 'MagicStick',
5455
uuid: getUuid(),
5556
path: '/compress'
57+
},
58+
{
59+
name: '图片转 Base64',
60+
desc: '不限制图片大小和数量,在线转换成 Base64 编码',
61+
icon: 'Paperclip',
62+
uuid: getUuid(),
63+
path: '/base64'
5664
}
5765
])
5866
5967
const selectTool = (tool: ToolItemModel) => {
6068
showToolPanel.value = true
6169
currentTool.value = { ...tool }
70+
store.dispatch('TOOLBOX_IMG_LIST_RESET')
6271
router.push(`${toolboxPath.value}${tool.path}`)
6372
}
6473

0 commit comments

Comments
 (0)