From ba8a2ab6dd796d4a7b7cb0c57b3abb41fbdba2d5 Mon Sep 17 00:00:00 2001 From: "549595297@qq.com" Date: Fri, 15 Mar 2019 10:52:50 +0800 Subject: [PATCH] =?UTF-8?q?1.0.5=20=E4=BC=98=E5=8C=96=E6=8E=A5=E5=8F=A3Tok?= =?UTF-8?q?en=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/RepoModule/pages/repo/issues.js | 15 +- src/RepoModule/pages/repo/repo.js | 196 ++++++++++-------- src/app.js | 20 +- src/pages/index/index.js | 68 +++--- src/pages/index/service.js | 6 +- src/pages/mine/developerInfo/developerInfo.js | 107 +++++----- src/pages/mine/follow/service.js | 1 + src/pages/mine/service.js | 3 +- src/service/repo.js | 7 +- src/utils/otherRequest.js | 20 +- 10 files changed, 242 insertions(+), 201 deletions(-) diff --git a/src/RepoModule/pages/repo/issues.js b/src/RepoModule/pages/repo/issues.js index 5582483..9151eba 100644 --- a/src/RepoModule/pages/repo/issues.js +++ b/src/RepoModule/pages/repo/issues.js @@ -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' @@ -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) { diff --git a/src/RepoModule/pages/repo/repo.js b/src/RepoModule/pages/repo/repo.js index 681a5e4..a76acb9 100644 --- a/src/RepoModule/pages/repo/repo.js +++ b/src/RepoModule/pages/repo/repo.js @@ -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' + }) } } @@ -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) { diff --git a/src/app.js b/src/app.js index 69c6829..42c78d5 100644 --- a/src/app.js +++ b/src/app.js @@ -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', @@ -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 () {} diff --git a/src/pages/index/index.js b/src/pages/index/index.js index 666b5c0..6fbf8ed 100644 --- a/src/pages/index/index.js +++ b/src/pages/index/index.js @@ -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, },() => { @@ -163,39 +162,36 @@ export default class Index extends Component { } return ( - { - isLogin ? ( - - { - (notice.status && !notice_closed) && - - {notice.notice_content} - - } - - + + { + (notice.status && !notice_closed) && + + {notice.notice_content} + + } + + + + { + history.length > 0 && + + + - { - history.length > 0 && - - - - - Clear All - - } - { history.length == 0 && - - - Giteer For 码云 - - } - ): - } + Clear All + + } + { history.length == 0 && + + + Giteer For 码云 + + } + ) } diff --git a/src/pages/index/service.js b/src/pages/index/service.js index 9b54c8e..8b1969d 100644 --- a/src/pages/index/service.js +++ b/src/pages/index/service.js @@ -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 diff --git a/src/pages/mine/developerInfo/developerInfo.js b/src/pages/mine/developerInfo/developerInfo.js index 040de13..3a3b5a6 100644 --- a/src/pages/mine/developerInfo/developerInfo.js +++ b/src/pages/mine/developerInfo/developerInfo.js @@ -71,64 +71,73 @@ class DeveloperInfo extends Component { this.setState({ developerInfo: res }, ()=>{ - this.checkFollowing() + if(hasLogin()){ + this.checkFollowing() + }else{ + Taro.stopPullDownRefresh(); + Taro.hideLoading(); + } }) } }); } checkFollowing() { - if (hasLogin()) { - const { username } = this.state; - this.props.dispatch({ - type: 'follow/checkFollowing', - payload:{ - username: username - }, - callback: (res) => { - this.setState({ - isFollowed: res.isFollow - }); - Taro.stopPullDownRefresh(); - Taro.hideLoading(); - } - }); - } + const { username } = this.state; + this.props.dispatch({ + type: 'follow/checkFollowing', + payload:{ + username: username + }, + callback: (res) => { + this.setState({ + isFollowed: res.isFollow + }); + Taro.stopPullDownRefresh(); + Taro.hideLoading(); + } + }); } handleFollow() { - const { isFollowed, username } = this.state; - if (isFollowed) { - //取消关注 - this.props.dispatch({ - type: 'follow/unFollowed', - payload:{ - username: username - }, - callback: (res) => { - console.log(res); - this.setState({ - isFollowed: false - }); - Taro.stopPullDownRefresh(); - Taro.hideLoading(); - } - }); - } else { - //添加关注 - this.props.dispatch({ - type: 'follow/doFollowed', - payload:{ - username: username - }, - callback: (res) => { - this.setState({ - isFollowed: true - }); - Taro.stopPullDownRefresh(); - Taro.hideLoading(); - } - }); + if(hasLogin()){ + const { isFollowed, username } = this.state; + if (isFollowed) { + //取消关注 + this.props.dispatch({ + type: 'follow/unFollowed', + payload:{ + username: username + }, + callback: (res) => { + console.log(res); + this.setState({ + isFollowed: false + }); + Taro.stopPullDownRefresh(); + Taro.hideLoading(); + } + }); + } else { + //添加关注 + this.props.dispatch({ + type: 'follow/doFollowed', + payload:{ + username: username + }, + callback: (res) => { + this.setState({ + isFollowed: true + }); + Taro.stopPullDownRefresh(); + Taro.hideLoading(); + } + }); + } + }else{ + Taro.navigateTo({ + url: '/pages/login/login' + }) } } diff --git a/src/pages/mine/follow/service.js b/src/pages/mine/follow/service.js index 26883de..350cc24 100644 --- a/src/pages/mine/follow/service.js +++ b/src/pages/mine/follow/service.js @@ -1,5 +1,6 @@ import Taro from '@tarojs/taro'; import Request from '../../../utils/request'; +import {repoRequest} from '../../../utils/otherRequest'; import {METHOD_TYPE} from '../../../constants/methodType' //列出授权用户的所有仓库 diff --git a/src/pages/mine/service.js b/src/pages/mine/service.js index e790076..9623fd6 100644 --- a/src/pages/mine/service.js +++ b/src/pages/mine/service.js @@ -1,5 +1,6 @@ import Taro from '@tarojs/taro'; import Request from '../../utils/request'; +import {repoRequest} from '../../utils/otherRequest'; //获取授权用户的资料 export const getMine = () =>Request({ @@ -7,7 +8,7 @@ export const getMine = () =>Request({ method: 'GET', }); //获取一个用户 -export const getUser = data =>Request({ +export const getUser = data =>repoRequest({ url: '/api/v5/users/'+ data.username, method: 'GET', data: {} diff --git a/src/service/repo.js b/src/service/repo.js index f3668d7..ea83667 100644 --- a/src/service/repo.js +++ b/src/service/repo.js @@ -1,15 +1,16 @@ import Taro from '@tarojs/taro'; import Request from '../utils/request'; -import {fileRequest} from '../utils/otherRequest'; +import {fileRequest,repoRequest} from '../utils/otherRequest'; import {METHOD_TYPE} from "../constants/methodType"; //列出授权用户的某个仓库 -export const getRepo = (data) =>Request({ +export const getRepo = (data) =>repoRequest({ url: '/api/v5/repos/'+data.url, method: 'GET', }); + //获取仓库README -export const getReadme = (data) =>Request({ +export const getReadme = (data) =>repoRequest({ url: '/api/v5/repos/'+data.url+'/readme', method: 'GET', }); diff --git a/src/utils/otherRequest.js b/src/utils/otherRequest.js index 7aaf98a..6a2011f 100644 --- a/src/utils/otherRequest.js +++ b/src/utils/otherRequest.js @@ -1,5 +1,5 @@ import Taro from "@tarojs/taro"; - +import {baseUrl} from "../config"; export const tokenRequest = () => { Taro.request({ url: 'https://gitee.com/oauth/token', @@ -22,3 +22,21 @@ export const fileRequest = (options) => Taro.request({ }).then(res => { return res.data; }); + +export const searchRequest = (options) => Taro.request({ + url: baseUrl+options.url, + data: { ...options.data }, + header: { 'content-type': 'application/json' }, + method: options.method.toUpperCase() +}).then(res => { + return res.data; +}); + +export const repoRequest = (options) => Taro.request({ + url: baseUrl+options.url, + data: { ...options.data }, + header: { 'content-type': 'application/json' }, + method: options.method.toUpperCase() +}).then(res => { + return res.data; +});