Compare commits

...

3 Commits

Author SHA1 Message Date
806f91e325 fix(AddFile): 修复添加文件信息不自动隐藏问题 2025-07-02 13:19:02 +08:00
0208de66bb refactor(sqlite3): 重构SQLite数据处理逻辑
- 删除旧版SQLite.js文件
- 更新主进程文件中的数据库交互逻辑
- 优化数据库的连接方式
2025-07-02 13:18:05 +08:00
2582645ffa chore(build): 更新应用配置和图标资源
- 更新 .gitignore 文件配置
- 修改 electron-builder.js 构建配置
- 添加应用图标资源文件
2025-07-02 13:17:17 +08:00
11 changed files with 42 additions and 186 deletions

3
.gitignore vendored
View File

@ -6,4 +6,5 @@ release/
node_modules/ node_modules/
dist/ dist/
build/ build/
*.lock *.lock
.DS_Store

View File

@ -11,7 +11,7 @@ export default {
{ target: 'zip', arch: ['arm64', 'x64'] }, { target: 'zip', arch: ['arm64', 'x64'] },
{ target: 'dmg', arch: ['arm64', 'x64'] }, { target: 'dmg', arch: ['arm64', 'x64'] },
], ],
icon: 'src/assets/icons/icon.icns', icon: 'public/icons/mac.icns',
artifactName: 'findyourfile-${version}-mac-${arch}.${ext}', artifactName: 'findyourfile-${version}-mac-${arch}.${ext}',
category: 'public.app-category.productivity', category: 'public.app-category.productivity',
hardenedRuntime: false, hardenedRuntime: false,
@ -22,7 +22,7 @@ export default {
{ target: 'zip', arch: ['x64'] }, { target: 'zip', arch: ['x64'] },
{ target: 'nsis', arch: ['x64'] }, { target: 'nsis', arch: ['x64'] },
], ],
icon: 'src/assets/icons/icon.ico', icon: 'public/icons/win.ico',
artifactName: 'findyourfile-${version}-win-x64.${ext}', artifactName: 'findyourfile-${version}-win-x64.${ext}',
}, },
nsis: { nsis: {

View File

@ -1,179 +0,0 @@
const sqlite3 = require('sqlite3').verbose()
const path = require('path')
const fs = require('fs')
const { app } = require('electron')
// 数据库路径
const dbPath = path.join(app.getPath('userData'), 'database.sqlite')
let db
// 初始化数据库
function initDatabase() {
const dbDir = path.dirname(dbPath)
if (!fs.existsSync(dbDir)) {
fs.mkdirSync(dbDir, { recursive: true })
}
db = new sqlite3.Database(dbPath)
// 创建表
db.serialize(() => {
db.run(`
CREATE TABLE IF NOT EXISTS files (
file_id INTEGER PRIMARY KEY AUTOINCREMENT,
file_name TEXT NOT NULL,
file_ext TEXT,
file_cat TEXT,
file_tags TEXT,
file_desc TEXT,
file_created_time DATETIME,
file_updated_time DATETIME,
file_path TEXT NOT NULL UNIQUE,
is_directory BOOLEAN DEFAULT 0,
added_time DATETIME DEFAULT CURRENT_TIMESTAMP
)
`)
})
console.log('Database initialized at:', dbPath)
return db
}
// 添加文件记录
function addFile(fileData) {
return new Promise((resolve, reject) => {
const stmt = db.prepare(`
INSERT INTO files (
file_name, file_ext, file_cat, file_tags, file_desc,
file_created_time, file_updated_time, file_path, is_directory
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
`)
stmt.run(
fileData.fileName,
fileData.fileExt,
fileData.fileCat,
JSON.stringify(fileData.fileTags || []),
fileData.fileDesc,
fileData.fileCreatedTime,
fileData.fileUpdatedTime,
fileData.filePath,
fileData.isDirectory ? 1 : 0,
function (err) {
if (err) {
reject(err)
} else {
resolve(this.lastID)
}
},
)
stmt.finalize()
})
}
// 搜索文件
function searchFiles(criteria) {
return new Promise((resolve, reject) => {
let query = `SELECT * FROM files WHERE 1=1`
const params = []
if (criteria.fileName) {
query += ` AND file_name LIKE ?`
params.push(`%${criteria.fileName}%`)
}
if (criteria.fileCat) {
query += ` AND file_cat = ?`
params.push(criteria.fileCat)
}
if (criteria.fileTags && criteria.fileTags.length > 0) {
const tagConditions = criteria.fileTags.map(() => `file_tags LIKE ?`).join(' OR ')
query += ` AND (${tagConditions})`
criteria.fileTags.forEach((tag) => {
params.push(`%${tag}%`)
})
}
if (criteria.startDate) {
query += ` AND added_time >= ?`
params.push(criteria.startDate)
}
if (criteria.endDate) {
query += ` AND added_time <= ?`
params.push(criteria.endDate)
}
db.all(query, params, (err, rows) => {
if (err) {
reject(err)
} else {
// 解析JSON格式的标签
const results = rows.map((row) => ({
...row,
fileTags: JSON.parse(row.file_tags || '[]'),
}))
resolve(results)
}
})
})
}
// 获取统计数据
function getStats() {
return new Promise((resolve, reject) => {
const stats = {}
// 获取文件总数
db.get('SELECT COUNT(*) as count FROM files WHERE is_directory = 0', (err, row) => {
if (err) {
reject(err)
return
}
stats.fileCount = row.count
// 获取文件夹总数
db.get('SELECT COUNT(*) as count FROM files WHERE is_directory = 1', (err, row) => {
if (err) {
reject(err)
return
}
stats.dirCount = row.count
// 获取文件类型分布
db.all(
'SELECT file_ext, COUNT(*) as count FROM files WHERE is_directory = 0 GROUP BY file_ext',
(err, rows) => {
if (err) {
reject(err)
return
}
stats.fileTypes = rows
// 获取最近添加的文件
db.all('SELECT * FROM files ORDER BY added_time DESC LIMIT 10', (err, rows) => {
if (err) {
reject(err)
} else {
stats.recentFiles = rows.map((row) => ({
...row,
fileTags: JSON.parse(row.file_tags || '[]'),
}))
resolve(stats)
}
})
},
)
})
})
})
}
module.exports = {
initDatabase,
addFile,
searchFiles,
getStats,
}

View File

@ -16,9 +16,15 @@ let mainWindow
let db let db
function createWindow() { function createWindow() {
// 设置应用图标路径
const iconPath = process.platform === 'darwin'
? path.join(__dirname, '../public/icons/mac.icns')
: path.join(__dirname, '../public/icons/win.ico')
mainWindow = new BrowserWindow({ mainWindow = new BrowserWindow({
width: 1200, width: 1200,
height: 800, height: 800,
icon: iconPath,
webPreferences: { webPreferences: {
preload: path.join(__dirname, 'preload.cjs'), preload: path.join(__dirname, 'preload.cjs'),
contextIsolation: true, contextIsolation: true,

View File

@ -26,7 +26,7 @@
"echarts": "^5.5.0", "echarts": "^5.5.0",
"element-plus": "^2.8.0", "element-plus": "^2.8.0",
"pinia": "^2.0.0", "pinia": "^2.0.0",
"sqlite3": "^5.1.0", "sqlite3": "^5.1.7",
"vue": "^3.4.0", "vue": "^3.4.0",
"vue-echarts": "^7.0.0", "vue-echarts": "^7.0.0",
"vue-router": "^4.0.0" "vue-router": "^4.0.0"

BIN
public/icons/favicon.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

BIN
public/icons/mac.icns Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

BIN
public/icons/win.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 264 KiB

View File

@ -3,6 +3,7 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" href="./icons/favicon.jpeg">
<title>文件位置查询</title> <title>文件位置查询</title>
</head> </head>
<body> <body>

View File

@ -14,7 +14,7 @@
<div class="drop-text"> <div class="drop-text">
<p>点击选择文件或拖放到此处</p> <p>点击选择文件或拖放到此处</p>
<el-button type="primary" size="small" @click.stop="selectFile">选择文件</el-button> <el-button type="primary" size="small" @click.stop="selectFile">选择文件</el-button>
<el-button size="small" @click.stop="selectDirectory">选择文件夹</el-button> <el-button type="success"size="small" @click.stop="selectDirectory">选择文件夹</el-button>
</div> </div>
</div> </div>
@ -31,7 +31,7 @@
</template> </template>
<script> <script>
import { ref } from 'vue' import { ref, watch } from 'vue'
import { Upload } from '@element-plus/icons-vue' import { Upload } from '@element-plus/icons-vue'
export default { export default {
@ -39,11 +39,28 @@ export default {
components: { components: {
Upload, Upload,
}, },
props: {
reset: {
type: Boolean,
default: false
}
},
emits: ['file-selected'], emits: ['file-selected'],
setup(props, { emit }) { setup(props, { emit }) {
const selectedFile = ref(null) const selectedFile = ref(null)
const isDragging = ref(false) const isDragging = ref(false)
//
watch(() => props.reset, (newVal) => {
if (newVal) {
resetFileSelector()
}
})
const resetFileSelector = () => {
selectedFile.value = null
}
const selectFile = async () => { const selectFile = async () => {
try { try {
const file = await window.electronAPI.selectFile() const file = await window.electronAPI.selectFile()
@ -104,6 +121,7 @@ export default {
selectFile, selectFile,
selectDirectory, selectDirectory,
handleDrop, handleDrop,
resetFileSelector
} }
}, },
} }

View File

@ -3,7 +3,7 @@
<h1>添加新文件</h1> <h1>添加新文件</h1>
<div class="file-selector-wrapper"> <div class="file-selector-wrapper">
<FileSelector @file-selected="handleFileSelected" /> <FileSelector @file-selected="handleFileSelected" :reset="resetSignal" />
</div> </div>
<el-form <el-form
@ -104,6 +104,7 @@ export default {
const fileFormRef = ref(null) const fileFormRef = ref(null)
const selectedFile = ref(null) const selectedFile = ref(null)
const isSubmitting = ref(false) const isSubmitting = ref(false)
const resetSignal = ref(false)
// //
const categories = ref([]) const categories = ref([])
@ -222,6 +223,13 @@ export default {
} }
const resetForm = () => { const resetForm = () => {
resetSignal.value = true //
// 便
setTimeout(() => {
resetSignal.value = false
}, 100)
selectedFile.value = null selectedFile.value = null
fileForm.filePath = '' fileForm.filePath = ''
fileForm.fileName = '' fileForm.fileName = ''
@ -252,6 +260,7 @@ export default {
availableTags, availableTags,
selectedTag, selectedTag,
isSubmitting, isSubmitting,
resetSignal,
handleFileSelected, handleFileSelected,
handleTagChange, handleTagChange,
removeTag, removeTag,