tonkia 6 years ago
parent 60f57996db
commit e159a52afe
  1. 47
      app.js
  2. 22
      db.js
  3. BIN
      static/img/webbg.jpg
  4. 42
      static/js/createScheme.js
  5. 115
      views/createScheme.html
  6. 2
      views/home.html

@ -124,41 +124,60 @@ app.get('/files/:fileType/:fileName', function (req, res) {
var fileName = req.params['fileName']; var fileName = req.params['fileName'];
res.sendFile(__dirname + "/uploads/" + fileType + "/" + fileName); res.sendFile(__dirname + "/uploads/" + fileType + "/" + fileName);
}); });
//------------------------------------------------------------------------------------------------
//保存方案 //保存方案
app.post('/saveScheme', function (req, res) { app.post('/saveScheme', function (req, res) {
var data = req.body; var data = req.body;
var id = data.id;
var img = data.img; var img = data.img;
delete data.img; delete data.img;
db.insertScheme(req.session.user.id, data.name, JSON.stringify(data), img, function (res) { //如果有id存在就update
//console.info(res); if (id) {
if (res.affectedRows > 0) { db.updateScheme(req.session.user.id, id, data.name, JSON.stringify(data), img, function (row) {
if (row.affectedRows > 0) {
} else { var returnData = {
affectedRows: row.affectedRows
}
res.send(returnData);
} else {
} }
}); });
} else {
//如果id不存在就插入数据返回id
db.insertScheme(req.session.user.id, data.name, JSON.stringify(data), img, function (row) {
if (row.affectedRows > 0) {
var returnData = {
affectedRows: row.affectedRows,
insertId: row.insertId
}
res.send(returnData);
} else {
//插入失败
}
});
}
// console.info(data); // console.info(data);
}); });
//------------------------------------------------------------------------------------------------
//获取方案 //获取初始方案
app.post('/getScheme', function (req, res) { app.post('/getScheme', function (req, res) {
var data = { name: '默认方案', components: [], img: null }; var data = { name: '默认方案', components: [], img: null, id: null };
res.send(data); res.send(data);
}); });
//根据局ID获取初始方案
app.post('/getScheme/:id', function (req, res) { app.post('/getScheme/:id', function (req, res) {
var id = req.params['id']; var id = req.params['id'];
var user = req.session.user; var user = req.session.user;
// console.info(user.id + ":" + id);
if (id) { if (id) {
db.getSchemeById(user.id, id, function (row) { db.getSchemeById(user.id, id, function (row) {
if (row.length > 0) { if (row.length > 0) {
// console.info(row[0].data);
var data = JSON.parse(row[0].data); var data = JSON.parse(row[0].data);
data.id = id;
res.send(data); res.send(data);
} else { } else {
//找不到方案 //TODO 找不到方案
} }
}) })
} else { } else {

22
db.js

@ -70,6 +70,25 @@ module.exports.insertScheme = function (uid, name, data, img, callback) {
}); });
}; };
module.exports.updateScheme = function (uid, id, name, data, img, callback) {
connection.getConnection(function (err, conn) {
if (err) {
console.info(err);
} else {
conn.query('UPDATE scheme SET name=?,data=?,img=? WHERE uid=? AND id =?', [name, data, img, uid, id], function (err, rows) {
if (err) {
console.log(err);
return;
}
callback(rows);
conn.release();
});
}
});
};
module.exports.getSchemeById = function (uid, id, callback) { module.exports.getSchemeById = function (uid, id, callback) {
connection.getConnection(function (err, conn) { connection.getConnection(function (err, conn) {
if (err) { if (err) {
@ -85,4 +104,5 @@ module.exports.getSchemeById = function (uid, id, callback) {
}); });
} }
}); });
}; };

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 4.7 KiB

@ -1,6 +1,11 @@
//全局变量 //全局变量
var renderer, scene, camera, controls; var renderer, scene, camera, controls;
//加载参数
var totalFinish = 0; var totalFinish = 0;
//相机参数
var height = 2;
var distance = 10;
var angel = 0;
//整个页面维护的数据 //整个页面维护的数据
//var data = { name: '默认方案', components: [] }; //var data = { name: '默认方案', components: [] };
//TODO 相机参数 //TODO 相机参数
@ -208,15 +213,16 @@ function initScene() {
} }
function initCamera() { function initCamera() {
//相机设置 //相机设置
camera = new THREE.PerspectiveCamera(45, $('#viewField').innerWidth() / $('#viewField').innerHeight()); camera = new THREE.PerspectiveCamera(45, $('#viewField').innerWidth() / $('#viewField').innerHeight());
camera.position.set(0, 5, 10); camera.position.set(distance * Math.sin(angel), height, distance * Math.cos(angel));
//让相机对着场景中央 //让相机对着场景中央
camera.lookAt(scene.position); camera.lookAt(0, height, 0);
//相机控制,控制的相机和监听的dom //相机控制,控制的相机和监听的dom
controls = new THREE.OrbitControls(camera, $('#viewField')[0]); // controls = new THREE.OrbitControls(camera, $('#viewField')[0]);
controls.target.set(0, 0, 0); // controls.target.set(0, 0, 0);
controls.update(); // controls.update();
} }
function initRenderer() { function initRenderer() {
@ -314,7 +320,10 @@ function initTexture() {
//初始化所有事件 //初始化所有事件
function initEvent() { function initEvent() {
$('#saveScheme').click(function () { $('#saveScheme').click(function () {
var saveData = data; //复制一个saveData
var saveData = {};
$.extend(saveData, data);
//去除aveData中多余的数据
for (var index in saveData.components) { for (var index in saveData.components) {
for (textureIndex in saveData.components[index].textures) { for (textureIndex in saveData.components[index].textures) {
delete saveData.components[index].textures[textureIndex].textureObj; delete saveData.components[index].textures[textureIndex].textureObj;
@ -323,15 +332,32 @@ function initEvent() {
delete saveData.components[index].models[modelIndex].modelObj; delete saveData.components[index].models[modelIndex].modelObj;
} }
} }
//生成缩略图
var image = new Image(); var image = new Image();
let imgData = renderer.domElement.toDataURL("image/jpeg");//这里可以选择png格式jpeg格式 let imgData = renderer.domElement.toDataURL("image/jpeg");//这里可以选择png格式jpeg格式
saveData.img = imgData; saveData.img = imgData;
console.info(saveData); //上传服务器
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: "/saveScheme", url: "/saveScheme",
contentType: "application/json; charset=utf-8", contentType: "application/json; charset=utf-8",
data: JSON.stringify(saveData) data: JSON.stringify(saveData),
success: function (returnData) {
console.info(returnData);
if (returnData.affectedRows > 0) {
//获取保存后的id
if (returnData.insertId)
data.id = returnData.insertId;
new $.zui.Messager('保存成功!', {
type: 'success',
close: false,
actions: [{
icon: 'times',
text: '确定'
}]
}).show();
}
}
}); });
}); });

@ -102,76 +102,79 @@
<button class="btn btn-success btn-block" id="saveScheme">保存方案</button> <button class="btn btn-success btn-block" id="saveScheme">保存方案</button>
</div> </div>
</div> </div>
<!-- 模态框:添加组件 --> <div class='pull-right' style='margin-right: 10px'><a href='/home'>返回主页</a></div>
<div class="modal fade" id="addComponentModal"> </div>
<div class="modal-dialog modal-sm">
<div class="modal-content"> <!-- 模态框:添加组件 -->
<div class="modal-header"> <div class="modal fade" id="addComponentModal">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span <div class="modal-dialog modal-sm">
class="sr-only">关闭</span></button> <div class="modal-content">
<h4 class="modal-title">添加新组件</h4> <div class="modal-header">
</div> <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span
<div class="modal-body"> class="sr-only">关闭</span></button>
<input type="text" class="form-control" id="componentName" placeholder="组件名称"> <h4 class="modal-title">添加新组件</h4>
</div> </div>
<div class="modal-footer"> <div class="modal-body">
<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button> <input type="text" class="form-control" id="componentName" placeholder="组件名称">
<button type="button" class="btn btn-primary" id="addComponent">添加</button> </div>
</div> <div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
<button type="button" class="btn btn-primary" id="addComponent">添加</button>
</div> </div>
</div> </div>
</div> </div>
</div>
<!-- 模态框:材质管理 --> <!-- 模态框:材质管理 -->
<div class="modal fade" id="textureManagermentModal"> <div class="modal fade" id="textureManagermentModal">
<div class="modal-dialog modal-lg"> <div class="modal-dialog modal-lg">
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> <div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span
class="sr-only">关闭</span></button> class="sr-only">关闭</span></button>
<h4 class="modal-title">贴图管理</h4> <h4 class="modal-title">贴图管理</h4>
</div> </div>
<div class="modal-body"> <div class="modal-body">
<div id="textureList"> <div id="textureList">
</div>
</div>
<div class="modal-footer">
<form id="uploadTextureForm" enctype="multipart/form-data">
<input type="file" name="file" id="textureFile" style="display: none" />
</form>
<button class="btn btn-primary" id="textureUpload">上传贴图</button>
<button type="button" class="btn btn-default" data-dismiss="modal" style="margin-left: 10px">确定</button>
</div> </div>
</div> </div>
<div class="modal-footer">
<form id="uploadTextureForm" enctype="multipart/form-data">
<input type="file" name="file" id="textureFile" style="display: none" />
</form>
<button class="btn btn-primary" id="textureUpload">上传贴图</button>
<button type="button" class="btn btn-default" data-dismiss="modal" style="margin-left: 10px">确定</button>
</div>
</div> </div>
</div> </div>
</div>
<!-- 模态框:修改模型名字 --> <!-- 模态框:修改模型名字 -->
<div class="modal fade" id="changeModelNameModal"> <div class="modal fade" id="changeModelNameModal">
<div class="modal-dialog modal-sm"> <div class="modal-dialog modal-sm">
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> <div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span
class="sr-only">关闭</span></button> class="sr-only">关闭</span></button>
<h4 class="modal-title">修改</h4> <h4 class="modal-title">修改</h4>
</div> </div>
<div class="modal-body"> <div class="modal-body">
<div id="textureList"> <div id="textureList">
<input type="text" class="form-control" id="modelName" placeholder="模型名称"> <input type="text" class="form-control" id="modelName" placeholder="模型名称">
</div>
</div>
<div class="modal-footer">
<form id="uploadTextureForm" enctype="multipart/form-data">
<input type="file" name="file" id="textureFile" style="display: none" />
</form>
<button class="btn btn-primary" id="changeModelName">确定修改</button>
<button type="button" class="btn btn-default" data-dismiss="modal" style="margin-left: 10px">取消</button>
</div> </div>
</div> </div>
<div class="modal-footer">
<form id="uploadTextureForm" enctype="multipart/form-data">
<input type="file" name="file" id="textureFile" style="display: none" />
</form>
<button class="btn btn-primary" id="changeModelName">确定修改</button>
<button type="button" class="btn btn-default" data-dismiss="modal" style="margin-left: 10px">取消</button>
</div>
</div> </div>
</div> </div>
<script src="/js/createScheme.js"></script> </div>
<script src="/js/createScheme.js"></script>
</body> </body>
</html> </html>

@ -47,7 +47,7 @@
<a class="dropdown-toggle" data-toggle="dropdown"><b id='name'>xxx</b> <a class="dropdown-toggle" data-toggle="dropdown"><b id='name'>xxx</b>
<b class="caret"></b></a> <b class="caret"></b></a>
<ul class="dropdown-menu" role="menu"> <ul class="dropdown-menu" role="menu">
<li><a href="your/nice/url">用户信息管理</a></li> <li><a href="#">用户信息管理</a></li>
<li class="divider"></li> <li class="divider"></li>
<li><a href="/logout">注销</a></li> <li><a href="/logout">注销</a></li>
</ul> </ul>

Loading…
Cancel
Save