Files
aida_front/src/store/Detail/designDetail.ts

386 lines
12 KiB
TypeScript
Raw Normal View History

2023-01-06 16:00:15 +08:00
import {Module} from 'vuex'
import {RootState} from '../index'
import { forEach } from 'jszip'
import { transform } from 'typescript'
2023-01-06 16:00:15 +08:00
interface DesignDetail{
2025-08-22 10:27:48 +08:00
designDetail:any,
2023-09-25 10:09:00 +08:00
designPreviewData:any,
2025-08-22 10:27:48 +08:00
frontBack:any,
selectDetail:any,
printZIndex:any,
//值都有 sketchcolor,print,element
currentDetailType:any,
currentPrintElement:any,
canvasKey:any,
2023-01-06 16:00:15 +08:00
}
2025-08-22 10:27:48 +08:00
const DesignDetail : Module<DesignDetail,RootState> = {
namespaced: true,
2023-01-06 16:00:15 +08:00
state:{
2025-08-22 10:27:48 +08:00
designDetail:null,
designPreviewData:{},
frontBack:{
front:[],
back:[],
body:{},
},
selectDetail:null,
printZIndex:-1,
currentDetailType:'',
currentPrintElement:null,
canvasKey:0,
2023-01-06 16:00:15 +08:00
},
mutations:{
clearDetailData(state){
state.designDetail = null
state.designPreviewData = {}
state.frontBack = {
front:[],
back:[],
body:{},
}
state.selectDetail = null
state.printZIndex = -1
state.currentDetailType = ''
state.currentPrintElement = null
state.canvasKey = 0
},
2025-08-22 10:27:48 +08:00
setDesignDetail(state,data){
if(data.others.length > 0 && data.others[0].type == "Body"){
state.frontBack.body = data.others[0]
}
let front:any = []
let back:any = []
state.designDetail = data
2025-08-22 10:27:48 +08:00
// let printZIndex =
data.clothes.forEach((v:any,index:any)=>{
// if(!v?.partialDesignDTO){
// }
function isJSONString(str) {
try {
JSON.parse(str);
return true; // 解析成功是有效的JSON字符串
} catch (e) {
return false; // 解析失败不是有效的JSON字符串
}
}
v?.printObject?.prints?.forEach((item:any) => {
if(isJSONString(item.object)){
item.object = JSON.parse(item.object)
}
});
v?.trims?.prints?.forEach((item:any) => {
if(isJSONString(item.object)){
item.object = JSON.parse(item.object)
}
});
2025-08-22 10:27:48 +08:00
for (let i = v.layersObject.length-1; i >= 0; i--) {
v.layersObject[i].style = {
top:v.layersObject[i].position?.[0],
left:v.layersObject[i].position?.[1],
width:v.layersObject[i].imageSize?.[0],
height:v.layersObject[i].imageSize?.[1],
2026-02-02 10:31:37 +08:00
transform:`rotate(${v.layersObject?.[i]?.rotate || 0}deg) scaleX(${v.layersObject[i].transpose?.[0] || 1}) scaleY(${v.layersObject[i].transpose?.[1] || 1})`,
2025-08-22 10:27:48 +08:00
}
v.layersObject[i].centers={
left:0,
top:0,
}
2025-08-26 10:14:34 +08:00
v.maskMinioUrl = v.layersObject?.[0]?.maskMinioUrl
v.maskUrl = v.layersObject?.[0]?.maskUrl
2025-08-22 10:27:48 +08:00
v.layersObject[i].designOpenrtionBtn = false
if(v.layersObject[i].imageCategory.indexOf("back") == -1){
front[index] = v.layersObject[i]
front[index].style.zIndex = v.priority + 10
2025-08-22 10:27:48 +08:00
front[index].id = v.id
}else{
back[index] = v.layersObject[i]
back[index].style.zIndex = v.priority
back[index].id = v.id
// back[index].style.zIndex = backIndex==0?v.layersObject[i]:backIndex++
}
if(state.printZIndex < v.priority){
state.printZIndex = v.priority
}
}
})
state.frontBack.front = front
state.frontBack.back = back
2023-01-06 16:00:15 +08:00
},
2025-08-22 10:27:48 +08:00
updataDetailItem(state,data){
state.designDetail.clothes.forEach((item:any) => {
if(item.id == state.selectDetail.id){
for (const key in data) {
item[key] = data[key]
}
}
});
},
addDesign(state,data){
},
setNewDetail(state,value){
// state.designDetail.clothes.forEach((item:any) => {
// if(item.id == state.selectDetail.id){
// }
// });
let select = state.selectDetail
if(value.id){
select = state.designDetail.clothes.find((item:any) => item.id == value.id)
}
2025-08-22 10:27:48 +08:00
let {data} = value
let str = value.str || state.currentDetailType
if(!select)return
if(!select.newDetail){
select.newDetail = {}
2025-08-22 10:27:48 +08:00
}
if(str == 'sketch'){
select.newDetail[str] = data
2025-08-22 10:27:48 +08:00
}else if(str == 'color'){
select.newDetail[str] = data
2025-08-22 10:27:48 +08:00
}else if(str == 'print'){
select.newDetail[str] = data
2025-08-22 10:27:48 +08:00
}else if(str == 'element'){
select.newDetail[str] = data
2025-08-22 10:27:48 +08:00
}else if(str == 'models'){
// if(!state.designDetail.newModel)state.designDetail.newModel={}
state.designDetail.newModel = JSON.parse(JSON.stringify(data))
}else{
if(!select.newDetail[str])select.newDetail[str] = []
const foundObjects = select.newDetail[str].filter((item:any) => item.id === data.id);
2025-08-22 10:27:48 +08:00
if(foundObjects.length == 0){
select.newDetail[str].push(data)
2025-08-22 10:27:48 +08:00
}
}
},
setCurrentPrintElement(state,data){//临时存放印花和元素点击用来监听在衣服上添加元素
state.currentPrintElement = data?.resData || data
},
setCurrentDetailType(state,data){
if(state.selectDetail && state.selectDetail.id){
state.currentDetailType = data
}else if(state.selectDetail && data == 'sketch'){
state.currentDetailType = data
}
},
setFrontBack(state,data){
state.frontBack = data
},
2025-08-22 10:27:48 +08:00
setDesignColthes(state,data){
if(!state.currentDetailType)state.currentDetailType = 'sketch'
//切换选择
// state.currentDetailType = ''
// state.designDetail.clothes[data.index] = data.clothes
state.designDetail.clothes.forEach((item:any) => {
if(item.id == data){
state.selectDetail = item
2026-01-21 09:43:26 +08:00
// state.frontBack.front.forEach((v:any,index:any)=>{
// v.designOpenrtionBtn = false
// if(v.id == data){
// v.designOpenrtionBtn = true
// }
// })
2025-08-22 10:27:48 +08:00
}
});
2023-01-06 16:00:15 +08:00
},
2025-08-22 10:27:48 +08:00
addDesignColthes(state){
let data = {
changed:null,
color:{rgba:{
r:255,
g:255,
b:255,
}},
designType:null,
gradient:null,
id:null,
partialDesign:{
layers:[],
partialDesignPath:'',
partialDesignMinioPath:'',
partialDesignBase64:''
},
layersObject:null,
newDetail:{},
level1Type:'Sketchboard',
minIOPath:null,
path:null,
printObject:null,
trims:null,
type:null,
transpose:[1,1],
rotate:0,
2025-08-22 10:27:48 +08:00
}
if(!state.currentDetailType)state.currentDetailType = 'sketch'
state.designDetail.clothes.forEach((item:any) => {
state.frontBack.front.forEach((v:any,index:any)=>{
v.designOpenrtionBtn = false
})
});
state.selectDetail = data
},
changeCanvasKey(state){
state.canvasKey+=1
},
canvasPreviewUpdata(state,{type,callBack}){
// state.selectDetail.newDetail?.print?.forEach((item:any) => {
// state.selectDetail.printObject.prints = []
// state.selectDetail.printObject.push({
// })
// });
if((type == 'print' || type == 'all') && state.selectDetail.newDetail?.print)state.selectDetail.printObject.prints = state.selectDetail.newDetail?.print
if((type == 'color' || type == 'all') && state.selectDetail.newDetail?.color?.rgba)state.selectDetail.color = {
...state.selectDetail.newDetail?.color,
...state.selectDetail.newDetail?.color?.rgba,
...state.selectDetail.newDetail?.color?.hsv,
}
if((type == 'element' || type == 'all') && state.selectDetail.newDetail?.element)state.selectDetail.trims.prints = state.selectDetail.newDetail?.element
if(type == 'all'){
state.selectDetail.newDetail = {}
}else{
state.selectDetail.newDetail[type] = null
}
callBack()
},
setPraeview(state,value){//preview
let data = value?.rv || value
let currentType = value?.currentType
2025-08-22 10:27:48 +08:00
if(state.designDetail.oldModel?.url)state.frontBack.body.path = state.designDetail.oldModel.url
if(value?.rv?.currentFullBodyView)state.designDetail.currentFullBodyView = value.rv.currentFullBodyView
2025-08-22 10:27:48 +08:00
for (let j = 0; j < data.clothes.length; j++) {
const item = data.clothes[j];
if(!item.id)continue
let id_:any
if(state.currentDetailType != 'models'){
if(data.clothes.length > 2){
//缺少字段临时添加
id_ = item.id || state.selectDetail.newDetail?.sketch?.id
}else{
id_ = state.selectDetail.id || state.selectDetail.newDetail?.sketch?.id
}
2025-08-22 10:27:48 +08:00
}else{
id_ = item.id
}
if(state.frontBack?.body?.path){
let scale:any = value.scale
if(state.selectDetail?.newDetail?.sketch?.id && !state.selectDetail.id){
state.frontBack.front.push({id:state.selectDetail.newDetail?.sketch?.id})
state.frontBack.back.push({id:state.selectDetail.newDetail?.sketch?.id})
2025-08-22 10:27:48 +08:00
}
state.frontBack.front.forEach((v:any,index:any)=>{
if(v.id == id_){
for (let i = item.layersObject.length-1; i >= 0; i--) {
item.layersObject[i].style = {
top:item.layersObject[i].position?.[0] * scale + 'px',
left:item.layersObject[i].position?.[1] * scale + 'px',
width:item.layersObject[i].imageSize?.[0] * scale + 'px',
height:item.layersObject[i].imageSize?.[1] * scale + 'px',
zIndex:v?.style?.zIndex?v.style.zIndex:v.priority?v.priority:state.frontBack.front.length,
2026-01-24 13:25:40 +08:00
transform:`scaleX(${item.layersObject[i].transpose?.[0] || 1}) scaleY(${item.layersObject[i].transpose?.[1] || 1}) rotate(${item.layersObject?.[i]?.rotate || 0}deg)`,
}
item.layersObject[i].centers={
left:0,
top:0,
}
item.layersObject[i].designOpenrtionBtn = false
if(item.layersObject[i].imageCategory.indexOf("back") == -1){
state.frontBack.front[index] = item.layersObject[i]
// state.frontBack.front[index].style.zIndex = v.priority
state.frontBack.front[index].id = item.id
}else{
state.frontBack.back[index] = item.layersObject[i]
// state.frontBack.back[index].style.zIndex = v.priority
state.frontBack.back[index].id = item.id
2025-08-22 10:27:48 +08:00
}
}
}
})
}
let uploadDetail = (detailItem)=>{
detailItem.change = item.change
if(detailItem?.newDetail?.color && currentType != 'color'){
detailItem.color = detailItem?.newDetail?.color
detailItem.newDetail.color = null
2025-08-22 10:27:48 +08:00
}
if(item.partialDesign){
detailItem.partialDesign = item.partialDesign
2025-08-22 10:27:48 +08:00
}
detailItem.designType = item.designType
detailItem.canvasId = item.canvasId
detailItem.layersObject = item.layersObject
detailItem.path = item.path
detailItem.minIOPath = item.minIOPath
detailItem.scale = [1,1]
detailItem.offset = [0,0]
detailItem.transpose = item.transpose || [1,1]
detailItem.rotate = item.rotate || 0
function isJSONString(str) {
try {
JSON.parse(str);
return true; // 解析成功是有效的JSON字符串
} catch (e) {
return false; // 解析失败不是有效的JSON字符串
}
}
item.trims?.prints?.forEach((item:any) => {
if(isJSONString(item.object)){
item.object = JSON.parse(item.object)
}
});
item.printObject?.prints?.forEach((item:any) => {
if(isJSONString(item.object)){
item.object = JSON.parse(item.object)
}
});
detailItem.printObject = item.printObject
detailItem.trims = item.trims
detailItem.type = item.type
detailItem.maskMinioUrl = item.layersObject?.[0]?.maskMinioUrl
detailItem.maskUrl = item.layersObject?.[0]?.maskUrl
detailItem.color = {
...item.color,
rgba:{
r:item.color?.r,
g:item.color?.g,
b:item.color?.b,
2025-09-25 23:41:33 +08:00
},
gradient:item.gradient,
}
if(detailItem.newDetail?.sketch?.id && !detailItem.id){
state.designDetail.clothes.push(detailItem)
2025-08-22 10:27:48 +08:00
}
detailItem.id = item.id
if(currentType)if(detailItem.newDetail?.[currentType] && currentType != 'color')delete detailItem.newDetail[currentType]
}
if(data.clothes.length > 2){
state.designDetail.clothes.forEach((detailItem:any) => {
if(detailItem.id == id_){
uploadDetail(detailItem)
}
});
}else{
uploadDetail(state.selectDetail)
}
2025-08-22 10:27:48 +08:00
}
2025-08-22 10:27:48 +08:00
},
2023-09-12 10:11:27 +08:00
// setDesignItemOthers(state,data){
2025-08-22 10:27:48 +08:00
// state.designDetail.others[data.index] = data.others
2023-09-12 10:11:27 +08:00
// },
2023-01-06 16:00:15 +08:00
},
actions:{
2025-08-22 10:27:48 +08:00
async setSubmit({ commit },str) {
// setTimeout(() => {
// const message = 'Hello from Vuex';
// commit('setMessage', message); // 更新状态
// resolve(message); // 返回数据
// }, 1000);
},
2023-01-06 16:00:15 +08:00
}
}
2025-08-22 10:27:48 +08:00
export default DesignDetail