4747 />
4848
4949 <!-- 通知组件 -->
50- <div v-if =" notifications.length > 0 || isCopying" class =" notification-container" >
51- <!-- 复制中 loading 通知 -->
52- <div v-if =" isCopying" class =" notification loading" >
53- <span class =" loading-spinner" ></span >
54- <span >正在处理内容...</span >
55- </div >
50+ <div v-if =" notifications.length > 0" class =" notification-container" >
5651 <div
5752 v-for =" notification in notifications"
5853 :key =" notification.id"
8075</template >
8176
8277<script setup>
83- import { ref } from ' vue'
84- import { useAppState , useElectron } from ' ./composables/index.js'
85- import { useGlobalThemeManager } from ' ./composables/index.js'
86- import { nextTick } from ' vue'
78+ import { ref , nextTick } from ' vue'
79+ import { useAppState , useElectron , useGlobalThemeManager } from ' ./composables/index.js'
8780import AppHeader from ' ./components/layout/AppHeader.vue'
8881import AppMain from ' ./components/layout/AppMain.vue'
8982import AppFooter from ' ./components/layout/AppFooter.vue'
@@ -102,7 +95,6 @@ const {
10295 notifications,
10396 selectedCopyFormat,
10497 copyFormatOptions,
105- isCopying,
10698
10799 // 计算属性
108100 hasContent,
@@ -138,79 +130,36 @@ const {
138130
139131// 设置菜单监听器
140132nextTick (() => {
141- console .log (' ⏰ 在下一个tick中设置菜单监听器...' );
142133 setupMenuListeners ({
143- onOpenFile : (event , { filePath, content }) => {
144- console .log (' 📁 渲染进程收到打开文件事件' );
145- console .log (' 📂 文件路径:' , filePath);
146-
147- // 更新编辑器内容
148- updateMarkdownContent (content);
149- console .log (' ✅ 编辑器内容已更新' );
150-
151- // 设置当前文件路径(通过 openFile 函数)
152- openFile (filePath, content);
153- console .log (' 📁 当前文件路径已设置' );
154-
155- const fileName = filePath .split (' /' ).pop () || filePath .split (' \\ ' ).pop ();
156- console .log (' 🔔 显示成功通知:' , fileName);
157- showNotification (` 已打开文件: ${ fileName} ` , ' success' );
158-
159- console .log (' 🎉 文件打开流程完成' );
134+ onOpenFile : (_event , { filePath, content }) => {
135+ updateMarkdownContent (content)
136+ openFile (filePath, content)
137+ const fileName = filePath .split (' /' ).pop () || filePath .split (' \\ ' ).pop ()
138+ showNotification (` 已打开文件: ${ fileName} ` , ' success' )
160139 },
161140 onSaveFile: async () => {
162- console .log (' 💾 渲染进程收到保存文件事件' );
163141 try {
164- const result = await saveFile (markdownContent .value );
142+ const result = await saveFile (markdownContent .value )
165143 if (result .success ) {
166- console .log (' ✅ 文件保存成功:' , result .filePath );
167- const fileName = result .filePath .split (' /' ).pop () || result .filePath .split (' \\ ' ).pop ();
168- showNotification (` 文件已保存: ${ fileName} ` , ' success' );
144+ const fileName = result .filePath .split (' /' ).pop () || result .filePath .split (' \\ ' ).pop ()
145+ showNotification (` 文件已保存: ${ fileName} ` , ' success' )
169146 } else {
170- console .log (' ❌ 文件保存失败:' , result .message );
171- showNotification (` 保存失败: ${ result .message } ` , ' error' );
147+ showNotification (` 保存失败: ${ result .message } ` , ' error' )
172148 }
173149 } catch (error) {
174- console .error (' 💥 保存文件时发生错误:' , error);
175- showNotification (` 保存失败: ${ error .message } ` , ' error' );
150+ showNotification (` 保存失败: ${ error .message } ` , ' error' )
176151 }
177152 }
178153 })
179-
154+
180155 // 设置文件内容更新监听器
181- setupFileUpdateListener ((event , { filePath, content }) => {
182- console .log (' 📨 收到文件内容更新事件' );
183- console .log (' 📂 文件路径:' , filePath);
184- console .log (' 📄 新内容长度:' , content .length );
185-
186- // 检查是否是当前打开的文件
187- if (currentFilePath .value === filePath) {
188- console .log (' 🔄 更新当前文件内容...' );
189-
190- // 检查内容是否真的发生了变化
191- if (markdownContent .value !== content) {
192- // 更新编辑器内容
193- updateMarkdownContent (content);
194- console .log (' ✅ 编辑器内容已自动更新' );
195-
196- // 显示更新通知
197- const fileName = filePath .split (' /' ).pop () || filePath .split (' \\ ' ).pop ();
198- showNotification (` 文件已更新: ${ fileName} ` );
199-
200- // 可选:记录更新日志
201- console .log (' 📝 文件内容更新记录:' , {
202- filePath,
203- oldLength: markdownContent .value .length ,
204- newLength: content .length ,
205- timestamp: new Date ().toISOString ()
206- });
207- } else {
208- console .log (' ℹ️ 内容相同,无需更新' );
209- }
210- } else {
211- console .log (' ℹ️ 不是当前打开的文件,忽略更新:' , filePath);
156+ setupFileUpdateListener ((_event , { filePath, content }) => {
157+ if (currentFilePath .value === filePath && markdownContent .value !== content) {
158+ updateMarkdownContent (content)
159+ const fileName = filePath .split (' /' ).pop () || filePath .split (' \\ ' ).pop ()
160+ showNotification (` 文件已更新: ${ fileName} ` )
212161 }
213- });
162+ })
214163})
215164
216165// 初始化主题管理器(全局单例内部已自动调用 initialize)
@@ -238,14 +187,6 @@ const handleFileChosen = async (e) => {
238187 }
239188}
240189
241- // 基于第一行 H1 自动生成文件名(导出功能移除后不再使用,可保留以备后续扩展)
242- // const makeExportFilename = () => {
243- // const md = markdownContent.value || ''
244- // const h1Match = md.match(/^#\s+(.+?)\s*$/m)
245- // const raw = (h1Match && h1Match[1]) || 'markdown-preview'
246- // return raw.replace(/[\\/:*?"<>|]/g, '').replace(/\s+/g, ' ').trim().slice(0, 80) || 'markdown-preview'
247- // }
248-
249190 </script >
250191
251192<style scoped>
0 commit comments