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'];
res.sendFile(__dirname + "/uploads/" + fileType + "/" + fileName);
});
//------------------------------------------------------------------------------------------------
//保存方案
app.post('/saveScheme', function (req, res) {
var data = req.body;
var id = data.id;
var img = data.img;
delete data.img;
db.insertScheme(req.session.user.id, data.name, JSON.stringify(data), img, function (res) {
//console.info(res);
if (res.affectedRows > 0) {
} else {
//如果有id存在就update
if (id) {
db.updateScheme(req.session.user.id, id, data.name, JSON.stringify(data), img, function (row) {
if (row.affectedRows > 0) {
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);
});
//获取方案
//------------------------------------------------------------------------------------------------
//获取初始方案
app.post('/getScheme', function (req, res) {
var data = { name: '默认方案', components: [], img: null };
var data = { name: '默认方案', components: [], img: null, id: null };
res.send(data);
});
//根据局ID获取初始方案
app.post('/getScheme/:id', function (req, res) {
var id = req.params['id'];
var user = req.session.user;
// console.info(user.id + ":" + id);
if (id) {
db.getSchemeById(user.id, id, function (row) {
if (row.length > 0) {
// console.info(row[0].data);
var data = JSON.parse(row[0].data);
data.id = id;
res.send(data);
} else {
//找不到方案
//TODO 找不到方案
}
})
} 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) {
connection.getConnection(function (err, conn) {
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 totalFinish = 0;
//相机参数
var height = 2;
var distance = 10;
var angel = 0;
//整个页面维护的数据
//var data = { name: '默认方案', components: [] };
//TODO 相机参数
@ -208,15 +213,16 @@ function initScene() {
}
function initCamera() {
//相机设置
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
controls = new THREE.OrbitControls(camera, $('#viewField')[0]);
controls.target.set(0, 0, 0);
controls.update();
// controls = new THREE.OrbitControls(camera, $('#viewField')[0]);
// controls.target.set(0, 0, 0);
// controls.update();
}
function initRenderer() {
@ -314,7 +320,10 @@ function initTexture() {
//初始化所有事件
function initEvent() {
$('#saveScheme').click(function () {
var saveData = data;
//复制一个saveData
var saveData = {};
$.extend(saveData, data);
//去除aveData中多余的数据
for (var index in saveData.components) {
for (textureIndex in saveData.components[index].textures) {
delete saveData.components[index].textures[textureIndex].textureObj;
@ -323,15 +332,32 @@ function initEvent() {
delete saveData.components[index].models[modelIndex].modelObj;
}
}
//生成缩略图
var image = new Image();
let imgData = renderer.domElement.toDataURL("image/jpeg");//这里可以选择png格式jpeg格式
saveData.img = imgData;
console.info(saveData);
//上传服务器
$.ajax({
type: "POST",
url: "/saveScheme",
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>
</div>
</div>
<!-- 模态框:添加组件 -->
<div class="modal fade" id="addComponentModal">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span
class="sr-only">关闭</span></button>
<h4 class="modal-title">添加新组件</h4>
</div>
<div class="modal-body">
<input type="text" class="form-control" id="componentName" placeholder="组件名称">
</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 class='pull-right' style='margin-right: 10px'><a href='/home'>返回主页</a></div>
</div>
<!-- 模态框:添加组件 -->
<div class="modal fade" id="addComponentModal">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span
class="sr-only">关闭</span></button>
<h4 class="modal-title">添加新组件</h4>
</div>
<div class="modal-body">
<input type="text" class="form-control" id="componentName" placeholder="组件名称">
</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 class="modal fade" id="textureManagermentModal">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span
class="sr-only">关闭</span></button>
<h4 class="modal-title">贴图管理</h4>
</div>
<div class="modal-body">
<div id="textureList">
<!-- 模态框:材质管理 -->
<div class="modal fade" id="textureManagermentModal">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span
class="sr-only">关闭</span></button>
<h4 class="modal-title">贴图管理</h4>
</div>
<div class="modal-body">
<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 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 fade" id="changeModelNameModal">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span
class="sr-only">关闭</span></button>
<h4 class="modal-title">修改</h4>
</div>
<div class="modal-body">
<div id="textureList">
<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 class="modal fade" id="changeModelNameModal">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span
class="sr-only">关闭</span></button>
<h4 class="modal-title">修改</h4>
</div>
<div class="modal-body">
<div id="textureList">
<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>
<script src="/js/createScheme.js"></script>
</div>
<script src="/js/createScheme.js"></script>
</body>
</html>

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

Loading…
Cancel
Save