feat(学校端): 教师/家长登录账号校验与租户一致,抽取 loginAccount 常量

Made-with: Cursor
This commit is contained in:
zhonghua 2026-03-24 16:07:27 +08:00
parent 1751d0e355
commit de448a3e64
4 changed files with 47 additions and 10 deletions

View File

@ -0,0 +1,9 @@
/**
* /
* 4-20 线
*/
export const LOGIN_ACCOUNT_PATTERN = /^[a-zA-Z][a-zA-Z0-9_]{3,19}$/;
export const LOGIN_ACCOUNT_PLACEHOLDER = '字母开头4-20位';
export const LOGIN_ACCOUNT_PATTERN_MESSAGE = '字母开头4-20位字母数字或下划线';

View File

@ -126,7 +126,7 @@
<a-input v-model:value="formData.name" placeholder="请输入学校名称" /> <a-input v-model:value="formData.name" placeholder="请输入学校名称" />
</a-form-item> </a-form-item>
<a-form-item v-if="!isEdit" label="登录账号" name="loginAccount"> <a-form-item v-if="!isEdit" label="登录账号" name="loginAccount">
<a-input v-model:value="formData.loginAccount" placeholder="字母开头4-20位" :disabled="isEdit" /> <a-input v-model:value="formData.loginAccount" :placeholder="LOGIN_ACCOUNT_PLACEHOLDER" :disabled="isEdit" />
</a-form-item> </a-form-item>
<a-form-item v-if="!isEdit" label="初始密码" name="password"> <a-form-item v-if="!isEdit" label="初始密码" name="password">
<a-input-password v-model:value="formData.password" placeholder="留空则默认为 123456" /> <a-input-password v-model:value="formData.password" placeholder="留空则默认为 123456" />
@ -351,6 +351,11 @@ import {
type CourseCollectionResponse, type CourseCollectionResponse,
} from '@/api/admin'; } from '@/api/admin';
import { getDiscountTypeText } from '@/api/collections'; import { getDiscountTypeText } from '@/api/collections';
import {
LOGIN_ACCOUNT_PATTERN,
LOGIN_ACCOUNT_PATTERN_MESSAGE,
LOGIN_ACCOUNT_PLACEHOLDER,
} from '@/constants/loginAccount';
// //
const searchForm = reactive({ const searchForm = reactive({
@ -414,7 +419,10 @@ const formRules = {
name: [{ required: true, message: '请输入学校名称' }], name: [{ required: true, message: '请输入学校名称' }],
loginAccount: [ loginAccount: [
{ required: true, message: '请输入登录账号' }, { required: true, message: '请输入登录账号' },
{ pattern: /^[a-zA-Z][a-zA-Z0-9_]{3,19}$/, message: '字母开头4-20位字母数字或下划线' }, {
pattern: LOGIN_ACCOUNT_PATTERN,
message: LOGIN_ACCOUNT_PATTERN_MESSAGE,
},
], ],
contactPerson: [{ required: true, message: '请输入联系人' }], contactPerson: [{ required: true, message: '请输入联系人' }],
contactPhone: [ contactPhone: [

View File

@ -148,7 +148,7 @@
</a-input> </a-input>
</a-form-item> </a-form-item>
<a-form-item label="登录账号" name="loginAccount"> <a-form-item label="登录账号" name="loginAccount">
<a-input v-model:value="formState.loginAccount" placeholder="请输入登录账号" :disabled="isEdit"> <a-input v-model:value="formState.loginAccount" :placeholder="LOGIN_ACCOUNT_PLACEHOLDER" :disabled="isEdit">
<template #prefix> <template #prefix>
<KeyOutlined style="color: #B2BEC3;" /> <KeyOutlined style="color: #B2BEC3;" />
</template> </template>
@ -335,6 +335,11 @@ import {
getClasses, getClasses,
} from '@/api/school'; } from '@/api/school';
import type { Parent, CreateParentDto, ParentChild, Student } from '@/api/school'; import type { Parent, CreateParentDto, ParentChild, Student } from '@/api/school';
import {
LOGIN_ACCOUNT_PATTERN,
LOGIN_ACCOUNT_PATTERN_MESSAGE,
LOGIN_ACCOUNT_PLACEHOLDER,
} from '@/constants/loginAccount';
// //
const getParentStatusText = (status: string): string => { const getParentStatusText = (status: string): string => {
@ -412,14 +417,19 @@ const formState = reactive<CreateParentDto & { id?: number }>({
password: '', password: '',
}); });
const rules: Record<string, any[]> = { const rules = computed(() => ({
name: [{ required: true, message: '请输入家长姓名', trigger: 'blur' }], name: [{ required: true, message: '请输入家长姓名', trigger: 'blur' }],
phone: [ phone: [
{ required: true, message: '请输入手机号', trigger: 'blur' }, { required: true, message: '请输入手机号', trigger: 'blur' },
{ pattern: /^1[3-9]\d{9}$/, message: '请输入正确的手机号', trigger: 'blur' }, { pattern: /^1[3-9]\d{9}$/, message: '请输入正确的手机号', trigger: 'blur' },
], ],
loginAccount: [{ required: true, message: '请输入登录账号', trigger: 'blur' }], loginAccount: [
}; { required: true, message: '请输入登录账号', trigger: 'blur' },
...(!isEdit.value
? [{ pattern: LOGIN_ACCOUNT_PATTERN, message: LOGIN_ACCOUNT_PATTERN_MESSAGE, trigger: 'blur' }]
: []),
],
}));
const loadParents = async () => { const loadParents = async () => {
loading.value = true; loading.value = true;

View File

@ -152,7 +152,7 @@
</a-input> </a-input>
</a-form-item> </a-form-item>
<a-form-item label="登录账号" name="loginAccount"> <a-form-item label="登录账号" name="loginAccount">
<a-input v-model:value="formState.loginAccount" placeholder="请输入登录账号" :disabled="isEdit"> <a-input v-model:value="formState.loginAccount" :placeholder="LOGIN_ACCOUNT_PLACEHOLDER" :disabled="isEdit">
<template #prefix> <template #prefix>
<KeyOutlined style="color: #B2BEC3;" /> <KeyOutlined style="color: #B2BEC3;" />
</template> </template>
@ -234,6 +234,11 @@ import {
getClasses, getClasses,
} from '@/api/school'; } from '@/api/school';
import type { Teacher, CreateTeacherDto, ClassInfo } from '@/api/school'; import type { Teacher, CreateTeacherDto, ClassInfo } from '@/api/school';
import {
LOGIN_ACCOUNT_PATTERN,
LOGIN_ACCOUNT_PATTERN_MESSAGE,
LOGIN_ACCOUNT_PLACEHOLDER,
} from '@/constants/loginAccount';
// //
const getTeacherStatusText = (status: string): string => { const getTeacherStatusText = (status: string): string => {
@ -301,14 +306,19 @@ const formState = reactive<CreateTeacherDto & { id?: number; status?: string }>(
status: 'ACTIVE', status: 'ACTIVE',
}); });
const rules: Record<string, any[]> = { const rules = computed(() => ({
name: [{ required: true, message: '请输入教师姓名', trigger: 'blur' }], name: [{ required: true, message: '请输入教师姓名', trigger: 'blur' }],
phone: [ phone: [
{ required: true, message: '请输入手机号', trigger: 'blur' }, { required: true, message: '请输入手机号', trigger: 'blur' },
{ pattern: /^1[3-9]\d{9}$/, message: '请输入正确的手机号', trigger: 'blur' }, { pattern: /^1[3-9]\d{9}$/, message: '请输入正确的手机号', trigger: 'blur' },
], ],
loginAccount: [{ required: true, message: '请输入登录账号', trigger: 'blur' }], loginAccount: [
}; { required: true, message: '请输入登录账号', trigger: 'blur' },
...(!isEdit.value
? [{ pattern: LOGIN_ACCOUNT_PATTERN, message: LOGIN_ACCOUNT_PATTERN_MESSAGE, trigger: 'blur' }]
: []),
],
}));
const loadTeachers = async () => { const loadTeachers = async () => {
loading.value = true; loading.value = true;