Commit 2b43a4a9 authored by wty's avatar wty

上线前准备

parent 82b30992
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
"morgan": "~1.9.1", "morgan": "~1.9.1",
"mysql": "^2.18.1", "mysql": "^2.18.1",
"nodemon": "^2.0.12", "nodemon": "^2.0.12",
"pm2": "^5.1.2",
"request": "^2.88.2" "request": "^2.88.2"
} }
} }
...@@ -5,25 +5,34 @@ const router = express.Router() ...@@ -5,25 +5,34 @@ const router = express.Router()
router.get('/addToolBox', (req, res) => { router.get('/addToolBox', (req, res) => {
const {toolBoxName, toolBoxIcon, toolBoxDesc, toolBoxUrl, typeId, childTypeId} = req.query const {toolBoxName, toolBoxIcon, toolBoxDesc, toolBoxUrl, typeId, childTypeId} = req.query
// res.send({success: true}) const SQL = 'INSERT INTO toolbox (toolBoxName, toolBoxIcon, toolBoxDesc, toolBoxUrl,sortId) VALUES (?,?,?,?,?)'
const SQL = 'INSERT INTO toolbox (toolBoxName, toolBoxIcon, toolBoxDesc, toolBoxUrl, sortId) VALUES (?,?,?,?)'
const typeSQL = `INSERT INTO toolbox_type (typeId,toolBoxId) VALUES (?,?)` Mysql.query(SQL, [toolBoxName, toolBoxDesc, toolBoxIcon, toolBoxUrl, 0], (err, result) => {
try {
Mysql.query(SQL, [toolBoxName, toolBoxDesc, toolBoxIcon, toolBoxUrl], (err, result) => {
if (err) { if (err) {
res.send({ res.send({
success: false, success: false,
err err
}) })
return
} }
request(domain + '/query/queryToolBox', {}, (a, b, body) => {
const data = JSON.parse(body).data
const lastToolBoxId = data[data.length - 1].toolBoxId
const SQL = 'INSERT INTO type_childtype_toolbox (toolBoxId,typeId,childTypeId) VALUES (?,?,?)'
Mysql.query(SQL, [lastToolBoxId,typeId,childTypeId], (err, result) => {
if (err) {
res.send({ res.send({
success: true, success: false,
data: result err
})
}) })
} catch (e) { return
console.error(e)
} }
res.send({
success: true
})
})
})
})
}) })
router.get('/addType', (req, res) => { router.get('/addType', (req, res) => {
......
...@@ -40,6 +40,9 @@ router.get('/queryChildType', (req, res) => { ...@@ -40,6 +40,9 @@ router.get('/queryChildType', (req, res) => {
router.get('/queryToolBox', (req, res) => { router.get('/queryToolBox', (req, res) => {
let {isFollow, typeId} = req.query let {isFollow, typeId} = req.query
let SQL = `SELECT toolbox.*, type_childtype_toolbox.childTypeId FROM type_childtype_toolbox INNER JOIN toolbox ON type_childtype_toolbox.toolBoxId = toolbox.toolBoxId WHERE type_childtype_toolbox.typeId = ?` let SQL = `SELECT toolbox.*, type_childtype_toolbox.childTypeId FROM type_childtype_toolbox INNER JOIN toolbox ON type_childtype_toolbox.toolBoxId = toolbox.toolBoxId WHERE type_childtype_toolbox.typeId = ?`
if (!isFollow && !typeId){
SQL = `SELECT * FROM toolBox`
}
if (isFollow) { if (isFollow) {
typeId = JSON.parse(typeId) typeId = JSON.parse(typeId)
SQL = 'SELECT * FROM toolbox WHERE toolboxId IN (?)' SQL = 'SELECT * FROM toolbox WHERE toolboxId IN (?)'
...@@ -52,11 +55,10 @@ router.get('/queryToolBox', (req, res) => { ...@@ -52,11 +55,10 @@ router.get('/queryToolBox', (req, res) => {
}) })
throw err throw err
} }
const _result = result.slice()
res.send({ res.send({
success: true, success: true,
data: _result.sort((a, b) => a.sortId - b.sortId) data: result
}) })
}) })
}); });
......
...@@ -40,23 +40,23 @@ router.get('/queryChildType', (req, res) => { ...@@ -40,23 +40,23 @@ router.get('/queryChildType', (req, res) => {
router.get('/queryTypeForManage', (req, res) => { router.get('/queryTypeForManage', (req, res) => {
const SQL = 'SELECT child_type.childTypeId, child_type.childTypeName, child_type.typeId, type.typeName FROM child_type INNER JOIN type ON child_type.typeId = type.typeId' const SQL = 'SELECT child_type.childTypeId, child_type.childTypeName, child_type.typeId, type.typeName FROM child_type INNER JOIN type ON child_type.typeId = type.typeId'
Mysql.query(SQL, [], (err, result) => { Mysql.query(SQL, [], (err, result) => {
console.log(result)
const dataArr = [] const dataArr = []
const combineType = (typeId) => { const combineType = (value) => {
if (dataArr.filter(v => v.typeId === typeId).length) return if (dataArr.filter(v => v.typeId === value.typeId).length) return
const childType = result.filter(v => v.typeId === 2).map(v => ({ const childType = result.filter(v => v.typeId === value.typeId).map(v => ({
childTypeId: v.childTypeId, childTypeId: v.childTypeId,
childTypeName: v.childTypeName childTypeName: v.childTypeName
})) }))
dataArr.push({ dataArr.push({
typeId: result[0].typeId, typeId: value.typeId,
typeName: result[0].typeName, typeName: value.typeName,
children: childType children: childType
}) })
} }
result.forEach(v => { result.forEach(v => {
combineType(v.typeId) combineType(v)
}) })
res.send({ res.send({
success: true, success: true,
data: dataArr data: dataArr
...@@ -64,4 +64,51 @@ router.get('/queryTypeForManage', (req, res) => { ...@@ -64,4 +64,51 @@ router.get('/queryTypeForManage', (req, res) => {
}) })
}) })
router.get('/deleteChildType', ((req, res) => {
const {childTypeId} = req.query
let SQL = 'DELETE FROM child_type WHERE childTypeId = ?;\n' +
'DELETE FROM type_childtype_toolbox WHERE childTypeId = ?;'
Mysql.query(SQL, [childTypeId, childTypeId], (err, result) => {
if (err) {
res.send({
success: false,
err
})
return
}
res.send({
success: true,
})
})
}))
router.get('/updateType', (req, res) => {
const {typeId, typeName, childTypeId, childTypeName} = req.query
let SQL
const values = []
if (typeId) {
SQL = 'UPDATE type SET typeName = ? WHERE typeId = ?'
values.push(typeName)
values.push(typeId)
} else {
SQL = 'UPDATE child_type SET childTypeName = ? WHERE childTypeId = ?'
values.push(childTypeName)
values.push(childTypeId)
}
Mysql.query(SQL, values, (err, result) => {
if (err) {
res.send({
success: false,
err
})
return
}
res.send({
success: true,
})
})
})
module.exports = router module.exports = router
...@@ -10,8 +10,6 @@ const ErrorCode = { ...@@ -10,8 +10,6 @@ const ErrorCode = {
/* GET users listing. */ /* GET users listing. */
router.get('/getUser', function (req, res, next) { router.get('/getUser', function (req, res, next) {
let {userId} = req.cookies let {userId} = req.cookies
console.log(req.cookies)
console.log('userId:',userId)
if (!userId){ if (!userId){
userId = req.query.userId userId = req.query.userId
} }
...@@ -30,11 +28,13 @@ router.get('/getUser', function (req, res, next) { ...@@ -30,11 +28,13 @@ router.get('/getUser', function (req, res, next) {
success: false, success: false,
err err
}) })
throw err return
} }
const _result = result.slice() const _result = result.slice()
_result[0].follow = JSON.parse(_result[0].follow) _result[0].follow = JSON.parse(_result[0].follow)
// console.log(JSON.parse(_result[0]))
res.send({ res.send({
success: true, success: true,
...@@ -80,12 +80,11 @@ router.get('/follow', (req, res) => { ...@@ -80,12 +80,11 @@ router.get('/follow', (req, res) => {
success: false, success: false,
err err
}) })
throw err return
} }
res.send({ res.send({
success: true, success: true,
}) })
}) })
}) })
......
This diff is collapsed.
...@@ -20,8 +20,9 @@ function ContentItem(props) { ...@@ -20,8 +20,9 @@ function ContentItem(props) {
const index = _follow.indexOf(toolBoxId) const index = _follow.indexOf(toolBoxId)
_follow.splice(index, 1) _follow.splice(index, 1)
} }
console.log( {follow: JSON.stringify(_follow), userId: dataCenter.userInfo.uid})
fetchData('/users/follow', {follow: JSON.stringify(_follow), userId: dataCenter.userInfo.uid}) fetchData('/users/follow', {follow: JSON.stringify(_follow), userId: dataCenter.userInfo.uid})
.then(() => fetchData('/users/getUser', {}, 'userInfo')) .then(() => fetchData('/users/getUser', {userId: 100001}, 'userInfo'))
} }
useEffect(() => { useEffect(() => {
......
...@@ -4,7 +4,7 @@ const initDataCenter = { ...@@ -4,7 +4,7 @@ const initDataCenter = {
childType: null, childType: null,
userInfo: null, userInfo: null,
needUpdateIndex: false, needUpdateIndex: false,
typeId: 2, typeId: 'follow',
childTypeId: 'all' childTypeId: 'all'
} }
...@@ -34,7 +34,8 @@ function deepFreeze(obj) { ...@@ -34,7 +34,8 @@ function deepFreeze(obj) {
deepFreeze(initDataCenter) deepFreeze(initDataCenter)
const dataReducer = (state, action) => { const dataReducer = (state, action) => {
console.log(action) // console.log(action)
console.table(action,['dataCenter的dispatch'])
switch (action.type) { switch (action.type) {
case 'UPDATE_DATA': case 'UPDATE_DATA':
return Object.assign({}, state, { return Object.assign({}, state, {
......
...@@ -2,29 +2,23 @@ import logo from "../../static/logo.png"; ...@@ -2,29 +2,23 @@ import logo from "../../static/logo.png";
import './index.scss' import './index.scss'
import ToolType from "../../component/ToolType/ToolType"; import ToolType from "../../component/ToolType/ToolType";
import Content from "../../component/Content/Content"; import Content from "../../component/Content/Content";
import {PopContext, Root} from "../../dataCenter/Root"; import {Root} from "../../dataCenter/Root";
import {useContext, useEffect, useState} from "react"; import {useContext, useEffect} from "react";
import {NEED_UPDATE_INDEX} from "../../dataCenter/action"; import {NEED_UPDATE_INDEX} from "../../dataCenter/action";
function Index() { function Index() {
const [pop, setPop] = useState()
const {fetchData, dataCenter, dispatch} = useContext(Root) const {fetchData, dataCenter, dispatch} = useContext(Root)
const showPop = popComponent => {
setPop(popComponent)
}
const getUser = () => { const getUser = () => {
fetchData('/users/getUser', {userId: '100001'}, 'userInfo') fetchData('/users/getUser', {userId: '100001'}, 'userInfo')
.catch(res => .catch(res =>
res.code === 70001 && (window.location.href = '/login') res.code === 70001 && (window.location.href = '/login')
) )
} }
useEffect(() => { useEffect(() => {
fetchData('/query/queryType', {}, 'type') fetchData('/query/queryType', {}, 'type')
.then(()=> fetchData('/query/queryChildType',{typeId: dataCenter.typeId},'childType')) .then(() => fetchData('/query/queryChildType', {typeId: dataCenter.typeId}, 'childType'))
.then(() => dispatch(NEED_UPDATE_INDEX())) .then(() => dispatch(NEED_UPDATE_INDEX()))
}, [dataCenter.typeId]) }, [dataCenter.typeId])
useEffect(() => { useEffect(() => {
if (dataCenter.needUpdateIndex) { if (dataCenter.needUpdateIndex) {
const _typeId = dataCenter.typeId === 'follow' ? { const _typeId = dataCenter.typeId === 'follow' ? {
...@@ -40,7 +34,7 @@ function Index() { ...@@ -40,7 +34,7 @@ function Index() {
}, []) }, [])
return ( return (
<PopContext.Provider value={{hidePop: () => setPop(''), showPop: popName => showPop(popName)}}>
<div className="index"> <div className="index">
<div className="welcome-top"> <div className="welcome-top">
<span>欢迎您! <span>欢迎您!
...@@ -63,16 +57,12 @@ function Index() { ...@@ -63,16 +57,12 @@ function Index() {
<div className="container"> <div className="container">
<Content/> <Content/>
</div> </div>
{
pop
}
<div className="index-footer"> <div className="index-footer">
兑吧研发中心·杭州兑吧网络科技游戏公司版权所有 兑吧研发中心·杭州兑吧网络科技游戏公司版权所有
<br/> <br/>
浙ICP备14017299号-1 浙ICP备14017299号-1
</div> </div>
</div> </div>
</PopContext.Provider>
) )
} }
......
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