Skip to content

Commit

Permalink
1.0.5 优化接口Token校验
Browse files Browse the repository at this point in the history
  • Loading branch information
549595297@qq.com committed Mar 15, 2019
1 parent 70eca3b commit ba8a2ab
Show file tree
Hide file tree
Showing 10 changed files with 242 additions and 201 deletions.
15 changes: 11 additions & 4 deletions src/RepoModule/pages/repo/issues.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { View } from '@tarojs/components'
import { AtIcon } from 'taro-ui'
import {connect} from "@tarojs/redux";
import {PER_PAGE, LOADING_TEXT, REFRESH_STATUS} from "../../../constants/common";

import { hasLogin } from '../../../utils/common'
import IssueList from '../../components/repo/issueList'
import Segment from '../../../components/index/segment'
import Empty from '../../../components/empty/index'
Expand Down Expand Up @@ -204,9 +204,16 @@ class Issues extends Component {
}

addIssue() {
Taro.navigateTo({
url: '/RepoModule/pages/repo/addIssue?path=' + this.state.path + '&repoPath=' + this.state.repoPath
})
if(hasLogin()){
Taro.navigateTo({
url: '/RepoModule/pages/repo/addIssue?path=' + this.state.path + '&repoPath=' + this.state.repoPath
})
}else{
Taro.navigateTo({
url: '/pages/login/login'
})
}

}

onTabChange(index) {
Expand Down
196 changes: 107 additions & 89 deletions src/RepoModule/pages/repo/repo.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,47 +166,53 @@ class Repo extends Component {
}

handleStar() {
Taro.showLoading({title: LOADING_TEXT})
const { isStar, repo } = this.state
let that = this
if (isStar) {
//取消收藏
this.props.dispatch({
type: 'repo/delStar',
payload:{
url: repo.full_name
},
callback: (res) => {
console.log(res);
this.setState({
isStar: false
});
Taro.stopPullDownRefresh();
Taro.hideLoading();
Taro.atMessage({
'message': '取消收藏',
'type': 'error',
})
}
});
} else {
this.props.dispatch({
type: 'repo/doStar',
payload:{
url: repo.full_name
},
callback: (res) => {
this.setState({
isStar: true
});
Taro.stopPullDownRefresh();
Taro.hideLoading();
Taro.atMessage({
'message': '已收藏',
'type': 'error',
})
}
});
if(hasLogin()){
Taro.showLoading({title: LOADING_TEXT})
const { isStar, repo } = this.state
let that = this
if (isStar) {
//取消收藏
this.props.dispatch({
type: 'repo/delStar',
payload:{
url: repo.full_name
},
callback: (res) => {
console.log(res);
this.setState({
isStar: false
});
Taro.stopPullDownRefresh();
Taro.hideLoading();
Taro.atMessage({
'message': '取消收藏',
'type': 'error',
})
}
});
} else {
this.props.dispatch({
type: 'repo/doStar',
payload:{
url: repo.full_name
},
callback: (res) => {
this.setState({
isStar: true
});
Taro.stopPullDownRefresh();
Taro.hideLoading();
Taro.atMessage({
'message': '已收藏',
'type': 'error',
})
}
});
}
}else{
Taro.navigateTo({
url: '/pages/login/login'
})
}
}

Expand All @@ -232,69 +238,81 @@ class Repo extends Component {
}

handleWatch() {
Taro.showLoading({title: LOADING_TEXT})
const { isWatch, repo } = this.state
let that = this
if (isWatch) {
//取消收藏
this.props.dispatch({
type: 'repo/delWatch',
payload:{
url: repo.full_name
},
callback: (res) => {
this.setState({
isWatch: false
});
Taro.stopPullDownRefresh();
Taro.hideLoading();
Taro.atMessage({
'message': '取消关注',
'type': 'error',
})
}
});
} else {
if(hasLogin()){
Taro.showLoading({title: LOADING_TEXT})
const { isWatch, repo } = this.state
let that = this
if (isWatch) {
//取消收藏
this.props.dispatch({
type: 'repo/delWatch',
payload:{
url: repo.full_name
},
callback: (res) => {
this.setState({
isWatch: false
});
Taro.stopPullDownRefresh();
Taro.hideLoading();
Taro.atMessage({
'message': '取消关注',
'type': 'error',
})
}
});
} else {
this.props.dispatch({
type: 'repo/doWatch',
payload:{
url: repo.full_name
},
callback: (res) => {
console.log(res);
this.setState({
isWatch: true
});
Taro.stopPullDownRefresh();
Taro.hideLoading();
Taro.atMessage({
'message': '已关注',
'type': 'error',
})
}
});
}
}else{
Taro.navigateTo({
url: '/pages/login/login'
})
}
}

handleFork() {
if(hasLogin()){
Taro.showLoading({title: LOADING_TEXT})
const { repo } = this.state
this.props.dispatch({
type: 'repo/doWatch',
type: 'repo/doFork',
payload:{
url: repo.full_name
},
callback: (res) => {
console.log(res);
this.setState({
isWatch: true
});
Taro.stopPullDownRefresh();
Taro.hideLoading();
Taro.atMessage({
'message': '已关注',
'message': 'Fork成功~',
'type': 'error',
})
}
});
}else{
Taro.navigateTo({
url: '/pages/login/login'
})
}
}

handleFork() {
Taro.showLoading({title: LOADING_TEXT})
const { repo } = this.state
this.props.dispatch({
type: 'repo/doFork',
payload:{
url: repo.full_name
},
callback: (res) => {
Taro.stopPullDownRefresh();
Taro.hideLoading();
Taro.atMessage({
'message': 'Fork成功~',
'type': 'error',
})
}
});
}

handleNavigate(type) {
const { repo } = this.state
switch (type) {
Expand Down
20 changes: 5 additions & 15 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,7 @@ class App extends Component {
text: '动态',
iconPath: './asset/images/tab/dynamic.png',
selectedIconPath: './asset/images/tab/dynamic_focus.png'
}, {
pagePath: 'pages/chat/index',
text: '私信',
iconPath: './asset/images/tab/chat.png',
selectedIconPath: './asset/images/tab/chat_focus.png'
}, {
},{
pagePath: 'pages/mine/index',
text: '我的',
iconPath: './asset/images/tab/mine.png',
Expand All @@ -120,22 +115,17 @@ class App extends Component {
traceUser: true
})
this.updateApp();
if(!hasLogin()){
Taro.navigateTo({
url: '/pages/login/login'
})
}else{
if(hasLogin()){
if(checkExpiresToken()){
tokenRequest()
}else {

}
}
}

componentDidShow () {
Taro.setTabBarBadge({
index: 2,
text: '1'
})

}

componentDidHide () {}
Expand Down
68 changes: 32 additions & 36 deletions src/pages/index/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,10 @@ export default class Index extends Component {
isLogin: hasLogin()
},()=>{
const {isLogin} = this.state;
this.loadNotice();
this.loadHistory();
if(isLogin){
if(!checkExpiresToken()){
this.loadNotice();
this.loadHistory();
}else {
if(checkExpiresToken()) {
this.setState({
isLogin: false,
},() => {
Expand Down Expand Up @@ -163,39 +162,36 @@ export default class Index extends Component {
}
return (
<View>
{
isLogin ? (
<View className='content'>
{
(notice.status && !notice_closed) &&
<AtNoticebar icon='volume-plus'
close
onClose={this.onCloseNotice.bind(this)}>
{notice.notice_content}
</AtNoticebar>
}
<View className='search-bar-fixed'>
<SearchBar onClickSearch={this.onClickSearch} />
<View className='content'>
{
(notice.status && !notice_closed) &&
<AtNoticebar icon='volume-plus'
close
onClose={this.onCloseNotice.bind(this)}>
{notice.notice_content}
</AtNoticebar>
}
<View className='search-bar-fixed'>
<SearchBar onClickSearch={this.onClickSearch} />
</View>
{
history.length > 0 &&
<View className='search-history-bg'>
<View className='search-history'>
<SearchHistory items={history} onTagClick={this.onTagClick}/>
</View>
{
history.length > 0 &&
<View className='search-history-bg'>
<View className='search-history'>
<SearchHistory items={history} onTagClick={this.onTagClick}/>
</View>
<View className='clear' onClick={this.clear_history.bind(this)}>Clear All</View>
</View>
}
{ history.length == 0 &&
<View style={{textAlign: 'center', marginTop: '90px'}}>
<Image mode='aspectFit'
className='logo'
src={require('../../asset/images/octocat.png')}/>
<Text className='text'>Giteer For 码云</Text>
</View>
}
</View>):<Login/>
}
<View className='clear' onClick={this.clear_history.bind(this)}>Clear All</View>
</View>
}
{ history.length == 0 &&
<View style={{textAlign: 'center', marginTop: '90px'}}>
<Image mode='aspectFit'
className='logo'
src={require('../../asset/images/octocat.png')}/>
<Text className='text'>Giteer For 码云</Text>
</View>
}
</View>
</View>
)
}
Expand Down
6 changes: 3 additions & 3 deletions src/pages/index/service.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import Taro from '@tarojs/taro';
import Request from '../../utils/request';
import {searchRequest} from '../../utils/otherRequest';

export const getSearchReposList = (data) => Request({
export const getSearchReposList = (data) => searchRequest({
url: '/api/v5/search/repositories',
method: 'GET',
data: data
});

export const getSearchUserList = (data) => Request({
export const getSearchUserList = (data) => searchRequest({
url: '/api/v5/search/users',
method: 'GET',
data: data
Expand Down
Loading

0 comments on commit ba8a2ab

Please sign in to comment.