21312
This commit is contained in:
41
index.html
41
index.html
@@ -652,27 +652,28 @@ SELECT * FROM users LIMIT 10;"></textarea>
|
||||
}
|
||||
|
||||
async generateRecordForm() {
|
||||
if (response.status === 401) {
|
||||
this.logout();
|
||||
return [];
|
||||
}
|
||||
const columns = await this.getTableStructure(this.currentTable);
|
||||
const container = document.getElementById('recordForm');
|
||||
|
||||
if (!columns || columns.length === 0) {
|
||||
container.innerHTML = `<p class="text-red-500">Не удалось загрузить структуру таблицы</p>`;
|
||||
return;
|
||||
}
|
||||
|
||||
container.innerHTML = columns.map(col => `
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-slate-700 mb-1">
|
||||
${col.name}
|
||||
${col.nullable ? '' : '<span class="text-red-500">*</span>'}
|
||||
</label>
|
||||
<input type="${this.getInputType(col.type)}"
|
||||
name="${col.name}"
|
||||
class="w-full px-4 py-2 border border-slate-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent outline-none"
|
||||
${col.default ? `value="${col.default}"` : ''}>
|
||||
<p class="text-xs text-slate-500 mt-1">${col.type}</p>
|
||||
</div>
|
||||
`).join('');
|
||||
}
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-slate-700 mb-1">
|
||||
${col.name}
|
||||
${col.nullable ? '' : '<span class="text-red-500">*</span>'}
|
||||
</label>
|
||||
<input type="${this.getInputType(col.type)}"
|
||||
name="${col.name}"
|
||||
class="w-full px-4 py-2 border border-slate-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent outline-none"
|
||||
${col.default ? `value="${col.default}"` : ''}>
|
||||
<p class="text-xs text-slate-500 mt-1">${col.type}</p>
|
||||
</div>
|
||||
`).join('');
|
||||
}
|
||||
|
||||
async getTableStructure(tableName) {
|
||||
try {
|
||||
@@ -706,7 +707,11 @@ SELECT * FROM users LIMIT 10;"></textarea>
|
||||
const inputs = form.querySelectorAll('input');
|
||||
const data = {};
|
||||
inputs.forEach(input => {
|
||||
if (input.type === 'number') {
|
||||
if (input.name === 'id') return;
|
||||
|
||||
if (input.type === 'checkbox') {
|
||||
data[input.name] = input.checked;
|
||||
} else if (input.type === 'number') {
|
||||
data[input.name] = parseFloat(input.value);
|
||||
} else {
|
||||
data[input.name] = input.value;
|
||||
|
||||
Reference in New Issue
Block a user