Ver Fonte

fix: codemirrot

lvkun996 há 3 anos atrás
pai
commit
5d5269bb76
2 ficheiros alterados com 9 adições e 11 exclusões
  1. 6 8
      src/components/CodeMirror/index.tsx
  2. 3 3
      src/pages/rts/protocol/index.vue

+ 6 - 8
src/components/CodeMirror/index.tsx

@@ -5,7 +5,7 @@ import { EditorView } from '@codemirror/view'
 import { EditorState, StateEffect } from '@codemirror/state'
 import { javascript } from '@codemirror/lang-javascript'
 import { useId } from '@/hooks'
-// '{"paramName":"page","paramType":"int","paramDesc":"分页页码","require":true}'
+
 export const CodeMirrorTsx = defineComponent({
   name: 'code-mirror-tsx',
   props: {
@@ -38,17 +38,11 @@ export const CodeMirrorTsx = defineComponent({
         doc: transDoc(),
         extensions: [basicSetup, javascript()]
       })
-      // transDoc(),
+
       view.value = new EditorView({
         state: editorState,
         parent: document.getElementById(`editorRef-${id}`)!
       })
-
-      setTimeout(() => {
-        console.dir(document.getElementById(`editorRef-${id}`))
-
-        // console.log(document.getElementById(`editorRef-${id}`)!.getValue())
-      }, 10000)
     }
 
     onMounted(() => {
@@ -59,6 +53,10 @@ export const CodeMirrorTsx = defineComponent({
       })
     })
 
+    ctx.expose({
+      getValue: () => JSON.parse(JSON.stringify(view.value!.state.doc.toJSON().join('')))
+    })
+
     return () => (
       <div ref="editorRef" id={`editorRef-${id}`}></div>
     )

+ 3 - 3
src/pages/rts/protocol/index.vue

@@ -23,6 +23,7 @@
       v-if="state.bodyJson"
       :body-json="state.bodyJson"
       body-type="json"
+      ref="codeMirrorRef"
     />
     <a-empty  style="margin-top: 200px;" v-else :image="Empty.PRESENTED_IMAGE_SIMPLE" description="请在左上角选择协议"/>
 
@@ -57,9 +58,8 @@ watch(
 const { start, stop } = useScheduler(() => state.loading = false, 2000)
 
 const saveProtocol = async () => {
-  console.log(codeMirrorRef.value.getValue)
-
-  // await RtsController.updateProtocol(state.name as RTS.protocol, state.bodyJson)
+  console.log()
+  await RtsController.updateProtocol(state.name as RTS.protocol, codeMirrorRef.value.getValue())
 }
 
 const getProtocol = async () => {