chengjie 5 miesięcy temu
rodzic
commit
d8ac4ae429
1 zmienionych plików z 6 dodań i 288 usunięć
  1. 6 288
      public/mg/kylx365_db_admin.html

+ 6 - 288
public/mg/kylx365_db_admin.html

@@ -623,40 +623,11 @@
623 623
                                     </div>
624 624
                                 </div>
625 625
                             </template>
626
-                            <div v-if="queryResults && queryResults.length > 0" style="margin-top: 10px; color: #666; font-size: 12px;">
627
-                                调试信息: 
628
-                                表头列数: {{ tableColumns.length }}, 
629
-                                数据行数: {{ queryResults.length }}, 
630
-                                第一条数据: {{ JSON.stringify(queryResults[0]) }}
631
-                            </div>
626
+                            
632 627
                         </div>
633 628
                         <div v-else class="no-data">
634 629
                             查询未返回数据
635 630
                         </div>
636
-
637
-                        <!-- 分页控件 -->
638
-                        <div class="pagination" v-if="totalPages > 1 && allResults.length > pageSize">
639
-                            <button class="pagination-btn" :class="{ disabled: currentPage === 1 }"
640
-                                @click="changePage(1)">
641
-                                首页
642
-                            </button>
643
-                            <button class="pagination-btn" :class="{ disabled: currentPage === 1 }"
644
-                                @click="changePage(currentPage - 1)">
645
-                                上一页
646
-                            </button>
647
-                            <button v-for="page in displayedPages" :key="page" class="pagination-btn"
648
-                                :class="{ active: currentPage === page }" @click="changePage(page)">
649
-                                {{ page }}
650
-                            </button>
651
-                            <button class="pagination-btn" :class="{ disabled: currentPage === totalPages }"
652
-                                @click="changePage(currentPage + 1)">
653
-                                下一页
654
-                            </button>
655
-                            <button class="pagination-btn" :class="{ disabled: currentPage === totalPages }"
656
-                                @click="changePage(totalPages)">
657
-                                末页
658
-                            </button>
659
-                        </div>
660 631
                     </div>
661 632
                     <div v-else-if="queryExecuted" class="no-data">
662 633
                         查询未返回数据
@@ -691,32 +662,13 @@
691 662
                 isQueryLoading: false,
692 663
                 isColumnsLoading: false,
693 664
                 queryExecuted: false,
694
-                currentPage: 1,
695
-                pageSize: 100,
696
-                totalPages: 1,
697 665
                 allResults: [],
698 666
                 tableColumnsList: [], // 存储表格字段列表
699 667
                 limitOptions: [10, 100, 500, 1000, 2000, 3000], // LIMIT选项
700 668
                 selectedLimit: 100 // 默认选中的LIMIT值
701 669
             },
702 670
             computed: {
703
-                displayedPages() {
704
-                    const pages = [];
705
-                    const maxVisiblePages = 5;
706
-
707
-                    let startPage = Math.max(1, this.currentPage - Math.floor(maxVisiblePages / 2));
708
-                    let endPage = Math.min(this.totalPages, startPage + maxVisiblePages - 1);
709
-
710
-                    if (endPage - startPage + 1 < maxVisiblePages) {
711
-                        startPage = Math.max(1, endPage - maxVisiblePages + 1);
712
-                    }
713
-
714
-                    for (let i = startPage; i <= endPage; i++) {
715
-                        pages.push(i);
716
-                    }
717
-
718
-                    return pages;
719
-                }
671
+                
720 672
             },
721 673
             mounted() {
722 674
                 this.loadTables();
@@ -730,7 +682,7 @@
730 682
                     // 调用后端API获取表格列表
731 683
                     fetch('/api/GetKylx365Tables')
732 684
                         .then(response => {
733
-                            console.log('API响应状态:', response.status);
685
+                                                            // console.log('API响应状态:', response.status);
734 686
                             if (!response.ok) {
735 687
                                 throw new Error(`HTTP error! status: ${response.status}`);
736 688
                             }
@@ -1122,20 +1074,15 @@
1122 1074
 
1123 1075
                     this.isQueryLoading = true;
1124 1076
                     this.queryExecuted = true;
1125
-                    this.currentPage = 1;
1126 1077
 
1127 1078
                     // 重置查询结果
1128 1079
                     this.queryResults = [];
1129 1080
                     this.tableColumns = [];
1130 1081
                     this.allResults = [];
1131
-                    this.totalPages = 1;
1132 1082
 
1133
-                    console.log('执行SQL查询:', this.sqlQuery.trim());
1134
-                    console.log('查询状态: 开始执行,设置isQueryLoading为true');
1135 1083
 
1136 1084
                     // 调用后端API执行SQL查询,使用RunKylx365DBSql接口
1137 1085
                     const apiUrl = '/api/RunKylx365DBSql';
1138
-                    console.log('API URL:', apiUrl);
1139 1086
 
1140 1087
                     fetch(apiUrl, {
1141 1088
                         method: 'POST',
@@ -1148,14 +1095,12 @@
1148 1095
                         })
1149 1096
                     })
1150 1097
                         .then(response => {
1151
-                            console.log('API响应状态:', response.status);
1152 1098
                             if (!response.ok) {
1153 1099
                                 throw new Error(`HTTP error! status: ${response.status}`);
1154 1100
                             }
1155 1101
                             return response.json();
1156 1102
                         })
1157 1103
                         .then(data => {
1158
-                            console.log('查询返回原始数据:', data); // 添加日志
1159 1104
 
1160 1105
                             // 检查数据格式
1161 1106
                             let resultData = null;
@@ -1163,26 +1108,21 @@
1163 1108
 
1164 1109
                             // 检查标准格式 {"errcode": 10000, result: [...]}
1165 1110
                             if (data && typeof data === 'object' && 'errcode' in data) {
1166
-                                console.log('检测到标准响应格式,errcode:', data.errcode);
1167 1111
 
1168 1112
                                 if (data.errcode !== 10000) {
1169 1113
                                     errorMessage = data.errmsg || '查询返回错误';
1170 1114
                                     console.error('查询返回错误:', errorMessage);
1171 1115
                                 } else if (data.result && Array.isArray(data.result)) {
1172
-                                    console.log('标准格式: data.result 是数组');
1173 1116
                                     resultData = data.result;
1174 1117
                                 }
1175 1118
                             }
1176 1119
                             // 检查其他可能的格式
1177 1120
                             else if (data && Array.isArray(data)) {
1178
-                                console.log('替代格式: data 本身是数组');
1179 1121
                                 resultData = data;
1180 1122
                             } else if (data && typeof data === 'object') {
1181
-                                console.log('检查对象中的数组属性');
1182 1123
                                 // 尝试在对象中找到数组属性
1183 1124
                                 for (const key in data) {
1184 1125
                                     if (Array.isArray(data[key])) {
1185
-                                        console.log(`找到数组属性: ${key}`);
1186 1126
                                         resultData = data[key];
1187 1127
                                         break;
1188 1128
                                     }
@@ -1195,65 +1135,22 @@
1195 1135
                                 this.queryResults = [];
1196 1136
                                 this.tableColumns = [];
1197 1137
                             } else if (resultData && Array.isArray(resultData)) {
1198
-                                console.log('处理查询结果,数据长度:', resultData.length);
1199
-                                console.log('第一条记录:', JSON.stringify(resultData[0]));
1200 1138
                                 this.processQueryResults(resultData);
1201 1139
                             } else {
1202
-                                console.log('未找到有效的查询结果数据');
1203 1140
                                 this.queryResults = [];
1204 1141
                                 this.tableColumns = [];
1205 1142
                                 this.showToastMessage('查询未返回数据', 'info');
1206 1143
                             }
1207
-                            console.log('查询状态: 执行完成,设置isQueryLoading为false');
1208 1144
                             this.isQueryLoading = false;
1209 1145
                         })
1210 1146
                         .catch(error => {
1211 1147
                             this.showToastMessage('执行查询失败,请稍后重试', 'error');
1212 1148
                             this.isQueryLoading = false;
1213
-
1214
-                            // 模拟数据用于开发测试
1215
-                            if (window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1') {
1216
-                                console.log('在本地环境中使用模拟数据');
1217
-
1218
-                                // 根据选择的表格生成模拟数据
1219
-                                let mockData = [];
1220
-
1221
-                                if (this.selectedTable === 'users') {
1222
-                                    mockData = [
1223
-                                        { id: 1, username: 'admin', email: 'admin@example.com', password: '******', created_at: '2023-01-01 00:00:00', status: 1 },
1224
-                                        { id: 2, username: 'user1', email: 'user1@example.com', password: '******', created_at: '2023-01-02 10:30:00', status: 1 },
1225
-                                        { id: 3, username: 'user2', email: 'user2@example.com', password: '******', created_at: '2023-01-03 15:45:00', status: 0 }
1226
-                                    ];
1227
-                                } else if (this.selectedTable === 'products') {
1228
-                                    mockData = [
1229
-                                        { id: 1, name: '产品A', price: '99.99', category_id: 1, stock: 100, description: '这是产品A的描述' },
1230
-                                        { id: 2, name: '产品B', price: '199.99', category_id: 2, stock: 50, description: '这是产品B的描述' },
1231
-                                        { id: 3, name: '产品C', price: '299.99', category_id: 1, stock: 75, description: '这是产品C的描述' }
1232
-                                    ];
1233
-                                } else {
1234
-                                    // 生成通用模拟数据
1235
-                                    for (let i = 1; i <= 10; i++) {
1236
-                                        mockData.push({
1237
-                                            id: i,
1238
-                                            name: `示例名称 ${i}`,
1239
-                                            description: `这是示例描述 ${i}`,
1240
-                                            created_at: new Date().toISOString().slice(0, 19).replace('T', ' ')
1241
-                                        });
1242
-                                    }
1243
-                                }
1244
-
1245
-                                this.processQueryResults(mockData);
1246
-                            }
1247 1149
                         });
1248 1150
                 },
1249 1151
 
1250 1152
                 // 处理查询结果
1251 1153
                 processQueryResults(results) {
1252
-                    console.group('处理查询结果');
1253
-                    console.log('原始结果:', results);
1254
-                    console.log('结果类型:', typeof results);
1255
-                    console.log('是否为数组:', Array.isArray(results));
1256
-                    console.log('结果长度:', results ? results.length : 0);
1257 1154
 
1258 1155
                     // 确保结果是一个数组
1259 1156
                     if (!results || !Array.isArray(results) || results.length === 0) {
@@ -1261,7 +1158,6 @@
1261 1158
                         this.$set(this, 'queryResults', []);
1262 1159
                         this.$set(this, 'tableColumns', []);
1263 1160
                         this.$set(this, 'allResults', []);
1264
-                        this.$set(this, 'totalPages', 1);
1265 1161
                         this.showToastMessage('查询未返回数据', 'info');
1266 1162
                         console.groupEnd();
1267 1163
                         return;
@@ -1270,17 +1166,12 @@
1270 1166
                     // 创建深拷贝避免引用问题
1271 1167
                     const safeResults = JSON.parse(JSON.stringify(results));
1272 1168
 
1273
-                    console.log('第一条记录:', JSON.stringify(results[0]));
1274
-                    console.log('第一条记录详细属性:', Object.keys(results[0]));
1275
-                    console.log('第一条记录值:', results[0]);
1276 1169
 
1277 1170
                     try {
1278
-                        console.log('原始结果数据:', results);
1279 1171
                         
1280 1172
                         // 直接使用原始结果数据
1281 1173
                         const formattedResults = results;
1282 1174
 
1283
-                        console.log('格式化后的结果:', formattedResults);
1284 1175
                         
1285 1176
                         // 使用Vue.set确保响应式更新
1286 1177
                         this.$set(this, 'allResults', formattedResults);
@@ -1298,7 +1189,6 @@
1298 1189
                             });
1299 1190
                             
1300 1191
                             const columns = Array.from(allColumns);
1301
-                            console.log('提取的有效表格列:', columns);
1302 1192
                             
1303 1193
                             // 验证数据完整性
1304 1194
                             const missingData = formattedResults.filter(row => {
@@ -1314,109 +1204,17 @@
1314 1204
                             this.$set(this, 'tableColumns', []);
1315 1205
                         }
1316 1206
 
1317
-                        // 计算总页数
1318
-                        const totalPages = Math.ceil(formattedResults.length / this.pageSize);
1319
-                        console.log('计算的总页数:', totalPages);
1320
-                        this.$set(this, 'totalPages', totalPages);
1321
-
1322
-                        // 直接设置第一页数据
1323
-                        const startIndex = 0;
1324
-                        const endIndex = Math.min(this.pageSize, formattedResults.length);
1325
-                        this.$set(this, 'queryResults', formattedResults.slice(startIndex, endIndex));
1326
-
1327
-                        // 添加调试信息
1328
-                        console.log('处理后的最终数据状态:');
1329
-                        console.log('allResults:', JSON.parse(JSON.stringify(this.allResults)));
1330
-                        console.log('tableColumns:', JSON.parse(JSON.stringify(this.tableColumns)));
1331
-                        console.log('queryResults:', JSON.parse(JSON.stringify(this.queryResults)));
1332
-                        console.log('Vue实例数据:', this.$data);
1207
+                        
1208
+                        this.$set(this, 'queryResults', formattedResults);
1333 1209
 
1334 1210
                         this.showToastMessage(`查询成功,返回 ${formattedResults.length} 条记录`, 'success');
1211
+
1335 1212
                     } catch (error) {
1336 1213
                         console.error('处理查询结果时出错:', error);
1337 1214
                         this.showToastMessage('处理查询结果时出错: ' + error.message, 'error');
1338 1215
                         this.queryResults = [];
1339 1216
                         this.tableColumns = [];
1340 1217
                         this.allResults = [];
1341
-                        this.totalPages = 1;
1342
-                    }
1343
-                },
1344
-
1345
-                // 切换页面
1346
-                changePage(page) {
1347
-                    console.group('切换页面');
1348
-                    console.log('目标页码:', page);
1349
-                    console.log('当前页码:', this.currentPage);
1350
-                    console.log('总页数:', this.totalPages);
1351
-                    console.log('所有结果数量:', this.allResults ? this.allResults.length : 0);
1352
-                    console.log('每页显示数量:', this.pageSize);
1353
-                    console.log('当前queryResults:', this.queryResults);
1354
-                    console.log('当前tableColumns:', this.tableColumns);
1355
-
1356
-                    try {
1357
-                        // 验证页码
1358
-                        if (page < 1 || page > this.totalPages) {
1359
-                            console.warn('页码超出范围');
1360
-                            console.groupEnd();
1361
-                            return;
1362
-                        }
1363
-
1364
-                        if (page === this.currentPage) {
1365
-                            console.log('已经在当前页面');
1366
-                            console.groupEnd();
1367
-                            return;
1368
-                        }
1369
-
1370
-                        this.$set(this, 'currentPage', page);
1371
-
1372
-                        if (!this.allResults || this.allResults.length === 0) {
1373
-                            console.warn('没有可用的结果数据');
1374
-                            this.$set(this, 'queryResults', []);
1375
-                            console.groupEnd();
1376
-                            return;
1377
-                        }
1378
-
1379
-                        // 计算当前页的数据
1380
-                        const startIndex = (page - 1) * this.pageSize;
1381
-                        const endIndex = Math.min(startIndex + this.pageSize, this.allResults.length);
1382
-
1383
-                        console.log('计算的起始索引:', startIndex);
1384
-                        console.log('计算的结束索引:', endIndex);
1385
-
1386
-                        // 创建新的数组引用确保Vue能检测到变化
1387
-                        const newResults = this.allResults.slice(startIndex, endIndex);
1388
-                        console.log('新页数据数量:', newResults.length);
1389
-                        if (newResults.length > 0) {
1390
-                            console.log('第一条记录:', JSON.stringify(newResults[0]));
1391
-                            console.log('第一条记录的列:', Object.keys(newResults[0]));
1392
-                        }
1393
-
1394
-                        // 使用Vue.set确保响应式更新
1395
-                        this.$set(this, 'queryResults', newResults);
1396
-
1397
-                        // 额外检查数据绑定
1398
-                        this.$nextTick(() => {
1399
-                            console.log('视图更新后检查数据:');
1400
-                            console.log('表格列:', this.tableColumns);
1401
-                            console.log('查询结果:', this.queryResults);
1402
-                            console.log('表格列与数据匹配检查:');
1403
-                            
1404
-                            if (this.queryResults.length > 0 && this.tableColumns.length > 0) {
1405
-                                const firstRow = this.queryResults[0];
1406
-                                const missingColumns = this.tableColumns.filter(col => !(col in firstRow));
1407
-                                if (missingColumns.length > 0) {
1408
-                                    console.warn('以下列在数据中缺失:', missingColumns);
1409
-                                }
1410
-                            }
1411
-                            
1412
-                            console.groupEnd();
1413
-                        });
1414
-                    } catch (error) {
1415
-                        console.error('切换页面时出错:', error);
1416
-                        this.showToastMessage('切换页面时出错: ' + error.message, 'error');
1417
-                        // 重置为第一页
1418
-                        this.currentPage = 1;
1419
-                        this.$set(this, 'queryResults', this.allResults ? this.allResults.slice(0, this.pageSize) : []);
1420 1218
                     }
1421 1219
                 },
1422 1220
 
@@ -1450,86 +1248,6 @@
1450 1248
                     }, 3000);
1451 1249
                 },
1452 1250
 
1453
-                // 强制重新渲染表格
1454
-                forceRender() {
1455
-                    console.group('强制重新渲染');
1456
-                    this.isRendering = true;
1457
-                    
1458
-                    // 显示加载状态
1459
-                    this.showToastMessage('正在强制刷新数据展示...', 'info');
1460
-                    
1461
-                    console.log('当前数据状态:', {
1462
-                        allResults: this.allResults,
1463
-                        queryResults: this.queryResults,
1464
-                        tableColumns: this.tableColumns
1465
-                    });
1466
-                    
1467
-                    // 强制更新数据
1468
-                    const temp = JSON.parse(JSON.stringify(this.allResults));
1469
-                    this.$set(this, 'allResults', []);
1470
-                    
1471
-                    this.$nextTick(() => {
1472
-                        this.$set(this, 'allResults', temp);
1473
-                        this.changePage(this.currentPage);
1474
-                        
1475
-                        // 二次检查确保渲染完成
1476
-                        this.$nextTick(() => {
1477
-                            const rows = document.querySelectorAll('.data-table tbody tr');
1478
-                            console.log('强制更新后行数:', rows.length);
1479
-                            
1480
-                            if (rows.length === 0 && temp.length > 0) {
1481
-                                console.warn('强制刷新失败,尝试最终方案');
1482
-                                this.$set(this, 'queryResults', []);
1483
-                                this.$nextTick(() => {
1484
-                                    this.$set(this, 'queryResults', temp.slice(0, this.itemsPerPage));
1485
-                                });
1486
-                            }
1487
-                            
1488
-                            this.isRendering = false;
1489
-                            this.showToastMessage('数据展示已刷新', 'success');
1490
-                            console.log('强制更新完成');
1491
-                        });
1492
-                    });
1493
-                    
1494
-                    console.groupEnd();
1495
-                },
1496
-
1497
-                // 调试方法:打印当前数据状态
1498
-                debugDataState() {
1499
-                    console.group('当前数据状态');
1500
-                    console.log('allResults:', JSON.parse(JSON.stringify(this.allResults)));
1501
-                    console.log('queryResults:', JSON.parse(JSON.stringify(this.queryResults)));
1502
-                    console.log('tableColumns:', JSON.parse(JSON.stringify(this.tableColumns)));
1503
-                    console.log('当前页码:', this.currentPage);
1504
-                    console.log('总页数:', this.totalPages);
1505
-                    
1506
-                    // 检查DOM状态
1507
-                    this.$nextTick(() => {
1508
-                        console.log('DOM状态检查:');
1509
-                        console.log('表格元素:', document.querySelector('.data-table'));
1510
-                        console.log('表头列数:', document.querySelectorAll('.data-table thead th').length);
1511
-                        console.log('数据行数:', document.querySelectorAll('.data-table tbody tr').length);
1512
-                    });
1513
-                    
1514
-                    console.groupEnd();
1515
-                },
1516
-                
1517
-                // 添加数据变化监视器
1518
-                watch: {
1519
-                    queryResults: {
1520
-                        handler(newVal) {
1521
-                            console.log('queryResults changed:', newVal.length);
1522
-                            this.$nextTick(() => {
1523
-                                const rows = document.querySelectorAll('.data-table tbody tr');
1524
-                                if (newVal.length > 0 && rows.length === 0) {
1525
-                                    console.warn('数据存在但未渲染,触发强制刷新');
1526
-                                    this.forceRender();
1527
-                                }
1528
-                            });
1529
-                        },
1530
-                        deep: true
1531
-                    }
1532
-                }
1533 1251
             }
1534 1252
         });
1535 1253
     </script>