广丰卷烟厂数采质量分析系统
zhuguifei
2026-03-02 80ff784bf60637cd348ae665fc907f7b1e527dd8
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
46
47
48
49
50
51
52
<script setup lang="ts">
import { computed } from 'vue';
import hljs from 'highlight.js/lib/core';
import json from 'highlight.js/lib/languages/json';
import { twMerge } from 'tailwind-merge';
 
hljs.registerLanguage('json', json);
 
defineOptions({
  name: 'JsonPreview'
});
 
interface Props {
  class?: string;
  code?: string;
  showLineNumbers?: boolean;
}
 
const props = withDefaults(defineProps<Props>(), {
  class: '',
  code: '',
  showLineNumbers: false
});
 
const DEFAULT_CLASS = 'max-h-500px';
 
/** 格式化JSON数据 */
const jsonData = computed<string>(() => {
  if (!props.code) return '';
  try {
    return typeof props.code === 'string'
      ? JSON.stringify(JSON.parse(props.code), null, '\t')
      : JSON.stringify(props.code, null, '\t');
  } catch {
    return props.code;
  }
});
</script>
 
<template>
  <NScrollbar :class="twMerge(DEFAULT_CLASS, props.class)">
    <NCode :code="jsonData" :hljs="hljs" language="json" :show-line-numbers="showLineNumbers" :word-wrap="true" />
  </NScrollbar>
</template>
 
<style lang="scss">
html[class='dark'] {
  .vjs-tree-node:hover {
    background-color: #7c7777;
  }
}
</style>