From 323957db94e01be6150b9b49b8d6ccf56a2a71c1 Mon Sep 17 00:00:00 2001 From: ThrRip Date: Tue, 28 Nov 2023 20:04:53 +0800 Subject: [PATCH] admin: Improve code readability and add "Tab to next field" --- packages/admin/components/PlaylistList.vue | 90 ++++++++++++++-------- 1 file changed, 56 insertions(+), 34 deletions(-) diff --git a/packages/admin/components/PlaylistList.vue b/packages/admin/components/PlaylistList.vue index 8dd188c..be2d76d 100644 --- a/packages/admin/components/PlaylistList.vue +++ b/packages/admin/components/PlaylistList.vue @@ -236,7 +236,7 @@ :enter-active-class="props.type === 'main' ? 'transition-opacity' : ''" :leave-active-class="props.type === 'main' ? 'transition-opacity delay-75' : ''" :leave-to-class="props.type === 'main' ? 'opacity-0' : ''" - @click="modifyingTarget.id = song.$id; modifyingTarget.field = 'name'; modifying = true" + @click="modifyStart({ id: song.$id, field: 'name' })" > >(new Set()) -const modifying = ref(false) +interface ModifyTarget { + id: Song['$id'] + field: 'name' | 'artist' | 'payment_amount' | 'language' +} const modifyingTarget = ref<{ - id: Song['$id'] | null - field: 'name' | 'artist' | 'payment_amount' | 'language' | null + // eslint-disable-next-line no-use-before-define + [P in keyof ModifyTarget]: ModifyTarget[P] | null }>({ id: null, field: null }) const modifyingInput = ref>() -watch(modifying, (value) => { - value ? - nextTick(() => modifyingInput.value?.[0]?.focus()) : - nextTick(() => modifyingInput.value?.[0]?.blur()) -}) + +function modifyStart (target: ModifyTarget) { + modifyingTarget.value.id = target.id + modifyingTarget.value.field = target.field + nextTick(() => modifyingInput.value?.[0]?.focus()) +} +function modifyFinish (changes: Song) { + modifyingTarget.value.id = null + modifyingTarget.value.field = null + emit('stageChanges', changes) +} +function modifyNext (currentTarget: ModifyTarget) { + const fields: Array = ['name', 'artist', 'payment_amount', 'language'] + modifyingInput.value?.[0]?.blur() + modifyingTarget.value.id = currentTarget.id + modifyingTarget.value.field = fields[fields.findIndex(field => field === currentTarget.field) + 1] + nextTick(() => modifyingInput.value?.[0]?.focus()) +} function create () { const id = crypto.randomUUID() @@ -510,6 +532,6 @@ function create () { setTimeout(() => scrollList('bottom'), 50) modifyingTarget.value.id = id modifyingTarget.value.field = 'name' - setTimeout(() => { modifying.value = true }, 2000) + setTimeout(() => modifyingInput.value?.[0]?.focus(), 2000) }