接口配置已适配新数据库结构

This commit is contained in:
jinchao 2025-05-16 10:26:07 +08:00
parent 61cfdb94e9
commit b5d652a77e
7 changed files with 235 additions and 185 deletions

Binary file not shown.

View File

@ -11,15 +11,15 @@ class HeaderTools extends HTMLElement {
return this.shadowRoot.getElementById('planeSelect').value;
}
get selectedProduct() {
return this.shadowRoot.getElementById('productSelect').value;
get selectedConfiguration() {
return this.shadowRoot.getElementById('configurationSelect').value;
}
// 保存选择到localStorage
saveSelection() {
const selection = {
plane: this.selectedPlane,
product: this.selectedProduct
configurationId: this.selectedConfiguration
};
localStorage.setItem('xnsim-selection', JSON.stringify(selection));
}
@ -30,16 +30,16 @@ class HeaderTools extends HTMLElement {
if (savedSelection) {
const selection = JSON.parse(savedSelection);
const planeSelect = this.shadowRoot.getElementById('planeSelect');
const productSelect = this.shadowRoot.getElementById('productSelect');
const configurationSelect = this.shadowRoot.getElementById('configurationSelect');
// 先加载机型列表
this.loadPlanes().then(() => {
if (selection.plane) {
planeSelect.value = selection.plane;
// 加载该机型下的构型列表
this.loadProducts(selection.plane).then(() => {
if (selection.product) {
productSelect.value = selection.product;
this.loadConfigurations(selection.plane).then(() => {
if (selection.configurationId) {
configurationSelect.value = selection.configurationId;
}
});
}
@ -88,7 +88,7 @@ class HeaderTools extends HTMLElement {
color: #666;
}
.plane-select, .product-select {
.plane-select, .configuration-select {
min-width: 120px;
height: 32px;
padding: 0 8px;
@ -130,7 +130,7 @@ class HeaderTools extends HTMLElement {
</div>
<div class="select-container">
<span class="select-label">构型</span>
<select class="product-select" id="productSelect">
<select class="configuration-select" id="configurationSelect">
<option value="">选择构型</option>
</select>
</div>
@ -157,7 +157,7 @@ class HeaderTools extends HTMLElement {
// 加载机型列表
this.loadPlanes();
// 加载构型列表
this.loadProducts();
this.loadConfigurations();
// 恢复上次的选择
this.restoreSelection();
@ -187,15 +187,19 @@ class HeaderTools extends HTMLElement {
detail: { plane: e.target.value }
}));
// 当机型改变时,重新加载该机型下的构型列表
this.loadProducts(e.target.value);
this.loadConfigurations(e.target.value);
// 保存选择
this.saveSelection();
});
// 构型选择
this.shadowRoot.getElementById('productSelect').addEventListener('change', (e) => {
this.dispatchEvent(new CustomEvent('product-change', {
detail: { product: e.target.value }
this.shadowRoot.getElementById('configurationSelect').addEventListener('change', (e) => {
const selectedOption = e.target.options[e.target.selectedIndex];
this.dispatchEvent(new CustomEvent('configuration-change', {
detail: {
configurationId: e.target.value,
configurationName: selectedOption.textContent
}
}));
// 保存选择
this.saveSelection();
@ -225,23 +229,23 @@ class HeaderTools extends HTMLElement {
}
}
async loadProducts(planeName = '') {
async loadConfigurations(planeName = '') {
try {
const url = planeName ? `/api/configurations?plane=${planeName}` : '/api/configurations';
const response = await fetch(url);
if (!response.ok) {
throw new Error('获取构型列表失败');
}
const products = await response.json();
const select = this.shadowRoot.getElementById('productSelect');
const configurations = await response.json();
const select = this.shadowRoot.getElementById('configurationSelect');
// 清空现有选项
select.innerHTML = '<option value="">选择构型</option>';
products.forEach(product => {
configurations.forEach(config => {
const option = document.createElement('option');
option.value = product.ConfName;
option.textContent = product.ConfName;
option.value = config.ConfID;
option.textContent = config.ConfName;
select.appendChild(option);
});
} catch (error) {

View File

@ -8,7 +8,7 @@ class InterfaceConfig extends HTMLElement {
super();
this.attachShadow({ mode: 'open' });
this.data = [];
this.products = []; // 存储构型列表
this.planes = []; // 存储构型列表
this.atas = []; // 存储ATA章节列表
}
@ -43,9 +43,18 @@ class InterfaceConfig extends HTMLElement {
}
try {
const savedSelection = localStorage.getItem('xnsim-selection');
if (!savedSelection) {
throw new Error('请先选择构型');
}
const selection = JSON.parse(savedSelection);
if (!selection.configurationId) {
throw new Error('请先选择构型');
}
const deletePromises = selectedRows.map(row => {
const { SystemName, ProductName, ATAName, ModelStructName, InterfaceName } = row;
return fetch(`/api/interface/delete?systemName=${SystemName}&productName=${ProductName}&ataName=${ATAName}&modelStructName=${ModelStructName}&interfaceName=${InterfaceName}`, {
const { InterfaceName } = row;
return fetch(`/api/interface/delete?interfaceName=${InterfaceName}&confID=${selection.configurationId}`, {
method: 'DELETE'
});
});
@ -61,30 +70,7 @@ class InterfaceConfig extends HTMLElement {
alert('删除成功');
} catch (error) {
console.error('删除接口时出错:', error);
alert('删除接口失败');
}
});
// 下载模板事件
toolbar.addEventListener('download-template', async () => {
try {
const response = await fetch('/api/interface/template');
if (!response.ok) {
throw new Error('下载模板失败');
}
const blob = await response.blob();
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = '接口变量模板.xlsx';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
window.URL.revokeObjectURL(url);
} catch (error) {
console.error('下载模板时出错:', error);
alert('下载模板失败');
alert(error.message || '删除接口失败');
}
});
@ -123,14 +109,29 @@ class InterfaceConfig extends HTMLElement {
importDialog.addEventListener('confirm-import', async (e) => {
const importData = e.detail;
try {
console.log('准备导入的数据:', importData);
const savedSelection = localStorage.getItem('xnsim-selection');
if (!savedSelection) {
throw new Error('请先选择构型');
}
const selection = JSON.parse(savedSelection);
if (!selection.configurationId) {
throw new Error('请先选择构型');
}
// 为每个导入项添加 confID
const importDataWithConfID = importData.map(item => ({
...item,
ConfID: selection.configurationId
}));
console.log('准备导入的数据:', importDataWithConfID);
const response = await fetch('/api/interface/import', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(importData)
body: JSON.stringify(importDataWithConfID)
});
if (!response.ok) {
@ -147,7 +148,7 @@ class InterfaceConfig extends HTMLElement {
}
} catch (error) {
console.error('保存导入数据时出错:', error);
alert('保存导入数据失败: ' + error.message);
alert(error.message || '保存导入数据失败');
}
});
@ -156,7 +157,7 @@ class InterfaceConfig extends HTMLElement {
const variableForm = this.shadowRoot.querySelector('variable-form');
if (variableForm) {
// 确保在设置编辑数据之前先设置选项
variableForm.setOptions(this.products, this.atas);
variableForm.setOptions(this.planes, this.atas);
// 先显示表单,再设置模式和数据
variableForm.show();
variableForm.setMode('edit', e.detail);
@ -165,10 +166,19 @@ class InterfaceConfig extends HTMLElement {
// 表格删除按钮事件
dataTable.addEventListener('delete', async (e) => {
const { SystemName, ProductName, ATAName, ModelStructName, InterfaceName } = e.detail;
const { InterfaceName } = e.detail;
try {
const response = await fetch(`/api/interface/delete?systemName=${SystemName}&productName=${ProductName}&ataName=${ATAName}&modelStructName=${ModelStructName}&interfaceName=${InterfaceName}`, {
const savedSelection = localStorage.getItem('xnsim-selection');
if (!savedSelection) {
throw new Error('请先选择构型');
}
const selection = JSON.parse(savedSelection);
if (!selection.configurationId) {
throw new Error('请先选择构型');
}
const response = await fetch(`/api/interface/delete?interfaceName=${InterfaceName}&confID=${selection.configurationId}`, {
method: 'DELETE'
});
@ -180,7 +190,7 @@ class InterfaceConfig extends HTMLElement {
alert('删除成功');
} catch (error) {
console.error('删除接口时出错:', error);
alert('删除接口失败');
alert(error.message || '删除接口失败');
}
});
@ -195,7 +205,7 @@ class InterfaceConfig extends HTMLElement {
const requestData = interfaceData.mode === 'edit' ? {
currentData: {
SystemName: 'XNSim',
ProductName: interfaceData.ProductName,
PlaneName: interfaceData.PlaneName,
ATAName: interfaceData.ATAName,
ModelStructName: interfaceData.ModelStructName,
InterfaceName: interfaceData.InterfaceName,
@ -204,18 +214,19 @@ class InterfaceConfig extends HTMLElement {
InterfaceIsArray: interfaceData.InterfaceIsArray,
InterfaceArraySize_1: interfaceData.InterfaceArraySize_1,
InterfaceArraySize_2: interfaceData.InterfaceArraySize_2,
InterfaceNotes: interfaceData.InterfaceNotes
InterfaceNotes: interfaceData.InterfaceNotes,
ConfID: interfaceData.ConfID
},
originalData: {
SystemName: 'XNSim',
ProductName: interfaceData.originalProductName || interfaceData.ProductName,
PlaneName: interfaceData.originalPlaneName || interfaceData.PlaneName,
ATAName: interfaceData.originalATAName || interfaceData.ATAName,
ModelStructName: interfaceData.originalModelStructName || interfaceData.ModelStructName,
InterfaceName: interfaceData.originalInterfaceName || interfaceData.InterfaceName
}
} : {
SystemName: 'XNSim',
ProductName: interfaceData.ProductName,
PlaneName: interfaceData.PlaneName,
ATAName: interfaceData.ATAName,
ModelStructName: interfaceData.ModelStructName,
InterfaceName: interfaceData.InterfaceName,
@ -224,7 +235,8 @@ class InterfaceConfig extends HTMLElement {
InterfaceIsArray: interfaceData.InterfaceIsArray,
InterfaceArraySize_1: interfaceData.InterfaceArraySize_1,
InterfaceArraySize_2: interfaceData.InterfaceArraySize_2,
InterfaceNotes: interfaceData.InterfaceNotes
InterfaceNotes: interfaceData.InterfaceNotes,
ConfID: interfaceData.ConfID
};
const response = await fetch(url, {
@ -288,14 +300,24 @@ class InterfaceConfig extends HTMLElement {
async loadData() {
try {
const response = await fetch('/api/interface/list');
// 从 localStorage 获取选择
const savedSelection = localStorage.getItem('xnsim-selection');
if (!savedSelection) {
throw new Error('请先选择构型');
}
const selection = JSON.parse(savedSelection);
if (!selection.configurationId) {
throw new Error('请先选择构型');
}
const response = await fetch(`/api/interface/list?systemName=XNSim&confID=${selection.configurationId}`);
if (!response.ok) {
throw new Error('获取数据失败');
}
this.data = await response.json();
// 从接口数据中提取构型和ATA章节列表
this.products = [...new Set(this.data.map(item => item.ProductName))];
// 从接口数据中提取型和ATA章节列表
this.planes = [...new Set(this.data.map(item => item.PlaneName))];
this.atas = [...new Set(this.data.map(item => item.ATAName))];
this.updateTable();
@ -304,16 +326,16 @@ class InterfaceConfig extends HTMLElement {
// 通知所有子组件数据已更新
const importDialog = this.shadowRoot.querySelector('import-dialog');
if (importDialog) {
importDialog.setOptions(this.products, this.atas);
importDialog.setOptions(this.planes, this.atas);
}
const variableForm = this.shadowRoot.querySelector('variable-form');
if (variableForm) {
variableForm.setOptions(this.products, this.atas);
variableForm.setOptions(this.planes, this.atas);
}
} catch (error) {
console.error('加载数据时出错:', error);
alert('加载数据失败');
alert(error.message || '加载数据失败');
}
}
@ -333,7 +355,7 @@ class InterfaceConfig extends HTMLElement {
// 更新下拉选项
toolbar.updateFilterOptions({
products: this.products,
planes: this.planes,
atas: this.atas,
structs
});

View File

@ -7,7 +7,7 @@ class InterfaceDataTable extends HTMLElement {
this.selectedRows = new Set();
this.searchKeyword = '';
this.filters = {
productName: '',
planeName: '',
ataName: '',
structName: ''
};
@ -92,7 +92,7 @@ class InterfaceDataTable extends HTMLElement {
// 重置所有筛选条件
this.searchKeyword = '';
this.filters = {
productName: '',
planeName: '',
ataName: '',
structName: ''
};
@ -164,9 +164,9 @@ class InterfaceDataTable extends HTMLElement {
// 首先根据高级搜索条件过滤
let filtered = [...this.data];
if (this.filters.productName) {
if (this.filters.planeName) {
filtered = filtered.filter(item =>
item.ProductName === this.filters.productName
item.PlaneName === this.filters.planeName
);
}
if (this.filters.ataName) {
@ -209,8 +209,11 @@ class InterfaceDataTable extends HTMLElement {
this.selectedRows.clear();
// 设置新数据
this.data = data;
this.filteredData = [...data];
this.data = data.map((item, index) => ({
...item,
_displayIndex: index
}));
this.filteredData = [...this.data];
this.currentPage = 1;
this.render();
} finally {
@ -238,11 +241,7 @@ class InterfaceDataTable extends HTMLElement {
getCurrentPageData() {
const start = (this.currentPage - 1) * this.pageSize;
const end = start + this.pageSize;
return this.filteredData.slice(start, end).map((item, index) => ({
...item,
_displayIndex: start + index
}));
return this.filteredData.slice(start, start + this.pageSize);
}
setPage(page) {
@ -323,7 +322,7 @@ class InterfaceDataTable extends HTMLElement {
text-align: center;
}
.product-cell {
.plane-cell {
width: 60px;
}
@ -435,7 +434,7 @@ class InterfaceDataTable extends HTMLElement {
<th class="checkbox-cell">
<input type="checkbox" id="selectAll">
</th>
<th class="product-cell"></th>
<th class="plane-cell"></th>
<th class="ata-cell">ATA章节</th>
<th class="struct-cell">接口结构体名</th>
<th class="interface-cell">接口名称</th>
@ -451,16 +450,16 @@ class InterfaceDataTable extends HTMLElement {
<td class="checkbox-cell">
<input type="checkbox" class="row-checkbox" data-index="${item._displayIndex}">
</td>
<td>${item.ProductName || ''}</td>
<td>${item.PlaneName || ''}</td>
<td>${item.ATAName || ''}</td>
<td>${item.ModelStructName || ''}</td>
<td>${item.InterfaceName || ''}</td>
<td>${item.InterfaceType || ''}</td>
<td>${this.formatArraySize(item)}</td>
<td>${item.InterfaceNotes || ''}</td>
<td>
<button type="button" class="action-btn edit-btn" data-index="${item._displayIndex}">编辑</button>
<button type="button" class="action-btn delete-btn" data-index="${item._displayIndex}">删除</button>
<td class="action-cell">
<button class="action-btn edit-btn" data-index="${item._displayIndex}">编辑</button>
<button class="action-btn delete-btn" data-index="${item._displayIndex}">删除</button>
</td>
</tr>
`).join('')}
@ -471,7 +470,6 @@ class InterfaceDataTable extends HTMLElement {
<div class="loading-spinner"></div>
</div>
` : ''}
</div>
<div class="pagination">
<button id="firstPage" ${this.currentPage === 1 ? 'disabled' : ''}>首页</button>
<button id="prevPage" ${this.currentPage === 1 ? 'disabled' : ''}>上一页</button>
@ -485,6 +483,7 @@ class InterfaceDataTable extends HTMLElement {
<option value="100" ${this.pageSize === 100 ? 'selected' : ''}>100/</option>
</select>
</div>
</div>
`;
this.bindEventListeners();
}
@ -607,7 +606,7 @@ class InterfaceDataTable extends HTMLElement {
const resetSearchHandler = async () => {
this.searchKeyword = '';
this.filters = {
productName: '',
planeName: '',
ataName: '',
structName: ''
};

View File

@ -3,7 +3,7 @@ class ImportDialog extends HTMLElement {
super();
this.attachShadow({ mode: 'open' });
this.data = [];
this.products = [];
this.planes = [];
this.atas = [];
}
@ -13,25 +13,15 @@ class ImportDialog extends HTMLElement {
}
// 接收父组件传递的选项数据
setOptions(products, atas) {
this.products = products;
setOptions(planes, atas) {
this.planes = planes;
this.atas = atas;
this.updateProductOptions();
this.updateAtaOptions();
}
updateProductOptions() {
const select = this.shadowRoot.querySelector('#product-select');
select.innerHTML = `
<option value="">请选择构型</option>
${this.products.map(product => `
<option value="${product}">${product}</option>
`).join('')}
`;
}
updateAtaOptions() {
const select = this.shadowRoot.querySelector('#ata-select');
if (select) {
select.innerHTML = `
<option value="">请选择ATA章节</option>
${this.atas.map(ata => `
@ -39,6 +29,7 @@ class ImportDialog extends HTMLElement {
`).join('')}
`;
}
}
show(data) {
this.data = data;
@ -83,14 +74,21 @@ class ImportDialog extends HTMLElement {
});
confirmBtn.addEventListener('click', () => {
const productSelect = this.shadowRoot.querySelector('#product-select');
const ataSelect = this.shadowRoot.querySelector('#ata-select');
const modelInput = this.shadowRoot.querySelector('#model-input');
if (!productSelect.value) {
alert('请选择构型');
// 从 localStorage 获取机型信息
const savedSelection = localStorage.getItem('xnsim-selection');
if (!savedSelection) {
alert('请先选择机型');
return;
}
const selection = JSON.parse(savedSelection);
if (!selection.configurationId) {
alert('请先选择机型');
return;
}
if (!ataSelect.value) {
alert('请选择ATA章节');
return;
@ -105,7 +103,7 @@ class ImportDialog extends HTMLElement {
// 处理数据,转换为数据库格式
const processedData = this.data.map(item => ({
SystemName: 'XNSim', // 系统名称固定为XNSim
ProductName: productSelect.value,
PlaneName: selection.plane,
ATAName: ataSelect.value,
ModelStructName: `${modelName}_${item.structName}`,
InterfaceName: lowercaseCheckbox.checked ? item.name.toLowerCase() : item.name,
@ -114,7 +112,8 @@ class ImportDialog extends HTMLElement {
InterfaceIsArray: item.isArray ? 1 : 0, // 确保是数字类型
InterfaceArraySize_1: item.arraySize1 || 0, // 确保是数字类型
InterfaceArraySize_2: item.arraySize2 || 0, // 确保是数字类型
InterfaceNotes: item.description || '' // 确保不是null
InterfaceNotes: item.description || '', // 确保不是null
ConfID: selection.configurationId
}));
// 验证数据
@ -138,6 +137,11 @@ class ImportDialog extends HTMLElement {
}
render() {
// 从 localStorage 获取机型信息
const savedSelection = localStorage.getItem('xnsim-selection');
const selection = savedSelection ? JSON.parse(savedSelection) : null;
const planeName = selection?.plane || '';
this.shadowRoot.innerHTML = `
<style>
:host {
@ -263,19 +267,24 @@ class ImportDialog extends HTMLElement {
background-color: #f44336;
color: white;
}
.plane-info {
background-color: #f5f5f5;
padding: 10px;
border-radius: 4px;
margin-bottom: 15px;
font-size: 14px;
}
</style>
<div class="dialog">
<div class="header">
<div class="title">导入数据预览</div>
<button class="close-btn">&times;</button>
</div>
<div class="options">
<div class="option-group">
<label for="product-select">构型</label>
<select id="product-select">
<option value="">请选择构型</option>
</select>
<div class="plane-info">
当前机型${planeName}
</div>
<div class="options">
<div class="option-group">
<label for="ata-select">ATA章节</label>
<select id="ata-select">

View File

@ -11,7 +11,7 @@ class InterfaceToolbar extends HTMLElement {
2. IDL文件格式规范
module XNSim {
// 型名称
// 型名称
module C909 {
// ATA章节名称
module ATAxx {
@ -68,7 +68,6 @@ class InterfaceToolbar extends HTMLElement {
const resetBtn = this.shadowRoot.querySelector('.reset-btn');
const advancedSearchBtn = this.shadowRoot.querySelector('.advanced-search-btn');
const advancedSearchPanel = this.shadowRoot.querySelector('.advanced-search-panel');
const productSelect = this.shadowRoot.querySelector('#filterProduct');
const ataSelect = this.shadowRoot.querySelector('#filterAta');
const structSelect = this.shadowRoot.querySelector('#filterStruct');
const importModal = this.shadowRoot.querySelector('#importModal');
@ -142,7 +141,6 @@ class InterfaceToolbar extends HTMLElement {
// 重置搜索框
searchInput.value = '';
// 重置高级搜索下拉框
productSelect.value = '';
ataSelect.value = '';
structSelect.value = '';
// 触发重置事件
@ -156,11 +154,10 @@ class InterfaceToolbar extends HTMLElement {
});
// 监听高级搜索的筛选条件变化
[productSelect, ataSelect, structSelect].forEach(select => {
[ataSelect, structSelect].forEach(select => {
select.addEventListener('change', () => {
this.dispatchEvent(new CustomEvent('advanced-search', {
detail: {
productName: productSelect.value,
ataName: ataSelect.value,
structName: structSelect.value
}
@ -430,9 +427,6 @@ class InterfaceToolbar extends HTMLElement {
</div>
</div>
<div class="advanced-search-panel">
<select id="filterProduct">
<option value="">选择构型</option>
</select>
<select id="filterAta">
<option value="">选择ATA章节</option>
</select>
@ -480,14 +474,9 @@ class InterfaceToolbar extends HTMLElement {
}
updateFilterOptions(options) {
const productSelect = this.shadowRoot.querySelector('#filterProduct');
const ataSelect = this.shadowRoot.querySelector('#filterAta');
const structSelect = this.shadowRoot.querySelector('#filterStruct');
// 更新构型选项
productSelect.innerHTML = '<option value="">选择构型</option>' +
options.products.map(product => `<option value="${product}">${product}</option>`).join('');
// 更新ATA章节选项
ataSelect.innerHTML = '<option value="">选择ATA章节</option>' +
options.atas.map(ata => `<option value="${ata}">${ata}</option>`).join('');

View File

@ -4,7 +4,7 @@ class VariableForm extends HTMLElement {
this.attachShadow({ mode: 'open' });
this.mode = 'add';
this.interfaceData = null;
this.products = [];
this.planes = [];
this.ataChapters = [];
this.modelStructs = [];
}
@ -15,21 +15,21 @@ class VariableForm extends HTMLElement {
}
// 接收父组件传递的选项数据
setOptions(products, atas) {
this.products = products;
setOptions(planes, atas) {
this.planes = planes;
this.ataChapters = atas;
this.updateProductOptions();
this.updatePlaneOptions();
this.updateAtaOptions();
}
updateProductOptions() {
const select = this.shadowRoot.querySelector('#productName');
updatePlaneOptions() {
const select = this.shadowRoot.querySelector('#planeName');
if (select) {
select.innerHTML = `
<option value="">请选择</option>
${this.products.map(product => `
<option value="${product}" ${this.interfaceData?.ProductName === product ? 'selected' : ''}>
${product}
<option value="">请选择</option>
${this.planes.map(plane => `
<option value="${plane}" ${this.interfaceData?.PlaneName === plane ? 'selected' : ''}>
${plane}
</option>
`).join('')}
`;
@ -50,9 +50,18 @@ class VariableForm extends HTMLElement {
}
}
async loadModelStructs(productName, ataName) {
async loadModelStructs(planeName, ataName) {
try {
const response = await fetch(`/api/interface/struct/list?systemName=XNSim&productName=${productName}&ataName=${ataName}`);
const savedSelection = localStorage.getItem('xnsim-selection');
if (!savedSelection) {
throw new Error('请先选择构型');
}
const selection = JSON.parse(savedSelection);
if (!selection.configurationId) {
throw new Error('请先选择构型');
}
const response = await fetch(`/api/interface/struct/list?systemName=XNSim&planeName=${planeName}&ataName=${ataName}&confID=${selection.configurationId}`);
if (!response.ok) {
throw new Error('获取模型结构体列表失败');
}
@ -61,7 +70,7 @@ class VariableForm extends HTMLElement {
this.updateModelStructSelect();
} catch (error) {
console.error('加载模型结构体列表失败:', error);
alert('加载模型结构体列表失败');
alert(error.message || '加载模型结构体列表失败');
}
}
@ -85,13 +94,13 @@ class VariableForm extends HTMLElement {
if (data) {
// 保存原始数据
this.originalData = {
ProductName: data.ProductName,
PlaneName: data.PlaneName,
ATAName: data.ATAName,
ModelStructName: data.ModelStructName,
InterfaceName: data.InterfaceName
};
// 如果是在编辑模式下,需要先加载模型结构体列表
this.loadModelStructs(data.ProductName, data.ATAName).then(() => {
this.loadModelStructs(data.PlaneName, data.ATAName).then(() => {
this.render();
this.addEventListeners();
this.show();
@ -120,7 +129,7 @@ class VariableForm extends HTMLElement {
addEventListeners() {
const form = this.shadowRoot.querySelector('form');
const cancelBtn = this.shadowRoot.querySelector('.cancel-btn');
const productSelect = this.shadowRoot.querySelector('#productName');
const planeSelect = this.shadowRoot.querySelector('#planeName');
const ataSelect = this.shadowRoot.querySelector('#ataName');
const interfaceNameInput = this.shadowRoot.querySelector('#interfaceName');
const isArrayCheckbox = this.shadowRoot.querySelector('#interfaceIsArray');
@ -128,19 +137,19 @@ class VariableForm extends HTMLElement {
const arraySize2Input = this.shadowRoot.querySelector('#interfaceArraySize_2');
// 监听构型和ATA章节的变化
productSelect.addEventListener('change', () => {
const productName = productSelect.value;
planeSelect.addEventListener('change', () => {
const planeName = planeSelect.value;
const ataName = ataSelect.value;
if (productName && ataName) {
this.loadModelStructs(productName, ataName);
if (planeName && ataName) {
this.loadModelStructs(planeName, ataName);
}
});
ataSelect.addEventListener('change', () => {
const productName = productSelect.value;
const planeName = planeSelect.value;
const ataName = ataSelect.value;
if (productName && ataName) {
this.loadModelStructs(productName, ataName);
if (planeName && ataName) {
this.loadModelStructs(planeName, ataName);
}
});
@ -185,7 +194,7 @@ class VariableForm extends HTMLElement {
const data = {
SystemName: 'XNSim',
ProductName: formData.get('productName'),
PlaneName: formData.get('planeName'),
ATAName: formData.get('ataName'),
ModelStructName: formData.get('modelStructName'),
InterfaceName: formData.get('interfaceName'),
@ -197,9 +206,22 @@ class VariableForm extends HTMLElement {
InterfaceNotes: formData.get('interfaceNotes')
};
// 从 localStorage 获取 ConfID
const savedSelection = localStorage.getItem('xnsim-selection');
if (!savedSelection) {
alert('请先选择机型');
return;
}
const selection = JSON.parse(savedSelection);
if (!selection.configurationId) {
alert('请先选择机型');
return;
}
data.ConfID = selection.configurationId;
// 如果是编辑模式,添加原始数据
if (this.mode === 'edit' && this.originalData) {
data.originalProductName = this.originalData.ProductName;
data.originalPlaneName = this.originalData.PlaneName;
data.originalATAName = this.originalData.ATAName;
data.originalModelStructName = this.originalData.ModelStructName;
data.originalInterfaceName = this.originalData.InterfaceName;
@ -208,11 +230,12 @@ class VariableForm extends HTMLElement {
// 验证必填字段
const requiredFields = [
'SystemName',
'ProductName',
'PlaneName',
'ATAName',
'ModelStructName',
'InterfaceName',
'InterfaceType'
'InterfaceType',
'ConfID'
];
const missingFields = requiredFields.filter(field => !data[field]);
@ -261,6 +284,11 @@ class VariableForm extends HTMLElement {
'float', 'double', 'long double', 'boolean'
];
// 从 localStorage 获取机型信息
const savedSelection = localStorage.getItem('xnsim-selection');
const selection = savedSelection ? JSON.parse(savedSelection) : null;
const planeName = selection?.plane || '';
this.shadowRoot.innerHTML = `
<style>
.form-overlay {
@ -359,23 +387,22 @@ class VariableForm extends HTMLElement {
.array-size-group input[type="number"] {
width: 100px;
}
.plane-info {
background-color: #f5f5f5;
padding: 10px;
border-radius: 4px;
margin-bottom: 15px;
}
</style>
<div class="form-overlay">
<div class="form-container">
<h2 class="form-title">${this.mode === 'add' ? '添加接口' : '编辑接口'}</h2>
<form>
<div class="form-group">
<label for="productName">构型</label>
<select id="productName" name="productName" required>
<option value="">请选择构型</option>
${this.products.map(product => `
<option value="${product}" ${this.interfaceData?.ProductName === product ? 'selected' : ''}>
${product}
</option>
`).join('')}
</select>
<div class="plane-info">
当前机型${planeName}
</div>
<form>
<input type="hidden" id="planeName" name="planeName" value="${planeName}">
<div class="form-group">
<label for="ataName">ATA章节</label>
<select id="ataName" name="ataName" required>