1、基础代码

This commit is contained in:
asypost committed 2026-11-03 16:52:16 +08:00
commit 19ed404da6
13 files changed
+3597

No files matched your search

+185
View File
@@ -0,0 +1,185 @@
```vue
<script setup>
import { computed } from 'vue'
const props = defineProps({
node: {
type: Object,
required: true,
},
})
// 获取代码语言
const language = computed(() => {
const className = props.node.properties.class ?? props.node.properties.class ?? ''
const classes = Array.isArray(className)
? className
: String(className).split(/\s+/)
console.log(classes)
return classes
.find(item => item.startsWith('language-'))
?.slice('language-'.length) ?? ''
})
const getTextContent = (children) => {
const result = [];
const stack = [...children].reverse();
while (stack.length > 0) {
const node = stack.pop();
if (node.type === "text") {
result.push(node.value);
} else if (node.children) {
stack.push(...node.children.reverse());
}
}
return result.join("");
};
// 获取代码文本
const codeText = computed(() => {
return getTextContent(props.node.children);
})
// 解析名片 JSON
const card = computed(() => {
if (language.value !== 'card') return null
try {
return JSON.parse(codeText.value)
} catch (error) {
console.error('名片 JSON 解析失败:', error)
return null
}
})
</script>
<template>
<div v-if="language === 'card' && card" class="business-card">
<div class="card-header">
<div class="avatar">
{{ card.name?.charAt(0) || '?' }}
</div>
<div class="person">
<div class="name">{{ card.name }}</div>
<div class="department">{{ card.department }}</div>
</div>
</div>
<div class="card-divider"></div>
<div class="card-info">
<div v-if="card.company" class="info-item">
<span class="label">公司</span>
<span>{{ card.company }}</span>
</div>
<div v-if="card.tel" class="info-item">
<span class="label">电话</span>
<span>{{ card.tel }}</span>
</div>
<div v-if="card.phone" class="info-item">
<span class="label">手机</span>
<span>{{ card.phone }}</span>
</div>
</div>
</div>
<div v-else class="code-block">
<div class="code-header">
<span>{{ language || 'Code' }}</span>
<button>复制</button>
</div>
<pre><slot /></pre>
</div>
</template>
<style scoped>
.business-card {
max-width: 420px;
padding: 20px;
border: 1px solid #ddd;
border-radius: 12px;
background: white;
color: #222;
}
.card-header {
display: flex;
align-items: center;
gap: 14px;
}
.avatar {
width: 48px;
height: 48px;
display: flex;
align-items: center;
justify-content: center;
border-radius: 50%;
background: #e8efff;
color: #3565b8;
font-size: 20px;
font-weight: 600;
}
.name {
font-size: 18px;
font-weight: 600;
}
.department {
margin-top: 4px;
color: #888;
font-size: 13px;
}
.card-divider {
height: 1px;
margin: 18px 0;
background: #eee;
}
.card-info {
display: grid;
gap: 12px;
}
.info-item {
display: flex;
gap: 16px;
font-size: 14px;
}
.label {
width: 40px;
flex-shrink: 0;
color: #999;
}
.code-block {
border: 1px solid #ddd;
border-radius: 8px;
overflow: hidden;
}
.code-header {
display: flex;
justify-content: space-between;
padding: 8px 12px;
background: #f5f5f5;
}
pre {
padding: 12px;
overflow-x: auto;
margin: 0;
}
</style>
```