fix: 增加用户名称修改校验

pull/175/head
ssongliu 2023-03-01 14:27:25 +08:00 committed by ssongliu
parent 98efb98190
commit 6ff3ff7f38
5 changed files with 37 additions and 7 deletions

View File

@ -45,7 +45,7 @@ const checkUserName = (rule: any, value: any, callback: any) => {
if (value === '' || typeof value === 'undefined' || value == null) {
callback(new Error(i18n.global.t('commons.rule.userName')));
} else {
const reg = /^[a-zA-Z\u4e00-\u9fa5]{1}[a-zA-Z0-9_\u4e00-\u9fa5]{5,30}$/;
const reg = /^[a-zA-Z\u4e00-\u9fa5]{1}[a-zA-Z0-9_\u4e00-\u9fa5]{2,30}$/;
if (!reg.test(value) && value !== '') {
callback(new Error(i18n.global.t('commons.rule.userName')));
} else {

View File

@ -120,7 +120,7 @@ export default {
requiredInput: 'Please enter the required fields',
requiredSelect: 'Please select the required fields',
commonName: 'Support English, Chinese, numbers, .-, and _ length 1-30',
userName: 'Support English, Chinese, numbers and _ length 5-30',
userName: 'Support English, Chinese, numbers and _ length 3-30',
simpleName: 'Support English, numbers and _ length 1-30',
dbName: 'Support English, Chinese, numbers, .-, and _ length 1-16',
imageName: 'Support English, Chinese, numbers, :.-_, length 1-30',
@ -726,6 +726,8 @@ export default {
all: 'All',
panel: 'Panel',
user: 'UserName',
userChange: 'Change username',
userChangeHelper: 'Change the user name and restart the service. Do you want to continue?',
passwd: 'Password',
emailHelper: 'For password retrieval',
title: 'Panel alias',

View File

@ -125,7 +125,7 @@ export default {
requiredInput: '',
requiredSelect: '',
commonName: '.-_,1-30',
userName: '_,5-30',
userName: '_,3-30',
simpleName: '_,1-30',
dbName: '.-_,1-16',
imageName: ':.-_,1-30',
@ -734,7 +734,9 @@ export default {
all: '',
panel: '',
user: '',
passwd: '',
userChange: '',
userChangeHelper: '',
passwd: '',
emailHelper: '',
title: '',
panelPort: '',

View File

@ -189,7 +189,7 @@ const registerForm = reactive({
rePassword: '',
});
const registerRules = reactive({
name: [Rules.requiredInput],
name: [Rules.requiredInput, Rules.userName],
password: [Rules.requiredInput, Rules.password],
rePassword: [Rules.requiredInput, Rules.password, { validator: checkPassword, trigger: 'blur' }],
});

View File

@ -11,7 +11,7 @@
<template #append>
<el-button
style="width: 85px"
@click="onSave(panelFormRef, 'UserName', form.userName)"
@click="onSaveUserName(panelFormRef, 'UserName', form.userName)"
icon="Collection"
>
{{ $t('commons.button.save') }}
@ -120,7 +120,7 @@
<script lang="ts" setup>
import { ref, reactive, onMounted, computed } from 'vue';
import { ElForm } from 'element-plus';
import { ElForm, ElMessageBox } from 'element-plus';
import LayoutContent from '@/layout/layout-content.vue';
import { syncTime, getSettingInfo, updateSetting } from '@/api/modules/setting';
import { Rules } from '@/global/form-rules';
@ -176,6 +176,32 @@ const onChangePassword = () => {
passwordRef.value.acceptParams({ complexityVerification: form.complexityVerification });
};
const onSaveUserName = async (formEl: FormInstance | undefined, key: string, val: any) => {
if (!formEl) return;
const result = await formEl.validateField('userName', callback);
if (!result) {
return;
}
ElMessageBox.confirm(i18n.t('setting.userChangeHelper'), i18n.t('setting.userChange'), {
confirmButtonText: i18n.t('commons.button.confirm'),
cancelButtonText: i18n.t('commons.button.cancel'),
type: 'info',
}).then(async () => {
await updateSetting({ key: key, value: val })
.then(async () => {
await logOutApi();
loading.value = false;
MsgSuccess(i18n.t('commons.msg.operationSuccess'));
router.push({ name: 'login', params: { code: '' } });
globalStore.setLogStatus(false);
return;
})
.catch(() => {
loading.value = false;
});
});
};
const onSave = async (formEl: FormInstance | undefined, key: string, val: any) => {
if (!formEl) return;
const result = await formEl.validateField(key.replace(key[0], key[0].toLowerCase()), callback);