code lint

This commit is contained in:
2025-03-06 00:12:38 +08:00
parent 6d6c69cf37
commit b1593b1c8e
11 changed files with 104 additions and 80 deletions

View File

@@ -32,13 +32,9 @@ const props = withDefaults(defineProps<Props>(), {
const code = defineModel<string>("value")
const lang = computed(() => {
if (props.language === "html") {
return html()
} else if (props.language === "css") {
return css()
} else {
return javascript()
}
if (props.language === "html") return html()
if (props.language === "css") return css()
return javascript()
})
</script>
<template>

View File

@@ -4,7 +4,7 @@
<Icon icon="noto:eyes" :width="20"></Icon>
<n-text class="titleText">预览</n-text>
</n-flex>
<n-button quaternary @click="download">下载</n-button>
<n-button quaternary @click="download" :disabled="!showDL">下载</n-button>
</n-flex>
<iframe class="iframe" ref="iframe"></iframe>
</template>
@@ -12,10 +12,11 @@
<script lang="ts" setup>
import { watchDebounced } from "@vueuse/core"
import { html, css, js } from "../store/editors"
import { onMounted, useTemplateRef } from "vue"
import { computed, onMounted, useTemplateRef } from "vue"
import { Icon } from "@iconify/vue"
const iframe = useTemplateRef<HTMLIFrameElement>("iframe")
const showDL = computed(() => html.value || css.value || js.value)
function getContent() {
return `<!DOCTYPE html>
@@ -37,10 +38,12 @@ function getContent() {
function preview() {
if (!iframe.value) return
const doc = iframe.value.contentDocument!
doc.open()
doc.write(getContent())
doc.close()
const doc = iframe.value.contentDocument
if (doc) {
doc.open()
doc.write(getContent())
doc.close()
}
}
function download() {

View File

@@ -75,8 +75,8 @@ async function getContent() {
function addButton() {
const action = document.createElement("div")
action.className = "codeblock-action"
const pres = $content.value!.querySelectorAll("pre")
pres.forEach((pre) => {
const pres = $content.value?.querySelectorAll("pre") ?? []
for (const pre of pres) {
let timer = 0
const copy = action.cloneNode() as HTMLDivElement
pre.insertBefore(copy, pre.children[0])
@@ -88,7 +88,7 @@ function addButton() {
const btn = copy.children[1] as HTMLDivElement
btn.onclick = () => {
tab.value = lang
const content = pre.children[1].textContent!
const content = pre.children[1].textContent
if (lang === "html") html.value = content
if (lang === "css") css.value = content
if (lang === "js") js.value = content
@@ -99,12 +99,14 @@ function addButton() {
btn.innerHTML = "替换"
}, 1000)
}
})
}
}
function modifyLink() {
const links = $content.value!.querySelectorAll("a")
links.forEach((link) => (link.target = "_blank"))
const links = $content.value?.querySelectorAll("a") ?? []
for (const link of links) {
link.target = "_blank"
}
}
async function render() {

View File

@@ -1,10 +1,6 @@
<template>
<n-flex>
<n-button
secondary
v-if="user.role !== Role.Super"
@click="edit"
>
<n-button secondary v-if="user.role !== Role.Super" @click="edit">
修改
</n-button>
<n-button