zhangjq
2026-01-27 6f51f667ae7b13dca029045c221d0b1722cf98df
public/pages/property/assetImportLog/assetImportLog.js
@@ -15,94 +15,168 @@
            }
        },
        _initMethod: function () {
            vc.component._listAssetImportLogs(DEFAULT_PAGE, DEFAULT_ROWS);
            // 标记组件未销毁
            this._isDestroyed = false;
            console.log('导入日志列表页面初始化,开始加载数据');
            // 直接调用数据加载方法,不等待mounted
            this._listAssetImportLogs(DEFAULT_PAGE, DEFAULT_ROWS);
        },
        _initEvent: function () {
            var $this = this;
            // 监听全局的assetImportLog事件
            vc.on('assetImportLog', 'listAssetImportLog', function (_param) {
                vc.component._listAssetImportLogs(DEFAULT_PAGE, DEFAULT_ROWS);
                // 检查组件是否已销毁
                if (!$this._isDestroyed) {
                    $this._listAssetImportLogs(DEFAULT_PAGE, DEFAULT_ROWS);
                }
            });
            // 监听分页事件
            vc.on('pagination', 'page_event', function (_currentPage) {
                vc.component._listAssetImportLogs(_currentPage, DEFAULT_ROWS);
                // 检查组件是否已销毁
                if (!$this._isDestroyed) {
                    $this._listAssetImportLogs(_currentPage, DEFAULT_ROWS);
                }
            });
        },
        _destroyedMethod: function () {
            console.log('导入日志列表页面已销毁,清理资源');
            // 标记组件已销毁,用于异步回调中检查
            vc.component._isDestroyed = true;
            this._isDestroyed = true;
        },
        methods: {
            _listAssetImportLogs: function (_page, _rows) {
                var param = {
                    params: {
                        page: _page,
                        row: _rows,
                        communityId: vc.getCurrentCommunity().communityId
                console.log('调用_listAssetImportLogs方法,页码:', _page, '行数:', _rows);
                var $this = this;
                try {
                    // 确保communityId正确获取
                    var currentCommunity = vc.getCurrentCommunity();
                    console.log('获取到的currentCommunity:', currentCommunity);
                    var communityId = currentCommunity ? currentCommunity.communityId : '';
                    console.log('获取到的communityId:', communityId);
                    if (!communityId) {
                        console.error('无法获取communityId');
                        return;
                    }
                };
                //发送get请求
                vc.http.apiGet('/assetImportLog/queryAssetImportLog',
                    param,
                    function (json, res) {
                        try {
                    var param = {
                        params: {
                            page: _page,
                            row: _rows,
                            communityId: communityId
                        }
                    };
                    console.log('发送请求的参数:', param);
                    //发送get请求
                    vc.http.apiGet('/assetImportLog/queryAssetImportLog',
                        param,
                        function (json, res) {
                            console.log('收到请求响应:', json, res);
                            try {
                                // 检查组件是否已销毁
                                if ($this._isDestroyed) {
                                    console.log('组件已销毁,跳过数据处理');
                                    return;
                                }
                                let _assetImportLogInfo = JSON.parse(json);
                                console.log('解析后的数据:', _assetImportLogInfo);
                                // 验证数据格式,确保所有必要字段存在
                                if (_assetImportLogInfo && _assetImportLogInfo.code == 0) {
                                    // 为组件数据添加默认值,防止出现undefined错误
                                    $this.assetImportLogInfo.total = _assetImportLogInfo.total || 0;
                                    $this.assetImportLogInfo.records = _assetImportLogInfo.records || 0;
                                    $this.assetImportLogInfo.logs = _assetImportLogInfo.data || [];
                                    console.log('设置组件数据:', $this.assetImportLogInfo);
                                    // 初始化分页组件
                                    vc.emit('pagination', 'init', {
                                        total: $this.assetImportLogInfo.records,
                                        dataCount: $this.assetImportLogInfo.total,
                                        currentPage: _page
                                    });
                                } else {
                                    // 数据格式不符合预期,显示友好错误信息
                                    console.warn('导入日志数据格式不符合预期:', _assetImportLogInfo);
                                    vc.toast('查询导入日志失败: ' + (_assetImportLogInfo.msg || '未知错误'));
                                    // 重置数据,避免显示旧数据
                                    $this.assetImportLogInfo.total = 0;
                                    $this.assetImportLogInfo.records = 0;
                                    $this.assetImportLogInfo.logs = [];
                                    // 重置分页组件
                                    vc.emit('pagination', 'init', {
                                        total: 0,
                                        dataCount: 0,
                                        currentPage: _page
                                    });
                                }
                            } catch (e) {
                                // 解析失败,显示友好错误信息
                                console.error('解析导入日志失败:', e, json);
                                vc.toast('解析导入日志失败: ' + e.message);
                                // 重置数据,避免显示旧数据
                                $this.assetImportLogInfo.total = 0;
                                $this.assetImportLogInfo.records = 0;
                                $this.assetImportLogInfo.logs = [];
                                // 重置分页组件
                                vc.emit('pagination', 'init', {
                                    total: 0,
                                    dataCount: 0,
                                    currentPage: _page
                                });
                            }
                        },
                        function (errInfo, error) {
                            // 检查组件是否已销毁
                            if (vc.component._isDestroyed) {
                                console.log('组件已销毁,跳过数据处理');
                            if ($this._isDestroyed) {
                                console.log('组件已销毁,跳过错误处理');
                                return;
                            }
                            
                            let _assetImportLogInfo = JSON.parse(json);
                            console.log('查询导入日志成功,返回数据:', _assetImportLogInfo);
                            // 详细记录错误信息,便于调试
                            console.error('请求导入日志失败:', errInfo, error);
                            
                            // 验证数据格式,确保所有必要字段存在
                            if (_assetImportLogInfo && _assetImportLogInfo.code == 0) {
                                // 为组件数据添加默认值,防止出现undefined错误
                                vc.component.assetImportLogInfo.total = _assetImportLogInfo.total || 0;
                                vc.component.assetImportLogInfo.records = _assetImportLogInfo.records || 0;
                                vc.component.assetImportLogInfo.logs = _assetImportLogInfo.data || [];
                                // 初始化分页组件
                                vc.emit('pagination', 'init', {
                                    total: vc.component.assetImportLogInfo.records,
                                    dataCount: vc.component.assetImportLogInfo.total,
                                    currentPage: _page
                                });
                            // 显示友好的错误信息
                            let errorMsg = '查询导入日志失败: ';
                            if (errInfo && errInfo.includes('Read timed out')) {
                                errorMsg += '请求超时,请稍后重试';
                            } else if (errInfo && errInfo.includes('I/O error')) {
                                errorMsg += '网络异常,请检查网络连接';
                            } else {
                                // 数据格式不符合预期,显示友好错误信息
                                console.warn('导入日志数据格式不符合预期:', _assetImportLogInfo);
                                vc.toast('查询导入日志失败: ' + (_assetImportLogInfo.msg || '未知错误'));
                                errorMsg += (errInfo || '未知错误');
                            }
                        } catch (e) {
                            // 解析失败,显示友好错误信息
                            console.error('解析导入日志失败:', e, json);
                            vc.toast('解析导入日志失败: ' + e.message);
                            vc.toast(errorMsg);
                            // 重置数据,避免显示旧数据
                            $this.assetImportLogInfo.total = 0;
                            $this.assetImportLogInfo.records = 0;
                            $this.assetImportLogInfo.logs = [];
                            // 重置分页组件
                            vc.emit('pagination', 'init', {
                                total: 0,
                                dataCount: 0,
                                currentPage: _page
                            });
                        }
                    },
                    function (errInfo, error) {
                        // 检查组件是否已销毁
                        if (vc.component._isDestroyed) {
                            console.log('组件已销毁,跳过错误处理');
                            return;
                        }
                        // 详细记录错误信息,便于调试
                        console.error('请求导入日志失败:', errInfo, error);
                        // 显示友好的错误信息
                        let errorMsg = '查询导入日志失败: ';
                        if (errInfo && errInfo.includes('Read timed out')) {
                            errorMsg += '请求超时,请稍后重试';
                        } else if (errInfo && errInfo.includes('I/O error')) {
                            errorMsg += '网络异常,请检查网络连接';
                        } else {
                            errorMsg += (errInfo || '未知错误');
                        }
                        vc.toast(errorMsg);
                    }
                );
                    );
                } catch (e) {
                    console.error('调用_listAssetImportLogs方法失败:', e);
                }
            },
            _queryData: function () {
                vc.component._listAssetImportLogs(DEFAULT_PAGE, DEFAULT_ROWS);
                this._listAssetImportLogs(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _openDetail: function (_log) {
                vc.jumpToPage('/#/pages/property/assetImportLogDetail?logId=' + _log.logId + "&logType=" + _log.logType);