feat: 优化表现
This commit is contained in:
1 parent
d61b5e8a52
commit
03212f9854
3 files changed
+26
-5
No files matched your search
@@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="cm-rander-wrapper">
|
<div :class="wrapperClass">
|
||||||
<div class="cm-header">
|
<div class="cm-header">
|
||||||
<div class="cm-header-title">
|
<div class="cm-header-title">
|
||||||
<span>CodeMirror</span>
|
<span>CodeMirror</span>
|
||||||
@@ -26,6 +26,7 @@ import { EditorState } from "@codemirror/state"
|
|||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
data: string,
|
data: string,
|
||||||
type?: string,
|
type?: string,
|
||||||
|
inline?: boolean,
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const show = ref(true)
|
const show = ref(true)
|
||||||
@@ -33,14 +34,18 @@ const cmRootRef = ref<HTMLElement>()
|
|||||||
|
|
||||||
const isLoading = ref(true)
|
const isLoading = ref(true)
|
||||||
|
|
||||||
|
const wrapperClass = computed(() => {
|
||||||
|
return ['cm-rander-wrapper', props.inline === true ? 'cm-rander-wrapper-inline' : '']
|
||||||
|
})
|
||||||
|
|
||||||
const rows = computed(() => {
|
const rows = computed(() => {
|
||||||
if (!props.data) {
|
if (!props.data) {
|
||||||
return 5
|
return 5
|
||||||
}
|
}
|
||||||
const lines = props.data.split('\n')
|
const lines = props.data.split('\n')
|
||||||
console.log({
|
// console.log({
|
||||||
L: lines.length,
|
// L: lines.length,
|
||||||
})
|
// })
|
||||||
return lines.length - 2 > 0 ? lines.length - 2 : 1
|
return lines.length - 2 > 0 ? lines.length - 2 : 1
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -135,6 +140,15 @@ onBeforeUnmount(() => {
|
|||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
.cm-rander-wrapper {
|
.cm-rander-wrapper {
|
||||||
|
&-inline {
|
||||||
|
display: inline-block;
|
||||||
|
.cm-header {
|
||||||
|
display: none !important;
|
||||||
|
}
|
||||||
|
.cm-gutters {
|
||||||
|
display: none !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
.cm-header {
|
.cm-header {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|||||||
@@ -45,12 +45,19 @@ const VNodeArr = computed(() => {
|
|||||||
// console.log({
|
// console.log({
|
||||||
// codeType,
|
// codeType,
|
||||||
// })
|
// })
|
||||||
|
// @ts-ignore
|
||||||
|
const inline = (item.children[0].children.trim() as string).includes('\n') ? false : true
|
||||||
|
console.log({
|
||||||
|
inline,
|
||||||
|
c: item.children
|
||||||
|
})
|
||||||
return h(
|
return h(
|
||||||
codeMirror,
|
codeMirror,
|
||||||
{
|
{
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
data: item.children[0].children.trim(),
|
data: item.children[0].children.trim(),
|
||||||
type: codeType,
|
type: codeType,
|
||||||
|
inline,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
{{ formatDate(post.date, 'yy-MM-dd HH:mm:ss') }}
|
{{ formatDate(post.date, 'yy-MM-dd HH:mm:ss') }}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="post-tags">
|
<div class="post-tags" v-if="post.tags.length">
|
||||||
<bookmark class="post-tags-icon" />
|
<bookmark class="post-tags-icon" />
|
||||||
<div v-for="tag in post.tags">{{ tag }}</div>
|
<div v-for="tag in post.tags">{{ tag }}</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in new issue
Block a user