From 0064b110d91ae36aeeb1220af5ecf4b140b93663 Mon Sep 17 00:00:00 2001 From: greenhat616 Date: Sun, 10 Sep 2023 12:57:37 +0800 Subject: [PATCH] feat: store state in swift modify --- components/do/review/Card.vue | 15 +++++++++--- components/do/review/CardActionsContainer.vue | 17 ++++++++++++-- utils/converter.ts | 23 +++++++++++++++++++ 3 files changed, 50 insertions(+), 5 deletions(-) diff --git a/components/do/review/Card.vue b/components/do/review/Card.vue index b99191e..0d87283 100644 --- a/components/do/review/Card.vue +++ b/components/do/review/Card.vue @@ -66,6 +66,17 @@ const userStore = useUserStore() const marksSelectedValues = ref([]) provide('sentence', props.sentence) // 提供句子数据给子组件 +// 快捷修改 +const doSwiftModify = ( + fn: (sentence: Sentence) => void, + initialState: Partial +) => { + emit( + 'doSwiftModify', + { ...(props.sentence as Sentence), ...initialState }, + fn + ) +} diff --git a/components/do/review/CardActionsContainer.vue b/components/do/review/CardActionsContainer.vue index b65ee91..8c011ee 100644 --- a/components/do/review/CardActionsContainer.vue +++ b/components/do/review/CardActionsContainer.vue @@ -16,7 +16,10 @@ const emit = defineEmits<{ doWebSearch: [] doLocalSearch: [] viewComments: [] - doSwiftModify: [onModifyFinished: (sentence: Sentence) => void] + doSwiftModify: [ + onModifyFinished: (sentence: Sentence) => void, + currentState: Partial + ] operationDone: [event: 'submit' | 'cancel'] }>() @@ -105,6 +108,16 @@ const onSwiftModify = (camel: Sentence) => { if (Object.keys(snake).length === 0) return comment.value = JSON.stringify(snake) } +const doSwiftModify = () => { + try { + const initialState = objToCamel>( + JSON.parse(comment.value || '{}') as Record + ) + emit('doSwiftModify', onSwiftModify, initialState) + } catch (e) { + emit('doSwiftModify', onSwiftModify, {} as Partial) + } +}