perf: view type automatic synchronization between edit and list for complex type

This commit is contained in:
Lykin 2024-03-26 17:33:30 +08:00
parent 668620425f
commit d1958a3290
5 changed files with 44 additions and 19 deletions

View File

@ -12,9 +12,10 @@ import WindowClose from '@/components/icons/WindowClose.vue'
import Pin from '@/components/icons/Pin.vue' import Pin from '@/components/icons/Pin.vue'
import OffScreen from '@/components/icons/OffScreen.vue' import OffScreen from '@/components/icons/OffScreen.vue'
import ContentEditor from '@/components/content_value/ContentEditor.vue' import ContentEditor from '@/components/content_value/ContentEditor.vue'
import { toString } from 'lodash' import { isEmpty, toString } from 'lodash'
const props = defineProps({ const props = defineProps({
keyPath: String,
show: { show: {
type: Boolean, type: Boolean,
}, },
@ -58,8 +59,8 @@ const emit = defineEmits([
watchEffect( watchEffect(
() => { () => {
if (props.show && props.value != null) { if (props.show && !isEmpty(props.keyPath)) {
onFormatChanged() onFormatChanged(props.decode, props.format)
} else { } else {
viewAs.value = '' viewAs.value = ''
} }
@ -127,6 +128,8 @@ const onFormatChanged = async (decode = null, format = null) => {
editingContent.value = viewAs.value = value editingContent.value = viewAs.value = value
viewAs.decode = decode || retDecode viewAs.decode = decode || retDecode
viewAs.format = format || retFormat viewAs.format = format || retFormat
emit('update:decode', viewAs.decode)
emit('update:format', viewAs.format)
} finally { } finally {
loading.value = false loading.value = false
} }

View File

@ -1,5 +1,5 @@
<script setup> <script setup>
import { computed, h, reactive, ref } from 'vue' import { computed, h, nextTick, reactive, ref } from 'vue'
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
import AddLink from '@/components/icons/AddLink.vue' import AddLink from '@/components/icons/AddLink.vue'
import { NButton, NIcon, useThemeVars } from 'naive-ui' import { NButton, NIcon, useThemeVars } from 'naive-ui'
@ -142,6 +142,8 @@ const startEdit = async (no, key, value) => {
currentEditRow.no = no currentEditRow.no = no
currentEditRow.key = key currentEditRow.key = key
currentEditRow.value = value currentEditRow.value = value
currentEditRow.decode = props.decode
currentEditRow.format = props.format
} }
const saveEdit = async (field, value, decode, format) => { const saveEdit = async (field, value, decode, format) => {
@ -183,8 +185,11 @@ const resetEdit = () => {
currentEditRow.no = 0 currentEditRow.no = 0
currentEditRow.key = '' currentEditRow.key = ''
currentEditRow.value = null currentEditRow.value = null
currentEditRow.format = formatTypes.RAW if (currentEditRow.format !== props.format || currentEditRow.decode !== props.decode) {
currentEditRow.decode = decodeTypes.NONE nextTick(() => onFormatChanged(currentEditRow.decode, currentEditRow.format))
}
// currentEditRow.format = formatTypes.RAW
// currentEditRow.decode = decodeTypes.NONE
} }
const actionColumn = { const actionColumn = {
@ -397,11 +402,12 @@ defineExpose({
class="entry-editor-container flex-item-expand" class="entry-editor-container flex-item-expand"
style="width: 100%"> style="width: 100%">
<content-entry-editor <content-entry-editor
v-model:decode="currentEditRow.decode"
v-model:format="currentEditRow.format"
v-model:fullscreen="fullEdit" v-model:fullscreen="fullEdit"
:decode="currentEditRow.decode"
:field="currentEditRow.key" :field="currentEditRow.key"
:field-label="$t('common.field')" :field-label="$t('common.field')"
:format="currentEditRow.format" :key-path="props.keyPath"
:show="inEdit" :show="inEdit"
:value="currentEditRow.value" :value="currentEditRow.value"
:value-label="$t('common.value')" :value-label="$t('common.value')"

View File

@ -1,5 +1,5 @@
<script setup> <script setup>
import { computed, h, reactive, ref } from 'vue' import { computed, h, nextTick, reactive, ref } from 'vue'
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
import AddLink from '@/components/icons/AddLink.vue' import AddLink from '@/components/icons/AddLink.vue'
import { NButton, NIcon, useThemeVars } from 'naive-ui' import { NButton, NIcon, useThemeVars } from 'naive-ui'
@ -116,6 +116,8 @@ const valueColumn = computed(() => ({
const startEdit = async (no, value) => { const startEdit = async (no, value) => {
currentEditRow.no = no currentEditRow.no = no
currentEditRow.value = value currentEditRow.value = value
currentEditRow.decode = props.decode
currentEditRow.format = props.format
} }
/** /**
@ -160,6 +162,9 @@ const saveEdit = async (pos, value, decode, format) => {
const resetEdit = () => { const resetEdit = () => {
currentEditRow.no = 0 currentEditRow.no = 0
currentEditRow.value = null currentEditRow.value = null
if (currentEditRow.format !== props.format || currentEditRow.decode !== props.decode) {
nextTick(() => onFormatChanged(currentEditRow.decode, currentEditRow.format))
}
} }
const actionColumn = { const actionColumn = {
@ -370,12 +375,13 @@ defineExpose({
class="entry-editor-container flex-item-expand" class="entry-editor-container flex-item-expand"
style="width: 100%"> style="width: 100%">
<content-entry-editor <content-entry-editor
v-model:decode="currentEditRow.decode"
v-model:format="currentEditRow.format"
v-model:fullscreen="fullEdit" v-model:fullscreen="fullEdit"
:decode="currentEditRow.decode"
:field="currentEditRow.no" :field="currentEditRow.no"
:field-label="$t('common.index')" :field-label="$t('common.index')"
:field-readonly="true" :field-readonly="true"
:format="currentEditRow.format" :key-path="props.keyPath"
:show="inEdit" :show="inEdit"
:value="currentEditRow.value" :value="currentEditRow.value"
:value-label="$t('common.value')" :value-label="$t('common.value')"

View File

@ -1,5 +1,5 @@
<script setup> <script setup>
import { computed, h, reactive, ref } from 'vue' import { computed, h, nextTick, reactive, ref } from 'vue'
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
import AddLink from '@/components/icons/AddLink.vue' import AddLink from '@/components/icons/AddLink.vue'
import { NButton, NIcon, useThemeVars } from 'naive-ui' import { NButton, NIcon, useThemeVars } from 'naive-ui'
@ -115,6 +115,8 @@ const valueColumn = computed(() => ({
const startEdit = async (no, value) => { const startEdit = async (no, value) => {
currentEditRow.no = no currentEditRow.no = no
currentEditRow.value = value currentEditRow.value = value
currentEditRow.decode = props.decode
currentEditRow.format = props.format
} }
/** /**
@ -157,6 +159,9 @@ const saveEdit = async (pos, value, decode, format) => {
const resetEdit = () => { const resetEdit = () => {
currentEditRow.no = 0 currentEditRow.no = 0
currentEditRow.value = null currentEditRow.value = null
if (currentEditRow.format !== props.format || currentEditRow.decode !== props.decode) {
nextTick(() => onFormatChanged(currentEditRow.decode, currentEditRow.format))
}
} }
const actionColumn = { const actionColumn = {
@ -367,12 +372,13 @@ defineExpose({
class="entry-editor-container flex-item-expand" class="entry-editor-container flex-item-expand"
style="width: 100%"> style="width: 100%">
<content-entry-editor <content-entry-editor
v-model:decode="currentEditRow.decode"
v-model:format="currentEditRow.format"
v-model:fullscreen="fullEdit" v-model:fullscreen="fullEdit"
:decode="currentEditRow.decode"
:field="currentEditRow.no" :field="currentEditRow.no"
:field-label="$t('common.index')" :field-label="$t('common.index')"
:field-readonly="true" :field-readonly="true"
:format="currentEditRow.format" :key-path="props.keyPath"
:show="inEdit" :show="inEdit"
:value="currentEditRow.value" :value="currentEditRow.value"
:value-label="$t('common.value')" :value-label="$t('common.value')"

View File

@ -1,5 +1,5 @@
<script setup> <script setup>
import { computed, h, reactive, ref } from 'vue' import { computed, h, nextTick, reactive, ref } from 'vue'
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
import AddLink from '@/components/icons/AddLink.vue' import AddLink from '@/components/icons/AddLink.vue'
import { NButton, NIcon, useThemeVars } from 'naive-ui' import { NButton, NIcon, useThemeVars } from 'naive-ui'
@ -166,6 +166,8 @@ const startEdit = async (no, score, value) => {
currentEditRow.no = no currentEditRow.no = no
currentEditRow.score = score currentEditRow.score = score
currentEditRow.value = value currentEditRow.value = value
currentEditRow.decode = props.decode
currentEditRow.format = props.format
} }
const saveEdit = async (field, value, decode, format) => { const saveEdit = async (field, value, decode, format) => {
@ -204,8 +206,9 @@ const resetEdit = () => {
currentEditRow.no = 0 currentEditRow.no = 0
currentEditRow.score = 0 currentEditRow.score = 0
currentEditRow.value = null currentEditRow.value = null
currentEditRow.format = formatTypes.RAW if (currentEditRow.format !== props.format || currentEditRow.decode !== props.decode) {
currentEditRow.decode = decodeTypes.NONE nextTick(() => onFormatChanged(currentEditRow.decode, currentEditRow.format))
}
} }
const actionColumn = { const actionColumn = {
@ -403,11 +406,12 @@ defineExpose({
class="entry-editor-container flex-item-expand" class="entry-editor-container flex-item-expand"
style="width: 100%"> style="width: 100%">
<content-entry-editor <content-entry-editor
v-model:decode="currentEditRow.decode"
v-model:format="currentEditRow.format"
v-model:fullscreen="fullEdit" v-model:fullscreen="fullEdit"
:decode="currentEditRow.decode"
:field="currentEditRow.score" :field="currentEditRow.score"
:field-label="$t('common.score')" :field-label="$t('common.score')"
:format="currentEditRow.format" :key-path="props.keyPath"
:show="inEdit" :show="inEdit"
:value="currentEditRow.value" :value="currentEditRow.value"
:value-label="$t('common.value')" :value-label="$t('common.value')"