Skip to content

Commit 5b1fda8

Browse files
author
wangqi
committedAug 13, 2019
models update
1 parent a8c4bdd commit 5b1fda8

File tree

10 files changed

+48
-11
lines changed

10 files changed

+48
-11
lines changed
 

‎containers/Layout/index.style.js

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export default styled.div`
55
flex-direction: column;
66
#main-content {
77
min-height: calc(100vh - 171px);
8+
padding: 32px 20px 0 20px;
89
border-top: 1px solid rgb(231,231,231);
910
border-bottom: 1px solid rgb(231,231,231);
1011
}

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "yibozi",
33
"version": "1.0.0",
44
"scripts": {
5-
"dev": "node server.js",
5+
"dev": "nodemon server.js",
66
"build": "next build",
77
"start": "NODE_ENV=production node server.js"
88
},

‎pages/article/editor/index.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@ const DynamicBraftEditorNossr = dynamic(
1515
);
1616

1717
const Editor = () => {
18-
const [ editorState, setEditorState ] = useState(null);
18+
const [ editorState = {}, setEditorState ] = useState({});
1919
// useEffect只在客户端调用
20-
useEffect(() => {
21-
const editorState = JSON.parse(localStorage.getItem('editorState') || '{}');
22-
setEditorState(editorState);
23-
}, []);
20+
// useEffect(() => {
21+
// setEditorState();
22+
// }, []);
2423

2524
// 保持文章方法
2625
const handleSubmitEditorState = async (submitData) => {

‎pages/article/index.style.jsx

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import styled from 'styled-components';
22

33
export default styled.div`
4-
padding: 32px 20px 0 20px;
54
.article-list {
65
display: flex;
76
flex-direction: row;

‎pages/home/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const Index = () => {
1111
<title>YIBOZI</title>
1212
</Head>
1313
<Style>
14+
home
1415
</Style>
1516
</Layout>
1617
);

‎server/controllers/article/check.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const { ArticleMolel } = require('../../models');
2+
3+
module.exports = async (ctx) => {
4+
const uuid = ctx.params.uuid;
5+
try {
6+
if (uuid) {
7+
const data = await ArticleMolel.findOne({ uuid });
8+
if(data) {
9+
ctx.state = {
10+
code: 0,
11+
data
12+
};
13+
}else {
14+
ctx.state = {
15+
code: -3,
16+
data: { msg: '暂无此数据' },
17+
};
18+
}
19+
} else {
20+
ctx.state = {
21+
code: -2,
22+
data: { msg: '参数不正确' },
23+
};
24+
}
25+
} catch (e) {
26+
ctx.state = {
27+
code: -1,
28+
data: {
29+
errorInfo: e,
30+
msg: '失败'
31+
},
32+
};
33+
}
34+
};

‎server/controllers/navigation/list.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module.exports = async (ctx) => {
1313
{
1414
id: 2,
1515
parent_id: 0,
16-
name: '博文',
16+
name: '文章',
1717
key:'article',
1818
path: '/article',
1919
asPath:'/article',

‎server/models/Article.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const { createuuid } = require('../utils');
66
// article 会自动加s去找数据库的集合 忽略大写
77
module.exports = mongoose.model('article',
88
new Schema({
9-
'uuid': { type: String, default: createuuid(8,16) }, // id
9+
'uuid': { type: String, default: () => createuuid(8,16) }, // id
1010
'title': { type: String }, // 文章标题
1111
'type': { type: String }, // 文章类别
1212
'createTime': { type: Number }, // 创建时间

‎server/models/Goods.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const { createuuid } = require('../utils');
66
// goods 会自动加s去找数据库的集合 忽略大写
77
module.exports = mongoose.model('good',
88
new Schema({
9-
'uuid': { type: String, default: createuuid(8,16) }, // id
9+
'uuid': { type: String, default: () => createuuid(8,16) }, // id
1010
'displayName': { type: String }, // 名称
1111
})
1212
);

‎server/routes/index.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@ router.delete('/api/goods/:uuid', controllers.goods.delete);
1717
/* navigation */
1818
router.get('/api/navigation', controllers.navigation.list );
1919

20-
/* 查找文章 */
20+
/* 查找文章列表 */
2121
router.get('/api/article', controllers.article.list );
2222

23+
/* 查找单个文章(通过id) */
24+
router.get('/api/article/:uuid', controllers.article.check );
25+
2326
/* 添加文章 */
2427
router.post('/api/article', controllers.article.add );
2528

0 commit comments

Comments
 (0)
Please sign in to comment.