From e159a52afe35e07007ea05687dba9d29b1440f54 Mon Sep 17 00:00:00 2001 From: tonkia Date: Tue, 25 Dec 2018 13:26:49 +0800 Subject: [PATCH] syn --- app.js | 47 +++++++++++----- db.js | 22 +++++++- static/img/webbg.jpg | Bin 19872 -> 4780 bytes static/js/createScheme.js | 42 +++++++++++--- views/createScheme.html | 115 +++++++++++++++++++------------------- views/home.html | 2 +- 6 files changed, 148 insertions(+), 80 deletions(-) diff --git a/app.js b/app.js index 1a3d0d5..0a7c118 100644 --- a/app.js +++ b/app.js @@ -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 { diff --git a/db.js b/db.js index a6a4c5b..112c014 100644 --- a/db.js +++ b/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) { }); } }); -}; \ No newline at end of file +}; + diff --git a/static/img/webbg.jpg b/static/img/webbg.jpg index 51d7e702893ad94ec3c85144408d5119b59f9aba..18d83c063d8fefd00f8f76faf6b77fda03203de8 100644 GIT binary patch literal 4780 zcmb7{c~}$IyT{K=7Lov!KnN0Tjrj=#1cHRP;5I?vCtxsPvk^h05+umthA|=zQCb$c z;=)qd(g?_^tVIz7)L;ccL{vZp1g$_#3p7x)2*0uSpZnbV*L~-C<~(!GdA{?R_q=o7 z_bm1;4g&*sS2tGxK@ixEU10Gg*ak>Mq7IQj($Uc&lSvdkn!cW{uAZr((GuF%j1}K} z%~-yixysgp$+G^}^5yJxmezJ_92^{0SZvt5-hPuU*TMda2t+26^>p=?>gzAHU%7mx z{r}q*TL6^=Wy2S75DUOm2uFn$?}MdZP%+s5VGxYd!A2|$zVze%xnLOgWeP-HxrPsm z_8A_Ex4-aH70ao05}Ro9e-r>Ffep~9|4aFc!r}nX!^B`JjtaJdnU6eZ&%GsfV3QrW zfBebVvaZ~2Ep+l%CjLWe3^{-Pikk_D|D6p~DV7_Obx@_8VilYov?|qmU*b|F*{tb$ zobCn@J|O-A7EGHxV(pA9wD}KY&!=+!;@h`I zKN7)C9T4S~^U^)RWfv;0_{4L|3cpynW3{SoZg@*G!w%t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2% ztkZjVExNPPnRY5ZSn8r?DwJVFu61|Xkzq7$aXvGcb7gv&=;I-w?PiaW{R$1kQ#Bag zmhmOsG(3nY_L-!s-T`Xg-iq$APEP%4=w$Q;tkki8&V&9WNk=ofyO}+MWyzUsSi=)U z)xvM!bW0^koLJ7HUIAJC7Z*DOYRfqoO?B^M 0) { + //获取保存后的id + if (returnData.insertId) + data.id = returnData.insertId; + new $.zui.Messager('保存成功!', { + type: 'success', + close: false, + actions: [{ + icon: 'times', + text: '确定' + }] + }).show(); + } + } }); }); diff --git a/views/createScheme.html b/views/createScheme.html index 0e7d480..59956a9 100644 --- a/views/createScheme.html +++ b/views/createScheme.html @@ -102,76 +102,79 @@ - -