fix: 桌面导出改用 IPC 直写(另存为对话框),设置页显示版本号

This commit is contained in:
root
2026-10-16 13:07:38 +08:00
parent 599aa09ab8
commit f0d30e2c29
11 changed files with 66 additions and 33 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -1,2 +1,2 @@
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./web-wVXIQy1j.js","./index-UNHXXnki.js","./index-CwZ2l8Dk.css"])))=>i.map(i=>d[i]);
import{r as s,_ as i}from"./index-UNHXXnki.js";var t;(function(e){e.Documents="DOCUMENTS",e.Data="DATA",e.Library="LIBRARY",e.Cache="CACHE",e.External="EXTERNAL",e.ExternalStorage="EXTERNAL_STORAGE"})(t||(t={}));var a;(function(e){e.UTF8="utf8",e.ASCII="ascii",e.UTF16="utf16"})(a||(a={}));const E=s("Filesystem",{web:()=>i(()=>import("./web-wVXIQy1j.js"),__vite__mapDeps([0,1,2]),import.meta.url).then(e=>new e.FilesystemWeb)});export{t as Directory,a as Encoding,E as Filesystem};
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./web-CP24IQDG.js","./index-DS0rgMh0.js","./index-DXlhKHmS.css"])))=>i.map(i=>d[i]);
import{r as s,_ as i}from"./index-DS0rgMh0.js";var t;(function(e){e.Documents="DOCUMENTS",e.Data="DATA",e.Library="LIBRARY",e.Cache="CACHE",e.External="EXTERNAL",e.ExternalStorage="EXTERNAL_STORAGE"})(t||(t={}));var a;(function(e){e.UTF8="utf8",e.ASCII="ascii",e.UTF16="utf16"})(a||(a={}));const E=s("Filesystem",{web:()=>i(()=>import("./web-CP24IQDG.js"),__vite__mapDeps([0,1,2]),import.meta.url).then(e=>new e.FilesystemWeb)});export{t as Directory,a as Encoding,E as Filesystem};
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+2 -2
View File
@@ -8,8 +8,8 @@
<link rel="icon" href="./icons/icon.svg" type="image/svg+xml" />
<link rel="apple-touch-icon" href="./icons/icon-192.png" />
<title>实习工作日志</title>
<script type="module" crossorigin src="./assets/index-UNHXXnki.js"></script>
<link rel="stylesheet" crossorigin href="./assets/index-CwZ2l8Dk.css">
<script type="module" crossorigin src="./assets/index-DS0rgMh0.js"></script>
<link rel="stylesheet" crossorigin href="./assets/index-DXlhKHmS.css">
</head>
<body>
<div id="app"></div>
+15 -1
View File
@@ -1,5 +1,6 @@
const { app, BrowserWindow, Menu, shell, dialog } = require('electron')
const { app, BrowserWindow, Menu, shell, dialog, ipcMain } = require('electron')
const path = require('path')
const fs = require('fs')
const DEV_URL = process.env.VITE_DEV_SERVER_URL || ''
@@ -16,6 +17,7 @@ function createWindow() {
webPreferences: {
contextIsolation: true,
nodeIntegration: false,
preload: path.join(__dirname, 'preload.cjs'),
spellcheck: false
}
})
@@ -45,6 +47,18 @@ function createWindow() {
}
}
// 导出文件:渲染进程请求主进程保存(标准另存为对话框 + 直接写盘)
ipcMain.handle('export-file', async (event, payload) => {
const win = BrowserWindow.fromWebContents(event.sender)
const result = await dialog.showSaveDialog(win, {
title: '保存文件',
defaultPath: path.join(app.getPath('downloads'), payload.filename)
})
if (result.canceled || !result.filePath) return { saved: false, path: '' }
fs.writeFileSync(result.filePath, payload.content, 'utf-8')
return { saved: true, path: result.filePath }
})
app.whenReady().then(() => {
createWindow()
app.on('activate', () => {
+5
View File
@@ -0,0 +1,5 @@
const { contextBridge, ipcRenderer } = require('electron')
contextBridge.exposeInMainWorld('electronAPI', {
saveFile: (filename, content) => ipcRenderer.invoke('export-file', { filename, content })
})
+7
View File
@@ -3,6 +3,13 @@ import { Capacitor } from '@capacitor/core'
// 导出文本文件:返回落盘位置(原生平台返回文件 URI;浏览器返回空串)
// 原生环境写入公共文档目录,失败时回退应用缓存目录
export async function downloadText(filename: string, text: string): Promise<string> {
// 桌面版(Electron):经主进程直接写盘,弹标准另存为对话框
const w = window as unknown as { electronAPI?: { saveFile: (n: string, c: string) => Promise<{ saved: boolean; path: string }> } }
if (w.electronAPI && w.electronAPI.saveFile) {
const r = await w.electronAPI.saveFile(filename, text)
return r && r.saved ? r.path : ''
}
if (Capacitor.isNativePlatform()) {
const { Filesystem, Directory, Encoding } = await import('@capacitor/filesystem')
try {
+2 -1
View File
@@ -36,6 +36,7 @@ const newLoginPwd1 = ref('')
const newLoginPwd2 = ref('')
const accError = ref('')
const deleteAccConfirm = ref(false)
const appVersion = __APP_VERSION__
const syncBase = ref('')
const cloudUser = ref('')
const syncStatus = ref('')
@@ -251,7 +252,7 @@ async function doImport() {
<div class="settings">
<div class="card section">
<div class="section-title">账号与隐私</div>
<div class="muted acc-line">当前用户:{{ username }} · 每位用户独立数据库隔离存储于本机 · 登录密码仅保存 PBKDF2 哈希</div>
<div class="muted acc-line">版本 v{{ appVersion }} · 当前用户:{{ username }} · 每位用户独立数据库隔离存储于本机 · 登录密码仅保存 PBKDF2 哈希</div>
<div class="ai-grid">
<div class="rule-item">
<label>旧登录密码</label>
+7 -1
View File
@@ -1,7 +1,13 @@
import { readFileSync } from 'node:fs'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
const pkg = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf-8'))
export default defineConfig({
plugins: [vue()],
base: './'
base: './',
define: {
__APP_VERSION__: JSON.stringify(pkg.version)
}
})