1
This commit is contained in:
41
index.js
41
index.js
@ -1,5 +1,6 @@
|
||||
import { EXRCubeTexture } from '@babylonjs/core';
|
||||
import { kernel } from './src/main.ts';
|
||||
import apiConfig from './src/config.js';
|
||||
|
||||
//初始化
|
||||
export const init = async () => {
|
||||
@ -28,7 +29,10 @@ export const init = async () => {
|
||||
|
||||
//初始化加载模型
|
||||
export const getAutoLoadModelList = async () => {
|
||||
const response = await fetch('http://localhost:3001/api/models/auto-load/list')
|
||||
const url = apiConfig.getApiUrl('/api/models/auto-load/list')
|
||||
console.log('API URL:', url)
|
||||
console.log('apiConfig:', apiConfig)
|
||||
const response = await fetch(url)
|
||||
const data = await response.json()
|
||||
const models = data.data // 这就是模型列表
|
||||
|
||||
@ -58,7 +62,7 @@ export const getAutoLoadModelList = async () => {
|
||||
|
||||
//获取放置区域
|
||||
export const getPlacementZone = async (sku) => {
|
||||
const response = await fetch(`http://localhost:3001/api/product-configs/by-sku/${sku}`);
|
||||
const response = await fetch(apiConfig.getApiUrl(`/api/product-configs/by-sku/${sku}`));
|
||||
const result = await response.json();
|
||||
if (result.code === 200) {
|
||||
// await initPlacementZoneConfig();
|
||||
@ -84,7 +88,7 @@ export const getPlacementZone = async (sku) => {
|
||||
export const getEvent = async (dropzone_data, sku) => {
|
||||
// 将模型放置到该区域
|
||||
try {
|
||||
const response = await fetch(`http://localhost:3001/api/product-configs/by-sku/${sku}`);
|
||||
const response = await fetch(apiConfig.getApiUrl(`/api/product-configs/by-sku/${sku}`));
|
||||
const result = await response.json();
|
||||
|
||||
if (result.code === 200 && result.data) {
|
||||
@ -118,7 +122,7 @@ export const executeEvent = async (dropzone_data, result) => {
|
||||
|
||||
// 先记录模型放置(会自动处理替换逻辑)
|
||||
kernel.dropZone.recordModelPlacement(wallName, index, modelId);
|
||||
console.log(Math.abs(rotation.y - 90) ,Math.abs(rotation.y - 90) > 5 ? 'x' : 'z' );
|
||||
console.log(Math.abs(rotation.y - 90), Math.abs(rotation.y - 90) > 5 ? 'x' : 'z');
|
||||
// 加载并放置模型
|
||||
await kernel.model.add({
|
||||
modelId: modelId,
|
||||
@ -126,7 +130,7 @@ export const executeEvent = async (dropzone_data, result) => {
|
||||
modelControlType: model_control_type,
|
||||
drag: {
|
||||
enable: true,
|
||||
axis:rotation.y === 0 || rotation.y === 180 ? 'x' : 'z',
|
||||
axis: rotation.y === 0 || rotation.y === 180 ? 'x' : 'z',
|
||||
step: 0.1,
|
||||
},
|
||||
transform: {
|
||||
@ -159,6 +163,7 @@ export const executeEvent = async (dropzone_data, result) => {
|
||||
|
||||
//换棚子
|
||||
export const executeEvent2 = async (result) => {
|
||||
|
||||
// 检查是否有模型更换事件
|
||||
const hasModelChange = result.data.events.some(e => e.event_type === 'change_model');
|
||||
|
||||
@ -173,6 +178,10 @@ export const executeEvent2 = async (result) => {
|
||||
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;
|
||||
};
|
||||
|
||||
const { id, name, file_url, model_control_type, category, placement_zone } = target_data;
|
||||
console.log('替换百叶模型:', event);
|
||||
@ -227,7 +236,7 @@ export const executeEvent2 = async (result) => {
|
||||
export const getHotspot = async () => {
|
||||
try {
|
||||
// 从后端获取激活状态的热点列表
|
||||
const response = await fetch('http://localhost:3001/api/hotspots?status=active&page=1&pageSize=100');
|
||||
const response = await fetch(apiConfig.getApiUrl('/api/hotspots?status=active&page=1&pageSize=100'));
|
||||
const result = await response.json();
|
||||
|
||||
if (result.code === 200 && result.data.list.length > 0) {
|
||||
@ -256,3 +265,23 @@ export const getHotspot = async () => {
|
||||
console.error('获取热点数据失败:', error);
|
||||
}
|
||||
}
|
||||
|
||||
export const getProductConfig = async (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;
|
||||
// await initPlacementZoneConfig();
|
||||
if (enable_placement_zone) {
|
||||
getPlacementZone(sku)
|
||||
}
|
||||
else {
|
||||
executeEvent2(result)
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取产品配置失败:', error);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user