前言:一款面向出行场景的全能型旅行管家
随着移动出行需求的不断升级,旅行爱好者对于行前规划、行中导航、行后复盘的全流程数字化管理需求日益强烈。传统笔记类应用难以承载行程、地点、预算与攻略等多维度信息的整合,而单纯的地图类应用又缺少对预算与攻略内容的深度组织能力。本文所剖析的这款旅行行程规划APP,正是基于HarmonyOS ArkTS技术栈构建的一套轻量级、模块化、视觉鲜明的出行管理解决方案。它将一次完整的旅行拆解为"行程、地点、预算、攻略、个人统计"五大核心模块,通过底部Tab栏进行统一调度,使每一类信息都能找到属于自己的归属与表达方式。
相关服务:美国云服务器租用

在功能定位上,该APP并非简单地堆砌功能列表,而是围绕"一次旅行的生命周期"进行精心组织。用户可以在行程模块中创建并管理多次出行,每条行程都包含目的地、起止日期、天数、状态、预算、已花费用、交通方式、出行人数与标签等完整元数据。地点模块则承担"想去清单"的角色,将景点、餐厅、酒店、购物四类目标按城市与评分组织起来,并标注"必去"与"已去"状态。预算模块以可视化方式呈现支出分布,提供进度环、分类柱状图与明细列表三种视图,帮助用户在出行过程中实时把控花费。攻略模块汇集了社区精华内容,按美食、景点、交通、住宿、省钱五大类别进行分类筛选,为用户的决策提供参考。个人统计模块则汇总历史数据,通过数字看板与城市足迹标签云,让旅行的累积成果一目了然。
在设计理念上,该APP采用了一套富有辨识度的色彩语言。主色调使用天空蓝 #0288D1 与日落橙 #FF8F00 形成冷暖对比,前者代表广阔的天空与远方的目的地,后者代表温暖的夕阳与归途的烟火气。整体背景使用极浅的湖蓝 #E1F5FE,营造出一种轻盈通透的视觉氛围,与旅行这一主题高度契合。卡片设计大量采用线性渐变(linearGradient),让每张行程卡都像一张独立的明信片,色彩来自数据本身(coverColor),避免了千篇一律的视觉重复。这种"数据驱动配色"的设计思想,使得UI在承载信息的同时本身也成为了一种审美表达。
从技术架构来看,该APP遵循了ArkTS声明式UI的典型范式。底层通过一组 interface 类型定义数据契约,保证了数据结构的强类型与可推导性。中间层使用 @Observed 装饰器将数据模型包装为可观察对象,为后续的状态驱动UI刷新奠定基础。上层通过 @Entry @Component 装饰的入口组件承载底部Tab导航,每个Tab对应一个独立的 @Component 子组件,组件内部通过 @State 管理本地交互状态(如选中的筛选下标、弹窗显隐等)。UI的复用则通过 @Builder 方法实现,将卡片、弹窗、统计面板等高频出现的视觉单元抽象为可复用的构建函数。这种"类型—模型—组件—构建器"四层结构清晰、职责分明,是ArkTS中大型页面组织的推荐范式。
应用场景方面,这款APP适合广泛的出行人群。对于自由行爱好者,行程卡中的预算进度条可以实时提醒花费是否超支;对于美食与摄影爱好者,地点模块的必去标记和评分系统可以帮助筛选值得专程前往的目的地;对于家庭出游,预算分类柱状图可以让一家之主清晰掌握食宿行购的分摊比例;对于资深背包客,攻略模块的省钱技巧与交通指南则是行前必读的功课;而对于喜欢记录与回顾的旅行家,个人统计模块的足迹标签云与累计天数则是一种精神层面的满足与激励。可以说,这款APP在"工具属性"与"情感属性"之间找到了良好的平衡点。
一、类型契约层:interface 定义的数据骨架
1.1 行程标签类型 TripTagItem
interface TripTagItem {
name: string;
color: string;
}

TripTagItem 是整个数据模型中最细粒度的类型,它描述的是行程卡片底部那一排彩色小标签的结构。每个标签由 name(标签文字)和 color(标签背景色)两个字段组成。将颜色与标签绑定在一起,使得标签在渲染时无需再通过额外的映射函数查找颜色,渲染逻辑更直接、性能更优。这种设计也方便后续扩展,比如要为标签添加点击跳转或图标时,只需在该接口上增加字段即可,不会影响已有调用方。
1.2 行程主体类型 TripPlanData
interface TripPlanData {
id: number;
title: string;
destination: string;
startDate: string;
endDate: string;
days: number;
status: string;
coverColor: string;
budget: number;
spent: number;
transport: string;
travelers: number;
description: string;
tags: TripTagItem[];
}

TripPlanData 是行程模块的核心数据契约,它几乎承载了一次旅行所需的全部元数据。id 用于唯一标识与列表渲染时的 key 关联;title 与 destination 分别表示行程名称与目的地,两者在卡片头部以不同字号并列展示;startDate、endDate、days 三者构成时间维度,其中 days 字段冗余存储天数的目的是避免在渲染时反复进行日期计算;status 是一个字符串枚举(“规划中”、“进行中”、“已完成”),用于筛选与状态徽章渲染;coverColor 是该行程卡片的主题色,直接驱动渐变背景;budget 与 spent 用于计算预算消耗百分比与进度条;transport 与 travelers 提供出行方式与人数信息;description 是一段简短的行程说明;tags 则引用上一节的 TripTagItem 数组。这种"扁平+嵌套"的混合结构既保证了序列化的便利性,又保留了语义上的层次感。
1.3 地点类型 PlaceItemData
interface PlaceItemData {
id: number;
name: string;
city: string;
category: string;
address: string;
rating: number;
visitTime: string;
duration: string;
cost: number;
imageColor: string;
notes: string;
isMustVisit: boolean;
visited: boolean;
}

PlaceItemData 描述的是一个具体的旅行地点。除了基础的 id、name、city、address 之外,它特别强调了"旅行决策辅助"字段:rating(评分,用于星级渲染)、visitTime(建议到访时间)、duration(建议停留时长)、cost(人均费用,0 表示免费)。两个布尔字段 isMustVisit 与 visited 分别对应"必去清单"与"已打卡"两种状态,前者决定是否在卡片右上角显示红色"必去"徽章,后者决定是否在卡片底部显示绿色"已去"标记。imageColor 用于地点图标背景的浅色渲染(通过追加 22 透明度实现)。notes 字段存储用户对该地点的备注,在点击卡片后弹出的详情浮层中展示。这一数据结构的设计体现了"决策导向"的产品思维——每个字段都在帮助用户回答"去不去、什么时候去、去多久、花多少"这四个核心问题。
1.4 预算类型 BudgetItemData
interface BudgetItemData {
id: number;
category: string;
amount: number;
date: string;
description: string;
tripTitle: string;
icon: string;
color: string;
}

BudgetItemData 是预算明细的一条记录。category 是六大分类之一(交通、住宿、餐饮、门票、购物、其他),amount 是金额,date 是支出日期,description 是具体的支出说明(如"北京-东京往返机票"),tripTitle 关联到所属的行程,icon 与 color 则是该条目在列表中展示的视觉标识。值得注意的是,icon 和 color 直接存储在数据对象上而非通过 category 查找,这种"冗余存储"的设计使得每条记录都能独立渲染而不依赖全局映射表,在数据来源复杂(比如未来从服务器拉取)时具备更好的灵活性。同时,tripTitle 使用字符串而非外键 tripId,是一种简化版的关联方式,便于在列表中直接展示,无需再做一次关联查询。
1.5 攻略类型 GuideItemData
interface GuideItemData {
id: number;
title: string;
category: string;
author: string;
readCount: number;
coverColor: string;
summary: string;
tags: string[];
}

GuideItemData 描述的是一篇旅行攻略文章。title 是文章标题,category 是五大分类之一(美食攻略、景点推荐、交通指南、住宿推荐、省钱技巧),author 是作者,readCount 是阅读量(渲染时会自动转换为"万"单位),coverColor 是该卡片左侧的彩色边条颜色,summary 是一段摘要(最多两行,超出省略),tags 是字符串数组形式的标签。这里的 tags 与行程标签不同,它只是纯字符串,没有颜色信息,渲染时统一使用主色 #0288D1 加边框样式,形成一种"标签按钮"的视觉效果。这种设计简化了数据结构,同时通过统一的视觉样式保证了攻略列表的整齐美感。
1.6 统计类型 TravelStatData 与 BudgetCategoryStat
interface TravelStatData {
label: string;
value: number;
icon: string;
color: string;
}
interface BudgetCategoryStat {
name: string;
amount: number;
color: string;
icon: string;
}

这两个接口分别服务于个人统计模块和预算分类柱状图。TravelStatData 用于"已去城市、总行程数、旅行天数、花费金额"四项汇总指标的展示,每个指标都有自己的图标和主题色,使数字看板富有层次。BudgetCategoryStat 则描述了预算分类的元信息(名称、颜色、图标),amount 字段初始为0,运行时通过统计函数动态填充。将"分类配置"与"分类数据"分离,是典型的元数据/数据分离模式,使得分类的视觉规则可以集中维护,新增或调整分类时只需修改一处配置。
二、可观察数据模型层:@Observed 装饰器的应用
2.1 TripPlan 可观察类
@Observed
class TripPlan {
id: number = 0;
title: string = '';
destination: string = '';
// ...其余字段
tags: TripTagItem[] = [];
constructor(data: TripPlanData) {
this.id = data.id;
this.title = data.title;
// ...赋值
this.tags = data.tags;
}
}
TripPlan 是 TripPlanData 接口对应的可观察类版本。通过 @Observed 装饰器,该类的实例在被 @State 或 @ObjectLink 持有时,其属性变化能够触发依赖该属性的UI组件刷新。这种"接口定义数据形状 + 类提供可观察能力"的双层设计是ArkTS中的常见模式:接口用于纯数据传递(如Mock数据数组),类用于需要响应式更新的场景。构造函数接收一个 TripPlanData 参数,逐字段赋值,保证了从接口数据到可观察实例的平滑转换。所有字段都给出了默认值(0、空字符串、空数组),这是一种防御性编程习惯,避免了在部分字段缺失时出现 undefined 引发渲染异常。
2.2 PlaceItem 可观察类
@Observed
class PlaceItem {
id: number = 0;
name: string = '';
// ...
isMustVisit: boolean = false;
visited: boolean = false;
constructor(data: PlaceItemData) {
// ...
this.isMustVisit = data.isMustVisit;
this.visited = data.visited;
}
}
PlaceItem 的结构设计与 TripPlan 一脉相承。两个布尔字段 isMustVisit 和 visited 是该模型的关键状态字段,未来若实现"打卡"功能,只需修改 visited 属性即可触发卡片UI的实时更新("已去"标记的显示/隐藏)。这种通过属性驱动UI的方式,正是声明式UI的核心思想。值得注意的是,虽然当前Mock数据是静态的,但通过 @Observed 提前包装,为后续接入真实数据源(如本地数据库或云端API)打下了响应式基础,是一种"面向未来"的设计。
2.3 BudgetItem 与 GuideItem 可观察类
@Observed
class BudgetItem {
id: number = 0;
category: string = '';
amount: number = 0;
// ...
constructor(data: BudgetItemData) { /* ... */ }
}
@Observed
class GuideItem {
id: number = 0;
title: string = '';
// ...
tags: string[] = [];
constructor(data: GuideItemData) { /* ... */ }
}
BudgetItem 和 GuideItem 同样遵循接口到类的转换范式。BudgetItem 的 amount 字段在未来可以支持实时编辑金额并触发预算统计的重新计算;GuideItem 的 readCount 可以在用户点击阅读后自增并实时刷新阅读量显示。这些可观察类构成了APP的"数据神经系统",是UI与业务逻辑之间通信的桥梁。
三、静态配置常量:UI配置的集中管理
3.1 Tab配置接口与底部Tab常量
interface TabConfig {
label: string;
icon: string;
index: number;
}
const BOTTOM_TABS: TabConfig[] = [
{ label: '行程', icon: '🗺️', index: 0 },
{ label: '地点', icon: '📍', index: 1 },
{ label: '预算', icon: '💰', index: 2 },
{ label: '攻略', icon: '📖', index: 3 },
{ label: '我的', icon: '👤', index: 4 }
];
TabConfig 接口统一描述了所有Tab项的结构(文字、图标、序号),BOTTOM_TABS 常量则定义了底部Tab栏的五个入口。将Tab配置抽取为常量数组,使得 BottomTabBar Builder 可以通过 ForEach 遍历渲染,避免了重复的五段几乎相同的代码。这种"数据驱动UI"的方式大幅减少了代码体积,也使得未来新增Tab(如"消息"、“动态”)只需在数组中添加一项即可,无需改动渲染逻辑。index 字段与枚举值对应,保证了点击切换时的类型安全。
3.2 行程状态Tab与地点分类Tab
const TRIP_STATUS_TABS: TabConfig[] = [
{ label: '全部', icon: '📋', index: 0 },
{ label: '规划中', icon: '📝', index: 1 },
{ label: '进行中', icon: '✈️', index: 2 },
{ label: '已完成', icon: '✅', index: 3 }
];
const PLACE_CATEGORY_TABS: TabConfig[] = [
{ label: '全部', icon: '📍', index: 0 },
{ label: '景点', icon: '🏛️', index: 1 },
{ label: '餐厅', icon: '🍽️', index: 2 },
{ label: '酒店', icon: '🏨', index: 3 },
{ label: '购物', icon: '🛍️', index: 4 }
];
这两组Tab分别服务于行程模块的状态筛选和地点模块的分类筛选。它们复用了 TabConfig 接口,体现了类型抽象的复用价值。行程状态Tab使用不同的图标暗示状态语义(📝表示规划中的草拟感、✈️表示进行中的出发感、✅表示已完成的达成感),地点分类Tab则使用对应场景的常见图标(🏛️景点、🍽️餐厅、🏨酒店、🛍️购物)。这种"图标即语义"的设计让用户在快速扫视时就能识别每个Tab的含义,降低了认知成本。
3.3 预算分类与攻略分类常量
const BUDGET_CATEGORIES: BudgetCategoryStat[] = [
{ name: '交通', amount: 0, color: '#0288D1', icon: '✈️' },
{ name: '住宿', amount: 0, color: '#FF8F00', icon: '🏨' },
{ name: '餐饮', amount: 0, color: '#43A047', icon: '🍽️' },
{ name: '门票', amount: 0, color: '#7B1FA2', icon: '🎫' },
{ name: '购物', amount: 0, color: '#E91E63', icon: '🛍️' },
{ name: '其他', amount: 0, color: '#607D8B', icon: '📦' }
];
const GUIDE_CATEGORIES: string[] = ['全部', '美食攻略', '景点推荐', '交通指南', '住宿推荐', '省钱技巧'];
BUDGET_CATEGORIES 是预算分类的元数据配置,每一项都定义了名称、颜色与图标,amount 初始为0,运行时由统计函数填充。六种颜色分别来自不同的色系(蓝、橙、绿、紫、粉、灰),保证了柱状图中各分类的视觉区分度。GUIDE_CATEGORIES 则是一个简单的字符串数组,因为攻略分类在渲染时只需文字即可,颜色统一使用主色。这两种不同复杂度的配置反映了"按需定义"的设计原则——不为简单的需求过度设计数据结构。
四、Mock数据:丰富的示例内容支撑
4.1 行程Mock数据
const MOCK_TRIPS: TripPlanData[] = [
{ id: 1, title: '东京七日深度游', destination: '日本·东京', startDate: '2026-08-15', endDate: '2026-08-21', days: 7, status: '规划中', coverColor: '#E91E63', budget: 15000, spent: 3200, transport: '飞机', travelers: 2, description: '探索东京的繁华与传统文化', tags: [{ name: '自由行', color: '#0288D1' }, { name: '美食', color: '#FF8F00' }] },
{ id: 2, title: '大理丽江慢生活', destination: '云南·大理丽江', startDate: '2026-07-01', endDate: '2026-07-06', days: 6, status: '进行中', coverColor: '#0288D1', budget: 8000, spent: 5600, transport: '高铁', travelers: 4, description: '感受云南的慢时光', tags: [{ name: '结伴游', color: '#43A047' }, { name: '摄影', color: '#7B1FA2' }] },
// ...共15条
];
MOCK_TRIPS 数组包含了15条覆盖国内外热门目的地的行程数据,从东京到大理、从三亚到西藏、从西安到苏州,覆盖了不同地域、不同天数、不同状态、不同交通方式、不同人数的多样化场景。每条行程都有独特的 coverColor,使得列表渲染时色彩斑斓而不重复。tags 字段的多样化(自由行、美食、结伴游、摄影、度假、亲子、独自旅行、朝圣、文化、短途、周末、休闲、探险、浪漫、冰雪、自然、城市、节日)展示了标签系统的灵活性。这种"丰富到接近真实"的Mock数据,使得开发阶段就能充分检验UI在各种边界情况下的表现,例如天数从2到11的跨度、预算从2000到20000的跨度、状态在三种之间的分布等。
4.2 地点Mock数据
const MOCK_PLACES: PlaceItemData[] = [
{ id: 1, name: '浅草寺', city: '东京', category: '景点', address: '东京都台东区浅草2-3-1', rating: 4.7, visitTime: '09:00', duration: '2小时', cost: 0, imageColor: '#E91E63', notes: '求签祈福,雷门拍照', isMustVisit: true, visited: false },
{ id: 2, name: '筑地市场', city: '东京', category: '餐厅', address: '东京都中央区筑地', rating: 4.8, visitTime: '07:00', duration: '1.5小时', cost: 300, imageColor: '#FF8F00', notes: '新鲜刺身寿司', isMustVisit: true, visited: false },
// ...共18条
];
MOCK_PLACES 包含18条地点数据,覆盖景点、餐厅、酒店、购物四个分类,并故意包含了 cost 为0(免费)的项、isMustVisit 为false的项、visited 为true的项,以确保所有UI分支都能被触发到。评分从4.3到4.9分布,能够验证星级渲染(满星、半星)的边界情况。visitTime 字段从07:00到18:00覆盖了全天不同时段,体现了"什么时候去最合适"这一旅行决策要素。
4.3 预算Mock数据与攻略Mock数据
const MOCK_BUDGETS: BudgetItemData[] = [
{ id: 1, category: '交通', amount: 3200, date: '2026-08-15', description: '北京-东京往返机票', tripTitle: '东京七日深度游', icon: '✈️', color: '#0288D1' },
// ...共20条
];
const MOCK_GUIDES: GuideItemData[] = [
{ id: 1, title: '东京自由行完整攻略', category: '美食攻略', author: '旅行达人小王', readCount: 12800, coverColor: '#E91E63', summary: '从美食到购物,一文搞定东京七日游', tags: ['东京', '美食', '购物'] },
// ...共12条
];
MOCK_BUDGETS 共20条,分布在六大分类中,关联到多条不同的行程,能够完整地驱动预算统计与柱状图的渲染。MOCK_GUIDES 共12条,覆盖五大分类,readCount 从4700到15200分布,能够验证"万"单位的转换逻辑(≥10000时显示为"X.X万")。
4.4 个人统计Mock数据
const MOCK_TRAVEL_STATS: TravelStatData[] = [
{ label: '已去城市', value: 28, icon: '🏙️', color: '#0288D1' },
{ label: '总行程数', value: 35, icon: '✈️', color: '#FF8F00' },
{ label: '旅行天数', value: 186, icon: '📅', color: '#43A047' },
{ label: '花费金额', value: 128000, icon: '💰', color: '#E91E63' }
];
MOCK_TRAVEL_STATS 定义了四个汇总指标,其中"花费金额"的 value 为128000,在渲染时会自动转换为"¥12.8万"的展示形式。这四个指标分别使用了主色系中的四种颜色,使得统计看板在视觉上呼应了整体配色方案,保持了品牌一致性。
五、统计函数:纯函数式的数据加工
5.1 筛选类函数
function getStatusTrips(trips: TripPlanData[], status: string): TripPlanData[] {
return trips.filter((t: TripPlanData): boolean => t.status === status);
}
function getCategoryPlaces(places: PlaceItemData[], category: string): PlaceItemData[] {
return places.filter((p: PlaceItemData): boolean => p.category === category);
}
function getBudgetByCategory(items: BudgetItemData[], cat: string): BudgetItemData[] {
return items.filter((b: BudgetItemData): boolean => b.category === cat);
}
function getGuidesByCategory(guides: GuideItemData[], cat: string): GuideItemDataData[] {
if (cat === '全部') return guides;
return guides.filter((g: GuideItemData): boolean => g.category === cat);
}
这一组函数都是纯函数,接收原始数据数组和筛选条件,返回过滤后的新数组。它们不修改原数组,符合函数式编程的不可变原则,保证了数据的可预测性。getGuidesByCategory 中对"全部"做了特殊处理,直接返回原数组,避免无意义的过滤操作。这些函数在各自的Tab页面组件中被 filteredTrips、filteredPlaces、filteredGuides 等方法调用,实现了"配置驱动的动态筛选"。
5.2 聚合类函数
function calcCategoryTotal(items: BudgetItemData[], cat: string): number {
return items.filter((b: BudgetItemData): boolean => b.category === cat)
.reduce((sum: number, b: BudgetItemData): number => sum + b.amount, 0);
}
function calcTotalBudget(items: BudgetItemData[]): number {
return items.reduce((sum: number, b: BudgetItemData): number => sum + b.amount, 0);
}
calcCategoryTotal 先过滤再求和,得到某一分类的总金额,用于柱状图中每根柱子的数值。calcTotalBudget 直接对全量数据求和,得到总预算金额,用于进度环和统计看板。两个函数都使用了 reduce 进行累加,初始值为0,保证了空数组情况下的安全返回。这种"小函数组合"的风格使得统计逻辑高度可测试、可复用。
六、底部Tab枚举与入口组件
6.1 BottomTab 枚举
enum BottomTab {
TRIPS = 0,
PLACES = 1,
BUDGET = 2,
GUIDES = 3,
PROFILE = 4
}
BottomTab 枚举将Tab的索引值赋予了语义化的名称。相比直接使用魔法数字(如 if (this.currentTab === 0)),使用 BottomTab.TRIPS 大幅提升了代码可读性。枚举值与 BOTTOM_TABS 常量数组中的 index 字段一一对应,保证了类型安全与配置一致性。
6.2 入口组件 TravelApp
@Entry
@Component
struct TravelApp {
@State currentTab: BottomTab = BottomTab.TRIPS;
build() {
Column() {
if (this.currentTab === BottomTab.TRIPS) {
TripTabPage()
} else if (this.currentTab === BottomTab.PLACES) {
PlaceTabPage()
} else if (this.currentTab === BottomTab.BUDGET) {
BudgetTabPage()
} else if (this.currentTab === BottomTab.GUIDES) {
GuideTabPage()
} else {
ProfileTabPage()
}
this.BottomTabBar()
}
.width('100%')
.height('100%')
.backgroundColor('#E1F5FE')
}
}
TravelApp 是整个APP的入口组件,通过 @Entry 装饰。它持有一个核心状态 currentTab,初始值为 BottomTab.TRIPS(默认显示行程页)。build 方法采用 if-else if-else 条件渲染的方式切换五个Tab页面组件,外层 Column 将页面内容与底部TabBar纵向排列。整个容器使用 #E1F5FE 作为背景色,奠定了全局的浅蓝氛围。这种"条件渲染 + 状态驱动"的方式是ArkTS中实现单页面切换的典型写法,简单直观。
6.3 BottomTabBar Builder
@Builder
BottomTabBar() {
Row() {
ForEach(BOTTOM_TABS, (tab: TabConfig, idx: number) => {
Column() {
Text(tab.icon)
.fontSize(22)
Text(tab.label)
.fontSize(11)
.fontColor(idx === this.currentTab ? '#0288D1' : '#90A4AE')
.margin({ top: 2 })
}
.width('20%')
.padding({ top: 8, bottom: 8 })
.onClick(() => { this.currentTab = idx as BottomTab; })
})
}
.width('100%')
.backgroundColor('#FFFFFF')
.borderWidth({ top: 1 })
.borderColor('#E0E0E0')
.padding({ bottom: 4 })
}
BottomTabBar 是底部导航栏的Builder方法。通过 ForEach 遍历 BOTTOM_TABS 常量,渲染五个等宽(20%)的Tab项。每个Tab项包含图标和文字两行,文字颜色根据是否为当前选中Tab动态切换:选中时为主色 #0288D1,未选中时为灰色 #90A4AE。点击事件中将 idx 强转为 BottomTab 枚举赋值给 currentTab,触发条件渲染的重新执行。整个TabBar使用白色背景与顶部细边线,与上方的浅蓝内容区形成清晰的层次分割。这种"配置驱动渲染"的方式让Tab的增删改都只需调整常量数组,极大地提升了可维护性。
七、行程Tab页面:TripTabPage
7.1 状态定义与页面骨架
@Component
struct TripTabPage {
@State activeStatusIdx: number = 0;
@State showAddModal: boolean = false;
build() {
Column() {
// 标题行 + 新行程按钮
// 状态筛选Tab
// 行程列表 Scroll
}
if (this.showAddModal) {
this.modalOverlay(() => { this.showAddModal = false; })
}
}
}
TripTabPage 持有两个本地状态:activeStatusIdx 记录当前选中的状态筛选下标(0全部、1规划中、2进行中、3已完成),showAddModal 控制新增行程弹窗的显隐。build 方法在主体 Column 之外,通过 if (this.showAddModal) 条件渲染弹窗,这是一种常见的弹窗管理方式——弹窗与主内容并列,互不干扰布局。值得注意的是,弹窗通过 this.modalOverlay(...) 调用Builder方法并传入一个回调函数(关闭弹窗的逻辑),这种"回调注入"的设计使得弹窗的关闭行为可以由调用方决定,提升了复用性。
7.2 标题行与状态筛选Tab
Row() {
Text('我的行程')
.fontSize(22)
.fontWeight(FontWeight.Bold)
.fontColor('#333333')
Column().layoutWeight(1)
Text('+ 新行程')
.fontSize(14)
.fontColor('#FFFFFF')
.backgroundColor('#0288D1')
.borderRadius(16)
.padding({ left: 14, right: 14, top: 6, bottom: 6 })
.onClick(() => { this.showAddModal = true; })
}
.width('100%')
.padding({ left: 16, right: 16, top: 12, bottom: 8 })
Row() {
ForEach(TRIP_STATUS_TABS, (tab: TabConfig, idx: number) => {
Text(tab.label)
.fontSize(13)
.fontColor(idx === this.activeStatusIdx ? '#FFFFFF' : '#546E7A')
.backgroundColor(idx === this.activeStatusIdx ? '#0288D1' : '#FFFFFF')
.borderRadius(18)
.padding({ left: 14, right: 14, top: 6, bottom: 6 })
.margin({ right: 8 })
.onClick(() => { this.activeStatusIdx = idx; })
})
}
.width('100%')
.padding({ left: 16, right: 16, top: 4, bottom: 8 })
标题行采用左标题右按钮的经典布局,中间通过一个 Column().layoutWeight(1) 占位实现两端对齐。"+ 新行程"按钮使用主色背景与圆角胶囊形状,点击后触发 showAddModal = true 弹出新增弹窗。状态筛选Tab通过 ForEach 渲染四个状态选项,选中态为蓝底白字,未选中态为白底灰字,圆角18形成胶囊外观。这种"互斥单选"的Tab样式在ArkTS中极为常见,是筛选场景的标准范式。
7.3 行程列表与过滤方法
Scroll() {
Column() {
ForEach(this.filteredTrips(), (trip: TripPlanData) => {
this.TripCard(trip)
})
}
.padding({ left: 16, right: 16, bottom: 80 })
}
.layoutWeight(1)
.scrollBar(BarState.Off)
filteredTrips(): TripPlanData[] {
const statusMap: string[] = ['全部', '规划中', '进行中', '已完成'];
const sel: string = statusMap[this.activeStatusIdx];
if (sel === '全部') return MOCK_TRIPS;
return getStatusTrips(MOCK_TRIPS, sel);
}
行程列表使用 Scroll 包裹 Column,通过 layoutWeight(1) 占据剩余空间,scrollBar(BarState.Off) 隐藏滚动条以保持视觉干净。filteredTrips 方法根据 activeStatusIdx 将下标映射为状态字符串,再调用前文的 getStatusTrips 函数进行过滤,"全部"则直接返回原数组。这种"下标到字符串的映射 + 函数式过滤"的组合,实现了响应式的列表筛选——用户点击状态Tab时,activeStatusIdx 变化触发 filteredTrips 重新执行,ForEach 据此重新渲染列表。
7.4 TripCard 行程卡片Builder
@Builder
TripCard(trip: TripPlanData) {
Column() {
// 头部:目的地 + 标题 + 状态徽章
Row() {
Column() {
Text(trip.destination)
.fontSize(17)
.fontWeight(FontWeight.Bold)
.fontColor('#FFFFFF')
Text(trip.title)
.fontSize(13)
.fontColor('#FFFFFF')
.opacity(0.85)
.margin({ top: 4 })
}
.alignItems(HorizontalAlign.Start)
Column().layoutWeight(1)
Column() {
Text(this.statusText(trip.status))
.fontSize(11)
.fontColor('#FFFFFF')
.backgroundColor(this.statusColor(trip.status))
.borderRadius(10)
.padding({ left: 8, right: 8, top: 3, bottom: 3 })
}
}
.width('100%')
.padding({ left: 16, right: 16, top: 14, bottom: 10 })
// ...更多行:日期/天数/交通/人数、预算/已花/百分比、进度条、标签
}
.width('100%')
.borderRadius(14)
.linearGradient({
direction: GradientDirection.Right,
colors: [[trip.coverColor, 0.0], [trip.coverColor + 'CC', 1.0]]
})
.margin({ bottom: 14 })
}
TripCard 是整个APP中最具视觉冲击力的Builder,它将一张行程的所有关键信息浓缩在一张渐变卡片中。卡片采用 linearGradient 从左到右的渐变,起始色为 coverColor(不透明),结束色为 coverColor + 'CC'(80%透明度),形成一种从浓到淡的明信片效果。由于每条行程的 coverColor 不同,列表中的卡片色彩各异,视觉上极为丰富。卡片头部展示目的地(大号白色加粗)与行程标题(小号白色半透明),右上角是带图标的状态徽章(背景色由 statusColor 根据状态返回)。卡片中部一行展示起止日期、天数、交通方式、出行人数,用"→"和"|"分隔,信息密度高但通过分隔符保持了可读性。卡片下部展示预算与已花费金额,已花费使用橙色加粗突出,旁边是消耗百分比。最底部是 Progress 线性进度条和标签行。这种"头部—信息行—预算行—进度条—标签"的五段式布局,是行程卡片的标准信息架构。
7.5 状态文本与颜色辅助方法
statusText(s: string): string {
if (s === '规划中') return '📝 ' + s;
if (s === '进行中') return '✈️ ' + s;
return '✅ ' + s;
}
statusColor(s: string): string {
if (s === '规划中') return '#4682B4';
if (s === '进行中') return '#0288D1';
return '#43A047';
}
这两个辅助方法分别返回状态徽章的文字(带emoji前缀)和背景色。statusText 根据状态添加不同的图标,增强了视觉识别;statusColor 为三种状态分别返回不同的蓝色系(规划中偏深的钢蓝、进行中的主色蓝、已完成的绿色),形成"由深到亮再到稳"的色彩语义。这种"方法封装状态映射"的方式比内联的条件表达式更易维护,新增状态时只需在方法中添加一个分支。
7.6 新增行程弹窗 modalOverlay
@Builder
modalOverlay(onClose: () => void) {
Column() {
Column() {
Text('新增行程')
.fontSize(20)
.fontWeight(FontWeight.Bold)
.fontColor('#333333')
.margin({ bottom: 16 })
Text('功能开发中...')
.fontSize(14)
.fontColor('#78909C')
.margin({ bottom: 20 })
Row() {
Text('取消')
.fontSize(14)
.fontColor('#78909C')
.padding({ left: 24, right: 24, top: 10, bottom: 10 })
.borderRadius(20)
.backgroundColor('#ECEFF1')
.onClick(onClose)
Text(' ')
Text('确认')
.fontSize(14)
.fontColor('#FFFFFF')
.padding({ left: 24, right: 24, top: 10, bottom: 10 })
.borderRadius(20)
.backgroundColor('#0288D1')
.onClick(onClose)
}
}
.padding(24)
.backgroundColor('#FFFFFF')
.borderRadius(16)
}
.width('100%')
.height('100%')
.justifyContent(FlexAlign.Center)
.backgroundColor('rgba(0,0,0,0.5)')
.onClick(onClose)
}
modalOverlay 是一个通用的弹窗Builder,接收一个 onClose 回调函数作为参数。外层 Column 占满全屏并使用半透明黑色背景(rgba(0,0,0,0.5))作为遮罩,点击遮罩区域调用 onClose 关闭弹窗——这是一种符合用户直觉的交互模式。内层 Column 是白色的弹窗主体,圆角16,居中显示。弹窗包含标题、提示文字与"取消/确认"两个按钮,"取消"使用灰色背景的次级样式,"确认"使用主色背景的主级样式,两者通过 Text(' ') 间隔。当前显示"功能开发中…"是占位内容,未来可替换为真实的表单组件。这种"回调注入 + 遮罩点击关闭"的弹窗模式在该APP的多个Tab中被复用,体现了良好的抽象与复用思想。
八、地点Tab页面:PlaceTabPage
8.1 状态定义与页面结构
@Component
struct PlaceTabPage {
@State activeCatIdx: number = 0;
@State showPlaceModal: boolean = false;
@State selectedPlace: PlaceItemData | null = null;
build() {
Column() {
// 标题、分类筛选Tab、地点列表 Scroll
}
if (this.showPlaceModal && this.selectedPlace !== null) {
this.modalOverlay(() => { this.showPlaceModal = false; })
}
}
}
PlaceTabPage 持有三个状态:activeCatIdx(当前分类下标)、showPlaceModal(弹窗显隐)、selectedPlace(当前选中的地点,可为null)。引入 selectedPlace 是因为地点弹窗需要展示选中地点的详细信息(名称与备注),这与行程弹窗的"新增"语义不同——地点弹窗是"查看/编辑"语义。selectedPlace 使用联合类型 PlaceItemData | null,初始为null,点击卡片时赋值为对应地点对象。弹窗渲染时双重判断 showPlaceModal && selectedPlace !== null,保证了类型安全,避免在Builder中访问null对象的属性。
8.2 PlaceCard 地点卡片Builder
@Builder
PlaceCard(place: PlaceItemData) {
Row() {
Column() {
Text(this.categoryIcon(place.category))
.fontSize(28)
}
.width(52)
.height(52)
.borderRadius(12)
.backgroundColor(place.imageColor + '22')
.justifyContent(FlexAlign.Center)
.margin({ right: 14 })
Column() {
Row() {
Text(place.name)
.fontSize(16)
.fontWeight(FontWeight.Bold)
.fontColor('#333333')
if (place.isMustVisit) {
Text('必去')
.fontSize(9)
.fontColor('#FFFFFF')
.backgroundColor('#E91E63')
.borderRadius(6)
.padding({ left: 6, right: 6, top: 2, bottom: 2 })
.margin({ left: 6 })
}
}
Text(place.address)
.fontSize(12)
.fontColor('#78909C')
.margin({ top: 4 })
.maxLines(1)
.textOverflow({ overflow: TextOverflow.Ellipsis })
Row() {
Text(this.starsStr(place.rating))
.fontSize(11)
.fontColor('#FF8F00')
Text(' ' + place.rating.toFixed(1))
.fontSize(11)
.fontColor('#FF8F00')
.fontWeight(FontWeight.Bold)
Text(' ' + place.duration)
.fontSize(11)
.fontColor('#90A4AE')
if (place.cost > 0) {
Text(' ¥' + place.cost)
.fontSize(11)
.fontColor('#43A047')
} else {
Text(' 免费')
.fontSize(11)
.fontColor('#43A047')
}
Column().layoutWeight(1)
if (place.visited) {
Text('✅ 已去')
.fontSize(10)
.fontColor('#43A047')
}
}
.width('100%')
.margin({ top: 4 })
}
.alignItems(HorizontalAlign.Start)
.layoutWeight(1)
}
.width('100%')
.padding(14)
.backgroundColor('#FFFFFF')
.borderRadius(12)
.margin({ bottom: 10 })
.onClick(() => {
this.selectedPlace = place;
this.showPlaceModal = true;
})
}
PlaceCard 采用横向布局,左侧是一个52x52的圆角图标方块(背景色为 imageColor + '22',即13%透明度的浅色版本),右侧是地点的详细信息列。详细列包含三行:第一行是名称与可选的"必去"红色徽章;第二行是地址(单行省略);第三行是星级、评分、时长、费用、已去标记的信息行。星级通过 starsStr 方法生成(满星⭐ + 半星☆),评分使用 toFixed(1) 保留一位小数。费用根据是否为0显示"¥X"或"免费"。整张卡片白底圆角,点击后弹出详情弹窗。这种"图标 + 多行信息"的列表项样式是信息密集型列表的经典范式。
8.3 星级与分类图标辅助方法
starsStr(rating: number): string {
const full: number = Math.floor(rating);
let s: string = '';
for (let i: number = 0; i < full; i++) { s += '⭐'; }
if (rating - full >= 0.5) { s += '☆'; }
return s;
}
categoryIcon(cat: string): string {
if (cat === '景点') return '🏛️';
if (cat === '餐厅') return '🍽️';
if (cat === '酒店') return '🏨';
return '🛍️';
}
starsStr 将数值评分转换为可视化的星级字符串:整数部分对应满星⭐,小数部分≥0.5则追加一个半星☆。这种"emoji星级"的方式无需图片资源即可实现星级展示,轻量且跨平台一致。categoryIcon 根据分类名称返回对应的emoji图标,与 PLACE_CATEGORY_TABS 中的图标保持一致,保证了视觉语言的统一。
8.4 地点详情弹窗
@Builder
modalOverlay(onClose: () => void) {
Column() {
Column() {
Text('编辑地点')
.fontSize(20)
.fontWeight(FontWeight.Bold)
.fontColor('#333333')
.margin({ bottom: 8 })
if (this.selectedPlace !== null) {
Text(this.selectedPlace.name)
.fontSize(16)
.fontColor('#FF8F00')
.margin({ bottom: 16 })
Text('备注: ' + this.selectedPlace.notes)
.fontSize(13)
.fontColor('#546E7A')
.margin({ bottom: 16 })
}
Text('编辑功能开发中...')
.fontSize(13)
.fontColor('#78909C')
.margin({ bottom: 20 })
Row() {
Text('关闭')
.fontSize(14)
.fontColor('#FFFFFF')
.padding({ left: 28, right: 28, top: 10, bottom: 10 })
.borderRadius(20)
.backgroundColor('#FF8F00')
.onClick(onClose)
}
}
.padding(24)
.backgroundColor('#FFFFFF')
.borderRadius(16)
.width('80%')
}
.width('100%')
.height('100%')
.justifyContent(FlexAlign.Center)
.backgroundColor('rgba(0,0,0,0.5)')
.onClick(onClose)
}
地点弹窗与行程弹窗结构类似,但内部内容不同——它展示的是选中地点的名称(橙色突出)与备注信息。弹窗宽度限制为80%,避免在大屏设备上过宽。单一"关闭"按钮使用橙色背景,与地点模块的整体色调(#FF8F00)保持一致。这种"每个模块的弹窗使用该模块的主题色"的设计,强化了模块间的视觉区分。
九、预算Tab页面:BudgetTabPage
9.1 状态定义与页面结构
@Component
struct BudgetTabPage {
@State showDeleteConfirm: boolean = false;
@State deleteItemId: number = 0;
build() {
Column() {
// 标题
this.BudgetOverview() // 预算进度环
this.CategoryBarChart() // 分类柱状图
// 支出明细标题
Scroll() { /* 支出列表 */ }
}
if (this.showDeleteConfirm) {
this.modalOverlay(() => { this.showDeleteConfirm = false; })
}
}
}
BudgetTabPage 持有 showDeleteConfirm(删除确认弹窗显隐)和 deleteItemId(待删除项的ID)两个状态。页面结构由四部分组成:标题、预算总览(进度环 + 四宫格统计)、分类柱状图、支出明细列表。弹窗用于删除确认,避免误操作。这种"总览 + 分类 + 明细"的三层信息架构,让用户从宏观到微观逐层下钻,是数据可视化页面的经典设计。
9.2 BudgetOverview 预算总览Builder
@Builder
BudgetOverview() {
Row() {
Column() {
Stack() {
Progress({
value: calcTotalBudget(MOCK_BUDGETS) / 150000 * 100,
total: 100,
type: ProgressType.Ring
})
.width(70)
.height(70)
.style({ strokeWidth: 8, scaleCount: 1, scaleWidth: 0 })
.color('#0288D1')
Column() {
Text('¥')
.fontSize(10)
.fontColor('#0288D1')
Text((calcTotalBudget(MOCK_BUDGETS) / 10000).toFixed(1) + '万')
.fontSize(15)
.fontWeight(FontWeight.Bold)
.fontColor('#333333')
}
}
}
.margin({ right: 20 })
Column() {
// 行程数、总预算、支出项、平均/程 四宫格
}
.alignItems(HorizontalAlign.Start)
}
.width('100%')
.padding(16)
.backgroundColor('#FFFFFF')
.borderRadius(14)
.margin({ left: 16, right: 16, bottom: 12 })
}
BudgetOverview 是预算模块的视觉核心。左侧使用 Stack 叠加一个环形进度条(ProgressType.Ring)和中央的金额文字,环形进度条的 value 是当前总支出占150000基准的比例,颜色为主色蓝。中央显示"¥"和"X.X万"的金额数字,通过 Stack 的层叠效果实现了"进度环 + 中心文字"的经典数据看板样式。右侧是一个2x2的四宫格,分别展示行程数(蓝)、总预算(橙)、支出项数(绿)、平均每程花费(紫),每个数字使用不同的主题色,呼应了整体的色彩体系。这种"环 + 四宫格"的组合信息密度高且层次分明。
9.3 CategoryBarChart 分类柱状图Builder
@Builder
CategoryBarChart() {
Column() {
Text('分类支出概览')
.fontSize(14)
.fontWeight(FontWeight.Bold)
.fontColor('#333333')
.margin({ bottom: 10 })
ForEach(BUDGET_CATEGORIES, (cat: BudgetCategoryStat) => {
this.BarRow(cat, calcCategoryTotal(MOCK_BUDGETS, cat.name))
})
}
.width('100%')
.padding(14)
.backgroundColor('#FFFFFF')
.borderRadius(14)
.margin({ left: 16, right: 16, bottom: 12 })
}
@Builder
BarRow(cat: BudgetCategoryStat, amount: number) {
Row() {
Text(cat.icon + ' ' + cat.name)
.fontSize(12)
.fontColor('#546E7A')
.width(60)
Row() {
Row() {
}
.height(16)
.borderRadius(8)
.backgroundColor(cat.color)
.width(this.barWidth(amount))
}
.width('100%')
.layoutWeight(1)
.margin({ left: 8, right: 8 })
Text('¥' + amount)
.fontSize(11)
.fontColor('#333333')
.fontWeight(FontWeight.Bold)
.width(60)
}
.width('100%')
.margin({ bottom: 6 })
}
barWidth(amount: number): string {
const max: number = calcCategoryTotal(MOCK_BUDGETS, '交通') + 2000;
const pct: number = amount / max * 100;
return pct.toFixed(0) + '%';
}
CategoryBarChart 通过 ForEach 遍历六大预算分类,每个分类调用 BarRow 渲染一行柱状条。BarRow 是单行柱状条的Builder,左侧是图标+名称(固定宽度60),中间是柱状条(背景色为分类色,宽度通过 barWidth 方法计算),右侧是金额数字。barWidth 方法以"交通"分类的总额加上2000作为最大值基准,计算其他分类的百分比宽度,保证了柱状条的相对长度能够直观反映各分类的支出比例。这种"纯CSS柱状图"通过控制 Row 的宽度百分比实现,无需引入图表库,轻量且高效。
9.4 BudgetItemRow 支出明细Builder
@Builder
BudgetItemRow(item: BudgetItemData) {
Row() {
Text(item.icon)
.fontSize(22)
.margin({ right: 12 })
Column() {
Text(item.description)
.fontSize(14)
.fontColor('#333333')
Text(item.tripTitle + ' | ' + item.date)
.fontSize(11)
.fontColor('#90A4AE')
.margin({ top: 2 })
}
.alignItems(HorizontalAlign.Start)
.layoutWeight(1)
Column() {
Text('¥' + item.amount)
.fontSize(16)
.fontWeight(FontWeight.Bold)
.fontColor(item.color)
Text(item.category)
.fontSize(10)
.fontColor('#90A4AE')
}
Text(' ✕ ')
.fontSize(14)
.fontColor('#B0BEC5')
.margin({ left: 6 })
.onClick(() => {
this.deleteItemId = item.id;
this.showDeleteConfirm = true;
})
}
.width('100%')
.padding(12)
.backgroundColor('#FFFFFF')
.borderRadius(10)
.margin({ bottom: 8 })
}
BudgetItemRow 是支出明细的单行Builder,左侧是emoji图标,中间是描述与所属行程/日期,右侧是金额(颜色取自数据对象的 color 字段)与分类名,最右侧是删除按钮"✕"。点击删除按钮设置 deleteItemId 并弹出确认弹窗,这种"两步删除"的设计有效防止了误删。金额使用数据自带的颜色字段渲染,使得每条支出在视觉上都能快速归类,是一种"数据即视觉"的设计思想。
9.5 删除确认弹窗
@Builder
modalOverlay(onClose: () => void) {
Column() {
Column() {
Text('确认删除')
.fontSize(20)
.fontWeight(FontWeight.Bold)
.fontColor('#333333')
.margin({ bottom: 12 })
Text('确定要删除这条预算记录吗?')
.fontSize(14)
.fontColor('#546E7A')
.margin({ bottom: 20 })
Row() {
Text('取消')
.fontSize(14)
.fontColor('#78909C')
.padding({ left: 24, right: 24, top: 10, bottom: 10 })
.borderRadius(20)
.backgroundColor('#ECEFF1')
.onClick(onClose)
Text(' ')
Text('删除')
.fontSize(14)
.fontColor('#FFFFFF')
.padding({ left: 24, right: 24, top: 10, bottom: 10 })
.borderRadius(20)
.backgroundColor('#E91E63')
.onClick(onClose)
}
}
.padding(24)
.backgroundColor('#FFFFFF')
.borderRadius(16)
.width('75%')
}
.width('100%')
.height('100%')
.justifyContent(FlexAlign.Center)
.backgroundColor('rgba(0,0,0,0.5)')
.onClick(onClose)
}
删除确认弹窗与新增弹窗结构相同,但内容与按钮颜色不同。"删除"按钮使用粉红色 #E91E63 背景,传达"危险操作"的视觉警示,符合通用的交互设计规范——破坏性操作应使用警示色。弹窗宽度75%,略宽于地点弹窗的80%,根据内容长短进行了微调,体现了对细节的把控。
十、攻略Tab页面:GuideTabPage
10.1 页面结构与横向滚动Tab
@Component
struct GuideTabPage {
@State activeGuideCat: number = 0;
build() {
Column() {
Row() {
Text('旅行攻略')
.fontSize(22)
.fontWeight(FontWeight.Bold)
.fontColor('#333333')
}
.width('100%')
.padding({ left: 16, right: 16, top: 12, bottom: 4 })
Scroll() {
Row() {
ForEach(GUIDE_CATEGORIES, (cat: string, idx: number) => {
Text(cat)
.fontSize(13)
.fontColor(idx === this.activeGuideCat ? '#FFFFFF' : '#546E7A')
.backgroundColor(idx === this.activeGuideCat ? '#0288D1' : '#FFFFFF')
.borderRadius(18)
.padding({ left: 14, right: 14, top: 6, bottom: 6 })
.margin({ right: 8 })
.onClick(() => { this.activeGuideCat = idx; })
})
}
.padding({ left: 16, right: 16, bottom: 8 })
}
.scrollable(ScrollDirection.Horizontal)
.scrollBar(BarState.Off)
Scroll() {
Column() {
ForEach(this.filteredGuides(), (guide: GuideItemData) => {
this.GuideCard(guide)
})
}
.padding({ left: 16, right: 16, bottom: 80 })
}
.layoutWeight(1)
.scrollBar(BarState.Off)
}
.width('100%')
.height('100%')
}
filteredGuides(): GuideItemData[] {
const sel: string = GUIDE_CATEGORIES[this.activeGuideCat];
return getGuidesByCategory(MOCK_GUIDES, sel);
}
}
GuideTabPage 只持有一个 activeGuideCat 状态,因为没有弹窗交互。值得注意的是,攻略分类Tab使用 Scroll 包裹并设置 scrollable(ScrollDirection.Horizontal),使其支持横向滚动——这是因为攻略分类有6个,在某些窄屏设备上可能一行放不下,横向滚动保证了所有分类都能被访问到。这种"按需横向滚动"的设计比固定布局更具适配性。filteredGuides 方法将下标映射为分类名再调用 getGuidesByCategory 过滤,逻辑简洁。
10.2 GuideCard 攻略卡片Builder
@Builder
GuideCard(guide: GuideItemData) {
Column() {
Row() {
Column() {
Text(guide.title)
.fontSize(16)
.fontWeight(FontWeight.Bold)
.fontColor('#333333')
Text(guide.summary)
.fontSize(12)
.fontColor('#78909C')
.margin({ top: 4 })
.maxLines(2)
.textOverflow({ overflow: TextOverflow.Ellipsis })
}
.alignItems(HorizontalAlign.Start)
.layoutWeight(1)
Column() {
Text(guide.category)
.fontSize(11)
.fontColor('#FFFFFF')
.backgroundColor('#0288D1')
.borderRadius(10)
.padding({ left: 8, right: 8, top: 4, bottom: 4 })
}
}
.width('100%')
.padding({ top: 4, bottom: 8 })
Row() {
Text('👤 ' + guide.author)
.fontSize(11)
.fontColor('#90A4AE')
Text(' ')
.fontSize(11)
Text('👁 ' + (guide.readCount >= 10000 ? (guide.readCount / 10000).toFixed(1) + '万' : guide.readCount.toString()))
.fontSize(11)
.fontColor('#90A4AE')
Column().layoutWeight(1)
ForEach(guide.tags, (tag: string) => {
Text(tag)
.fontSize(10)
.fontColor('#0288D1')
.borderRadius(8)
.borderWidth(1)
.borderColor('#0288D1')
.padding({ left: 6, right: 6, top: 2, bottom: 2 })
.margin({ left: 4 })
})
}
.width('100%')
}
.width('100%')
.padding(14)
.backgroundColor('#FFFFFF')
.borderRadius(12)
.margin({ bottom: 12 })
.borderWidth({ left: 4 })
.borderColor(guide.coverColor)
}
GuideCard 的设计独树一帜:卡片左侧有一条4像素宽的彩色边条(borderWidth({ left: 4 }) + borderColor(guide.coverColor)),这种"左侧色条"的样式常见于内容卡片,用于快速区分不同类别。卡片上半部分是标题(加粗)与摘要(最多两行省略),右上角是分类徽章;下半部分是作者、阅读量(自动转"万"单位)与标签按钮(描边样式)。标签使用 borderWidth(1) + borderColor('#0288D1') 实现描边效果,与行程卡片的实心标签形成视觉差异,强化了"内容型卡片"与"数据型卡片"的区分。这种"色条 + 描边标签"的组合是攻略类内容卡片的典型样式。
十一、我的Tab页面:ProfileTabPage
11.1 页面整体结构
@Component
struct ProfileTabPage {
build() {
Column() {
// 用户信息卡片
Row() {
Column() {
Text('👤')
.fontSize(40)
Text('旅行家')
.fontSize(18)
.fontWeight(FontWeight.Bold)
.fontColor('#333333')
.margin({ top: 4 })
Text('已走过28座城市,累计35次旅行')
.fontSize(12)
.fontColor('#78909C')
.margin({ top: 2 })
}
.padding(20)
}
.width('100%')
.padding({ left: 16, right: 16, top: 12 })
.backgroundColor('#FFFFFF')
.borderRadius({ bottomLeft: 20, bottomRight: 20 })
this.StatGrid()
Text('旅行足迹')
.fontSize(16)
.fontWeight(FontWeight.Bold)
.fontColor('#333333')
.padding({ left: 16, top: 16, bottom: 8 })
.alignSelf(ItemAlign.Start)
// 城市标签云
Row() {
ForEach(['东京', '大理', '三亚', /* ...17个城市 */], (city: string) => {
Text(city)
.fontSize(11)
.fontColor('#0288D1')
.backgroundColor('#E1F5FE')
.borderRadius(12)
.padding({ left: 10, right: 10, top: 5, bottom: 5 })
.margin({ right: 6, bottom: 6 })
})
}
.width('100%')
.padding({ left: 16, right: 16 })
.flexWrap(FlexWrap.Wrap)
Column().layoutWeight(1)
// 设置入口
Row() {
Text('⚙️ 设置')
.fontSize(14)
.fontColor('#546E7A')
.padding({ left: 20, top: 10, bottom: 10 })
}
.width('100%')
.margin({ left: 16, right: 16, bottom: 80 })
.backgroundColor('#FFFFFF')
.borderRadius(12)
}
.width('100%')
.height('100%')
}
}
ProfileTabPage 是唯一没有 @State 的Tab页面,因为它是一个纯展示型的个人中心。页面由用户信息卡片、统计网格、旅行足迹标签云、设置入口四部分组成。用户信息卡片使用 borderRadius({ bottomLeft: 20, bottomRight: 20 }) 只圆角下方两个角,形成一种"头部吸顶"的视觉风格。城市标签云使用 flexWrap(FlexWrap.Wrap) 实现自动换行,每个城市标签使用主色文字+浅蓝背景的胶囊样式,与整体配色统一。底部"设置"入口预留了功能扩展位,未来可接入设置页。这种"信息展示 + 功能入口"的双层结构是个人中心页的标准布局。
11.2 StatGrid 统计网格Builder
@Builder
StatGrid() {
Row() {
ForEach(MOCK_TRAVEL_STATS, (stat: TravelStatData) => {
Column() {
Text(stat.icon)
.fontSize(28)
.margin({ bottom: 4 })
Text(stat.label === '花费金额' ? '¥' + (stat.value / 10000).toFixed(1) + '万' : stat.value.toString())
.fontSize(16)
.fontWeight(FontWeight.Bold)
.fontColor(stat.color)
Text(stat.label)
.fontSize(10)
.fontColor('#78909C')
.margin({ top: 2 })
}
.width('23%')
.padding({ top: 10, bottom: 10 })
})
}
.width('100%')
.padding({ left: 10, right: 10, top: 12, bottom: 12 })
.backgroundColor('#FFFFFF')
.borderRadius(14)
.margin({ left: 16, right: 16, top: 12 })
}
StatGrid 渲染四个统计指标,每个指标占23%宽度,四个合计92%,加上间距形成均衡的四宫格。每个指标包含图标(大号emoji)、数值(彩色加粗)、标签(灰色小字)三行。数值渲染时对"花费金额"做了特殊处理,将其转换为"¥X.X万"的展示形式,其他指标直接显示数值。每个指标的数值颜色取自数据对象的 color 字段,与预算总览中的四宫格色彩呼应,形成跨模块的视觉一致性。
十二、模块与组件特性对比
下表对该APP中各核心模块/组件的关键特性进行了横向对比:
| 模块/组件 | 主要职责 | 核心状态 | 关键交互 | 视觉特色 | 数据来源 | 弹窗类型 | 复用Builder |
|---|---|---|---|---|---|---|---|
| TravelApp(入口) | Tab调度与全局容器 | currentTab | 底部Tab切换 | 浅蓝全局背景 | BOTTOM_TABS常量 | 无 | BottomTabBar |
| TripTabPage(行程) | 行程列表管理与筛选 | activeStatusIdx、showAddModal | 状态筛选、新增行程 | 渐变彩色卡片 | MOCK_TRIPS(15条) | 新增行程弹窗 | TripCard、modalOverlay |
| PlaceTabPage(地点) | 地点清单与详情查看 | activeCatIdx、showPlaceModal、selectedPlace | 分类筛选、点击查看详情 | 图标+多行信息列表 | MOCK_PLACES(18条) | 地点详情弹窗 | PlaceCard、modalOverlay |
| BudgetTabPage(预算) | 支出统计与明细管理 | showDeleteConfirm、deleteItemId | 删除确认、柱状图查看 | 进度环+柱状图+明细 | MOCK_BUDGETS(20条) | 删除确认弹窗 | BudgetOverview、CategoryBarChart、BarRow、BudgetItemRow、modalOverlay |
| GuideTabPage(攻略) | 攻略内容浏览与筛选 | activeGuideCat | 横向滚动分类筛选 | 左侧色条+描边标签 | MOCK_GUIDES(12条) | 无 | GuideCard |
| ProfileTabPage(我的) | 个人统计与足迹展示 | 无(纯展示) | 无交互(预留设置入口) | 四宫格+城市标签云 | MOCK_TRAVEL_STATS、城市数组 | 无 | StatGrid |
| TripCard(行程卡片) | 单条行程的可视化展示 | 无(参数传入) | 无(未来可加点击) | 数据驱动渐变色 | trip参数 | 无 | 无 |
| PlaceCard(地点卡片) | 单个地点的可视化展示 | 无(参数传入) | 点击弹出详情 | 图标方块+必去徽章 | place参数 | 无 | 无 |
安装DevEco Studio程序

选择目标安装目录:

设置环境变量,但是需要重启一下:

新建一个空白模板:

设置API为24的模板项目:

初始化项目,自动下载相关依赖:

完整代码:
// 278.ets - 旅行行程规划APP
// 主题: 天空蓝 #0288D1 + 日落橙 #FF8F00, 背景 #E1F5FE
// 底部Tab: 🗺️ 行程 | 📍 地点 | 💰 预算 | 📖 攻略 | 👤 我的
// 布局风格: 时间线/旅程日志风格,卡片有渐变背景色
// ===== 1. interface类型定义 =====
interface TripTagItem {
name: string;
color: string;
}
interface TripPlanData {
id: number;
title: string;
destination: string;
startDate: string;
endDate: string;
days: number;
status: string;
coverColor: string;
budget: number;
spent: number;
transport: string;
travelers: number;
description: string;
tags: TripTagItem[];
}
interface PlaceItemData {
id: number;
name: string;
city: string;
category: string;
address: string;
rating: number;
visitTime: string;
duration: string;
cost: number;
imageColor: string;
notes: string;
isMustVisit: boolean;
visited: boolean;
}
interface BudgetItemData {
id: number;
category: string;
amount: number;
date: string;
description: string;
tripTitle: string;
icon: string;
color: string;
}
interface GuideItemData {
id: number;
title: string;
category: string;
author: string;
readCount: number;
coverColor: string;
summary: string;
tags: string[];
}
interface TravelStatData {
label: string;
value: number;
icon: string;
color: string;
}
interface BudgetCategoryStat {
name: string;
amount: number;
color: string;
icon: string;
}
// ===== 2. @Observed数据模型类 =====
@Observed
class TripPlan {
id: number = 0;
title: string = '';
destination: string = '';
startDate: string = '';
endDate: string = '';
days: number = 0;
status: string = '';
coverColor: string = '';
budget: number = 0;
spent: number = 0;
transport: string = '';
travelers: number = 0;
description: string = '';
tags: TripTagItem[] = [];
constructor(data: TripPlanData) {
this.id = data.id;
this.title = data.title;
this.destination = data.destination;
this.startDate = data.startDate;
this.endDate = data.endDate;
this.days = data.days;
this.status = data.status;
this.coverColor = data.coverColor;
this.budget = data.budget;
this.spent = data.spent;
this.transport = data.transport;
this.travelers = data.travelers;
this.description = data.description;
this.tags = data.tags;
}
}
@Observed
class PlaceItem {
id: number = 0;
name: string = '';
city: string = '';
category: string = '';
address: string = '';
rating: number = 0;
visitTime: string = '';
duration: string = '';
cost: number = 0;
imageColor: string = '';
notes: string = '';
isMustVisit: boolean = false;
visited: boolean = false;
constructor(data: PlaceItemData) {
this.id = data.id;
this.name = data.name;
this.city = data.city;
this.category = data.category;
this.address = data.address;
this.rating = data.rating;
this.visitTime = data.visitTime;
this.duration = data.duration;
this.cost = data.cost;
this.imageColor = data.imageColor;
this.notes = data.notes;
this.isMustVisit = data.isMustVisit;
this.visited = data.visited;
}
}
@Observed
class BudgetItem {
id: number = 0;
category: string = '';
amount: number = 0;
date: string = '';
description: string = '';
tripTitle: string = '';
icon: string = '';
color: string = '';
constructor(data: BudgetItemData) {
this.id = data.id;
this.category = data.category;
this.amount = data.amount;
this.date = data.date;
this.description = data.description;
this.tripTitle = data.tripTitle;
this.icon = data.icon;
this.color = data.color;
}
}
@Observed
class GuideItem {
id: number = 0;
title: string = '';
category: string = '';
author: string = '';
readCount: number = 0;
coverColor: string = '';
summary: string = '';
tags: string[] = [];
constructor(data: GuideItemData) {
this.id = data.id;
this.title = data.title;
this.category = data.category;
this.author = data.author;
this.readCount = data.readCount;
this.coverColor = data.coverColor;
this.summary = data.summary;
this.tags = data.tags;
}
}
// ===== 3. 静态配置常量 =====
interface TabConfig {
label: string;
icon: string;
index: number;
}
const TRIP_STATUS_TABS: TabConfig[] = [
{ label: '全部', icon: '📋', index: 0 },
{ label: '规划中', icon: '📝', index: 1 },
{ label: '进行中', icon: '✈️', index: 2 },
{ label: '已完成', icon: '✅', index: 3 }
];
const PLACE_CATEGORY_TABS: TabConfig[] = [
{ label: '全部', icon: '📍', index: 0 },
{ label: '景点', icon: '🏛️', index: 1 },
{ label: '餐厅', icon: '🍽️', index: 2 },
{ label: '酒店', icon: '🏨', index: 3 },
{ label: '购物', icon: '🛍️', index: 4 }
];
const BUDGET_CATEGORIES: BudgetCategoryStat[] = [
{ name: '交通', amount: 0, color: '#0288D1', icon: '✈️' },
{ name: '住宿', amount: 0, color: '#FF8F00', icon: '🏨' },
{ name: '餐饮', amount: 0, color: '#43A047', icon: '🍽️' },
{ name: '门票', amount: 0, color: '#7B1FA2', icon: '🎫' },
{ name: '购物', amount: 0, color: '#E91E63', icon: '🛍️' },
{ name: '其他', amount: 0, color: '#607D8B', icon: '📦' }
];
const GUIDE_CATEGORIES: string[] = ['全部', '美食攻略', '景点推荐', '交通指南', '住宿推荐', '省钱技巧'];
const BOTTOM_TABS: TabConfig[] = [
{ label: '行程', icon: '🗺️', index: 0 },
{ label: '地点', icon: '📍', index: 1 },
{ label: '预算', icon: '💰', index: 2 },
{ label: '攻略', icon: '📖', index: 3 },
{ label: '我的', icon: '👤', index: 4 }
];
// ===== 4. Mock数据数组 =====
const MOCK_TRIPS: TripPlanData[] = [
{ id: 1, title: '东京七日深度游', destination: '日本·东京', startDate: '2026-08-15', endDate: '2026-08-21', days: 7, status: '规划中', coverColor: '#E91E63', budget: 15000, spent: 3200, transport: '飞机', travelers: 2, description: '探索东京的繁华与传统文化', tags: [{ name: '自由行', color: '#0288D1' }, { name: '美食', color: '#FF8F00' }] },
{ id: 2, title: '大理丽江慢生活', destination: '云南·大理丽江', startDate: '2026-07-01', endDate: '2026-07-06', days: 6, status: '进行中', coverColor: '#0288D1', budget: 8000, spent: 5600, transport: '高铁', travelers: 4, description: '感受云南的慢时光', tags: [{ name: '结伴游', color: '#43A047' }, { name: '摄影', color: '#7B1FA2' }] },
{ id: 3, title: '三亚海滩度假', destination: '海南·三亚', startDate: '2026-06-10', endDate: '2026-06-14', days: 5, status: '已完成', coverColor: '#FF8F00', budget: 10000, spent: 9800, transport: '飞机', travelers: 2, description: '阳光沙滩海鲜大餐', tags: [{ name: '度假', color: '#0288D1' }, { name: '亲子', color: '#E91E63' }] },
{ id: 4, title: '成都美食之旅', destination: '四川·成都', startDate: '2026-09-01', endDate: '2026-09-04', days: 4, status: '规划中', coverColor: '#43A047', budget: 5000, spent: 800, transport: '高铁', travelers: 3, description: '火锅串串兔头走起', tags: [{ name: '美食', color: '#FF8F00' }, { name: '短途', color: '#7B1FA2' }] },
{ id: 5, title: '西藏朝圣之旅', destination: '西藏·拉萨', startDate: '2026-05-20', endDate: '2026-05-30', days: 11, status: '已完成', coverColor: '#7B1FA2', budget: 20000, spent: 18500, transport: '飞机', travelers: 1, description: '布达拉宫纳木错羊卓雍措', tags: [{ name: '独自旅行', color: '#607D8B' }, { name: '朝圣', color: '#0288D1' }] },
{ id: 6, title: '西安古都三日', destination: '陕西·西安', startDate: '2026-08-01', endDate: '2026-08-03', days: 3, status: '规划中', coverColor: '#FF5722', budget: 3000, spent: 0, transport: '高铁', travelers: 2, description: '兵马俑回民街古城墙', tags: [{ name: '文化', color: '#43A047' }, { name: '短途', color: '#FF8F00' }] },
{ id: 7, title: '杭州西湖周末游', destination: '浙江·杭州', startDate: '2026-07-15', endDate: '2026-07-16', days: 2, status: '进行中', coverColor: '#00BCD4', budget: 2000, spent: 1200, transport: '高铁', travelers: 2, description: '西湖美景龙井茶香', tags: [{ name: '周末', color: '#0288D1' }, { name: '休闲', color: '#43A047' }] },
{ id: 8, title: '张家界探险', destination: '湖南·张家界', startDate: '2026-04-10', endDate: '2026-04-14', days: 5, status: '已完成', coverColor: '#4CAF50', budget: 6000, spent: 5500, transport: '飞机', travelers: 4, description: '玻璃栈道天门山', tags: [{ name: '结伴游', color: '#E91E63' }, { name: '探险', color: '#FF8F00' }] },
{ id: 9, title: '厦门鼓浪屿浪漫', destination: '福建·厦门', startDate: '2026-09-10', endDate: '2026-09-13', days: 4, status: '规划中', coverColor: '#FF9800', budget: 4500, spent: 0, transport: '高铁', travelers: 2, description: '鼓浪屿琴声海风', tags: [{ name: '浪漫', color: '#E91E63' }, { name: '美食', color: '#43A047' }] },
{ id: 10, title: '哈尔滨冰雪游', destination: '黑龙江·哈尔滨', startDate: '2026-01-20', endDate: '2026-01-24', days: 5, status: '已完成', coverColor: '#2196F3', budget: 7000, spent: 6800, transport: '飞机', travelers: 3, description: '冰雪大世界中央大街', tags: [{ name: '冰雪', color: '#0288D1' }, { name: '结伴游', color: '#7B1FA2' }] },
{ id: 11, title: '桂林山水甲天下', destination: '广西·桂林', startDate: '2026-10-01', endDate: '2026-10-05', days: 5, status: '进行中', coverColor: '#8BC34A', budget: 5500, spent: 3000, transport: '高铁', travelers: 4, description: '漓江竹筏阳朔西街', tags: [{ name: '自然', color: '#43A047' }, { name: '结伴游', color: '#FF8F00' }] },
{ id: 12, title: '重庆山城暴走', destination: '重庆', startDate: '2026-08-20', endDate: '2026-08-23', days: 4, status: '规划中', coverColor: '#795548', budget: 4000, spent: 500, transport: '高铁', travelers: 2, description: '洪崖洞解放碑火锅', tags: [{ name: '美食', color: '#E91E63' }, { name: '城市', color: '#0288D1' }] },
{ id: 13, title: '青岛啤酒节狂欢', destination: '山东·青岛', startDate: '2026-07-20', endDate: '2026-07-23', days: 4, status: '进行中', coverColor: '#03A9F4', budget: 3500, spent: 2000, transport: '高铁', travelers: 5, description: '啤酒海鲜海风', tags: [{ name: '节日', color: '#FF8F00' }, { name: '结伴游', color: '#43A047' }] },
{ id: 14, title: '敦煌丝路之旅', destination: '甘肃·敦煌', startDate: '2026-05-01', endDate: '2026-05-06', days: 6, status: '已完成', coverColor: '#FFC107', budget: 9000, spent: 8500, transport: '飞机', travelers: 2, description: '莫高窟鸣沙山月牙泉', tags: [{ name: '文化', color: '#7B1FA2' }, { name: '摄影', color: '#0288D1' }] },
{ id: 15, title: '苏州园林雅集', destination: '江苏·苏州', startDate: '2026-09-15', endDate: '2026-09-17', days: 3, status: '规划中', coverColor: '#009688', budget: 2500, spent: 0, transport: '高铁', travelers: 1, description: '拙政园虎丘平江路', tags: [{ name: '独自', color: '#607D8B' }, { name: '文化', color: '#43A047' }] }
];
const MOCK_PLACES: PlaceItemData[] = [
{ id: 1, name: '浅草寺', city: '东京', category: '景点', address: '东京都台东区浅草2-3-1', rating: 4.7, visitTime: '09:00', duration: '2小时', cost: 0, imageColor: '#E91E63', notes: '求签祈福,雷门拍照', isMustVisit: true, visited: false },
{ id: 2, name: '筑地市场', city: '东京', category: '餐厅', address: '东京都中央区筑地', rating: 4.8, visitTime: '07:00', duration: '1.5小时', cost: 300, imageColor: '#FF8F00', notes: '新鲜刺身寿司', isMustVisit: true, visited: false },
{ id: 3, name: '洱海骑行道', city: '大理', category: '景点', address: '大理白族自治州洱海', rating: 4.9, visitTime: '08:00', duration: '4小时', cost: 50, imageColor: '#0288D1', notes: '环湖骑行绝美', isMustVisit: true, visited: true },
{ id: 4, name: '大理古城客栈', city: '大理', category: '酒店', address: '大理古城人民路', rating: 4.5, visitTime: '14:00', duration: '入住', cost: 380, imageColor: '#43A047', notes: '白族庭院风格', isMustVisit: false, visited: true },
{ id: 5, name: '三亚亚龙湾', city: '三亚', category: '景点', address: '三亚市亚龙湾', rating: 4.6, visitTime: '10:00', duration: '5小时', cost: 0, imageColor: '#FF8F00', notes: '白沙滩碧海蓝天', isMustVisit: true, visited: true },
{ id: 6, name: '锦里古街', city: '成都', category: '购物', address: '成都市武侯祠大街', rating: 4.4, visitTime: '15:00', duration: '2小时', cost: 150, imageColor: '#E91E63', notes: '小吃工艺品', isMustVisit: true, visited: false },
{ id: 7, name: '布达拉宫', city: '拉萨', category: '景点', address: '拉萨市城关区', rating: 4.9, visitTime: '09:00', duration: '3小时', cost: 200, imageColor: '#7B1FA2', notes: '提前预约门票', isMustVisit: true, visited: true },
{ id: 8, name: '兵马俑博物馆', city: '西安', category: '景点', address: '西安市临潼区', rating: 4.8, visitTime: '08:30', duration: '3小时', cost: 120, imageColor: '#FF5722', notes: '世界第八大奇迹', isMustVisit: true, visited: false },
{ id: 9, name: '龙井茶园', city: '杭州', category: '景点', address: '杭州市西湖区龙井村', rating: 4.5, visitTime: '10:00', duration: '2小时', cost: 80, imageColor: '#00BCD4', notes: '品茶赏景', isMustVisit: false, visited: false },
{ id: 10, name: '天门山', city: '张家界', category: '景点', address: '张家界市永定区', rating: 4.7, visitTime: '08:00', duration: '4小时', cost: 258, imageColor: '#4CAF50', notes: '玻璃栈道惊险', isMustVisit: true, visited: true },
{ id: 11, name: '鼓浪屿日光岩', city: '厦门', category: '景点', address: '厦门市鼓浪屿', rating: 4.6, visitTime: '09:00', duration: '2小时', cost: 60, imageColor: '#FF9800', notes: '全岛最高点', isMustVisit: true, visited: false },
{ id: 12, name: '冰雪大世界', city: '哈尔滨', category: '景点', address: '哈尔滨市松北区', rating: 4.8, visitTime: '16:00', duration: '3小时', cost: 330, imageColor: '#2196F3', notes: '冰雕灯光秀', isMustVisit: true, visited: true },
{ id: 13, name: '漓江竹筏', city: '桂林', category: '景点', address: '桂林市阳朔县', rating: 4.9, visitTime: '08:00', duration: '4小时', cost: 200, imageColor: '#8BC34A', notes: '人在画中游', isMustVisit: true, visited: true },
{ id: 14, name: '洪崖洞', city: '重庆', category: '景点', address: '重庆市渝中区', rating: 4.5, visitTime: '18:00', duration: '2小时', cost: 0, imageColor: '#795548', notes: '夜景千与千寻', isMustVisit: true, visited: false },
{ id: 15, name: '栈桥', city: '青岛', category: '景点', address: '青岛市市南区', rating: 4.3, visitTime: '10:00', duration: '1小时', cost: 0, imageColor: '#03A9F4', notes: '青岛地标', isMustVisit: false, visited: false },
{ id: 16, name: '莫高窟', city: '敦煌', category: '景点', address: '敦煌市莫高镇', rating: 4.9, visitTime: '09:00', duration: '3小时', cost: 238, imageColor: '#FFC107', notes: '千年壁画', isMustVisit: true, visited: true },
{ id: 17, name: '拙政园', city: '苏州', category: '景点', address: '苏州市姑苏区', rating: 4.7, visitTime: '08:00', duration: '2小时', cost: 80, imageColor: '#009688', notes: '江南园林之首', isMustVisit: true, visited: false },
{ id: 18, name: '回民街小吃', city: '西安', category: '餐厅', address: '西安市莲湖区回民街', rating: 4.4, visitTime: '12:00', duration: '1.5小时', cost: 80, imageColor: '#FF5722', notes: '肉夹馍凉皮', isMustVisit: true, visited: false }
];
const MOCK_BUDGETS: BudgetItemData[] = [
{ id: 1, category: '交通', amount: 3200, date: '2026-08-15', description: '北京-东京往返机票', tripTitle: '东京七日深度游', icon: '✈️', color: '#0288D1' },
{ id: 2, category: '住宿', amount: 4500, date: '2026-08-15', description: '新宿酒店6晚', tripTitle: '东京七日深度游', icon: '🏨', color: '#FF8F00' },
{ id: 3, category: '餐饮', amount: 2100, date: '2026-08-16', description: '日料餐厅预订', tripTitle: '东京七日深度游', icon: '🍣', color: '#43A047' },
{ id: 4, category: '门票', amount: 800, date: '2026-08-17', description: '迪士尼乐园门票', tripTitle: '东京七日深度游', icon: '🎫', color: '#7B1FA2' },
{ id: 5, category: '购物', amount: 3000, date: '2026-08-18', description: '药妆店采购', tripTitle: '东京七日深度游', icon: '🛍️', color: '#E91E63' },
{ id: 6, category: '交通', amount: 1200, date: '2026-07-01', description: '昆明-大理高铁', tripTitle: '大理丽江慢生活', icon: '🚄', color: '#0288D1' },
{ id: 7, category: '住宿', amount: 2400, date: '2026-07-01', description: '大理古城民宿5晚', tripTitle: '大理丽江慢生活', icon: '🏨', color: '#FF8F00' },
{ id: 8, category: '餐饮', amount: 1500, date: '2026-07-02', description: '白族特色餐厅', tripTitle: '大理丽江慢生活', icon: '🍲', color: '#43A047' },
{ id: 9, category: '交通', amount: 2500, date: '2026-06-10', description: '北京-三亚往返', tripTitle: '三亚海滩度假', icon: '✈️', color: '#0288D1' },
{ id: 10, category: '住宿', amount: 4000, date: '2026-06-10', description: '亚龙湾度假酒店4晚', tripTitle: '三亚海滩度假', icon: '🏨', color: '#FF8F00' },
{ id: 11, category: '餐饮', amount: 2000, date: '2026-06-11', description: '海鲜大餐系列', tripTitle: '三亚海滩度假', icon: '🦞', color: '#43A047' },
{ id: 12, category: '门票', amount: 600, date: '2026-06-12', description: '蜈支洲岛门票', tripTitle: '三亚海滩度假', icon: '🎫', color: '#7B1FA2' },
{ id: 13, category: '其他', amount: 700, date: '2026-06-13', description: '水上项目', tripTitle: '三亚海滩度假', icon: '🏄', color: '#607D8B' },
{ id: 14, category: '交通', amount: 800, date: '2026-09-01', description: '西安-成都高铁', tripTitle: '成都美食之旅', icon: '🚄', color: '#0288D1' },
{ id: 15, category: '餐饮', amount: 1800, date: '2026-09-01', description: '火锅串串兔头', tripTitle: '成都美食之旅', icon: '🍲', color: '#43A047' },
{ id: 16, category: '住宿', amount: 1200, date: '2026-09-01', description: '春熙路酒店3晚', tripTitle: '成都美食之旅', icon: '🏨', color: '#FF8F00' },
{ id: 17, category: '交通', amount: 3500, date: '2026-05-20', description: '上海-拉萨往返', tripTitle: '西藏朝圣之旅', icon: '✈️', color: '#0288D1' },
{ id: 18, category: '住宿', amount: 5000, date: '2026-05-20', description: '拉萨酒店10晚', tripTitle: '西藏朝圣之旅', icon: '🏨', color: '#FF8F00' },
{ id: 19, category: '门票', amount: 1200, date: '2026-05-21', description: '布达拉宫+纳木错', tripTitle: '西藏朝圣之旅', icon: '🎫', color: '#7B1FA2' },
{ id: 20, category: '其他', amount: 8800, date: '2026-05-22', description: '包车+向导+氧气', tripTitle: '西藏朝圣之旅', icon: '🚙', color: '#607D8B' }
];
const MOCK_GUIDES: GuideItemData[] = [
{ id: 1, title: '东京自由行完整攻略', category: '美食攻略', author: '旅行达人小王', readCount: 12800, coverColor: '#E91E63', summary: '从美食到购物,一文搞定东京七日游', tags: ['东京', '美食', '购物'] },
{ id: 2, title: '大理丽江拍照机位分享', category: '景点推荐', author: '摄影师老张', readCount: 9600, coverColor: '#0288D1', summary: '20个绝美拍照点,出片率100%', tags: ['大理', '丽江', '摄影'] },
{ id: 3, title: '三亚家庭游避坑指南', category: '省钱技巧', author: '宝妈旅行记', readCount: 7500, coverColor: '#FF8F00', summary: '带娃游三亚怎么花钱最少玩最好', tags: ['三亚', '亲子', '省钱'] },
{ id: 4, title: '成都火锅店排名Top10', category: '美食攻略', author: '吃货阿芳', readCount: 15200, coverColor: '#43A047', summary: '本地人推荐的正宗火锅店', tags: ['成都', '火锅', '美食'] },
{ id: 5, title: '西藏高原反应全攻略', category: '交通指南', author: '户外玩家', readCount: 11000, coverColor: '#7B1FA2', summary: '高原反应预防与应对措施', tags: ['西藏', '高原', '健康'] },
{ id: 6, title: '西安三日游最佳路线', category: '景点推荐', author: '历史迷小李', readCount: 8300, coverColor: '#FF5722', summary: '兵马俑+古城墙+回民街一次走完', tags: ['西安', '历史', '路线'] },
{ id: 7, title: '杭州周末游省钱攻略', category: '省钱技巧', author: '背包客阿杰', readCount: 6200, coverColor: '#00BCD4', summary: '人均500玩转杭州西湖', tags: ['杭州', '省钱', '周末'] },
{ id: 8, title: '张家界住宿推荐', category: '住宿推荐', author: '民宿体验师', readCount: 5400, coverColor: '#4CAF50', summary: '天门山脚下的特色民宿合集', tags: ['张家界', '住宿', '民宿'] },
{ id: 9, title: '厦门鼓浪屿深度游', category: '景点推荐', author: '文艺青年小林', readCount: 9800, coverColor: '#FF9800', summary: '避开人潮玩转鼓浪屿', tags: ['厦门', '鼓浪屿', '文艺'] },
{ id: 10, title: '哈尔滨冰雕节攻略', category: '景点推荐', author: '东北老铁', readCount: 14500, coverColor: '#2196F3', summary: '冰雪大世界+雪乡一站式攻略', tags: ['哈尔滨', '冰雪', '冬季'] },
{ id: 11, title: '桂林阳朔竹筏避坑', category: '交通指南', author: '背包客小刘', readCount: 4700, coverColor: '#8BC34A', summary: '漓江竹筏怎么选不踩坑', tags: ['桂林', '阳朔', '竹筏'] },
{ id: 12, title: '重庆山城暴走路线', category: '景点推荐', author: '山城土著', readCount: 8900, coverColor: '#795548', summary: '3D魔幻城市暴走指南', tags: ['重庆', '城市', '暴走'] }
];
const MOCK_TRAVEL_STATS: TravelStatData[] = [
{ label: '已去城市', value: 28, icon: '🏙️', color: '#0288D1' },
{ label: '总行程数', value: 35, icon: '✈️', color: '#FF8F00' },
{ label: '旅行天数', value: 186, icon: '📅', color: '#43A047' },
{ label: '花费金额', value: 128000, icon: '💰', color: '#E91E63' }
];
// ===== 5. 统计函数 =====
function getStatusTrips(trips: TripPlanData[], status: string): TripPlanData[] {
return trips.filter((t: TripPlanData): boolean => t.status === status);
}
function getCategoryPlaces(places: PlaceItemData[], category: string): PlaceItemData[] {
return places.filter((p: PlaceItemData): boolean => p.category === category);
}
function getBudgetByCategory(items: BudgetItemData[], cat: string): BudgetItemData[] {
return items.filter((b: BudgetItemData): boolean => b.category === cat);
}
function calcCategoryTotal(items: BudgetItemData[], cat: string): number {
return items.filter((b: BudgetItemData): boolean => b.category === cat)
.reduce((sum: number, b: BudgetItemData): number => sum + b.amount, 0);
}
function calcTotalBudget(items: BudgetItemData[]): number {
return items.reduce((sum: number, b: BudgetItemData): number => sum + b.amount, 0);
}
function getGuidesByCategory(guides: GuideItemData[], cat: string): GuideItemData[] {
if (cat === '全部') return guides;
return guides.filter((g: GuideItemData): boolean => g.category === cat);
}
// ===== 6. 底部Tab枚举 =====
enum BottomTab {
TRIPS = 0,
PLACES = 1,
BUDGET = 2,
GUIDES = 3,
PROFILE = 4
}
// ===== 7. @Entry @Component 入口页面 =====
@Entry
@Component
struct TravelApp {
@State currentTab: BottomTab = BottomTab.TRIPS;
build() {
Column() {
if (this.currentTab === BottomTab.TRIPS) {
TripTabPage()
} else if (this.currentTab === BottomTab.PLACES) {
PlaceTabPage()
} else if (this.currentTab === BottomTab.BUDGET) {
BudgetTabPage()
} else if (this.currentTab === BottomTab.GUIDES) {
GuideTabPage()
} else {
ProfileTabPage()
}
this.BottomTabBar()
}
.width('100%')
.height('100%')
.backgroundColor('#E1F5FE')
}
@Builder
BottomTabBar() {
Row() {
ForEach(BOTTOM_TABS, (tab: TabConfig, idx: number) => {
Column() {
Text(tab.icon)
.fontSize(22)
Text(tab.label)
.fontSize(11)
.fontColor(idx === this.currentTab ? '#0288D1' : '#90A4AE')
.margin({ top: 2 })
}
.width('20%')
.padding({ top: 8, bottom: 8 })
.onClick(() => { this.currentTab = idx as BottomTab; })
})
}
.width('100%')
.backgroundColor('#FFFFFF')
.borderWidth({ top: 1 })
.borderColor('#E0E0E0')
.padding({ bottom: 4 })
}
}
// ===== 8. 各Tab页面组件 =====
// ----- 行程Tab -----
@Component
struct TripTabPage {
@State activeStatusIdx: number = 0;
@State showAddModal: boolean = false;
build() {
Column() {
Row() {
Text('我的行程')
.fontSize(22)
.fontWeight(FontWeight.Bold)
.fontColor('#333333')
Column().layoutWeight(1)
Text('+ 新行程')
.fontSize(14)
.fontColor('#FFFFFF')
.backgroundColor('#0288D1')
.borderRadius(16)
.padding({ left: 14, right: 14, top: 6, bottom: 6 })
.onClick(() => { this.showAddModal = true; })
}
.width('100%')
.padding({ left: 16, right: 16, top: 12, bottom: 8 })
Row() {
ForEach(TRIP_STATUS_TABS, (tab: TabConfig, idx: number) => {
Text(tab.label)
.fontSize(13)
.fontColor(idx === this.activeStatusIdx ? '#FFFFFF' : '#546E7A')
.backgroundColor(idx === this.activeStatusIdx ? '#0288D1' : '#FFFFFF')
.borderRadius(18)
.padding({ left: 14, right: 14, top: 6, bottom: 6 })
.margin({ right: 8 })
.onClick(() => { this.activeStatusIdx = idx; })
})
}
.width('100%')
.padding({ left: 16, right: 16, top: 4, bottom: 8 })
Scroll() {
Column() {
ForEach(this.filteredTrips(), (trip: TripPlanData) => {
this.TripCard(trip)
})
}
.padding({ left: 16, right: 16, bottom: 80 })
}
.layoutWeight(1)
.scrollBar(BarState.Off)
}
.width('100%')
.height('100%')
if (this.showAddModal) {
this.modalOverlay(() => { this.showAddModal = false; })
}
}
filteredTrips(): TripPlanData[] {
const statusMap: string[] = ['全部', '规划中', '进行中', '已完成'];
const sel: string = statusMap[this.activeStatusIdx];
if (sel === '全部') return MOCK_TRIPS;
return getStatusTrips(MOCK_TRIPS, sel);
}
@Builder
TripCard(trip: TripPlanData) {
Column() {
Row() {
Column() {
Text(trip.destination)
.fontSize(17)
.fontWeight(FontWeight.Bold)
.fontColor('#FFFFFF')
Text(trip.title)
.fontSize(13)
.fontColor('#FFFFFF')
.opacity(0.85)
.margin({ top: 4 })
}
.alignItems(HorizontalAlign.Start)
Column().layoutWeight(1)
Column() {
Text(this.statusText(trip.status))
.fontSize(11)
.fontColor('#FFFFFF')
.backgroundColor(this.statusColor(trip.status))
.borderRadius(10)
.padding({ left: 8, right: 8, top: 3, bottom: 3 })
}
}
.width('100%')
.padding({ left: 16, right: 16, top: 14, bottom: 10 })
Row() {
Text(trip.startDate)
.fontSize(12)
.fontColor('#FFFFFF')
.opacity(0.9)
Text(' → ')
.fontSize(12)
.fontColor('#FFFFFF')
.opacity(0.7)
Text(trip.endDate)
.fontSize(12)
.fontColor('#FFFFFF')
.opacity(0.9)
Text(' ')
.fontSize(12)
Text(trip.days + '天')
.fontSize(12)
.fontColor('#FFFFFF')
.opacity(0.9)
Text(' | ')
.fontSize(12)
.fontColor('#FFFFFF')
.opacity(0.7)
Text(trip.transport)
.fontSize(12)
.fontColor('#FFFFFF')
.opacity(0.9)
Text(' | ')
.fontSize(12)
.fontColor('#FFFFFF')
.opacity(0.7)
Text(trip.travelers + '人')
.fontSize(12)
.fontColor('#FFFFFF')
.opacity(0.9)
}
.width('100%')
.padding({ left: 16, right: 16, top: 4, bottom: 8 })
Row() {
Text('预算 ¥' + trip.budget)
.fontSize(12)
.fontColor('#FFFFFF')
.opacity(0.9)
Text(' ')
.fontSize(12)
Text('已花 ¥' + trip.spent)
.fontSize(12)
.fontColor('#FF8F00')
.fontWeight(FontWeight.Bold)
Column().layoutWeight(1)
if (trip.budget > 0) {
Text(Math.floor(trip.spent / trip.budget * 100) + '%')
.fontSize(12)
.fontColor('#FFFFFF')
.opacity(0.9)
}
}
.width('100%')
.padding({ left: 16, right: 16, bottom: 8 })
Row() {
Progress({ value: trip.budget > 0 ? trip.spent / trip.budget * 100 : 0, type: ProgressType.Linear })
.width('100%')
.height(4)
.color('#FF8F00')
.style({ strokeWidth: 4 })
}
.width('100%')
.padding({ left: 16, right: 16, bottom: 12 })
Row() {
ForEach(trip.tags, (tag: TripTagItem) => {
Text(tag.name)
.fontSize(10)
.fontColor('#FFFFFF')
.backgroundColor(tag.color)
.borderRadius(8)
.padding({ left: 8, right: 8, top: 2, bottom: 2 })
.margin({ right: 6 })
})
}
.width('100%')
.padding({ left: 16, right: 16, bottom: 14 })
}
.width('100%')
.borderRadius(14)
.linearGradient({
direction: GradientDirection.Right,
colors: [[trip.coverColor, 0.0], [trip.coverColor + 'CC', 1.0]]
})
.margin({ bottom: 14 })
}
statusText(s: string): string {
if (s === '规划中') return '📝 ' + s;
if (s === '进行中') return '✈️ ' + s;
return '✅ ' + s;
}
statusColor(s: string): string {
if (s === '规划中') return '#4682B4';
if (s === '进行中') return '#0288D1';
return '#43A047';
}
@Builder
modalOverlay(onClose: () => void) {
Column() {
Column() {
Text('新增行程')
.fontSize(20)
.fontWeight(FontWeight.Bold)
.fontColor('#333333')
.margin({ bottom: 16 })
Text('功能开发中...')
.fontSize(14)
.fontColor('#78909C')
.margin({ bottom: 20 })
Row() {
Text('取消')
.fontSize(14)
.fontColor('#78909C')
.padding({ left: 24, right: 24, top: 10, bottom: 10 })
.borderRadius(20)
.backgroundColor('#ECEFF1')
.onClick(onClose)
Text(' ')
Text('确认')
.fontSize(14)
.fontColor('#FFFFFF')
.padding({ left: 24, right: 24, top: 10, bottom: 10 })
.borderRadius(20)
.backgroundColor('#0288D1')
.onClick(onClose)
}
}
.padding(24)
.backgroundColor('#FFFFFF')
.borderRadius(16)
}
.width('100%')
.height('100%')
.justifyContent(FlexAlign.Center)
.backgroundColor('rgba(0,0,0,0.5)')
.onClick(onClose)
}
}
// ----- 地点Tab -----
@Component
struct PlaceTabPage {
@State activeCatIdx: number = 0;
@State showPlaceModal: boolean = false;
@State selectedPlace: PlaceItemData | null = null;
build() {
Column() {
Row() {
Text('旅行地点')
.fontSize(22)
.fontWeight(FontWeight.Bold)
.fontColor('#333333')
}
.width('100%')
.padding({ left: 16, right: 16, top: 12, bottom: 8 })
Row() {
ForEach(PLACE_CATEGORY_TABS, (tab: TabConfig, idx: number) => {
Text(tab.label)
.fontSize(13)
.fontColor(idx === this.activeCatIdx ? '#FFFFFF' : '#546E7A')
.backgroundColor(idx === this.activeCatIdx ? '#FF8F00' : '#FFFFFF')
.borderRadius(18)
.padding({ left: 14, right: 14, top: 6, bottom: 6 })
.margin({ right: 8 })
.onClick(() => { this.activeCatIdx = idx; })
})
}
.width('100%')
.padding({ left: 16, right: 16, top: 4, bottom: 8 })
Scroll() {
Column() {
ForEach(this.filteredPlaces(), (place: PlaceItemData) => {
this.PlaceCard(place)
})
}
.padding({ left: 16, right: 16, bottom: 80 })
}
.layoutWeight(1)
.scrollBar(BarState.Off)
}
.width('100%')
.height('100%')
if (this.showPlaceModal && this.selectedPlace !== null) {
this.modalOverlay(() => { this.showPlaceModal = false; })
}
}
filteredPlaces(): PlaceItemData[] {
const catMap: string[] = ['全部', '景点', '餐厅', '酒店', '购物'];
const sel: string = catMap[this.activeCatIdx];
if (sel === '全部') return MOCK_PLACES;
return getCategoryPlaces(MOCK_PLACES, sel);
}
@Builder
PlaceCard(place: PlaceItemData) {
Row() {
Column() {
Text(this.categoryIcon(place.category))
.fontSize(28)
}
.width(52)
.height(52)
.borderRadius(12)
.backgroundColor(place.imageColor + '22')
.justifyContent(FlexAlign.Center)
.margin({ right: 14 })
Column() {
Row() {
Text(place.name)
.fontSize(16)
.fontWeight(FontWeight.Bold)
.fontColor('#333333')
if (place.isMustVisit) {
Text('必去')
.fontSize(9)
.fontColor('#FFFFFF')
.backgroundColor('#E91E63')
.borderRadius(6)
.padding({ left: 6, right: 6, top: 2, bottom: 2 })
.margin({ left: 6 })
}
}
Text(place.address)
.fontSize(12)
.fontColor('#78909C')
.margin({ top: 4 })
.maxLines(1)
.textOverflow({ overflow: TextOverflow.Ellipsis })
Row() {
Text(this.starsStr(place.rating))
.fontSize(11)
.fontColor('#FF8F00')
Text(' ' + place.rating.toFixed(1))
.fontSize(11)
.fontColor('#FF8F00')
.fontWeight(FontWeight.Bold)
Text(' ' + place.duration)
.fontSize(11)
.fontColor('#90A4AE')
if (place.cost > 0) {
Text(' ¥' + place.cost)
.fontSize(11)
.fontColor('#43A047')
} else {
Text(' 免费')
.fontSize(11)
.fontColor('#43A047')
}
Column().layoutWeight(1)
if (place.visited) {
Text('✅ 已去')
.fontSize(10)
.fontColor('#43A047')
}
}
.width('100%')
.margin({ top: 4 })
}
.alignItems(HorizontalAlign.Start)
.layoutWeight(1)
}
.width('100%')
.padding(14)
.backgroundColor('#FFFFFF')
.borderRadius(12)
.margin({ bottom: 10 })
.onClick(() => {
this.selectedPlace = place;
this.showPlaceModal = true;
})
}
starsStr(rating: number): string {
const full: number = Math.floor(rating);
let s: string = '';
for (let i: number = 0; i < full; i++) { s += '⭐'; }
if (rating - full >= 0.5) { s += '☆'; }
return s;
}
categoryIcon(cat: string): string {
if (cat === '景点') return '🏛️';
if (cat === '餐厅') return '🍽️';
if (cat === '酒店') return '🏨';
return '🛍️';
}
@Builder
modalOverlay(onClose: () => void) {
Column() {
Column() {
Text('编辑地点')
.fontSize(20)
.fontWeight(FontWeight.Bold)
.fontColor('#333333')
.margin({ bottom: 8 })
if (this.selectedPlace !== null) {
Text(this.selectedPlace.name)
.fontSize(16)
.fontColor('#FF8F00')
.margin({ bottom: 16 })
Text('备注: ' + this.selectedPlace.notes)
.fontSize(13)
.fontColor('#546E7A')
.margin({ bottom: 16 })
}
Text('编辑功能开发中...')
.fontSize(13)
.fontColor('#78909C')
.margin({ bottom: 20 })
Row() {
Text('关闭')
.fontSize(14)
.fontColor('#FFFFFF')
.padding({ left: 28, right: 28, top: 10, bottom: 10 })
.borderRadius(20)
.backgroundColor('#FF8F00')
.onClick(onClose)
}
}
.padding(24)
.backgroundColor('#FFFFFF')
.borderRadius(16)
.width('80%')
}
.width('100%')
.height('100%')
.justifyContent(FlexAlign.Center)
.backgroundColor('rgba(0,0,0,0.5)')
.onClick(onClose)
}
}
// ----- 预算Tab -----
@Component
struct BudgetTabPage {
@State showDeleteConfirm: boolean = false;
@State deleteItemId: number = 0;
build() {
Column() {
Row() {
Text('旅行预算')
.fontSize(22)
.fontWeight(FontWeight.Bold)
.fontColor('#333333')
}
.width('100%')
.padding({ left: 16, right: 16, top: 12, bottom: 4 })
// 预算进度环
this.BudgetOverview()
// 分类柱状图
this.CategoryBarChart()
// 支出列表标题
Row() {
Text('支出明细')
.fontSize(16)
.fontWeight(FontWeight.Bold)
.fontColor('#333333')
}
.width('100%')
.padding({ left: 16, right: 16, top: 8, bottom: 8 })
Scroll() {
Column() {
ForEach(MOCK_BUDGETS, (item: BudgetItemData) => {
this.BudgetItemRow(item)
})
}
.padding({ left: 16, right: 16, bottom: 80 })
}
.layoutWeight(1)
.scrollBar(BarState.Off)
}
.width('100%')
.height('100%')
if (this.showDeleteConfirm) {
this.modalOverlay(() => { this.showDeleteConfirm = false; })
}
}
@Builder
BudgetOverview() {
Row() {
Column() {
Stack() {
Progress({
value: calcTotalBudget(MOCK_BUDGETS) / 150000 * 100,
total: 100,
type: ProgressType.Ring
})
.width(70)
.height(70)
.style({ strokeWidth: 8, scaleCount: 1, scaleWidth: 0 })
.color('#0288D1')
Column() {
Text('¥')
.fontSize(10)
.fontColor('#0288D1')
Text((calcTotalBudget(MOCK_BUDGETS) / 10000).toFixed(1) + '万')
.fontSize(15)
.fontWeight(FontWeight.Bold)
.fontColor('#333333')
}
}
}
.margin({ right: 20 })
Column() {
Row() {
Column() {
Text(MOCK_TRIPS.length.toString())
.fontSize(20)
.fontWeight(FontWeight.Bold)
.fontColor('#0288D1')
Text('行程数')
.fontSize(11)
.fontColor('#78909C')
}
.margin({ right: 24 })
Column() {
Text('¥' + (calcTotalBudget(MOCK_BUDGETS) / 10000).toFixed(1) + '万')
.fontSize(20)
.fontWeight(FontWeight.Bold)
.fontColor('#FF8F00')
Text('总预算')
.fontSize(11)
.fontColor('#78909C')
}
}
.margin({ bottom: 8 })
Row() {
Column() {
Text(MOCK_BUDGETS.length.toString())
.fontSize(20)
.fontWeight(FontWeight.Bold)
.fontColor('#43A047')
Text('支出项')
.fontSize(11)
.fontColor('#78909C')
}
.margin({ right: 24 })
Column() {
Text((calcTotalBudget(MOCK_BUDGETS) / MOCK_TRIPS.length / 10000).toFixed(1) + '万')
.fontSize(20)
.fontWeight(FontWeight.Bold)
.fontColor('#7B1FA2')
Text('平均/程')
.fontSize(11)
.fontColor('#78909C')
}
}
}
.alignItems(HorizontalAlign.Start)
}
.width('100%')
.padding(16)
.backgroundColor('#FFFFFF')
.borderRadius(14)
.margin({ left: 16, right: 16, bottom: 12 })
}
@Builder
CategoryBarChart() {
Column() {
Text('分类支出概览')
.fontSize(14)
.fontWeight(FontWeight.Bold)
.fontColor('#333333')
.margin({ bottom: 10 })
ForEach(BUDGET_CATEGORIES, (cat: BudgetCategoryStat) => {
this.BarRow(cat, calcCategoryTotal(MOCK_BUDGETS, cat.name))
})
}
.width('100%')
.padding(14)
.backgroundColor('#FFFFFF')
.borderRadius(14)
.margin({ left: 16, right: 16, bottom: 12 })
}
@Builder
BarRow(cat: BudgetCategoryStat, amount: number) {
Row() {
Text(cat.icon + ' ' + cat.name)
.fontSize(12)
.fontColor('#546E7A')
.width(60)
Row() {
Row() {
}
.height(16)
.borderRadius(8)
.backgroundColor(cat.color)
.width(this.barWidth(amount))
}
.width('100%')
.layoutWeight(1)
.margin({ left: 8, right: 8 })
Text('¥' + amount)
.fontSize(11)
.fontColor('#333333')
.fontWeight(FontWeight.Bold)
.width(60)
}
.width('100%')
.margin({ bottom: 6 })
}
barWidth(amount: number): string {
const max: number = calcCategoryTotal(MOCK_BUDGETS, '交通') + 2000;
const pct: number = amount / max * 100;
return pct.toFixed(0) + '%';
}
@Builder
BudgetItemRow(item: BudgetItemData) {
Row() {
Text(item.icon)
.fontSize(22)
.margin({ right: 12 })
Column() {
Text(item.description)
.fontSize(14)
.fontColor('#333333')
Text(item.tripTitle + ' | ' + item.date)
.fontSize(11)
.fontColor('#90A4AE')
.margin({ top: 2 })
}
.alignItems(HorizontalAlign.Start)
.layoutWeight(1)
Column() {
Text('¥' + item.amount)
.fontSize(16)
.fontWeight(FontWeight.Bold)
.fontColor(item.color)
Text(item.category)
.fontSize(10)
.fontColor('#90A4AE')
}
Text(' ✕ ')
.fontSize(14)
.fontColor('#B0BEC5')
.margin({ left: 6 })
.onClick(() => {
this.deleteItemId = item.id;
this.showDeleteConfirm = true;
})
}
.width('100%')
.padding(12)
.backgroundColor('#FFFFFF')
.borderRadius(10)
.margin({ bottom: 8 })
}
@Builder
modalOverlay(onClose: () => void) {
Column() {
Column() {
Text('确认删除')
.fontSize(20)
.fontWeight(FontWeight.Bold)
.fontColor('#333333')
.margin({ bottom: 12 })
Text('确定要删除这条预算记录吗?')
.fontSize(14)
.fontColor('#546E7A')
.margin({ bottom: 20 })
Row() {
Text('取消')
.fontSize(14)
.fontColor('#78909C')
.padding({ left: 24, right: 24, top: 10, bottom: 10 })
.borderRadius(20)
.backgroundColor('#ECEFF1')
.onClick(onClose)
Text(' ')
Text('删除')
.fontSize(14)
.fontColor('#FFFFFF')
.padding({ left: 24, right: 24, top: 10, bottom: 10 })
.borderRadius(20)
.backgroundColor('#E91E63')
.onClick(onClose)
}
}
.padding(24)
.backgroundColor('#FFFFFF')
.borderRadius(16)
.width('75%')
}
.width('100%')
.height('100%')
.justifyContent(FlexAlign.Center)
.backgroundColor('rgba(0,0,0,0.5)')
.onClick(onClose)
}
}
// ----- 攻略Tab -----
@Component
struct GuideTabPage {
@State activeGuideCat: number = 0;
build() {
Column() {
Row() {
Text('旅行攻略')
.fontSize(22)
.fontWeight(FontWeight.Bold)
.fontColor('#333333')
}
.width('100%')
.padding({ left: 16, right: 16, top: 12, bottom: 4 })
Scroll() {
Row() {
ForEach(GUIDE_CATEGORIES, (cat: string, idx: number) => {
Text(cat)
.fontSize(13)
.fontColor(idx === this.activeGuideCat ? '#FFFFFF' : '#546E7A')
.backgroundColor(idx === this.activeGuideCat ? '#0288D1' : '#FFFFFF')
.borderRadius(18)
.padding({ left: 14, right: 14, top: 6, bottom: 6 })
.margin({ right: 8 })
.onClick(() => { this.activeGuideCat = idx; })
})
}
.padding({ left: 16, right: 16, bottom: 8 })
}
.scrollable(ScrollDirection.Horizontal)
.scrollBar(BarState.Off)
Scroll() {
Column() {
ForEach(this.filteredGuides(), (guide: GuideItemData) => {
this.GuideCard(guide)
})
}
.padding({ left: 16, right: 16, bottom: 80 })
}
.layoutWeight(1)
.scrollBar(BarState.Off)
}
.width('100%')
.height('100%')
}
filteredGuides(): GuideItemData[] {
const sel: string = GUIDE_CATEGORIES[this.activeGuideCat];
return getGuidesByCategory(MOCK_GUIDES, sel);
}
@Builder
GuideCard(guide: GuideItemData) {
Column() {
Row() {
Column() {
Text(guide.title)
.fontSize(16)
.fontWeight(FontWeight.Bold)
.fontColor('#333333')
Text(guide.summary)
.fontSize(12)
.fontColor('#78909C')
.margin({ top: 4 })
.maxLines(2)
.textOverflow({ overflow: TextOverflow.Ellipsis })
}
.alignItems(HorizontalAlign.Start)
.layoutWeight(1)
Column() {
Text(guide.category)
.fontSize(11)
.fontColor('#FFFFFF')
.backgroundColor('#0288D1')
.borderRadius(10)
.padding({ left: 8, right: 8, top: 4, bottom: 4 })
}
}
.width('100%')
.padding({ top: 4, bottom: 8 })
Row() {
Text('👤 ' + guide.author)
.fontSize(11)
.fontColor('#90A4AE')
Text(' ')
.fontSize(11)
Text('👁 ' + (guide.readCount >= 10000 ? (guide.readCount / 10000).toFixed(1) + '万' : guide.readCount.toString()))
.fontSize(11)
.fontColor('#90A4AE')
Column().layoutWeight(1)
ForEach(guide.tags, (tag: string) => {
Text(tag)
.fontSize(10)
.fontColor('#0288D1')
.borderRadius(8)
.borderWidth(1)
.borderColor('#0288D1')
.padding({ left: 6, right: 6, top: 2, bottom: 2 })
.margin({ left: 4 })
})
}
.width('100%')
}
.width('100%')
.padding(14)
.backgroundColor('#FFFFFF')
.borderRadius(12)
.margin({ bottom: 12 })
.borderWidth({ left: 4 })
.borderColor(guide.coverColor)
}
}
// ----- 我的Tab -----
@Component
struct ProfileTabPage {
build() {
Column() {
Row() {
Column() {
Text('👤')
.fontSize(40)
Text('旅行家')
.fontSize(18)
.fontWeight(FontWeight.Bold)
.fontColor('#333333')
.margin({ top: 4 })
Text('已走过28座城市,累计35次旅行')
.fontSize(12)
.fontColor('#78909C')
.margin({ top: 2 })
}
.padding(20)
}
.width('100%')
.padding({ left: 16, right: 16, top: 12 })
.backgroundColor('#FFFFFF')
.borderRadius({ bottomLeft: 20, bottomRight: 20 })
this.StatGrid()
Text('旅行足迹')
.fontSize(16)
.fontWeight(FontWeight.Bold)
.fontColor('#333333')
.padding({ left: 16, top: 16, bottom: 8 })
.alignSelf(ItemAlign.Start)
Row() {
ForEach(['东京', '大理', '三亚', '成都', '拉萨', '西安', '杭州', '张家界', '厦门', '哈尔滨', '桂林', '重庆', '青岛', '敦煌', '苏州', '武汉', '南京'], (city: string) => {
Text(city)
.fontSize(11)
.fontColor('#0288D1')
.backgroundColor('#E1F5FE')
.borderRadius(12)
.padding({ left: 10, right: 10, top: 5, bottom: 5 })
.margin({ right: 6, bottom: 6 })
})
}
.width('100%')
.padding({ left: 16, right: 16 })
.flexWrap(FlexWrap.Wrap)
Column().layoutWeight(1)
Row() {
Text('⚙️ 设置')
.fontSize(14)
.fontColor('#546E7A')
.padding({ left: 20, top: 10, bottom: 10 })
}
.width('100%')
.margin({ left: 16, right: 16, bottom: 80 })
.backgroundColor('#FFFFFF')
.borderRadius(12)
}
.width('100%')
.height('100%')
}
@Builder
StatGrid() {
Row() {
ForEach(MOCK_TRAVEL_STATS, (stat: TravelStatData) => {
Column() {
Text(stat.icon)
.fontSize(28)
.margin({ bottom: 4 })
Text(stat.label === '花费金额' ? '¥' + (stat.value / 10000).toFixed(1) + '万' : stat.value.toString())
.fontSize(16)
.fontWeight(FontWeight.Bold)
.fontColor(stat.color)
Text(stat.label)
.fontSize(10)
.fontColor('#78909C')
.margin({ top: 2 })
}
.width('23%')
.padding({ top: 10, bottom: 10 })
})
}
.width('100%')
.padding({ left: 10, right: 10, top: 12, bottom: 12 })
.backgroundColor('#FFFFFF')
.borderRadius(14)
.margin({ left: 16, right: 16, top: 12 })
}
}
十三、技术要点总结
从整体架构来看,这款旅行规划APP展现了ArkTS声明式UI开发的成熟范式。其核心设计思想可以概括为"类型驱动数据、数据驱动UI、状态驱动交互"三层递进。最底层的 interface 类型定义了严格的数据契约,保证了全应用的数据形状一致与可推导;中间层的 @Observed 可观察类为响应式更新奠定了基础,虽然当前使用的是静态Mock数据,但这种提前包装使得未来接入真实数据源(如首选项存储、关系型数据库或网络API)时能够无缝切换;上层的 @State 状态管理与 @Builder 构建器组合,实现了UI与状态的自动绑定。这种分层设计使得代码具备良好的可测试性、可维护性与可扩展性。

在视觉设计层面,该APP最值得称道的是"数据驱动配色"的理念。行程卡片的渐变色来自每条数据的 coverColor 字段,地点卡片的图标背景色来自 imageColor 字段,攻略卡片的左侧色条来自 coverColor 字段,预算明细的金额颜色来自 color 字段——每一处色彩都从数据中生长出来,而非硬编码在UI逻辑中。这种设计使得相同的Builder能够渲染出风格迥异但和谐统一的视觉效果,是"内容即设计"思想的具体实践。同时,主色(天空蓝 #0288D1 + 日落橙 #FF8F00)的冷暖对比贯穿全应用,形成了一套自洽的色彩语言。弹窗按钮颜色根据模块语义变化(行程用主色蓝、地点用橙色、删除用警示粉红),体现了对色彩心理学的细致考量。
在交互设计层面,该APP采用了"配置驱动 + 回调注入"的弹窗模式。所有弹窗都通过 modalOverlay(onClose) 这一统一Builder渲染,通过传入不同的回调函数实现不同的关闭逻辑,极大提升了代码复用率。遮罩层点击关闭、按钮显式关闭的双通道关闭机制符合用户直觉。删除操作采用"两步确认"模式,避免了误删风险。横向滚动Tab、maxLines + textOverflow 的文本省略、flexWrap 的自动换行等细节处理,都体现了对多种屏幕尺寸与内容长度的适配考量。ForEach 配合 key(隐式使用对象引用)的列表渲染保证了数据变化时的最小化更新。
从可改进方向来看,该APP仍有若干值得优化的空间。首先,所有数据均为静态Mock,未来应接入 @Observed + @ObjectLink 的完整响应式链路,或使用 AppStorage / LocalStorage 实现跨组件状态共享,使行程、地点、预算之间的数据能够联动(如新增预算时自动更新对应行程的 spent 字段)。其次,弹窗目前是简单的"功能开发中"占位,应替换为真实的表单组件(TextInput、DatePicker、Picker等),并引入表单校验逻辑。第三,列表渲染的 ForEach 未显式指定 keyGenerator,在数据频繁增删时可能影响性能与动画效果,建议为每条数据提供稳定的 key(如 id 字段)。第四,可以引入 @Watch 装饰器监听状态变化,实现更精细的副作用管理(如筛选变化时记录用户行为)。第五,攻略模块缺乏点击进入详情页的能力,可引入 Navigation 组件实现页面跳转与返回栈管理。第六,预算统计目前是实时计算,数据量增大时可考虑引入缓存机制。最后,可考虑增加暗色主题支持,通过 @Media 或自定义主题变量实现日夜模式切换。这些优化方向将使该APP从"功能Demo"进化为"生产级应用"。
综上所述,这款基于HarmonyOS ArkTS的旅行行程规划APP,以其清晰的模块划分、鲜明的视觉语言、扎实的类型系统与可扩展的状态管理,为我们展示了一个优秀的移动端出行管理工具应有的样貌。它不仅是一个功能完整的旅行助手,更是一份值得学习的ArkTS实战教材——从类型定义到数据模型、从静态配置到动态筛选、从入口组件到子页面、从卡片Builder到弹窗Builder,每一层都体现了声明式UI的精髓与工程化的最佳实践。对于想要深入学习HarmonyOS应用开发的开发者而言,这个项目无疑是一个极佳的参考样本。