Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(frontend): 重构部分方法和命名,并新增文件拖拽 #525

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
deleteFile, deleteFolder,
getFileFromUser,
linkToFile,
newFileFromSidebar, newFolder, renameFileOrFolder,
newFileFromSidebar, newFolder, renameFileOrFolder, moveFileOrFolder,
saveFile,
saveToTarget,
saveToPDFTarget,
Expand Down Expand Up @@ -129,6 +129,9 @@ app.on('ready', async () => {
ipcMain.on('renameFileOrFolder', (e, newPath, oldPath) => {
renameFileOrFolder(newPath, oldPath)
})
ipcMain.on('move-file-or-folder', (e, srcPath, dstPath) => {
moveFileOrFolder(srcPath, dstPath)
})
ipcMain.on('newFileFromSidebar', (e, filePath, fileName) => {
newFileFromSidebar(filePath, fileName)
})
Expand Down
2 changes: 1 addition & 1 deletion src/main/filesystem/fileManipulate.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export const saveToPDFTarget = async (fileContent) => {
* @param {string} srcPath 原文件/文件夹路径
* @param {string} destDir 目标文件夹
*/
export const move = async (srcPath, destDir) => {
export const moveFileOrFolder = async (srcPath, destDir) => {
try {
const fname = path.basename(srcPath)
const targetPath = makeValidFilePath(path.resolve(destDir, fname))
Expand Down
6 changes: 3 additions & 3 deletions src/main/filesystem/linkManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import path from 'path'
import { addTagToDoc, getLinksInFile, removeTagFromDoc } from '../../common/parseLinks'
import fs from 'fs-extra'
import { isValidMarkdownFilePath } from '../helper/path'
import { deleteFolder, move } from '@/main/filesystem/fileManipulate'
import { deleteFolder, moveFileOrFolder } from '@/main/filesystem/fileManipulate'
class LinkManager {
/**
* 管理tag和cites
Expand Down Expand Up @@ -227,7 +227,7 @@ class LinkManager {
for (const filename of filepaths) {
const filepath = path.resolve(dirPath, filename)
this.removeFile(filepath)
const newPath = await move(filepath, targetPath)
const newPath = await moveFileOrFolder(filepath, targetPath)
this.addFile(newPath)
this.win.webContents.send('set-file-path-by-move', { oldPath: filepath, newPath })
const doc = (await fs.promises.readFile(newPath)).toString()
Expand All @@ -249,7 +249,7 @@ class LinkManager {
const subItemPath = path.resolve(folderPath, subItem)
if (isValidMarkdownFilePath(subItemPath)) {
this.removeFile(subItemPath)
const newPath = await move(subItemPath, targetPath)
const newPath = await moveFileOrFolder(subItemPath, targetPath)
this.addFile(newPath)
this.win.webContents.send('set-file-path-by-move', { subItemPath, newPath })
const doc = (await fs.promises.readFile(newPath)).toString()
Expand Down
3 changes: 3 additions & 0 deletions src/main/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ contextBridge.exposeInMainWorld('electronAPI', {
openFolder: () => ipcRenderer.send('open-folder'),
openFolderByPath: (path) => ipcRenderer.send('open-folder-by-path', path),

moveFileOrFolder: (srcPath, dstPath) => ipcRenderer.send('move-file-or-folder', srcPath, dstPath), // TODO

saveFile: (path, content) => ipcRenderer.send('save-file', path, content),
saveToAnotherFile: (content) => ipcRenderer.send('save-as', content),
exportPDF: (html) => ipcRenderer.invoke('exportPDF', html),
Expand Down Expand Up @@ -91,6 +93,7 @@ contextBridge.exposeInMainWorld('pathAPI', {
join: path.join,
relative: path.relative,
basename: path.basename,
dirname: path.dirname,
existSync: fs.pathExistsSync,
isMarkdownExtname,
sep: path.sep,
Expand Down
186 changes: 61 additions & 125 deletions src/renderer/App.vue

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/renderer/commands/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ const commands = [
if (mode === 0 || mode === 1) {
bus.emit('exportHTML')
} else {
bus.emit('showMyAlert', { message: '当前不在文本模式或源码模式,不能导出HTML' })
bus.emit('showAlertWith', { message: '当前不在文本模式或源码模式,不能导出HTML' })
}
}
},
Expand All @@ -159,7 +159,7 @@ const commands = [
if (mode === 0 || mode === 1) {
bus.emit('exportPDF')
} else {
bus.emit('showMyAlert', { message: '当前不在文本模式或源码模式,不能导出PDF' })
bus.emit('showAlertWith', { message: '当前不在文本模式或源码模式,不能导出PDF' })
}
}
},
Expand All @@ -173,7 +173,7 @@ const commands = [
} else if (mode === 3) {
bus.emit('exportGraphPNG')
} else {
bus.emit('showMyAlert', { message: '当前不在树视图或图视图,不能导出PNG' })
bus.emit('showAlertWith', { message: '当前不在树视图或图视图,不能导出PNG' })
}
}
},
Expand Down
14 changes: 7 additions & 7 deletions src/renderer/components/sideBar/FileNavItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@dragover.stop="dragover($event)"
@dragstart.stop="dragstart()"
@dragend.stop="dragend($event)"
draggable="false"
draggable="true"
class="my-1 w-full items-center content-center flex flex-wrap"
>
<div
Expand Down Expand Up @@ -80,8 +80,8 @@
<v-contextmenu-item class="hover:bg-gray-200 text-gray-700" @click="handleCopyFileOrFolder">复制</v-contextmenu-item>
<v-contextmenu-item class="hover:bg-gray-200 text-gray-700" @click="handleDelete" v-if="item.path !== topItem.path">删除</v-contextmenu-item>
<v-contextmenu-item class="hover:bg-gray-200 text-gray-700" @click="handleRename" v-if="item.path !== topItem.path">重命名</v-contextmenu-item>
<v-contextmenu-item class="hover:bg-gray-200 text-gray-700" v-if="item.type ==='file'" @click="handleCopyAbsolutePath">复制路径</v-contextmenu-item>
<!-- <v-contextmenu-item class="hover:bg-gray-200 text-gray-700" v-if="item.type==='file'" @click="handleCopyPartPath">复制相对路径</v-contextmenu-item>-->
<v-contextmenu-item class="hover:bg-gray-200 text-gray-700" v-if="item.type === 'file'" @click="handleCopyAbsolutePath">复制路径</v-contextmenu-item>
<v-contextmenu-item class="hover:bg-gray-200 text-gray-700" v-if="item.type === 'file'" @click="handleCopyPartPath">复制相对路径</v-contextmenu-item>
</v-contextmenu>
</div>
<ul v-if="(hasChildren && expanded)">
Expand Down Expand Up @@ -202,7 +202,7 @@ export default {

function dragstart () {
// 源对象
bus.emit('getSource', props.item)
bus.emit('setDragBeginPath', props.item)
}

function dragenter (e) {
Expand All @@ -212,12 +212,12 @@ export default {

function dragover (e) {
e.preventDefault()
bus.emit('getDst', props.item)
bus.emit('setDragEndPath', props.item)
}

function dragend (e) {
e.preventDefault()
bus.emit('toDst')
bus.emit('moveByDrag')
}

function handleRightClick (e) {
Expand All @@ -238,7 +238,7 @@ export default {
}

function handleCopyPartPath () {
bus.emit('CopyPartPath', props.item)
bus.emit('setClipboardRelativePath', props.item)
}

function handleCopyFileOrFolder () {
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/sideBar/ForestBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export default {
dataOption.value = option
if (option === 1) {
if (props.data.length === 0) {
bus.emit('showMyAlert', { message: '请先打开文件夹' })
bus.emit('showAlertWith', { message: '请先打开文件夹' })
} else {
files.value.length = 0
files.value = getDataByArray(props.data)
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/sideBar/GraphBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export default {
const showOpt = ref(true)

function handleProcess () {
bus.emit('showMyAlert', { message: '敬请期待!' })
bus.emit('showAlertWith', { message: '敬请期待!' })
}

function quitGraph () {
Expand Down
6 changes: 3 additions & 3 deletions src/renderer/components/sideBar/SideBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -317,15 +317,15 @@ export default {

function getSearch () {
if (props.data.length === 0) {
bus.emit('showMyAlert', { message: '必须要打开文件夹才能使用全局搜索' })
bus.emit('showAlertWith', { message: '必须要打开文件夹才能使用全局搜索' })
} else {
isFile.value = 1
}
}

function getGraph () {
if (props.data.length === 0) {
bus.emit('showMyAlert', { message: '必须要打开文件夹才能体验榕图模式' })
bus.emit('showAlertWith', { message: '必须要打开文件夹才能体验榕图模式' })
} else {
isFile.value = 6
bus.emit('changeToGraph')
Expand All @@ -334,7 +334,7 @@ export default {

function getForest () {
if (props.data.length === 0) {
bus.emit('showMyAlert', { message: '必须要打开文件夹才能体验榕林模式' })
bus.emit('showAlertWith', { message: '必须要打开文件夹才能体验榕林模式' })
} else {
isFile.value = 5
bus.emit('changeToForest')
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/textArea/TextArea.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export default {
// 图视图
bus.emit('exportGraphPNG')
} else {
bus.emit('showMyAlert', { message: '当前不在树视图或图试图,不能导出PNG' })
bus.emit('showAlertWith', { message: '当前不在树视图或图试图,不能导出PNG' })
}
})

Expand Down