From 26622039ac37ecf5336d4a954edd539346880cf6 Mon Sep 17 00:00:00 2001 From: ZvonimirSun Date: Sat, 23 Dec 2023 22:52:22 +0800 Subject: [PATCH] =?UTF-8?q?feat(cssFormatter):=20=E6=94=B9=E7=94=A8FormatT?= =?UTF-8?q?ransformer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/FormatTransformer.vue | 29 +++++++++++++++++++++------- src/views/cssFormatter.vue | 5 +++-- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/components/FormatTransformer.vue b/src/components/FormatTransformer.vue index 2837271f2..b5a885f0a 100644 --- a/src/components/FormatTransformer.vue +++ b/src/components/FormatTransformer.vue @@ -8,6 +8,7 @@ import type { Ref } from 'vue' const props = withDefaults( defineProps<{ plugin: EditorPlugin, + target?: string inputLabel?: string inputDefault?: string inputPlaceholder?: string, @@ -16,6 +17,7 @@ const props = withDefaults( options?: Record }>(), { + target: '', inputLabel: '输入', inputDefault: '', inputPlaceholder: '输入...', @@ -25,8 +27,21 @@ const props = withDefaults( } ) -const { plugin, inputLabel, inputDefault, inputPlaceholder, invalidMessage, outputLabel, options } = toRefs(props) +const { plugin, inputDefault } = toRefs(props) +const { _inputLabel, _inputPlaceholder, _invalidMessage, _outputLabel } = props.target + ? { + _inputLabel: '你的' + props.target + '内容', + _inputPlaceholder: '在这里粘贴' + props.target + '内容...', + _invalidMessage: '请输入正确的' + props.target + '内容', + _outputLabel: '格式化后的' + props.target + '内容' + } + : { + _inputLabel: props.inputLabel, + _inputPlaceholder: props.inputPlaceholder, + _invalidMessage: props.invalidMessage, + _outputLabel: props.outputLabel + } const emits = defineEmits<{(e: 'format', data: string): void}>() const editor = ref>() as Ref> @@ -41,9 +56,9 @@ const valid = computed(() => isValid(form.input)) watch(inputDefault, (val) => { form.input = val }) -watch([valid, options, editor], () => { +watch([valid, () => props.options, editor], () => { if (valid.value) { - editor.value?.setInput(formatter(form.input, options.value)) + editor.value?.setInput(formatter(form.input, props.options)) } else { editor.value?.setInput('') } @@ -55,7 +70,7 @@ const rules = reactive>({ input: [{ validator: (rule: unknown, val: string, callback: any) => { if (!valid.value) { - callback(new Error(invalidMessage.value)) + callback(new Error(_invalidMessage)) } else { callback() } @@ -73,18 +88,18 @@ const rules = reactive>({ :rules="rules" > -