Files
meida/puton-master/src/stores/globalStore.ts
T
2026-08-19 21:48:12 +08:00

334 lines
8.3 KiB
TypeScript

import { type UploadUserFile } from 'element-plus'
import { defineStore } from 'pinia'
import { ref } from 'vue'
import type { IClotheInfo, IModelInfo, INavStatus, IClothType, IRoomInfo } from '@/interface'
import jfLogoImg from '@/assets/imgs/jf_logo.png'
import juyunImg from '@/assets/imgs/juyun.png'
import logoImg from '@/assets/imgs/logo.png'
import { MenuEnum } from '@/enum/MenuEnum'
export const useGlobalStore = defineStore('global', () => {
const gender = ref<'male' | 'female'>('female')
const noticeVideo = ref<string>(
'https://digit-person.oss-cn-beijing.aliyuncs.com/digital_cloth/1720444463478.mp4'
)
const creatingImgMark = ref('1720084773937.png')
const createFailMark = ref('1720084729963.png')
const creatingAndFailMarkList = ref<string[]>([creatingImgMark.value, createFailMark.value])
const menu = reactive<INavStatus>({
mainNav: MenuEnum.MY_WARDROBE,
subNav: MenuEnum.ALL
})
type INav = {
isPerson: 'yes' | 'no'
clothType?: IClothType
}
const nav = computed<INav>(() => {
const isPersonMaps = {
[MenuEnum.CLOTHES_LIBRARY]: 'no',
[MenuEnum.MY_WARDROBE]: 'yes'
}
const clothTypeMaps = {
[MenuEnum.ALL]: null,
[MenuEnum.UPPER_OUTER_GARMENT]: 'topCloth',
[MenuEnum.BOTTOMS]: 'bottomCloth',
[MenuEnum.DRESS]: 'dress',
[MenuEnum.SUIT]: 'suit',
[MenuEnum.HAIRSTYLE]: 'hair',
[MenuEnum.FIGURE]: 'figure',
[MenuEnum.UNDERWEAR]: 'underwear'
}
const isPerson = <'yes' | 'no'>isPersonMaps[menu.mainNav]
const clothType = <IClothType>clothTypeMaps[menu.subNav]
return Object.assign({ isPerson }, clothType && { clothType })
})
const updateMenu = (val: INavStatus) => {
menu.mainNav = val.mainNav
menu.subNav = val.subNav
}
const updateGender = (genderVal: 'male' | 'female') => {
if (genderVal !== gender.value) {
gender.value = genderVal
clearAllSelected()
}
}
const selectedTopCloth = ref<IClotheInfo>()
const selectedBottomCloth = ref<IClotheInfo>()
const selectedDressCloth = ref<IClotheInfo>()
const selectMutipleModelIds = ref<IModelInfo['id'][]>([])
const selectMutipleClothesIds = ref<(IModelInfo['id'] | IModelInfo['id'][])[]>()
const selectedModel = ref<IModelInfo>()
const selectedRoomInfo = ref<IRoomInfo>()
const selectedHairCloth = ref<IClotheInfo>()
const selectedFigureCloth = ref<IClotheInfo>()
const selectedUnderwearCloth = ref<IClotheInfo>()
const updateRoomInfo = (roomInfo: IRoomInfo) => {
updateMenu({
mainNav: MenuEnum.CLOTHES_LIBRARY,
subNav: MenuEnum.ALL
})
nextTick(() => {
console.log('更新一下')
selectedRoomInfo.value = roomInfo
})
}
const clearSelectedTopCloth = () => (selectedTopCloth.value = undefined)
const clearSelectedBottomCloth = () => (selectedBottomCloth.value = undefined)
const clearSecectedDressCloth = () => (selectedDressCloth.value = undefined)
const clearSecectedMutipleModelIds = () => {
selectMutipleModelIds.value = []
}
const clearSecectedMutipleClothesIds = () => {
selectMutipleClothesIds.value = []
}
const clearSelectedModel = () => (selectedModel.value = undefined)
const clearSelectedRoomInfo = () => {
selectedRoomInfo.value = undefined
}
const clearSelectedHairCloth = () => {
selectedHairCloth.value = undefined
}
const clearSelectedFigureCloth = () => {
selectedFigureCloth.value = undefined
}
const ClearselectedUnderwearCloth = () => {
selectedUnderwearCloth.value = undefined
}
const updateModel = (data: IModelInfo) => {
selectedModel.value = data
}
const clearSelectedCloths = () => {
clearSelectedTopCloth()
clearSelectedBottomCloth()
clearSecectedDressCloth()
clearSelectedHairCloth()
clearSelectedFigureCloth()
ClearselectedUnderwearCloth()
}
const clearAllSelected = () => {
clearSelectedCloths()
clearSelectedModel()
clearSecectedMutipleModelIds()
}
const fileList = ref<UploadUserFile[]>([])
const updateFileList = (data: UploadUserFile[]) => {
fileList.value = data
}
const updateSelectedCloth = (data: IClotheInfo) => {
if (data.clothType === 'topCloth') {
clearSecectedDressCloth()
clearSelectedHairCloth()
clearSelectedFigureCloth()
ClearselectedUnderwearCloth()
selectedTopCloth.value = data
}
if (data.clothType === 'bottomCloth') {
clearSecectedDressCloth()
clearSelectedHairCloth()
clearSelectedFigureCloth()
ClearselectedUnderwearCloth()
selectedBottomCloth.value = data
}
if (data.clothType === 'dress') {
clearSelectedCloths()
selectedDressCloth.value = data
}
if (data.clothType === 'suit') {
clearSelectedCloths()
data?.suitList?.forEach((i) => updateSelectedCloth(i))
}
if (data.clothType === 'hair') {
clearSelectedCloths()
selectedHairCloth.value = data
}
if (data.clothType === 'figure') {
clearSelectedCloths()
selectedFigureCloth.value = data
}
if (data.clothType === 'underwear') {
clearSelectedCloths()
selectedUnderwearCloth.value = data
}
}
const updateSelectMutipleModelIds = (modelId: IModelInfo['id']) => {
const oldValue = selectMutipleModelIds.value
selectMutipleModelIds.value = oldValue.includes(modelId)
? oldValue.filter((i) => i != modelId)
: [...oldValue, modelId]
}
const updateSelectMutileClothesIds = (clothId: IClotheInfo['clothId'], item: IClotheInfo) => {
const oldValue = selectMutipleClothesIds.value
if (item.clothType === 'suit') {
const idArr = JSON.parse(item.fileUrl) as IClotheInfo[]
console.log('AT-[ value &&&&&********** ]', idArr)
}
let value: string | string[]
if (item.clothType === 'suit') {
const idArr = JSON.parse(item.fileUrl) as IClotheInfo[]
value = idArr.map((i) => i.clothId)
} else {
value = clothId
}
console.log('AT-[ value &&&&&********** ]', value)
if (item.clothType != 'suit') {
selectMutipleClothesIds.value = oldValue?.includes(clothId)
? oldValue.filter((i) => i != clothId)
: [...(oldValue || []), clothId]
} else {
const index = oldValue?.findIndex((i) => i.toString() == value.toString())
if (index != -1) {
selectMutipleClothesIds.value = oldValue?.filter((i, idx) => index != idx)
} else {
selectMutipleClothesIds.value = [...(oldValue || []), value]
}
}
}
type IBrandInfo = {
logo: string
title: string
mainWebsite: string
style?: Record<string, string>
}
const brandInfoMaps = ref(
new Map<'jfputon' | 'fashionroom' | 'puton' | string, IBrandInfo>([
[
'jfputon',
{
logo: jfLogoImg,
title: '精分数据',
mainWebsite: 'https://jf.aidigitalfield.com',
style: {
height: '90%'
}
}
],
[
'fashionroom',
{
logo: juyunImg,
title: '聚云美搭官网',
mainWebsite: 'https://www.marshotspot.com',
style: {
height: '90%'
}
}
],
[
'puton',
{
logo: logoImg,
title: 'PutOn美搭助手_AI穿搭平台_数字力场',
mainWebsite: 'https://www.aidigitalfield.com',
style: {
width: ' 94px'
}
}
]
])
)
return {
menu,
updateMenu,
gender,
updateGender,
selectedTopCloth,
selectedBottomCloth,
selectedDressCloth,
updateSelectedCloth,
selectedModel,
updateModel,
clearSelectedTopCloth,
clearSelectedBottomCloth,
clearSecectedDressCloth,
clearSelectedCloths,
selectMutipleModelIds,
updateSelectMutipleModelIds,
clearSecectedMutipleModelIds,
clearAllSelected,
nav,
fileList,
updateFileList,
noticeVideo,
creatingImgMark,
createFailMark,
creatingAndFailMarkList,
selectMutipleClothesIds,
clearSecectedMutipleClothesIds,
updateSelectMutileClothesIds,
selectedRoomInfo,
clearSelectedRoomInfo,
updateRoomInfo,
selectedHairCloth,
clearSelectedHairCloth,
selectedFigureCloth,
clearSelectedFigureCloth,
brandInfoMaps,
selectedUnderwearCloth,
ClearselectedUnderwearCloth
}
})