fix: 增加一些校验规则

pull/205/head
ssongliu 2023-03-13 23:41:55 +08:00 committed by ssongliu
parent 35098ce79c
commit eb56b918a6
4 changed files with 20 additions and 18 deletions

View File

@ -28,7 +28,7 @@
<el-table-column :label="$t('commons.table.operate')"> <el-table-column :label="$t('commons.table.operate')">
<template #default="{ row, $index }"> <template #default="{ row, $index }">
<div> <div>
<el-button link v-if="row.edit" type="primary" @click="saveGroup(groupForm, row, true)"> <el-button link v-if="row.edit" type="primary" @click="saveGroup(groupForm, row)">
{{ $t('commons.button.save') }} {{ $t('commons.button.save') }}
</el-button> </el-button>
<el-button link v-if="!row.edit" type="primary" @click="editGroup($index)"> <el-button link v-if="!row.edit" type="primary" @click="editGroup($index)">
@ -46,12 +46,7 @@
<el-button link v-if="row.edit" type="primary" @click="search()"> <el-button link v-if="row.edit" type="primary" @click="search()">
{{ $t('commons.button.cancel') }} {{ $t('commons.button.cancel') }}
</el-button> </el-button>
<el-button <el-button link v-if="!row.edit && !row.isDefault" type="primary" @click="setDefault(row)">
link
v-if="!row.edit && !row.isDefault"
type="primary"
@click="saveGroup(groupForm, row, false)"
>
{{ $t('website.setDefault') }} {{ $t('website.setDefault') }}
</el-button> </el-button>
</div> </div>
@ -83,7 +78,7 @@ interface DialogProps {
type: string; type: string;
} }
const groupForm = ref(); const groupForm = ref<FormInstance>();
const acceptParams = (params: DialogProps): void => { const acceptParams = (params: DialogProps): void => {
type.value = params.type; type.value = params.type;
open.value = true; open.value = true;
@ -106,16 +101,13 @@ const search = () => {
}); });
}; };
const saveGroup = async (formEl: FormInstance, group: Group.GroupInfo, isEdit: boolean) => { const saveGroup = async (formEl: FormInstance, group: Group.GroupInfo) => {
if (!formEl) return; if (!formEl) return;
await formEl.validate((valid) => { await formEl.validate((valid) => {
if (!valid) { if (!valid) {
return; return;
} }
group.type = type.value; group.type = type.value;
if (!isEdit) {
group.isDefault = true;
}
if (group.id == 0) { if (group.id == 0) {
CreateGroup(group).then(() => { CreateGroup(group).then(() => {
MsgSuccess(i18n.global.t('commons.msg.createSuccess')); MsgSuccess(i18n.global.t('commons.msg.createSuccess'));
@ -130,6 +122,14 @@ const saveGroup = async (formEl: FormInstance, group: Group.GroupInfo, isEdit: b
}); });
}; };
const setDefault = (group: Group.GroupInfo) => {
group.isDefault = true;
UpdateGroup(group).then(() => {
MsgSuccess(i18n.global.t('commons.msg.updateSuccess'));
search();
});
};
const openCreate = () => { const openCreate = () => {
for (const d of data.value) { for (const d of data.value) {
if (d.name == '') { if (d.name == '') {

View File

@ -6,7 +6,7 @@
<el-form ref="newNameRef" v-loading="loading" :model="renameForm" label-position="top"> <el-form ref="newNameRef" v-loading="loading" :model="renameForm" label-position="top">
<el-row type="flex" justify="center"> <el-row type="flex" justify="center">
<el-col :span="22"> <el-col :span="22">
<el-form-item :label="$t('container.newName')" :rules="Rules.requiredInput" prop="newName"> <el-form-item :label="$t('container.newName')" :rules="Rules.volumeName" prop="newName">
<el-input v-model="renameForm.newName"></el-input> <el-input v-model="renameForm.newName"></el-input>
</el-form-item> </el-form-item>
</el-col> </el-col>

View File

@ -19,7 +19,7 @@
<el-option v-for="item in repos" :key="item.id" :value="item.id" :label="item.name" /> <el-option v-for="item in repos" :key="item.id" :value="item.id" :label="item.name" />
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item :label="$t('container.imageName')" :rules="Rules.requiredInput" prop="targetName"> <el-form-item :label="$t('container.imageName')" :rules="Rules.imageName" prop="targetName">
<el-input v-model="form.targetName"> <el-input v-model="form.targetName">
<template v-if="form.fromRepo" #prepend>{{ loadDetailInfo(form.repoID) }}/</template> <template v-if="form.fromRepo" #prepend>{{ loadDetailInfo(form.repoID) }}/</template>
</el-input> </el-input>

View File

@ -118,12 +118,14 @@ const rules = reactive({
const loadGroups = async () => { const loadGroups = async () => {
const res = await GetGroupList({ type: 'host' }); const res = await GetGroupList({ type: 'host' });
groupList.value = res.data; groupList.value = res.data;
if (dialogData.value.title === 'create') {
for (const item of groupList.value) { for (const item of groupList.value) {
if (item.isDefault) { if (item.isDefault) {
dialogData.value.rowData.groupID = item.id; dialogData.value.rowData.groupID = item.id;
break; break;
} }
} }
}
}; };
const submitAddHost = (formEl: FormInstance | undefined, ops: string) => { const submitAddHost = (formEl: FormInstance | undefined, ops: string) => {