tonkia 6 years ago
parent 60f57996db
commit e159a52afe
  1. 41
      app.js
  2. 20
      db.js
  3. BIN
      static/img/webbg.jpg
  4. 42
      static/js/createScheme.js
  5. 3
      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) {
//如果有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 {

20
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) {
@ -86,3 +105,4 @@ 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,6 +102,9 @@
<button class="btn btn-success btn-block" id="saveScheme">保存方案</button>
</div>
</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">

@ -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