Showing
1 changed file
with
40 additions
and
18 deletions
| @@ -11,7 +11,8 @@ import { | @@ -11,7 +11,8 @@ import { | ||
| 11 | ListView, | 11 | ListView, |
| 12 | Share, | 12 | Share, |
| 13 | TouchableOpacity, | 13 | TouchableOpacity, |
| 14 | - AsyncStorage | 14 | + AsyncStorage, |
| 15 | + Alert | ||
| 15 | } from "react-native"; | 16 | } from "react-native"; |
| 16 | import { StackNavigator, TabNavigator } from "react-navigation"; | 17 | import { StackNavigator, TabNavigator } from "react-navigation"; |
| 17 | import post from "../utils/fetch"; | 18 | import post from "../utils/fetch"; |
| @@ -56,24 +57,45 @@ export default class ArticleTemplate extends Component { | @@ -56,24 +57,45 @@ export default class ArticleTemplate extends Component { | ||
| 56 | 57 | ||
| 57 | share() { | 58 | share() { |
| 58 | const that = this; | 59 | const that = this; |
| 59 | - Share.share( | 60 | + AsyncStorage.multiGet(["IS_LOGIN", "USER_ID"], (err, result) => { |
| 60 | - { | 61 | + if (err) { |
| 61 | - title: "保护神", | 62 | + console.error(err); |
| 62 | - message: that.state.articleData.title, | ||
| 63 | - url: | ||
| 64 | - that.state.type == "home" | ||
| 65 | - ? `https://devpay.brae.co/insurance.html?uid=${this.state | ||
| 66 | - .USER_ID}&tid=${this.state.id}` | ||
| 67 | - : `https://devpay.brae.co/insurance.html?uid=${this.state | ||
| 68 | - .USER_ID}&sid=${this.state.id}` | ||
| 69 | - }, | ||
| 70 | - { | ||
| 71 | - excludedActivityTypes: ["com.apple.UIKit.activity.PostToTwitter"], | ||
| 72 | - tintColor: "green" | ||
| 73 | } | 63 | } |
| 74 | - ) | 64 | + that.setState( |
| 75 | - .then(that._showResult) | 65 | + { |
| 76 | - .catch(error => this.setState({ result: "error: " + error.message })); | 66 | + IS_LOGIN: result[0][1], |
| 67 | + USER_ID: result[1][1] != null ? result[1][1] : "" | ||
| 68 | + }, | ||
| 69 | + () => { | ||
| 70 | + if (that.state.IS_LOGIN != "yes") { | ||
| 71 | + Alert.alert("请先登录账号"); | ||
| 72 | + } else { | ||
| 73 | + Share.share( | ||
| 74 | + { | ||
| 75 | + title: "保护神", | ||
| 76 | + message: that.state.articleData.title, | ||
| 77 | + url: | ||
| 78 | + that.state.type == "home" | ||
| 79 | + ? `https://devpay.brae.co/insurance.html?uid=${this.state | ||
| 80 | + .USER_ID}&tid=${that.state.id}` | ||
| 81 | + : `https://devpay.brae.co/insurance.html?uid=${this.state | ||
| 82 | + .USER_ID}&sid=${that.state.id}` | ||
| 83 | + }, | ||
| 84 | + { | ||
| 85 | + excludedActivityTypes: [ | ||
| 86 | + "com.apple.UIKit.activity.PostToTwitter" | ||
| 87 | + ], | ||
| 88 | + tintColor: "green" | ||
| 89 | + } | ||
| 90 | + ) | ||
| 91 | + .then(that._showResult) | ||
| 92 | + .catch(error => | ||
| 93 | + this.setState({ result: "error: " + error.message }) | ||
| 94 | + ); | ||
| 95 | + } | ||
| 96 | + } | ||
| 97 | + ); | ||
| 98 | + }); | ||
| 77 | } | 99 | } |
| 78 | 100 | ||
| 79 | getAsyncStorage() { | 101 | getAsyncStorage() { |
-
Please register or login to post a comment