|
@ -1,15 +1,15 @@ |
|
|
<script lang="ts" setup> |
|
|
<script lang="ts" setup> |
|
|
|
|
|
import { useHistoryStore } from "@/stores/history"; |
|
|
import { BrowserWindow, System } from "@/system"; |
|
|
import { BrowserWindow, System } from "@/system"; |
|
|
import { inject, onMounted, ref, toRaw, onUnmounted } from "vue"; |
|
|
import { getSplit, getSystemConfig } from "@/system/config"; |
|
|
|
|
|
import { decodeBase64, isBase64 } from "@/util/file"; |
|
|
import { notifyError, notifySuccess } from "@/util/msg"; |
|
|
import { notifyError, notifySuccess } from "@/util/msg"; |
|
|
import Vditor from "vditor"; |
|
|
|
|
|
import "vditor/dist/index.css"; |
|
|
|
|
|
import { getMdOption } from "@/util/vditor"; |
|
|
import { getMdOption } from "@/util/vditor"; |
|
|
import { isBase64, decodeBase64 } from "@/util/file"; |
|
|
|
|
|
import moment from "moment"; |
|
|
|
|
|
import { useHistoryStore } from "@/stores/history"; |
|
|
|
|
|
import { getSplit } from "@/system/config"; |
|
|
|
|
|
import { saveAs } from "file-saver"; |
|
|
import { saveAs } from "file-saver"; |
|
|
|
|
|
import moment from "moment"; |
|
|
|
|
|
import Vditor from "vditor"; |
|
|
|
|
|
import "vditor/dist/index.css"; |
|
|
|
|
|
import { inject, onMounted, onUnmounted, ref, toRaw } from "vue"; |
|
|
|
|
|
|
|
|
const historyStore = useHistoryStore(); |
|
|
const historyStore = useHistoryStore(); |
|
|
|
|
|
|
|
@ -27,7 +27,10 @@ console.log(SP); |
|
|
|
|
|
|
|
|
const debouncedHandleKeyDown = (event: KeyboardEvent) => { |
|
|
const debouncedHandleKeyDown = (event: KeyboardEvent) => { |
|
|
// 确保仅在我们的按钮获得焦点时处理快捷键 |
|
|
// 确保仅在我们的按钮获得焦点时处理快捷键 |
|
|
if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === "s") { |
|
|
if ( |
|
|
|
|
|
(event.metaKey || event.ctrlKey) && |
|
|
|
|
|
event.key.toLowerCase() === "s" |
|
|
|
|
|
) { |
|
|
event.stopPropagation(); // 先阻止事件冒泡 |
|
|
event.stopPropagation(); // 先阻止事件冒泡 |
|
|
event.preventDefault(); // 再阻止默认行为 |
|
|
event.preventDefault(); // 再阻止默认行为 |
|
|
if (!isSaveing.value) { |
|
|
if (!isSaveing.value) { |
|
@ -100,15 +103,34 @@ async function saveData() { |
|
|
fileTitleArr.pop(); |
|
|
fileTitleArr.pop(); |
|
|
const oldTitle = fileTitleArr.join("."); |
|
|
const oldTitle = fileTitleArr.join("."); |
|
|
if (oldTitle != baseTitle.value) { |
|
|
if (oldTitle != baseTitle.value) { |
|
|
filepath.value = filepath.value.replace(oldTitle, baseTitle.value); |
|
|
filepath.value = filepath.value.replace( |
|
|
|
|
|
oldTitle, |
|
|
|
|
|
baseTitle.value |
|
|
|
|
|
); |
|
|
refreshDesktop = true; |
|
|
refreshDesktop = true; |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
refreshDesktop = true; |
|
|
refreshDesktop = true; |
|
|
} |
|
|
} |
|
|
|
|
|
const file = await sys?.fs.getShareInfo(filepath.value); |
|
|
|
|
|
const isWrite = |
|
|
|
|
|
file.fs.sender === getSystemConfig().userInfo.id |
|
|
|
|
|
? 1 |
|
|
|
|
|
: file.fs.is_write; |
|
|
//console.log(path) |
|
|
//console.log(path) |
|
|
await sys?.fs.writeFile(filepath.value, vditor.value.getValue()); |
|
|
const res = file.fi.isShare |
|
|
notifySuccess("保存成功!"); |
|
|
? await sys?.fs.writeShareFile( |
|
|
|
|
|
filepath.value, |
|
|
|
|
|
vditor.value.getValue(), |
|
|
|
|
|
isWrite |
|
|
|
|
|
) |
|
|
|
|
|
: await sys?.fs.writeFile(filepath.value, vditor.value.getValue()); |
|
|
|
|
|
if (res.success) { |
|
|
|
|
|
notifySuccess(res.message || "保存成功!"); |
|
|
|
|
|
} else { |
|
|
|
|
|
notifyError(res.message || "保存失败"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
isSaveing.value = false; |
|
|
isSaveing.value = false; |
|
|
if (refreshDesktop) { |
|
|
if (refreshDesktop) { |
|
|
sys.refershAppList(); |
|
|
sys.refershAppList(); |
|
@ -126,7 +148,10 @@ function uploadFile(event: any) { |
|
|
} |
|
|
} |
|
|
const reader = new FileReader(); |
|
|
const reader = new FileReader(); |
|
|
reader.onload = (e: any) => { |
|
|
reader.onload = (e: any) => { |
|
|
baseTitle.value = file.name.substring(0, file.name.lastIndexOf(".")); |
|
|
baseTitle.value = file.name.substring( |
|
|
|
|
|
0, |
|
|
|
|
|
file.name.lastIndexOf(".") |
|
|
|
|
|
); |
|
|
vditor.value.setValue(e.target.result); |
|
|
vditor.value.setValue(e.target.result); |
|
|
}; |
|
|
}; |
|
|
reader.readAsText(file); |
|
|
reader.readAsText(file); |
|
@ -144,7 +169,9 @@ function download() { |
|
|
notifyError("内容不能为空"); |
|
|
notifyError("内容不能为空"); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
let blob = new Blob([contentData], { type: "text/plain;charset=utf-8" }); |
|
|
let blob = new Blob([contentData], { |
|
|
|
|
|
type: "text/plain;charset=utf-8", |
|
|
|
|
|
}); |
|
|
saveAs(blob, baseTitle.value + ".md"); |
|
|
saveAs(blob, baseTitle.value + ".md"); |
|
|
} |
|
|
} |
|
|
</script> |
|
|
</script> |
|
@ -176,12 +203,29 @@ function download() { |
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
</el-drawer> |
|
|
</el-drawer> |
|
|
<el-row justify="space-between" :gutter="20" :span="24" style="margin: 10px 20px"> |
|
|
<el-row |
|
|
|
|
|
justify="space-between" |
|
|
|
|
|
:gutter="20" |
|
|
|
|
|
:span="24" |
|
|
|
|
|
style="margin: 10px 20px" |
|
|
|
|
|
> |
|
|
<el-col :span="5"> |
|
|
<el-col :span="5"> |
|
|
<el-button @click.stop="drawerBox = !drawerBox" icon="Menu" circle /> |
|
|
<el-button |
|
|
<el-button @click.stop="importMd" icon="Upload" circle /> |
|
|
@click.stop="drawerBox = !drawerBox" |
|
|
|
|
|
icon="Menu" |
|
|
|
|
|
circle |
|
|
|
|
|
/> |
|
|
|
|
|
<el-button |
|
|
|
|
|
@click.stop="importMd" |
|
|
|
|
|
icon="Upload" |
|
|
|
|
|
circle |
|
|
|
|
|
/> |
|
|
|
|
|
|
|
|
<el-button @click.stop="download" icon="Download" circle /> |
|
|
<el-button |
|
|
|
|
|
@click.stop="download" |
|
|
|
|
|
icon="Download" |
|
|
|
|
|
circle |
|
|
|
|
|
/> |
|
|
<input |
|
|
<input |
|
|
type="file" |
|
|
type="file" |
|
|
ref="fileInput" |
|
|
ref="fileInput" |
|
@ -191,13 +235,24 @@ function download() { |
|
|
/> |
|
|
/> |
|
|
</el-col> |
|
|
</el-col> |
|
|
<el-col :span="15"> |
|
|
<el-col :span="15"> |
|
|
<el-input v-model="baseTitle" placeholder="输入标题" /> |
|
|
<el-input |
|
|
|
|
|
v-model="baseTitle" |
|
|
|
|
|
placeholder="输入标题" |
|
|
|
|
|
/> |
|
|
</el-col> |
|
|
</el-col> |
|
|
<el-col :span="2"> |
|
|
<el-col :span="2"> |
|
|
<el-button @click.stop="saveData()" icon="Finished" :loading="isSaveing" circle /> |
|
|
<el-button |
|
|
|
|
|
@click.stop="saveData()" |
|
|
|
|
|
icon="Finished" |
|
|
|
|
|
:loading="isSaveing" |
|
|
|
|
|
circle |
|
|
|
|
|
/> |
|
|
</el-col> |
|
|
</el-col> |
|
|
</el-row> |
|
|
</el-row> |
|
|
<div id="vditorContainer" style="margin: 10px 20px"></div> |
|
|
<div |
|
|
|
|
|
id="vditorContainer" |
|
|
|
|
|
style="margin: 10px 20px" |
|
|
|
|
|
></div> |
|
|
</template> |
|
|
</template> |
|
|
<style scoped> |
|
|
<style scoped> |
|
|
@import "@/assets/left.scss"; |
|
|
@import "@/assets/left.scss"; |
|
|