Commit 2014702d authored by wty's avatar wty

更改后端代码

parent 5d3571d1
const express = require('express')
const request = require("request");
const Mysql = require("../SQLPool");
const getMysql = require('../SQLPool')
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) => {
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 (?,?,?,?,?)'
Mysql.query(SQL, [toolbox_name, toolbox_desc, toolbox_icon, toolbox_url, 0], (err, result) => {
if (err) {
res.send({
success: false,
err
Mysql.query(SQL, [toolbox_name, toolbox_desc, toolbox_icon, toolbox_url, 0], (err, result) => {
if (err) {
res.send({
success: false,
err
})
return
}
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(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) => {
console.log(values)
try {
Mysql.query(SQL, values, (err, result) => {
if (err) {
res.send({
success: false,
err
})
return
throw err
}
res.send({
success: true
success: true,
data: result
})
})
})
} 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)
}
})
}).catch(e => console.error(e))
module.exports = router
const express = require('express')
const request = require('request')
const Mysql = require("../SQLPool");
const getMysql = require('../SQLPool')
const router = express.Router()
router.get('/deleteToolBoxById', (req, res) => {
const {toolbox_id} = req.query
const SQL = 'DELETE FROM toolbox WHERE toolbox_id = ?'
try {
Mysql.query(SQL, [toolbox_id], (err, result) => {
if (err) {
getMysql.then(Mysql => {
router.get('/deleteToolBoxById', (req, res) => {
const {toolbox_id} = req.query
const SQL = 'DELETE FROM toolbox WHERE toolbox_id = ?'
try {
Mysql.query(SQL, [toolbox_id], (err, result) => {
if (err) {
res.send({
success: false,
err
})
throw err
}
res.send({
success: false,
err
success: true,
data: result
})
throw err
}
res.send({
success: true,
data: result
})
})
}catch (e){
console.error(e)
}
}catch (e){
console.error(e)
}
})
})
}).catch(e => console.error(e))
module.exports = router
const express = require('express');
const Mysql = require('../SQLPool')
const getMysql = require('../SQLPool')
const fs = require("fs");
const request = require("request");
const path = require("path");
const router = express.Router();
getMysql.then(Mysql => {
router.post('/addPage', (req, res) => {
const {page_name, code} = req.body
router.post('/addPage', (req, res) => {
const {page_name, code} = req.body
const SQL = `INSERT INTO page (page_name) VALUES (?)`
const SQL = `INSERT INTO page (page_name) VALUES (?)`
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)
Mysql.query(SQL, [page_name], (err, result) => {
if (err) {
res.send({
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 => {
const url = 'http://172.16.130.180:3001/static/' + 'page' + v['page_id'] + '.html'
return {
...v,
pageUrl: url
router.get('/queryPage', (req, res) => {
const SQL = 'SELECT * FROM page'
Mysql.query(SQL, [], (err, result) => {
if (err) {
res.send({
success: false,
err
})
}
})
res.send({
success: true,
data: _result
})
})
})
const _result = result.map(v => {
const url = 'http://172.16.130.180:3001/static/' + 'page' + v['page_id'] + '.html'
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({
success: false,
error: err
success: true,
data: _result
})
} else {
try{
const fileName = 'page' + page_id + '.html'
fs.writeFileSync(path.join(__dirname, '../static/' + fileName), code)
res.send({
success: true
})
}catch (e){
})
})
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({
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
const express = require('express')
const request = require("request");
const Mysql = require('../SQLPool')
const getMysql = require('../SQLPool')
const router = express.Router()
router.get('/queryType', (req, res) => {
const SQL = 'SELECT * FROM type'
Mysql.query(SQL, (err, result) => {
if (err) {
getMysql.then(Mysql => {
router.get('/queryType', (req, res) => {
const SQL = 'SELECT * FROM type'
Mysql.query(SQL, (err, result) => {
if (err) {
res.send({
success: false,
err
})
return
}
res.send({
success: false,
err
success: true,
data: result
})
return
}
res.send({
success: true,
data: result
})
})
})
router.get('/queryChildType', (req, res) => {
const SQL = 'SELECT * FROM child_type'
Mysql.query(SQL, (err, result) => {
if (err) {
router.get('/queryChildType', (req, res) => {
const SQL = 'SELECT * FROM child_type'
Mysql.query(SQL, (err, result) => {
if (err) {
res.send({
success: false,
err
})
return
}
res.send({
success: false,
err
success: true,
data: result
})
return
}
res.send({
success: true,
data: result
})
})
})
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'
Mysql.query(SQL, [], (err, result) => {
const dataArr = []
const combineType = (value) => {
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 => ({
child_type_id: v.child_type_id,
child_type_name: v.child_type_name
}))
dataArr.push({
type_id: value.type_id,
type_name: value.type_name,
children: childType
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'
Mysql.query(SQL, [], (err, result) => {
const dataArr = []
const combineType = (value) => {
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 => ({
child_type_id: v.child_type_id,
child_type_name: v.child_type_name
}))
dataArr.push({
type_id: value.type_id,
type_name: value.type_name,
children: childType
})
}
result.forEach(v => {
combineType(v)
})
}
result.forEach(v => {
combineType(v)
})
res.send({
success: true,
data: dataArr
res.send({
success: true,
data: dataArr
})
})
})
})
router.get('/deleteChildType', ((req, res) => {
const {child_type_id} = req.query
router.get('/deleteChildType', ((req, res) => {
const {child_type_id} = req.query
let SQL = 'DELETE FROM child_type WHERE child_type_id = ?;'
let SQL2 = 'DELETE FROM type_childtype_toolbox 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 = ?;'
Mysql.query(SQL, [child_type_id], (err, result) => {
if (err) {
res.send({
success: false,
err
Mysql.query(SQL, [child_type_id], (err, result) => {
if (err) {
res.send({
success: false,
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({
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
const express = require('express')
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) => {
if (err) {
getMysql.then(Mysql => {
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({
success: false,
err
success: true,
data: result
})
}
res.send({
success: true,
data: result
})
})
})
// router.get('/updateToolBoxSort',(req, res) => {
// const {sortArr} = req.query
......@@ -28,5 +30,7 @@ router.get('/updateToolBox', (req, res) => {
// data: sortArr
// })
// })
}).catch(e => console.error(e))
module.exports = router
......@@ -10,17 +10,18 @@ getMysql.then(Mysql => {
/* GET users listing. */
router.get('/getUser', function (req, res, next) {
let {uid} = req.cookies
if (!uid){
uid = req.query.uid
}
// if (!uid) {
// res.send({
// success: false,
// code: ErrorCode.USER_NOT_LOGIN,
// data: '用户尚未登录'
// })
// return
console.info(req.cookies)
// if (!uid){
// uid = req.query.uid
// }
if (!uid) {
res.send({
success: false,
code: ErrorCode.USER_NOT_LOGIN,
data: '用户尚未登录'
})
return
}
const SQL = 'SELECT * FROM `user` WHERE `user`.uid = ?'
Mysql.query(SQL, [uid], (err, result) => {
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