Showing
10 changed files
with
333 additions
and
259 deletions
.eslintrc.json
0 → 100644
| 1 | +{ | ||
| 2 | + "env": { | ||
| 3 | + "browser": true, | ||
| 4 | + "es6": true, | ||
| 5 | + "node": true | ||
| 6 | + }, | ||
| 7 | + "extends": [ | ||
| 8 | + "eslint:recommended", | ||
| 9 | + "plugin:react/recommended" | ||
| 10 | + ], | ||
| 11 | + "parserOptions": { | ||
| 12 | + "ecmaFeatures": { | ||
| 13 | + "experimentalObjectRestSpread": true, | ||
| 14 | + "jsx": true | ||
| 15 | + }, | ||
| 16 | + "sourceType": "module" | ||
| 17 | + }, | ||
| 18 | + "plugins": [ | ||
| 19 | + "react" | ||
| 20 | + ], | ||
| 21 | + "rules": { | ||
| 22 | + "indent": [ | ||
| 23 | + "error", | ||
| 24 | + 2, | ||
| 25 | + { | ||
| 26 | + "SwitchCase": 1 | ||
| 27 | + } | ||
| 28 | + ], | ||
| 29 | + "linebreak-style": [ | ||
| 30 | + "error", | ||
| 31 | + "unix" | ||
| 32 | + ], | ||
| 33 | + "quotes": [ | ||
| 34 | + "error", | ||
| 35 | + "single" | ||
| 36 | + ], | ||
| 37 | + "semi": [ | ||
| 38 | + "error", | ||
| 39 | + "always", | ||
| 40 | + { | ||
| 41 | + "omitLastInOneLineBlock": true | ||
| 42 | + } | ||
| 43 | + ], | ||
| 44 | + "react/prop-types": 0 | ||
| 45 | + } | ||
| 46 | +} |
| @@ -21,9 +21,7 @@ import Discover from "./src/pages/Discover/index"; | @@ -21,9 +21,7 @@ import Discover from "./src/pages/Discover/index"; | ||
| 21 | import AIBegin from "./src/pages/Home/AISolution/Begin"; | 21 | import AIBegin from "./src/pages/Home/AISolution/Begin"; |
| 22 | import AIQuestion from "./src/pages/Home/AISolution/Question"; | 22 | import AIQuestion from "./src/pages/Home/AISolution/Question"; |
| 23 | import AISolution from "./src/pages/Home/AISolution/Solution"; | 23 | import AISolution from "./src/pages/Home/AISolution/Solution"; |
| 24 | -import HealthBegin from "./src/pages/Home/HealthQuestionnaire/HealthBegin"; | 24 | +import HealthQuestionnaire from "./src/pages/Home/healthQuestionnaire"; |
| 25 | -import HealthQuestion from "./src/pages/Home/HealthQuestionnaire/HealthQuestion"; | ||
| 26 | -import HealthResult from "./src/pages/Home/HealthQuestionnaire/HealthResult"; | ||
| 27 | 25 | ||
| 28 | // 底部导航栏配置,但也只是作为一个页面,加载到StackNavigator成为第一个页面 | 26 | // 底部导航栏配置,但也只是作为一个页面,加载到StackNavigator成为第一个页面 |
| 29 | const MainTabBar = TabNavigator( | 27 | const MainTabBar = TabNavigator( |
| @@ -127,18 +125,10 @@ const ProtectGod = StackNavigator( | @@ -127,18 +125,10 @@ const ProtectGod = StackNavigator( | ||
| 127 | screen: AISolution, | 125 | screen: AISolution, |
| 128 | navigationOptions: { headerTitle: "智能方案" } | 126 | navigationOptions: { headerTitle: "智能方案" } |
| 129 | }, | 127 | }, |
| 130 | - HealthBegin: { | 128 | + HealthQuestionnaire: { |
| 131 | - screen: HealthBegin, | 129 | + screen: HealthQuestionnaire, |
| 132 | navigationOptions: { headerTitle: "健康问卷" } | 130 | navigationOptions: { headerTitle: "健康问卷" } |
| 133 | - }, | 131 | + } |
| 134 | - HealthQuestion: { | ||
| 135 | - screen: HealthQuestion, | ||
| 136 | - navigationOptions: { headerTitle: "健康问卷" } | ||
| 137 | - }, | ||
| 138 | - HealthResult: { | ||
| 139 | - screen: HealthResult, | ||
| 140 | - navigationOptions: { headerTitle: "健康问卷" } | ||
| 141 | - }, | ||
| 142 | }, | 132 | }, |
| 143 | { | 133 | { |
| 144 | navigationOptions: { | 134 | navigationOptions: { |
| @@ -15,6 +15,8 @@ | @@ -15,6 +15,8 @@ | ||
| 15 | "devDependencies": { | 15 | "devDependencies": { |
| 16 | "babel-jest": "20.0.3", | 16 | "babel-jest": "20.0.3", |
| 17 | "babel-preset-react-native": "3.0.2", | 17 | "babel-preset-react-native": "3.0.2", |
| 18 | + "eslint": "^4.7.2", | ||
| 19 | + "eslint-plugin-react": "^7.4.0", | ||
| 18 | "jest": "20.0.4", | 20 | "jest": "20.0.4", |
| 19 | "react-test-renderer": "16.0.0-alpha.12" | 21 | "react-test-renderer": "16.0.0-alpha.12" |
| 20 | }, | 22 | }, |
src/assets/home/questionnaire.png
0 → 100644
19.9 KB
| 1 | -import React, { Component } from "react"; | ||
| 2 | -import { | ||
| 3 | - AppRegistry, | ||
| 4 | - StyleSheet, | ||
| 5 | - Text, | ||
| 6 | - View, | ||
| 7 | - Image, | ||
| 8 | - TouchableOpacity, | ||
| 9 | - ScrollView, | ||
| 10 | - ListView, | ||
| 11 | - Dimensions, | ||
| 12 | - DatePickerIOS | ||
| 13 | -} from "react-native"; | ||
| 14 | -import { StackNavigator, TabNavigator } from "react-navigation"; | ||
| 15 | - | ||
| 16 | -export default class Home extends Component { | ||
| 17 | - constructor(props) { | ||
| 18 | - super(props); | ||
| 19 | - this.state = { | ||
| 20 | - showDate: false, | ||
| 21 | - date: new Date() | ||
| 22 | - }; | ||
| 23 | - } | ||
| 24 | - componentWillMount() {} | ||
| 25 | - | ||
| 26 | - componentDidMount() {} | ||
| 27 | - | ||
| 28 | - getListData() { | ||
| 29 | - let that = this; | ||
| 30 | - return fetch(`https://devpay.brae.co/test/insurance/topic`, { | ||
| 31 | - method: "POST", | ||
| 32 | - headers: { | ||
| 33 | - Accept: "application/json", | ||
| 34 | - "Content-Type": "application/json" | ||
| 35 | - } | ||
| 36 | - }) | ||
| 37 | - .then(resp => { | ||
| 38 | - if (resp.status === 200) { | ||
| 39 | - return resp.json(); | ||
| 40 | - } else { | ||
| 41 | - console.error("something went wrong!"); | ||
| 42 | - } | ||
| 43 | - }) | ||
| 44 | - .then(respJson => { | ||
| 45 | - if (respJson.enmsg != "ok") { | ||
| 46 | - alert(respJson.cnmsg); | ||
| 47 | - } else { | ||
| 48 | - that.setState({ | ||
| 49 | - ListData: respJson.data.topic | ||
| 50 | - }); | ||
| 51 | - console.log("首页列表", this.state.ListData); | ||
| 52 | - } | ||
| 53 | - }); | ||
| 54 | - } | ||
| 55 | - | ||
| 56 | - render() { | ||
| 57 | - // console.log("首页的this.props", this); | ||
| 58 | - // console.log("render首页文章列表", this.state.ListData); | ||
| 59 | - const { navigate } = this.props.navigation; | ||
| 60 | - return ( | ||
| 61 | - <View style={styles.container}> | ||
| 62 | - <Text>健康问卷开始</Text> | ||
| 63 | - {this.state.showDate ? ( | ||
| 64 | - <DatePickerIOS | ||
| 65 | - style={styles.dateWrapper} | ||
| 66 | - date={this.state.date} | ||
| 67 | - onDateChange={date => this.setState({ date })} | ||
| 68 | - mode="date" | ||
| 69 | - /> | ||
| 70 | - ) : null} | ||
| 71 | - | ||
| 72 | - <TouchableOpacity | ||
| 73 | - onPress={() => { | ||
| 74 | - { | ||
| 75 | - /* alert(this.state.date); */ | ||
| 76 | - } | ||
| 77 | - this.setState({ | ||
| 78 | - showDate: !this.state.showDate | ||
| 79 | - }); | ||
| 80 | - }} | ||
| 81 | - > | ||
| 82 | - <Text>打印时间</Text> | ||
| 83 | - </TouchableOpacity> | ||
| 84 | - </View> | ||
| 85 | - ); | ||
| 86 | - } | ||
| 87 | -} | ||
| 88 | - | ||
| 89 | -const styles = StyleSheet.create({ | ||
| 90 | - container: { | ||
| 91 | - flex: 1, | ||
| 92 | - justifyContent: "flex-start", | ||
| 93 | - alignItems: "stretch", | ||
| 94 | - backgroundColor: "#EFEFEF" | ||
| 95 | - }, | ||
| 96 | - dateWrapper: { | ||
| 97 | - // position: "absolute", | ||
| 98 | - // bottom: 200, | ||
| 99 | - marginBottom: 50, | ||
| 100 | - width: 250 | ||
| 101 | - } | ||
| 102 | -}); |
| 1 | -import React, { Component } from "react"; | ||
| 2 | -import { | ||
| 3 | - AppRegistry, | ||
| 4 | - StyleSheet, | ||
| 5 | - Text, | ||
| 6 | - View, | ||
| 7 | - Image, | ||
| 8 | - TouchableOpacity, | ||
| 9 | - ScrollView, | ||
| 10 | - ListView, | ||
| 11 | - Dimensions, | ||
| 12 | -} from "react-native"; | ||
| 13 | -import { StackNavigator, TabNavigator } from "react-navigation"; | ||
| 14 | - | ||
| 15 | -export default class Home extends Component { | ||
| 16 | - constructor(props) { | ||
| 17 | - super(props); | ||
| 18 | - this.state = {}; | ||
| 19 | - } | ||
| 20 | - componentWillMount() {} | ||
| 21 | - | ||
| 22 | - componentDidMount() {} | ||
| 23 | - | ||
| 24 | - getListData() { | ||
| 25 | - let that = this; | ||
| 26 | - return fetch(`https://devpay.brae.co/test/insurance/topic`, { | ||
| 27 | - method: "POST", | ||
| 28 | - headers: { | ||
| 29 | - Accept: "application/json", | ||
| 30 | - "Content-Type": "application/json" | ||
| 31 | - } | ||
| 32 | - }) | ||
| 33 | - .then(resp => { | ||
| 34 | - if (resp.status === 200) { | ||
| 35 | - return resp.json(); | ||
| 36 | - } else { | ||
| 37 | - console.error("something went wrong!"); | ||
| 38 | - } | ||
| 39 | - }) | ||
| 40 | - .then(respJson => { | ||
| 41 | - if (respJson.enmsg != "ok") { | ||
| 42 | - alert(respJson.cnmsg); | ||
| 43 | - } else { | ||
| 44 | - that.setState({ | ||
| 45 | - ListData: respJson.data.topic | ||
| 46 | - }); | ||
| 47 | - console.log("首页列表", this.state.ListData); | ||
| 48 | - } | ||
| 49 | - }); | ||
| 50 | - } | ||
| 51 | - | ||
| 52 | - render() { | ||
| 53 | - // console.log("首页的this.props", this); | ||
| 54 | - // console.log("render首页文章列表", this.state.ListData); | ||
| 55 | - const { navigate } = this.props.navigation; | ||
| 56 | - return ( | ||
| 57 | - <View style={styles.container}> | ||
| 58 | - <Text>健康问卷 问题</Text> | ||
| 59 | - </View> | ||
| 60 | - ); | ||
| 61 | - } | ||
| 62 | -} | ||
| 63 | - | ||
| 64 | -const styles = StyleSheet.create({ | ||
| 65 | - container: { | ||
| 66 | - flex: 1, | ||
| 67 | - justifyContent: "flex-start", | ||
| 68 | - alignItems: "stretch", | ||
| 69 | - backgroundColor: "#EFEFEF" | ||
| 70 | - }, | ||
| 71 | -}); |
| 1 | -import React, { Component } from "react"; | ||
| 2 | -import { | ||
| 3 | - AppRegistry, | ||
| 4 | - StyleSheet, | ||
| 5 | - Text, | ||
| 6 | - View, | ||
| 7 | - Image, | ||
| 8 | - TouchableOpacity, | ||
| 9 | - ScrollView, | ||
| 10 | - ListView, | ||
| 11 | - Dimensions, | ||
| 12 | -} from "react-native"; | ||
| 13 | -import { StackNavigator, TabNavigator } from "react-navigation"; | ||
| 14 | - | ||
| 15 | -export default class Home extends Component { | ||
| 16 | - constructor(props) { | ||
| 17 | - super(props); | ||
| 18 | - this.state = {}; | ||
| 19 | - } | ||
| 20 | - componentWillMount() {} | ||
| 21 | - | ||
| 22 | - componentDidMount() {} | ||
| 23 | - | ||
| 24 | - getListData() { | ||
| 25 | - let that = this; | ||
| 26 | - return fetch(`https://devpay.brae.co/test/insurance/topic`, { | ||
| 27 | - method: "POST", | ||
| 28 | - headers: { | ||
| 29 | - Accept: "application/json", | ||
| 30 | - "Content-Type": "application/json" | ||
| 31 | - } | ||
| 32 | - }) | ||
| 33 | - .then(resp => { | ||
| 34 | - if (resp.status === 200) { | ||
| 35 | - return resp.json(); | ||
| 36 | - } else { | ||
| 37 | - console.error("something went wrong!"); | ||
| 38 | - } | ||
| 39 | - }) | ||
| 40 | - .then(respJson => { | ||
| 41 | - if (respJson.enmsg != "ok") { | ||
| 42 | - alert(respJson.cnmsg); | ||
| 43 | - } else { | ||
| 44 | - that.setState({ | ||
| 45 | - ListData: respJson.data.topic | ||
| 46 | - }); | ||
| 47 | - console.log("首页列表", this.state.ListData); | ||
| 48 | - } | ||
| 49 | - }); | ||
| 50 | - } | ||
| 51 | - | ||
| 52 | - render() { | ||
| 53 | - // console.log("首页的this.props", this); | ||
| 54 | - // console.log("render首页文章列表", this.state.ListData); | ||
| 55 | - const { navigate } = this.props.navigation; | ||
| 56 | - return ( | ||
| 57 | - <View style={styles.container}> | ||
| 58 | - <Text>健康问卷 结果</Text> | ||
| 59 | - </View> | ||
| 60 | - ); | ||
| 61 | - } | ||
| 62 | -} | ||
| 63 | - | ||
| 64 | -const styles = StyleSheet.create({ | ||
| 65 | - container: { | ||
| 66 | - flex: 1, | ||
| 67 | - justifyContent: "flex-start", | ||
| 68 | - alignItems: "stretch", | ||
| 69 | - backgroundColor: "#EFEFEF" | ||
| 70 | - }, | ||
| 71 | -}); |
src/pages/Home/healthQuestionnaire.js
0 → 100644
| 1 | +import React, { Component } from 'react'; | ||
| 2 | +import { | ||
| 3 | + Dimensions, | ||
| 4 | + Image, | ||
| 5 | + StyleSheet, | ||
| 6 | + Text, | ||
| 7 | + TouchableOpacity, | ||
| 8 | + TouchableWithoutFeedback, | ||
| 9 | + View, | ||
| 10 | +} from 'react-native'; | ||
| 11 | + | ||
| 12 | +const questions = [ | ||
| 13 | + { question: '早上起床时,有持续的发丝掉落。', score: 5 }, | ||
| 14 | + { question: '情绪抑郁,会对着天空发呆。', score: 3 }, | ||
| 15 | + { question: '记不起昨天想好的事,而且最近经常有这种现象出现。', score: 10 }, | ||
| 16 | + { question: '上班途中,害怕走进办公室,觉得工作令人厌倦。', score: 5 }, | ||
| 17 | + { question: '不想面对同事和上司,有一种自闭倾向。', score: 5 }, | ||
| 18 | + { question: '工作效率明显下降,上司已表达了对你的不满。', score: 5 }, | ||
| 19 | + { question: '每天工作一小时,就感身体倦怠,胸闷气短。', score: 10 }, | ||
| 20 | + { question: '工作情绪始终无法高涨,最令自己不解的是无名的火气很大,但又没有精力发作。', score: 5 }, | ||
| 21 | + { question: '每天进餐少,即使口味非常适合自己的菜肴,也食不知味。', score: 5 }, | ||
| 22 | + { question: '盼望早点逃离办公室,能够回家躺在床上多休息。', score: 5 }, | ||
| 23 | + { question: '对城市的污染、噪声非常敏感,比常人渴望清幽,希望到宁静的山水处,使身心得以休息。', score: 5 }, | ||
| 24 | + { question: '不再像以前一样热衷于朋友的聚会,有一种强打起精神勉强应酬的感觉。', score: 2 }, | ||
| 25 | + { question: '晚上经常睡不着觉,即使睡着了,又老是在做梦状态,睡眠状态很糟。', score: 10 }, | ||
| 26 | + { question: '体重明显下降,早上起来,发现眼眶深陷,下巴突出。', score: 10 }, | ||
| 27 | + { question: '感觉免疫力下降,容易伤风感冒。', score: 5 }, | ||
| 28 | + { question: '性能力下降。昨天配偶对你明显表示有性要求,你却感到疲惫不堪,毫无性欲,令配偶怀疑你有外遇。', score: 10 }, | ||
| 29 | +]; | ||
| 30 | + | ||
| 31 | +class Start extends Component { | ||
| 32 | + | ||
| 33 | + render() { | ||
| 34 | + return ( | ||
| 35 | + <View style={[styles.container, { backgroundColor: 'white', alignItems: 'center' }]}> | ||
| 36 | + <Image style={styles.startImage} source={require('../../assets/home/questionnaire.png')} resizeMode='contain' /> | ||
| 37 | + <TouchableOpacity style={styles.startBtn} onPress={() => this.props.onStart()}> | ||
| 38 | + <Text style={styles.startBtnText}>开始测试</Text> | ||
| 39 | + </TouchableOpacity> | ||
| 40 | + <Text style={styles.startComment}>已有276人</Text> | ||
| 41 | + </View> | ||
| 42 | + ); | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | +} | ||
| 46 | + | ||
| 47 | +class Question extends Component { | ||
| 48 | + constructor(props) { | ||
| 49 | + super(props); | ||
| 50 | + this.state = { | ||
| 51 | + answer: null, | ||
| 52 | + }; | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + render() { | ||
| 56 | + const { number, pressHandler } = this.props; | ||
| 57 | + return ( | ||
| 58 | + <View style={styles.container}> | ||
| 59 | + <View style={styles.qPromptContainer}> | ||
| 60 | + <Text style={styles.qPromptText}>请根据您的真实情况选择</Text> | ||
| 61 | + <Text style={styles.qPromptText}>{number + 1}/{questions.length}</Text> | ||
| 62 | + </View> | ||
| 63 | + <View style={styles.qQuestionContainer}> | ||
| 64 | + <Text style={styles.qQuestion}>{number + 1}. {questions[number].question}</Text> | ||
| 65 | + </View> | ||
| 66 | + <View style={styles.qOptionContainer}> | ||
| 67 | + <TouchableOpacity style={styles.qOption} onPress={() => { pressHandler(questions[number].score) }}> | ||
| 68 | + <Text style={styles.qOptionText}>符合</Text> | ||
| 69 | + </TouchableOpacity> | ||
| 70 | + <TouchableOpacity style={styles.qOption} onPress={() => { pressHandler(0) }}> | ||
| 71 | + <Text style={styles.qOptionText}>不符合</Text> | ||
| 72 | + </TouchableOpacity> | ||
| 73 | + </View> | ||
| 74 | + </View> | ||
| 75 | + ); | ||
| 76 | + } | ||
| 77 | +} | ||
| 78 | + | ||
| 79 | +class Result extends Component { | ||
| 80 | + render() { | ||
| 81 | + return ( | ||
| 82 | + <View style={styles.container}> | ||
| 83 | + <View style={styles.rContainer}> | ||
| 84 | + <Text style={styles.rTitle}>检测结果</Text> | ||
| 85 | + <Text style={styles.rDetail}>hhggdsdfghkjkhggv</Text> | ||
| 86 | + </View> | ||
| 87 | + <TouchableOpacity style={styles.rResetBtn} onPress={()=> { this.props.onReset() }}> | ||
| 88 | + <Text style={styles.rResetText}>重新检测</Text> | ||
| 89 | + </TouchableOpacity> | ||
| 90 | + </View> | ||
| 91 | + ); | ||
| 92 | + } | ||
| 93 | +} | ||
| 94 | + | ||
| 95 | +class HealthQuestionnaire extends Component { | ||
| 96 | + constructor(props) { | ||
| 97 | + super(props); | ||
| 98 | + this.state = { | ||
| 99 | + stage: 0, | ||
| 100 | + score: 0, | ||
| 101 | + currentNumber: 0, | ||
| 102 | + }; | ||
| 103 | + } | ||
| 104 | + | ||
| 105 | + render() { | ||
| 106 | + const { stage } = this.state; | ||
| 107 | + return stage == 0 ? | ||
| 108 | + <Start onStart={() => { this.setState({ stage: 1 }) }} /> | ||
| 109 | + : stage == 1 ? | ||
| 110 | + <Question | ||
| 111 | + pressHandler={score => { | ||
| 112 | + const old = this.state; | ||
| 113 | + let tmp = { | ||
| 114 | + score: old.score + score, | ||
| 115 | + currentNumber: old.currentNumber + 1 | ||
| 116 | + }; | ||
| 117 | + if (old.currentNumber == questions.length - 1) { | ||
| 118 | + tmp.stage = old.stage + 1; | ||
| 119 | + } | ||
| 120 | + this.setState({ | ||
| 121 | + ...tmp, | ||
| 122 | + }); | ||
| 123 | + }} | ||
| 124 | + number={this.state.currentNumber} | ||
| 125 | + /> : | ||
| 126 | + <Result score={this.state.score} onReset={() => { this.setState({ score: 0, stage: 0, currentNumber: 0 }) }} /> | ||
| 127 | + } | ||
| 128 | +} | ||
| 129 | + | ||
| 130 | + | ||
| 131 | +const { width } = Dimensions.get('window'); | ||
| 132 | + | ||
| 133 | +const styles = StyleSheet.create({ | ||
| 134 | + container: { | ||
| 135 | + flex: 1, | ||
| 136 | + alignItems: 'stretch', | ||
| 137 | + paddingHorizontal: 12, | ||
| 138 | + }, | ||
| 139 | + startImage: { | ||
| 140 | + width: width - 140, | ||
| 141 | + height: (width - 140) / 454 * 208, | ||
| 142 | + marginVertical: 100, | ||
| 143 | + }, | ||
| 144 | + startBtn: { | ||
| 145 | + width: width - 80, | ||
| 146 | + height: 45, | ||
| 147 | + justifyContent: 'center', | ||
| 148 | + alignItems: 'center', | ||
| 149 | + backgroundColor: '#1b9341', | ||
| 150 | + borderRadius: 5, | ||
| 151 | + }, | ||
| 152 | + startBtnText: { | ||
| 153 | + fontSize: 16, | ||
| 154 | + color: 'white', | ||
| 155 | + }, | ||
| 156 | + startComment: { | ||
| 157 | + marginTop: 8, | ||
| 158 | + fontSize: 13, | ||
| 159 | + color: '#727272', | ||
| 160 | + }, | ||
| 161 | + qPromptContainer: { | ||
| 162 | + height: 36, | ||
| 163 | + flexDirection: 'row', | ||
| 164 | + justifyContent: 'space-between', | ||
| 165 | + alignItems: 'center', | ||
| 166 | + }, | ||
| 167 | + qPromptText: { | ||
| 168 | + fontSize: 13, | ||
| 169 | + color: '#7a7a7a' | ||
| 170 | + }, | ||
| 171 | + qQuestionContainer: { | ||
| 172 | + padding: 12, | ||
| 173 | + flex: 1, | ||
| 174 | + backgroundColor: 'white', | ||
| 175 | + borderRadius: 5, | ||
| 176 | + }, | ||
| 177 | + qQuestion: { | ||
| 178 | + fontSize: 15, | ||
| 179 | + color: '#242424', | ||
| 180 | + }, | ||
| 181 | + qOptionContainer: { | ||
| 182 | + marginVertical: 14, | ||
| 183 | + flexDirection: 'row', | ||
| 184 | + justifyContent: 'space-between', | ||
| 185 | + borderTopWidth: 0.5, | ||
| 186 | + borderColor: '#e6e6e6' | ||
| 187 | + }, | ||
| 188 | + qOption: { | ||
| 189 | + justifyContent: 'center', | ||
| 190 | + alignItems: 'center', | ||
| 191 | + borderRadius: 5, | ||
| 192 | + backgroundColor: '#1b9341', | ||
| 193 | + height: 44, | ||
| 194 | + width: (width - 28 - 14) / 2, | ||
| 195 | + }, | ||
| 196 | + qOptionText: { | ||
| 197 | + fontSize: 15, | ||
| 198 | + color: 'white', | ||
| 199 | + }, | ||
| 200 | + rContainer: { | ||
| 201 | + flex: 1, | ||
| 202 | + borderRadius: 5, | ||
| 203 | + backgroundColor: 'white', | ||
| 204 | + marginTop: 15, | ||
| 205 | + paddingHorizontal: 24, | ||
| 206 | + paddingBottom: 38, | ||
| 207 | + }, | ||
| 208 | + rTitle: { | ||
| 209 | + marginVertical: 37, | ||
| 210 | + alignSelf: 'center', | ||
| 211 | + fontSize: 20, | ||
| 212 | + fontWeight: 'bold', | ||
| 213 | + }, | ||
| 214 | + rDetail: { | ||
| 215 | + fontSize: 15, | ||
| 216 | + color: '#242424' | ||
| 217 | + }, | ||
| 218 | + rResetBtn: { | ||
| 219 | + justifyContent: 'center', | ||
| 220 | + alignItems: 'center', | ||
| 221 | + marginVertical: 25, | ||
| 222 | + backgroundColor: '#1b9341', | ||
| 223 | + height: 45, | ||
| 224 | + borderRadius: 5, | ||
| 225 | + }, | ||
| 226 | + rResetText: { | ||
| 227 | + fontSize: 16, | ||
| 228 | + color: 'white', | ||
| 229 | + }, | ||
| 230 | +}); | ||
| 231 | + | ||
| 232 | +export default HealthQuestionnaire; |
| @@ -172,7 +172,7 @@ export default class Home extends Component { | @@ -172,7 +172,7 @@ export default class Home extends Component { | ||
| 172 | <TouchableOpacity | 172 | <TouchableOpacity |
| 173 | style={styles.AHContainer} | 173 | style={styles.AHContainer} |
| 174 | onPress={() => { | 174 | onPress={() => { |
| 175 | - navigate("HealthBegin"); | 175 | + navigate("HealthQuestionnaire"); |
| 176 | }} | 176 | }} |
| 177 | > | 177 | > |
| 178 | <Image style={styles.AHIcon} source={require("../../assets/home/ic_questionnaire.png")}/> | 178 | <Image style={styles.AHIcon} source={require("../../assets/home/ic_questionnaire.png")}/> |
src/utils/fetch.js
0 → 100644
| 1 | +import { | ||
| 2 | + Alert, | ||
| 3 | +} from 'react-native'; | ||
| 4 | + | ||
| 5 | +const MAIN_URL = 'https://devpay.brae.co'; | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * | ||
| 9 | + * @param {String} url 形如'/some/directory/'的接口,以'/'开头 | ||
| 10 | + * @param {Object} data 上送数据 | ||
| 11 | + * @param {function} sucCB 成功回调函数 | ||
| 12 | + * @param {function} errCB 失败回调函数 | ||
| 13 | + * @param {Object} header 补充包头 | ||
| 14 | + */ | ||
| 15 | +export default function post(url, data, sucCB, errCB, header = {}) { | ||
| 16 | + const requestUrl = `${MAIN_URL}${url}`; | ||
| 17 | + const body = JSON.stringify(data); | ||
| 18 | + const headers = { | ||
| 19 | + "Accept": "application/json", | ||
| 20 | + "Content-Type": "application/json", | ||
| 21 | + ...header, | ||
| 22 | + } | ||
| 23 | + fetch(requestUrl, { | ||
| 24 | + method: 'POST', | ||
| 25 | + body: body, | ||
| 26 | + headers: headers, | ||
| 27 | + }).then(res => { | ||
| 28 | + if (res && res.status === 200) { | ||
| 29 | + return res.json(); | ||
| 30 | + } else { | ||
| 31 | + throw new Error('server') | ||
| 32 | + } | ||
| 33 | + }).then(res => { | ||
| 34 | + if (res && res.code === 200 && res.enmsg === 'ok') { | ||
| 35 | + sucCB(res); | ||
| 36 | + } else { | ||
| 37 | + errCB(res); | ||
| 38 | + } | ||
| 39 | + }).catch(err => { | ||
| 40 | + console.log(err) | ||
| 41 | + // 所有非 200 的情况都作为服务器内部错误处理 | ||
| 42 | + if (err.message === 'server') { | ||
| 43 | + errCB({ code: 500, enmsg: 'server error', cnmsg: '服务器内部错误', data: null }); | ||
| 44 | + } else { | ||
| 45 | + errCB({ code: 500, enmsg: 'client error', cnmsg: '网络异常', data: null }); | ||
| 46 | + } | ||
| 47 | + }) | ||
| 48 | +} |
-
Please register or login to post a comment