修复错误

This commit is contained in:
ChenYi 2025-07-16 17:08:11 +08:00
parent cd772d5b04
commit 3d4b568a3b

View File

@ -76,6 +76,11 @@ const fixedColumns = [
// - 使
const allColumns = computed(() => {
//
if (!isGridInitialized.value) {
return [...fixedColumns];
}
const columns = [...fixedColumns];
//
@ -100,12 +105,12 @@ const initDefaultColumns = () => {
}
};
//
const isGridInitialized = ref(false);
//
initDefaultColumns();
//
fetchDeviceOptions();
const formOptions: VbenFormProps = {
schema: querySchema.value,
initialValues: {
@ -189,7 +194,7 @@ const gridOptions: VxeGridProps<any> = {
highlight: true,
labelField: 'name',
},
columns: allColumns, // 使
columns: fixedColumns, // 使
height: 'auto',
keepSource: true,
pagerConfig: {
@ -323,34 +328,61 @@ watch(
},
);
//
const initializeGrid = async () => {
try {
//
await fetchDeviceOptions();
//
isGridInitialized.value = true;
//
if (gridApi && gridApi.setState) {
await nextTick();
gridApi.setState({
gridOptions: {
...gridOptions,
columns: allColumns.value,
},
});
}
//
if (DeviceType || DeviceId || FocusAddress || SystemName) {
//
setTimeout(() => {
if (gridApi) {
gridApi.reload();
}
}, 300);
}
} catch (error) {
console.error('初始化表格失败:', error);
}
};
//
watch(
() => [DeviceType, DeviceId, FocusAddress, SystemName],
async (newValues, oldValues) => {
//
if (newValues.some(val => val) && gridApi) {
//
await fetchDeviceOptions();
if (newValues.some(val => val) && gridApi && isGridInitialized.value) {
//
setTimeout(() => {
gridApi.reload();
}, 100);
}
},
{ immediate: true }
{ immediate: false } // false
);
//
//
onMounted(async () => {
//
if (DeviceType || DeviceId || FocusAddress || SystemName) {
//
await fetchDeviceOptions();
//
setTimeout(() => {
gridApi.reload();
}, 200);
}
// VXE
setTimeout(async () => {
await initializeGrid();
}, 100);
});
</script>