This commit is contained in:
2025-02-23 23:17:06 +08:00
parent d934111354
commit e275da04ee
8 changed files with 200 additions and 134 deletions

View File

@@ -51,6 +51,6 @@ const lang = computed(() => {
indentWithTab
:extensions="[styleTheme, lang, isDark ? oneDark : smoothy]"
:tabSize="4"
:style="{ height: 'calc(100vh - 52px)', fontSize: props.fontSize + 'px' }"
:style="{ height: '100%', fontSize: props.fontSize + 'px' }"
/>
</template>

View File

@@ -0,0 +1,60 @@
<template>
<n-tabs pane-class="pane" default-value="html" type="segment">
<n-tab-pane name="html" tab="HTML">
<Editor language="html" :font-size="size" v-model:value="html" />
</n-tab-pane>
<n-tab-pane name="css" tab="CSS">
<Editor language="css" :font-size="size" v-model:value="css" />
</n-tab-pane>
<n-tab-pane name="js" tab="JS">
<Editor language="js" :font-size="size" v-model:value="js" />
</n-tab-pane>
<n-tab-pane name="actions" tab="选项">
<n-flex vertical class="wrapper">
<!-- <n-flex align="center">
<span class="label">主题</span>
<n-button @click="toggleDark()">
{{ isDark ? "浅色" : "深色" }}
</n-button>
</n-flex> -->
<n-flex align="center">
<span class="label">重置</span>
<n-button @click="reset('html')">HTML</n-button>
<n-button @click="reset('css')">CSS</n-button>
<n-button @click="reset('js')">JS</n-button>
</n-flex>
<n-flex align="center">
<span class="label">字号</span>
<n-flex align="center">
<span :style="{ 'font-size': size + 'px' }">{{ size }}</span>
<n-button @click="changeSize(size - 2)" :disabled="size === 20">
调小
</n-button>
<n-button @click="changeSize(size + 2)" :disabled="size === 40">
调大
</n-button>
</n-flex>
</n-flex>
</n-flex>
</n-tab-pane>
</n-tabs>
</template>
<script lang="ts" setup>
import { useDark, useToggle } from "@vueuse/core"
import Editor from "./Editor.vue"
import { html, css, js, reset, size, changeSize } from "../store.ts"
const isDark = useDark()
const toggleDark = useToggle(isDark)
</script>
<style scoped>
.pane {
height: calc(100vh - 52px);
}
.wrapper {
padding: 12px;
}
.label {
font-size: 16px;
}
</style>

View File

@@ -8,12 +8,11 @@ import { onMounted, useTemplateRef, watch } from "vue"
const iframe = useTemplateRef<HTMLIFrameElement>("iframe")
function preview() {
if (!iframe.value) return
const doc = iframe.value.contentDocument
doc!.open()
doc!.write(`<!DOCTYPE html>
const doc = iframe.value.contentDocument!
doc.open()
doc.write(`<!DOCTYPE html>
<html lang="zh-Hans-CN">
<head>
<meta charset="UTF-8" />
@@ -25,7 +24,7 @@ function preview() {
${html.value}
</body>
</html>`)
doc!.close()
doc.close()
}
watch([html, css], preview)