Compare commits

..

No commits in common. "806f91e325113eac0549c9ae2052e8883d950be7" and "3648f46181d6d55471ae7897cfcb3f23b3e2d030" have entirely different histories.

11 changed files with 186 additions and 42 deletions

3
.gitignore vendored
View File

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

View File

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

179
electron/database/sqlite.js Normal file
View File

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

View File

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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 63 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 264 KiB

View File

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

View File

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

View File

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