generate-option.component.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. import { CommonModule } from '@angular/common';
  2. import { Component, input, OnInit } from '@angular/core';
  3. import { Router } from '@angular/router';
  4. import { IonicModule, NavController } from '@ionic/angular';
  5. import { addIcons } from 'ionicons';
  6. import { arrowBackOutline } from 'ionicons/icons';
  7. import { FormsModule } from '@angular/forms';
  8. addIcons({ 'arrow-back-outline': arrowBackOutline });
  9. @Component({
  10. selector: 'app-generate-option',
  11. templateUrl: './generate-option.component.html',
  12. styleUrls: ['./generate-option.component.scss'],
  13. standalone: true,
  14. imports: [IonicModule, CommonModule, FormsModule],
  15. })
  16. export class GenerateOptionComponent implements OnInit {
  17. userProfile: UserProfile = {
  18. gender: '不限制',
  19. age: '不限制',
  20. height: '不限制',
  21. weight: '不限制',
  22. season: '不限制',
  23. regStyle: '不限制',
  24. sceFunction: '不限制',
  25. dsgPhilosophy: '不限制',
  26. artStyle: '不限制',
  27. color: '不限制',
  28. }
  29. //构造器
  30. constructor(private router: Router, private navCtrl: NavController) { }
  31. //初始化
  32. ngOnInit() {
  33. }
  34. //返回按钮事件
  35. goBack() {
  36. this.navCtrl.back();
  37. }
  38. //性别选项卡定义变量,第一位为男,第二位为女
  39. gender: { [key: string]: boolean } = {
  40. '男': false,
  41. '女': false
  42. };
  43. //年龄选项卡定义变量
  44. age: { [key: string]: boolean } = {
  45. '20岁以下': false,
  46. '20-30岁': false,
  47. '30-40岁': false,
  48. '40岁以上': false
  49. };
  50. //身高选项卡定义变量
  51. height: { [key: string]: boolean } = {
  52. '160cm以下': false,
  53. '160-170cm': false,
  54. '170-180cm': false,
  55. '180-190cm': false,
  56. '190cm以上': false
  57. };
  58. /**
  59. * @切换选项卡
  60. * 1.将其他选项卡设置为false
  61. * 2.将当前选项卡设置为true
  62. * 3.将true对应的键赋值给userProfile中对应的属性
  63. */
  64. toggleActive(option: { [key: string]: boolean }, index: number,name: string) {
  65. for (const optkey in option) {
  66. option[optkey] = false;
  67. }
  68. const keys = Object.keys(option); // 获取 option 对象中的所有键
  69. const selectedKey = keys[index]; // 根据索引找到选中的键
  70. // 将选中的键对应的值设置为 true
  71. option[selectedKey] = true;
  72. // 更新 userProfile 中的对应字段
  73. this.userProfile[name as keyof UserProfile] = selectedKey;
  74. console.log(this.userProfile);
  75. }
  76. /**
  77. * 获取图片路径
  78. */
  79. getImageSrc(option: { [key: string]: boolean }, index: number, String: string): string {
  80. const keys = Object.keys(option); // 获取 option 对象中的所有键
  81. const selectedKey = keys[index]; // 根据索引找到选中的键
  82. const isActive = option[selectedKey];
  83. return isActive ? '/assets/generate-option-style/' + String + '-isActive-true.png' : '/assets/generate-option-style/' + String + '-isActive-false.png';
  84. }
  85. //选项卡结构配置数据
  86. cards = [
  87. {
  88. id: '体重',
  89. chips: [
  90. { id: 1, isElected: false, label: '50kg以下' },
  91. { id: 2, isElected: false, label: '50-55kg' },
  92. { id: 3, isElected: false, label: '55-60kg' },
  93. { id: 4, isElected: false, label: '60-70kg' },
  94. { id: 5, isElected: false, label: '70kg以上' },
  95. ],
  96. },
  97. {
  98. id: '季节',
  99. chips: [
  100. { id: 1, isElected: false, label: '春季' },
  101. { id: 2, isElected: false, label: '夏季' },
  102. { id: 3, isElected: false, label: '秋季' },
  103. { id: 4, isElected: false, label: '冬季' },
  104. ],
  105. },
  106. {
  107. id: '区域风格',
  108. chips: [
  109. { id: 1, isElected: false, label: '中国风' },
  110. { id: 2, isElected: false, label: '日系' },
  111. { id: 3, isElected: false, label: '韩系' },
  112. { id: 4, isElected: false, label: '欧美风' },
  113. { id: 5, isElected: false, label: '英伦风' },
  114. { id: 6, isElected: false, label: '法式' },
  115. { id: 7, isElected: false, label: '波西米亚风' },
  116. ],
  117. },
  118. {
  119. id: '场景功能',
  120. chips: [
  121. { id: 1, isElected: false, label: '通勤风' },
  122. { id: 2, isElected: false, label: '休闲风' },
  123. { id: 3, isElected: false, label: '田园风' },
  124. { id: 4, isElected: false, label: '校园风' },
  125. { id: 5, isElected: false, label: 'Party风' },
  126. { id: 6, isElected: false, label: '约会装' },
  127. { id: 7, isElected: false, label: '度假风' },
  128. ],
  129. },
  130. {
  131. id: '设计理念',
  132. chips: [
  133. { id: 1, isElected: false, label: '新中式' },
  134. { id: 2, isElected: false, label: '淑女风' },
  135. { id: 3, isElected: false, label: '名媛风' },
  136. { id: 4, isElected: false, label: '瑞丽风' },
  137. { id: 5, isElected: false, label: '简约风' },
  138. { id: 6, isElected: false, label: '极简风' },
  139. { id: 7, isElected: false, label: '中性风' },
  140. { id: 8, isElected: false, label: '性冷淡风' },
  141. { id: 9, isElected: false, label: '民族风' },
  142. { id: 10, isElected: false, label: '戏剧风' },
  143. { id: 11, isElected: false, label: '复古风' },
  144. { id: 12, isElected: false, label: 'Y2K' },
  145. { id: 13, isElected: false, label: '嘻哈风' },
  146. { id: 14, isElected: false, label: '朋克风' },
  147. { id: 15, isElected: false, label: '嬉皮风' },
  148. { id: 16, isElected: false, label: '甜酷风' },
  149. ],
  150. },
  151. {
  152. id: '艺术风格',
  153. chips: [
  154. { id: 1, isElected: false, label: '拜占庭艺术' },
  155. { id: 2, isElected: false, label: '哥特风格' },
  156. { id: 3, isElected: false, label: '浪漫主义' },
  157. { id: 4, isElected: false, label: '巴洛克风格' },
  158. { id: 5, isElected: false, label: '洛可可风格' },
  159. { id: 6, isElected: false, label: '洛丽塔风格' },
  160. { id: 7, isElected: false, label: '维多利亚风' },
  161. { id: 8, isElected: false, label: '欧普风格' },
  162. { id: 9, isElected: false, label: '未来主义' },
  163. { id: 10, isElected: false, label: '极简主义' },
  164. { id: 11, isElected: false, label: '新古典主义' },
  165. ],
  166. },
  167. {
  168. id: '色彩搭配',
  169. chips: [
  170. { id: 1, isElected: false, label: '多巴胺穿搭' },
  171. { id: 2, isElected: false, label: '美拉德穿搭' },
  172. ],
  173. },
  174. ];
  175. //补充说明
  176. styleDesc: string = '';
  177. //用户提示词
  178. userPrompt: string = '';
  179. //点击选项卡事件
  180. toggleChip(cardId: string, chipId: number): void {
  181. this.cards.forEach((card) => {
  182. if (card.id === cardId) {
  183. card.chips.forEach((chip) => {
  184. chip.isElected = chip.id === chipId; // 当前点击的 chip 设为 active,其他设为 false
  185. });
  186. switch (card.id) {
  187. case '体重':
  188. this.userProfile.weight = card.chips[chipId - 1].label;
  189. break;
  190. case '季节':
  191. this.userProfile.season = card.chips[chipId - 1].label;
  192. break;
  193. case '区域风格':
  194. this.userProfile.regStyle = card.chips[chipId - 1].label;
  195. break;
  196. case '场景功能':
  197. this.userProfile.sceFunction = card.chips[chipId - 1].label;
  198. break;
  199. case '设计理念':
  200. this.userProfile.dsgPhilosophy = card.chips[chipId - 1].label;
  201. break;
  202. case '艺术风格':
  203. this.userProfile.artStyle = card.chips[chipId - 1].label;
  204. break;
  205. case '色彩搭配':
  206. this.userProfile.color = card.chips[chipId - 1].label;
  207. break;
  208. }
  209. }
  210. })
  211. };
  212. //生成传递提示词事件
  213. sendMsg() {
  214. this.userPrompt = "请生成一个穿搭照片绘画提示词:模板如下:\n" +
  215. "穿搭主题:夏季通勤风格\n" +
  216. "性别:男性\n" +
  217. "体重:70kg\n" +
  218. "年龄:约40-45岁\n" +
  219. "整体风格:简约、舒适、专业\n" +
  220. "上装:\n" +
  221. "衬衫:选择一款轻薄透气的短袖衬衫,颜色可以是浅蓝色或淡灰色,搭配细条纹或小格纹图案,以增加层次感。衬衫的剪裁要稍微宽松,以便于活动,适合办公室环境。\n" +
  222. "外套(可选):如果需要在空调环境中,搭配一件轻便的深色西装外套,面料应为透气的棉麻混纺,能够增添正式感。\n" +
  223. "下装:\n" +
  224. "裤子:选择一条修身但不紧身的深色休闲裤(如海军蓝或深灰色),采用轻便的面料,保持通勤的舒适性。裤子长度适中,裤脚可微微收口,展现干练的形象。\n" +
  225. "鞋子:\n" +
  226. "鞋款:搭配一双经典的休闲皮鞋或轻便的商务休闲鞋,颜色可以选择黑色或深棕色,鞋面光滑,适合正式场合,同时也提供舒适的步行体验。\n" +
  227. "配饰:" +
  228. "腰带:搭配一条与鞋子颜色一致的皮质腰带,简约设计,增加整体协调感。\n" +
  229. "手表:佩戴一款简约风格的手表,金属表带或皮表带均可,展现成熟稳重的气质。\n" +
  230. "公文包:选择一款深色的公文包,材质为皮革或优质帆布,既实用又具有商务气息。\n" +
  231. "场景功能:适合在办公室、商务会议、午餐约会等场合穿着,整体搭配既显得专业又不失时尚感,适合夏季通勤的需求。\n" +
  232. "以上模板仅供参考,可以写的更详细一些,但不要过于繁琐和冗长。\n" +
  233. "以下内容为用户需求:\n" +
  234. "性别:" + this.userProfile.gender + "\n" +
  235. "年龄:" + this.userProfile.age + "\n" +
  236. "身高:" + this.userProfile.height + "\n" +
  237. "体重:" + this.userProfile.weight + "\n" +
  238. "季节:" + this.userProfile.season + "\n" +
  239. "区域风格:" + this.userProfile.regStyle + "\n" +
  240. "场景功能:" + this.userProfile.sceFunction + "\n" +
  241. "设计理念:" + this.userProfile.dsgPhilosophy + "\n" +
  242. "艺术风格:" + this.userProfile.artStyle + "\n" +
  243. "色彩搭配:" + this.userProfile.color + "\n" +
  244. "补充说明:" + this.styleDesc + "\n";
  245. console.log(this.userPrompt)
  246. }
  247. goChatPanel() {
  248. this.router.navigate(['/chatPanel'], {
  249. queryParams: { userPrompt: this.userPrompt }
  250. });
  251. }
  252. onHelperTextClick() {
  253. // 处理点击事件的逻辑,比如打开一个对话框或执行其他操作
  254. alert('你点击了帮助文本!');
  255. }
  256. sendMsgAndGoGenerateResult() {
  257. this.sendMsg();
  258. //this.goChatPanel();
  259. }
  260. }
  261. type UserProfile = {
  262. gender: string;
  263. age: string;
  264. height: string;
  265. weight: string;
  266. season: string;
  267. regStyle: string;
  268. sceFunction: string;
  269. dsgPhilosophy: string;
  270. artStyle: string;
  271. color: string;
  272. };