-
+
{{ $t('commons.button.save') }}
@@ -38,7 +42,12 @@
{{ $t('commons.button.cancel') }}
-
+
{{ $t('website.setDefault') }}
@@ -54,6 +63,8 @@ import ComplexTable from '@/components/complex-table/index.vue';
import { ListGroups, CreateGroup, DeleteGroup, UpdateGroup } from '@/api/modules/website';
import Header from '@/components/drawer-header/index.vue';
import { MsgSuccess } from '@/utils/message';
+import { Rules } from '@/global/form-rules';
+import { FormInstance } from 'element-plus';
interface groupData {
id: number;
@@ -62,6 +73,11 @@ interface groupData {
default: boolean;
}
+let rules = ref({
+ name: [Rules.name],
+});
+const groupForm = ref();
+
let open = ref(false);
let data = ref([]);
const handleClose = () => {
@@ -84,26 +100,32 @@ const search = () => {
});
};
-const saveGroup = (create: groupData, isDefault: boolean) => {
- const group = {
- name: create.name,
- id: create.id,
- default: create.default,
- };
- if (isDefault) {
- group.default = isDefault;
- }
- if (create.id == 0) {
- CreateGroup(group).then(() => {
- MsgSuccess(i18n.global.t('commons.msg.createSuccess'));
- search();
- });
- } else {
- UpdateGroup(group).then(() => {
- MsgSuccess(i18n.global.t('commons.msg.updateSuccess'));
- search();
- });
- }
+const saveGroup = async (formEl: FormInstance, create: groupData, isDefault: boolean) => {
+ if (!formEl) return;
+ await formEl.validate((valid) => {
+ if (!valid) {
+ return;
+ }
+ const group = {
+ name: create.name,
+ id: create.id,
+ default: create.default,
+ };
+ if (isDefault) {
+ group.default = isDefault;
+ }
+ if (create.id == 0) {
+ CreateGroup(group).then(() => {
+ MsgSuccess(i18n.global.t('commons.msg.createSuccess'));
+ search();
+ });
+ } else {
+ UpdateGroup(group).then(() => {
+ MsgSuccess(i18n.global.t('commons.msg.updateSuccess'));
+ search();
+ });
+ }
+ });
};
const acceptParams = async () => {
@@ -160,6 +182,7 @@ const cancelEdit = (index: number) => {
data.value.splice(index, 1);
} else {
data.value[index].edit = false;
+ search();
}
};