Commit 2b43a4a9 authored by wty's avatar wty

上线前准备

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