|
@@ -34,7 +34,6 @@ export class WayPage implements OnInit {
|
|
|
|
|
|
ngOnInit() {
|
|
|
this.loadRoutes();
|
|
|
- this.loadBirdTypes();
|
|
|
}
|
|
|
// 显示创建表单
|
|
|
showCreateForm() {
|
|
@@ -73,6 +72,7 @@ export class WayPage implements OnInit {
|
|
|
for (const birdId of this.newRouteData.birds) {
|
|
|
const birdQuery = new CloudQuery("BirdType");
|
|
|
birdQuery.equalTo("objectId", birdId);
|
|
|
+
|
|
|
const bird = await birdQuery.first();
|
|
|
if (bird) {
|
|
|
birdPointers.push(bird.toPointer());
|
|
@@ -126,11 +126,15 @@ export class WayPage implements OnInit {
|
|
|
|
|
|
// 在组件类中添加
|
|
|
routeDetailedBirdsMap = new Map<string, CloudObject[]>(); // 存储路线ID到鸟类数组的映射
|
|
|
+// 添加获取路线鸟类的方法
|
|
|
+ getBirdsForRoute(routeId: string): CloudObject[] {
|
|
|
+ return this.routeDetailedBirdsMap.get(routeId) || [];
|
|
|
+ }
|
|
|
|
|
|
async loadRoutes() {
|
|
|
this.isLoading = true;
|
|
|
try {
|
|
|
- let query = new CloudQuery("Route");
|
|
|
+ const query = new CloudQuery("Route");
|
|
|
query.include("birds"); // 如果birds是指针数组,可能需要这个
|
|
|
|
|
|
const routes: CloudObject[] = await query.find();
|
|
@@ -138,6 +142,8 @@ async loadRoutes() {
|
|
|
|
|
|
// 并行获取所有路线的鸟类数据
|
|
|
await Promise.all(routes.map(async route => {
|
|
|
+ if (!route.id) return;
|
|
|
+
|
|
|
const detailedBirds = [];
|
|
|
const birdPointers = route.get('birds') || [];
|
|
|
|
|
@@ -147,14 +153,11 @@ async loadRoutes() {
|
|
|
const bird = await birdQuery.first();
|
|
|
if (bird) detailedBirds.push(bird);
|
|
|
}
|
|
|
-
|
|
|
- this.routes.forEach(route => {
|
|
|
- if (!route.id) return;
|
|
|
- this.routeDetailedBirdsMap.set(route.id, this.routeDetailedBirdsMap.get(route.id) || []);
|
|
|
- });
|
|
|
+ this.routeDetailedBirdsMap.set(route.id, detailedBirds);
|
|
|
+
|
|
|
}));
|
|
|
|
|
|
- this.routes = [...routes];
|
|
|
+ this.routes = routes;
|
|
|
} catch (error) {
|
|
|
console.error("加载路线数据失败", error);
|
|
|
} finally {
|
|
@@ -162,15 +165,7 @@ async loadRoutes() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// 添加辅助方法
|
|
|
-getRouteBirds(routeId: string | undefined): CloudObject[] {
|
|
|
- if (!routeId) return [];
|
|
|
- const birds = this.routeDetailedBirdsMap.get(routeId);
|
|
|
- console.log(`获取路线 ${routeId} 的鸟类:`, birds);
|
|
|
- return birds || [];
|
|
|
- }
|
|
|
-
|
|
|
- getStars(rating: number): string[] {
|
|
|
+getStars(rating: number): string[] {
|
|
|
const fullStars = Math.floor(rating);
|
|
|
const halfStar = rating % 1 >= 0.5 ? 1 : 0;
|
|
|
const emptyStars = 5 - fullStars - halfStar;
|
|
@@ -182,7 +177,7 @@ getRouteBirds(routeId: string | undefined): CloudObject[] {
|
|
|
];
|
|
|
}
|
|
|
|
|
|
- async importSampleRoutes() {
|
|
|
+async importSampleRoutes() {
|
|
|
const routeDataset = [
|
|
|
{
|
|
|
name: "鄱阳湖冬季候鸟观赏路线",
|
|
@@ -288,6 +283,7 @@ getRouteBirds(routeId: string | undefined): CloudObject[] {
|
|
|
|
|
|
if (bird) {
|
|
|
birdPointers.push(bird.toPointer());
|
|
|
+ console.log(`找到鸟类:${birdData.name}`);
|
|
|
} else {
|
|
|
console.warn(`未找到鸟类: ${birdData.name}`);
|
|
|
}
|
|
@@ -327,9 +323,9 @@ getRouteBirds(routeId: string | undefined): CloudObject[] {
|
|
|
await this.loadRoutes(); // 刷新列表
|
|
|
}
|
|
|
|
|
|
- async handleUploadClick() {
|
|
|
- const newRoute = new CloudObject("Route");
|
|
|
- newRoute.set({
|
|
|
+async handleUploadClick() {
|
|
|
+ const newRoute = new CloudObject("Route");
|
|
|
+ newRoute.set({
|
|
|
title: "新建路线",
|
|
|
location: "未设置位置",
|
|
|
duration: "0小时",
|
|
@@ -347,14 +343,6 @@ getRouteBirds(routeId: string | undefined): CloudObject[] {
|
|
|
} catch (error) {
|
|
|
console.error('创建路线失败', error);
|
|
|
}
|
|
|
- }
|
|
|
- async loadBirdTypes() {
|
|
|
- try {
|
|
|
- const query = new CloudQuery("BirdType");
|
|
|
- this.birdTypes = await query.find();
|
|
|
- console.log("鸟类数据加载成功", this.birdTypes);
|
|
|
- } catch (error) {
|
|
|
- console.error("加载鸟类数据失败", error);
|
|
|
- }
|
|
|
}
|
|
|
+
|
|
|
}
|