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