feat: 记录文件的更新和保存时间

This commit is contained in:
Frankie Huang 2025-06-28 18:47:04 +08:00
parent 8586dcc320
commit f2ba92530f

View File

@ -79,7 +79,7 @@ watch(rootFolderPath, (newRootPath) => {
// <FolderTree> currentFilePath // <FolderTree> currentFilePath
const currentFilePath = ref(localStorage.getItem('currentSelectedFilePath') || ""); const currentFilePath = ref(localStorage.getItem('currentSelectedFilePath') || "");
let switchFilePath = false; // markdownCode watch let switchFilePath = true; // markdownCode watch
// currentFilePath MarkdownEditor // currentFilePath MarkdownEditor
watch(currentFilePath, async (newFilePath) => { watch(currentFilePath, async (newFilePath) => {
switchFilePath = true; switchFilePath = true;
@ -95,11 +95,14 @@ const getFileNameFromFilePath = (filePath) => {
const mainEditor = ref(null); const mainEditor = ref(null);
const markdownCode = ref("# Hello Markdown"); const markdownCode = ref("# Hello Markdown");
const lastSaveTime = new Map(); //
const lastUpdateTime = ref(0); //
watch(markdownCode, (newMarkdownCode) => { watch(markdownCode, (newMarkdownCode) => {
if (switchFilePath === true) { if (switchFilePath === true) {
switchFilePath = false; switchFilePath = false;
return; return;
} }
lastUpdateTime.value = new Date().getTime();
console.log("code be updated"); console.log("code be updated");
}) })
async function readFileContent(filePath) { async function readFileContent(filePath) {
@ -110,6 +113,7 @@ async function readFileContent(filePath) {
GetSingleArticle(articleID).then((data) => { GetSingleArticle(articleID).then((data) => {
markdownCode.value = data.mdCode; markdownCode.value = data.mdCode;
currentFilePath.value = filePath; currentFilePath.value = filePath;
lastSaveTime.set(filePath, new Date().getTime());
Message.success('已读取文件内容,并加载到编辑器中:' + filePath); Message.success('已读取文件内容,并加载到编辑器中:' + filePath);
}).catch((error) => { }).catch((error) => {
Message.error(`调用异常: ${error}`); Message.error(`调用异常: ${error}`);
@ -120,6 +124,7 @@ async function readFileContent(filePath) {
const fileContent = await readTextFile(filePath); const fileContent = await readTextFile(filePath);
markdownCode.value = fileContent; markdownCode.value = fileContent;
currentFilePath.value = filePath; currentFilePath.value = filePath;
lastSaveTime.set(filePath, new Date().getTime());
Message.success('已读取文件内容,并加载到编辑器中:' + filePath); Message.success('已读取文件内容,并加载到编辑器中:' + filePath);
} catch (err) { } catch (err) {
Message.error('文件读取失败:' + err); Message.error('文件读取失败:' + err);
@ -149,6 +154,7 @@ async function writeFileContent(markdownCode) {
await writeTextFile(currentFilePath.value, markdownCode); await writeTextFile(currentFilePath.value, markdownCode);
Message.success('文件更新成功:' + currentFilePath.value); Message.success('文件更新成功:' + currentFilePath.value);
} }
lastSaveTime.set(currentFilePath.value, new Date().getTime());
} catch (err) { } catch (err) {
Message.error('文件更新失败:' + err); Message.error('文件更新失败:' + err);
} }