@@ -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 (
;
return (
diff --git a/src/router/index.js b/src/router/index.js
index 4711670..81beb2f 100644
--- a/src/router/index.js
+++ b/src/router/index.js
@@ -1,11 +1,20 @@
import React from 'react';
import { Router } from 'react-router';
-import routes from '../routes/Root';
+import routes from '../routes/Root/app';
import routing, { history } from '../store/routing';
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/Main/index.js b/src/routes/Main/index.js
index 637fca5..b38b291 100644
--- a/src/routes/Main/index.js
+++ b/src/routes/Main/index.js
@@ -6,7 +6,7 @@ export default {
path: '/',
indexRoute:{
getComponent (location, callback) {
- import('../../pages/Main/Default').then(module => {
+ 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/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/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/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/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/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/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/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();
diff --git a/src/store/session.js b/src/store/session.js
index 53b1d88..d199223 100644
--- a/src/store/session.js
+++ b/src/store/session.js
@@ -17,9 +17,9 @@ class Session {
constructor (obj) {
this.init(obj);
}
-
+
@action.bound
- init ({accesstoken, loginname, id}) {
+ init ({accesstoken, loginname, id} = {}) {
this.accesstoken = accesstoken ? JSON.parse(accesstoken) : '';
this.loginname = loginname ? JSON.parse(loginname) : '';
this.id = id ? JSON.stringify(id) : '';
@@ -34,7 +34,7 @@ class Session {
this.accesstoken = value;
}
- @action.bound
+ @action.bound
async login () {
try {
status.setSubmitting(true);
@@ -53,13 +53,13 @@ class Session {
Toast.fail('登录失败', 1);
} finally {
console.log(status);
- status.setSubmitting(false);
+ status.setSubmitting(false);
}
}
@action.bound
clear () {
- this.init({});
+ this.init();
}
@action.bound
@@ -72,4 +72,4 @@ class Session {
-export default new Session(db.get(keys));
\ No newline at end of file
+export default new Session(db.get(keys));
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));