Commit 970d30e1 authored by wty's avatar wty

增加子分类后端代码

parent d7fb09d6
...@@ -12,13 +12,9 @@ router.get('/queryType', (req, res) => { ...@@ -12,13 +12,9 @@ router.get('/queryType', (req, res) => {
err err
}) })
} }
const _result = result.slice().map(v => {JSON.parse(v.typeContent)})
res.send({ res.send({
success: true, success: true,
data: { data: result.map(v => ({...v, typeContent: JSON.parse(v.typeContent)}))
...result,
_result
}
}) })
}) })
}); });
......
...@@ -12,14 +12,15 @@ router.get('/getUser', function (req, res, next) { ...@@ -12,14 +12,15 @@ router.get('/getUser', function (req, res, next) {
let {userId} = req.cookies let {userId} = req.cookies
console.log(req.cookies) console.log(req.cookies)
console.log('userId:',userId) console.log('userId:',userId)
if (!userId) { userId = req.query.userId
res.send({ // if (!userId) {
success: false, // res.send({
code: ErrorCode.USER_NOT_LOGIN, // success: false,
data: '用户尚未登录' // code: ErrorCode.USER_NOT_LOGIN,
}) // data: '用户尚未登录'
return // })
} // return
// }
const SQL = 'SELECT * FROM `user` WHERE `user`.uid = ?' const SQL = 'SELECT * FROM `user` WHERE `user`.uid = ?'
Mysql.query(SQL, [userId], (err, result) => { Mysql.query(SQL, [userId], (err, result) => {
if (err) { if (err) {
......
...@@ -2,36 +2,60 @@ import './ToolType.scss' ...@@ -2,36 +2,60 @@ import './ToolType.scss'
import {useContext, useEffect, useState} from "react"; import {useContext, useEffect, useState} from "react";
import {Root} from "../../dataCenter/Root"; import {Root} from "../../dataCenter/Root";
import {NEED_UPDATE_INDEX} from "../../dataCenter/action"; import {NEED_UPDATE_INDEX} from "../../dataCenter/action";
import {Tabs} from "antd";
function ToolType (props) {
function ToolType(props) {
const {dataCenter, fetchData, updateIndex, dispatch} = useContext(Root) const {dataCenter, fetchData, updateIndex, dispatch} = useContext(Root)
const [typeId, setTypeId] = useState(2) const [typeId, setTypeId] = useState(2)
const {TabPane} = Tabs;
useEffect(()=>{ useEffect(() => {
updateIndex() updateIndex()
},[typeId]) }, [typeId])
useEffect(()=>{ useEffect(() => {
if (dataCenter.needUpdateIndex){ if (dataCenter.needUpdateIndex) {
const _typeId = typeId === 'all' ? {} : typeId === 'follow' ? {isFollow:true,typeId: JSON.stringify(dataCenter.userInfo.follow)} : {typeId: typeId} const _typeId = typeId === 'all' ? {} : typeId === 'follow' ? {
fetchData('/query/queryToolBox',_typeId,'toolBox').then(()=>dispatch(NEED_UPDATE_INDEX())) isFollow: true,
typeId: JSON.stringify(dataCenter.userInfo.follow)
} : {typeId: typeId}
fetchData('/query/queryToolBox', _typeId, 'toolBox').then(() => dispatch(NEED_UPDATE_INDEX()))
} }
},[dataCenter.needUpdateIndex]) }, [dataCenter.needUpdateIndex])
console.log(dataCenter?.type?.filter(v => v.typeId === typeId))
return ( 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="tab-tool-type">
<div className={typeId === 'follow' ?'item-tool-type item-tool-type-selected' : 'item-tool-type'} onClick={()=>setTypeId('follow')}>我的收藏</div> <div className={typeId === 'all' ? 'item-tool-type item-tool-type-selected' : 'item-tool-type'}
{ onClick={() => setTypeId('all')}>工具
dataCenter?.type?.length && dataCenter.type.map(v => { </div>
const classNameArr = ['item-tool-type '] <div className={typeId === 'follow' ? 'item-tool-type item-tool-type-selected' : 'item-tool-type'}
if (v["typeId"] === typeId) classNameArr.push('item-tool-type-selected') onClick={() => setTypeId('follow')}>我的收藏
return ( </div>
<div key={v["typeId"] } className={classNameArr.join('')} onClick={()=>setTypeId(v["typeId"])}>{v.typeName}</div> {
) dataCenter?.type?.length && dataCenter.type.map(v => {
}) const classNameArr = ['item-tool-type ']
} if (v["typeId"] === typeId) classNameArr.push('item-tool-type-selected')
</div> return (
<div key={v["typeId"]} className={classNameArr.join('')}
onClick={() => setTypeId(v["typeId"])}>{v.typeName}</div>
)
})
}
</div>
<div className="child-type">
{
dataCenter?.type?.length && dataCenter.type.filter(v => v.typeId === typeId)[0].typeContent.map(v => {
return (
<div key={v.id} className="item-childType">{v.name}</div>
)
})
}
</div>
</>
) )
} }
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
} }
} }
.childType{ .child-type{
margin-left: 0; margin-left: 0;
font-size: 15px; font-size: 15px;
display: flex; display: flex;
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
justify-content: flex-start; justify-content: flex-start;
flex-wrap: nowrap; flex-wrap: nowrap;
overflow-x: auto; overflow-x: auto;
border: 1px solid #000;
.item-childType{ .item-childType{
flex: 0 0 auto; flex: 0 0 auto;
......
...@@ -27,7 +27,7 @@ function DataCenter(props) { ...@@ -27,7 +27,7 @@ function DataCenter(props) {
} }
const fetchData = (path, requestData, dataName) => const fetchData = (path, requestData, dataName) =>
fetch(generateUrl(path, requestData), {credentials: 'include'}) fetch(generateUrl(path, requestData), {credentials: 'include',mode: 'no-cors'})
.then(res => res.json()) .then(res => res.json())
.then(res => { .then(res => {
if (res.success) { if (res.success) {
......
import React from 'react'; import React from 'react';
import ReactDOM from 'react-dom'; import ReactDOM from 'react-dom';
import { ConfigProvider, DatePicker, message } from 'antd';
// 由于 antd 组件的默认文案是英文,所以需要修改为中文
import zhCN from 'antd/lib/locale/zh_CN';
import moment from 'moment';
import 'moment/locale/zh-cn';
import 'antd/dist/antd.css';
import './index.css';
import './index.css'; import './index.css';
import App from './App'; import App from './App';
import reportWebVitals from './reportWebVitals'; import reportWebVitals from './reportWebVitals';
moment.locale('zh-cn');
ReactDOM.render( ReactDOM.render(
<React.StrictMode> <React.StrictMode>
<App /> <ConfigProvider locale={zhCN}>
</React.StrictMode>, <App />
document.getElementById('root') </ConfigProvider>
</React.StrictMode>,
document.getElementById('root')
); );
// If you want to start measuring performance in your app, pass a function // If you want to start measuring performance in your app, pass a function
......
This diff is collapsed.
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