ViewArticle.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. removeClippedSubviews={false}>
  72. { this.state.messageInfo.articleImages.map((item, index) => {
  73. return (
  74. <Image
  75. key={index}
  76. style={{width: $width, height: $width}}
  77. source={{uri: utils.getImageUrl(item.articleImagePath)}}/>
  78. );
  79. })}
  80. </Swiper>
  81. }
  82. <View style={styles.header}>
  83. <TextView
  84. style={styles.textTitle}>
  85. {this.state.messageInfo.articleTitle}
  86. </TextView>
  87. <View style={ui.flexc}>
  88. <MaterialCommunityIcons
  89. name="clock-time-four-outline"
  90. color={textSecondary}
  91. size={12}/>
  92. <TextView
  93. style={styles.textDate}
  94. numberOfLines={1}>
  95. {this.state.messageInfo.createTime}
  96. </TextView>
  97. <MaterialCommunityIcons
  98. name="eye-check-outline"
  99. size={12}
  100. color={textPrimary}/>
  101. <TextView
  102. style={styles.textView}
  103. numberOfLines={1}>
  104. {this.state.messageInfo.articleViews}
  105. </TextView>
  106. </View>
  107. <View style={ui.flex}>
  108. <TextView
  109. style={styles.labelTypeText}
  110. numberOfLines={1}>
  111. {this.state.messageInfo.articleTypeName}
  112. </TextView>
  113. </View>
  114. </View>
  115. <TextView
  116. style={styles.textMessage}
  117. selectable={true}>
  118. {this.state.messageInfo.articleContent}
  119. </TextView>
  120. { utils.isNotEmpty(this.state.messageInfo.articleLinks) &&
  121. <>
  122. <TextView style={styles.textLinkTitle}>{$t("notification.labelLinks")}</TextView>
  123. { this.state.messageInfo.articleLinks.map((item, index) =>
  124. <View style={styles.itemLink} key={index}>
  125. <TextView style={styles.linkIndex}>{index + 1}.</TextView>
  126. <TextView
  127. style={styles.linkHyper}
  128. onPress={() => this.accessLink(item.articleLink)}>{item.articleLinkName}</TextView>
  129. </View>
  130. )}
  131. </>
  132. }
  133. <EndView/>
  134. </ScrollView>
  135. );
  136. }
  137. }
  138. const styles = StyleSheet.create({
  139. container: {
  140. flex: 1,
  141. backgroundColor: pageBackground
  142. },
  143. textTitle: {
  144. color: textPrimary,
  145. fontSize: 18,
  146. fontWeight: 'bold',
  147. paddingBottom: 2
  148. },
  149. textDate: {
  150. flex: 1,
  151. color: textSecondary,
  152. fontSize: 10,
  153. paddingLeft: 2
  154. },
  155. textView: {
  156. color: textSecondary,
  157. fontSize: 10,
  158. paddingLeft: 4
  159. },
  160. header: {
  161. padding: 16,
  162. ...ElevationObject(1),
  163. backgroundColor: pageBackground
  164. },
  165. textMessage: {
  166. color: textPrimary,
  167. fontSize: 14,
  168. padding: 16
  169. },
  170. labelTypeText: {
  171. fontSize: 11,
  172. borderWidth: 1,
  173. borderRadius: 4,
  174. borderColor: colorPrimary,
  175. marginTop: 8,
  176. ...$padding(2, 6)
  177. },
  178. textLinkTitle: {
  179. color: textPrimary,
  180. fontSize: 16,
  181. fontWeight: 'bold',
  182. padding: 16
  183. },
  184. itemLink: {
  185. ...$padding(0, 16, 8),
  186. flexDirection: 'row'
  187. },
  188. linkIndex: {
  189. fontSize: 14,
  190. paddingRight: 2
  191. },
  192. linkHyper: {
  193. ...ui.link,
  194. fontSize: 14,
  195. textDecorationLine: 'underline'
  196. },
  197. linkActive: {
  198. color: "#FF3B30"
  199. }
  200. })