|
|
@@ -0,0 +1,197 @@
|
|
|
+<template>
|
|
|
+ <SplitterCollapse>
|
|
|
+ <SplitterCollapseItem title="图片">
|
|
|
+ <template #header-right>
|
|
|
+ <el-tooltip content="添加">
|
|
|
+ <span class="mr-12px" @click.capture.stop="handleAddImage"><LuPlus size="14px" /></span>
|
|
|
+ </el-tooltip>
|
|
|
+ </template>
|
|
|
+ <div class="w-full h-full flex flex-col">
|
|
|
+ <div class="p-12px flex gap-8px shrink-0">
|
|
|
+ <el-input v-model="imageSearch" size="small" placeholder="输入搜索..." />
|
|
|
+ </div>
|
|
|
+ <el-scrollbar class="flex-1">
|
|
|
+ <ResourceItem
|
|
|
+ v-for="item in getImages || []"
|
|
|
+ :key="item.id"
|
|
|
+ :data="item"
|
|
|
+ type="image"
|
|
|
+ @delete="deleteResource(item, 'images')"
|
|
|
+ />
|
|
|
+ <div v-if="!getImages?.length" class="text-center">暂无图片~</div>
|
|
|
+ </el-scrollbar>
|
|
|
+ </div>
|
|
|
+ </SplitterCollapseItem>
|
|
|
+ <SplitterCollapseItem title="字体">
|
|
|
+ <template #header-right>
|
|
|
+ <el-tooltip content="添加">
|
|
|
+ <span class="mr-12px" @click.capture.stop="handleAddFont"><LuPlus size="14px" /></span>
|
|
|
+ </el-tooltip>
|
|
|
+ </template>
|
|
|
+ <div class="w-full h-full flex flex-col">
|
|
|
+ <div class="p-12px flex gap-8px shrink-0">
|
|
|
+ <el-input v-model="fontSearch" size="small" placeholder="输入搜索..." />
|
|
|
+ </div>
|
|
|
+ <el-scrollbar class="flex-1">
|
|
|
+ <ResourceItem
|
|
|
+ v-for="item in getFonts || []"
|
|
|
+ :key="item.id"
|
|
|
+ :data="item"
|
|
|
+ type="font"
|
|
|
+ @delete="deleteResource(item, 'fonts')"
|
|
|
+ />
|
|
|
+ <div v-if="!getFonts?.length" class="text-center">暂无字体~</div>
|
|
|
+ </el-scrollbar>
|
|
|
+ </div>
|
|
|
+ </SplitterCollapseItem>
|
|
|
+ <SplitterCollapseItem title="其他数据">
|
|
|
+ <template #header-right>
|
|
|
+ <el-tooltip content="添加">
|
|
|
+ <span class="mr-12px" @click.capture.stop="handleAddOther"><LuPlus size="14px" /></span>
|
|
|
+ </el-tooltip>
|
|
|
+ </template>
|
|
|
+ <div class="w-full h-full flex flex-col">
|
|
|
+ <div class="p-12px flex gap-8px shrink-0">
|
|
|
+ <el-input v-model="otherSearch" size="small" placeholder="输入搜索..." />
|
|
|
+ </div>
|
|
|
+ <el-scrollbar class="flex-1">
|
|
|
+ <ResourceItem
|
|
|
+ v-for="item in getOthers || []"
|
|
|
+ :key="item.id"
|
|
|
+ :data="item"
|
|
|
+ type="other"
|
|
|
+ @delete="deleteResource(item, 'others')"
|
|
|
+ />
|
|
|
+ <div v-if="!getOthers?.length" class="text-center">暂无资源~</div>
|
|
|
+ </el-scrollbar>
|
|
|
+ </div>
|
|
|
+ </SplitterCollapseItem>
|
|
|
+ </SplitterCollapse>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script setup lang="ts">
|
|
|
+import type { FontResource, ImageResource, OtherResource, Resource } from '@/types/resource'
|
|
|
+
|
|
|
+import { ref, computed } from 'vue'
|
|
|
+import { SplitterCollapse, SplitterCollapseItem } from '@/components/SplitterCollapse'
|
|
|
+import { LuPlus } from 'vue-icons-plus/lu'
|
|
|
+import { useProjectStore } from '@/store/modules/project'
|
|
|
+import { createFileResource } from '@/model'
|
|
|
+import ResourceItem from './components/ResourceItem.vue'
|
|
|
+
|
|
|
+const projectStore = useProjectStore()
|
|
|
+const imageSearch = ref('')
|
|
|
+const fontSearch = ref('')
|
|
|
+const otherSearch = ref('')
|
|
|
+
|
|
|
+const getImages = computed(() => {
|
|
|
+ return projectStore.project?.resources.images.filter((item) =>
|
|
|
+ item.fileName.includes(imageSearch.value)
|
|
|
+ )
|
|
|
+})
|
|
|
+
|
|
|
+const getFonts = computed(() => {
|
|
|
+ return projectStore.project?.resources.fonts.filter((item) =>
|
|
|
+ item.fileName.includes(fontSearch.value)
|
|
|
+ )
|
|
|
+})
|
|
|
+
|
|
|
+const getOthers = computed(() => {
|
|
|
+ return projectStore.project?.resources.others.filter((item) =>
|
|
|
+ item.fileName.includes(otherSearch.value)
|
|
|
+ )
|
|
|
+})
|
|
|
+
|
|
|
+// 添加图片
|
|
|
+const handleAddImage = async () => {
|
|
|
+ const paths = await window.electron.ipcRenderer.invoke('get-file', {
|
|
|
+ title: '选择文件',
|
|
|
+ buttonLabel: '添加',
|
|
|
+ properties: ['openFile', 'multiSelections'],
|
|
|
+ filters: [
|
|
|
+ {
|
|
|
+ name: 'Images',
|
|
|
+ extensions: ['png', 'jpg', 'jpeg', 'gif']
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ })
|
|
|
+
|
|
|
+ paths.forEach(async (path) => {
|
|
|
+ const fileName = path.split('\\').pop()
|
|
|
+ // 复制文件
|
|
|
+ await window.electron.ipcRenderer.invoke(
|
|
|
+ 'copy-file',
|
|
|
+ path,
|
|
|
+ `${projectStore.projectPath}\\src\\assets\\images\\${fileName}`
|
|
|
+ )
|
|
|
+ // 记录文件
|
|
|
+ projectStore.project?.resources.images.push(
|
|
|
+ createFileResource(`\\src\\assets\\images\\${fileName}`, 'image') as ImageResource
|
|
|
+ )
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+// 添加字体
|
|
|
+const handleAddFont = async () => {
|
|
|
+ const paths = await window.electron.ipcRenderer.invoke('get-file', {
|
|
|
+ title: '选择文件',
|
|
|
+ buttonLabel: '添加',
|
|
|
+ properties: ['openFile', 'multiSelections'],
|
|
|
+ filters: [
|
|
|
+ {
|
|
|
+ name: 'Fonts',
|
|
|
+ extensions: ['ttf', 'woff', 'otf']
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ })
|
|
|
+
|
|
|
+ paths.forEach(async (path) => {
|
|
|
+ const fileName = path.split('\\').pop()
|
|
|
+ // 复制文件
|
|
|
+ await window.electron.ipcRenderer.invoke(
|
|
|
+ 'copy-file',
|
|
|
+ path,
|
|
|
+ `${projectStore.projectPath}\\src\\assets\\fonts\\${fileName}`
|
|
|
+ )
|
|
|
+ // 记录文件
|
|
|
+ projectStore.project?.resources.fonts.push(
|
|
|
+ createFileResource(`\\src\\assets\\fonts\\${fileName}`, 'font') as FontResource
|
|
|
+ )
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+// 添加其他资源
|
|
|
+const handleAddOther = async () => {
|
|
|
+ const paths = await window.electron.ipcRenderer.invoke('get-file', {
|
|
|
+ title: '选择文件',
|
|
|
+ buttonLabel: '添加',
|
|
|
+ properties: ['openFile', 'multiSelections']
|
|
|
+ })
|
|
|
+
|
|
|
+ paths.forEach(async (path) => {
|
|
|
+ const fileName = path.split('\\').pop()
|
|
|
+ // 复制文件
|
|
|
+ await window.electron.ipcRenderer.invoke(
|
|
|
+ 'copy-file',
|
|
|
+ path,
|
|
|
+ `${projectStore.projectPath}\\src\\assets\\others\\${fileName}`
|
|
|
+ )
|
|
|
+ // 记录文件
|
|
|
+ projectStore.project?.resources.others.push(
|
|
|
+ createFileResource(`\\src\\assets\\images\\${fileName}`, 'other') as OtherResource
|
|
|
+ )
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+// 删除资源
|
|
|
+const deleteResource = async (resource: Resource, type: 'images' | 'fonts' | 'others') => {
|
|
|
+ await window.electron.ipcRenderer.invoke('delete-file', projectStore.projectPath + resource.path)
|
|
|
+ const index =
|
|
|
+ projectStore.project?.resources[type].findIndex((item) => item.id === resource.id) || -1
|
|
|
+ if (index > -1) {
|
|
|
+ projectStore.project?.resources[type].splice(index, 1)
|
|
|
+ }
|
|
|
+}
|
|
|
+</script>
|
|
|
+
|
|
|
+<style scoped></style>
|