3x-ui/web/html/modals/node_modal.html

150 lines
5.7 KiB
HTML
Raw Normal View History

2026-01-05 21:12:53 +00:00
{{define "modals/nodeModal"}}
2026-01-10 19:51:10 +00:00
<a-modal id="node-modal" v-model="nodeModal.visible" :title="nodeModal.title"
@ok="nodeModal.ok" @cancel="nodeModal.cancel" :ok-text="nodeModal.okText" :width="600">
<a-form layout="vertical">
<a-form-item label='{{ i18n "pages.nodes.nodeName" }}'>
2026-01-05 21:12:53 +00:00
<a-input v-model.trim="nodeModal.formData.name" placeholder="e.g., Node-1"></a-input>
</a-form-item>
2026-01-10 19:51:10 +00:00
<a-form-item label='{{ i18n "pages.nodes.nodeAddress" }}'>
<a-input v-model.trim="nodeModal.formData.address" placeholder='{{ i18n "pages.nodes.fullUrlHint" }}'></a-input>
2026-01-05 21:12:53 +00:00
</a-form-item>
2026-01-10 19:51:10 +00:00
<a-form-item label='{{ i18n "pages.nodes.nodePort" }}'>
<a-input-number v-model.number="nodeModal.formData.port" :min="1" :max="65535" :style="{ width: '100%' }"></a-input-number>
</a-form-item>
<a-form-item label='{{ i18n "pages.nodes.nodeApiKey" }}'>
<a-input-password v-model.trim="nodeModal.formData.apiKey" placeholder='{{ i18n "pages.nodes.enterApiKey" }}'></a-input-password>
2026-01-05 21:12:53 +00:00
</a-form-item>
</a-form>
</a-modal>
<script>
const nodeModal = window.nodeModal = {
visible: false,
title: '',
2026-01-10 19:51:10 +00:00
okText: 'OK',
2026-01-05 21:12:53 +00:00
formData: {
name: '',
address: '',
2026-01-10 19:51:10 +00:00
port: 8080,
2026-01-05 21:12:53 +00:00
apiKey: ''
},
ok() {
2026-01-10 19:51:10 +00:00
// Валидация полей - используем nodeModal напрямую для правильного контекста
if (!nodeModal.formData.name || !nodeModal.formData.name.trim()) {
if (typeof app !== 'undefined' && app.$message) {
app.$message.error('{{ i18n "pages.nodes.enterNodeName" }}');
} else if (typeof Vue !== 'undefined' && Vue.prototype && Vue.prototype.$message) {
Vue.prototype.$message.error('{{ i18n "pages.nodes.enterNodeName" }}');
}
2026-01-05 21:12:53 +00:00
return;
}
2026-01-10 19:51:10 +00:00
if (!nodeModal.formData.address || !nodeModal.formData.address.trim()) {
if (typeof app !== 'undefined' && app.$message) {
app.$message.error('{{ i18n "pages.nodes.enterNodeAddress" }}');
} else if (typeof Vue !== 'undefined' && Vue.prototype && Vue.prototype.$message) {
Vue.prototype.$message.error('{{ i18n "pages.nodes.enterNodeAddress" }}');
}
2026-01-05 21:12:53 +00:00
return;
}
2026-01-10 19:51:10 +00:00
if (!nodeModal.formData.apiKey || !nodeModal.formData.apiKey.trim()) {
if (typeof app !== 'undefined' && app.$message) {
app.$message.error('{{ i18n "pages.nodes.enterApiKey" }}');
} else if (typeof Vue !== 'undefined' && Vue.prototype && Vue.prototype.$message) {
Vue.prototype.$message.error('{{ i18n "pages.nodes.enterApiKey" }}');
}
2026-01-05 21:12:53 +00:00
return;
}
2026-01-10 19:51:10 +00:00
// Если все поля заполнены, формируем полный адрес с портом
const dataToSend = { ...nodeModal.formData };
// Всегда добавляем порт к адресу
let fullAddress = dataToSend.address.trim();
const port = dataToSend.port && dataToSend.port > 0 ? dataToSend.port : 8080;
// Правильно добавляем порт к URL
// Парсим URL: http://192.168.0.7 -> http://192.168.0.7:8080
const urlMatch = fullAddress.match(/^(https?:\/\/)([^\/:]+)(\/.*)?$/);
if (urlMatch) {
const protocol = urlMatch[1]; // http:// или https://
const host = urlMatch[2]; // 192.168.0.7
const path = urlMatch[3] || ''; // /path или ''
fullAddress = `${protocol}${host}:${port}${path}`;
2026-01-05 21:12:53 +00:00
} else {
2026-01-10 19:51:10 +00:00
// Если не удалось распарсить, просто добавляем порт
fullAddress = `${fullAddress}:${port}`;
2026-01-05 21:12:53 +00:00
}
2026-01-10 19:51:10 +00:00
// Удаляем порт из данных, так как он теперь в адресе
delete dataToSend.port;
dataToSend.address = fullAddress;
// Вызываем confirm с объединенным адресом
if (nodeModal.confirm) {
nodeModal.confirm(dataToSend);
}
nodeModal.visible = false;
},
cancel() {
this.visible = false;
},
show({ title = '', okText = 'OK', node = null, confirm = (data) => { }, isEdit = false }) {
2026-01-05 21:12:53 +00:00
this.title = title;
this.okText = okText;
this.confirm = confirm;
if (node) {
2026-01-10 19:51:10 +00:00
// Извлекаем адрес и порт из полного URL
let address = node.address || '';
let port = 8080;
// Всегда извлекаем порт из адреса, если он там есть
if (address) {
const urlMatch = address.match(/^(https?:\/\/[^\/:]+)(:(\d+))?(\/.*)?$/);
if (urlMatch) {
// Убираем порт из адреса для отображения
const protocol = urlMatch[1].match(/^(https?:\/\/)/)[1];
const host = urlMatch[1].replace(/^https?:\/\//, '');
const path = urlMatch[4] || '';
address = `${protocol}${host}${path}`;
// Если порт был в адресе, извлекаем его
if (urlMatch[3]) {
port = parseInt(urlMatch[3], 10);
}
}
}
2026-01-05 21:12:53 +00:00
this.formData = {
name: node.name || '',
2026-01-10 19:51:10 +00:00
address: address,
port: port,
2026-01-05 21:12:53 +00:00
apiKey: node.apiKey || ''
};
} else {
this.formData = {
name: '',
address: '',
2026-01-10 19:51:10 +00:00
port: 8080,
2026-01-05 21:12:53 +00:00
apiKey: ''
};
}
this.visible = true;
},
close() {
2026-01-10 19:51:10 +00:00
this.visible = false;
2026-01-05 21:12:53 +00:00
}
};
2026-01-10 19:51:10 +00:00
const nodeModalVueInstance = new Vue({
delimiters: ['[[', ']]'],
el: '#node-modal',
data: {
nodeModal: nodeModal
2026-01-05 21:12:53 +00:00
}
2026-01-10 19:51:10 +00:00
});
2026-01-05 21:12:53 +00:00
</script>
{{end}}