Selaa lähdekoodia

fix: 更改侧边栏的逻辑

liutian 3 kuukautta sitten
vanhempi
commit
ce20e3c148

+ 18 - 0
packages/core/src/form/text_field.js

@@ -482,6 +482,12 @@ export default class TextField extends Base {
           contents: this.annotation.contents
         }
       })
+
+      this.eventBus.dispatch('formFieldValuesChange', {
+        type: 'textfield',
+        pageNumber: this.page + 1,
+        contents: this.annotation.contents,
+      })
     }
     this.textContainer.style.pointerEvents = 'none'
     this.textContainer.style.cursor = 'pointer'
@@ -873,10 +879,17 @@ export default class TextField extends Base {
       }
 
       const updateAnnot = Object.assign({}, annotationData, props)
+
       this.eventBus.dispatch('annotationChange', {
         type: 'modify',
         annotation: updateAnnot
       })
+
+      'contents' in props && this.eventBus.dispatch('formFieldValuesChange', {
+        type: 'textfield',
+        pageNumber: this.page + 1,
+        contents: this.annotation.contents,
+      })
     }
   }
 
@@ -1077,5 +1090,10 @@ export default class TextField extends Base {
       type: 'modify',
       annotation: updateAnnot
     })
+    'contents' in props && this.eventBus.dispatch('formFieldValuesChange', {
+      type: 'textfield',
+      pageNumber: this.page + 1,
+      contents: this.annotation.contents,
+    })
   }
 }

+ 36 - 37
packages/webview/src/components/RightPanel/RightPanel.vue

@@ -121,7 +121,7 @@
           </div>
           <div class="content-block">
             <h2>{{ $t('rightPanel.defaultValue') }}</h2>
-            <textarea name="default-value" id="default-value" rows="3" v-model="property.contents"></textarea>
+            <textarea name="default-value" id="default-value" rows="3" v-model="property.contents" @blur="handleProperty('contents')"></textarea>
           </div>
           <div class="content-block">
             <div class="check-box" @click="property.isMultiLine = !property.isMultiLine">
@@ -257,35 +257,41 @@
   let isOneCheckbox = ref(true)
 
   const handleProperty = (key) => {
-    if (key === 'fieldName') {
-      useDocument.setPropertyPanel({ 'fieldName': property.fieldName })
-    }
-    if (key === 'title') {
-      useDocument.setPropertyPanel({ 'title': property.title })
-    }
-    if (key === 'destPage') {
-      const destPageValue = property.destPage
-      if (destPageValue !== '' && destPageValue != oldDestPage) {
-        useDocument.setPropertyPanel({
-          actionType: 1,
-          destPage: destPageValue.toString()
-        })
-        oldDestPage = destPageValue
-      }
-    } else if (key === 'url') {
-      let urlValue = property.url
-      if (urlValue !== '') {
-        if (!urlValue.startsWith('http://') && !urlValue.startsWith('https://')) {
-          urlValue = 'https://' + urlValue
+    switch (key) {
+      case 'fieldName':
+        useDocument.setPropertyPanel({ 'fieldName': property.fieldName })
+        break
+      case 'title':
+        useDocument.setPropertyPanel({ 'title': property.title })
+        break
+      case 'destPage':
+        const destPageValue = property.destPage
+        if (destPageValue !== '' && destPageValue != oldDestPage) {
+          useDocument.setPropertyPanel({
+            actionType: 1,
+            destPage: destPageValue.toString()
+          })
+          oldDestPage = destPageValue
         }
-        useDocument.setPropertyPanel({
-          url: urlValue,
-          actionType: 6
-        })
-        oldUrl = urlValue
-      } else {
-        property.url = oldUrl
-      }
+        break
+      case 'url':
+        let urlValue = property.url
+        if (urlValue !== '') {
+          if (!urlValue.startsWith('http://') && !urlValue.startsWith('https://')) {
+            urlValue = 'https://' + urlValue
+          }
+          useDocument.setPropertyPanel({
+            url: urlValue,
+            actionType: 6
+          })
+          oldUrl = urlValue
+        } else {
+          property.url = oldUrl
+        }
+        break
+      case 'contents':
+        useDocument.setPropertyPanel({ 'contents': property.contents })
+        break
     }
   }
 
@@ -323,14 +329,7 @@
   watch(() => property.textAlignment, (newValue, oldValue) => {
     useDocument.setPropertyPanel({'textAlignment': newValue})
   })
-  
-  watch(() => property.contents, (newValue, oldValue) => {
-    if (newValue === '') {
-      newValue = ' '
-    }
-    useDocument.setPropertyPanel({'contents': newValue})
-  })
-  
+
   watch(() => property.isMultiLine, (newValue, oldValue) => {
     useDocument.setPropertyPanel({'isMultiLine': newValue})
   })