|
@@ -10,9 +10,9 @@ import { TaskGenerateUserValiate } from 'src/agent/tasks/generate/generate-user-
|
|
|
import { TaskExecutor } from 'src/agent/agent.start';
|
|
|
import { TaskGeneratePrompt } from 'src/agent/tasks/generate/generate-prompt';
|
|
|
import { TaskGeneratePicture } from 'src/agent/tasks/generate/generate-picture';
|
|
|
-import { CloudQuery, CloudUser } from 'src/lib/ncloud';
|
|
|
+import { CloudObject, CloudQuery, CloudUser } from 'src/lib/ncloud';
|
|
|
import { CustomHeaderComponent } from 'src/lib/component/custom-header/custom-header.component';
|
|
|
-import { IonButton, IonCard, IonContent, IonIcon, IonImg, IonText, IonTextarea } from '@ionic/angular/standalone';
|
|
|
+import { AlertController, AlertInput, IonAlert, IonButton, IonCard, IonContent, IonIcon, IonImg, IonText, IonTextarea } from '@ionic/angular/standalone';
|
|
|
addIcons({ 'arrow-back-outline': arrowBackOutline, radioButtonOffOutline, closeCircleOutline, checkmarkCircleOutline, reloadOutline });
|
|
|
@Component({
|
|
|
selector: 'app-generate-option',
|
|
@@ -20,7 +20,7 @@ addIcons({ 'arrow-back-outline': arrowBackOutline, radioButtonOffOutline, closeC
|
|
|
styleUrls: ['./generate-option.component.scss'],
|
|
|
standalone: true,
|
|
|
imports: [CustomHeaderComponent, CommonModule, FormsModule, IonButton, IonCard, IonIcon,
|
|
|
- IonImg, IonText, IonTextarea, IonContent
|
|
|
+ IonImg, IonText, IonTextarea, IonContent, IonAlert
|
|
|
],
|
|
|
providers: [ModalController],
|
|
|
})
|
|
@@ -29,9 +29,14 @@ export class GenerateOptionComponent implements OnInit {
|
|
|
* @构造和初始化
|
|
|
*/
|
|
|
//构造器
|
|
|
- constructor(private modalCtrl: ModalController, private router: Router, private navCtrl: NavController) { }
|
|
|
+ constructor(private alertController: AlertController, private modalCtrl: ModalController, private router: Router, private navCtrl: NavController) { }
|
|
|
//初始化
|
|
|
- ngOnInit() { }
|
|
|
+ isCreateMode: boolean = false;
|
|
|
+ isEditMode: boolean = false;
|
|
|
+ ngOnInit() {
|
|
|
+ //接受来自创建风格的路由参数
|
|
|
+ this.handleStyleList();
|
|
|
+ }
|
|
|
/**
|
|
|
* @返回按钮事件
|
|
|
*/
|
|
@@ -162,11 +167,6 @@ export class GenerateOptionComponent implements OnInit {
|
|
|
'维多利亚风': false,
|
|
|
'未来主义': false,
|
|
|
}
|
|
|
- //颜色选项卡定义变量
|
|
|
- color: { [key: string]: boolean } = {
|
|
|
- '多巴胺穿搭': false,
|
|
|
- '美拉德穿搭': false
|
|
|
- };
|
|
|
|
|
|
/**
|
|
|
* @根据索引找到键值
|
|
@@ -175,6 +175,13 @@ export class GenerateOptionComponent implements OnInit {
|
|
|
const keys = Object.keys(option); // 获取 option 对象中的所有键
|
|
|
return keys[index]; // 根据索引找到选中的键
|
|
|
}
|
|
|
+ /**
|
|
|
+ * @根据键值找到索引
|
|
|
+ */
|
|
|
+ getIndexByKey(option: { [key: string]: boolean }, key: string): number {
|
|
|
+ const keys = Object.keys(option); // 获取 option 对象中的所有键
|
|
|
+ return keys.indexOf(key); // 根据键找到索引
|
|
|
+ }
|
|
|
/**
|
|
|
* @返回字典中true值对应的key
|
|
|
*/
|
|
@@ -201,7 +208,10 @@ export class GenerateOptionComponent implements OnInit {
|
|
|
// 将选中的键对应的值设置为 true
|
|
|
option[selectedKey] = true;
|
|
|
// 更新 userProfile 中的对应字段
|
|
|
- this.userProfile[name as keyof UserProfile] = selectedKey + ":" + this.description[selectedKey];
|
|
|
+ if (['gender', 'age', 'height', 'weight', 'season'].includes(name))
|
|
|
+ this.userProfile[name as keyof UserProfile] = selectedKey;
|
|
|
+ else
|
|
|
+ this.userProfile[name as keyof UserProfile] = selectedKey + ":" + this.description[selectedKey];
|
|
|
} else {
|
|
|
option[selectedKey] = false;
|
|
|
this.userProfile[name as keyof UserProfile] = '不限制';
|
|
@@ -348,6 +358,102 @@ export class GenerateOptionComponent implements OnInit {
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
+ /**
|
|
|
+ * @保存风格信息
|
|
|
+ */
|
|
|
+ //打开保存风格信息的弹窗
|
|
|
+ async saveStyle() {
|
|
|
+ //判断五个字段是否为"不限制"
|
|
|
+ if (this.userProfile.gender === "不限制" || this.userProfile.age === "不限制" || this.userProfile.height === "不限制" || this.userProfile.weight === "不限制" || this.userProfile.season === "不限制") {
|
|
|
+ console.log("信息未完善,不保存风格信息");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const alert = await this.alertController.create({
|
|
|
+ header: '请完善风格信息',
|
|
|
+ inputs: this.alertInputs,
|
|
|
+ buttons: [
|
|
|
+ {
|
|
|
+ text: '取消',
|
|
|
+ role: 'cancel',
|
|
|
+ cssClass: 'secondary',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ text: '确认',
|
|
|
+ handler: (data) => {
|
|
|
+ console.log('输入的数据:', data); // 处理用户输入
|
|
|
+ this.handleAlertInput(data); // 调用处理函数
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ });
|
|
|
+ await alert.present();
|
|
|
+ }
|
|
|
+ //完善风格信息
|
|
|
+ public alertInputs: AlertInput[] = [
|
|
|
+ {
|
|
|
+ name: 'styleName',
|
|
|
+ placeholder: '风格名称',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: 'styleDesc',
|
|
|
+ type: 'textarea',
|
|
|
+ placeholder: '自定义描述',
|
|
|
+ },
|
|
|
+ ];
|
|
|
+ //处理风格信息
|
|
|
+ handleAlertInput(data: any) {
|
|
|
+ let object = new CloudObject("UserStyleInfo");
|
|
|
+ const user = new CloudUser().toPointer();
|
|
|
+ let content = JSON.stringify(this.userProfile);
|
|
|
+ object.set({
|
|
|
+ "UserID": user,
|
|
|
+ "name": data.styleName,
|
|
|
+ "desc": data.styleDesc,
|
|
|
+ "content": content,
|
|
|
+ });
|
|
|
+ if(this.isEditMode){
|
|
|
+ object.id = this.editId;
|
|
|
+ }
|
|
|
+ object.save();
|
|
|
+ this.goBack();
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * @风格列表跳转处理
|
|
|
+ */
|
|
|
+ editId: string|any = "";
|
|
|
+ handleStyleList() {
|
|
|
+ const navigation = this.router.getCurrentNavigation();
|
|
|
+ if (navigation?.extras.state) {
|
|
|
+ this.isCreateMode = navigation.extras.state?.['fromMyStyleListPage'] || false;
|
|
|
+ console.log('创建模式开启:', this.isCreateMode);
|
|
|
+ this.isEditMode = navigation.extras.state?.['fromMyStyleInfoPage'] || false;
|
|
|
+ console.log('编辑模式开启:', this.isEditMode);
|
|
|
+ if (this.isEditMode) {
|
|
|
+ const style: CloudObject = navigation.extras.state?.['style'];
|
|
|
+ const json = JSON.parse(style?.get('content'));
|
|
|
+ this.userProfile = json;
|
|
|
+ console.log('已获取userStyle信息,存储至userProfile', this.userProfile);
|
|
|
+ this.editId = style?.id;
|
|
|
+ //根据json数据模拟用户填充表单
|
|
|
+ this.gender[json.gender]=true;
|
|
|
+ this.age[json.age]=true;
|
|
|
+ this.height[json.height]=true;
|
|
|
+ this.weight[json.weight]=true;
|
|
|
+ this.season[json.season]=true;
|
|
|
+ //json对应字段取“:”前面的所有字符
|
|
|
+ json.areaStyle=json.areaStyle?.split(":")[0];
|
|
|
+ json.function=json.function?.split(":")[0];
|
|
|
+ json.artStyle=json.artStyle?.split(":")[0];
|
|
|
+ json.designIdea=json.designIdea?.split(":")[0];
|
|
|
+ this.areaStyle[json.areaStyle]=true;
|
|
|
+ this.function[json.function]=true;
|
|
|
+ this.artStyle[json.artStyle]=true;
|
|
|
+ this.designIdea[json.designIdea]=true;
|
|
|
+ this.alertInputs[0].value = style?.get('name');
|
|
|
+ this.alertInputs[1].value = style?.get('desc');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
/**
|
|
|
* @用户信息结构
|