| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- /**
- * 文章详情
- * @邠心vbe on 2023/10/24
- */
- import React, { Component } from 'react';
- import { View, StyleSheet, Image, ScrollView, Linking } from 'react-native';
- import Swiper from 'react-native-swiper';
- import apiArticle from '../../api/apiArticle';
- import HeaderTitle from '../../components/HeaderTitle';
- import TextView from '../../components/TextView';
- import VbeSkeleton from '../../components/VbeSkeleton';
- import utils from '../../utils/utils';
- import { PagerView } from './ViewUtil';
- export default class ViewArticle extends Component {
- constructor(props) {
- super(props);
- this.state = {
- id: "",
- loading: true,
- messageInfo: {
- articleTypeName: "",
- articleTitle: "",
- articleContent: ""
- }
- };
- }
- componentDidMount() {
- if (this.props.route?.params?.id) {
- this.setState({
- id: this.props.route?.params?.id
- }, () => {
- this.readMessage();
- })
- }
- }
- readMessage() {
- apiArticle.readMessage(this.state.id).then(res => {
- if (res.data) {
- this.setState({
- messageInfo: res.data
- });
- this.setPageTitle();
- }
- }).catch(err => {
- toastShort(err);
- });
- }
- setPageTitle() {
- if (this.state.messageInfo.articleTitle) {
- this.props.navigation.setOptions({
- headerTitle: () => (<HeaderTitle title={this.state.messageInfo.articleTitle}/>)
- });
- setTimeout(() => {
- this.setState({
- loading: false
- });
- }, 300);
- }
- }
- accessLink(url) {
- Linking.openURL(utils.getImageUrl(url))
- }
- render() {
- if (this.state.loading) {
- return (
- <View style={styles.container}>
- <VbeSkeleton
- style={{width: $width, height: $width}}
- layout={[
- {width: $width, height: $width}
- ]}
- animationDirection={"horizontalRight"}/>
- <VbeSkeleton
- style={styles.loadingView}
- layout={[
- {width: '90%', height: 20, marginTop: 8},
- {width: '50%', height: 12, marginTop: 8},
- {width: '100%', height: 15, marginTop: 24},
- {width: '100%', height: 15, marginTop: 8},
- {width: '100%', height: 15, marginTop: 8},
- {width: '100%', height: 15, marginTop: 8},
- {width: '30%', height: 15, marginTop: 8}
- ]}
- animationDirection={"horizontalRight"}/>
- </View>
- )
- } else {
- return (
- <ScrollView
- style={styles.container}
- contentContainerStyle={$padding(0,0,32)}
- stickyHeaderIndices={[utils.isNotEmpty(this.state.messageInfo.articleImages) ? 1 : 0]}>
- { utils.isNotEmpty(this.state.messageInfo.articleImages) &&
- <Swiper
- style={{height: $width}}
- autoplay={true}
- autoplayTimeout={5}
- renderPagination={(index,total) => <PagerView index={index+1} total={total}/> }
- removeClippedSubviews={false}>
- { this.state.messageInfo.articleImages.map((item, index) => {
- return (
- <Image
- key={index}
- style={{width: $width, height: $width}}
- source={{uri: utils.getImageUrl(item.articleImagePath)}}/>
- );
- })}
- </Swiper>
- }
- <View style={styles.header}>
- <TextView
- style={styles.textTitle}>
- {this.state.messageInfo.articleTitle}
- </TextView>
- <View style={ui.flexc}>
- <MaterialCommunityIcons
- name="clock-time-four-outline"
- color={textSecondary}
- size={12}/>
- <TextView
- style={styles.textDate}
- numberOfLines={1}>
- {this.state.messageInfo.createTime}
- </TextView>
- </View>
- <View style={ui.flexc}>
- <MaterialCommunityIcons
- name="eye-check-outline"
- size={12}
- color={textPrimary}/>
- <TextView
- style={styles.textView}
- numberOfLines={1}>
- {this.state.messageInfo.articleViews}
- </TextView>
- </View>
- <View style={ui.flex}>
- <TextView
- style={styles.labelTypeText}
- numberOfLines={1}>
- {this.state.messageInfo.articleTypeName}
- </TextView>
- </View>
- </View>
- <TextView
- style={styles.textMessage}
- selectable={true}>
- {this.state.messageInfo.articleContent}
- </TextView>
- { utils.isNotEmpty(this.state.messageInfo.articleLinks) &&
- <>
- <TextView style={styles.textLinkTitle}>{$t("notification.labelLinks")}</TextView>
- { this.state.messageInfo.articleLinks.map((item, index) =>
- <View style={styles.itemLink} key={index}>
- <TextView style={styles.linkIndex}>{index + 1}.</TextView>
- <TextView
- style={styles.linkHyper}
- onPress={() => this.accessLink(item.articleLink)}>{item.articleLinkName}</TextView>
- </View>
- )}
- </>
- }
- <EndView/>
- </ScrollView>
- );
- }
- }
- }
- const styles = StyleSheet.create({
- container: {
- flex: 1,
- backgroundColor: pageBackground
- },
- loadingView: {
- flex: 1,
- padding: 16,
- justifyContent: 'flex-start',
- backgroundColor: pageBackground
- },
- textTitle: {
- color: textPrimary,
- fontSize: 14,
- fontWeight: 'bold',
- paddingBottom: 2
- },
- textDate: {
- flex: 1,
- color: textSecondary,
- fontSize: 12,
- paddingLeft: 2
- },
- textView: {
- color: textSecondary,
- fontSize: 14,
- padding: 4
- },
- header: {
- padding: 16,
- //...ElevationObject(1),
- backgroundColor: pageBackground
- },
- textMessage: {
- color: textPrimary,
- fontSize: 12,
- paddingLeft: 16,
- paddingRight: 16
- },
- labelTypeText: {
- fontSize: 12,
- fontWeight: 'bold',
- borderWidth: 1,
- borderRadius: 4,
- borderColor: colorPrimary,
- marginTop: 8,
- ...$padding(2, 6)
- },
- textLinkTitle: {
- color: textPrimary,
- fontSize: 14,
- fontWeight: 'bold',
- padding: 16
- },
- itemLink: {
- ...$padding(0, 16, 8),
- flexDirection: 'row'
- },
- linkIndex: {
- fontSize: 12,
- paddingRight: 2
- },
- linkHyper: {
- ...ui.link,
- fontSize: 12,
- textDecorationLine: 'underline'
- },
- linkActive: {
- color: "#FF3B30"
- }
- })
|