From 8b4b767f4ca78f7c6f7586d8ba662552c2b7bb51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=97=A0=E6=9C=A8?= Date: Wed, 21 Jul 2021 15:43:25 +0800 Subject: [PATCH] feat(demo): add `async-validator` demo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加表单使用后端接口异步验证的例子 --- mock/demo/system.ts | 15 ++++++++- src/api/demo/system.ts | 4 +++ src/views/demo/form/RuleForm.vue | 33 +++++++++++++++++-- src/views/demo/system/account/account.data.ts | 21 ++++++++++-- 4 files changed, 67 insertions(+), 6 deletions(-) diff --git a/mock/demo/system.ts b/mock/demo/system.ts index 9cde354c9c5..e24f50cb28f 100644 --- a/mock/demo/system.ts +++ b/mock/demo/system.ts @@ -1,5 +1,5 @@ import { MockMethod } from 'vite-plugin-mock'; -import { resultPageSuccess, resultSuccess } from '../_util'; +import { resultError, resultPageSuccess, resultSuccess } from '../_util'; const accountList = (() => { const result: any[] = []; @@ -185,4 +185,17 @@ export default [ return resultSuccess(menuList); }, }, + { + url: '/basic-api/system/accountExist', + timeout: 500, + method: 'post', + response: ({ body }) => { + const { account } = body || {}; + if (account && account.indexOf('admin') !== -1) { + return resultError('该字段不能包含admin'); + } else { + return resultSuccess(`${account} can use`); + } + }, + }, ] as MockMethod[]; diff --git a/src/api/demo/system.ts b/src/api/demo/system.ts index 69f1ac09b31..f5c296b5da7 100644 --- a/src/api/demo/system.ts +++ b/src/api/demo/system.ts @@ -14,6 +14,7 @@ import { defHttp } from '/@/utils/http/axios'; enum Api { AccountList = '/system/getAccountList', + IsAccountExist = '/system/accountExist', DeptList = '/system/getDeptList', setRoleStatus = '/system/setRoleStatus', MenuList = '/system/getMenuList', @@ -38,3 +39,6 @@ export const getAllRoleList = (params?: RoleParams) => export const setRoleStatus = (id: number, status: string) => defHttp.post({ url: Api.setRoleStatus, params: { id, status } }); + +export const isAccountExist = (account: string) => + defHttp.post({ url: Api.IsAccountExist, params: { account } }, { errorMessageMode: 'none' }); diff --git a/src/views/demo/form/RuleForm.vue b/src/views/demo/form/RuleForm.vue index 6af3232c768..8124dae7539 100644 --- a/src/views/demo/form/RuleForm.vue +++ b/src/views/demo/form/RuleForm.vue @@ -15,9 +15,10 @@