Commit f04f2a92 authored by wty's avatar wty

新增子类

parent abe5826f
# node
# Version v10.8
FROM harbor.dui88.com/library/node10:cat
LABEL MAINTAINER op@duiba.com.cn
ARG appname
ARG NODE_ENV
RUN echo "export LANG=en_US.UTF-8" && echo "Asia/Shanghai" > /etc/timezone
# RUN npm install pm2 -g --register=https://registry.npm.taobao.org/
ENV LANG='en_US.UTF-8'
RUN mkdir /root/duiba-deploy/
ADD ./duiba-deploy /root/duiba-deploy/
WORKDIR /root/duiba-deploy/
#define entry point which will be run first when the container starts up
ENTRYPOINT yarn start
...@@ -10,7 +10,8 @@ const queryRouter = require('./routes/query') ...@@ -10,7 +10,8 @@ const queryRouter = require('./routes/query')
const addRouter = require('./routes/add') const addRouter = require('./routes/add')
const deleteRouter = require('./routes/delete') const deleteRouter = require('./routes/delete')
const updateRouter = require('./routes/update') const updateRouter = require('./routes/update')
const submitRouter = require('./routes/submit') const submitRouter = require('./routes/page')
const typeManage = require('./routes/typeManage')
const app = express(); const app = express();
global.domain = 'http://127.0.0.1:3001' global.domain = 'http://127.0.0.1:3001'
...@@ -25,14 +26,21 @@ global.domain = 'http://127.0.0.1:3001' ...@@ -25,14 +26,21 @@ global.domain = 'http://127.0.0.1:3001'
// }); // });
app.use((req, res, next) => { app.use((req, res, next) => {
//设置请求头 const url = req.url
res.set({
const header = {
'Access-Control-Allow-Credentials': true, 'Access-Control-Allow-Credentials': true,
'Access-Control-Allow-Origin': req.headers.origin || '*', 'Access-Control-Allow-Origin': req.headers.origin || '*',
'Access-Control-Allow-Headers': 'X-Requested-With,Content-Type', 'Access-Control-Allow-Headers': 'X-Requested-With,Content-Type',
'Access-Control-Allow-Methods': 'PUT,POST,GET,DEconstE,OPTIONS', 'Access-Control-Allow-Methods': 'PUT,POST,GET,DEconstE,OPTIONS',
'Content-Type': 'application/json; charset=utf-8' 'Content-Type': 'application/json; charset=utf-8'
}) }
if (url.includes('static')){
header["Content-Type"] = 'text/html; charset=utf-8'
}
//设置相应头
res.set(header)
req.method === 'OPTIONS' ? res.status(204).end() : next() req.method === 'OPTIONS' ? res.status(204).end() : next()
}) })
...@@ -42,15 +50,16 @@ app.use(logger('dev')); ...@@ -42,15 +50,16 @@ app.use(logger('dev'));
app.use(express.json()); app.use(express.json());
app.use(express.urlencoded({extended: false})); app.use(express.urlencoded({extended: false}));
app.use(cookieParser()); app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public'))); app.use('/static', express.static(path.join(__dirname, 'static')));
app.use('/', indexRouter); app.use('/', indexRouter);
app.use('/users', usersRouter); app.use('/users', usersRouter);
app.use('/query', queryRouter) app.use('/query', queryRouter)
app.use('/add', addRouter) app.use('/add', addRouter)
app.use('/delete',deleteRouter) app.use('/delete', deleteRouter)
app.use('/update', updateRouter) app.use('/update', updateRouter)
app.use('/submit', submitRouter) app.use('/page', submitRouter)
app.use('/typeManage', typeManage)
module.exports = app; module.exports = app;
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
"version": "0.0.0", "version": "0.0.0",
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "nodemon ./bin/www" "dev": "nodemon ./bin/www",
"start": "node ./bin/www"
}, },
"dependencies": { "dependencies": {
"@types/express": "^4.17.13", "@types/express": "^4.17.13",
......
<html>
<head>
<title>Express</title>
<link rel="stylesheet" href="/stylesheets/style.css">
</head>
<body>
<h1>Express</h1>
<p>Welcome to Express</p>
</body>
</html>
body {
padding: 50px;
font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
}
a {
color: #00B7FF;
}
<html>
<head>
<title>Tool1</title>
<link rel="stylesheet" href="/stylesheets/style.css">
</head>
<body>
<h1>Tool1</h1>
<p>Tool1</p>
</body>
</html>
...@@ -4,39 +4,43 @@ const Mysql = require("../SQLPool"); ...@@ -4,39 +4,43 @@ const Mysql = require("../SQLPool");
const router = express.Router() const router = express.Router()
router.get('/addToolBox', (req, res) => { router.get('/addToolBox', (req, res) => {
const {toolBoxName, toolBoxIcon, toolBoxDesc, toolBoxUrl, typeId} = req.query const {toolBoxName, toolBoxIcon, toolBoxDesc, toolBoxUrl, typeId, childTypeId} = req.query
// res.send({success: true}) // 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 (?,?)` const typeSQL = `INSERT INTO toolbox_type (typeId,toolBoxId) VALUES (?,?)`
try { try {
request(domain + '/query/queryToolBoxSortId', {}, (a, b, body) => { Mysql.query(SQL, [toolBoxName, toolBoxDesc, toolBoxIcon, toolBoxUrl], (err, result) => {
const data = JSON.parse(body).data if (err) {
Mysql.query(SQL, [toolBoxName, toolBoxDesc, toolBoxIcon, toolBoxUrl, data[data.length - 1]], (err, result) => {
if (err){
res.send({
success: false,
err
})
}
res.send({ res.send({
success: true, success: false,
data: result err
}) })
}
res.send({
success: true,
data: result
}) })
}) })
// Mysql.query(typeSQL, [])
} catch (e) { } catch (e) {
console.error(e) console.error(e)
} }
}) })
router.get('/addType', (req, res) => { router.get('/addType', (req, res) => {
const {typeName} = req.query const {typeName, childTypeName, typeId} = req.query
const SQL = 'INSERT INTO type (typeName) VALUES (?)' console.log(req.query)
let SQL = 'INSERT INTO type (typeName) VALUES (?)'
const values = []
if (childTypeName && typeId) {
SQL = 'INSERT INTO child_type (childTypeName, typeId) VALUES (?,?)'
values.push(childTypeName)
values.push(typeId)
} else {
values.push(typeName)
}
console.log(values)
try { try {
Mysql.query(SQL, [typeName], (err, result) => { Mysql.query(SQL, values, (err, result) => {
if (err) { if (err) {
res.send({ res.send({
success: false, success: false,
...@@ -55,6 +59,4 @@ router.get('/addType', (req, res) => { ...@@ -55,6 +59,4 @@ router.get('/addType', (req, res) => {
}) })
module.exports = router module.exports = router
const express = require('express');
const Mysql = require('../SQLPool')
const fs = require("fs");
const request = require("request");
const path = require("path");
const router = express.Router();
router.post('/addPage', (req, res) => {
const {pageName, code} = req.body
const SQL = `INSERT INTO page (pageName) VALUES (?)`
Mysql.query(SQL, [pageName], (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]['pageId']
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['pageId'] + '.html'
return {
...v,
pageUrl: url
}
})
res.send({
success: true,
data: _result
})
})
})
router.post('/updatePage', (req, res) => {
const {pageId, pageName, code} = req.body
const SQL = 'UPDATE page SET pageName=? WHERE pageId = ?'
Mysql.query(SQL, [pageName, pageId], (err, result) => {
if (err) {
res.send({
success: false,
error: err
})
} else {
try{
const fileName = 'page' + pageId + '.html'
fs.writeFileSync(path.join(__dirname, '../static/' + fileName), code)
res.send({
success: true
})
}catch (e){
res.send({
success: false,
error: e
})
}
}
})
})
module.exports = router
...@@ -14,42 +14,37 @@ router.get('/queryType', (req, res) => { ...@@ -14,42 +14,37 @@ router.get('/queryType', (req, res) => {
} }
res.send({ res.send({
success: true, success: true,
data: result.map(v => ({...v, typeContent: JSON.parse(v.typeContent)})) data: result
}) })
}) })
}); });
router.get('/queryToolBox', (req, res) => { router.get('/queryChildType', (req, res) => {
let {isFollow, typeId, childTypeId} = req.query const {typeId} = req.query
let SQL = `SELECT toolbox.* FROM type_childtype_toolbox INNER JOIN toolbox ON type_childtype_toolbox.toolBoxId = toolbox.toolBoxId INNER JOIN child_type ON type_childtype_toolbox.childTypeId = child_type.childTypeId INNER JOIN type ON type_childtype_toolbox.typeId = type.typeId WHERE type_childtype_toolbox.typeId = ?` const SQL = 'SELECT child_type.childTypeId, child_type.childTypeName, child_type.typeId FROM child_type INNER JOIN type ON child_type.typeId = type.typeId WHERE type.typeId = ?'
if (isFollow) { Mysql.query(SQL,[typeId], (err, result) => {
typeId = JSON.parse(typeId)
SQL = 'SELECT * FROM toolbox WHERE toolboxId IN (?)'
} else if (typeId) {
if (childTypeId){
SQL = SQL + ` AND child_type.childTypeId = ?`;
}
}
Mysql.query(SQL, [typeId, childTypeId], (err, result) => {
if (err) { if (err) {
res.send({ res.send({
success: false, success: false,
err 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
}) })
}) })
}); });
router.get('/queryToolBoxSortId', (req, res) => {
const SQL = 'SELECT sortId FROM toolBox' router.get('/queryToolBox', (req, res) => {
Mysql.query(SQL, (err, result) => { 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 = JSON.parse(typeId)
SQL = 'SELECT * FROM toolbox WHERE toolboxId IN (?)'
}
Mysql.query(SQL, [typeId], (err, result) => {
if (err) { if (err) {
res.send({ res.send({
success: false, success: false,
...@@ -57,13 +52,32 @@ router.get('/queryToolBoxSortId', (req, res) => { ...@@ -57,13 +52,32 @@ router.get('/queryToolBoxSortId', (req, res) => {
}) })
throw err throw err
} }
const _result = [] const _result = result.slice()
result.map(v => _result.push(v["sortId"]))
res.send({ res.send({
success: true, success: true,
data: _result.sort((a, b) => a - b) data: _result.sort((a, b) => a.sortId - b.sortId)
}) })
}) })
}) });
// router.get('/queryToolBoxSortId', (req, res) => {
// const SQL = 'SELECT sortId FROM toolBox'
// Mysql.query(SQL, (err, result) => {
// if (err) {
// res.send({
// success: false,
// err
// })
// throw err
// }
// const _result = []
// result.map(v => _result.push(v["sortId"]))
// res.send({
// success: true,
// data: _result.sort((a, b) => a - b)
// })
// })
// })
module.exports = router module.exports = router
const express = require('express')
const router = express.Router()
router.get('/', (req, res) => {
res.set({
'Content-Type': 'text/html; charset=utf-8'
})
})
module.exports = router
const express = require('express');
const Mysql = require('../SQLPool')
const router = express.Router();
router.get('/addPage', (req, res) => {
const {pageName} = req.query
const SQL = `INSERT INTO page (pageName) VALUES (?)`
Mysql.query(SQL, [pageName], (err, result) => {
if (err) {
res.send({
success: false,
err
})
}
res.send({
success: true,
data: result
})
})
})
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
})
})
})
router.post('/release', (req, res) => {
console.log(req.body)
const {code} = req.body
console.log(code)
res.send({
success: true
})
})
module.exports = router
const express = require('express')
const request = require("request");
const Mysql = require('../SQLPool')
const router = express.Router()
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: true,
data: result
})
})
})
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: true,
data: result
})
})
})
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 => ({
childTypeId: v.childTypeId,
childTypeName: v.childTypeName
}))
dataArr.push({
typeId: result[0].typeId,
typeName: result[0].typeName,
children: childType
})
}
result.forEach(v => {
combineType(v.typeId)
})
res.send({
success: true,
data: dataArr
})
})
})
module.exports = router
...@@ -5,26 +5,24 @@ import {Root} from "../../dataCenter/Root"; ...@@ -5,26 +5,24 @@ import {Root} from "../../dataCenter/Root";
function Content(props) { function Content(props) {
const {dataCenter, fetchData} = useContext(Root) const {dataCenter, fetchData} = useContext(Root)
const [gridPosition, setGridPosition] = useState([]) const [toolBoxData, setToolBoxData] = useState([])
const updatePosition = ()=>{
fetchData('/update/updateToolBoxSort',{sortArr: JSON.stringify([{toolBoxId: 10, sortId: 1}])})
}
useEffect(() => {
setGridPosition(dataCenter.toolBox && dataCenter.toolBox.map(v => v.toolBoxId))
}, [dataCenter.toolBox])
useEffect(()=>{
setToolBoxData(dataCenter?.toolBox?.filter(v => {
if (dataCenter.childTypeId === 'all') return true
else return v.childTypeId === dataCenter.childTypeId
}) || [])
},[dataCenter.childTypeId])
return ( return (
<div className="content"> <div className="content">
{ {
dataCenter?.toolBox?.length ? dataCenter.toolBox.map(v => { toolBoxData.length ? toolBoxData.map(v => {
return ( return (
<ContentItem key={v['toolBoxId']} value={v}/> <ContentItem key={v['toolBoxId']} value={v}/>
) )
}) })
: :
'没有数据了!' '没有数据了!'
} }
</div> </div>
) )
......
...@@ -13,7 +13,6 @@ function Pop_addToolBox() { ...@@ -13,7 +13,6 @@ function Pop_addToolBox() {
.then(() => updateIndex()) .then(() => updateIndex())
} }
return ( return (
<PopContainer> <PopContainer>
<h2 className='Pop-title'>新建工具盒</h2> <h2 className='Pop-title'>新建工具盒</h2>
......
import './ToolType.scss' import './ToolType.scss'
import {useContext, useEffect, useState} from "react"; import {useContext} from "react";
import {Root} from "../../dataCenter/Root"; import {Root} from "../../dataCenter/Root";
import {NEED_UPDATE_INDEX} from "../../dataCenter/action"; import {CHANGE_CHILD_TYPE, CHANGE_TYPE} from "../../dataCenter/action";
import {Tabs} from "antd";
const ChildTypeItem = props => {
const {dataCenter, dispatch} = useContext(Root)
const {childTypeId, childTypeName} = props
const classNameArr = ['child-type-item']
if (childTypeId === dataCenter.childTypeId) {
classNameArr.push('child-type-item-selected')
}
const handleClick = () => {
console.log(childTypeId)
dispatch(CHANGE_CHILD_TYPE(childTypeId))
}
return (
<div className={classNameArr.join(' ')} onClick={handleClick}>{childTypeName}</div>
)
}
function ToolType(props) {
const {dataCenter, fetchData, updateIndex, dispatch} = useContext(Root)
const [typeId, setTypeId] = useState(2)
const {TabPane} = Tabs;
useEffect(() => {
updateIndex()
}, [typeId])
useEffect(() => {
if (dataCenter.needUpdateIndex) {
const _typeId = typeId === 'all' ? {} : typeId === 'follow' ? {
isFollow: true,
typeId: JSON.stringify(dataCenter.userInfo.follow)
} : {typeId: typeId}
fetchData('/query/queryToolBox', _typeId, 'toolBox').then(() => dispatch(NEED_UPDATE_INDEX()))
}
}, [dataCenter.needUpdateIndex])
console.log(dataCenter?.type?.filter(v => v.typeId === typeId))
function ToolType(props) {
const {dataCenter, dispatch} = useContext(Root)
return ( return (
<> <>
<div className="tab-tool-type"> <div className="tab-tool-type">
<div className={typeId === 'all' ? 'item-tool-type item-tool-type-selected' : 'item-tool-type'} {/*<div className={dataCenter.typeId === 'all' ? 'item-tool-type item-tool-type-selected' : 'item-tool-type'}*/}
onClick={() => setTypeId('all')}>工具 {/* onClick={() => setTypeId('all')}>工具*/}
</div> {/*</div>*/}
<div className={typeId === 'follow' ? 'item-tool-type item-tool-type-selected' : 'item-tool-type'} {/*<div className={dataCenter.typeId === 'follow' ? 'item-tool-type item-tool-type-selected' : 'item-tool-type'}*/}
onClick={() => setTypeId('follow')}>我的收藏 {/* onClick={() => setTypeId('follow')}>我的收藏*/}
</div> {/*</div>*/}
{ {
dataCenter?.type?.length && dataCenter.type.map(v => { dataCenter?.type?.length && dataCenter.type.map(v => {
const classNameArr = ['item-tool-type '] const classNameArr = ['item-tool-type ']
if (v["typeId"] === typeId) classNameArr.push('item-tool-type-selected') if (v["typeId"] === dataCenter.typeId) classNameArr.push('item-tool-type-selected')
return ( return (
<div key={v["typeId"]} className={classNameArr.join('')} <div key={v["typeId"]} className={classNameArr.join('')}
onClick={() => setTypeId(v["typeId"])}>{v.typeName}</div> onClick={() => dispatch(CHANGE_TYPE( v["typeId"]))}>{v.typeName}</div>
) )
}) })
} }
</div> </div>
{/* <div className="child-type"> <div className="child-type">
<ChildTypeItem key={'all'} childTypeId={'all'} childTypeName={'全部'}/>
{ {
dataCenter?.type?.length && dataCenter.type.filter(v => v.typeId === typeId)[0].typeContent.map(v => { dataCenter?.childType?.length && dataCenter?.childType.map(v => {
return ( return (
<div key={v.id} className="item-childType">{v.name}</div> <ChildTypeItem key={v.childTypeId} childTypeId={v.childTypeId}
childTypeName={v.childTypeName}/>
) )
}) })
} }
</div> */} </div>
</> </>
) )
} }
......
@import "../../common/common"; @import "../../common/common";
.tab-tool-type { .tab-tool-type {
width: 100%; width: 100%;
max-width: 1190px; max-width: 1190px;
...@@ -8,10 +9,11 @@ ...@@ -8,10 +9,11 @@
background: $tabBackgroundColor; background: $tabBackgroundColor;
display: flex; display: flex;
border-radius: 3px 3px; border-radius: 3px 3px;
background: linear-gradient( 21deg,#00afcb 1%,#26d6ca)!important; background: linear-gradient(21deg, #00afcb 1%, #26d6ca) !important;
color: #fff; color: #fff;
font-size: 14px; font-size: 14px;
padding-top: 4px; padding-top: 4px;
.item-tool-type { .item-tool-type {
width: 80px; width: 80px;
line-height: 35px; line-height: 35px;
...@@ -29,18 +31,21 @@ ...@@ -29,18 +31,21 @@
} }
} }
.child-type{ .child-type {
margin-left: 0;
font-size: 15px;
display: flex; display: flex;
gap: 10px; background: #fff;
justify-content: flex-start; padding-left: 30px;
flex-wrap: nowrap;
overflow-x: auto;
border: 1px solid #000;
.item-childType{ .child-type-item {
flex: 0 0 auto; min-width: 30px;
margin: 0; height: 36px;
line-height: 36px;
text-align: center;
margin-right: 15px;
cursor: pointer;
}
.child-type-item-selected {
border-bottom: 4px solid #12C2CB;
color: #12C2CB;
} }
} }
...@@ -43,13 +43,9 @@ function DataCenter(props) { ...@@ -43,13 +43,9 @@ function DataCenter(props) {
throw e throw e
}) })
const updateIndex = () => {
fetchData('/query/queryType', {}, 'type')
.then(() => dispatch(NEED_UPDATE_INDEX()))
}
return ( return (
<Root.Provider value={{dataCenter, dispatch, fetchData, updateIndex}}> <Root.Provider value={{dataCenter, dispatch, fetchData}}>
{ {
props.children props.children
} }
......
const UPDATE_DATA = data => ({type: 'UPDATE_DATA', data: {...data}}) const UPDATE_DATA = data => ({type: 'UPDATE_DATA', data: {...data}})
const NEED_UPDATE_INDEX = () => ({type: 'NEED_UPDATE_INDEX'}) const NEED_UPDATE_INDEX = () => ({type: 'NEED_UPDATE_INDEX'})
const CHANGE_TYPE = typeId => ({type: 'CHANGE_TYPE', typeId: typeId})
const CHANGE_CHILD_TYPE = childTypeId => ({type: 'CHANGE_CHILD_TYPE', childTypeId: childTypeId})
export { export {
UPDATE_DATA, UPDATE_DATA,
NEED_UPDATE_INDEX NEED_UPDATE_INDEX,
CHANGE_TYPE,
CHANGE_CHILD_TYPE
} }
const initDataCenter = { const initDataCenter = {
toolBox: null, toolBox: null,
type: null, type: null,
childType: null,
userInfo: null, userInfo: null,
needUpdateIndex: false needUpdateIndex: false,
typeId: 2,
childTypeId: 'all'
} }
/** /**
...@@ -39,6 +42,10 @@ const dataReducer = (state, action) => { ...@@ -39,6 +42,10 @@ const dataReducer = (state, action) => {
}) })
case 'NEED_UPDATE_INDEX': case 'NEED_UPDATE_INDEX':
return Object.assign({}, state, {needUpdateIndex: !state.needUpdateIndex}) return Object.assign({}, state, {needUpdateIndex: !state.needUpdateIndex})
case 'CHANGE_TYPE':
return Object.assign({}, state, {typeId: action.typeId})
case 'CHANGE_CHILD_TYPE':
return Object.assign({}, state, {childTypeId: action.childTypeId})
default: default:
return state return state
} }
......
...@@ -4,22 +4,40 @@ import ToolType from "../../component/ToolType/ToolType"; ...@@ -4,22 +4,40 @@ 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 {PopContext, Root} from "../../dataCenter/Root";
import {useContext, useEffect, useState} from "react"; import {useContext, useEffect, useState} from "react";
import {NEED_UPDATE_INDEX} from "../../dataCenter/action";
function Index() { function Index() {
const [pop, setPop] = useState() const [pop, setPop] = useState()
const {fetchData, dataCenter} = useContext(Root) const {fetchData, dataCenter, dispatch} = useContext(Root)
const showPop = popComponent => { const showPop = popComponent => {
setPop(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')
.then(()=> fetchData('/query/queryChildType',{typeId: dataCenter.typeId},'childType'))
.then(() => dispatch(NEED_UPDATE_INDEX()))
}, [dataCenter.typeId])
useEffect(() => {
if (dataCenter.needUpdateIndex) {
const _typeId = dataCenter.typeId === 'all' ? {} : dataCenter.typeId === 'follow' ? {
isFollow: true,
typeId: JSON.stringify(dataCenter.userInfo.follow)
} : {typeId: dataCenter.typeId}
fetchData('/query/queryToolBox', _typeId, 'toolBox').then(() => dispatch(NEED_UPDATE_INDEX()))
}
}, [dataCenter.needUpdateIndex])
useEffect(() => {
getUser() getUser()
},[]) }, [])
return ( return (
<PopContext.Provider value={{hidePop: () => setPop(''), showPop: popName => showPop(popName)}}> <PopContext.Provider value={{hidePop: () => setPop(''), showPop: popName => showPop(popName)}}>
...@@ -32,9 +50,12 @@ function Index() { ...@@ -32,9 +50,12 @@ function Index() {
</div> </div>
<div className="nav"> <div className="nav">
<div className="nav-title"> <div className="nav-title">
<img src={logo} alt=""/> <img src={logo} alt=""/>
</div>
<div className="nav-weather">
<iframe width="360" height="40" frameBorder="0" scrolling="no" hspace="0"
src="https://i.tianqi.com/?c=code&a=getcode&id=40&icon=1"/>
</div> </div>
<div className="nav-weather"><iframe width="360" height="40" frameBorder="0" scrolling="no" hspace="0" src="https://i.tianqi.com/?c=code&a=getcode&id=40&icon=1"/></div>
</div> </div>
<div className="tool-nav"> <div className="tool-nav">
<ToolType/> <ToolType/>
...@@ -46,9 +67,9 @@ function Index() { ...@@ -46,9 +67,9 @@ function Index() {
pop pop
} }
<div className="index-footer"> <div className="index-footer">
兑吧研发中心·杭州兑吧网络科技游戏公司版权所有 兑吧研发中心·杭州兑吧网络科技游戏公司版权所有
<br/> <br/>
浙ICP备14017299号-1 浙ICP备14017299号-1
</div> </div>
</div> </div>
</PopContext.Provider> </PopContext.Provider>
......
...@@ -39,7 +39,7 @@ body { ...@@ -39,7 +39,7 @@ body {
content: ""; content: "";
} }
} }
.nav { .nav {
width: 100%; width: 100%;
height: 60px; height: 60px;
...@@ -78,7 +78,7 @@ body { ...@@ -78,7 +78,7 @@ body {
width: 100%; width: 100%;
min-width: 612px; min-width: 612px;
max-width: 1190px; max-width: 1190px;
padding: 20px 0; padding: 0 0 20px 0;
margin: 0 auto 0; margin: 0 auto 0;
box-sizing: border-box; box-sizing: border-box;
} }
......
# 接口文档
### queryType 查询父类型
/query/queryType GET
### getUser 获取用户信息
参数:(cookie userId)
/users/getUser GET
### queryToolBox 获取工具箱信息
参数: typeId (childTypeId)
/query/queryToolBox GET
### queryChildType 查询子类型信息
参数: typeId
/query/queryChildType GET
### addToolBox
参数: toolBoxName: 123
toolBoxIcon: 123132
toolBoxDesc: 213312
toolBoxUrl: qweqwe
typeId: 2
childType: 1
/add/addToolBoxId GET
### addType 新建父类型
参数: TypeName
/add/addType GET
### addChildType 新建子类型
### addPage 发布页面
参数: code pageName POST
/page/addPage
### queryPage 查询自定义页面信息
/page/queryPage GET
###
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