七、综合案例(携程口碑榜、QQ音乐排行榜、支付宝首页、网易云音乐推荐页面、小米商城首页)

1. 携程口碑榜

// 基础
// 241028 12:58完成
// 241029 老师讲解后修改

interface SelectMenu {
  title: string,
  isClicked: boolean,
}

interface ScenicSpot {
  img: ResourceStr,
  name: string,
  hot: number,
  score: number,
  comment: number,
  price?: number,
  reason: string,
  label: string[],
  address: string,
  distance: number
}

@Entry
@Component
struct Index {
  // 商业选择菜单
  @State
  menu: SelectMenu[] = [
    { title: '酒店', isClicked: false },
    { title: '景点', isClicked: false },
    { title: '夜游', isClicked: false },
    { title: '美食', isClicked: false },
  ]
  // 热门项目选项
  @State
  selectItem: string[] = ['必打卡', '滑雪', '亲子', '自然风光', '测试']
  // 热门景点列表
  @State
  scenic: ScenicSpot [] = [
    {
      img: $r('app.media.universal'),
      name: '北京环球度假区',
      hot: 9.8,
      score: 4.5,
      comment: 1.8,
      price: 308,
      reason: '这个冬天来环球影城,一起沉浸在冬日独有的浪漫,漫步在雪花飞舞的雪天,创造专属于这个冬天来环球影城,一起沉浸在冬日独有的浪漫,漫步在雪花飞舞的雪天,创造专属于',
      label: ['嗨玩乐园', '游乐园'],
      address: '北京 · 果园环岛/通州区',
      distance: 36.7
    },
    {
      img: $r('app.media.imperial'),
      name: '故宫博物院',
      hot: 10,
      score: 4.8,
      comment: 14.6,
      reason: '城墙建筑,院落布局,屋脊小兽,都包含着古代人民的巧夺天工,带小朋友穿梭明清时空,带小朋友穿梭明清时空',
      label: ['探秘展馆', '文化古迹', '博物馆', '场馆展馆'],
      address: '北京 · 天安门/王府井',
      distance: 16.5
    }
  ]

  // 携程口碑榜
  build() {
    Scroll() {
      Column() {
        // banner区域
        Column() {
          // logo
          Image($r('app.media.log'))
            .width(203)
            .position({ x: 77, y: 70 })
          // 底部 装饰线
          Image($r('app.media.banner_line'))
            .width('100%')
            .position({ y: 226 })
            .zIndex(1)
          // 右边 评选规则
          Text('评选规则')
            .width(54)
            .height(20)
            .fontColor('#f6dfc8')
            .fontSize(10)
            .textAlign(TextAlign.Center)
            .backgroundColor('#4dffe0d0')
            .position({ x: 305, y: 120 })
            .borderRadius({ topLeft: 50, bottomLeft: 50 })
          // 下方三个图片 推荐景点
          Row() {
            Image($r('app.media.ski'))
              .width(120)
            Image($r('app.media.hot'))
              .width(120)
            Image($r('app.media.rank'))
              .width(120)
          }
          .position({ y: 162 })
        }
        .width('100%')
        .height(267)
        .backgroundImage($r('app.media.banner'))
        .margin({ bottom: 12 })

        // 选择城市和目的地
        Row() {
          // 左边 选择城市
          Row({ space: 4 }) {
            Text('北京')
              .fontWeight(600)
              .fontColor('#5f2b0e')
            Image($r('app.media.ic_public_arrow_down_0'))
              .width(12)
              .fillColor('#fff')
              .backgroundColor('#5f2b0e')
              .borderRadius(6)
          }
          .width(163)
          .height('100%')
          .borderRadius(16)
          .linearGradient({
            angle: 90,
            colors: [['#ffe2c8', 0], ['#e6af8a', 1]]
          })
          .justifyContent(FlexAlign.Center)

          // 右边 口碑目的地
          Text('口碑目的地')
            .fontWeight(500)
            .fontColor('#99532e')
            .width(163)
            .height('100%')
            .backgroundColor('#f8d5b8')
            .borderRadius(16)
            .textAlign(TextAlign.Center)
        }
        .width('100%')
        .height(36)
        .margin({ top: 12, bottom: 12 })
        .padding({ left: 12, right: 12 })
        .justifyContent(FlexAlign.SpaceBetween)

        // 商业选项菜单
        Row() {
          ForEach(this.menu, (item: SelectMenu, index: number) => {
            Text(item.title)
              .fontColor(this.menu[index].isClicked ? '#ffffffff' : '#ff000000')
              .backgroundColor(this.menu[index].isClicked ? '#cccc9466' : '#ffffffff')
              .textAlign(TextAlign.Center)
              .width(78)
              .height('100%')
              .borderRadius(4)// 阴影
              .shadow({
                radius: 4,
                color: '#122f1b0e',
                offsetX: 1,
                offsetY: 1
              })
              .onClick(() => {
                this.menu[index] = {
                  title: this.menu[index].title,
                  isClicked: !this.menu[index].isClicked
                }
                console.log('索引' + index + ' 是否点击' + this.menu[index].isClicked);
              })
          })
        }
        .width('100%')
        .height(36)
        // .backgroundColor(Color.Yellow)
        .margin({ top: 12, bottom: 12 })
        .padding({ left: 12, right: 12 })
        .justifyContent(FlexAlign.SpaceBetween)

        // 热门项目选项 selectItem
        Row({ space: 25 }) {
          // 1. 近期热门
          Row() {
            Image($r('app.media.ic_hot'))
              .width(17)
              .fillColor('#99db935c')
            Text('近期热门')
              .fontWeight(600)
              .fontColor('#ff673915')
              .fontSize(14)
            // 亦可用背景图做
            /*Image($r('app.media.select'))
              .width(71)
              .height(5)
              .borderRadius(3)
              .linearGradient({
                colors: [['rgba(255, 226, 200, 0.4)', 0], ['rgba(230, 175, 138, 0.4)', 1]]
              })
              .position({ x: 0, y: '100%' })
              .translate({ x: 3, y: '-100%' })*/
          }
          .width(85)
          .height(18)
          .backgroundImage($r('app.media.select'))
          .backgroundImagePosition(Alignment.BottomStart)

          Scroll() {
            Row({ space: 25 }) {
              ForEach(this.selectItem, (item: string) => {
                Text(item)
                  .fontColor('#666666')
                  .fontSize(14)
              })
            }
          }
          .layoutWeight(1)
          .scrollable(ScrollDirection.Horizontal)
          .scrollBar(BarState.Off)
        }
        .width('100%')
        .height(18)
        .margin({ bottom: 12 })
        .padding({ left: 12 })

        // 热门榜标题
        Text('北京近期热门景点榜')
          .height(34)
          .fontWeight(600)
          .fontColor('#3d1a07')
          .fontSize(24)

        // 热门景点列表
        Column({ space: 12 }) {
          ForEach(this.scenic, (item: ScenicSpot, index: number) => {
            Row({ space: 8 }) {
              // 左边主图
              Image(item.img)
                .width(88)
                .height(175)
                .borderRadius(5)
              // 左上角排行定位区域
              Text(`NO.${index + 1}`)
                .width(50)
                .height(28)
                .fontWeight(700)
                .fontColor('#ff000000')
                .fontSize(11)
                .textAlign(TextAlign.Center)
                .backgroundImage($r('app.media.no_icon'))
                .position({ x: -4, y: 0 })
              // 右边
              Column({ space: 6 }) {
                // 景点名字
                Row({ space: 4 }) {
                  Text(item.name)
                    .fontWeight(600)
                    .fontColor('#ff333333')
                  Text('5A')
                    .height(16)
                    .backgroundColor('#eef1f6')
                    .borderRadius(4)
                    .fontSize(11)
                    .fontColor('#5678a8')
                    .padding({ left: 4, right: 4 })
                }
                .height(20)

                // 右上 喜欢收藏图标
                Image($r('app.media.ic_xihuan'))
                  .width(18)
                  .fillColor('#444444')
                  .position({ x: 198, y: 6 })
                // 第二行
                Row({ space: 9 }) {
                  Row() {
                    Image($r('app.media.ic_huo'))
                      .width(9)
                      .fillColor(Color.White)
                    Text(item.hot.toString())
                      .fontSize(14)
                      .fontColor(Color.White)
                  }
                  .height(18)
                  .borderRadius(4)
                  .linearGradient({
                    angle: 90,
                    colors: [['#ffff856e', 0], ['#ffff902a', 1]]
                  })
                  .padding({ left: 4, right: 4 })

                  Row({ space: 8 }) {
                    Text(`${item.score}分 ${item.comment}w条点评`)
                      .fontColor('#ff666666')
                      .fontSize(12)
                    if (item.price) {
                      Text(`¥${item.price}起`)
                        .fontColor('#ff666666')
                        .fontSize(12)
                    }
                  }
                  .height(18)
                }

                Text() {
                  ImageSpan($r('app.media.dianzan'))
                    .width(14)
                  Span('上榜理由:')
                    .fontWeight(600)
                  Span(item.reason)
                }
                .fontColor('#ff5f2b0e')
                .fontSize(13)
                .lineHeight(18)
                .width('100%')
                .height(72)
                .backgroundColor('#fffff7f1')
                .padding(8)
                .maxLines(3)
                .textOverflow({ overflow: TextOverflow.Ellipsis })

                Row({ space: 4 }) {
                  ForEach(item.label, (item: string) => {
                    Text(item)
                      .fontColor('#99aeca')
                      .fontSize(10)
                      .height(17)
                      .border({
                        width: 1,
                        color: '#ff99aeca',
                        radius: 4
                      })
                      .padding({ left: 4, right: 4 })
                  })
                }
                .height(17)

                Row({ space: 5 }) {
                  Image($r('app.media.ic_daohangdizhi'))
                    .width(12)
                    .fillColor('#999999')
                  Row() {
                    Text(item.address)
                      .fontColor('#999999')
                      .fontSize(12)
                    Blank()
                    Text(`距您${item.distance}km`)
                      .fontColor('#999999')
                      .fontSize(12)
                  }
                  .layoutWeight(1)
                  .height('100%')
                }
                .width('100%')
                .height(16)

              }
              .width(216)
              .height(175)
              .alignItems(HorizontalAlign.Start)

            }
            .width(336)
            .height(200)
            .padding(12)
            .backgroundColor('#FFFFFF')
            .shadow({
              offsetX: 0,
              offsetY: 2,
              radius: 8,
              color: '#1a000000'
            })
          })

        }
        .padding(12)
      }
      .width('100%')
      .backgroundColor('#FFFFFF')
    }
    .width('100%')
    .scrollBar(BarState.Off)
  }
}

2. QQ音乐排行榜

@Entry
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值