wwf
3 天以前 23fa268f56dcd99c8dcd46f50f3ffcaa4cdcbc49
entry/src/main/ets/pages/home/ActiveDetail.ets
@@ -1,38 +1,97 @@
import { router } from "@kit.ArkUI"
import { promptAction, router } from "@kit.ArkUI"
import { http } from "@kit.NetworkKit"
import { LvMarkdownIn } from "@luvi/lv-markdown-in"
import { HttpResponseResult } from "../../data/HttpResponse"
import { ROMAIN } from "../../utils/config"
class Activity {
  id: string = ''
  name: string = ''
  pic: string = ''
  startDate: string = ''
  endTime: string = ''
  signupCount: number = 0
  status: string = ''
  content: string = ''
}
@Entry
@Component
export struct ActiveDetail {
  @State index: number = 0
  @State hotTrainingId: string = ''
  @State activeInfo: Activity = {
    id: '',
    name: '',
    pic: '',
    startDate: '',
    endTime: '',
    signupCount: 0,
    status: '',
    content: '',
  }
  aboutToAppear(): void {
    interface Params {
      index: number
      id: string
    }
    const params: Params = router.getParams() as Params
    this.index = params.index
    this.hotTrainingId = params.id
    this.getDetail()
  }
  getDetail() {
    let httpRequest = http.createHttp();
    httpRequest.request(
      `${ROMAIN}/quiz-community/public/v1.0/home/hotTraining/details?hotTrainingId=${this.hotTrainingId}`,
      {
        method: http.RequestMethod.GET,
        header: { 'Content-Type': 'application/json', 'x-jwt-token': `Bearer ${AppStorage.get('x-jwt-token')}` },
      },
      (err, data) => {
        console.log('response', '/home/hotTraining/details')
        console.log(JSON.stringify(data.result))
        if (data.responseCode == 200) {
          const resData = (typeof data.result == 'string' ? JSON.parse(data.result) : data.result) as HttpResponseResult<Activity>
          if (resData.code == 200) {
            this.activeInfo = resData.data as Activity
          } else {
            promptAction.showToast({ message: resData.msg })
          }
        }
      }
    )
  }
  getTagFontColor(statusText: string) {
    switch (statusText) {
      case '报名中':
      case 'signup':
        return '#10920e'
      case '进行中':
      case 'training':
        return '#ffa100'
      default :
        return '#666666'
    }
  }
  getTagBgColor(statusText: string) {
    switch (statusText) {
      case '报名中':
  getTagBgColor(status: string) {
    switch (status) {
      case 'signup':
        return '#d5f2db'
      case '进行中':
      case 'training':
        return '#fff0cc'
      default :
        return '#ebebeb'
    }
  }
  getStatusText(status: string) {
    if (status == 'signup') {
      return '报名中'
    } else if (status == 'training') {
      return '进行中'
    } else if (status == 'finished') {
      return '已结束'
    }
    return ''
  }
  build() {
@@ -41,6 +100,9 @@
        Image($r('app.media.left_icon'))
          .width(20)
          .height(20)
          .onClick(() => {
            router.back()
          })
        Text('详情页')
          .fontSize(18)
          .fontWeight(700)
@@ -55,50 +117,40 @@
        .height(150)
      Column({ space: 14 }) {
        Text('北京人工智能IE')
        Text(this.activeInfo.name)
          .fontWeight(800)
          .width('100%')
        Row({ space: 10 }) {
          Text('报名中')
          Text(this.getStatusText(this.activeInfo.status))
            .fontSize(10)
            .fontWeight(500)
            .padding({ left: 4, right: 4, top: 2, bottom: 2 })
            .borderRadius(10)
            .fontColor(this.getTagFontColor('报名中'))
            .backgroundColor(this.getTagBgColor('报名中'))
            .fontColor(this.getTagFontColor(this.activeInfo.status))
            .backgroundColor(this.getTagBgColor(this.activeInfo.status))
          Row() {
            Image($r('app.media.date_icon'))
              .width(12)
              .height(12)
            Text('20250520-20250620')
            Text(`${this.activeInfo.startDate}-${this.activeInfo.endTime}`)
              .fontSize(10)
              .fontColor('#676767')
              .margin({ left: 4 })
          }
          Text(`80人已报名`)
          Text(`${this.activeInfo.signupCount}人已报名`)
            .fontSize(10)
            .fontColor('#676767')
        }
        .width('100%')
        .justifyContent(FlexAlign.Start)
        Text('课程介绍')
        LvMarkdownIn({ text: this.activeInfo.content })
          .width('100%')
          .fontSize(14)
          .fontWeight(800)
        Text('本课程是计算机网络技术、通信技术等专业的专业核心课程,旨在培养学生的网络技术职业能力、职业素养和创新能力。' +
          '\n采用项目式实训教学,通过引入一个循序渐进的企业网络组建案例,让学生在模拟真实场景中掌握中小型企业网络组建的知识和能力' +
          '教材内容覆盖华为“1+X”证书考试要求,包含大量实操练习。')
          .width('100%')
          .fontSize(13)
          .lineHeight(20)
          .height(560)
          .padding({ left: 10, right: 10 })
      }
      .padding(14)
    }
    .width('100%')
    .height('100%')