@@ -81,4 +81,4 @@ const ListItem = ({item, index, length}) => {
);
};
-export default ListItem;
+export default HomeListItem;
diff --git a/src/pages/Main/Default.js b/src/pages/Main/Default.js
index 604251e..696a6ac 100644
--- a/src/pages/Main/Default.js
+++ b/src/pages/Main/Default.js
@@ -54,9 +54,12 @@ class MyTabs extends React.Component {
onChange={this.changeType}
>
{
- Object.entries(tabs).map((item, index) =>
+ Object.entries(tabs).map((item) =>
(
))
}
diff --git a/src/pages/Publish/index.js b/src/pages/Publish/index.js
index e5bf489..be51721 100644
--- a/src/pages/Publish/index.js
+++ b/src/pages/Publish/index.js
@@ -1,6 +1,5 @@
import React from 'react';
import { SimpleNavbar } from '../../components/NavBar';
-import Success from './Success';
import { InputItem, TextareaItem, Tabs, Button, Picker, List } from 'antd-mobile';
import { inject, observer } from 'mobx-react';
@@ -44,9 +43,8 @@ class Publish extends React.Component {
render () {
- const { title, tab, error, markdown, canSubmit, finish } = this.props.publish;
+ const { title, tab, error, markdown, canSubmit } = this.props.publish;
const { submitting } = this.props;
- if (finish) return
diff --git a/src/router/index.js b/src/router/index.js
index 4711670..97e1a47 100644
--- a/src/router/index.js
+++ b/src/router/index.js
@@ -6,6 +6,15 @@ import global from '../store/global';
import session from '../store/session';
import { Toast } from 'antd-mobile';
+
+//路径与对应的底部tab的映射表
+export const RouteTabMap = {
+ '/': 'home',
+ '/publish': 'publish',
+ '/message': 'message',
+ '/mine': 'mine'
+}
+
history.listen(location => {
const currentPathname = location.pathname;
// 路由变化时,记录旧新路由
@@ -32,6 +41,13 @@ history.listen(location => {
routing.goBack();
}
});
+
+ //路由切换时确保底部当前tab与路由一致
+ let correspondTab = RouteTabMap[currentPathname]
+ if(correspondTab && global.tab !== correspondTab) {
+ global.updateVal('tab', correspondTab)
+ }
+
})
const Root = (props) => {
diff --git a/src/routes/Publish/success.js b/src/routes/Publish/success.js
new file mode 100644
index 0000000..9a7d585
--- /dev/null
+++ b/src/routes/Publish/success.js
@@ -0,0 +1,6 @@
+export default {
+ path: '/publish/success',
+ getComponent (location, callback) {
+ import('../../pages/Publish/Success').then(module => callback(null, module.default));
+ }
+}
diff --git a/src/routes/Root/index.js b/src/routes/Root/index.js
index 284ae53..764b1cf 100644
--- a/src/routes/Root/index.js
+++ b/src/routes/Root/index.js
@@ -5,6 +5,7 @@ import Reply from '../Mine/reply';
import Topic from '../Mine/topic';
import Collection from '../Mine/collection';
import Login from '../Login';
+import PublishSuccess from '../Publish/success'
export default [
Main,
@@ -13,5 +14,6 @@ export default [
Collection,
Topic,
Detail,
- Login
+ Login,
+ PublishSuccess
];
diff --git a/src/store/global.js b/src/store/global.js
index 3911b68..d45376f 100644
--- a/src/store/global.js
+++ b/src/store/global.js
@@ -1,6 +1,8 @@
import { observable, action, useStrict } from 'mobx';
import routing from './routing';
import db from '../utils/db';
+import {RouteTabMap} from '../router/index'
+
useStrict(true);
const LinkToWhiteList = ['/', '/message', '/publish', '/mine'];
@@ -33,6 +35,7 @@ class Global {
this[key] = val;
}
+ //tab切换 + 路由切换
@action.bound
changeTab (tab) {
this.tab = tab;
@@ -41,16 +44,16 @@ class Global {
}
LinkTo () {
- switch (this.tab) {
- case 'home': routing.push('/'); break;
- case 'publish': routing.push('/publish'); break;
- case 'message': routing.push('/message'); break;
- case 'mine': routing.push('/mine'); break;
- default: return;
+ for(let key in RouteTabMap) {
+ let value = RouteTabMap[key]
+ if(value === this.tab) {
+ routing.push(key)
+ break
+ }
}
}
}
const self = new Global(db.get(['tab', 'from', 'to']));
-export default self;
\ No newline at end of file
+export default self;
diff --git a/src/store/publish.js b/src/store/publish.js
index 5f5326f..b4e0d56 100644
--- a/src/store/publish.js
+++ b/src/store/publish.js
@@ -35,7 +35,8 @@ marked.setOptions({
class Publish {
@observable content = '';
@observable title = '';
- @observable tab = ['ask'];
+ //默认发到客户端测试版块
+ @observable tab = ['dev'];
@observable error = {
title: null,
tab: false,
@@ -82,7 +83,7 @@ class Publish {
runInAction(() => {
this.finish = true;
});
- routing.push('/success');
+ routing.push('/publish/success');
} catch (err) {
Toast.fail('发布失败,稍后再试', 1);
} finally {
@@ -104,4 +105,4 @@ class Publish {
}
}
-export default new Publish();
\ No newline at end of file
+export default new Publish();
From f6d618609d71f235921d545525daa13330859527 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=AD=99=E6=99=A8=E5=85=89?= <809200299@qq.com>
Date: Sat, 3 Mar 2018 17:07:19 +0800
Subject: [PATCH 5/7] =?UTF-8?q?update:=20=E6=B7=BB=E5=8A=A0=E5=85=A8?=
=?UTF-8?q?=E5=B1=80loading,=20=E9=81=BF=E5=85=8D=E5=88=B0=E5=A4=84?=
=?UTF-8?q?=E5=BC=95=E7=94=A8=E3=80=82=E9=A6=96=E9=A1=B5tab=E5=8A=A0?=
=?UTF-8?q?=E5=85=A5=E5=AE=A2=E6=88=B7=E7=AB=AF=E6=B5=8B=E8=AF=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 6 ++++-
src/components/List/index.js | 13 ++++------
src/components/Loading/index.js | 9 +++++--
src/pages/Detail/index.js | 29 ++++++++++-------------
src/pages/Homepage/index.js | 3 ---
src/pages/Main/app.js | 27 +++++++++++++++++++++
src/pages/Main/{Default.js => myTabs.js} | 3 ++-
src/pages/Message/index.js | 6 ++---
src/pages/Mine/StateLess.js | 4 +---
src/pages/Mine/index.js | 4 +---
src/router/index.js | 2 +-
src/routes/Main/index.js | 4 ++--
src/routes/Root/app.js | 11 +++++++++
src/store/collections.js | 2 +-
src/store/detail.js | 9 +++++--
src/store/messages.js | 30 ++++++++++++++++++------
src/store/topics.js | 8 ++++---
17 files changed, 111 insertions(+), 59 deletions(-)
create mode 100644 src/pages/Main/app.js
rename src/pages/Main/{Default.js => myTabs.js} (97%)
create mode 100644 src/routes/Root/app.js
diff --git a/README.md b/README.md
index 2b61ff1..4db7ac5 100644
--- a/README.md
+++ b/README.md
@@ -56,12 +56,16 @@ react-cnode/
- 升级 antd-mobile 到 2.x
-- 开发环境添加mobx devtool
+- ~~开发环境添加mobx devtool 没什么实际作用,不添加~~
### bug
- 未登录时,点击用户中心,会进入登录页,点击X,退出到首页,但是footer图标还是用户中心。
- 发布主题后,点击继续发布报错,不能继续发布。
+### 特性
+- 首页顶部tab添加客户端测试tab(key为dev),完成
+- 把loading组件拿出来放到最外面,避免在每个用到的地方都写一遍
+
### 如何启动
Step 1
```
diff --git a/src/components/List/index.js b/src/components/List/index.js
index 7712b61..7627327 100644
--- a/src/components/List/index.js
+++ b/src/components/List/index.js
@@ -1,16 +1,11 @@
import React from 'react'
import { ListView, RefreshControl } from 'antd-mobile';
-import Loading from '../Loading';
import PropTypes from 'prop-types';
const MyBody = (props) => (
{props.children}
);
-const Footer = () => (
-
-);
-
class List extends React.Component {
static propTypes = {
disableRefresh: PropTypes.bool,
@@ -118,7 +113,7 @@ class List extends React.Component {
}
render () {
- const { loading, refreshing, disableRefresh, disableLoadMore, useBodyScroll, ListItem, data, height } = this.props;
+ const { refreshing, disableRefresh, disableLoadMore, useBodyScroll, ListItem, data, height } = this.props;
const { dataSource } = this.state;
if (useBodyScroll) {
return (
@@ -129,7 +124,7 @@ class List extends React.Component {
pageSize={10}
useBodyScroll
renderRow={(rowData, sIndex, rIndex) =>
}
- renderFooter={() => loading ?
: null}
+ renderFooter={() => null}
/>
);
} else {
@@ -145,7 +140,7 @@ class List extends React.Component {
renderBodyComponent={() =>
}
onEndReached={disableLoadMore ? null : this.loadMore}
renderRow={(rowData, sIndex, rIndex) =>
}
- renderFooter={() => loading ?
: null}
+ renderFooter={() => null}
refreshControl={
!disableRefresh ?
: null
}
@@ -158,4 +153,4 @@ class List extends React.Component {
};
}
-export default List;
\ No newline at end of file
+export default List;
diff --git a/src/components/Loading/index.js b/src/components/Loading/index.js
index c4f6ce2..6ef687d 100644
--- a/src/components/Loading/index.js
+++ b/src/components/Loading/index.js
@@ -3,8 +3,13 @@ import { Flex, ActivityIndicator } from 'antd-mobile';
const Loading = (props) => {
return (
-
+
+
+
);
}
-export default Loading;
\ No newline at end of file
+export default Loading;
diff --git a/src/pages/Detail/index.js b/src/pages/Detail/index.js
index 4688621..69da58d 100644
--- a/src/pages/Detail/index.js
+++ b/src/pages/Detail/index.js
@@ -1,6 +1,5 @@
import React from 'react'
import { Popup, Toast } from 'antd-mobile';
-import Loading from '../../components/Loading';
import { BackNavBar } from '../../components/NavBar';
import BackTop from './components/BackTop';
import Comment from './components/Comment';
@@ -88,23 +87,19 @@ class Detail extends React.Component {
}
render () {
- const { loading } = this.props;
- if (loading) {
- return (
);
- } else {
- return (
-
-
-
-
-
-
-
-
-
+
+ return (
+
+ );
}
}
diff --git a/src/pages/Homepage/index.js b/src/pages/Homepage/index.js
index 6cd174c..ab36d30 100644
--- a/src/pages/Homepage/index.js
+++ b/src/pages/Homepage/index.js
@@ -1,7 +1,6 @@
import React from 'react';
import BusinessCard from '../../components/BusinessCard';
import { BackNavBar } from '../../components/NavBar';
-import Loading from '../../components/Loading';
import RecentReplies from './components/RecentReplies';
import RecentTopics from './components/RecentTopics';
import { Tabs } from 'antd-mobile';
@@ -42,8 +41,6 @@ class Homepage extends React.Component {
}
render () {
- const { loading } = this.props;
- if (loading) return
return (
diff --git a/src/pages/Main/app.js b/src/pages/Main/app.js
new file mode 100644
index 0000000..e57d1aa
--- /dev/null
+++ b/src/pages/Main/app.js
@@ -0,0 +1,27 @@
+import React from 'react';
+import { inject, observer } from 'mobx-react';
+import Loading from '../../components/Loading'
+
+@inject(({status}) => ({
+ loading: status.loading
+}))
+@observer
+class App extends React.Component {
+
+ render () {
+ const {loading, children} = this.props;
+ return (
+
+ {loading && }
+ {children}
+
+ );
+ }
+}
+
+export default App;
diff --git a/src/pages/Main/Default.js b/src/pages/Main/myTabs.js
similarity index 97%
rename from src/pages/Main/Default.js
rename to src/pages/Main/myTabs.js
index 696a6ac..883d039 100644
--- a/src/pages/Main/Default.js
+++ b/src/pages/Main/myTabs.js
@@ -9,7 +9,8 @@ const tabs = {
good: '精华',
share: '分享',
ask: '问答',
- job: '招聘'
+ job: '招聘',
+ dev: '客户端测试'
}
@inject(({topics, status}) => ({
loading: status.loading,
diff --git a/src/pages/Message/index.js b/src/pages/Message/index.js
index d46a118..241c46e 100644
--- a/src/pages/Message/index.js
+++ b/src/pages/Message/index.js
@@ -1,7 +1,6 @@
import React from 'react';
import { SimpleNavbar } from '../../components/NavBar';
import { inject, observer } from 'mobx-react';
-import Loading from '../../components/Loading';
import ListItem from './components/MessageListItem';
import List from '../../components/List';
@@ -21,8 +20,7 @@ class Message extends React.Component {
}
render () {
- const { loading, messages } = this.props;
- if (loading) return
;
+ const { messages } = this.props;
return (
@@ -40,4 +38,4 @@ class Message extends React.Component {
}
}
-export default Message;
\ No newline at end of file
+export default Message;
diff --git a/src/pages/Mine/StateLess.js b/src/pages/Mine/StateLess.js
index e489c95..17e15c9 100644
--- a/src/pages/Mine/StateLess.js
+++ b/src/pages/Mine/StateLess.js
@@ -1,7 +1,6 @@
import React, { Component } from 'react';
import List from '../../components/List';
import { BackNavBar } from '../../components/NavBar';
-import Loading from '../../components/Loading';
import ListItem from '../../components/ListItem';
@@ -11,8 +10,7 @@ export default class Stateless extends Component {
}
render () {
- const { loading, title, _loading, loadMore, data } = this.props;
- if (loading) return
+ const { title, _loading, loadMore, data } = this.props;
return (
diff --git a/src/pages/Mine/index.js b/src/pages/Mine/index.js
index 55d8949..a5e37c1 100644
--- a/src/pages/Mine/index.js
+++ b/src/pages/Mine/index.js
@@ -1,6 +1,5 @@
import React from 'react'
import BusinessCard from '../../components/BusinessCard';
-import Loading from '../../components/Loading';
import { SimpleNavbar } from '../../components/NavBar';
import { List, Icon, Toast } from 'antd-mobile';
import { inject, observer } from 'mobx-react';
@@ -30,8 +29,7 @@ class Mine extends React.Component {
}
render () {
- const { logout, loading, push } = this.props;
- if (loading) return (
);
+ const { logout, push } = this.props;
return (
{
+ import('../../pages/Main/myTabs').then(module => {
callback(null, module.default)
});
}
@@ -21,4 +21,4 @@ export default {
Publish,
Message
]
-}
\ No newline at end of file
+}
diff --git a/src/routes/Root/app.js b/src/routes/Root/app.js
new file mode 100644
index 0000000..c42eb49
--- /dev/null
+++ b/src/routes/Root/app.js
@@ -0,0 +1,11 @@
+import IndexRoutes from './index'
+
+export default {
+ path: '',
+ getComponent (location, callback) {
+ import('../../pages/Main/app').then(module => {
+ callback(null, module.default)
+ });
+ },
+ childRoutes: IndexRoutes
+}
diff --git a/src/store/collections.js b/src/store/collections.js
index f1af926..648063e 100644
--- a/src/store/collections.js
+++ b/src/store/collections.js
@@ -74,4 +74,4 @@ class Collections {
}
}
-export default new Collections();
\ No newline at end of file
+export default new Collections();
diff --git a/src/store/detail.js b/src/store/detail.js
index ae327c6..1d0412a 100644
--- a/src/store/detail.js
+++ b/src/store/detail.js
@@ -57,12 +57,17 @@ class Detail {
}
}
+ /**
+ * 获取详情数据后,将所有回复放入this.allReplies,从中取出this.limit条数据放入this.replies
+ * @param allReplies
+ */
@action.bound
setReplies (allReplies) {
for (const r of allReplies) {
this.allReplies.push(new Reply(r));
}
- this.replies = this.allReplies.slice(++this.page * this.limit, this.limit);
+
+ this.replies = this.allReplies.slice(0, this.limit);
}
@action.bound
@@ -135,4 +140,4 @@ class Detail {
}
}
-export default new Detail();
\ No newline at end of file
+export default new Detail();
diff --git a/src/store/messages.js b/src/store/messages.js
index e90a07c..681a888 100644
--- a/src/store/messages.js
+++ b/src/store/messages.js
@@ -6,13 +6,26 @@ import status from './status';
useStrict(true);
class Messages {
- @observable messages = [];
- @observable messageCount = 0;
- @observable loading = false;
- allmessages = [];
- page = 1;
- reachEnd = false;
- limit = 10;
+ @observable messages;
+ @observable messageCount;
+ @observable loading;
+
+ constructor() {
+ this.init()
+ }
+
+
+ @action.bound
+ init() {
+ this.messages = [];
+ this.messageCount = 0;
+ this.loading = false;
+
+ this.allmessages = []
+ this.page = 1;
+ this.reachEnd = false;
+ this.limit = 10;
+ }
@action.bound
async getMessageCount () {
@@ -26,6 +39,9 @@ class Messages {
@action.bound
async getMessages () {
if (!session.accesstoken || status.loading) return;
+
+ this.init()
+
try {
status.setLoading(true);
const { data } = await axios.get(`/messages?accesstoken=${session.accesstoken}`);
diff --git a/src/store/topics.js b/src/store/topics.js
index 54981c3..517c415 100644
--- a/src/store/topics.js
+++ b/src/store/topics.js
@@ -5,6 +5,8 @@ import db from '../utils/db';
useStrict(true);
+const dbFields = ['type', 'page', 'data']
+
class Topics {
@observable type;
@observable data;
@@ -41,7 +43,7 @@ class Topics {
runInAction(() => {
this.data = data.data;
});
- db.save(['type', 'page', 'data'], {
+ db.save(dbFields, {
type,
page: 1,
data: data.data.slice()
@@ -61,7 +63,7 @@ class Topics {
this.data = [...this.data, ...data.data];
this.page++;
this.reachEnd = data.data.length === 0;
- db.save(['type', 'page', 'data'], {
+ db.save(dbFields, {
type: this.type,
page: this.page,
data: this.data.slice()
@@ -78,4 +80,4 @@ class Topics {
}
}
-export default new Topics(db.get(['type', 'data', 'page']));
+export default new Topics(db.get(dbFields));
From f4a34fd6aca3b2b1d7494e2ef0a526a6c134936a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=AD=99=E6=99=A8=E5=85=89?= <809200299@qq.com>
Date: Sun, 4 Mar 2018 17:38:14 +0800
Subject: [PATCH 6/7] =?UTF-8?q?update:=20=E6=81=A2=E5=A4=8Dreadme=E6=96=87?=
=?UTF-8?q?=E4=BB=B6=E5=88=B0=E5=88=9D=E5=A7=8B=E5=86=85=E5=AE=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 14 --------------
1 file changed, 14 deletions(-)
diff --git a/README.md b/README.md
index 4db7ac5..e2c83ca 100644
--- a/README.md
+++ b/README.md
@@ -52,20 +52,6 @@ react-cnode/
- ~~live demo~~
-- 升级 react-router 到4
-
-- 升级 antd-mobile 到 2.x
-
-- ~~开发环境添加mobx devtool 没什么实际作用,不添加~~
-
-### bug
-- 未登录时,点击用户中心,会进入登录页,点击X,退出到首页,但是footer图标还是用户中心。
-- 发布主题后,点击继续发布报错,不能继续发布。
-
-### 特性
-- 首页顶部tab添加客户端测试tab(key为dev),完成
-- 把loading组件拿出来放到最外面,避免在每个用到的地方都写一遍
-
### 如何启动
Step 1
```
From 97369bb3e49db9810f575189cc0d3a4ce7ce394f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=AD=99=E6=99=A8=E5=85=89?= <809200299@qq.com>
Date: Sun, 4 Mar 2018 17:40:14 +0800
Subject: [PATCH 7/7] update: restore readme.md
---
README.md | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index e2c83ca..db63ed6 100644
--- a/README.md
+++ b/README.md
@@ -32,7 +32,7 @@ react-cnode/
│ |
| |—— db.js * localstorage操作
| |
- | |__ index.js * 别的工具函数
+ | |__ index.js * 别的工具函数
│
│
│——constants/ * 一些常量(其实没怎么用)
@@ -52,6 +52,8 @@ react-cnode/
- ~~live demo~~
+- 升级 react-router 到4
+
### 如何启动
Step 1
```