feat: 限制分组名称,解决编辑之后点取消显示错误

pull/184/head
zhengkunwang223 2 years ago committed by ssongliu
parent 40e5dfaa11
commit f548080fea

@ -14,13 +14,17 @@
{{ row.name }} {{ row.name }}
<span v-if="row.default">({{ $t('website.default') }})</span> <span v-if="row.default">({{ $t('website.default') }})</span>
</span> </span>
<el-input v-if="row.edit" v-model="row.name"></el-input> <el-form ref="groupForm" :model="row" :rules="rules">
<el-form-item prop="name" v-if="row.edit">
<el-input v-model="row.name"></el-input>
</el-form-item>
</el-form>
</template> </template>
</el-table-column> </el-table-column>
<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(row, false)"> <el-button link v-if="row.edit" type="primary" @click="saveGroup(groupForm, row, false)">
{{ $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)">
@ -38,7 +42,12 @@
<el-button link v-if="row.edit" type="primary" @click="cancelEdit($index)"> <el-button link v-if="row.edit" type="primary" @click="cancelEdit($index)">
{{ $t('commons.button.cancel') }} {{ $t('commons.button.cancel') }}
</el-button> </el-button>
<el-button link v-if="!row.edit && !row.default" type="primary" @click="saveGroup(row, true)"> <el-button
link
v-if="!row.edit && !row.default"
type="primary"
@click="saveGroup(groupForm, row, true)"
>
{{ $t('website.setDefault') }} {{ $t('website.setDefault') }}
</el-button> </el-button>
</div> </div>
@ -54,6 +63,8 @@ import ComplexTable from '@/components/complex-table/index.vue';
import { ListGroups, CreateGroup, DeleteGroup, UpdateGroup } from '@/api/modules/website'; import { ListGroups, CreateGroup, DeleteGroup, UpdateGroup } from '@/api/modules/website';
import Header from '@/components/drawer-header/index.vue'; import Header from '@/components/drawer-header/index.vue';
import { MsgSuccess } from '@/utils/message'; import { MsgSuccess } from '@/utils/message';
import { Rules } from '@/global/form-rules';
import { FormInstance } from 'element-plus';
interface groupData { interface groupData {
id: number; id: number;
@ -62,6 +73,11 @@ interface groupData {
default: boolean; default: boolean;
} }
let rules = ref<any>({
name: [Rules.name],
});
const groupForm = ref<FormInstance>();
let open = ref(false); let open = ref(false);
let data = ref<groupData[]>([]); let data = ref<groupData[]>([]);
const handleClose = () => { const handleClose = () => {
@ -84,26 +100,32 @@ const search = () => {
}); });
}; };
const saveGroup = (create: groupData, isDefault: boolean) => { const saveGroup = async (formEl: FormInstance, create: groupData, isDefault: boolean) => {
const group = { if (!formEl) return;
name: create.name, await formEl.validate((valid) => {
id: create.id, if (!valid) {
default: create.default, return;
}; }
if (isDefault) { const group = {
group.default = isDefault; name: create.name,
} id: create.id,
if (create.id == 0) { default: create.default,
CreateGroup(group).then(() => { };
MsgSuccess(i18n.global.t('commons.msg.createSuccess')); if (isDefault) {
search(); group.default = isDefault;
}); }
} else { if (create.id == 0) {
UpdateGroup(group).then(() => { CreateGroup(group).then(() => {
MsgSuccess(i18n.global.t('commons.msg.updateSuccess')); MsgSuccess(i18n.global.t('commons.msg.createSuccess'));
search(); search();
}); });
} } else {
UpdateGroup(group).then(() => {
MsgSuccess(i18n.global.t('commons.msg.updateSuccess'));
search();
});
}
});
}; };
const acceptParams = async () => { const acceptParams = async () => {
@ -160,6 +182,7 @@ const cancelEdit = (index: number) => {
data.value.splice(index, 1); data.value.splice(index, 1);
} else { } else {
data.value[index].edit = false; data.value[index].edit = false;
search();
} }
}; };

Loading…
Cancel
Save