/** * @description 代码预览 */ import React from "react" import { PopModalProps, PopModal, StateManage, Button, PropertyService } from "zion-ui" import Editor from "@monaco-editor/react" const className = "zion-ui-code-container" interface ICodePreview { code?: string modalProps?: PopModalProps language?: string allowPreview?: boolean } export const CodePreview = function (params: ICodePreview) { const { code, modalProps, language, allowPreview } = params const codeEleId = "zion-ui-code-container-" + ((Math.random() * 100000).toFixed(0)) const editorOptions = { "fontSize": 13, "tabSize": 4, "wordWrapColumn": 400, "formatOnSave": true, "renderControlCharacters": false, "detectIndentation": false, "codeDataApiOnSave": { "source.fixAll.eslint": false }, "formatOnPaste": true, } const editorMap: any = { editor: null } const footer =
const modalState = PopModal({ width: "80%", height: "70%", top: "20px", allowFullScreen: false, content:
{ editorMap.editor = editor const timer = setTimeout(() => { editor.setValue(code); editor.getAction('editor.action.formatDocument').run(); clearTimeout(timer) }, 300) }} language={language || "jsx"}>
, ...modalProps, footer }) }