36 lines
942 B
Vue
36 lines
942 B
Vue
<script setup>
|
|
import { nextTick, ref } from 'vue';
|
|
import VnInput from './VnInput.vue';
|
|
import { useAccountShortToStandard } from 'src/composables/useAccountShortToStandard';
|
|
|
|
const $props = defineProps({
|
|
insertable: {
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
});
|
|
|
|
const emit = defineEmits(['update:modelValue', 'accountShortToStandard']);
|
|
const model = defineModel({ prop: 'modelValue' });
|
|
const inputRef = ref(false);
|
|
|
|
function setCursorPosition(pos) {
|
|
const input = inputRef.value.vnInputRef.$el.querySelector('input');
|
|
input.focus();
|
|
input.setSelectionRange(pos, pos);
|
|
}
|
|
|
|
async function handleUpdateModel(val) {
|
|
model.value = val?.at(-1) === '.' ? useAccountShortToStandard(val) : val;
|
|
await nextTick(() => setCursorPosition(0));
|
|
}
|
|
</script>
|
|
<template>
|
|
<VnInput
|
|
v-model="model"
|
|
ref="inputRef"
|
|
:insertable
|
|
@update:model-value="handleUpdateModel"
|
|
/>
|
|
</template>
|