From 04d741025f567b15d8fe111dd00fdd1024a694e6 Mon Sep 17 00:00:00 2001 From: siontion Date: Tue, 14 May 2024 14:07:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=94=A8=E6=88=B7=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/gw/login/index.ts | 4 +++ src/stores/user.ts | 12 ++++++- src/views/Gw/user/UserForm.vue | 65 +++++++++++++++++++++------------- 3 files changed, 56 insertions(+), 25 deletions(-) diff --git a/src/api/gw/login/index.ts b/src/api/gw/login/index.ts index e98d3bc..1bf2a44 100644 --- a/src/api/gw/login/index.ts +++ b/src/api/gw/login/index.ts @@ -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}) +} diff --git a/src/stores/user.ts b/src/stores/user.ts index d3bd6d4..433811a 100644 --- a/src/stores/user.ts +++ b/src/stores/user.ts @@ -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} }) diff --git a/src/views/Gw/user/UserForm.vue b/src/views/Gw/user/UserForm.vue index 784ec17..86a9317 100644 --- a/src/views/Gw/user/UserForm.vue +++ b/src/views/Gw/user/UserForm.vue @@ -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,31 +125,40 @@ const open = async (type: string, row?: any) => { const fnSubmitA = async () => { await refFormA.value.validate().then(async (res: any) => { if(!res){ - switch (active.value) { - case 'add': - const paramsA = { - data: formDataA.value - } - await comApi.saveUser(paramsA) - VXETable.modal.message({ content: '新增成功', status: 'success' }) - break; - case 'edit': - let setVal: any = _map(formDataA.value, (o1, k1) => { - return { field: k1, value: o1 } - }) - const paramsB = { - filter: { - field: 'ID', - value: formDataA.value.ID - }, - set: setVal - } - await comApi.editUser(paramsB) - VXETable.modal.message({ content: '修改成功', status: 'success' }) - break; + + 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 = { + data: formDataA.value + } + await comApi.saveUser(paramsA) + VXETable.modal.message({ content: '新增成功', status: 'success' }) + break; + case 'edit': + let setVal: any = _map(formDataA.value, (o1, k1) => { + return { field: k1, value: o1 } + }) + const paramsB = { + filter: { + field: 'ID', + value: formDataA.value.ID + }, + set: setVal + } + await comApi.editUser(paramsB) + VXETable.modal.message({ content: '修改成功', status: 'success' }) + break; + } + refShow.value = false + emit('success') } - refShow.value = false - emit('success') + + } }) }