删除console.log
This commit is contained in:
81
index.js
81
index.js
@ -5,6 +5,10 @@ import { setSkuMapping, getSkuByModelId, clearSkuMapping, clearAllSkuMappings }
|
||||
// 存储 kernel 实例
|
||||
let kernelInstance = null;
|
||||
|
||||
// 存储已加载的墙面配置(key为墙面名称,value为墙面配置)
|
||||
// 用于拖拽时能找到对应的墙面配置
|
||||
let wall_divisions_cache = new Map();
|
||||
|
||||
// 导出 SKU 映射相关函数,方便外部使用
|
||||
export { getSkuByModelId, clearSkuMapping, clearAllSkuMappings };
|
||||
|
||||
@ -18,7 +22,6 @@ export const initApp = (kernel) => {
|
||||
throw new Error('kernel 实例是必需的');
|
||||
}
|
||||
kernelInstance = kernel;
|
||||
console.log('应用逻辑已初始化,kernel 实例已注入');
|
||||
return kernelInstance;
|
||||
};
|
||||
|
||||
@ -101,6 +104,7 @@ export const getAutoLoadModelList = async () => {
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
//获取放置区域
|
||||
export const getPlacementZone = async (sku) => {
|
||||
//pergolaSku 是需要在加载棚子的时取其引用,传进来的sku则是配件的sku,根据配件的sku来判断放置区域
|
||||
@ -155,13 +159,16 @@ export const getPlacementZone = async (sku) => {
|
||||
}
|
||||
}
|
||||
|
||||
//棚子同时包10和20的并且含配件是13
|
||||
//棚子同时包10和20的并且含配件是13
|
||||
if (only10_20 && has13) {
|
||||
|
||||
if (pergolaSku === "SPF111S1020PILLAR4PCS") {
|
||||
division_include.push('前', '后')
|
||||
}
|
||||
}
|
||||
|
||||
console.log('[放置区域] 本次配件的方向:', division_include);
|
||||
|
||||
const response = await fetch(apiConfig.getApiUrl(`/api/product-configs/by-sku/${sku}`));
|
||||
const result = await response.json();
|
||||
if (result.code === 200) {
|
||||
@ -169,10 +176,18 @@ export const getPlacementZone = async (sku) => {
|
||||
const { enable_placement_zone, wall_divisions } = result.data;
|
||||
// const {position_x, position_y, position_z} = data;
|
||||
if (enable_placement_zone && wall_divisions != undefined) {
|
||||
console.log(wall_divisions);
|
||||
console.log('[放置区域] 当前配件的墙面配置:', wall_divisions);
|
||||
|
||||
// 将当前配件的墙面配置缓存起来(用于拖拽时查找)
|
||||
wall_divisions.forEach(wall => {
|
||||
wall_divisions_cache.set(wall.name, wall);
|
||||
});
|
||||
console.log('[放置区域] 已缓存的所有墙面配置:', Array.from(wall_divisions_cache.keys()));
|
||||
|
||||
// 只使用当前配件的墙面配置,不累积显示
|
||||
const filteredDivisions = wall_divisions.filter(item => division_include.includes(item.name))
|
||||
console.log(filteredDivisions);
|
||||
console.log('[放置区域] 当前显示的墙面:', filteredDivisions);
|
||||
|
||||
// 只清除旧的放置区域网格,不清除模型
|
||||
kernel.dropZone.clearZones();
|
||||
const divisions = filteredDivisions.map(wall => ({
|
||||
@ -187,6 +202,48 @@ export const getPlacementZone = async (sku) => {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空墙面配置缓存
|
||||
* 当需要重新开始配件布局时调用此方法
|
||||
*/
|
||||
export const clearDivisionCache = () => {
|
||||
wall_divisions_cache.clear();
|
||||
console.log('[放置区域] 墙面配置缓存已清空');
|
||||
};
|
||||
|
||||
/**
|
||||
* 根据墙面名称获取缓存的墙面配置
|
||||
* @param {string} wallName 墙面名称
|
||||
* @returns {Object|null} 墙面配置对象,如果没有则返回 null
|
||||
*/
|
||||
export const getCachedWallConfig = (wallName) => {
|
||||
return wall_divisions_cache.get(wallName) || null;
|
||||
};
|
||||
|
||||
/**
|
||||
* 显示指定墙面的放置区域(从缓存恢复)
|
||||
* @param {string} wallName 墙面名称
|
||||
*/
|
||||
export const showWallFromCache = (wallName) => {
|
||||
const kernel = getKernel();
|
||||
const wallConfig = wall_divisions_cache.get(wallName);
|
||||
|
||||
if (wallConfig) {
|
||||
console.log(`[放置区域] 从缓存恢复墙面 ${wallName}:`, wallConfig);
|
||||
|
||||
// 清除旧的放置区域网格
|
||||
kernel.dropZone.clearZones();
|
||||
|
||||
// 重新生成该墙面的放置区域
|
||||
kernel.dropZone.updateDivisions([wallConfig]);
|
||||
|
||||
// 显示放置区域
|
||||
kernel.dropZone.show();
|
||||
} else {
|
||||
console.warn(`[放置区域] 墙面 ${wallName} 没有缓存配置`);
|
||||
}
|
||||
};
|
||||
|
||||
//执行事件
|
||||
export const getEvent = async (dropzone_data, sku) => {
|
||||
|
||||
@ -196,8 +253,6 @@ export const getEvent = async (dropzone_data, sku) => {
|
||||
const result = await response.json();
|
||||
|
||||
if (result.code === 200 && result.data) {
|
||||
console.log('SKU配置数据:', result.data);
|
||||
console.log('关联事件:', result.data.events);
|
||||
|
||||
// 使用 for...of 循环以支持 await
|
||||
await executeEvent(dropzone_data, result, sku)
|
||||
@ -253,7 +308,6 @@ export const executeEvent = async (dropzone_data, result, sku) => {
|
||||
}
|
||||
});
|
||||
|
||||
console.log(`百叶模型已放置为 ${name + '_' + modelId}`);
|
||||
}
|
||||
}
|
||||
|
||||
@ -275,7 +329,6 @@ export const executeEvent = async (dropzone_data, result, sku) => {
|
||||
roughness: +roughness
|
||||
});
|
||||
|
||||
console.log(`百叶模型颜色已替换为 ${color}`);
|
||||
}
|
||||
}
|
||||
|
||||
@ -290,7 +343,6 @@ export const executeEvent = async (dropzone_data, result, sku) => {
|
||||
}
|
||||
}
|
||||
|
||||
console.log('当前棚子的 SKU:', pergolaSku);
|
||||
return pergolaSku;
|
||||
}
|
||||
|
||||
@ -309,13 +361,11 @@ export const executeEvent2 = async (result, sku) => {
|
||||
if (firstModelEvent && firstModelEvent.target_data) {
|
||||
const { name, category } = firstModelEvent.target_data;
|
||||
modelAlreadyExists = kernel.model.exists(name + '_' + category);
|
||||
console.log(`检查模型 ${name + '_' + category} 是否存在:`, modelAlreadyExists);
|
||||
}
|
||||
}
|
||||
kernel.dropZone.hide();
|
||||
// 只有在需要更换模型且模型不存在时才清除
|
||||
if (hasModelChange && !modelAlreadyExists) {
|
||||
console.log('模型不存在,执行清除操作');
|
||||
|
||||
kernel.model.removeAll();
|
||||
// 清除所有 SKU 映射
|
||||
@ -324,11 +374,9 @@ export const executeEvent2 = async (result, sku) => {
|
||||
|
||||
// 先处理所有 change_model 事件
|
||||
for (const event of result.data.events) {
|
||||
console.log(event);
|
||||
|
||||
if (event.event_type === 'change_model') {
|
||||
const { target_data } = event;
|
||||
console.log(event.target_data);
|
||||
if (!target_data) {
|
||||
console.error('change_model事件缺少target_data')
|
||||
return;
|
||||
@ -337,7 +385,6 @@ export const executeEvent2 = async (result, sku) => {
|
||||
const { id, name, file_url, model_control_type, category, placement_zone } = target_data;
|
||||
// 如果模型已存在,跳过加载
|
||||
if (modelAlreadyExists) {
|
||||
console.log(`模型 ${name + '_' + category} 已存在,跳过加载`);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -364,7 +411,6 @@ export const executeEvent2 = async (result, sku) => {
|
||||
modelControlType: model_control_type,
|
||||
})
|
||||
|
||||
console.log(`模型已放置为 ${name + '_' + category}`);
|
||||
}
|
||||
}
|
||||
|
||||
@ -373,7 +419,6 @@ export const executeEvent2 = async (result, sku) => {
|
||||
if (event.event_type === 'change_color') {
|
||||
const materialName = event.material_name;
|
||||
const { color, color_map_url, normal_map_url, metallic, roughness } = event.target_data;
|
||||
console.log('替换模型颜色:', event.target_data);
|
||||
|
||||
kernel.material.apply({
|
||||
target: materialName,
|
||||
@ -384,7 +429,6 @@ export const executeEvent2 = async (result, sku) => {
|
||||
roughness: +roughness,
|
||||
});
|
||||
|
||||
console.log(`百叶模型颜色已替换为 ${color}`);
|
||||
}
|
||||
}
|
||||
|
||||
@ -417,7 +461,6 @@ export const getHotspot = async () => {
|
||||
|
||||
// 渲染热点
|
||||
kernel.hotspot.render(hotspots);
|
||||
console.log('热点渲染成功:', hotspots);
|
||||
} else {
|
||||
console.log('没有可用的热点数据');
|
||||
}
|
||||
@ -427,11 +470,11 @@ export const getHotspot = async () => {
|
||||
}
|
||||
//点击右侧按钮自动判断
|
||||
export const getProductConfig = async (sku) => {
|
||||
console.log(sku);
|
||||
try {
|
||||
const response = await fetch(`${apiConfig.getApiUrl(`/api/product-configs/by-sku/${sku}`)}`);
|
||||
const result = await response.json();
|
||||
if (result.code === 200) {
|
||||
console.log(result.data);
|
||||
const { enable_placement_zone } = result.data;
|
||||
//如果触发的是配件,需要显示放置区域
|
||||
|
||||
|
||||
Reference in New Issue
Block a user