bug: 🐛 用户名校验
Some checks failed
Release / lint (push) Successful in 44s
Release / Release (push) Failing after 56s

This commit is contained in:
my_ong
2025-03-14 16:20:47 +08:00
parent 05ac02f58a
commit 2ffb3ae55c
6 changed files with 247 additions and 177 deletions

108
src/api/acl/api.d.ts vendored
View File

@@ -4,34 +4,34 @@ declare namespace acl {
*/
export interface Permission {
/** createdTime */
createdTime?: string;
createdTime?: string
/** 权限描述 */
description?: string;
description?: string
/** id */
id?: number;
id?: number
/** 权限key,英文 */
key?: string;
key?: string
/** 权限keyPath,用来做业务,(父级keyPath.key) */
keyPath?: string;
keyPath?: string
/** 权限名称,中文用来做标识 */
name?: string;
name?: string
/** 父权限key */
parentKey?: string;
parentKey?: string
/** 权限类型 */
type?: 'MENU' | 'BUTTON' | 'OTHER';
type?: 'MENU' | 'BUTTON' | 'OTHER'
/** typeInfo */
typeInfo?: acl.Codebook;
typeInfo?: acl.Codebook
/** updatedTime */
updatedTime?: string;
updatedTime?: string
}
/**
@@ -39,37 +39,37 @@ declare namespace acl {
*/
export interface PermissionInfo {
/** createdTime */
createdTime?: string;
createdTime?: string
/** 权限描述 */
description?: string;
description?: string
/** id */
id?: number;
id?: number
/** 权限key,英文 */
key?: string;
key?: string
/** 权限keyPath,用来做业务,(父级keyPath.key) */
keyPath?: string;
keyPath?: string
/** 权限名称,中文用来做标识 */
name?: string;
name?: string
/** 父权限key */
parentKey?: string;
parentKey?: string
/** 权限是否选中标识 */
selected: boolean;
selected: boolean
/** 权限类型 */
type?: 'MENU' | 'BUTTON' | 'OTHER';
type?: 'MENU' | 'BUTTON' | 'OTHER'
/** typeInfo */
typeInfo?: acl.Codebook;
typeInfo?: acl.Codebook
/** updatedTime */
updatedTime?: string;
updatedTime?: string
}
/**
@@ -77,22 +77,22 @@ declare namespace acl {
*/
export interface Role {
/** createdTime */
createdTime?: string;
createdTime?: string
/** 角色描述 */
description?: string;
description?: string
/** id */
id?: number;
id?: number
/** 角色key,英文,用来做业务 */
key: string;
key?: string
/** 角色名称,中文用来做标识 */
name?: string;
name?: string
/** updatedTime */
updatedTime?: string;
updatedTime?: string
}
/**
@@ -100,25 +100,25 @@ declare namespace acl {
*/
export interface RoleInfo {
/** createdTime */
createdTime?: string;
createdTime?: string
/** 角色描述 */
description?: string;
description?: string
/** id */
id?: number;
id?: number
/** 角色key,英文,用来做业务 */
key: string;
key?: string
/** 角色名称,中文用来做标识 */
name?: string;
name?: string
/** 角色是否选中标识 */
selected: boolean;
selected: boolean
/** updatedTime */
updatedTime?: string;
updatedTime?: string
}
/**
@@ -126,22 +126,22 @@ declare namespace acl {
*/
export interface TreeString {
/** 下级列表 */
children?: Array<acl.TreeString>;
children?: Array<acl.TreeString>
/** 描述 */
description?: string;
description?: string
/** ID */
key: string;
key: string
/** 名称 */
name: string;
name: string
/** originData */
originData: acl.TreeableString;
originData: acl.TreeableString
/** 父级 ID */
parentKey?: string;
parentKey?: string
}
/**
@@ -149,16 +149,16 @@ declare namespace acl {
*/
export interface TreeableString {
/** description */
description?: string;
description?: string
/** key */
key?: string;
key?: string
/** name */
name?: string;
name?: string
/** parentKey */
parentKey?: string;
parentKey?: string
}
/**
@@ -166,33 +166,33 @@ declare namespace acl {
*/
export interface User {
/** createdTime */
createdTime?: string;
createdTime?: string
/** 邮箱 */
email?: string;
email?: string
/** 真实姓名 */
fullName?: string;
fullName?: string
/** id */
id?: number;
id?: number
/** 手机号 */
mobile?: string;
mobile?: string
/** 用户名 */
name: string;
name: string
/** 密码 */
password?: string;
password?: string
/** 性别 */
sex?: 'MALE' | 'FEMALE';
sex?: 'MALE' | 'FEMALE'
/** sexInfo */
sexInfo?: acl.Codebook;
sexInfo?: acl.Codebook
/** updatedTime */
updatedTime?: string;
updatedTime?: string
}
}

View File

@@ -0,0 +1,26 @@
/**
* @desc 检查用户名是否存在,true存在,false不存在
*/
import { defaultSuccess, defaultError, http } from '@/plugins/axios'
import type { AxiosResponse } from 'axios'
export interface Params {
/** name */
name: string
}
export default async function (
params: Params,
success: (data: boolean) => void = defaultSuccess,
fail: (error: { code: string; error?: string }) => void = defaultError,
): Promise<void> {
return http({
method: 'get',
url: `/user/exist-name`,
params,
})
.then((data: AxiosResponse<boolean, unknown>) => {
success(data.data)
})
.catch((error: { code: string; error?: string }) => fail(error))
}

View File

@@ -2,22 +2,24 @@
* @description 用户
*
*/
import saveOrUpdateUser from './saveOrUpdateUser';
import all from './all';
import sexes from './sexes';
import detail from './detail';
import deleteUser from './deleteUser';
import resetPassword from './resetPassword';
import permissionInfos from './permissionInfos';
import permissions from './permissions';
import grant from './grant';
import roleInfos from './roleInfos';
import grantRole from './grantRole';
import users from './users';
import saveOrUpdateUser from './saveOrUpdateUser'
import all from './all'
import existName from './existName'
import sexes from './sexes'
import detail from './detail'
import deleteUser from './deleteUser'
import resetPassword from './resetPassword'
import permissionInfos from './permissionInfos'
import permissions from './permissions'
import grant from './grant'
import roleInfos from './roleInfos'
import grantRole from './grantRole'
import users from './users'
export default {
saveOrUpdateUser,
all,
existName,
sexes,
detail,
deleteUser,
@@ -28,4 +30,4 @@ export default {
roleInfos,
grantRole,
users,
};
}

View File

@@ -1210,6 +1210,37 @@
},
"parameters": []
},
{
"description": "检查用户名是否存在,true存在,false不存在",
"name": "existName",
"method": "get",
"path": "/user/exist-name",
"response": {
"typeArgs": [],
"typeName": "boolean",
"isDefsType": false,
"templateIndex": -1,
"compileTemplateKeyword": "#/definitions/",
"enum": [],
"typeProperties": []
},
"parameters": [
{
"required": true,
"in": "query",
"name": "name",
"dataType": {
"typeArgs": [],
"typeName": "string",
"isDefsType": false,
"templateIndex": -1,
"compileTemplateKeyword": "#/definitions/",
"enum": [],
"typeProperties": []
}
}
]
},
{
"description": "用户性别",
"name": "sexes",
@@ -2255,7 +2286,7 @@
},
"name": "key",
"description": "角色key,英文,用来做业务",
"required": true
"required": false
},
{
"dataType": {
@@ -2343,7 +2374,7 @@
},
"name": "key",
"description": "角色key,英文,用来做业务",
"required": true
"required": false
},
{
"dataType": {

View File

@@ -177,12 +177,10 @@
{
title: t('pages.acl.user.table.columns.sex'),
dataIndex: 'sex',
width: 75,
},
{
title: t('pages.acl.user.table.columns.operation'),
dataIndex: 'operation',
width: 400,
},
]

View File

@@ -5,6 +5,8 @@ const { t } = i18n.global
import { useAppStore } from '@/stores/app'
import { FormItem, FormConfig } from '@/components/form-render/form-render-types'
import { Rule } from 'ant-design-vue/es/form'
import api from '@/api'
export const config: FormConfig = {
layout: 'horizontal',
@@ -42,12 +44,8 @@ export const formItems = (sexes: Codebook[]): FormItem[] => {
},
rules: [
{
type: 'string',
required: true,
whitespace: true,
validator: validate,
trigger: ['blur', 'change'],
pattern: new RegExp('^(?=.*[A-Za-z])(?=.*\\d)[A-Za-z\\d]{8,}$'),
message: '8位数字字母组合',
},
],
},
@@ -161,3 +159,18 @@ export const formItems = (sexes: Codebook[]): FormItem[] => {
},
]
}
const validate = async (_rule: Rule, value: string) => {
const regex = /^[a-zA-Z0-9]{4,8}$/
if (!regex.test(value)) {
return Promise.reject('用户名只能是4-8位字母或数字')
} else {
api.aclApi.user.existName({ name: value }, (data) => {
if (data) {
return Promise.reject('用户名已经存在')
} else {
return Promise.resolve()
}
})
}
}