|
@@ -0,0 +1,254 @@
|
|
|
+import { Component, OnInit } from '@angular/core';
|
|
|
+import { HttpClient } from '@angular/common/http';
|
|
|
+import { IonButton, IonCard, IonCardContent, IonCardHeader, IonContent, IonProgressBar, LoadingController } from '@ionic/angular/standalone';
|
|
|
+import { DalleOptions, FmodeChatCompletion, ImagineWork } from 'fmode-ng';
|
|
|
+import { CommonModule } from '@angular/common';
|
|
|
+import { FormsModule } from '@angular/forms';
|
|
|
+import { NavigationExtras, Router } from '@angular/router';
|
|
|
+
|
|
|
+import { IonCardSubtitle, IonTextarea, ModalController } from '@ionic/angular/standalone';
|
|
|
+import { IonHeader, IonTitle, IonToolbar, IonLabel, IonItem, IonList, IonBackButton, IonButtons, IonIcon, IonItemDivider, IonAvatar, IonThumbnail, IonItemOptions, IonItemOption, IonItemSliding, IonInput, IonCheckbox, IonRadio, IonToggle, IonRadioGroup, IonSearchbar, IonSegment, IonSegmentButton, IonDatetime, IonFooter, IonCardTitle, IonCol, IonRow, IonGrid, IonChip, IonImg } from '@ionic/angular/standalone';
|
|
|
+import { EditTagComponent } from '../edit-tag/edit-tag.component';
|
|
|
+import { MarkdownPreviewModule } from 'fmode-ng';
|
|
|
+import { ChatPanelOptions, FmChatModalInput, FmodeChat, FmodeChatMessage, openChatPanelModal } from 'fmode-ng';
|
|
|
+import { Icon } from 'ionicons/dist/types/components/icon/icon';
|
|
|
+import { camera, trendingUpOutline, sparklesOutline, cloudyOutline, diceOutline } from 'ionicons/icons';
|
|
|
+import { addIcons } from 'ionicons';
|
|
|
+import { CloudObject, CloudQuery, CloudUser } from 'src/lib/ncloud';
|
|
|
+import { SwiperComponent } from '../swiper/swiper.component';
|
|
|
+import { extactAndParseJsonFromString } from 'src/agent/agent.json';
|
|
|
+import { RouterModule } from '@angular/router';
|
|
|
+import { NavController } from '@ionic/angular';
|
|
|
+import { AlertController } from '@ionic/angular';
|
|
|
+import { openUserLoginModal } from 'src/lib/user/modal-user-login/modal-user-login.component';
|
|
|
+import { openCommentPostModal } from 'src/lib/user/modal-comment-post/modal-comment-post.component';
|
|
|
+@Component({
|
|
|
+ selector: 'app-tianqi',
|
|
|
+ templateUrl: './tianqi.component.html',
|
|
|
+ styleUrls: ['./tianqi.component.scss'],
|
|
|
+ standalone: true,
|
|
|
+ imports:[IonButton,IonContent,IonCard,IonCardContent,IonCardHeader,IonProgressBar,IonProgressBar,IonContent, IonHeader, IonTitle, IonToolbar, CommonModule, FormsModule, IonButton, IonInput, EditTagComponent, IonTextarea, IonItem, IonList, MarkdownPreviewModule, IonIcon, IonContent, IonHeader, IonTitle, IonToolbar, CommonModule, FormsModule, IonButton, IonLabel, IonLabel, IonList, IonItem, IonBackButton, IonButtons, IonIcon, IonItemDivider, IonAvatar, IonThumbnail, IonItemOptions, IonItemSliding, IonItemOption, IonItemOptions, IonInput, IonCheckbox, IonRadio, IonToggle, IonRadioGroup, IonSearchbar, IonSegment, IonSegmentButton, IonDatetime, IonFooter, IonCardContent, IonCardTitle, IonCardHeader, IonCard, IonCol, IonRow, IonGrid, IonChip, IonImg, IonCardSubtitle, SwiperComponent, RouterModule,]
|
|
|
+})
|
|
|
+export class TianqiComponent implements OnInit {
|
|
|
+ time: string="";
|
|
|
+ yulu: string="";
|
|
|
+ livesAll={
|
|
|
+ "status": "1",
|
|
|
+ "count": "1",
|
|
|
+ "info": "OK",
|
|
|
+ "infocode": "10000",
|
|
|
+ "forecasts": [
|
|
|
+ {
|
|
|
+ "city": "南昌市",
|
|
|
+ "adcode": "360100",
|
|
|
+ "province": "江西",
|
|
|
+ "reporttime": "2024-12-19 16:02:45",
|
|
|
+ "casts": [
|
|
|
+ {
|
|
|
+ "date": "2024-12-19",
|
|
|
+ "week": "4",
|
|
|
+ "dayweather": "晴",
|
|
|
+ "nightweather": "晴",
|
|
|
+ "daytemp": "9",
|
|
|
+ "nighttemp": "-2",
|
|
|
+ "daywind": "东北",
|
|
|
+ "nightwind": "东北",
|
|
|
+ "daypower": "1-3",
|
|
|
+ "nightpower": "1-3",
|
|
|
+ "daytemp_float": "9.0",
|
|
|
+ "nighttemp_float": "-2.0"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "date": "2024-12-20",
|
|
|
+ "week": "5",
|
|
|
+ "dayweather": "晴",
|
|
|
+ "nightweather": "晴",
|
|
|
+ "daytemp": "12",
|
|
|
+ "nighttemp": "0",
|
|
|
+ "daywind": "东北",
|
|
|
+ "nightwind": "东北",
|
|
|
+ "daypower": "1-3",
|
|
|
+ "nightpower": "1-3",
|
|
|
+ "daytemp_float": "12.0",
|
|
|
+ "nighttemp_float": "0.0"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "date": "2024-12-21",
|
|
|
+ "week": "6",
|
|
|
+ "dayweather": "多云",
|
|
|
+ "nightweather": "多云",
|
|
|
+ "daytemp": "12",
|
|
|
+ "nighttemp": "1",
|
|
|
+ "daywind": "东北",
|
|
|
+ "nightwind": "东北",
|
|
|
+ "daypower": "1-3",
|
|
|
+ "nightpower": "1-3",
|
|
|
+ "daytemp_float": "12.0",
|
|
|
+ "nighttemp_float": "1.0"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "date": "2024-12-22",
|
|
|
+ "week": "7",
|
|
|
+ "dayweather": "多云",
|
|
|
+ "nightweather": "阴",
|
|
|
+ "daytemp": "9",
|
|
|
+ "nighttemp": "2",
|
|
|
+ "daywind": "东",
|
|
|
+ "nightwind": "东",
|
|
|
+ "daypower": "1-3",
|
|
|
+ "nightpower": "1-3",
|
|
|
+ "daytemp_float": "9.0",
|
|
|
+ "nighttemp_float": "2.0"
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ ]
|
|
|
+};
|
|
|
+ juti: string="";
|
|
|
+ loading: HTMLIonLoadingElement | null = null;
|
|
|
+
|
|
|
+ constructor(private http: HttpClient,private loadingController: LoadingController,) {}
|
|
|
+
|
|
|
+ getAdcodeAndWeather() {
|
|
|
+ // 第一个请求,获取 adcode
|
|
|
+ this.http.get('https://restapi.amap.com/v3/ip?output=json&key=555ac0f9311d59145cdec7db32e27528')
|
|
|
+ .subscribe((response: any) => {
|
|
|
+ const adcode = response.adcode; // 获取 adcode 字段
|
|
|
+ if (adcode) {
|
|
|
+ this.getWeather(adcode); // 使用 adcode 获取天气信息
|
|
|
+ } else {
|
|
|
+ console.error('adcode not found in response:', response);
|
|
|
+ }
|
|
|
+ }, error => {
|
|
|
+ console.error('Error fetching adcode:', error);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ getWeather(adcode: string) {
|
|
|
+ // 第二个请求,获取天气信息
|
|
|
+ const weatherUrl = `https://restapi.amap.com/v3/weather/weatherInfo?city=${adcode}&key=555ac0f9311d59145cdec7db32e27528`;
|
|
|
+ this.http.get(weatherUrl)
|
|
|
+ .subscribe((response: any) => {
|
|
|
+ this.lives = response.lives; // 获取 lives 数组
|
|
|
+ console.log('Weather lives data:', this.lives);
|
|
|
+ this.getAll(adcode)
|
|
|
+ }, error => {
|
|
|
+ console.error('Error fetching weather data:', error);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ getAll(adcode: string){
|
|
|
+ const urlWeatherAll = "https://restapi.amap.com/v3/weather/weatherInfo?city=" +adcode + "&extensions=all&key=555ac0f9311d59145cdec7db32e27528";
|
|
|
+ this.http.get(urlWeatherAll)
|
|
|
+ .subscribe((response: any) => {
|
|
|
+ this.livesAll = response; // 获取 lives 数组
|
|
|
+ console.log('Weather livesAll data:', this.livesAll);
|
|
|
+
|
|
|
+ }, error => {
|
|
|
+ console.error('Error fetching weather data:', error);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ lives=[
|
|
|
+ {
|
|
|
+ "province": "江西",
|
|
|
+ "city": "南昌市",
|
|
|
+ "adcode": "360100",
|
|
|
+ "weather": "晴",
|
|
|
+ "temperature": "8",
|
|
|
+ "winddirection": "东北",
|
|
|
+ "windpower": "≤3",
|
|
|
+ "humidity": "39",
|
|
|
+ "reporttime": "2024-12-19 15:37:35",
|
|
|
+ "temperature_float": "8.0",
|
|
|
+ "humidity_float": "39.0"
|
|
|
+ }
|
|
|
+]
|
|
|
+ ngOnInit() {
|
|
|
+ // this.getAdcodeAndWeather()
|
|
|
+ const dateMap = ["周天","周一","周二","周三","周四","周五","周六"];
|
|
|
+ const weekdayMap = ["零","一","两","三","四","五"];
|
|
|
+ const urlIp = "https://restapi.amap.com/v3/ip?output=json&key=你的Key";
|
|
|
+ const date = new Date();
|
|
|
+ this.time=date.getMonth() + 1 + "-" + date.getDate() + " " + dateMap[date.getDay()]
|
|
|
+ if(date.getDay() == 6 || date.getDay() == 0){
|
|
|
+ this.yulu="好好享受周末吧~"
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ this.yulu="再坚持" + weekdayMap[(6 - date.getDay())] + "天就到周末啦~"
|
|
|
+ }
|
|
|
+ const weather_log = this.lives[0]["weather"];
|
|
|
+ const daytemp = this.livesAll["forecasts"][0]["casts"][0]["daytemp"];
|
|
|
+ const nighttemp = this.livesAll["forecasts"][0]["casts"][0]["nighttemp"];
|
|
|
+ this.juti=nighttemp + "° " + "/ " + daytemp + "°" + "\xa0\xa0\xa0" + weather_log
|
|
|
+ console.log(this.juti);
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ public gptre:string = "";
|
|
|
+ public progress = 0;
|
|
|
+ public Complete=false
|
|
|
+ async aa(){
|
|
|
+ this.loading = await this.loadingController.create({
|
|
|
+ message: '生成计划中...',
|
|
|
+ // duration: 30000 // 加载时长可以根据实际需求调整
|
|
|
+ });
|
|
|
+
|
|
|
+ await this.loading.present();
|
|
|
+
|
|
|
+ let prompt = `
|
|
|
+ 现在的温度是${this.lives[0].temperature+ "°"},
|
|
|
+ 今天的温度范围和天气是${this.juti},请你作为一名专业服装设计师,
|
|
|
+ 向我推荐适合今日的衣服和裤子,并联想补充衣服和裤子的具体细节
|
|
|
+ `;
|
|
|
+
|
|
|
+ let completion = new FmodeChatCompletion([
|
|
|
+ { role: "system", content: "" },
|
|
|
+ { role: "user", content: prompt }
|
|
|
+ ]);
|
|
|
+ completion.sendCompletion().subscribe(
|
|
|
+ (message: any) => {
|
|
|
+ this.gptre=message.content
|
|
|
+ console.log("Received message:", message);
|
|
|
+ if(this.progress<0.97){
|
|
|
+ if(this.progress<0.5){
|
|
|
+ this.progress+=0.002
|
|
|
+ }
|
|
|
+ if(this.progress>=0.8){
|
|
|
+ this.progress+=0.001
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (message?.complete) {
|
|
|
+ this.Complete=true
|
|
|
+
|
|
|
+ console.log("完成");
|
|
|
+ this.createImage()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ )
|
|
|
+ }
|
|
|
+imagineWork: ImagineWork | undefined
|
|
|
+ images: Array<string> = []
|
|
|
+ createImage(){
|
|
|
+ this.imagineWork = new ImagineWork();
|
|
|
+ let options: DalleOptions = { prompt: this.gptre }
|
|
|
+ this.imagineWork.draw(options).subscribe(async work => {
|
|
|
+ if(this.progress<0.5){
|
|
|
+ this.progress+=0.01
|
|
|
+ }
|
|
|
+ if(this.progress>=0.8){
|
|
|
+ this.progress+=0.001
|
|
|
+ }
|
|
|
+ console.log("imagineWork", work?.toJSON())
|
|
|
+ console.log("images", work?.get("images"))
|
|
|
+ if (work?.get("images")?.length) {
|
|
|
+ if (this.loading) {
|
|
|
+ await this.loading.dismiss();
|
|
|
+ this.loading = null; // 清空 loading 实例
|
|
|
+ }
|
|
|
+ this.progress=0
|
|
|
+
|
|
|
+ this.images = work?.get("images");
|
|
|
+ this.progress=0}
|
|
|
+ })}
|
|
|
+
|
|
|
+
|
|
|
+}
|