Explorar el Código

feat: 完善了请求的URL、 完成了首页下列表的请求

YuJing hace 2 semanas
padre
commit
a3e8b8863a

+ 16 - 16
commons/basic/src/main/ets/apis/YTRequest.ets

@@ -7,15 +7,15 @@ import axios, {
   FormData,
   InternalAxiosRequestConfig
 } from '@ohos/axios';
-import { ContextHelper, IBestToast, ReqString, YTLog } from '../../../../Index';
+import { ContextHelper, IBestToast, ReqString, YTLog, ytOaidUtils } from '../../../../Index';
 import { AppStorageKeyCollect } from '../constants';
 import { userInfo } from '../models/UserInfo';
 import { yTRouter } from '../utils/arkts/utils/YTRouter';
 
 
-export const baseURL: string = 'https://hm.ytpm.net/prod-activity'
+export const baseURL: string = 'https://hm-test.ytpm.net/prod-military'
 
-// export const baseURL: string = 'http://192.168.1.160:48103'
+// export const baseURL: string = 'http://192.168.1.20:25017'
 
 export const instance = axios.create({
   baseURL,
@@ -23,23 +23,23 @@ export const instance = axios.create({
 })
 
 // 添加请求拦截器
-instance.interceptors.request.use((config: InternalAxiosRequestConfig) => {
+instance.interceptors.request.use(async (config: InternalAxiosRequestConfig) => {
 
   // 对请求数据做点什么 - 为请求参数添加 token
-  if (AppStorage.get<string>(AppStorageKeyCollect.TOKEN)) {
-    config.headers.Authorization = AppStorage.get<string>(AppStorageKeyCollect.TOKEN)
-  }
+  // if (AppStorage.get<string>(AppStorageKeyCollect.TOKEN)) {
+  //   config.headers.Authorization = AppStorage.get<string>(AppStorageKeyCollect.TOKEN)
+  // }
 
   // 为请求参数添加 oaid
-  if ((config.method == 'get' || config.method == 'delete') && config.url) {
-    // if(config?.params) {
-    //   config.params.oaid = await ytOaidUtils.getOaid()
-    // }
-  } else {
-    // if(config?.data) {
-    //   config.data.oaid = await ytOaidUtils.getOaid()
-    // }
-  }
+  // if ((config.method == 'get' || config.method == 'delete') && config.url) {
+  //   if(config?.params) {
+  //     config.params.oaid = await ytOaidUtils.getOaid()
+  //   }
+  // } else {
+  //   if(config?.data) {
+  //     config.data.oaid = await ytOaidUtils.getOaid()
+  //   }
+  // }
 
 
   YTLog.info(config.data, '请求参数')

+ 31 - 0
features/feature/src/main/ets/Apis/ApiUrl.ets

@@ -0,0 +1,31 @@
+export class ApiUrl {
+  /**
+   * @description 获取军事资讯
+   * @method POST
+   */
+  static getMilitaryNews = '/api/military/news/getMilitaryNews';
+
+  /**
+   * @description 获取中国近代战争历史时间线
+   * @method POST
+   */
+  static getModernWarTimeline = '/api/military/news/getModernWarHistory';
+
+  /**
+   * @description 获取今日的历史军事资讯列表(自动补全)
+   * @method GET
+   */
+  static getTodayInHistory = '/api/military/news/today';
+
+  /**
+   * @description 献花
+   * @method GET
+   */
+  static giveFlowers = '/api/military/heroicModel/flowersNum';
+
+  /**
+   * @description 查询所有英雄事迹记录
+   * @method POST
+   */
+  static getAllHeroicModel = '/api/military/heroicModel/list';
+}

+ 30 - 0
features/feature/src/main/ets/Apis/HistoryApis.ets

@@ -0,0 +1,30 @@
+import { YTRequest } from "basic";
+import { HeroDeedItem, HistoryEventDetail, NesResponse, Query } from "../model/Index";
+import { ApiUrl } from "./ApiUrl";
+
+export class HistoryApis {
+  // 获取军事新闻
+  static getMilitaryNews(query: Query): Promise<NesResponse>{
+    return YTRequest.post<NesResponse, Query>(ApiUrl.getMilitaryNews, query)
+  }
+
+  // 获取中国近代战争历史时间线
+  static getModernWarTimeline(): Promise<NesResponse>{
+    return YTRequest.get<NesResponse>(ApiUrl.getModernWarTimeline, {})
+  }
+
+  // 获取今日的历史军事资讯列表
+  static getTodayInHistory(): Promise<HistoryEventDetail>{
+    return YTRequest.post<HistoryEventDetail>(ApiUrl.getTodayInHistory, {})
+  }
+
+  // 献花
+  static giveFlowers(contentId: number): Promise<HeroDeedItem>{
+    return YTRequest.get<HeroDeedItem>(ApiUrl.giveFlowers, { contentId })
+  }
+
+  // 获取英雄事迹列表
+  static getHeroDeedList(query: Query): Promise<NesResponse>{
+    return YTRequest.post<NesResponse, Query>(ApiUrl.getAllHeroicModel, query)
+  }
+}

+ 90 - 0
features/feature/src/main/ets/model/Index.ets

@@ -0,0 +1,90 @@
+// 军事咨询查询参数
+export interface Query{
+  limit?: number,
+  page?: number
+  type?: number
+  pageSizes?: number,
+  total?: number
+}
+
+// 军事咨询列表项
+export interface MilitaryNewsItem {
+  tagId: string;
+  createTime: string;
+  author: string | null;
+  appName: string;
+  appId: string;
+  contentId: string;
+  title: string;
+  tagName: string;
+  categoryName: string;
+  content: string;
+  categoryId: string;
+}
+
+// 军事咨询返回数据结构
+export interface NesResponse {
+  page: string;
+  total: string;
+  newList: MilitaryNewsItem[];
+}
+
+// 历史时间线
+export interface HistoryTimelineItem {
+  tagId: string;
+  createTime: string;
+  author: string | null;
+  appName: string;
+  appId: string;
+  contentId: string;
+  title: string;
+  tagName: string;
+  categoryName: string;
+  content: string;
+  categoryId: string;
+}
+
+// 今日历史事件咨询列表
+export interface HistoryEventDetail {
+  createBy: string | null;
+  createTime: string | null;
+  updateBy: string | null;
+  updateTime: string | null;
+  contentId: string;
+  historyTime: string;
+  title: string;
+  content: string;
+  delFlag: string;
+}
+
+// 英雄事迹列表项
+@ObservedV2
+export class HeroDeedItem {
+  createBy?: string;
+  createTime?: string;
+  updateBy?: string;
+  updateTime?: string;
+  contentId?: string;
+  heroName?: string;
+  period?: string;
+  type?: string;
+  description?: string;
+  heroicDeeds?: string;
+  flowersNum?: string;
+  delFlag?: string;
+}
+
+// 英雄事迹列表响应数据结构
+export class Response<T> {
+  records?: T;
+  total?: string;
+  size?: string;
+  current?: string;
+  orders?: ESObject[];
+  optimizeCountSql?: boolean;
+  searchCount?: boolean;
+  maxLimit?: string;
+  countId?: string;
+  pages?: string;
+}
+

+ 6 - 10
features/feature/src/main/ets/pages/MsgDetailPage.ets

@@ -1,13 +1,13 @@
 import { RouterPage, YTAvoid } from 'basic'
 import { _YtHeader } from '../components/YtComp/_YtHeader'
+import { MilitaryNewsItem } from '../model/Index'
 
 @ComponentV2
-@RouterPage
 struct MsgDetailPage {
   @Local safeTop: number = AppStorage.get(YTAvoid.SAFE_TOP_KEY) as number
   @Local safeBottom: number = AppStorage.get(YTAvoid.SAFE_BOTTOM_KEY) as number
 
-  @Param title: string = '中国海军新型驱逐舰完成首次远海训练中国海军新型驱逐舰完成首次远海训练中国海军新型驱逐舰完成首次远海训练中国海军新型驱逐舰完成首次远海训练'
+  @Param @Require item: MilitaryNewsItem
 
   build() {
     NavDestination() {
@@ -21,11 +21,7 @@ struct MsgDetailPage {
         Column(){
           List(){
             ListItem(){
-              Text('今夜,让我们一起想象漫步于一座静谧的森林。月光如轻纱般透过交错的枝叶,在你脚下的小径上洒下斑驳的光点。空气清凉而纯净,带着泥土和松针的芬芳。\n' +
-                '\n' +
-                '你深深吸一口气,能闻到树木的清香和雨后湿润的气息。耳边是轻柔的夜风拂过树梢的沙沙声,偶尔传来远处不知名昆虫的唧唧鸣叫,它们仿佛在为你唱着一首轻柔的摇篮曲。\n' +
-                '\n' +
-                '你的脚步很轻,很慢,每一步都让你离喧嚣更远,离内心的平静更近。前方的路柔和地延伸,你知道它是安全的,你可以完全放松下来,将自己交给这片宁静的天地。让森林的宁静包裹你,带你缓缓沉入安详的睡眠。')
+              Text(this.item.content.replace(/<[^>]*>/g, '\n').replace(/&nbsp;/g, ''))
                 .fontSize(14)
                 .lineHeight(22)
                 .fontWeight(400)
@@ -50,7 +46,7 @@ struct MsgDetailPage {
 
   @Builder
   titleComp(){
-    Text(this.title)
+    Text(this.item.title)
       .width(270)
       .maxLines(1)
       .fontSize(18)
@@ -61,6 +57,6 @@ struct MsgDetailPage {
 }
 
 @Builder
-function MsgDetailBuilder() {
-  MsgDetailPage()
+function MsgDetailBuilder(_: string, item: MilitaryNewsItem) {
+  MsgDetailPage({item: item})
 }

+ 3 - 2
features/feature/src/main/ets/utils/RouterUtils.ets

@@ -1,9 +1,10 @@
 import { yTRouter } from "basic";
 import { DiaLogPageEnum, DiaLogParam, YTDiaLogModel } from "basic/src/main/ets/models/YTDiaLogModel";
+import { MilitaryNewsItem } from "../model/Index";
 
 class RouterUtils {
-  router2MsgDetailPage(){
-    yTRouter.pushPathByName("MsgDetailPage", null)
+  router2MsgDetailPage(p: MilitaryNewsItem){
+    yTRouter.pushPathByName("MsgDetailPage", p)
   }
 
   router2HistoryToday(){

+ 11 - 10
features/feature/src/main/ets/view/MainView.ets

@@ -1,3 +1,5 @@
+import { DateFormat, YTDateUtil } from "basic";
+import { MilitaryNewsItem } from "../model/Index";
 import { uRouter } from "../utils/RouterUtils";
 import { MainViewModel } from "../viewModel/MainViewModel";
 
@@ -42,16 +44,17 @@ export struct MainView {
 
       Column(){
         List({space: 16}){
-          Repeat(this.vm.dataSource)
-            .each((item) => {
+          Repeat<MilitaryNewsItem>(this.vm.dataSource)
+            .each((item: RepeatItem<MilitaryNewsItem>) => {
               ListItem(){
-                MsgItem()
+                MsgItem({data: item.item})
               }
             })
         }
         .width("100%")
         .height("100%")
         .scrollBar(BarState.Off)
+        .onReachEnd(() => { if(this.vm.dataSource.length > 0) this.vm.getMilitaryNews(false) })
       }
       .width("100%")
       .layoutWeight(1)
@@ -66,12 +69,10 @@ export struct MainView {
 
 @ComponentV2
 struct MsgItem{
-  @Param title: string = '中国海军新型驱逐舰完成首次远海训练中国海军新型驱逐舰完成首次远海训练'
-  @Param description: string = '今日,中国海军某新型驱逐舰圆满完成首次远海实战化训练, 检验多项新型武器装备性能今日,中国海军某新型驱逐舰圆满完成首次远海实战化训练, 检验多项新型武器装备性能...'
-  @Param time: string = '2021-09-01'
+  @Param @Require data: MilitaryNewsItem
 
   routerPage(){
-    uRouter.router2MsgDetailPage()
+    uRouter.router2MsgDetailPage(this.data)
   }
 
   build() {
@@ -81,7 +82,7 @@ struct MsgItem{
           .width(18)
           .aspectRatio(1)
 
-        Text(this.title)
+        Text(this.data.title)
           .maxLines(1)
           .fontSize(16)
           .fontWeight(500)
@@ -92,7 +93,7 @@ struct MsgItem{
       .width("100%")
 
       Row(){
-        Text(this.description)
+        Text(this.data.content.replace(/<[^>]*>/g, ''))
           .maxLines(2)
           .fontSize(14)
           .fontColor('#7D7D7D')
@@ -101,7 +102,7 @@ struct MsgItem{
       .width("100%")
 
       Row(){
-        Text(this.time)
+        Text(YTDateUtil.formatDate(new Date(this.data.createTime), DateFormat.UNDERLINE))
           .fontSize(12)
           .fontColor('#333333')
           .textAlign(TextAlign.End)

+ 38 - 2
features/feature/src/main/ets/viewModel/MainViewModel.ets

@@ -1,10 +1,12 @@
-import { YTAvoid, yTRouter } from "basic"
+import { YTAvoid } from "basic"
+import { HistoryApis } from "../Apis/HistoryApis"
+import { MilitaryNewsItem, NesResponse, Query } from "../model/Index"
 
 @ObservedV2
 export class MainViewModel{
   @Trace safeTop: number = 0
 
-  @Trace dataSource: Array<string> = new Array(10).fill('')
+  @Trace dataSource: Array<MilitaryNewsItem> = []
 
   @Trace selectIndex: number = -1
   @Trace areaList: Array<Area> = new Array(3)
@@ -12,17 +14,31 @@ export class MainViewModel{
   @Trace lineX: number = 32
   @Trace lineY: number = 102
 
+  query: Query = {
+    page: 1,
+    limit: 6,
+    // 类型 0全部.1国内 2国际
+    type: 0
+  }
+
   constructor() {
     this.safeTop = AppStorage.get(YTAvoid.SAFE_TOP_KEY) as number
+
+    this.getMilitaryNews()
   }
 
   // 更改选中的下标
   changeSelectIndex(i: number) {
+    if(this.selectIndex == i) return
+
     animateToImmediately({ duration: 200 }, () => {
       this.selectIndex = i
 
       this.lineX = this.areaList[i].globalPosition.x as number - 15
       this.lineY = this.areaList[i].globalPosition.y as number - 17
+
+      this.query.type = i
+      this.getMilitaryNews(true)
     })
   }
 
@@ -35,4 +51,24 @@ export class MainViewModel{
       this.lineWidth = this.areaList[i].width as number - 30
     }
   }
+
+  // 获取军事咨询
+  async getMilitaryNews(isReload: boolean = true) {
+    if (isReload) {
+      this.query.page = 1
+    } else {
+      if(this.dataSource.length >= this.query.total!) return
+      this.query.page!++
+    }
+
+    let ans: NesResponse = await HistoryApis.getMilitaryNews(this.query)
+
+    if(isReload){
+      this.dataSource = ans?.newList
+    } else {
+      this.dataSource.push(...ans?.newList)
+    }
+
+    this.query.total = Number.parseInt(ans?.total ?? "0")
+  }
 }