wangzhibo
2026-07-16 b57020623cf0c946706573bf102e548c3a544423
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
<template>
    <cl-editor-preview v-if="!isHide" :ref="setRefs('preview')" type="code" :tabs="tabs">
        <el-button @click="open">代码</el-button>
    </cl-editor-preview>
</template>
 
<script setup lang="ts">
defineOptions({
    name: 'demo-code'
});
 
import { useCool } from '/@/cool';
import { type PropType, computed } from 'vue';
import { demo } from 'virtual:demo';
import { basename } from '/@/cool/utils';
import { isEmpty } from 'lodash-es';
 
const props = defineProps({
    files: {
        type: Array as PropType<string[]>,
        default: () => []
    }
});
 
const { refs, setRefs } = useCool();
 
// 是否隐藏
const isHide = computed(() => isEmpty(demo));
 
// 文件列表
const tabs = computed(() => {
    return props.files?.map(e => {
        return {
            name: basename(e),
            language: e.includes('.vue') ? 'html' : 'typescript',
            data: demo[e]
        };
    });
});
 
// 打开
function open() {
    refs.preview.open();
}
</script>