59. [HarmonyOS NEXT 实战案例四] 天气应用网格布局(上)

简介: 天气应用是移动设备上常见的应用类型,它需要在有限的屏幕空间内展示多种天气信息,如当前温度、天气状况、未来天气预报、空气质量等。HarmonyOS NEXT提供的GridRow和GridCol组件非常适合实现这种复杂的信息展示布局。本教程将详细讲解如何使用这些组件构建一个美观、实用的天气应用界面。

[HarmonyOS NEXT 实战案例四] 天气应用网格布局(上)

项目已开源,开源地址: https://gitcode.com/nutpi/HarmonyosNextCaseStudyTutorial , 欢迎fork & star

效果演示

img_73aa8767.png

1. 概述

天气应用是移动设备上常见的应用类型,它需要在有限的屏幕空间内展示多种天气信息,如当前温度、天气状况、未来天气预报、空气质量等。HarmonyOS NEXT提供的GridRow和GridCol组件非常适合实现这种复杂的信息展示布局。本教程将详细讲解如何使用这些组件构建一个美观、实用的天气应用界面。

2. 数据结构设计

在实现天气应用界面之前,我们需要先定义相关的数据结构。在本案例中,我们定义了以下几个接口:

2.1 当前天气信息

interface CurrentWeather {
   
    temperature: number;  // 当前温度
    weatherType: string;  // 天气类型
    weatherIcon: ResourceStr;  // 天气图标
    location: string;  // 位置
    updateTime: string;  // 更新时间
}

2.2 天气详情信息

interface WeatherDetail {
   
    title: string;  // 标题
    value: string;  // 值
    unit: string;  // 单位
    icon: ResourceStr;  // 图标
}

2.3 每日天气预报

interface DailyForecast {
   
    date: string;  // 日期
    day: string;  // 星期几
    weatherType: string;  // 天气类型
    weatherIcon: ResourceStr;  // 天气图标
    highTemp: number;  // 最高温度
    lowTemp: number;  // 最低温度
}

2.4 每小时天气预报

interface HourlyForecast {
   
    time: string;  // 时间
    weatherIcon: ResourceStr;  // 天气图标
    temperature: number;  // 温度
}

3. 数据准备

在组件内部,我们准备了模拟的天气数据:

// 当前天气信息
private currentWeather: CurrentWeather = {
   
    temperature: 26,
    weatherType: '晴',
    weatherIcon: $r("app.media.sunny"),
    location: '北京市海淀区',
    updateTime: '10:30 更新'
};

// 天气详情信息
private weatherDetails: WeatherDetail[] = [
    {
    title: '体感温度', value: '28', unit: '°C', icon: $r("app.media.temperature") },
    {
    title: '湿度', value: '45', unit: '%', icon: $r("app.media.humidity") },
    {
    title: '气压', value: '1013', unit: 'hPa', icon: $r("app.media.pressure") },
    {
    title: '能见度', value: '25', unit: 'km', icon: $r("app.media.visibility") },
    {
    title: '风速', value: '3.5', unit: 'm/s', icon: $r("app.media.wind") },
    {
    title: '紫外线', value: '中等', unit: '', icon: $r("app.media.uv") }
];

// 每日天气预报
private dailyForecasts: DailyForecast[] = [
    {
    date: '6月1日', day: '今天', weatherType: '晴', weatherIcon: $r("app.media.sunny"), highTemp: 28, lowTemp: 18 },
    {
    date: '6月2日', day: '明天', weatherType: '多云', weatherIcon: $r("app.media.cloudy"), highTemp: 26, lowTemp: 17 },
    {
    date: '6月3日', day: '周五', weatherType: '小雨', weatherIcon: $r("app.media.rainy"), highTemp: 24, lowTemp: 16 },
    {
    date: '6月4日', day: '周六', weatherType: '阴', weatherIcon: $r("app.media.overcast"), highTemp: 25, lowTemp: 17 },
    {
    date: '6月5日', day: '周日', weatherType: '晴', weatherIcon: $r("app.media.sunny"), highTemp: 29, lowTemp: 19 }
];

// 每小时天气预报
private hourlyForecasts: HourlyForecast[] = [
    {
    time: '现在', weatherIcon: $r("app.media.sunny"), temperature: 26 },
    {
    time: '11:00', weatherIcon: $r("app.media.sunny"), temperature: 27 },
    {
    time: '12:00', weatherIcon: $r("app.media.sunny"), temperature: 28 },
    {
    time: '13:00', weatherIcon: $r("app.media.cloudy"), temperature: 28 },
    {
    time: '14:00', weatherIcon: $r("app.media.cloudy"), temperature: 27 },
    {
    time: '15:00', weatherIcon: $r("app.media.cloudy"), temperature: 26 },
    {
    time: '16:00', weatherIcon: $r("app.media.cloudy"), temperature: 25 },
    {
    time: '17:00', weatherIcon: $r("app.media.cloudy"), temperature: 24 }
];

4. 布局实现

4.1 整体布局结构

天气应用界面的整体结构如下:

Scroll() {
   
    Column() {
   
        // 当前天气信息
        this.CurrentWeatherSection()

        // 每小时天气预报
        this.HourlyForecastSection()

        // 每日天气预报
        this.DailyForecastSection()

        // 天气详情信息
        this.WeatherDetailsSection()
    }
    .width('100%')
    .padding(16)
}
.scrollBar(BarState.Off)
.scrollable(ScrollDirection.Vertical)
.width('100%')
.height('100%')
.backgroundColor('#F5F5F5')

整体布局使用了Scroll组件作为容器,使内容可以垂直滚动。内部使用Column组件垂直排列各个部分,包括当前天气信息、每小时天气预报、每日天气预报和天气详情信息。最外层的Scroll设置了100%宽高、隐藏滚动条和浅灰色背景。

4.2 当前天气信息部分

当前天气信息部分的实现如下:

@Builder
private CurrentWeatherSection() {
   
    Column() {
   
        Row() {
   
            Text(this.currentWeather.location)
                .fontSize(16)
                .fontColor('#333333')

            Text(this.currentWeather.updateTime)
                .fontSize(12)
                .fontColor('#666666')
                .margin({
    left: 8 })
        }
        .width('100%')
        .justifyContent(FlexAlign.SpaceBetween)

        Row() {
   
            Text(this.currentWeather.temperature.toString())
                .fontSize(64)
                .fontWeight(FontWeight.Bold)
                .fontColor('#333333')

            Text('°C')
                .fontSize(24)
                .fontColor('#333333')
                .margin({
    top: 12 })
        }
        .margin({
    top: 16 })

        Row() {
   
            Image(this.currentWeather.weatherIcon)
                .width(24)
                .height(24)

            Text(this.currentWeather.weatherType)
                .fontSize(16)
                .fontColor('#333333')
                .margin({
    left: 4 })
        }
        .margin({
    top: 8 })
    }
    .width('100%')
    .padding(16)
    .backgroundColor(Color.White)
    .borderRadius(16)
}

当前天气信息部分使用Column组件垂直排列以下元素:

  1. 位置和更新时间:使用Row组件水平排列,两端对齐
  2. 温度:使用Row组件水平排列温度数值和单位
  3. 天气类型:使用Row组件水平排列天气图标和天气类型文本

4.3 每小时天气预报部分

每小时天气预报部分的实现如下:

@Builder
private HourlyForecastSection() {
   
    Column() {
   
        Text('24小时预报')
            .fontSize(16)
            .fontWeight(FontWeight.Bold)
            .width('100%')
            .textAlign(TextAlign.Start)

        Scroll() {
   
            Row() {
   
                ForEach(this.hourlyForecasts, (item: HourlyForecast) => {
   
                    Column() {
   
                        Text(item.time)
                            .fontSize(12)
                            .fontColor('#333333')

                        Image(item.weatherIcon)
                            .width(24)
                            .height(24)
                            .margin({
    top: 8, bottom: 8 })

                        Text(item.temperature.toString() + '°')
                            .fontSize(14)
                            .fontColor('#333333')
                    }
                    .width(64)
                    .alignItems(HorizontalAlign.Center)
                })
            }
        }
        .scrollable(ScrollDirection.Horizontal)
        .scrollBar(BarState.Off)
        .margin({
    top: 12 })
    }
    .width('100%')
    .padding(16)
    .backgroundColor(Color.White)
    .borderRadius(16)
    .margin({
    top: 16 })
}

每小时天气预报部分使用Column组件垂直排列以下元素:

  1. 标题:使用Text组件显示"24小时预报",设置16的字体大小、粗体字重和左对齐
  2. 滚动区域:使用Scroll组件,内部使用Row组件水平排列每小时天气信息
  3. 每小时天气信息:使用Column组件垂直排列时间、天气图标和温度

4.4 每日天气预报部分

每日天气预报部分的实现如下:

@Builder
private DailyForecastSection() {
   
    Column() {
   
        Text('未来5天')
            .fontSize(16)
            .fontWeight(FontWeight.Bold)
            .width('100%')
            .textAlign(TextAlign.Start)

        ForEach(this.dailyForecasts, (item: DailyForecast) => {
   
            Row() {
   
                Text(item.date)
                    .fontSize(14)
                    .fontColor('#333333')
                    .width('25%')

                Text(item.day)
                    .fontSize(14)
                    .fontColor('#333333')
                    .width('15%')

                Row() {
   
                    Image(item.weatherIcon)
                        .width(24)
                        .height(24)

                    Text(item.weatherType)
                        .fontSize(14)
                        .fontColor('#333333')
                        .margin({
    left: 4 })
                }
                .width('30%')

                Row() {
   
                    Text(item.lowTemp.toString() + '°')
                        .fontSize(14)
                        .fontColor('#666666')

                    Text(' / ')
                        .fontSize(14)
                        .fontColor('#666666')

                    Text(item.highTemp.toString() + '°')
                        .fontSize(14)
                        .fontColor('#333333')
                }
                .width('30%')
                .justifyContent(FlexAlign.End)
            }
            .width('100%')
            .padding({
    top: 12, bottom: 12 })
            .justifyContent(FlexAlign.SpaceBetween)
            .border({
    width: {
    bottom: 1 }, color: '#F0F0F0', style: BorderStyle.Solid })
        })
    }
    .width('100%')
    .padding(16)
    .backgroundColor(Color.White)
    .borderRadius(16)
    .margin({
    top: 16 })
}

每日天气预报部分使用Column组件垂直排列以下元素:

  1. 标题:使用Text组件显示"未来5天",设置16的字体大小、粗体字重和左对齐
  2. 每日天气信息:使用ForEach循环遍历每日天气数据,每项使用Row组件水平排列日期、星期几、天气类型和温度范围

4.5 天气详情信息部分

天气详情信息部分的实现如下:

@Builder
private WeatherDetailsSection() {
   
    Column() {
   
        Text('详细信息')
            .fontSize(16)
            .fontWeight(FontWeight.Bold)
            .width('100%')
            .textAlign(TextAlign.Start)

        GridRow({
    columns: 3, gutter: 16 }) {
   
            ForEach(this.weatherDetails, (item: WeatherDetail) => {
   
                GridCol({
    span: 1 }) {
   
                    Column() {
   
                        Row() {
   
                            Image(item.icon)
                                .width(16)
                                .height(16)

                            Text(item.title)
                                .fontSize(12)
                                .fontColor('#666666')
                                .margin({
    left: 4 })
                        }
                        .width('100%')

                        Row() {
   
                            Text(item.value)
                                .fontSize(16)
                                .fontColor('#333333')

                            Text(item.unit)
                                .fontSize(12)
                                .fontColor('#666666')
                                .margin({
    left: 2 })
                        }
                        .margin({
    top: 8 })
                    }
                    .width('100%')
                    .padding(12)
                    .backgroundColor('#F9F9F9')
                    .borderRadius(12)
                }
            })
        }
        .margin({
    top: 12 })
    }
    .width('100%')
    .padding(16)
    .backgroundColor(Color.White)
    .borderRadius(16)
    .margin({
    top: 16, bottom: 16 })
}

天气详情信息部分使用Column组件垂直排列以下元素:

  1. 标题:使用Text组件显示"详细信息",设置16的字体大小、粗体字重和左对齐
  2. 网格布局:使用GridRow和GridCol组件实现3列网格布局,每个网格项显示一个天气详情信息

4.6 GridRow和GridCol配置

在天气详情信息部分,我们使用了GridRow和GridCol组件实现网格布局:

GridRow({
    columns: 3, gutter: 16 })

参数说明:

  • columns: 3:设置网格为3列布局
  • gutter: 16:设置网格项之间的间距为16vp
GridCol({
    span: 1 })

参数说明:

  • span: 1:设置该列占用1个网格单元

5. 布局效果分析

5.1 整体布局特点

本案例中的天气应用界面具有以下特点:

特点 描述
布局方式 垂直滚动的卡片式布局
背景色 #F5F5F5(浅灰色)
卡片背景色 白色
卡片圆角 16vp
卡片间距 16vp
卡片内边距 16vp

5.2 天气详情网格布局特点

天气详情部分的网格布局具有以下特点:

特点 描述
列数 3列
间距 16vp
网格项背景色 #F9F9F9(浅灰色)
网格项圆角 12vp
网格项内边距 12vp

6. GridRow和GridCol组件详解

6.1 GridRow组件

GridRow组件是HarmonyOS NEXT中实现网格布局的容器组件,它将子组件按照网格进行排列。GridRow组件的主要属性如下:

属性名 类型 描述
columns number \ GridRowColumnOptions 设置布局列数
gutter Length \ GutterOption 设置列间距
breakpoints { value: Array, reference: BreakpointsReference } 设置断点响应参考值
direction GridRowDirection 设置布局方向

其中,GridRowColumnOptions类型可以设置不同断点下的列数,GutterOption类型可以设置水平和垂直方向的间距。

6.2 GridCol组件

GridCol组件用于定义网格中的列项,它必须作为GridRow的子组件使用。GridCol组件的主要属性如下:

属性名 类型 描述
span number \ GridColSpanOption 设置跨列数
offset number \ GridColOffsetOption 设置偏移列数
order number \ GridColOrderOption 设置显示顺序

其中,GridColSpanOption、GridColOffsetOption和GridColOrderOption类型可以设置不同断点下的跨列数、偏移列数和显示顺序。

7. 完整代码

以下是天气应用网格布局的完整代码:

// 当前天气信息接口
interface CurrentWeather {
   
    temperature: number;  // 当前温度
    weatherType: string;  // 天气类型
    weatherIcon: ResourceStr;  // 天气图标
    location: string;  // 位置
    updateTime: string;  // 更新时间
}

// 天气详情信息接口
interface WeatherDetail {
   
    title: string;  // 标题
    value: string;  // 值
    unit: string;  // 单位
    icon: ResourceStr;  // 图标
}

// 每日天气预报接口
interface DailyForecast {
   
    date: string;  // 日期
    day: string;  // 星期几
    weatherType: string;  // 天气类型
    weatherIcon: ResourceStr;  // 天气图标
    highTemp: number;  // 最高温度
    lowTemp: number;  // 最低温度
}

// 每小时天气预报接口
interface HourlyForecast {
   
    time: string;  // 时间
    weatherIcon: ResourceStr;  // 天气图标
    temperature: number;  // 温度
}

@Component
export struct WeatherGrid {
   
    // 当前天气信息
    private currentWeather: CurrentWeather = {
   
        temperature: 26,
        weatherType: '晴',
        weatherIcon: $r("app.media.sunny"),
        location: '北京市海淀区',
        updateTime: '10:30 更新'
    };

    // 天气详情信息
    private weatherDetails: WeatherDetail[] = [
        {
    title: '体感温度', value: '28', unit: '°C', icon: $r("app.media.temperature") },
        {
    title: '湿度', value: '45', unit: '%', icon: $r("app.media.humidity") },
        {
    title: '气压', value: '1013', unit: 'hPa', icon: $r("app.media.pressure") },
        {
    title: '能见度', value: '25', unit: 'km', icon: $r("app.media.visibility") },
        {
    title: '风速', value: '3.5', unit: 'm/s', icon: $r("app.media.wind") },
        {
    title: '紫外线', value: '中等', unit: '', icon: $r("app.media.uv") }
    ];

    // 每日天气预报
    private dailyForecasts: DailyForecast[] = [
        {
    date: '6月1日', day: '今天', weatherType: '晴', weatherIcon: $r("app.media.sunny"), highTemp: 28, lowTemp: 18 },
        {
    date: '6月2日', day: '明天', weatherType: '多云', weatherIcon: $r("app.media.cloudy"), highTemp: 26, lowTemp: 17 },
        {
    date: '6月3日', day: '周五', weatherType: '小雨', weatherIcon: $r("app.media.rainy"), highTemp: 24, lowTemp: 16 },
        {
    date: '6月4日', day: '周六', weatherType: '阴', weatherIcon: $r("app.media.overcast"), highTemp: 25, lowTemp: 17 },
        {
    date: '6月5日', day: '周日', weatherType: '晴', weatherIcon: $r("app.media.sunny"), highTemp: 29, lowTemp: 19 }
    ];

    // 每小时天气预报
    private hourlyForecasts: HourlyForecast[] = [
        {
    time: '现在', weatherIcon: $r("app.media.sunny"), temperature: 26 },
        {
    time: '11:00', weatherIcon: $r("app.media.sunny"), temperature: 27 },
        {
    time: '12:00', weatherIcon: $r("app.media.sunny"), temperature: 28 },
        {
    time: '13:00', weatherIcon: $r("app.media.cloudy"), temperature: 28 },
        {
    time: '14:00', weatherIcon: $r("app.media.cloudy"), temperature: 27 },
        {
    time: '15:00', weatherIcon: $r("app.media.cloudy"), temperature: 26 },
        {
    time: '16:00', weatherIcon: $r("app.media.cloudy"), temperature: 25 },
        {
    time: '17:00', weatherIcon: $r("app.media.cloudy"), temperature: 24 }
    ];

    build() {
   
        Scroll() {
   
            Column() {
   
                // 当前天气信息
                this.CurrentWeatherSection()

                // 每小时天气预报
                this.HourlyForecastSection()

                // 每日天气预报
                this.DailyForecastSection()

                // 天气详情信息
                this.WeatherDetailsSection()
            }
            .width('100%')
            .padding(16)
        }
        .scrollBar(BarState.Off)
        .scrollable(ScrollDirection.Vertical)
        .width('100%')
        .height('100%')
        .backgroundColor('#F5F5F5')
    }

    @Builder
    private CurrentWeatherSection() {
   
        Column() {
   
            Row() {
   
                Text(this.currentWeather.location)
                    .fontSize(16)
                    .fontColor('#333333')

                Text(this.currentWeather.updateTime)
                    .fontSize(12)
                    .fontColor('#666666')
                    .margin({
    left: 8 })
            }
            .width('100%')
            .justifyContent(FlexAlign.SpaceBetween)

            Row() {
   
                Text(this.currentWeather.temperature.toString())
                    .fontSize(64)
                    .fontWeight(FontWeight.Bold)
                    .fontColor('#333333')

                Text('°C')
                    .fontSize(24)
                    .fontColor('#333333')
                    .margin({
    top: 12 })
            }
            .margin({
    top: 16 })

            Row() {
   
                Image(this.currentWeather.weatherIcon)
                    .width(24)
                    .height(24)

                Text(this.currentWeather.weatherType)
                    .fontSize(16)
                    .fontColor('#333333')
                    .margin({
    left: 4 })
            }
            .margin({
    top: 8 })
        }
        .width('100%')
        .padding(16)
        .backgroundColor(Color.White)
        .borderRadius(16)
    }

    @Builder
    private HourlyForecastSection() {
   
        Column() {
   
            Text('24小时预报')
                .fontSize(16)
                .fontWeight(FontWeight.Bold)
                .width('100%')
                .textAlign(TextAlign.Start)

            Scroll() {
   
                Row() {
   
                    ForEach(this.hourlyForecasts, (item: HourlyForecast) => {
   
                        Column() {
   
                            Text(item.time)
                                .fontSize(12)
                                .fontColor('#333333')

                            Image(item.weatherIcon)
                                .width(24)
                                .height(24)
                                .margin({
    top: 8, bottom: 8 })

                            Text(item.temperature.toString() + '°')
                                .fontSize(14)
                                .fontColor('#333333')
                        }
                        .width(64)
                        .alignItems(HorizontalAlign.Center)
                    })
                }
            }
            .scrollable(ScrollDirection.Horizontal)
            .scrollBar(BarState.Off)
            .margin({
    top: 12 })
        }
        .width('100%')
        .padding(16)
        .backgroundColor(Color.White)
        .borderRadius(16)
        .margin({
    top: 16 })
    }

    @Builder
    private DailyForecastSection() {
   
        Column() {
   
            Text('未来5天')
                .fontSize(16)
                .fontWeight(FontWeight.Bold)
                .width('100%')
                .textAlign(TextAlign.Start)

            ForEach(this.dailyForecasts, (item: DailyForecast) => {
   
                Row() {
   
                    Text(item.date)
                        .fontSize(14)
                        .fontColor('#333333')
                        .width('25%')

                    Text(item.day)
                        .fontSize(14)
                        .fontColor('#333333')
                        .width('15%')

                    Row() {
   
                        Image(item.weatherIcon)
                            .width(24)
                            .height(24)

                        Text(item.weatherType)
                            .fontSize(14)
                            .fontColor('#333333')
                            .margin({
    left: 4 })
                    }
                    .width('30%')

                    Row() {
   
                        Text(item.lowTemp.toString() + '°')
                            .fontSize(14)
                            .fontColor('#666666')

                        Text(' / ')
                            .fontSize(14)
                            .fontColor('#666666')

                        Text(item.highTemp.toString() + '°')
                            .fontSize(14)
                            .fontColor('#333333')
                    }
                    .width('30%')
                    .justifyContent(FlexAlign.End)
                }
                .width('100%')
                .padding({
    top: 12, bottom: 12 })
                .justifyContent(FlexAlign.SpaceBetween)
                .border({
    width: {
    bottom: 1 }, color: '#F0F0F0', style: BorderStyle.Solid })
            })
        }
        .width('100%')
        .padding(16)
        .backgroundColor(Color.White)
        .borderRadius(16)
        .margin({
    top: 16 })
    }

    @Builder
    private WeatherDetailsSection() {
   
        Column() {
   
            Text('详细信息')
                .fontSize(16)
                .fontWeight(FontWeight.Bold)
                .width('100%')
                .textAlign(TextAlign.Start)

            GridRow({
    columns: 3, gutter: 16 }) {
   
                ForEach(this.weatherDetails, (item: WeatherDetail) => {
   
                    GridCol({
    span: 1 }) {
   
                        Column() {
   
                            Row() {
   
                                Image(item.icon)
                                    .width(16)
                                    .height(16)

                                Text(item.title)
                                    .fontSize(12)
                                    .fontColor('#666666')
                                    .margin({
    left: 4 })
                            }
                            .width('100%')

                            Row() {
   
                                Text(item.value)
                                    .fontSize(16)
                                    .fontColor('#333333')

                                Text(item.unit)
                                    .fontSize(12)
                                    .fontColor('#666666')
                                    .margin({
    left: 2 })
                            }
                            .margin({
    top: 8 })
                        }
                        .width('100%')
                        .padding(12)
                        .backgroundColor('#F9F9F9')
                        .borderRadius(12)
                    }
                })
            }
            .margin({
    top: 12 })
        }
        .width('100%')
        .padding(16)
        .backgroundColor(Color.White)
        .borderRadius(16)
        .margin({
    top: 16, bottom: 16 })
    }
}

8. 与其他布局方式的比较

8.1 GridRow vs List布局

HarmonyOS NEXT提供了多种布局方式,除了GridRow和GridCol组件,还有List组件。下面是两者在天气详情信息展示中的比较:

特性 GridRow + GridCol List
布局方式 网格布局 列表布局
适用场景 多列展示,如天气详情信息 单列展示,如每日天气预报
响应式支持 原生支持断点响应 需要额外处理
间距设置 统一设置gutter 需要单独为每个子项设置margin
跨列能力 支持span属性设置跨列 不支持

8.2 适用场景

GridRow和GridCol组件在天气应用中适用于以下场景:

  • 天气详情信息的多列展示
  • 需要在不同屏幕尺寸下调整列数的响应式布局
  • 需要某些元素跨列的复杂布局

List组件在天气应用中适用于以下场景:

  • 每日天气预报的单列展示
  • 需要支持滚动的长列表
  • 需要支持列表项的增删改查操作

9. 总结

本教程详细讲解了如何使用HarmonyOS NEXT的GridRow和GridCol组件实现天气应用的网格布局。通过合理的数据结构设计和布局配置,我们实现了一个美观、实用的天气应用界面,包括当前天气信息、每小时天气预报、每日天气预报和天气详情信息。在下一篇教程中,我们将继续深入探讨如何优化这个布局,并添加更多交互功能和高级特性。

相关文章
|
10天前
|
存储 缓存 5G
鸿蒙 HarmonyOS NEXT端云一体化开发-云存储篇
本文介绍用户登录后获取昵称、头像的方法,包括通过云端API和AppStorage两种方式,并实现上传头像至云存储及更新用户信息。同时解决图片缓存问题,添加上传进度提示,支持自动登录判断,提升用户体验。
59 0
|
10天前
|
存储 负载均衡 数据库
鸿蒙 HarmonyOS NEXT端云一体化开发-云函数篇
本文介绍基于华为AGC的端云一体化开发流程,涵盖项目创建、云函数开通、应用配置及DevEco集成。重点讲解云函数的编写、部署、调用与传参,并涉及环境变量设置、负载均衡、重试机制与熔断策略等高阶特性,助力开发者高效构建稳定云端服务。
87 0
鸿蒙 HarmonyOS NEXT端云一体化开发-云函数篇
|
3月前
|
容器
HarmonyOS NEXT仓颉开发语言实战案例:外卖App
仓颉语言实战分享,教你如何用仓颉开发外卖App界面。内容包括页面布局、导航栏自定义、搜索框实现、列表模块构建等,附完整代码示例。轻松掌握Scroll、List等组件使用技巧,提升HarmonyOS应用开发能力。
|
2月前
|
安全 JavaScript API
鸿蒙开发核心要素
鸿蒙开发核心要素
|
3月前
|
存储 IDE 定位技术
【HarmonyOS 5】鸿蒙组件&模板服务详解 - 助力高效开发的利器
在移动应用开发领域,效率与质量始终是开发者追求的核心目标。鸿蒙系统作为新兴的操作系统,为开发者提供了丰富且强大的开发资源,其中鸿蒙组件&模板服务更是成为开发者快速构建高质量应用的得力助手。
133 0
HarmonyOS NEXT仓颉开发语言实战案例:电影App
周末好!本文分享使用仓颉语言重构ArkTS实现的电影App案例,对比两者在UI布局、组件写法及语法差异。内容包括页面结构、列表分组、分类切换与电影展示等。通过代码演示仓颉在HarmonyOS开发中的应用。##仓颉##ArkTS##HarmonyOS开发
|
3月前
|
容器
HarmonyOS NEXT仓颉开发语言实战案例:健身App
本期分享一个健身App首页的布局实现,顶部采用Stack容器实现重叠背景与偏移效果,列表部分使用List结合Scroll实现可滚动内容。代码结构清晰,适合学习HarmonyOS布局技巧。
HarmonyOS NEXT仓颉开发语言实战案例:小而美的旅行App
本文分享了一个旅行App首页的设计与实现,使用List容器搭配Row、Column布局完成个人信息、功能列表及推荐模块的排版,详细展示了HarmonyOS下的界面构建技巧。
|
3月前
|
容器
HarmonyOS NEXT仓颉开发语言实战案例:银行App
仓颉语言银行App项目分享,页面布局采用List容器,实现沉浸式体验与模块化设计。顶部资产模块结合Stack与Row布局,背景图与内容分离,代码清晰易懂;功能按钮部分通过负边距实现上移效果,圆角仅保留顶部;热门推荐使用header组件,结构更规范。整体代码风格与ArkTS相似,但细节更灵活,适合金融类应用开发。
|
10天前
|
存储 JSON 数据建模
鸿蒙 HarmonyOS NEXT端云一体化开发-云数据库篇
云数据库采用存储区、对象类型、对象三级结构,支持灵活的数据建模与权限管理,可通过AGC平台或本地项目初始化,实现数据的增删改查及端侧高效调用。
37 0