mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-04-06 03:57:56 +08:00
feat: 输入文本含有空格时,弹窗提示
This commit is contained in:
parent
3c167f3b54
commit
ab5e31dfea
@ -1,4 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
|
<TMagicPopover :visible="popoverVisible" width="220px">
|
||||||
|
<template #reference>
|
||||||
<TMagicInput
|
<TMagicInput
|
||||||
v-model="model[name]"
|
v-model="model[name]"
|
||||||
clearable
|
clearable
|
||||||
@ -21,12 +23,22 @@
|
|||||||
</TMagicButton>
|
</TMagicButton>
|
||||||
</template>
|
</template>
|
||||||
</TMagicInput>
|
</TMagicInput>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<div class="m-form-item__content">
|
||||||
|
<div class="m-form-validate__warning">输入内容前后有空格,是否移除空格?</div>
|
||||||
|
<div style="display: flex; justify-content: flex-end">
|
||||||
|
<TMagicButton type="text" size="small" @click="popoverVisible = false">保持原样</TMagicButton>
|
||||||
|
<TMagicButton type="primary" size="small" @click="confirmTrimHandler">移除空格</TMagicButton>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</TMagicPopover>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { inject } from 'vue';
|
import { inject, ref } from 'vue';
|
||||||
|
|
||||||
import { TMagicButton, TMagicInput } from '@tmagic/design';
|
import { TMagicButton, TMagicInput, TMagicPopover } from '@tmagic/design';
|
||||||
import { isNumber } from '@tmagic/utils';
|
import { isNumber } from '@tmagic/utils';
|
||||||
|
|
||||||
import type { FieldProps, FormState, TextConfig } from '../schema';
|
import type { FieldProps, FormState, TextConfig } from '../schema';
|
||||||
@ -47,11 +59,25 @@ useAddField(props.prop);
|
|||||||
|
|
||||||
const mForm = inject<FormState | undefined>('mForm');
|
const mForm = inject<FormState | undefined>('mForm');
|
||||||
|
|
||||||
|
const popoverVisible = ref(false);
|
||||||
|
|
||||||
|
const confirmTrimHandler = () => {
|
||||||
|
emit('change', props.model[props.name].trim() || '');
|
||||||
|
popoverVisible.value = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
const checkWhiteSpace = (value: unknown) => {
|
||||||
|
if (typeof value === 'string' && !props.config.trim) {
|
||||||
|
popoverVisible.value = value.trim() !== value;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const changeHandler = (value: string) => {
|
const changeHandler = (value: string) => {
|
||||||
emit('change', value);
|
emit('change', value);
|
||||||
};
|
};
|
||||||
|
|
||||||
const inputHandler = (v: string) => {
|
const inputHandler = (v: string) => {
|
||||||
|
checkWhiteSpace(v);
|
||||||
emit('input', v);
|
emit('input', v);
|
||||||
mForm?.$emit('field-input', props.prop, v);
|
mForm?.$emit('field-input', props.prop, v);
|
||||||
};
|
};
|
||||||
@ -124,3 +150,11 @@ const keyUpHandler = ($event: KeyboardEvent) => {
|
|||||||
emit('change', props.model[props.name]);
|
emit('change', props.model[props.name]);
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.m-form-validate__warning {
|
||||||
|
color: var(--el-color-warning);
|
||||||
|
font-size: 12px;
|
||||||
|
width: 100%;
|
||||||
|
line-height: 1.4;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user