From 9a90d4d995a2a3fb2226c0b57f5b5999a3a14e03 Mon Sep 17 00:00:00 2001 From: tonkia Date: Thu, 27 Dec 2018 21:26:43 +0800 Subject: [PATCH] complete share page --- 123456 | 0 static/js/createScheme.js | 17 ++++---- static/js/share.js | 88 +++++++++++++++++++++++++++++++++++++++ views/share.html | 50 ++++++++++++++++++++++ 4 files changed, 147 insertions(+), 8 deletions(-) create mode 100644 123456 diff --git a/123456 b/123456 new file mode 100644 index 0000000..e69de29 diff --git a/static/js/createScheme.js b/static/js/createScheme.js index 439eaac..0bb0ce9 100644 --- a/static/js/createScheme.js +++ b/static/js/createScheme.js @@ -171,15 +171,16 @@ function delTexture(index) { //点击事件:切换贴图 function changeTexture(index) { - if (index < 0) - return; - var modelIndex = data.components[componentIndex].modelIndex; - if (modelIndex < 0) - return; - data.components[componentIndex].textureIndex = index; - replaceTexture(data.components[componentIndex].models[modelIndex].modelObj, data.components[componentIndex].textures[index].textureObj); + if (componentIndex >= 0) { + if (index < 0) + return; + var modelIndex = data.components[componentIndex].modelIndex; + if (modelIndex < 0) + return; + data.components[componentIndex].textureIndex = index; + replaceTexture(data.components[componentIndex].models[modelIndex].modelObj, data.components[componentIndex].textures[index].textureObj); + } } - //--------------------------------------------------------------------------------------------------------------------- //ui初始化结束后 //初始化Threejs diff --git a/static/js/share.js b/static/js/share.js index e3fdf6b..6ec2a74 100644 --- a/static/js/share.js +++ b/static/js/share.js @@ -1,4 +1,5 @@ var data; +var componentIndex; $().ready(function () { init(); @@ -78,9 +79,96 @@ function init() { //------------------------------------------------------------------------------ //界面初始化 + + +var swiperComponent; +var swiperModel; +var swiperTexture; + function initUi() { + $('#ui').show(); + initComponentList(); + initSwiper(); +} +function initComponentList() { + for (var index in data.components) { + $('#componentList').prepend("
" + data.components[index].name + "
"); + } +} + +function initSwiper() { + swiperModel = new Swiper('#swiperModel', { + grabCursor: true, + spaceBetween: 20, + slidesPerView: 3, + }) + + swiperTexture = new Swiper('#swiperTexture', { + grabCursor: true, + slidesPerView: 6, + spaceBetween: 20, + }) + + swiperComponent = new Swiper('#swiperComponent', { + grabCursor: true, + direction: 'vertical', + on: { + slideChange: function () { + componentIndex = this.activeIndex; + freshModelList(this.activeIndex); + freshTextureList(this.activeIndex); + }, + }, + }) +} + +function freshModelList(componentIndex) { + swiperModel.removeAllSlides(); + for (var index in data.components[componentIndex].models) { + swiperModel.appendSlide('
'); + } } + +function freshTextureList(componentIndex) { + swiperTexture.removeAllSlides(); + for (var index in data.components[componentIndex].textures) { + var fileName = data.components[componentIndex].textures[index].name; + var fileId = data.components[componentIndex].textures[index].fileId; + swiperTexture.appendSlide('
' + fileName + '
'); + } +} +//点击事件:切换模型 +function changeModel(index) { + //先换贴图 + data.components[componentIndex].modelIndex = index; + var textureIndex = data.components[componentIndex].textureIndex; + changeTexture(textureIndex); + //显示模型 + for (var i in data.components[componentIndex].models) { + if (i == index) { + data.components[componentIndex].models[i].modelObj.visible = true; + } else { + data.components[componentIndex].models[i].modelObj.visible = false; + } + } +} + + +//点击事件:切换贴图 +function changeTexture(index) { + if (componentIndex >= 0) { + if (index < 0) + return; + var modelIndex = data.components[componentIndex].modelIndex; + if (modelIndex < 0) + return; + data.components[componentIndex].textureIndex = index; + replaceTexture(data.components[componentIndex].models[modelIndex].modelObj, data.components[componentIndex].textures[index].textureObj); + } +} + + //------------------------------------------------------------------------------ //threejs配置 function initThree() { diff --git a/views/share.html b/views/share.html index d0ea675..66c79fb 100644 --- a/views/share.html +++ b/views/share.html @@ -19,6 +19,9 @@ + + + + + + + + +
@@ -65,6 +114,7 @@
+ \ No newline at end of file