Skip to content

Commit 63a1069

Browse files
feat: limit website name length in configuration (#11422)
1 parent 5674673 commit 63a1069

File tree

2 files changed

+51
-19
lines changed

2 files changed

+51
-19
lines changed

frontend/src/views/website/website/config/basic/other/index.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<el-form-item :label="$t('commons.table.name')" prop="primaryDomain">
66
<el-input v-model="form.primaryDomain"></el-input>
77
</el-form-item>
8-
<el-form-item :label="$t('website.alias')" prop="primaryDomain">
8+
<el-form-item :label="$t('website.alias')" prop="alias">
99
<el-input v-model="form.alias" disabled></el-input>
1010
</el-form-item>
1111
<GroupSelect
@@ -60,7 +60,7 @@ const form = reactive({
6060
favorite: false,
6161
});
6262
const rules = ref({
63-
primaryDomain: [Rules.requiredInput],
63+
primaryDomain: [Rules.requiredInput, Rules.linuxName],
6464
webSiteGroupId: [Rules.requiredSelect],
6565
});
6666

frontend/src/views/website/website/domain/index.vue

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
<template>
22
<div class="name-row">
33
<div>
4-
<el-input
5-
v-if="isEditing"
6-
v-model="editValue"
7-
@keyup.enter="saveEdit"
8-
@blur="saveEdit"
9-
@keyup.esc="cancelEdit"
10-
class="domain-input"
11-
ref="inputRef"
12-
/>
4+
<el-form :model="formData" :rules="rules" ref="formRef" v-if="isEditing" @submit.prevent>
5+
<el-form-item prop="domainName" class="inline-form-item">
6+
<el-input
7+
v-model="formData.domainName"
8+
@keyup.enter.prevent="saveEdit"
9+
@blur="saveEdit"
10+
@keyup.esc="cancelEdit"
11+
class="domain-input"
12+
ref="inputRef"
13+
/>
14+
</el-form-item>
15+
</el-form>
1316
<el-text v-else type="primary" class="cursor-pointer" @click="openConfig(row.id)">
1417
{{ row.primaryDomain }}
1518
</el-text>
@@ -62,6 +65,7 @@ import { ref } from 'vue';
6265
import { listDomains } from '@/api/modules/website';
6366
import { Website } from '@/api/interface/website';
6467
import { routerToNameWithParams } from '@/utils/router';
68+
import { Rules } from '@/global/form-rules';
6569
6670
interface Props {
6771
row: Website.Website;
@@ -71,27 +75,38 @@ const props = defineProps<Props>();
7175
const emit = defineEmits(['favoriteChange', 'domainEdit']);
7276
const inputRef = ref();
7377
const isEditing = ref(false);
74-
const editValue = ref('');
7578
const domains = ref<Website.Domain[]>([]);
79+
const formData = reactive({
80+
domainName: '',
81+
});
82+
const rules = ref({
83+
domainName: [Rules.requiredInput, Rules.linuxName],
84+
});
85+
const formRef = ref();
7686
7787
const startEdit = () => {
78-
editValue.value = props.row.primaryDomain;
88+
formData.domainName = props.row.primaryDomain;
7989
isEditing.value = true;
8090
nextTick(() => {
8191
inputRef.value?.focus();
8292
inputRef.value?.select();
8393
});
8494
};
8595
86-
const saveEdit = () => {
87-
if (editValue.value.trim() && editValue.value !== props.row.primaryDomain) {
88-
emit('domainEdit', props.row, editValue.value.trim());
89-
}
90-
isEditing.value = false;
96+
const saveEdit = async () => {
97+
await formRef.value.validate((valid) => {
98+
if (valid) {
99+
const editValue = formData.domainName.trim();
100+
if (editValue && editValue !== props.row.primaryDomain) {
101+
emit('domainEdit', props.row, editValue);
102+
}
103+
isEditing.value = false;
104+
}
105+
});
91106
};
92107
93108
const cancelEdit = () => {
94-
editValue.value = props.row.primaryDomain;
109+
formData.domainName = props.row.primaryDomain;
95110
isEditing.value = false;
96111
};
97112
@@ -133,4 +148,21 @@ const favoriteWebsite = (row: Website.Website) => {
133148
justify-content: space-between;
134149
width: 100%;
135150
}
151+
:deep(.el-form) {
152+
margin: 0;
153+
line-height: 1;
154+
}
155+
:deep(.el-form-item) {
156+
margin-bottom: 0;
157+
}
158+
:deep(.el-form-item__error) {
159+
position: absolute;
160+
top: 100%;
161+
left: 0;
162+
padding-top: 2px;
163+
}
164+
165+
.domain-input {
166+
width: 200px;
167+
}
136168
</style>

0 commit comments

Comments
 (0)