LabelLinkView.js 2.45 KB
import React, {Component} from 'react';
import {Text, TouchableOpacity} from 'react-native';
// 默认高度
const defaultHeight = (30);
// 默认垂直内边距
const VPading = (6);
/*
提示文字组件(type:'LABEL')
 */
export default class LabelLinkView extends Component {
    // 构造方法
    constructor(props) {
        super(props);
        this.state = {}
        // 传入参数
        this.attrData = this.props.attrData;
        // json解析后的传入参数
        this.extendData = (this.attrData.data && this.attrData.data.length > 0) ? JSON.parse(this.attrData.data) : {};
    }

    // 绘制UI
    render() {
        /*
        name:标题
        code:代码编号
        type:控件类型(LABEL)
        description:描述
        isRequired:是否必须
        isPreview:是否预览
        */
        let {name, code, type, description, isRequired, isPreview} = this.attrData;
        /*
        placeholder:提示文字
        hyperlink:超链接
        */
        let {placeholder, hyperlink} = this.extendData;
        // 是否为超链接
        let isHyperlink = !!hyperlink && hyperlink.length > 0 && (hyperlink.indexOf('http://') === 0 || hyperlink.indexOf('https://') === 0);

        return (
            // 最外层点击触发区域(可以触发超链接跳转)
            <TouchableOpacity
                style={{
                    width: '100%',
                    backgroundColor: 'rgba(245, 245, 245, 1)',
                    flexDirection: 'row',
                    alignItems: 'center',
                    paddingVertical: VPading,
                    paddingLeft: 10,
                    paddingRight: 15,
                    minHeight: defaultHeight
                }}
                activeOpacity={0.8}
                onPress={() => {
                    if (isHyperlink) {
                        this.props.navigation.navigate("CommonWebView", {url: hyperlink})
                    }
                }}
            >
                {/*{isRequired&&<Text style={{ color: "#FF3030" }}>* {" "}</Text>}*/}
                {/*{!isRequired&&<Text style={{ color: "#fff" }}>* {" "}</Text>}*/}
                {/*显示文字*/}
                <Text style={{
                    fontSize: 14,
                    color: '#999',
                    marginLeft: 10,
                    textDecorationLine: isHyperlink ? 'underline' : 'none'
                }}>{placeholder || description}</Text>
            </TouchableOpacity>
        );
    }
}