1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/**
 入驻小区
 **/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            assetImportLogInfo: {
                logs: [],
                total: 0,
                records: 1,
                moreCondition: false,
                carNum: ''
            }
        },
        _initMethod: function () {
            vc.component._listAssetImportLogs(DEFAULT_PAGE, DEFAULT_ROWS);
        },
        _initEvent: function () {
            vc.on('assetImportLog', 'listAssetImportLog', function (_param) {
                vc.component._listAssetImportLogs(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('pagination', 'page_event', function (_currentPage) {
                vc.component._listAssetImportLogs(_currentPage, DEFAULT_ROWS);
            });
        },
        methods: {
            _listAssetImportLogs: function (_page, _rows) {
                // 查询导入日志,增加重试机制和超时设置
                function queryLogs(retryCount = 0) {
                    const maxRetries = 2;
                    console.log('查询导入日志,重试次数:', retryCount);
                    
                    var param = {
                        params: {
                            page: _page,
                            row: _rows,
                            communityId: vc.getCurrentCommunity().communityId
                        }
                    };
                    //发送get请求,增加超时设置为30秒
                    vc.http.apiGet('/assetImportLog/queryAssetImportLog',
                        param,
                        {
                            timeout: 30000 // 30秒超时
                        },
                        function (json, res) {
                            try {
                                let _assetImportLogInfo = JSON.parse(json);
                                console.log('查询导入日志成功,共', _assetImportLogInfo.data ? _assetImportLogInfo.data.length : 0, '条记录');
                                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
                                });
                            } catch (e) {
                                console.error('解析导入日志失败:', e, json);
                                vc.toast('解析导入日志失败: ' + e.message);
                            }
                        },
                        function (errInfo, error) {
                            console.error('请求导入日志失败:', errInfo, error);
                            
                            // 如果是网络错误或超时,且重试次数未达上限,则重试
                            if ((errInfo && (errInfo.includes('I/O error') || errInfo.includes('Read timed out') || errInfo.includes('timeout'))) && retryCount < maxRetries) {
                                console.log('网络错误或超时,准备重试,重试次数:', retryCount + 1);
                                // 延迟重试,避免立即重试
                                setTimeout(function() {
                                    queryLogs(retryCount + 1);
                                }, 1000);
                            } else {
                                // 显示友好的错误信息
                                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);
                            }
                        }
                    );
                }
                
                // 开始查询
                queryLogs();
            },
            _queryData: function () {
                vc.component._listAssetImportLogs(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _openDetail: function (_log) {
                vc.jumpToPage('/#/pages/property/assetImportLogDetail?logId=' + _log.logId + "&logType=" + _log.logType);
            }
        }
    });
})(window.vc);