neighborhood.page.ts 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. import { Component, OnInit } from '@angular/core';
  2. import { CloudObject, CloudQuery } from 'src/lib/ncloud';
  3. @Component({
  4. selector: 'app-neighborhood',
  5. templateUrl: './neighborhood.page.html',
  6. styleUrls: ['./neighborhood.page.scss'],
  7. standalone:false
  8. })
  9. export class NeighborhoodPage implements OnInit {
  10. constructor() {
  11. this.loadBirdType()
  12. }
  13. birdList:CloudObject[]=[]
  14. async loadBirdType(){
  15. let query=new CloudQuery("BirdType")
  16. this.birdList=await query.find();
  17. }
  18. // 在组件中添加方法
  19. getStars(rating: number): string[] {
  20. const fullStars = Math.floor(rating);
  21. const halfStar = rating % 1 >= 0.5 ? 1 : 0;
  22. const emptyStars = 5 - fullStars - halfStar;
  23. return [
  24. ...Array(fullStars).fill('★'),
  25. ...(halfStar ? ['★'] : []),
  26. ...Array(emptyStars).fill('☆')
  27. ];
  28. }
  29. ngOnInit() {
  30. this.birdList = [];
  31. }
  32. async importBrid(){
  33. const birdDataset = [
  34. {
  35. name: "红嘴相思鸟",
  36. scientificName: "Leiothrix lutea",
  37. rating: 4.5,
  38. distance: 1.2,
  39. image: "assets/avatars/hongzui.jpeg",
  40. description: "红嘴相思鸟以其鲜艳的红色嘴喙和婉转的鸣叫声而闻名,是深受观鸟爱好者喜爱的鸟类。",
  41. conservationStatus: "国家二级保护动物",
  42. tags: ["鸣禽", "色彩鲜艳", "群居"],
  43. taxonomy: {
  44. order: "雀形目",
  45. family: "鹟科",
  46. genus: "相思鸟属"
  47. },
  48. characteristics: {
  49. size: "体长约15厘米",
  50. color: "橄榄绿色背部,橙黄色胸腹部,红色嘴喙",
  51. habitat: "常绿阔叶林、竹林和灌木丛"
  52. },
  53. observation: {
  54. season: "全年",
  55. time: "清晨和黄昏"
  56. }
  57. },
  58. {
  59. name: "白鹭",
  60. scientificName: "Egretta garzetta",
  61. rating: 3.8,
  62. distance: 0.8,
  63. image: "assets/avatars/bailu.jpeg",
  64. description: "白鹭是一种优雅的水鸟,常在湿地和浅水区觅食,飞行时颈部呈'S'形弯曲。",
  65. conservationStatus: "",
  66. tags: ["水鸟", "白色羽毛", "湿地"],
  67. taxonomy: {
  68. order: "鹈形目",
  69. family: "鹭科",
  70. genus: "白鹭属"
  71. },
  72. characteristics: {
  73. size: "体长约55-65厘米",
  74. color: "全身白色,喙和腿黑色,趾黄色",
  75. habitat: "湿地、河流、湖泊"
  76. },
  77. observation: {
  78. season: "春秋季",
  79. time: "早晨"
  80. }
  81. },
  82. {
  83. name: "红腹锦鸡",
  84. scientificName: "Chrysolophus pictus",
  85. rating: 5.0,
  86. distance: 3.5,
  87. image: "assets/avatars/hongfujinji.jpeg",
  88. description: "红腹锦鸡是中国特有鸟类,雄鸟羽毛色彩艳丽,是国家二级保护动物。",
  89. conservationStatus: "国家二级保护动物",
  90. tags: ["中国特有", "色彩艳丽", "珍稀"],
  91. taxonomy: {
  92. order: "鸡形目",
  93. family: "雉科",
  94. genus: "锦鸡属"
  95. },
  96. characteristics: {
  97. size: "体长约100厘米",
  98. color: "金色冠羽,红色胸腹部,多彩的背部羽毛",
  99. habitat: "山地森林、灌木丛"
  100. },
  101. observation: {
  102. season: "春季",
  103. time: "日出后"
  104. }
  105. },
  106. {
  107. name: "黑脸琵鹭",
  108. scientificName: "Platalea minor",
  109. rating: 4.7,
  110. distance: 2.1,
  111. image: "assets/avatars/heilianpilu.jpeg",
  112. description: "黑脸琵鹭是濒危鸟类,以其独特的匙状嘴喙和黑色面部而闻名。",
  113. conservationStatus: "国家一级保护动物",
  114. tags: ["濒危", "湿地", "迁徙"],
  115. taxonomy: {
  116. order: "鹈形目",
  117. family: "鹮科",
  118. genus: "琵鹭属"
  119. },
  120. characteristics: {
  121. size: "体长约60-78厘米",
  122. color: "白色羽毛,黑色面部和嘴喙",
  123. habitat: "沿海湿地、河口"
  124. },
  125. observation: {
  126. season: "冬季",
  127. time: "白天"
  128. }
  129. },
  130. {
  131. name: "画眉",
  132. scientificName: "Garrulax canorus",
  133. rating: 4.2,
  134. distance: 0.5,
  135. image: "assets/avatars/huamei.jpeg",
  136. description: "画眉以其优美的鸣叫声而闻名,是中国传统的笼养鸟之一。",
  137. conservationStatus: "",
  138. tags: ["鸣禽", "笼养鸟", "常见"],
  139. taxonomy: {
  140. order: "雀形目",
  141. family: "鹟科",
  142. genus: "噪鹛属"
  143. },
  144. characteristics: {
  145. size: "体长约21-25厘米",
  146. color: "棕褐色,眼周有白色眉纹",
  147. habitat: "灌木丛、竹林、公园"
  148. },
  149. observation: {
  150. season: "全年",
  151. time: "全天"
  152. }
  153. }
  154. ];
  155. const BirdType=new CloudObject("BirdType");
  156. const query=new CloudQuery("Birdtype");
  157. for(const bird of birdDataset){
  158. try{
  159. // 每次循环都创建新的查询对象
  160. const query = new CloudQuery("BirdType");
  161. //检查是否已存在同名鸟类
  162. query.equalTo("name",bird.name);
  163. const existing=await query.first();
  164. if(existing){
  165. console.log(`鸟类${bird.name}"已存在,保存跳过`);
  166. continue;
  167. }
  168. //创建新鸟类对象
  169. const newBird=new CloudObject("BirdType");
  170. newBird.set(bird);
  171. //保存到数据库
  172. await newBird.save();
  173. console.log(`鸟类${bird.name}保存成功`);
  174. }catch(error){
  175. console.error(`保存鸟类${bird.name}时出错`,error);
  176. }
  177. }
  178. console.log("所有鸟类数据处理完成");
  179. }
  180. }