fix: 修复TelInput组件号码无法解析问题
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
<!-- https://github.com/jackocnr/intl-tel-input/blob/master/react/src/intl-tel-input/react.tsx -->
|
||||
<script lang="ts" setup>
|
||||
import intlTelInput, { Iti, SomeOptions } from 'intl-tel-input';
|
||||
import { Iti } from 'intl-tel-input';
|
||||
import intlTelInput from 'intl-tel-input/intlTelInputWithUtils';
|
||||
import 'intl-tel-input/build/css/intlTelInput.min.css';
|
||||
import 'intl-tel-input/build/js/utils.js';
|
||||
import { ref, onMounted, onBeforeUnmount, nextTick, watch } from 'vue';
|
||||
import { ref, onMounted, onBeforeUnmount, nextTick } from 'vue';
|
||||
import useI18n from '@/hooks/useI18n';
|
||||
const { currentLocale } = useI18n();
|
||||
const emit = defineEmits(['update:value', 'update:change']);
|
||||
@@ -45,13 +45,13 @@ const itiRef = ref<Iti | null>(null);
|
||||
function fnChange() {
|
||||
if (!itiRef.value) return;
|
||||
|
||||
const num = itiRef.value?.getNumber() || '';
|
||||
const number = itiRef.value?.getNumber() || '';
|
||||
const countryIso = itiRef.value?.getSelectedCountryData().iso2 || '';
|
||||
// note: this number will be in standard E164 format, but any container component can use
|
||||
// intlTelInputUtils.formatNumber() to convert this to another format
|
||||
// as well as intlTelInputUtils.getNumberType() etc. if need be
|
||||
let data = {
|
||||
num,
|
||||
number,
|
||||
countryIso,
|
||||
validity: false,
|
||||
errorCode: -1,
|
||||
@@ -69,21 +69,11 @@ function fnChange() {
|
||||
data.errorCode = errorCode;
|
||||
}
|
||||
// console.log(data);
|
||||
emit('update:value', num);
|
||||
|
||||
emit('update:value', number);
|
||||
emit('update:change', data);
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.value,
|
||||
v => {
|
||||
if (v) {
|
||||
itiRef.value?.setNumber(v);
|
||||
} else {
|
||||
itiRef.value?.setNumber('');
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
onMounted(() => {
|
||||
nextTick(async () => {
|
||||
if (inputRef.value) {
|
||||
@@ -106,7 +96,13 @@ onMounted(() => {
|
||||
formatOnDisplay: true,
|
||||
autoPlaceholder: 'polite',
|
||||
i18n: i18n,
|
||||
} as SomeOptions);
|
||||
});
|
||||
if (props.value) {
|
||||
itiRef.value.setNumber(props.value);
|
||||
}
|
||||
if (props.disabled) {
|
||||
itiRef.value.setDisabled(props.disabled);
|
||||
}
|
||||
inputRef.value.addEventListener('countrychange', fnChange);
|
||||
}
|
||||
});
|
||||
@@ -124,8 +120,7 @@ onBeforeUnmount(() => {
|
||||
<input
|
||||
type="tel"
|
||||
class="ant-input"
|
||||
ref="inputRef"
|
||||
:value="value"
|
||||
ref="inputRef"
|
||||
:disabled="disabled"
|
||||
:placeholder="placeholder"
|
||||
:maxlength="maxlength"
|
||||
|
||||
5
src/typings/vite-env.d.ts
vendored
5
src/typings/vite-env.d.ts
vendored
@@ -8,3 +8,8 @@ declare module '*.vue' {
|
||||
}
|
||||
|
||||
declare module 'vue3-smooth-dnd';
|
||||
|
||||
declare module 'intl-tel-input/intlTelInputWithUtils' {
|
||||
import intlTelInput from 'intl-tel-input';
|
||||
export default intlTelInput;
|
||||
}
|
||||
|
||||
@@ -169,7 +169,7 @@ onMounted(() => {
|
||||
<IntlTelInput
|
||||
v-model:value="stateForm.form.phonenumber"
|
||||
allow-clear
|
||||
:maxlength="16"
|
||||
:maxlength="20"
|
||||
:placeholder="t('views.account.settings.phonenumberPleace')"
|
||||
></IntlTelInput>
|
||||
</a-form-item>
|
||||
|
||||
@@ -1367,7 +1367,7 @@ onMounted(() => {
|
||||
<IntlTelInput
|
||||
v-model:value="modalState.from.phonenumber"
|
||||
allow-clear
|
||||
:maxlength="16"
|
||||
:maxlength="20"
|
||||
:placeholder="t('common.inputPlease')"
|
||||
></IntlTelInput>
|
||||
</a-form-item>
|
||||
|
||||
Reference in New Issue
Block a user