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')
const addRouter = require('./routes/add')
const deleteRouter = require('./routes/delete')
const updateRouter = require('./routes/update')
const submitRouter = require('./routes/submit')
const submitRouter = require('./routes/page')
const typeManage = require('./routes/typeManage')
const app = express();
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) => {
//设置请求头
res.set({
const url = req.url
const header = {
'Access-Control-Allow-Credentials': true,
'Access-Control-Allow-Origin': req.headers.origin || '*',
'Access-Control-Allow-Headers': 'X-Requested-With,Content-Type',
'Access-Control-Allow-Methods': 'PUT,POST,GET,DEconstE,OPTIONS',
'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()
})
......@@ -42,15 +50,16 @@ app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({extended: false}));
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('/users', usersRouter);
app.use('/query', queryRouter)
app.use('/add', addRouter)
app.use('/delete',deleteRouter)
app.use('/delete', deleteRouter)
app.use('/update', updateRouter)
app.use('/submit', submitRouter)
app.use('/page', submitRouter)
app.use('/typeManage', typeManage)
module.exports = app;
......@@ -3,7 +3,8 @@
"version": "0.0.0",
"private": true,
"scripts": {
"dev": "nodemon ./bin/www"
"dev": "nodemon ./bin/www",
"start": "node ./bin/www"
},
"dependencies": {
"@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,15 +4,13 @@ const Mysql = require("../SQLPool");
const router = express.Router()
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})
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 (?,?)`
try {
request(domain + '/query/queryToolBoxSortId', {}, (a, b, body) => {
const data = JSON.parse(body).data
Mysql.query(SQL, [toolBoxName, toolBoxDesc, toolBoxIcon, toolBoxUrl, data[data.length - 1]], (err, result) => {
if (err){
Mysql.query(SQL, [toolBoxName, toolBoxDesc, toolBoxIcon, toolBoxUrl], (err, result) => {
if (err) {
res.send({
success: false,
err
......@@ -23,20 +21,26 @@ router.get('/addToolBox', (req, res) => {
data: result
})
})
})
// Mysql.query(typeSQL, [])
} catch (e) {
console.error(e)
}
})
router.get('/addType', (req, res) => {
const {typeName} = req.query
const SQL = 'INSERT INTO type (typeName) VALUES (?)'
const {typeName, childTypeName, typeId} = req.query
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 {
Mysql.query(SQL, [typeName], (err, result) => {
Mysql.query(SQL, values, (err, result) => {
if (err) {
res.send({
success: false,
......@@ -55,6 +59,4 @@ router.get('/addType', (req, res) => {
})
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) => {
}
res.send({
success: true,
data: result.map(v => ({...v, typeContent: JSON.parse(v.typeContent)}))
data: result
})
})
});
router.get('/queryToolBox', (req, res) => {
let {isFollow, typeId, childTypeId} = 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 = ?`
if (isFollow) {
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) => {
router.get('/queryChildType', (req, res) => {
const {typeId} = req.query
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 = ?'
Mysql.query(SQL,[typeId], (err, result) => {
if (err) {
res.send({
success: false,
err
})
throw err
}
const _result = result.slice()
res.send({
success: true,
data: _result.sort((a, b) => a.sortId - b.sortId)
data: result
})
})
});
router.get('/queryToolBoxSortId', (req, res) => {
const SQL = 'SELECT sortId FROM toolBox'
Mysql.query(SQL, (err, result) => {
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 = JSON.parse(typeId)
SQL = 'SELECT * FROM toolbox WHERE toolboxId IN (?)'
}
Mysql.query(SQL, [typeId], (err, result) => {
if (err) {
res.send({
success: false,
......@@ -57,13 +52,32 @@ router.get('/queryToolBoxSortId', (req, res) => {
})
throw err
}
const _result = []
result.map(v => _result.push(v["sortId"]))
const _result = result.slice()
res.send({
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
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,20 +5,18 @@ import {Root} from "../../dataCenter/Root";
function Content(props) {
const {dataCenter, fetchData} = useContext(Root)
const [gridPosition, setGridPosition] = 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])
const [toolBoxData, setToolBoxData] = useState([])
useEffect(()=>{
setToolBoxData(dataCenter?.toolBox?.filter(v => {
if (dataCenter.childTypeId === 'all') return true
else return v.childTypeId === dataCenter.childTypeId
}) || [])
},[dataCenter.childTypeId])
return (
<div className="content">
{
dataCenter?.toolBox?.length ? dataCenter.toolBox.map(v => {
toolBoxData.length ? toolBoxData.map(v => {
return (
<ContentItem key={v['toolBoxId']} value={v}/>
)
......
......@@ -13,7 +13,6 @@ function Pop_addToolBox() {
.then(() => updateIndex())
}
return (
<PopContainer>
<h2 className='Pop-title'>新建工具盒</h2>
......
import './ToolType.scss'
import {useContext, useEffect, useState} from "react";
import {useContext} from "react";
import {Root} from "../../dataCenter/Root";
import {NEED_UPDATE_INDEX} from "../../dataCenter/action";
import {Tabs} from "antd";
import {CHANGE_CHILD_TYPE, CHANGE_TYPE} from "../../dataCenter/action";
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()))
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))
}
}, [dataCenter.needUpdateIndex])
return (
<div className={classNameArr.join(' ')} onClick={handleClick}>{childTypeName}</div>
)
}
console.log(dataCenter?.type?.filter(v => v.typeId === typeId))
function ToolType(props) {
const {dataCenter, dispatch} = useContext(Root)
return (
<>
<div className="tab-tool-type">
<div className={typeId === 'all' ? 'item-tool-type item-tool-type-selected' : 'item-tool-type'}
onClick={() => setTypeId('all')}>工具
</div>
<div className={typeId === 'follow' ? 'item-tool-type item-tool-type-selected' : 'item-tool-type'}
onClick={() => setTypeId('follow')}>我的收藏
</div>
{/*<div className={dataCenter.typeId === 'all' ? 'item-tool-type item-tool-type-selected' : 'item-tool-type'}*/}
{/* onClick={() => setTypeId('all')}>工具*/}
{/*</div>*/}
{/*<div className={dataCenter.typeId === 'follow' ? 'item-tool-type item-tool-type-selected' : 'item-tool-type'}*/}
{/* onClick={() => setTypeId('follow')}>我的收藏*/}
{/*</div>*/}
{
dataCenter?.type?.length && dataCenter.type.map(v => {
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 (
<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 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 (
<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";
.tab-tool-type {
width: 100%;
max-width: 1190px;
......@@ -8,10 +9,11 @@
background: $tabBackgroundColor;
display: flex;
border-radius: 3px 3px;
background: linear-gradient( 21deg,#00afcb 1%,#26d6ca)!important;
background: linear-gradient(21deg, #00afcb 1%, #26d6ca) !important;
color: #fff;
font-size: 14px;
padding-top: 4px;
.item-tool-type {
width: 80px;
line-height: 35px;
......@@ -29,18 +31,21 @@
}
}
.child-type{
margin-left: 0;
font-size: 15px;
.child-type {
display: flex;
gap: 10px;
justify-content: flex-start;
flex-wrap: nowrap;
overflow-x: auto;
border: 1px solid #000;
background: #fff;
padding-left: 30px;
.item-childType{
flex: 0 0 auto;
margin: 0;
.child-type-item {
min-width: 30px;
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) {
throw e
})
const updateIndex = () => {
fetchData('/query/queryType', {}, 'type')
.then(() => dispatch(NEED_UPDATE_INDEX()))
}
return (
<Root.Provider value={{dataCenter, dispatch, fetchData, updateIndex}}>
<Root.Provider value={{dataCenter, dispatch, fetchData}}>
{
props.children
}
......
const UPDATE_DATA = data => ({type: 'UPDATE_DATA', data: {...data}})
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 {
UPDATE_DATA,
NEED_UPDATE_INDEX
NEED_UPDATE_INDEX,
CHANGE_TYPE,
CHANGE_CHILD_TYPE
}
const initDataCenter = {
toolBox: null,
type: null,
childType: null,
userInfo: null,
needUpdateIndex: false
needUpdateIndex: false,
typeId: 2,
childTypeId: 'all'
}
/**
......@@ -39,6 +42,10 @@ const dataReducer = (state, action) => {
})
case 'NEED_UPDATE_INDEX':
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:
return state
}
......
......@@ -4,22 +4,40 @@ 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 {NEED_UPDATE_INDEX} from "../../dataCenter/action";
function Index() {
const [pop, setPop] = useState()
const {fetchData, dataCenter} = useContext(Root)
const {fetchData, dataCenter, dispatch} = useContext(Root)
const showPop = popComponent => {
setPop(popComponent)
}
const getUser = ()=>{
fetchData('/users/getUser', {userId:'100001'}, 'userInfo')
const getUser = () => {
fetchData('/users/getUser', {userId: '100001'}, 'userInfo')
.catch(res =>
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()
},[])
}, [])
return (
<PopContext.Provider value={{hidePop: () => setPop(''), showPop: popName => showPop(popName)}}>
......@@ -34,7 +52,10 @@ function Index() {
<div className="nav-title">
<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 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="tool-nav">
<ToolType/>
......
......@@ -78,7 +78,7 @@ body {
width: 100%;
min-width: 612px;
max-width: 1190px;
padding: 20px 0;
padding: 0 0 20px 0;
margin: 0 auto 0;
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