Quellcode durchsuchen

feat: 完成了战争历史下的数据请求和交互

YuJing vor 2 Wochen
Ursprung
Commit
228e096ad1

+ 5 - 5
features/feature/src/main/ets/Apis/HistoryApis.ets

@@ -1,5 +1,5 @@
 import { YTRequest } from "basic";
-import { HeroDeedItem, HistoryEventDetail, NesResponse, Query } from "../model/Index";
+import { HeroDeedItem, HistoryEventDetail, HistoryTimelineItem, NesResponse, Query } from "../model/Index";
 import { ApiUrl } from "./ApiUrl";
 
 export class HistoryApis {
@@ -9,13 +9,13 @@ export class HistoryApis {
   }
 
   // 获取中国近代战争历史时间线
-  static getModernWarTimeline(): Promise<NesResponse>{
-    return YTRequest.get<NesResponse>(ApiUrl.getModernWarTimeline, {})
+  static getModernWarTimeline(): Promise<HistoryTimelineItem[]>{
+    return YTRequest.post<HistoryTimelineItem[]>(ApiUrl.getModernWarTimeline, {})
   }
 
   // 获取今日的历史军事资讯列表
-  static getTodayInHistory(): Promise<HistoryEventDetail>{
-    return YTRequest.post<HistoryEventDetail>(ApiUrl.getTodayInHistory, {})
+  static getTodayInHistory(): Promise<HistoryEventDetail[]>{
+    return YTRequest.get<HistoryEventDetail[]>(ApiUrl.getTodayInHistory, {})
   }
 
   // 献花

+ 16 - 5
features/feature/src/main/ets/components/YtComp/YTDiaLogBuild.ets

@@ -1,5 +1,7 @@
 import { BasicType, YTAvoid } from 'basic'
 import { DiaLogPageEnum, DiaLogParam } from 'basic/src/main/ets/models/YTDiaLogModel'
+import { HistoryApis } from '../../Apis/HistoryApis'
+import { HistoryEventDetail } from '../../model/Index'
 import { NumberKeyBoard, NumberKeyBoardStyle } from './NumberKeyboard'
 import { YtDatePicker } from './YtDatePicker'
 import { _YtHeader } from './_YtHeader'
@@ -276,9 +278,19 @@ struct HistoryToday{
   @Event onBack: (ans?:ESObject) => void
   @Param @Require param: BasicType
 
-  @Local dataSource: Array<string> = new Array(10).fill('')
+  @Local dataSource: Array<HistoryEventDetail> = []
   @Local safeBottom: number = AppStorage.get(YTAvoid.SAFE_BOTTOM_KEY) as number
 
+  // 获取今日历史事件
+  async getHistoryToday(): Promise<void> {
+    this.dataSource = await HistoryApis.getTodayInHistory()
+  }
+
+
+  aboutToAppear(): void {
+    this.getHistoryToday()
+  }
+
   build() {
     Column({space: 18}){
       Row(){
@@ -302,20 +314,19 @@ struct HistoryToday{
             .each(i => {
               ListItem(){
                 Column({space: 10}){
-                  Text('1941年')
+                  Text(i.item.historyTime)
                     .fontSize(18)
                     .width("100%")
                     .fontWeight(500)
                     .fontColor('#FF333333')
 
-                  Text('中国海军新型驱逐舰完成首次远海训练')
+                  Text(i.item.title)
                     .width("100%")
                     .fontSize(14)
                     .fontWeight(400)
                     .fontColor('#FF333333')
 
-                  Text('近日,中国海军某新型驱逐舰圆满完成首次远海\n' +
-                    '实战化训练,检验了多项新型武器装备性能...')
+                  Text(i.item.content)
                     .width("100%")
                     .fontSize(14)
                     .fontWeight(300)

+ 4 - 4
features/feature/src/main/ets/model/Index.ets

@@ -46,10 +46,10 @@ export interface HistoryTimelineItem {
 
 // 今日历史事件咨询列表
 export interface HistoryEventDetail {
-  createBy: string | null;
-  createTime: string | null;
-  updateBy: string | null;
-  updateTime: string | null;
+  createBy: string;
+  createTime: string;
+  updateBy: string;
+  updateTime: string;
   contentId: string;
   historyTime: string;
   title: string;

+ 18 - 7
features/feature/src/main/ets/view/SecondView.ets

@@ -1,16 +1,27 @@
 import { YTAvoid } from "basic"
+import { HistoryApis } from "../Apis/HistoryApis"
+import { HistoryTimelineItem } from "../model/Index"
 import { uRouter } from "../utils/RouterUtils"
 
 
 @ComponentV2
 export struct SecondView {
   @Local safeTop: number = AppStorage.get(YTAvoid.SAFE_TOP_KEY) as number
-  @Local dataSource: Array<string> = new Array(18).fill('')
+  @Local dataSource: Array<HistoryTimelineItem> = []
 
   router2HistoryToday(){
     uRouter.router2HistoryToday()
   }
 
+  // 获取战争历史时间线
+  async getHistoryTimeline() {
+    this.dataSource = await HistoryApis.getModernWarTimeline()
+  }
+
+  aboutToAppear(): void {
+    this.getHistoryTimeline()
+  }
+
   build() {
     Column(){
       Column({space: 20}){
@@ -36,7 +47,7 @@ export struct SecondView {
         List({space: 17}){
           Repeat(this.dataSource)
             .each((i) => {
-              HistoryItem()
+              HistoryItem({data: i.item})
             })
         }
         .width("100%")
@@ -56,7 +67,7 @@ export struct SecondView {
 @ComponentV2
 struct HistoryItem{
   @Local h: number = 120
-
+  @Param @Require data: HistoryTimelineItem
 
   build() {
     Column({space: 5}){
@@ -65,7 +76,7 @@ struct HistoryItem{
           .width(35)
           .aspectRatio(1)
 
-        Text('1840')
+        Text(this.data.tagName)
           .fontSize(14)
           .fontWeight(400)
           .fontColor('#000000')
@@ -88,13 +99,13 @@ struct HistoryItem{
               .width(23)
               .aspectRatio(1)
 
-            Text('鸦片战争')
+            Text(this.data.title)
               .fontSize(16)
               .fontWeight(500)
               .fontColor('#333333')
           }
 
-          Text('中国近代史的开端,清政府战败,签订《南京条约》')
+          Text(this.data.content.replace(/<[^>]*>/g, ''))
             .fontSize(14)
             .fontWeight(400)
             .width("100%")
@@ -106,7 +117,7 @@ struct HistoryItem{
         .backgroundColor(Color.White)
         .alignItems(HorizontalAlign.Start)
         .constraintSize({minHeight: '115'})
-        .padding({ top: 10, left: 3, right: 3, bottom: 10 })
+        .padding({ top: 10, left: 10, right: 3, bottom: 10 })
       }
     }
     .width("100%")