ViewArticle.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /**
  2. * 文章详情
  3. * @邠心vbe on 2023/10/24
  4. */
  5. import React, { Component } from 'react';
  6. import { View, StyleSheet, Image, ScrollView, Linking } from 'react-native';
  7. import Swiper from 'react-native-swiper';
  8. import apiArticle from '../../api/apiArticle';
  9. import { ElevationObject } from '../../components/Button';
  10. import HeaderTitle from '../../components/HeaderTitle';
  11. import TextView from '../../components/TextView';
  12. import utils from '../../utils/utils';
  13. export default class ViewArticle extends Component {
  14. constructor(props) {
  15. super(props);
  16. this.state = {
  17. id: "",
  18. messageInfo: {
  19. articleTypeName: "",
  20. articleTitle: "",
  21. articleContent: ""
  22. }
  23. };
  24. }
  25. componentDidMount() {
  26. if (this.props.route?.params?.id) {
  27. this.setState({
  28. id: this.props.route?.params?.id
  29. }, () => {
  30. this.readMessage();
  31. })
  32. }
  33. }
  34. readMessage() {
  35. Dialog.showProgressDialog();
  36. apiArticle.readMessage(this.state.id).then(res => {
  37. if (res.data) {
  38. this.setState({
  39. messageInfo: res.data
  40. });
  41. this.setPageTitle();
  42. }
  43. }).catch(err => {
  44. toastShort(err);
  45. }).finally(() => {
  46. Dialog.dismissLoading();
  47. })
  48. }
  49. setPageTitle() {
  50. if (this.state.messageInfo.articleTitle) {
  51. this.props.navigation.setOptions({
  52. headerTitle: () => (<HeaderTitle title={this.state.messageInfo.articleTitle}/>)
  53. })
  54. }
  55. }
  56. accessLink(url) {
  57. Linking.openURL(utils.getImageUrl(url))
  58. }
  59. render() {
  60. return (
  61. <ScrollView
  62. style={styles.container}
  63. contentContainerStyle={$padding(0,0,32)}
  64. stickyHeaderIndices={[utils.isNotEmpty(this.state.messageInfo.articleImages) ? 1 : 0]}>
  65. { utils.isNotEmpty(this.state.messageInfo.articleImages) &&
  66. <Swiper
  67. style={{height: $width}}
  68. autoplay={true}
  69. autoplayTimeout={5}
  70. renderPagination={() => <></>}>
  71. { this.state.messageInfo.articleImages.map((item, index) => {
  72. return (
  73. <Image
  74. key={index}
  75. style={{width: $width, height: $width}}
  76. source={{uri: utils.getImageUrl(item.articleImagePath)}}/>
  77. );
  78. })}
  79. </Swiper>
  80. }
  81. <View style={styles.header}>
  82. <TextView
  83. style={styles.textTitle}>
  84. {this.state.messageInfo.articleTitle}
  85. </TextView>
  86. <View style={ui.flexc}>
  87. <MaterialCommunityIcons
  88. name="clock-time-four-outline"
  89. color={textSecondary}
  90. size={12}/>
  91. <TextView
  92. style={styles.textDate}
  93. numberOfLines={1}>
  94. {this.state.messageInfo.createTime}
  95. </TextView>
  96. <MaterialCommunityIcons
  97. name="eye-check-outline"
  98. size={12}
  99. color={textPrimary}/>
  100. <TextView
  101. style={styles.textView}
  102. numberOfLines={1}>
  103. {this.state.messageInfo.articleViews}
  104. </TextView>
  105. </View>
  106. <View style={ui.flex}>
  107. <TextView
  108. style={styles.labelTypeText}
  109. numberOfLines={1}>
  110. {this.state.messageInfo.articleTypeName}
  111. </TextView>
  112. </View>
  113. </View>
  114. <TextView
  115. style={styles.textMessage}>
  116. {this.state.messageInfo.articleContent}
  117. </TextView>
  118. { utils.isNotEmpty(this.state.messageInfo.articleLinks) &&
  119. <>
  120. <TextView style={styles.textLinkTitle}>{$t("notification.labelLinks")}</TextView>
  121. { this.state.messageInfo.articleLinks.map((item, index) =>
  122. <View style={styles.itemLink} key={index}>
  123. <TextView style={styles.linkIndex}>{index + 1}.</TextView>
  124. <TextView
  125. style={styles.linkHyper}
  126. onPress={() => this.accessLink(item.articleLink)}>{item.articleLinkName}</TextView>
  127. </View>
  128. )}
  129. </>
  130. }
  131. <EndView/>
  132. </ScrollView>
  133. );
  134. }
  135. }
  136. const styles = StyleSheet.create({
  137. container: {
  138. flex: 1,
  139. backgroundColor: pageBackground
  140. },
  141. textTitle: {
  142. color: textPrimary,
  143. fontSize: 18,
  144. fontWeight: 'bold',
  145. paddingBottom: 2
  146. },
  147. textDate: {
  148. flex: 1,
  149. color: textSecondary,
  150. fontSize: 10,
  151. paddingLeft: 2
  152. },
  153. textView: {
  154. color: textSecondary,
  155. fontSize: 10,
  156. paddingLeft: 4
  157. },
  158. header: {
  159. padding: 16,
  160. ...ElevationObject(1),
  161. backgroundColor: pageBackground
  162. },
  163. textMessage: {
  164. color: textPrimary,
  165. fontSize: 14,
  166. padding: 16
  167. },
  168. labelTypeText: {
  169. fontSize: 11,
  170. borderWidth: 1,
  171. borderRadius: 4,
  172. borderColor: colorPrimary,
  173. marginTop: 8,
  174. ...$padding(2, 6)
  175. },
  176. textLinkTitle: {
  177. color: textPrimary,
  178. fontSize: 16,
  179. fontWeight: 'bold',
  180. padding: 16
  181. },
  182. itemLink: {
  183. ...$padding(0, 16, 8),
  184. flexDirection: 'row'
  185. },
  186. linkIndex: {
  187. fontSize: 14,
  188. paddingRight: 2
  189. },
  190. linkHyper: {
  191. ...ui.link,
  192. fontSize: 14,
  193. textDecorationLine: 'underline'
  194. },
  195. linkActive: {
  196. color: "#FF3B30"
  197. }
  198. })