餐厅美食评分 - KMP OpenHarmony打造的智能指南
餐厅美食评分系统摘要 本文介绍了一个基于Kotlin Multiplatform框架的跨平台餐厅美食评分系统。系统从菜品质量(35%)、服务质量(25%)、环境卫生(25%)和价格合理性(15%)四个维度进行加权评分,综合计算0-100分的餐厅评分并划分星级。系统提供餐厅对比、个性化推荐、美食建议等功能,支持在Android、iOS、Web和OpenHarmony等多平台运行。通过科学的评分算法和

目录
概述
美食已成为现代生活中不可或缺的一部分。无论是日常用餐还是特殊场合聚餐,选择合适的餐厅对于获得最佳美食体验至关重要。然而,面对众多餐厅和大量的用户评价,食客往往难以做出最优选择。餐厅美食评分系统是帮助食客了解餐厅特色、评估餐厅质量、制定最优用餐计划的重要工具。本文档介绍如何在 Kotlin Multiplatform (KMP) 框架下,结合 OpenHarmony 鸿蒙操作系统,实现一个功能完整的餐厅美食评分系统。
餐厅美食评分系统是一个综合性的美食信息平台,它不仅能够对餐厅进行多维度评分,还能够进行餐厅对比、生成美食建议、提供个性化的餐厅推荐。通过KMP框架的跨端能力,这个工具可以在Android、iOS、Web和OpenHarmony等多个平台上运行,为食客提供了一个强大的美食决策辅助工具。
餐厅美食评分的重要性
餐厅美食评分在现代饮食中的重要性日益凸显:
- 品质保证:科学的评分能够帮助食客了解餐厅的真实情况。
- 时间节省:通过评分可以快速找到优质餐厅,节省寻找时间。
- 成本控制:合理的餐厅选择能够控制用餐成本。
- 体验提升:选择高评分餐厅能够显著提升用餐体验。
- 决策支持:评分系统为用餐决策提供了科学的支持。
工具的核心价值
餐厅美食评分系统提供以下价值:
- 多维度评分:从菜品质量、服务态度、环境卫生、价格合理性等多个维度进行评分
- 综合对比:支持多个餐厅的对比分析
- 个性化推荐:根据用户偏好提供个性化的餐厅推荐
- 详细信息:提供餐厅的详细信息和用户评价
- 美食建议:根据评分结果提供美食建议
- 跨平台支持:一份代码可在多个平台运行,提高开发效率
美食评分基础
核心概念
餐厅评分(Restaurant Rating):对餐厅的综合评价,通常用0-100的分数表示。
菜品质量(Dish Quality):餐厅菜品的味道、新鲜度和创意程度。
服务质量(Service Quality):餐厅员工的服务态度和服务效率。
环境卫生(Environment Hygiene):餐厅的环境卫生和装修风格。
价格合理性(Price Reasonableness):菜品价格与质量的匹配度。
用户满意度(User Satisfaction):用户对餐厅的整体满意程度。
常见的餐厅评估维度
菜品特色:餐厅的招牌菜、特色菜等。
烹饪水平:厨师的烹饪技术和创新能力。
服务体验:从进店到离店的整个服务流程。
环境氛围:餐厅的装修风格、音乐、灯光等。
卫生安全:食品卫生、厨房卫生等。
价格定位:菜品价格、人均消费等。
影响餐厅评分的关键因素
食材质量:优质的食材是美食的基础。
烹饪技术:高超的烹饪技术能够提升菜品质量。
服务态度:热情周到的服务能够显著提升用餐体验。
卫生标准:严格的卫生标准是餐厅的基本要求。
创新能力:不断创新的菜品能够吸引更多食客。
口碑积累:良好的口碑是餐厅发展的重要基础。
核心评估方法
1. 菜品评估
评估餐厅菜品的质量和特色。
2. 服务评估
评估餐厅的服务质量和态度。
3. 环境评估
评估餐厅的环境卫生和装修风格。
4. 价格评估
评估菜品价格的合理性。
5. 综合评分
综合考虑多个维度,计算总体评分。
6. 个性化推荐
根据用户偏好提供个性化的餐厅推荐。
Kotlin 源代码
// RestaurantRatingSystem.kt
import java.time.LocalDateTime
import kotlin.math.pow
data class Restaurant(
val id: String,
val name: String,
val cuisine: String,
val location: String,
val priceRange: String,
val openingHours: String
)
data class RestaurantRating(
val restaurantId: String,
val restaurantName: String,
val dishQualityScore: Double,
val serviceScore: Double,
val environmentScore: Double,
val priceScore: Double,
val overallScore: Double,
val ratingLevel: String,
val reviewCount: Int,
val averageConsumption: Double,
val recommendations: List<String>,
val timestamp: String
)
data class RatingMetrics(
val totalRestaurants: Long,
val averageScore: Double,
val highestRatedRestaurant: String,
val lowestRatedRestaurant: String,
val averageConsumption: Double,
val mostPopularCuisine: String
)
data class RestaurantComparison(
val restaurants: List<RestaurantRating>,
val bestDishes: String,
val bestService: String,
val bestEnvironment: String,
val bestValue: String,
val recommendation: String
)
class RestaurantRatingSystem {
private val restaurants = mutableListOf<Restaurant>()
private val ratings = mutableListOf<RestaurantRating>()
private var restaurantIdCounter = 0
// 添加餐厅
fun addRestaurant(
name: String,
cuisine: String,
location: String,
priceRange: String,
openingHours: String
): Restaurant {
val id = "REST${++restaurantIdCounter}"
val restaurant = Restaurant(id, name, cuisine, location, priceRange, openingHours)
restaurants.add(restaurant)
return restaurant
}
// 评分餐厅
fun rateRestaurant(
restaurantId: String,
dishQualityScore: Double,
serviceScore: Double,
environmentScore: Double,
priceScore: Double,
reviewCount: Int,
averageConsumption: Double
): RestaurantRating {
val restaurant = restaurants.find { it.id == restaurantId }
?: return RestaurantRating("", "", 0.0, 0.0, 0.0, 0.0, 0.0, "", 0, 0.0, emptyList(), "")
// 确保分数在0-100范围内
val dishQuality = minOf(maxOf(dishQualityScore, 0.0), 100.0)
val service = minOf(maxOf(serviceScore, 0.0), 100.0)
val environment = minOf(maxOf(environmentScore, 0.0), 100.0)
val price = minOf(maxOf(priceScore, 0.0), 100.0)
// 计算综合评分(加权平均)
val overallScore = dishQuality * 0.35 + service * 0.25 + environment * 0.25 + price * 0.15
// 判断评分等级
val ratingLevel = when {
overallScore >= 90 -> "5星"
overallScore >= 80 -> "4星"
overallScore >= 70 -> "3星"
overallScore >= 60 -> "2星"
else -> "1星"
}
// 生成建议
val recommendations = generateRecommendations(
dishQuality, service, environment, price, reviewCount, restaurant.cuisine
)
val rating = RestaurantRating(
restaurantId, restaurant.name, dishQuality, service, environment, price,
overallScore, ratingLevel, reviewCount, averageConsumption,
recommendations, LocalDateTime.now().toString()
)
ratings.add(rating)
return rating
}
// 生成建议
private fun generateRecommendations(
dishQuality: Double,
service: Double,
environment: Double,
price: Double,
reviewCount: Int,
cuisine: String
): List<String> {
val recommendations = mutableListOf<String>()
if (dishQuality >= 85) {
recommendations.add("🍽️ 菜品质量优秀,强烈推荐品尝")
} else if (dishQuality < 60) {
recommendations.add("🍽️ 菜品质量一般,可作为备选")
}
if (service >= 80) {
recommendations.add("👥 服务态度热情,用餐体验佳")
} else if (service < 60) {
recommendations.add("👥 服务有待改进,可能影响体验")
}
if (environment >= 80) {
recommendations.add("🏠 环境舒适卫生,适合聚餐")
} else if (environment < 60) {
recommendations.add("🏠 环境一般,建议提前了解")
}
if (price >= 75) {
recommendations.add("💰 性价比高,物有所值")
} else if (price < 50) {
recommendations.add("💰 价格较高,需谨慎考虑")
}
if (reviewCount > 1000) {
recommendations.add("⭐ 评价众多,口碑良好")
} else if (reviewCount < 100) {
recommendations.add("⭐ 评价较少,可能新店")
}
if (cuisine == "中餐" && dishQuality >= 80) {
recommendations.add("🥢 中餐烹饪精湛,值得一试")
} else if (cuisine == "西餐" && service >= 80) {
recommendations.add("🍷 西餐服务专业,用餐优雅")
}
return recommendations
}
// 获取评分指标
fun getRatingMetrics(): RatingMetrics {
if (ratings.isEmpty()) {
return RatingMetrics(0, 0.0, "", "", 0.0, "")
}
val totalRestaurants = restaurants.size.toLong()
val averageScore = ratings.map { it.overallScore }.average()
val highestRated = ratings.maxByOrNull { it.overallScore }?.restaurantName ?: ""
val lowestRated = ratings.minByOrNull { it.overallScore }?.restaurantName ?: ""
val averageConsumption = ratings.map { it.averageConsumption }.average()
val mostPopularCuisine = restaurants.groupBy { it.cuisine }
.maxByOrNull { it.value.size }?.key ?: ""
return RatingMetrics(
totalRestaurants, averageScore, highestRated, lowestRated,
averageConsumption, mostPopularCuisine
)
}
// 获取所有评分
fun getAllRatings(): List<RestaurantRating> {
return ratings.toList()
}
// 餐厅对比
fun compareRestaurants(restaurantIds: List<String>): RestaurantComparison {
val comparisonRatings = ratings.filter { it.restaurantId in restaurantIds }
val bestDishes = comparisonRatings.maxByOrNull { it.dishQualityScore }?.restaurantName ?: ""
val bestService = comparisonRatings.maxByOrNull { it.serviceScore }?.restaurantName ?: ""
val bestEnvironment = comparisonRatings.maxByOrNull { it.environmentScore }?.restaurantName ?: ""
val bestValue = comparisonRatings.maxByOrNull { it.priceScore }?.restaurantName ?: ""
val avgScore = comparisonRatings.map { it.overallScore }.average()
val recommendation = when {
avgScore >= 85 -> "这些餐厅整体评分很高,都值得品尝"
avgScore >= 75 -> "这些餐厅评分良好,可根据偏好选择"
else -> "这些餐厅评分一般,建议选择评分最高的"
}
return RestaurantComparison(
comparisonRatings, bestDishes, bestService, bestEnvironment, bestValue, recommendation
)
}
// 生成美食报告
fun generateFoodReport(): Map<String, Any> {
val metrics = getRatingMetrics()
return mapOf(
"timestamp" to LocalDateTime.now().toString(),
"metrics" to metrics,
"ratings" to ratings.toList(),
"topRestaurants" to ratings.sortedByDescending { it.overallScore }.take(5),
"recommendations" to generateGeneralRecommendations(metrics)
)
}
// 生成通用建议
private fun generateGeneralRecommendations(metrics: RatingMetrics): List<String> {
val recommendations = mutableListOf<String>()
if (metrics.averageScore >= 80) {
recommendations.add("📊 整体餐厅质量高,美食选择丰富")
} else if (metrics.averageScore < 70) {
recommendations.add("📊 整体餐厅质量一般,建议选择高评分餐厅")
}
if (metrics.averageConsumption > 100) {
recommendations.add("💵 人均消费较高,建议提前预算")
}
recommendations.add("✅ 根据个人口味选择餐厅,享受美食体验")
return recommendations
}
// 清空数据
fun clearData() {
restaurants.clear()
ratings.clear()
}
}
fun main() {
val system = RestaurantRatingSystem()
// 添加餐厅
system.addRestaurant("老字号饭店", "中餐", "市中心", "中等", "11:00-22:00")
system.addRestaurant("西餐厅", "西餐", "商业街", "高档", "12:00-23:00")
system.addRestaurant("火锅城", "火锅", "城北", "中等", "10:00-23:30")
// 评分餐厅
val rating1 = system.rateRestaurant("REST1", 92.0, 88.0, 85.0, 80.0, 500, 60.0)
val rating2 = system.rateRestaurant("REST2", 90.0, 92.0, 90.0, 75.0, 800, 150.0)
val rating3 = system.rateRestaurant("REST3", 88.0, 85.0, 82.0, 85.0, 600, 70.0)
println("餐厅评分结果:")
println("${rating1.restaurantName}: ${String.format("%.2f", rating1.overallScore)} (${rating1.ratingLevel})")
println("${rating2.restaurantName}: ${String.format("%.2f", rating2.overallScore)} (${rating2.ratingLevel})")
println("${rating3.restaurantName}: ${String.format("%.2f", rating3.overallScore)} (${rating3.ratingLevel})")
// 生成报告
val report = system.generateFoodReport()
println("\n美食报告已生成")
}
Kotlin代码说明:这个Kotlin实现提供了完整的餐厅美食评分功能。RestaurantRatingSystem 类能够管理餐厅信息、进行餐厅评分、进行餐厅对比、生成美食报告。通过使用数据类和科学的计算方法,代码既简洁又准确。系统支持多维度的餐厅分析,从单个餐厅的详细评分到整个餐厅库的趋势分析,为食客提供了全面的美食决策支持。
JavaScript 编译代码
// RestaurantRatingSystem.js
class Restaurant {
constructor(id, name, cuisine, location, priceRange, openingHours) {
this.id = id;
this.name = name;
this.cuisine = cuisine;
this.location = location;
this.priceRange = priceRange;
this.openingHours = openingHours;
}
}
class RestaurantRating {
constructor(restaurantId, restaurantName, dishQualityScore, serviceScore, environmentScore, priceScore, overallScore, ratingLevel, reviewCount, averageConsumption, recommendations, timestamp) {
this.restaurantId = restaurantId;
this.restaurantName = restaurantName;
this.dishQualityScore = dishQualityScore;
this.serviceScore = serviceScore;
this.environmentScore = environmentScore;
this.priceScore = priceScore;
this.overallScore = overallScore;
this.ratingLevel = ratingLevel;
this.reviewCount = reviewCount;
this.averageConsumption = averageConsumption;
this.recommendations = recommendations;
this.timestamp = timestamp;
}
}
class RatingMetrics {
constructor(totalRestaurants, averageScore, highestRatedRestaurant, lowestRatedRestaurant, averageConsumption, mostPopularCuisine) {
this.totalRestaurants = totalRestaurants;
this.averageScore = averageScore;
this.highestRatedRestaurant = highestRatedRestaurant;
this.lowestRatedRestaurant = lowestRatedRestaurant;
this.averageConsumption = averageConsumption;
this.mostPopularCuisine = mostPopularCuisine;
}
}
class RestaurantRatingSystem {
constructor() {
this.restaurants = [];
this.ratings = [];
this.restaurantIdCounter = 0;
}
addRestaurant(name, cuisine, location, priceRange, openingHours) {
const id = `REST${++this.restaurantIdCounter}`;
const restaurant = new Restaurant(id, name, cuisine, location, priceRange, openingHours);
this.restaurants.push(restaurant);
return restaurant;
}
rateRestaurant(restaurantId, dishQualityScore, serviceScore, environmentScore, priceScore, reviewCount, averageConsumption) {
const restaurant = this.restaurants.find(r => r.id === restaurantId);
if (!restaurant) return null;
const dishQuality = Math.min(Math.max(dishQualityScore, 0), 100);
const service = Math.min(Math.max(serviceScore, 0), 100);
const environment = Math.min(Math.max(environmentScore, 0), 100);
const price = Math.min(Math.max(priceScore, 0), 100);
const overallScore = dishQuality * 0.35 + service * 0.25 + environment * 0.25 + price * 0.15;
let ratingLevel;
if (overallScore >= 90) ratingLevel = "5星";
else if (overallScore >= 80) ratingLevel = "4星";
else if (overallScore >= 70) ratingLevel = "3星";
else if (overallScore >= 60) ratingLevel = "2星";
else ratingLevel = "1星";
const recommendations = this.generateRecommendations(dishQuality, service, environment, price, reviewCount, restaurant.cuisine);
const rating = new RestaurantRating(restaurantId, restaurant.name, dishQuality, service, environment, price, overallScore, ratingLevel, reviewCount, averageConsumption, recommendations, new Date().toISOString());
this.ratings.push(rating);
return rating;
}
generateRecommendations(dishQuality, service, environment, price, reviewCount, cuisine) {
const recommendations = [];
if (dishQuality >= 85) {
recommendations.push("🍽️ 菜品质量优秀,强烈推荐品尝");
} else if (dishQuality < 60) {
recommendations.push("🍽️ 菜品质量一般,可作为备选");
}
if (service >= 80) {
recommendations.push("👥 服务态度热情,用餐体验佳");
} else if (service < 60) {
recommendations.push("👥 服务有待改进,可能影响体验");
}
if (environment >= 80) {
recommendations.push("🏠 环境舒适卫生,适合聚餐");
} else if (environment < 60) {
recommendations.push("🏠 环境一般,建议提前了解");
}
if (price >= 75) {
recommendations.push("💰 性价比高,物有所值");
} else if (price < 50) {
recommendations.push("💰 价格较高,需谨慎考虑");
}
if (reviewCount > 1000) {
recommendations.push("⭐ 评价众多,口碑良好");
} else if (reviewCount < 100) {
recommendations.push("⭐ 评价较少,可能新店");
}
if (cuisine === "中餐" && dishQuality >= 80) {
recommendations.push("🥢 中餐烹饪精湛,值得一试");
} else if (cuisine === "西餐" && service >= 80) {
recommendations.push("🍷 西餐服务专业,用餐优雅");
}
return recommendations;
}
getRatingMetrics() {
if (this.ratings.length === 0) {
return new RatingMetrics(0, 0, "", "", 0, "");
}
const totalRestaurants = this.restaurants.length;
const averageScore = this.ratings.reduce((sum, r) => sum + r.overallScore, 0) / this.ratings.length;
const highestRated = this.ratings.reduce((max, r) => r.overallScore > max.overallScore ? r : max).restaurantName;
const lowestRated = this.ratings.reduce((min, r) => r.overallScore < min.overallScore ? r : min).restaurantName;
const averageConsumption = this.ratings.reduce((sum, r) => sum + r.averageConsumption, 0) / this.ratings.length;
const cuisineCount = {};
for (const restaurant of this.restaurants) {
cuisineCount[restaurant.cuisine] = (cuisineCount[restaurant.cuisine] || 0) + 1;
}
const mostPopularCuisine = Object.keys(cuisineCount).reduce((a, b) => cuisineCount[a] > cuisineCount[b] ? a : b, "");
return new RatingMetrics(totalRestaurants, averageScore, highestRated, lowestRated, averageConsumption, mostPopularCuisine);
}
getAllRatings() {
return this.ratings;
}
compareRestaurants(restaurantIds) {
const comparisonRatings = this.ratings.filter(r => restaurantIds.includes(r.restaurantId));
const bestDishes = comparisonRatings.reduce((max, r) => r.dishQualityScore > max.dishQualityScore ? r : max).restaurantName;
const bestService = comparisonRatings.reduce((max, r) => r.serviceScore > max.serviceScore ? r : max).restaurantName;
const bestEnvironment = comparisonRatings.reduce((max, r) => r.environmentScore > max.environmentScore ? r : max).restaurantName;
const bestValue = comparisonRatings.reduce((max, r) => r.priceScore > max.priceScore ? r : max).restaurantName;
const avgScore = comparisonRatings.reduce((sum, r) => sum + r.overallScore, 0) / comparisonRatings.length;
let recommendation;
if (avgScore >= 85) recommendation = "这些餐厅整体评分很高,都值得品尝";
else if (avgScore >= 75) recommendation = "这些餐厅评分良好,可根据偏好选择";
else recommendation = "这些餐厅评分一般,建议选择评分最高的";
return {
restaurants: comparisonRatings,
bestDishes: bestDishes,
bestService: bestService,
bestEnvironment: bestEnvironment,
bestValue: bestValue,
recommendation: recommendation
};
}
generateFoodReport() {
const metrics = this.getRatingMetrics();
return {
timestamp: new Date().toISOString(),
metrics: metrics,
ratings: this.ratings,
topRestaurants: this.ratings.sort((a, b) => b.overallScore - a.overallScore).slice(0, 5),
recommendations: this.generateGeneralRecommendations(metrics)
};
}
generateGeneralRecommendations(metrics) {
const recommendations = [];
if (metrics.averageScore >= 80) {
recommendations.push("📊 整体餐厅质量高,美食选择丰富");
} else if (metrics.averageScore < 70) {
recommendations.push("📊 整体餐厅质量一般,建议选择高评分餐厅");
}
if (metrics.averageConsumption > 100) {
recommendations.push("💵 人均消费较高,建议提前预算");
}
recommendations.push("✅ 根据个人口味选择餐厅,享受美食体验");
return recommendations;
}
clearData() {
this.restaurants = [];
this.ratings = [];
}
}
// 使用示例
const system = new RestaurantRatingSystem();
system.addRestaurant("老字号饭店", "中餐", "市中心", "中等", "11:00-22:00");
system.addRestaurant("西餐厅", "西餐", "商业街", "高档", "12:00-23:00");
system.addRestaurant("火锅城", "火锅", "城北", "中等", "10:00-23:30");
const rating1 = system.rateRestaurant("REST1", 92, 88, 85, 80, 500, 60);
const rating2 = system.rateRestaurant("REST2", 90, 92, 90, 75, 800, 150);
const rating3 = system.rateRestaurant("REST3", 88, 85, 82, 85, 600, 70);
console.log("餐厅评分结果:");
console.log(`${rating1.restaurantName}: ${rating1.overallScore.toFixed(2)} (${rating1.ratingLevel})`);
console.log(`${rating2.restaurantName}: ${rating2.overallScore.toFixed(2)} (${rating2.ratingLevel})`);
console.log(`${rating3.restaurantName}: ${rating3.overallScore.toFixed(2)} (${rating3.ratingLevel})`);
const report = system.generateFoodReport();
console.log("\n美食报告已生成");
JavaScript代码说明:JavaScript版本是Kotlin代码的直接转译。我们使用ES6的class语法定义各个类,使用数学函数进行计算。整体逻辑和算法与Kotlin版本保持一致,确保跨平台的一致性。JavaScript的灵活性使得代码更加简洁,同时保持了清晰的结构和完整的功能。
ArkTS 调用代码
// RestaurantRatingPage.ets
import { RestaurantRatingSystem } from './RestaurantRatingSystem';
@Entry
@Component
struct RestaurantRatingPage {
@State restaurantName: string = '老字号饭店';
@State cuisine: string = '中餐';
@State location: string = '市中心';
@State priceRange: string = '中等';
@State dishQualityScore: number = 90;
@State serviceScore: number = 85;
@State environmentScore: number = 80;
@State priceScore: number = 80;
@State reviewCount: number = 500;
@State averageConsumption: number = 60;
@State selectedTab: number = 0;
@State ratings: Array<any> = [];
@State metrics: any = null;
@State isLoading: boolean = false;
@State errorMessage: string = '';
@State report: any = null;
private system: RestaurantRatingSystem = new RestaurantRatingSystem();
private cuisines = ['中餐', '西餐', '日料', '韩餐', '火锅', '烤肉', '海鲜'];
private priceRanges = ['便宜', '中等', '高档', '超高档'];
addAndRateRestaurant() {
if (!this.restaurantName.trim() || !this.location.trim()) {
this.errorMessage = '请输入餐厅名称和位置';
return;
}
this.isLoading = true;
this.errorMessage = '';
try {
this.system.addRestaurant(
this.restaurantName,
this.cuisine,
this.location,
this.priceRange,
"全天营业"
);
const restaurantId = `REST${this.ratings.length + 1}`;
this.system.rateRestaurant(
restaurantId,
this.dishQualityScore,
this.serviceScore,
this.environmentScore,
this.priceScore,
this.reviewCount,
this.averageConsumption
);
this.ratings = this.system.getAllRatings();
this.metrics = this.system.getRatingMetrics();
AlertDialog.show({ message: '餐厅已添加并评分' });
// 重置表单
this.restaurantName = '';
this.location = '';
this.dishQualityScore = 80;
this.serviceScore = 80;
this.environmentScore = 80;
this.priceScore = 80;
} catch (error) {
this.errorMessage = '操作失败: ' + error.message;
} finally {
this.isLoading = false;
}
}
generateReport() {
this.isLoading = true;
try {
this.report = this.system.generateFoodReport();
} catch (error) {
this.errorMessage = '生成报告失败: ' + error.message;
} finally {
this.isLoading = false;
}
}
getRatingLevelColor(level: string): string {
switch (level) {
case '5星': return '#FFD700';
case '4星': return '#4CAF50';
case '3星': return '#FF9800';
case '2星': return '#F44336';
case '1星': return '#D32F2F';
default: return '#999999';
}
}
build() {
Column() {
Text('餐厅美食评分系统')
.fontSize(24)
.fontWeight(FontWeight.Bold)
.margin({ top: 20, bottom: 20 })
Tabs({ barPosition: BarPosition.Start }) {
TabContent() {
Column() {
Text('添加餐厅').fontSize(14).fontWeight(FontWeight.Bold).margin({ bottom: 15 })
Text('餐厅名称:').fontSize(12).margin({ bottom: 5 })
TextInput({ placeholder: '老字号饭店' })
.value(this.restaurantName)
.onChange((value: string) => { this.restaurantName = value; })
.height(40).padding(10).border({ width: 1, color: '#cccccc' }).margin({ bottom: 15 })
Row() {
Column() {
Text('位置:').fontSize(12).margin({ bottom: 5 })
TextInput({ placeholder: '市中心' })
.value(this.location)
.onChange((value: string) => { this.location = value; })
.height(40).padding(10).border({ width: 1, color: '#cccccc' })
}
.flex(1)
Column() {
Text('人均消费:').fontSize(12).margin({ bottom: 5 })
TextInput({ placeholder: '60' })
.type(InputType.Number)
.value(this.averageConsumption.toString())
.onChange((value: string) => { this.averageConsumption = parseFloat(value) || 0; })
.height(40).padding(10).border({ width: 1, color: '#cccccc' })
}
.flex(1)
.margin({ left: 10 })
}
.margin({ bottom: 15 })
Row() {
Column() {
Text('菜系:').fontSize(12).margin({ bottom: 5 })
Select(this.cuisines.map(c => ({ value: c })))
.value(this.cuisine)
.onSelect((index: number, value?: string) => {
this.cuisine = value || '中餐';
})
}
.flex(1)
Column() {
Text('价位:').fontSize(12).margin({ bottom: 5 })
Select(this.priceRanges.map(p => ({ value: p })))
.value(this.priceRange)
.onSelect((index: number, value?: string) => {
this.priceRange = value || '中等';
})
}
.flex(1)
.margin({ left: 10 })
}
.margin({ bottom: 15 })
Text('菜品质量评分:').fontSize(12).margin({ bottom: 5 })
Slider({ value: this.dishQualityScore, min: 0, max: 100, step: 5 })
.onChange((value: number) => { this.dishQualityScore = value; })
.margin({ bottom: 15 })
Row() {
Column() {
Text('服务评分:').fontSize(12).margin({ bottom: 5 })
Slider({ value: this.serviceScore, min: 0, max: 100, step: 5 })
.onChange((value: number) => { this.serviceScore = value; })
}
.flex(1)
Column() {
Text('环境评分:').fontSize(12).margin({ bottom: 5 })
Slider({ value: this.environmentScore, min: 0, max: 100, step: 5 })
.onChange((value: number) => { this.environmentScore = value; })
}
.flex(1)
.margin({ left: 10 })
}
.margin({ bottom: 15 })
Text('价格评分:').fontSize(12).margin({ bottom: 5 })
Slider({ value: this.priceScore, min: 0, max: 100, step: 5 })
.onChange((value: number) => { this.priceScore = value; })
.margin({ bottom: 15 })
Text('评价数:').fontSize(12).margin({ bottom: 5 })
TextInput({ placeholder: '500' })
.type(InputType.Number)
.value(this.reviewCount.toString())
.onChange((value: string) => { this.reviewCount = parseInt(value) || 0; })
.height(40).padding(10).border({ width: 1, color: '#cccccc' }).margin({ bottom: 15 })
Button('添加并评分').width('100%').height(40).margin({ bottom: 15 })
.onClick(() => { this.addAndRateRestaurant(); }).enabled(!this.isLoading)
if (this.errorMessage) {
Text(this.errorMessage).fontSize(12).fontColor('#F44336').margin({ bottom: 15 })
}
}
.padding(15)
}
.tabBar('➕ 添加餐厅')
TabContent() {
Column() {
if (this.ratings.length > 0) {
Text('餐厅评分').fontSize(16).fontWeight(FontWeight.Bold).margin({ bottom: 15 })
List() {
ForEach(this.ratings, (rating: any) => {
ListItem() {
Column() {
Row() {
Text(rating.restaurantName).fontSize(14).fontWeight(FontWeight.Bold).flex(1)
Text(rating.ratingLevel).fontSize(12).fontColor(this.getRatingLevelColor(rating.ratingLevel))
.fontWeight(FontWeight.Bold)
}
.margin({ bottom: 10 })
Row() {
Text('综合评分:').fontSize(11)
Text(rating.overallScore.toFixed(1)).fontSize(11).fontWeight(FontWeight.Bold)
.fontColor('#2196F3')
}
.margin({ bottom: 5 })
Row() {
Column() {
Text('菜品:').fontSize(10).fontColor('#999999')
Text(rating.dishQualityScore.toFixed(0)).fontSize(10).fontWeight(FontWeight.Bold)
}
.flex(1)
Column() {
Text('服务:').fontSize(10).fontColor('#999999')
Text(rating.serviceScore.toFixed(0)).fontSize(10).fontWeight(FontWeight.Bold)
}
.flex(1)
Column() {
Text('环境:').fontSize(10).fontColor('#999999')
Text(rating.environmentScore.toFixed(0)).fontSize(10).fontWeight(FontWeight.Bold)
}
.flex(1)
Column() {
Text('价格:').fontSize(10).fontColor('#999999')
Text(rating.priceScore.toFixed(0)).fontSize(10).fontWeight(FontWeight.Bold)
}
.flex(1)
}
}
.padding(10).border({ width: 1, color: '#eeeeee' }).borderRadius(5)
}
}, (rating: any) => rating.restaurantId)
}
} else {
Text('请先添加餐厅').fontSize(12).fontColor('#999999')
}
}
.padding(15)
}
.tabBar('⭐ 评分列表')
TabContent() {
Column() {
if (this.metrics) {
Text('评分指标').fontSize(16).fontWeight(FontWeight.Bold).margin({ bottom: 15 })
Row() {
Column() {
Text('平均评分').fontSize(11).fontColor('#999999')
Text(this.metrics.averageScore.toFixed(1)).fontSize(18)
.fontWeight(FontWeight.Bold).fontColor('#2196F3').margin({ top: 5 })
}
.flex(1).alignItems(HorizontalAlign.Center).padding(15).backgroundColor('#F5F5F5').borderRadius(5)
Column() {
Text('餐厅总数').fontSize(11).fontColor('#999999')
Text(this.metrics.totalRestaurants.toString()).fontSize(18)
.fontWeight(FontWeight.Bold).fontColor('#4CAF50').margin({ top: 5 })
}
.flex(1).alignItems(HorizontalAlign.Center).padding(15).backgroundColor('#F5F5F5').borderRadius(5)
.margin({ left: 10 })
}
.margin({ bottom: 15 })
Column() {
Row() {
Text('最高评分:').fontSize(12)
Text(this.metrics.highestRatedRestaurant).fontSize(12).fontWeight(FontWeight.Bold)
}
.margin({ bottom: 10 })
Row() {
Text('最低评分:').fontSize(12)
Text(this.metrics.lowestRatedRestaurant).fontSize(12).fontWeight(FontWeight.Bold)
}
.margin({ bottom: 10 })
Row() {
Text('热门菜系:').fontSize(12)
Text(this.metrics.mostPopularCuisine).fontSize(12).fontWeight(FontWeight.Bold)
}
}
.padding(10).backgroundColor('#F5F5F5').borderRadius(5)
} else {
Text('请先添加餐厅').fontSize(12).fontColor('#999999')
}
}
.padding(15)
}
.tabBar('📊 指标')
TabContent() {
Column() {
Button('生成报告').width('100%').height(40).margin({ bottom: 15 })
.onClick(() => { this.generateReport(); })
if (this.report) {
Text('美食报告').fontSize(16).fontWeight(FontWeight.Bold).margin({ bottom: 15 })
if (this.report.recommendations && this.report.recommendations.length > 0) {
Text('建议:').fontSize(14).fontWeight(FontWeight.Bold).margin({ bottom: 10 })
Column() {
ForEach(this.report.recommendations, (rec: string, index: number) => {
Row() {
Text('•').fontSize(14).fontWeight(FontWeight.Bold).margin({ right: 10 })
Text(rec).fontSize(11).flex(1)
}
.padding(10).margin({ bottom: 8 }).backgroundColor('#E3F2FD').borderRadius(5)
}, (rec: string, index: number) => index.toString())
}
}
}
}
.padding(15)
}
.tabBar('📈 报告')
}
.width('100%')
.flex(1)
}
.padding(10)
.width('100%')
.height('100%')
}
}
ArkTS代码说明:这个ArkTS实现展示了如何在OpenHarmony应用中集成餐厅美食评分系统。通过使用标签页组件,用户可以在添加餐厅、查看评分列表、查看评分指标和生成报告之间切换。UI设计直观,提供了良好的用户体验。每个标签页都有不同的功能,用户可以全面地进行餐厅评分和美食选择。
评分指标详解
餐厅评分维度
菜品质量评分:餐厅菜品的味道、新鲜度和创意程度,范围0-100。
服务评分:餐厅员工的服务态度和服务效率,范围0-100。
环境评分:餐厅的环境卫生和装修风格,范围0-100。
价格评分:菜品价格与质量的匹配度,范围0-100。
综合评分:四个维度的加权平均,权重分别为35%、25%、25%、15%。
评分等级
5星:综合评分90-100分,餐厅质量优秀。
4星:综合评分80-89分,餐厅质量良好。
3星:综合评分70-79分,餐厅质量一般。
2星:综合评分60-69分,餐厅质量较差。
1星:综合评分0-59分,餐厅质量很差。
实战应用
应用场景1:美食选择
食客可以使用这个系统评估不同餐厅,制定最优的用餐计划。
应用场景2:餐厅管理
餐厅管理部门可以使用这个系统了解用户评价,改进餐厅管理。
应用场景3:美食推荐
美食平台可以集成这个系统,为用户提供个性化的餐厅推荐。
应用场景4:美食研究
美食研究机构可以使用这个系统进行餐厅评估和美食市场分析。
总结
餐厅美食评分系统是现代美食生活中的重要工具。通过KMP框架和OpenHarmony操作系统的结合,我们可以实现一个功能完整、高效可靠的餐厅评分系统。
这个工具不仅能够对餐厅进行多维度评分,还能够进行餐厅对比、生成美食建议、提供个性化的餐厅推荐。通过本文介绍的Kotlin实现、JavaScript编译和ArkTS调用,食客可以快速构建自己的美食决策系统。
在实际应用中,餐厅评分的价值远不止于此。从提升用餐体验到优化餐饮资源配置,从支持美食决策到促进餐饮产业发展,餐厅评分都发挥着重要的作用。通过持续改进和优化,可以构建更加科学和高效的美食评估体系。
掌握好餐厅评分的方法和工具,对于提升美食体验和实现美食目标都有重要的帮助。通过这个系统的学习和使用,希望能够帮助食客更好地了解餐厅特色,制定科学的用餐计划,享受美好的美食体验。欢迎加入开源鸿蒙跨平台社区:https://openharmonycrossplatform.csdn.net
更多推荐



所有评论(0)