123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- import { Component, OnInit } from '@angular/core';
- import { CloudObject, CloudQuery } from 'src/lib/ncloud';
- @Component({
- selector: 'app-neighborhood',
- templateUrl: './neighborhood.page.html',
- styleUrls: ['./neighborhood.page.scss'],
- standalone:false
- })
- export class NeighborhoodPage implements OnInit {
-
- constructor() {
- this.loadBirdType()
- }
- birdList:CloudObject[]=[]
- async loadBirdType(){
- let query=new CloudQuery("BirdType")
- this.birdList=await query.find();
- }
- // 在组件中添加方法
- getStars(rating: number): string[] {
- const fullStars = Math.floor(rating);
- const halfStar = rating % 1 >= 0.5 ? 1 : 0;
- const emptyStars = 5 - fullStars - halfStar;
- return [
- ...Array(fullStars).fill('★'),
- ...(halfStar ? ['★'] : []),
- ...Array(emptyStars).fill('☆')
- ];
- }
- ngOnInit() {
- this.birdList = [];
- }
- async importBrid(){
- const birdDataset = [
- {
- name: "红嘴相思鸟",
- scientificName: "Leiothrix lutea",
- rating: 4.5,
- distance: 1.2,
- image: "assets/avatars/hongzui.jpeg",
- description: "红嘴相思鸟以其鲜艳的红色嘴喙和婉转的鸣叫声而闻名,是深受观鸟爱好者喜爱的鸟类。",
- conservationStatus: "国家二级保护动物",
- tags: ["鸣禽", "色彩鲜艳", "群居"],
- taxonomy: {
- order: "雀形目",
- family: "鹟科",
- genus: "相思鸟属"
- },
- characteristics: {
- size: "体长约15厘米",
- color: "橄榄绿色背部,橙黄色胸腹部,红色嘴喙",
- habitat: "常绿阔叶林、竹林和灌木丛"
- },
- observation: {
- season: "全年",
- time: "清晨和黄昏"
- }
- },
- {
- name: "白鹭",
- scientificName: "Egretta garzetta",
- rating: 3.8,
- distance: 0.8,
- image: "assets/avatars/bailu.jpeg",
- description: "白鹭是一种优雅的水鸟,常在湿地和浅水区觅食,飞行时颈部呈'S'形弯曲。",
- conservationStatus: "",
- tags: ["水鸟", "白色羽毛", "湿地"],
- taxonomy: {
- order: "鹈形目",
- family: "鹭科",
- genus: "白鹭属"
- },
- characteristics: {
- size: "体长约55-65厘米",
- color: "全身白色,喙和腿黑色,趾黄色",
- habitat: "湿地、河流、湖泊"
- },
- observation: {
- season: "春秋季",
- time: "早晨"
- }
- },
- {
- name: "红腹锦鸡",
- scientificName: "Chrysolophus pictus",
- rating: 5.0,
- distance: 3.5,
- image: "assets/avatars/hongfujinji.jpeg",
- description: "红腹锦鸡是中国特有鸟类,雄鸟羽毛色彩艳丽,是国家二级保护动物。",
- conservationStatus: "国家二级保护动物",
- tags: ["中国特有", "色彩艳丽", "珍稀"],
- taxonomy: {
- order: "鸡形目",
- family: "雉科",
- genus: "锦鸡属"
- },
- characteristics: {
- size: "体长约100厘米",
- color: "金色冠羽,红色胸腹部,多彩的背部羽毛",
- habitat: "山地森林、灌木丛"
- },
- observation: {
- season: "春季",
- time: "日出后"
- }
- },
- {
- name: "黑脸琵鹭",
- scientificName: "Platalea minor",
- rating: 4.7,
- distance: 2.1,
- image: "assets/avatars/heilianpilu.jpeg",
- description: "黑脸琵鹭是濒危鸟类,以其独特的匙状嘴喙和黑色面部而闻名。",
- conservationStatus: "国家一级保护动物",
- tags: ["濒危", "湿地", "迁徙"],
- taxonomy: {
- order: "鹈形目",
- family: "鹮科",
- genus: "琵鹭属"
- },
- characteristics: {
- size: "体长约60-78厘米",
- color: "白色羽毛,黑色面部和嘴喙",
- habitat: "沿海湿地、河口"
- },
- observation: {
- season: "冬季",
- time: "白天"
- }
- },
- {
- name: "画眉",
- scientificName: "Garrulax canorus",
- rating: 4.2,
- distance: 0.5,
- image: "assets/avatars/huamei.jpeg",
- description: "画眉以其优美的鸣叫声而闻名,是中国传统的笼养鸟之一。",
- conservationStatus: "",
- tags: ["鸣禽", "笼养鸟", "常见"],
- taxonomy: {
- order: "雀形目",
- family: "鹟科",
- genus: "噪鹛属"
- },
- characteristics: {
- size: "体长约21-25厘米",
- color: "棕褐色,眼周有白色眉纹",
- habitat: "灌木丛、竹林、公园"
- },
- observation: {
- season: "全年",
- time: "全天"
- }
- }
- ];
- const BirdType=new CloudObject("BirdType");
- const query=new CloudQuery("Birdtype");
-
- for(const bird of birdDataset){
- try{
- // 每次循环都创建新的查询对象
- const query = new CloudQuery("BirdType");
- //检查是否已存在同名鸟类
- query.equalTo("name",bird.name);
- const existing=await query.first();
- if(existing){
- console.log(`鸟类${bird.name}"已存在,保存跳过`);
- continue;
- }
- //创建新鸟类对象
- const newBird=new CloudObject("BirdType");
- newBird.set(bird);
- //保存到数据库
- await newBird.save();
- console.log(`鸟类${bird.name}保存成功`);
- }catch(error){
- console.error(`保存鸟类${bird.name}时出错`,error);
- }
- }
- console.log("所有鸟类数据处理完成");
- }
- }
|