ViewArticle.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. </View>
  99. <View style={ui.flexc}>
  100. <MaterialCommunityIcons
  101. name="eye-check-outline"
  102. size={12}
  103. color={textPrimary}/>
  104. <TextView
  105. style={styles.textView}
  106. numberOfLines={1}>
  107. {this.state.messageInfo.articleViews}
  108. </TextView>
  109. </View>
  110. <View style={ui.flex}>
  111. <TextView
  112. style={styles.labelTypeText}
  113. numberOfLines={1}>
  114. {this.state.messageInfo.articleTypeName}
  115. </TextView>
  116. </View>
  117. </View>
  118. <TextView
  119. style={styles.textMessage}
  120. selectable={true}>
  121. {this.state.messageInfo.articleContent}
  122. </TextView>
  123. { utils.isNotEmpty(this.state.messageInfo.articleLinks) &&
  124. <>
  125. <TextView style={styles.textLinkTitle}>{$t("notification.labelLinks")}</TextView>
  126. { this.state.messageInfo.articleLinks.map((item, index) =>
  127. <View style={styles.itemLink} key={index}>
  128. <TextView style={styles.linkIndex}>{index + 1}.</TextView>
  129. <TextView
  130. style={styles.linkHyper}
  131. onPress={() => this.accessLink(item.articleLink)}>{item.articleLinkName}</TextView>
  132. </View>
  133. )}
  134. </>
  135. }
  136. <EndView/>
  137. </ScrollView>
  138. );
  139. }
  140. }
  141. const styles = StyleSheet.create({
  142. container: {
  143. flex: 1,
  144. backgroundColor: pageBackground
  145. },
  146. textTitle: {
  147. color: textPrimary,
  148. fontSize: 14,
  149. fontWeight: 'bold',
  150. paddingBottom: 2
  151. },
  152. textDate: {
  153. flex: 1,
  154. color: textSecondary,
  155. fontSize: 12,
  156. paddingLeft: 2
  157. },
  158. textView: {
  159. color: textSecondary,
  160. fontSize: 14,
  161. padding: 4
  162. },
  163. header: {
  164. padding: 16,
  165. //...ElevationObject(1),
  166. backgroundColor: pageBackground
  167. },
  168. textMessage: {
  169. color: textPrimary,
  170. fontSize: 12,
  171. paddingLeft: 16,
  172. paddingRight: 16
  173. },
  174. labelTypeText: {
  175. fontSize: 12,
  176. fontWeight: 'bold',
  177. borderWidth: 1,
  178. borderRadius: 4,
  179. borderColor: colorPrimary,
  180. marginTop: 8,
  181. ...$padding(2, 6)
  182. },
  183. textLinkTitle: {
  184. color: textPrimary,
  185. fontSize: 14,
  186. fontWeight: 'bold',
  187. padding: 16
  188. },
  189. itemLink: {
  190. ...$padding(0, 16, 8),
  191. flexDirection: 'row'
  192. },
  193. linkIndex: {
  194. fontSize: 12,
  195. paddingRight: 2
  196. },
  197. linkHyper: {
  198. ...ui.link,
  199. fontSize: 12,
  200. textDecorationLine: 'underline'
  201. },
  202. linkActive: {
  203. color: "#FF3B30"
  204. }
  205. })