wip: coding
parent
cf738b8701
commit
f4c940d95e
@ -0,0 +1,7 @@
|
|||||||
|
export interface IUserModel {
|
||||||
|
user_name: string
|
||||||
|
password: string
|
||||||
|
check_password: string
|
||||||
|
is_admin: number
|
||||||
|
code: string | number
|
||||||
|
}
|
||||||
@ -0,0 +1,12 @@
|
|||||||
|
import { useAxios } from '@/hooks/web/useAxios'
|
||||||
|
import { IUserModel } from '@/api-types/user'
|
||||||
|
|
||||||
|
const request = useAxios()
|
||||||
|
|
||||||
|
export const getCodeApi = () => {
|
||||||
|
return request.get<IResponse<string>>({ url: 'user/captcha' })
|
||||||
|
}
|
||||||
|
|
||||||
|
export const registerApi = (data: Omit<IUserModel, 'is_admin'>) => {
|
||||||
|
return request.post<IResponse<IUserModel>>({ url: 'user/register', data })
|
||||||
|
}
|
||||||
@ -0,0 +1,60 @@
|
|||||||
|
type Callback = (error?: string | Error | undefined) => void
|
||||||
|
|
||||||
|
interface LengthRange {
|
||||||
|
min: number
|
||||||
|
max: number
|
||||||
|
message: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useValidator = () => {
|
||||||
|
const required = (message: string) => {
|
||||||
|
return {
|
||||||
|
required: true,
|
||||||
|
message
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const lengthRange = (val: any, callback: Callback, options: LengthRange) => {
|
||||||
|
const { min, max, message } = options
|
||||||
|
if (val.length < min || val.length > max) {
|
||||||
|
callback(new Error(message))
|
||||||
|
} else {
|
||||||
|
callback()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const notSpace = (val: any, callback: Callback, message: string) => {
|
||||||
|
// 用户名不能有空格
|
||||||
|
if (val.indexOf(' ') !== -1) {
|
||||||
|
callback(new Error(message))
|
||||||
|
} else {
|
||||||
|
callback()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const notSpecialCharacters = (val: any, callback: Callback, message: string) => {
|
||||||
|
// 密码不能是特殊字符
|
||||||
|
if (/[`~!@#$%^&*()_+<>?:"{},.\/;'[\]]/gi.test(val)) {
|
||||||
|
callback(new Error(message))
|
||||||
|
} else {
|
||||||
|
callback()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 两个字符串是否想等
|
||||||
|
const isEqual = (val1: string, val2: string, callback: Callback, message: string) => {
|
||||||
|
if (val1 === val2) {
|
||||||
|
callback()
|
||||||
|
} else {
|
||||||
|
callback(new Error(message))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
required,
|
||||||
|
lengthRange,
|
||||||
|
notSpace,
|
||||||
|
notSpecialCharacters,
|
||||||
|
isEqual
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,2 +1,2 @@
|
|||||||
@import './var.css';
|
@import './var.css';
|
||||||
@import 'element-plus/theme-chalk/dark/css-vars.css';
|
@import 'element-plus/theme-chalk/dark/css-vars.css';
|
||||||
|
|||||||
Loading…
Reference in New Issue