前端服务器详情页支持编辑服务器名称

This commit is contained in:
jingrow 2025-08-09 22:25:18 +08:00
parent c7d55d99d8
commit 36543c4f75

View File

@ -87,7 +87,58 @@
<div v-if="info.prefix">
<component :is="info.prefix" />
</div>
<span>
<!-- 服务器名称特殊处理 - 支持内联编辑 -->
<div v-if="info.label === '服务器名称'" class="flex-1 min-w-0">
<div v-if="!editingServerName"
@click="startEditServerName"
class="group flex items-center cursor-pointer rounded-md px-2 py-1 -mx-2 -my-1 hover:bg-gray-100 transition-colors duration-200"
:title="'点击编辑服务器名称'"
>
<span class="truncate">{{ info.value }}</span>
<svg class="ml-2 h-4 w-4 text-gray-400 opacity-0 group-hover:opacity-100 transition-opacity duration-200" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z"></path>
</svg>
</div>
<div v-else class="flex items-center space-x-2">
<input
ref="serverNameInput"
v-model="editServerNameValue"
@keyup.enter="saveServerName"
@keyup.escape="cancelEditServerName"
@blur="handleInputBlur"
class="flex-1 px-2 py-1 text-sm border border-blue-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent shadow-sm"
:disabled="saveServerNameLoading"
maxlength="100"
placeholder="请输入服务器名称"
/>
<button
@click="saveServerName"
:disabled="saveServerNameLoading"
class="p-1 text-green-600 hover:text-green-700 disabled:opacity-50 transition-colors duration-200"
title="保存"
>
<svg v-if="!saveServerNameLoading" class="h-4 w-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path>
</svg>
<svg v-else class="h-4 w-4 animate-spin" fill="none" viewBox="0 0 24 24">
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
<path class="opacity-75" fill="currentColor" d="m12 6a6 6 0 0 1 6 6h4a10 10 0 0 0-10-10v4z"></path>
</svg>
</button>
<button
@click="cancelEditServerName"
:disabled="saveServerNameLoading"
class="p-1 text-gray-500 hover:text-gray-700 disabled:opacity-50 transition-colors duration-200"
title="取消"
>
<svg class="h-4 w-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
</svg>
</button>
</div>
</div>
<!-- 其他信息正常显示 -->
<span v-else>
{{ info.value }}
</span>
<div v-if="info.suffix">
@ -239,6 +290,9 @@ export default {
resetSystemLoading: false,
upgradeLoading: false,
copySuccess: false,
editingServerName: false,
editServerNameValue: '',
saveServerNameLoading: false,
};
},
methods: {
@ -514,6 +568,78 @@ export default {
//
this.$jsiteServer.reload();
},
startEditServerName() {
this.editServerNameValue = this.$jsiteServer.pg?.title || this.$jsiteServer.pg?.name || '';
this.editingServerName = true;
this.$nextTick(() => {
const input = this.$refs.serverNameInput;
if (input && typeof input.focus === 'function') {
input.focus();
if (typeof input.select === 'function') {
input.select();
}
}
});
},
cancelEditServerName() {
this.editingServerName = false;
this.editServerNameValue = '';
},
handleInputBlur() {
//
setTimeout(() => {
if (this.editingServerName && !this.saveServerNameLoading) {
this.saveServerName();
}
}, 150);
},
async saveServerName() {
if (this.saveServerNameLoading) return;
const newName = this.editServerNameValue.trim();
if (!newName) {
toast.error('服务器名称不能为空');
return;
}
if (newName.length < 2) {
toast.error('服务器名称至少需要2个字符');
return;
}
if (newName.length > 100) {
toast.error('服务器名称不能超过100个字符');
return;
}
if (newName === (this.$jsiteServer.pg?.title || this.$jsiteServer.pg?.name)) {
this.cancelEditServerName();
return;
}
this.saveServerNameLoading = true;
try {
this.$jsiteServer.setValue.submit(
{ title: newName },
{
onSuccess: () => {
toast.success('服务器名称已更新');
this.editingServerName = false;
this.editServerNameValue = '';
this.saveServerNameLoading = false;
},
onError: (error) => {
toast.error(getToastErrorMessage(error));
this.saveServerNameLoading = false;
}
}
);
} catch (error) {
toast.error('更新失败,请重试');
this.saveServerNameLoading = false;
}
},
},
computed: {
serverInformation() {