ViewArticle.js 5.3 KB

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