添加用户重复验证

main
siontion 5 months ago
parent 526a302199
commit 04d741025f

@ -25,3 +25,7 @@ export const getUserChk: any = async (data: any) => {
})
return rt
}
export const isExistUserName = async (data:any) => {
return await request.post({ url: `/DistributionBoxTesting/IsExistsUser?id=`+data.id+"&name="+data.name})
}

@ -46,5 +46,15 @@ export const useUserStore: any = defineStore('user', () => {
wsCache.set(CACHE_KEY.userInfo, { UserName: UserName.value, isLogin: isLogin.value })
router.push({ name: 'login' })
}
return { UserName, isLogin, fnLogin, fnLoginOut }
async function fnIsExistUser(data:any){
const isExist: any = await LoginApi.isExistUserName({
id: data.id,
name: data.name
})
return isExist
}
return { UserName, isLogin, fnLogin, fnLoginOut ,fnIsExistUser}
})

@ -48,6 +48,10 @@ import { map as _map } from 'lodash'
import { VXETable } from 'vxe-table'
import * as comApi from '@/api/gw/com'
import { useUserStore } from '../../../stores/user'
const userStore = useUserStore()
const { fnLogin,fnIsExistUser } = userStore
// [success]
const emit = defineEmits(['success'])
//
@ -95,6 +99,9 @@ const open = async (type: string, row?: any) => {
case 'add':
refShow.value = true
modalTitle.value = '添加用户'
formDataA.value.Id = 0
formDataA.value.UserName=''
formDataA.value.Password=''
break;
case 'edit':
refShow.value = true
@ -109,6 +116,7 @@ const open = async (type: string, row?: any) => {
const rowInfoA = await comApi.getUser(paramsA)
console.log(rowInfoA)
formDataA.value = rowInfoA.Data
formDataA.value.Id = rowInfoA.Data.ID
formDataA.value.Password=''
break;
}
@ -117,6 +125,12 @@ const open = async (type: string, row?: any) => {
const fnSubmitA = async () => {
await refFormA.value.validate().then(async (res: any) => {
if(!res){
const rt = await fnIsExistUser({ name: formDataA.value.UserName, id: formDataA.value.Id })
if (rt) {
VXETable.modal.alert({ content: '用户名已存在'})
return
}else{
switch (active.value) {
case 'add':
const paramsA = {
@ -143,6 +157,9 @@ const fnSubmitA = async () => {
refShow.value = false
emit('success')
}
}
})
}

Loading…
Cancel
Save