-- 项目名称校验

This commit is contained in:
yuping
2022-12-10 21:00:42 +08:00
parent 0a8e7c3651
commit f74c68fc25
6 changed files with 1031 additions and 814 deletions

View File

@@ -0,0 +1,58 @@
<template>
<a-input
v-model:value="modelV"
placeholder="请输入项目名称"
:show-count="showCount"
:maxlength="maxlength"
@blur="validateProName"
/>
<div style="color:red;font-size: 10px" v-if="value && !validate">名称重复请重新输入</div>
</template>
<script setup>
import {defineProps, defineEmits, watch, ref} from "vue";
import {validateName} from "@/api/index1";
const props = defineProps({
value: {
type: String,
},
validate: {
type: Boolean,
default: true
},
type: {
type: Number,
default: 1
},
maxlength: {
type: Number,
default: 30
},
showCount: {
type: Boolean,
default: false
}
})
const emit = defineEmits({})
const modelV = ref()
watch(() => props.value, () => {
if (props.value !== modelV.value) {
modelV.value = props.value
}
})
watch(modelV, () => {
emit('update:value', modelV.value)
})
function validateProName() {
console.log(props.value)
props.value && validateName({name: props.value, type: props.type}).then(res => {
emit('update:validate', res.data.data !== 1)
})
}
</script>