forked from mxx1111/mdlook
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomUploadForm.vue
More file actions
93 lines (81 loc) · 2.38 KB
/
Copy pathCustomUploadForm.vue
File metadata and controls
93 lines (81 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<script setup lang='ts'>
import { Compartment } from '@codemirror/state'
import { EditorView } from '@codemirror/view'
import { javascriptSetup, theme } from '@md/shared'
import { useUIStore } from '@/stores/ui'
import { removeLeft } from '@/utils'
import { store } from '@/utils/storage'
const code = store.reactive(`formCustomConfig`, removeLeft(`
const { file, util, okCb, errCb } = CUSTOM_ARG
param = new FormData()
param.append('file', file)
util.axios.post('${window.location.origin}/upload', param, {
headers: { 'Content-Type': 'multipart/form-data' }
}).then(res => {
okCb(res.url)
}).catch(err => {
errCb(err)
})
`).trim())
const formCustomTextarea = useTemplateRef<HTMLDivElement>(`formCustomTextarea`)
const uiStore = useUIStore()
const { isDark } = storeToRefs(uiStore)
const editor = ref<EditorView | null>(null)
const themeCompartment = new Compartment()
onMounted(() => {
const editorView = new EditorView({
parent: formCustomTextarea.value!,
extensions: [javascriptSetup(), themeCompartment.of(theme(isDark.value))],
doc: code.value,
})
editor.value = editorView
})
watch(isDark, (dark) => {
editor.value?.dispatch({
effects: themeCompartment.reconfigure(theme(dark)),
})
})
onUnmounted(() => {
if (editor.value) {
editor.value.destroy()
}
})
function formCustomSave() {
const str = editor.value!.state.doc.toString()
code.value = str
toast.success(`保存成功`)
}
</script>
<template>
<div class="flex flex-col flex-1 overflow-hidden">
<div class="flex-1 overflow-y-auto p-1 [scrollbar-width:none] [-ms-overflow-style:none] [&::-webkit-scrollbar]:hidden space-y-4">
<div class="h-60 border border-gray-200 dark:border-gray-700 rounded-lg flex flex-col overflow-y-auto">
<div
ref="formCustomTextarea"
class="flex-1 custom-codemirror"
/>
</div>
<Button
variant="link"
class="p-0 h-auto text-left whitespace-normal"
as="a"
href="https://github.com/mxx1111/mdlook/blob/main/docs/custom-upload.md"
target="_blank" rel="noopener noreferrer"
>
参数详情?
</Button>
</div>
<DialogFooter class="p-1">
<Button @click="formCustomSave">
保存配置
</Button>
</DialogFooter>
</div>
</template>
<style scoped>
@media (max-width: 768px) {
:deep(.CodeMirror) {
font-size: 12px;
}
}
</style>