// 每一个存储的模块,命名规则use开头,store结尾 import { defineStore } from 'pinia' export const useGenerateStore = defineStore({ id: 'generate', // 必须指明唯一的pinia仓库的id state: () => { return { style: { id: -1, oldId: -1,//表示从生成页面返回回来,需要调整的样式id }, model: { id: -1, }, tryOnId:{//生成穿好衣服的回参 id: -1, isLike: false,//是否喜欢 }, isGenerate: false,//点击继续按钮后是否需要生成 /** 顾客照片信息 */ photoInfo: { id: "", url: "", file: null, }, /** AI魔改信息 */ customizeInfo: { inputText: "", tryOnId: "", tryOnUrl: "", styleUrl: "", isRegenerated: "", isFavorite: false, }, } }, getters: { /** 顾客id */ customerId: (state) => 1, /** 进店记录id */ visitRecordId: (state) => 1, /** 服装id */ styleId: (state) => 1, /** 模特照片id */ modelPhotoId: (state) => 1, /** 原始试穿id */ originalTryOnId: (state) => 1, /** 顾客照片id */ customerPhotoId: (state) => state.photoInfo.id, }, actions: { selectStyle(data: any) { this.style.id = data.id console.log(this) }, //生成后去掉id 设置oldId来修改样式 useStyleGenerate() { this.style.oldId = this.style.id this.style.id = -1 }, updateStyle(data) { console.log(data) if (data.id == this.style.oldId) { this.style.oldId = -1 } }, //模特相关 selectModel(data: any) { this.model.id = data.id console.log(this) }, setIsGenerate(isGenerate: boolean) { this.isGenerate = isGenerate }, /** 更新顾客照片信息 */ updatePhotoInfo(data: any) { this.photoInfo.id = data.visitRecordId || "" this.photoInfo.url = data.defaultImageUrl || "" this.photoInfo.file = null }, /** 清空 AI魔改信息 */ clearCustomizeInfo() { this.customizeInfo.inputText = "" this.customizeInfo.tryOnId = "" this.customizeInfo.tryOnUrl = "" this.customizeInfo.styleUrl = "" this.customizeInfo.isRegenerated = "" this.customizeInfo.isFavorite = false }, } })