Commit 2014702d authored by wty's avatar wty

更改后端代码

parent 5d3571d1
const express = require('express') const express = require('express')
const request = require("request"); const request = require("request");
const Mysql = require("../SQLPool"); const getMysql = require('../SQLPool')
const router = express.Router() const router = express.Router()
getMysql.then(Mysql => {
router.get('/addToolBox', (req, res) => {
const {toolbox_name, toolbox_icon, toolbox_desc, toolbox_url, type_id, child_type_id} = req.query
const SQL = 'INSERT INTO toolbox (toolbox_name, toolbox_icon, toolbox_desc, toolbox_url,sort_id) VALUES (?,?,?,?,?)'
router.get('/addToolBox', (req, res) => { Mysql.query(SQL, [toolbox_name, toolbox_desc, toolbox_icon, toolbox_url, 0], (err, result) => {
const {toolbox_name, toolbox_icon, toolbox_desc, toolbox_url, type_id, child_type_id} = req.query if (err) {
const SQL = 'INSERT INTO toolbox (toolbox_name, toolbox_icon, toolbox_desc, toolbox_url,sort_id) VALUES (?,?,?,?,?)' res.send({
success: false,
Mysql.query(SQL, [toolbox_name, toolbox_desc, toolbox_icon, toolbox_url, 0], (err, result) => { err
if (err) { })
res.send({ return
success: false, }
err request(domain + '/query/queryToolBox', {}, (error, response, body) => {
console.log(domain + '/query/queryToolBox')
console.log('body:',body)
const data = JSON.parse(body).data
const lastToolBoxId = data[data.length - 1].toolbox_id
const SQL = 'INSERT INTO type_childtype_toolbox (toolbox_id,type_id,child_type_id) VALUES (?,?,?)'
Mysql.query(SQL, [lastToolBoxId,type_id,child_type_id], (err, result) => {
if (err) {
res.send({
success: false,
err
})
return
}
res.send({
success: true
})
})
}) })
return })
})
router.get('/addType', (req, res) => {
const {type_name, child_type_name, type_id} = req.query
console.log(req.query)
let SQL = 'INSERT INTO type (type_name) VALUES (?)'
const values = []
if (child_type_name && type_id) {
SQL = 'INSERT INTO child_type (child_type_name, type_id) VALUES (?,?)'
values.push(child_type_name)
values.push(type_id)
} else {
values.push(type_name)
} }
request(domain + '/query/queryToolBox', {}, (error, response, body) => { console.log(values)
console.log(domain + '/query/queryToolBox') try {
console.log('body:',body) Mysql.query(SQL, values, (err, result) => {
const data = JSON.parse(body).data
const lastToolBoxId = data[data.length - 1].toolbox_id
const SQL = 'INSERT INTO type_childtype_toolbox (toolbox_id,type_id,child_type_id) VALUES (?,?,?)'
Mysql.query(SQL, [lastToolBoxId,type_id,child_type_id], (err, result) => {
if (err) { if (err) {
res.send({ res.send({
success: false, success: false,
err err
}) })
return throw err
} }
res.send({ res.send({
success: true success: true,
data: result
}) })
}) })
}) } catch (e) {
console.error(e)
}
}) })
}) }).catch(e => console.error(e))
router.get('/addType', (req, res) => {
const {type_name, child_type_name, type_id} = req.query
console.log(req.query)
let SQL = 'INSERT INTO type (type_name) VALUES (?)'
const values = []
if (child_type_name && type_id) {
SQL = 'INSERT INTO child_type (child_type_name, type_id) VALUES (?,?)'
values.push(child_type_name)
values.push(type_id)
} else {
values.push(type_name)
}
console.log(values)
try {
Mysql.query(SQL, values, (err, result) => {
if (err) {
res.send({
success: false,
err
})
throw err
}
res.send({
success: true,
data: result
})
})
} catch (e) {
console.error(e)
}
})
module.exports = router module.exports = router
const express = require('express') const express = require('express')
const request = require('request') const request = require('request')
const Mysql = require("../SQLPool"); const getMysql = require('../SQLPool')
const router = express.Router() const router = express.Router()
router.get('/deleteToolBoxById', (req, res) => { getMysql.then(Mysql => {
const {toolbox_id} = req.query router.get('/deleteToolBoxById', (req, res) => {
const SQL = 'DELETE FROM toolbox WHERE toolbox_id = ?' const {toolbox_id} = req.query
try { const SQL = 'DELETE FROM toolbox WHERE toolbox_id = ?'
Mysql.query(SQL, [toolbox_id], (err, result) => { try {
if (err) { Mysql.query(SQL, [toolbox_id], (err, result) => {
if (err) {
res.send({
success: false,
err
})
throw err
}
res.send({ res.send({
success: false, success: true,
err data: result
}) })
throw err
}
res.send({
success: true,
data: result
}) })
}) }catch (e){
}catch (e){ console.error(e)
console.error(e) }
}
}) })
}).catch(e => console.error(e))
module.exports = router module.exports = router
const express = require('express'); const express = require('express');
const Mysql = require('../SQLPool') const getMysql = require('../SQLPool')
const fs = require("fs"); const fs = require("fs");
const request = require("request"); const request = require("request");
const path = require("path"); const path = require("path");
const router = express.Router(); const router = express.Router();
getMysql.then(Mysql => {
router.post('/addPage', (req, res) => {
const {page_name, code} = req.body
router.post('/addPage', (req, res) => { const SQL = `INSERT INTO page (page_name) VALUES (?)`
const {page_name, code} = req.body
const SQL = `INSERT INTO page (page_name) VALUES (?)` Mysql.query(SQL, [page_name], (err, result) => {
if (err) {
Mysql.query(SQL, [page_name], (err, result) => {
if (err) {
res.send({
success: false,
error: err
})
} else {
const a = [{
typeId: 1,
}]
try {
request(domain + '/page/queryPage', {}, (a, b, body) => {
const data = JSON.parse(body).data
const id = data[data.length - 1]['page_id']
const fileName = 'page' + id + '.html'
try {
console.log('path:', path.join(__dirname, '../static/' + fileName))
fs.writeFileSync(path.join(__dirname, '../static/' + fileName), code)
res.send({
success: true
})
} catch (e) {
res.send({
success: false,
error: e
})
console.error(e)
}
})
} catch (e) {
console.error(e)
res.send({ res.send({
success: false, success: false,
error: e error: err
}) })
} else {
const a = [{
typeId: 1,
}]
try {
request(domain + '/page/queryPage', {}, (a, b, body) => {
const data = JSON.parse(body).data
const id = data[data.length - 1]['page_id']
const fileName = 'page' + id + '.html'
try {
console.log('path:', path.join(__dirname, '../static/' + fileName))
fs.writeFileSync(path.join(__dirname, '../static/' + fileName), code)
res.send({
success: true
})
} catch (e) {
res.send({
success: false,
error: e
})
console.error(e)
}
})
} catch (e) {
console.error(e)
res.send({
success: false,
error: e
})
}
} }
} })
}) })
})
router.get('/queryPage', (req, res) => {
const SQL = 'SELECT * FROM page'
Mysql.query(SQL, [], (err, result) => {
if (err) {
res.send({
success: false,
err
})
}
const _result = result.map(v => { router.get('/queryPage', (req, res) => {
const url = 'http://172.16.130.180:3001/static/' + 'page' + v['page_id'] + '.html' const SQL = 'SELECT * FROM page'
return { Mysql.query(SQL, [], (err, result) => {
...v, if (err) {
pageUrl: url res.send({
success: false,
err
})
} }
})
res.send({ const _result = result.map(v => {
success: true, const url = 'http://172.16.130.180:3001/static/' + 'page' + v['page_id'] + '.html'
data: _result return {
}) ...v,
}) pageUrl: url
}) }
})
router.post('/updatePage', (req, res) => {
const {page_id, page_name, code} = req.body
const SQL = 'UPDATE page SET page_name=? WHERE page_id = ?'
Mysql.query(SQL, [page_name, page_id], (err, result) => {
if (err) {
res.send({ res.send({
success: false, success: true,
error: err data: _result
}) })
} else { })
try{ })
const fileName = 'page' + page_id + '.html'
fs.writeFileSync(path.join(__dirname, '../static/' + fileName), code) router.post('/updatePage', (req, res) => {
res.send({ const {page_id, page_name, code} = req.body
success: true const SQL = 'UPDATE page SET page_name=? WHERE page_id = ?'
}) Mysql.query(SQL, [page_name, page_id], (err, result) => {
}catch (e){ if (err) {
res.send({ res.send({
success: false, success: false,
error: e error: err
}) })
} } else {
try{
const fileName = 'page' + page_id + '.html'
fs.writeFileSync(path.join(__dirname, '../static/' + fileName), code)
res.send({
success: true
})
}catch (e){
res.send({
success: false,
error: e
})
}
} }
})
}) })
}) }).catch(e => console.error(e))
module.exports = router module.exports = router
const express = require('express') const express = require('express')
const request = require("request"); const request = require("request");
const Mysql = require('../SQLPool') const getMysql = require('../SQLPool')
const router = express.Router() const router = express.Router()
getMysql.then(Mysql => {
router.get('/queryType', (req, res) => { router.get('/queryType', (req, res) => {
const SQL = 'SELECT * FROM type' const SQL = 'SELECT * FROM type'
Mysql.query(SQL, (err, result) => { Mysql.query(SQL, (err, result) => {
if (err) { if (err) {
res.send({
success: false,
err
})
return
}
res.send({ res.send({
success: false, success: true,
err data: result
}) })
return
}
res.send({
success: true,
data: result
}) })
}) })
})
router.get('/queryChildType', (req, res) => { router.get('/queryChildType', (req, res) => {
const SQL = 'SELECT * FROM child_type' const SQL = 'SELECT * FROM child_type'
Mysql.query(SQL, (err, result) => { Mysql.query(SQL, (err, result) => {
if (err) { if (err) {
res.send({
success: false,
err
})
return
}
res.send({ res.send({
success: false, success: true,
err data: result
}) })
return
}
res.send({
success: true,
data: result
}) })
}) })
})
router.get('/queryTypeForManage', (req, res) => { router.get('/queryTypeForManage', (req, res) => {
const SQL = 'SELECT child_type.child_type_id, child_type.child_type_name, child_type.type_id, type.type_name FROM child_type INNER JOIN type ON child_type.type_id = type.type_id' const SQL = 'SELECT child_type.child_type_id, child_type.child_type_name, child_type.type_id, type.type_name FROM child_type INNER JOIN type ON child_type.type_id = type.type_id'
Mysql.query(SQL, [], (err, result) => { Mysql.query(SQL, [], (err, result) => {
const dataArr = [] const dataArr = []
const combineType = (value) => { const combineType = (value) => {
if (dataArr.filter(v => v.type_id === value.type_id).length) return if (dataArr.filter(v => v.type_id === value.type_id).length) return
const childType = result.filter(v => v.type_id === value.type_id).map(v => ({ const childType = result.filter(v => v.type_id === value.type_id).map(v => ({
child_type_id: v.child_type_id, child_type_id: v.child_type_id,
child_type_name: v.child_type_name child_type_name: v.child_type_name
})) }))
dataArr.push({ dataArr.push({
type_id: value.type_id, type_id: value.type_id,
type_name: value.type_name, type_name: value.type_name,
children: childType children: childType
})
}
result.forEach(v => {
combineType(v)
}) })
}
result.forEach(v => {
combineType(v)
})
res.send({ res.send({
success: true, success: true,
data: dataArr data: dataArr
})
}) })
}) })
})
router.get('/deleteChildType', ((req, res) => { router.get('/deleteChildType', ((req, res) => {
const {child_type_id} = req.query const {child_type_id} = req.query
let SQL = 'DELETE FROM child_type WHERE child_type_id = ?;' let SQL = 'DELETE FROM child_type WHERE child_type_id = ?;'
let SQL2 = 'DELETE FROM type_childtype_toolbox WHERE child_type_id = ?;' let SQL2 = 'DELETE FROM type_childtype_toolbox WHERE child_type_id = ?;'
Mysql.query(SQL, [child_type_id], (err, result) => { Mysql.query(SQL, [child_type_id], (err, result) => {
if (err) { if (err) {
res.send({ res.send({
success: false, success: false,
err err
})
return
}
Mysql.query(SQL2, [child_type_id], (err, result) => {
res.send({
success: true,
})
}) })
return
})
}))
router.get('/updateType', (req, res) => {
const {type_id, type_name, child_type_id, child_type_name} = req.query
let SQL
const values = []
if (type_id) {
SQL = 'UPDATE type SET type_name = ? WHERE type_id = ?'
values.push(type_name)
values.push(type_id)
} else {
SQL = 'UPDATE child_type SET child_type_name = ? WHERE child_type_id = ?'
values.push(child_type_name)
values.push(child_type_id)
} }
Mysql.query(SQL2, [child_type_id], (err, result) => { Mysql.query(SQL, values, (err, result) => {
if (err) {
res.send({
success: false,
err
})
return
}
res.send({ res.send({
success: true, success: true,
}) })
}) })
}) })
})) }).catch(e => console.error(e))
router.get('/updateType', (req, res) => {
const {type_id, type_name, child_type_id, child_type_name} = req.query
let SQL
const values = []
if (type_id) {
SQL = 'UPDATE type SET type_name = ? WHERE type_id = ?'
values.push(type_name)
values.push(type_id)
} else {
SQL = 'UPDATE child_type SET child_type_name = ? WHERE child_type_id = ?'
values.push(child_type_name)
values.push(child_type_id)
}
Mysql.query(SQL, values, (err, result) => {
if (err) {
res.send({
success: false,
err
})
return
}
res.send({
success: true,
})
})
})
module.exports = router module.exports = router
const express = require('express') const express = require('express')
const router = express.Router() const router = express.Router()
const Mysql = require('../SQLPool') const getMysql = require('../SQLPool')
router.get('/updateToolBox', (req, res) => {
const {toolbox_name, toolbox_icon, toolbox_url, toolbox_desc, toolbox_id} = req.query
const SQL = 'UPDATE toolbox SET toolbox_name= ?, toolbox_icon=?, toolbox_url=?, toolbox_desc=? WHERE toolbox_id = ?'
Mysql.query(SQL, [toolbox_name, toolbox_icon, toolbox_url, toolbox_desc, toolbox_id], (err, result) => { getMysql.then(Mysql => {
if (err) { router.get('/updateToolBox', (req, res) => {
const {toolbox_name, toolbox_icon, toolbox_url, toolbox_desc, toolbox_id} = req.query
const SQL = 'UPDATE toolbox SET toolbox_name= ?, toolbox_icon=?, toolbox_url=?, toolbox_desc=? WHERE toolbox_id = ?'
Mysql.query(SQL, [toolbox_name, toolbox_icon, toolbox_url, toolbox_desc, toolbox_id], (err, result) => {
if (err) {
res.send({
success: false,
err
})
}
res.send({ res.send({
success: false, success: true,
err data: result
}) })
}
res.send({
success: true,
data: result
}) })
}) })
})
// router.get('/updateToolBoxSort',(req, res) => { // router.get('/updateToolBoxSort',(req, res) => {
// const {sortArr} = req.query // const {sortArr} = req.query
...@@ -28,5 +30,7 @@ router.get('/updateToolBox', (req, res) => { ...@@ -28,5 +30,7 @@ router.get('/updateToolBox', (req, res) => {
// data: sortArr // data: sortArr
// }) // })
// }) // })
}).catch(e => console.error(e))
module.exports = router module.exports = router
...@@ -10,17 +10,18 @@ getMysql.then(Mysql => { ...@@ -10,17 +10,18 @@ getMysql.then(Mysql => {
/* GET users listing. */ /* GET users listing. */
router.get('/getUser', function (req, res, next) { router.get('/getUser', function (req, res, next) {
let {uid} = req.cookies let {uid} = req.cookies
if (!uid){ console.info(req.cookies)
uid = req.query.uid // if (!uid){
} // uid = req.query.uid
// if (!uid) {
// res.send({
// success: false,
// code: ErrorCode.USER_NOT_LOGIN,
// data: '用户尚未登录'
// })
// return
// } // }
if (!uid) {
res.send({
success: false,
code: ErrorCode.USER_NOT_LOGIN,
data: '用户尚未登录'
})
return
}
const SQL = 'SELECT * FROM `user` WHERE `user`.uid = ?' const SQL = 'SELECT * FROM `user` WHERE `user`.uid = ?'
Mysql.query(SQL, [uid], (err, result) => { Mysql.query(SQL, [uid], (err, result) => {
if (err || !result || !result.length) { if (err || !result || !result.length) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment