-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
763 additions
and
816 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
src/components/CodemirrorEditor/EditorHeader/FileDropdown.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<script setup> | ||
import { onMounted, ref } from 'vue' | ||
import { storeToRefs } from 'pinia' | ||
import { useStore } from '@/stores' | ||
const store = useStore() | ||
const { | ||
isDark, | ||
isEditOnLeft, | ||
} = storeToRefs(store) | ||
const { | ||
toggleDark, | ||
toggleEditOnLeft, | ||
exportEditorContent, | ||
downloadEditorContent, | ||
} = store | ||
const fileInput = ref(null) | ||
onMounted(() => { | ||
fileInput.value.onchange = () => { | ||
const file = fileInput.value.files[0] | ||
if (file === null) { | ||
return | ||
} | ||
const read = new FileReader() | ||
read.readAsText(file) | ||
read.onload = () => { | ||
editor.value.setValue(read.result) | ||
editorRefresh() | ||
} | ||
} | ||
}) | ||
function refClick() { | ||
fileInput.value.click() | ||
} | ||
</script> | ||
|
||
<template> | ||
<el-dropdown> | ||
<span class="el-dropdown-link"> | ||
文件<el-icon class="ml-2"> | ||
<ElIconArrowDown /> | ||
</el-icon> | ||
</span> | ||
<template #dropdown> | ||
<el-dropdown-menu> | ||
<el-dropdown-item class="leading-8" @click="refClick()"> | ||
<el-icon> | ||
<ElIconUpload /> | ||
</el-icon> | ||
导入 .md | ||
<input ref="fileInput" hidden type="file" accept=".md"> | ||
</el-dropdown-item> | ||
<el-dropdown-item class="leading-8" @click="downloadEditorContent()"> | ||
<el-icon> | ||
<ElIconDownload /> | ||
</el-icon> | ||
导出 .md | ||
</el-dropdown-item> | ||
<el-dropdown-item class="leading-8" @click="exportEditorContent()"> | ||
<el-icon> | ||
<ElIconDocument /> | ||
</el-icon> | ||
导出 .html | ||
</el-dropdown-item> | ||
<el-dropdown-item divided class="leading-8" @click="toggleDark()"> | ||
<el-icon :class="{ 'opacity-0': !isDark }"> | ||
<ElIconCheck /> | ||
</el-icon> | ||
深色模式 | ||
</el-dropdown-item> | ||
<el-dropdown-item divided class="leading-8" @click="toggleEditOnLeft()"> | ||
<el-icon :class="{ 'opacity-0': !isEditOnLeft }"> | ||
<ElIconCheck /> | ||
</el-icon> | ||
左侧编辑 | ||
</el-dropdown-item> | ||
</el-dropdown-menu> | ||
</template> | ||
</el-dropdown> | ||
</template> | ||
|
||
<style lang="less" scoped> | ||
.el-dropdown-link { | ||
display: flex; | ||
align-items: center; | ||
cursor: pointer; | ||
} | ||
</style> |
107 changes: 107 additions & 0 deletions
107
src/components/CodemirrorEditor/EditorHeader/PostInfo.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<script setup> | ||
import { ref } from 'vue' | ||
import { storeToRefs } from 'pinia' | ||
import { useStore } from '@/stores' | ||
defineEmits([`close`, `post`]) | ||
const store = useStore() | ||
const { output } = storeToRefs(store) | ||
const dialogVisible = ref(false) | ||
const form = ref({ | ||
title: ``, | ||
desc: ``, | ||
thumb: ``, | ||
content: ``, | ||
}) | ||
function prePost() { | ||
let auto = {} | ||
try { | ||
auto = { | ||
thumb: document.querySelector(`#output img`)?.src, | ||
title: [1, 2, 3, 4, 5, 6] | ||
.map(h => document.querySelector(`#output h${h}`)) | ||
.filter(h => h)[0].textContent, | ||
desc: document.querySelector(`#output p`).textContent, | ||
content: output.value, | ||
} | ||
} | ||
catch (error) { | ||
console.log(`error`, error) | ||
} | ||
form.value = { | ||
...auto, | ||
auto, | ||
} | ||
dialogVisible.value = true | ||
} | ||
function post() { | ||
dialogVisible.value = false | ||
// 使用 window.$syncer 可以检测是否安装插件 | ||
window.syncPost({ | ||
thumb: form.value.thumb || form.value.auto.thumb, | ||
title: form.value.title || form.value.auto.title, | ||
desc: form.value.desc || form.value.auto.desc, | ||
content: form.value.content || form.value.auto.content, | ||
}) | ||
} | ||
</script> | ||
|
||
<template> | ||
<el-button plain type="primary" @click="prePost"> | ||
发布 | ||
</el-button> | ||
|
||
<el-dialog | ||
title="发布" | ||
:model-value="dialogVisible" | ||
@close="dialogVisible = false" | ||
> | ||
<el-alert | ||
class="mb-4" | ||
title="注:此功能由第三方浏览器插件支持,本平台不保证安全性。" | ||
type="info" | ||
show-icon | ||
/> | ||
<el-form | ||
class="postInfo" | ||
label-width="50" | ||
:model="form" | ||
> | ||
<el-form-item label="封面"> | ||
<el-input | ||
v-model="form.thumb" | ||
placeholder="自动提取第一张图" | ||
/> | ||
</el-form-item> | ||
<el-form-item label="标题"> | ||
<el-input | ||
v-model="form.title" | ||
placeholder="自动提取第一个标题" | ||
/> | ||
</el-form-item> | ||
<el-form-item label="描述"> | ||
<el-input | ||
v-model="form.desc" | ||
type="textarea" | ||
:rows="4" | ||
placeholder="自动提取第一个段落" | ||
/> | ||
</el-form-item> | ||
</el-form> | ||
|
||
<template #footer> | ||
<el-button @click="dialogVisible = false"> | ||
取 消 | ||
</el-button> | ||
<el-button type="primary" @click="post"> | ||
确 定 | ||
</el-button> | ||
</template> | ||
</el-dialog> | ||
</template> |
58 changes: 0 additions & 58 deletions
58
src/components/CodemirrorEditor/EditorHeader/PostInfoDialog.vue
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.