Browse Source

feat:修复我的交易列表没有占满窗口宽度,选中后看不清,表头与数据列不对齐的问题

yangyi 1 month ago
parent
commit
e8b5223b7e

+ 15 - 2
client/src/main/java/space/anyi/client/controller/MainController.java

@@ -8,8 +8,8 @@ import javafx.scene.Node;
 import javafx.scene.control.*;
 import javafx.scene.control.cell.PropertyValueFactory;
 import javafx.scene.layout.*;
-import javafx.scene.paint.Color;
 import javafx.geometry.Pos;
+import java.time.format.DateTimeFormatter;
 import space.anyi.client.App;
 import space.anyi.client.service.AiService;
 import space.anyi.client.service.BookService;
@@ -72,7 +72,7 @@ public class MainController {
     @FXML private TableColumn<UserTransactionDTO, String> transBookTitleCol;
     @FXML private TableColumn<UserTransactionDTO, Integer> transNumCol;
     @FXML private TableColumn<UserTransactionDTO, BigDecimal> transPriceCol;
-    @FXML private TableColumn<UserTransactionDTO, String> transTimeCol;
+    @FXML private TableColumn<UserTransactionDTO, java.time.LocalDateTime> transTimeCol;
     @FXML private VBox transEmptyState;
 
     // Profile tab
@@ -494,6 +494,19 @@ public class MainController {
         transNumCol.setCellValueFactory(new PropertyValueFactory<>("transactionNum"));
         transPriceCol.setCellValueFactory(new PropertyValueFactory<>("transactionPrice"));
         transTimeCol.setCellValueFactory(new PropertyValueFactory<>("transactionTime"));
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+        transTimeCol.setCellFactory(col -> new TableCell<>() {
+            @Override
+            protected void updateItem(java.time.LocalDateTime item, boolean empty) {
+                super.updateItem(item, empty);
+                if (empty || item == null) {
+                    setText(null);
+                } else {
+                    setText(item.format(formatter));
+                }
+            }
+        });
+        transTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
     }
 
     @FXML

+ 10 - 2
client/src/main/resources/css/style.css

@@ -90,9 +90,14 @@
     -fx-text-fill: -fx-text-secondary;
     -fx-font-size: 13px;
 }
+.table-view .column-header > .label {
+    -fx-alignment: center-left;
+}
 .table-view .column-header .label {
     -fx-text-fill: -fx-text-secondary;
     -fx-font-weight: bold;
+    -fx-padding: 0;
+    -fx-alignment: CENTER_LEFT;
 }
 .table-view .table-row-cell {
     -fx-background-color: transparent;
@@ -107,8 +112,11 @@
     -fx-background-color: -fx-primary-light;
 }
 .table-view .table-row-cell:selected {
-    -fx-background-color: -fx-primary-light;
-    -fx-text-fill: -fx-text;
+    -fx-background-color: -fx-primary;
+    -fx-text-fill: white;
+}
+.table-view .table-row-cell:selected .table-cell {
+    -fx-text-fill: white;
 }
 .table-view .table-cell {
     -fx-padding: 8px 16px;

+ 5 - 5
client/src/main/resources/fxml/trans.fxml

@@ -13,11 +13,11 @@
     <StackPane VBox.vgrow="ALWAYS">
         <TableView fx:id="transTable" VBox.vgrow="ALWAYS">
             <columns>
-                <TableColumn fx:id="transIdCol" text="交易编号" prefWidth="80"/>
-                <TableColumn fx:id="transBookTitleCol" text="书名" prefWidth="200"/>
-                <TableColumn fx:id="transNumCol" text="数量" prefWidth="80"/>
-                <TableColumn fx:id="transPriceCol" text="总价" prefWidth="120"/>
-                <TableColumn fx:id="transTimeCol" text="交易时间" prefWidth="220"/>
+                <TableColumn fx:id="transIdCol" text="交易编号" minWidth="60" prefWidth="80" maxWidth="100" sortable="false"/>
+                <TableColumn fx:id="transBookTitleCol" text="书名" minWidth="150" prefWidth="300" sortable="false"/>
+                <TableColumn fx:id="transNumCol" text="数量" minWidth="50" prefWidth="80" maxWidth="100" sortable="false"/>
+                <TableColumn fx:id="transPriceCol" text="总价" minWidth="80" prefWidth="120" maxWidth="150" sortable="false"/>
+                <TableColumn fx:id="transTimeCol" text="交易时间" minWidth="150" prefWidth="180" maxWidth="220" sortable="false"/>
             </columns>
         </TableView>
         <VBox fx:id="transEmptyState" visible="false" managed="false" styleClass="empty-state">