fix: the value is not updated after refreshing #90

This commit is contained in:
Lykin 2023-12-02 00:25:22 +08:00
parent ab8077999d
commit 988e8e3339
4 changed files with 25 additions and 21 deletions

View File

@ -77,25 +77,31 @@ const displayValue = computed(() => {
watch( watch(
() => props.value, () => props.value,
(val, oldVal) => { (val, oldVal) => {
if (val !== undefined && oldVal !== undefined) { if (val !== undefined) {
onFormatChanged(viewAs.decode, viewAs.format) onFormatChanged(viewAs.decode, viewAs.format)
} }
}, },
) )
const converting = ref(false)
const onFormatChanged = async (decode = '', format = '') => { const onFormatChanged = async (decode = '', format = '') => {
const { try {
value, converting.value = true
decode: retDecode, const {
format: retFormat, value,
} = await browserStore.convertValue({ decode: retDecode,
value: props.value, format: retFormat,
decode, } = await browserStore.convertValue({
format, value: props.value,
}) decode,
editingContent.value = viewAs.value = value format,
viewAs.decode = decode || retDecode })
viewAs.format = format || retFormat editingContent.value = viewAs.value = value
viewAs.decode = decode || retDecode
viewAs.format = format || retFormat
} finally {
converting.value = false
}
} }
/** /**
@ -152,9 +158,10 @@ const onSave = async () => {
defineExpose({ defineExpose({
reset: () => { reset: () => {
viewAs.value = '' viewAs.value = ''
viewAs.decode = ''
viewAs.format = ''
editingContent.value = '' editingContent.value = ''
}, },
beforeShow: () => onFormatChanged(),
}) })
</script> </script>
@ -195,9 +202,9 @@ defineExpose({
</n-button-group> </n-button-group>
</div> </div>
<div class="value-wrapper value-item-part flex-item-expand flex-box-v"> <div class="value-wrapper value-item-part flex-item-expand flex-box-v">
<n-spin :show="props.loading" /> <n-spin :show="props.loading || converting" />
<content-editor <content-editor
v-show="!props.loading" v-show="!(props.loading || converting)"
:content="displayValue" :content="displayValue"
:language="viewLanguage" :language="viewLanguage"
:loading="props.loading" :loading="props.loading"

View File

@ -156,9 +156,6 @@ const initContent = async () => {
contentRef.value?.reset() contentRef.value?.reset()
} }
await loadData(true, false, '') await loadData(true, false, '')
if (contentRef.value?.beforeShow != null) {
await contentRef.value?.beforeShow()
}
} finally { } finally {
initializing.value = false initializing.value = false
} }

View File

@ -269,7 +269,7 @@ onMounted(() => onReload())
size="20" size="20"
t-tooltip="interface.load_all" t-tooltip="interface.load_all"
@click="onLoadAll" /> @click="onLoadAll" />
<div class="flex-item-expand" /> <div class="flex-item-expand" style="min-width: 10px" />
<icon-button <icon-button
:button-class="['nav-pane-func-btn']" :button-class="['nav-pane-func-btn']"
:icon="Delete" :icon="Delete"

View File

@ -235,7 +235,7 @@ const useTabStore = defineStore('tab', {
tabData.value = assign(value, tabData.value || {}) tabData.value = assign(value, tabData.value || {})
} }
} else { } else {
tabData.value = value || [] tabData.value = value
} }
}, },