import React, { Component } from 'react' import {Block, Button, Image, Navigator, Swiper, SwiperItem, Text, Video, View} from '@tarojs/components' import {Props} from 'types/Decode' import {styleToObj} from "../../utils/dom" import AudioPlayer from "../AudioPlayer/AudioPlayer"; import Latex from "../Latex/latex"; import Yuml from "../Yuml/Yuml"; import Table from "../Table/table"; import Img from "../Img/Img"; import DecodeA from "./decodeA"; import TodoGroup from "../TodoGroup/TodoGroup"; import config from '../../utils/config' import Copy from '../../../images/copy.svg' import Local from '../../../images/local.svg' import MapIcon from '../../../images/map.svg' import ShiPinHao from '../../../images/shipinhao.svg' import {Data} from "../../../types/Data"; function isEmptyString(t: string|undefined):boolean { return !t || t === "" || t === "\r\n" || t==="\r"|| t==="\n"; } function convertString(t: string|undefined):string|undefined { if(t) { return t.replace(/\r|\n/,''); } else { return t; } } function isSetTheValue(item: Data, name:string) { if(!item.attr) { return false; } let keys = Object.keys(item.attr); if(keys.includes(name)) { let v = item.attr[name]; if(v == undefined) { return true; } else { return v != '0'; } } return false; } export default class DecodeB extends Component { options = { addGlobalClass: true } imgClick = (src) => { if (this.props.onImgClick) { this.props.onImgClick(src) } } linkClick = (href) => { if (this.props.onLinkClick) { this.props.onLinkClick(href) } } buildChildView() { const {nodes, latexApi, yumlApi, inCode, onCopyLink} = this.props if (nodes && nodes.child) { return nodes.child.map(item => { const tag = item.tag || 'undefined' const style = styleToObj(item.attr && item.attr.style ? item.attr.style : '') const id = item.attr && item.attr.id ? item.attr.id : ''; if (item.attr && item.attr.width) { style.width = item.attr.width } let childView; if (tag === 'undefined') { if(id) { if(inCode) { childView = {item.text} } else { childView = {isEmptyString(item.text) ? item.text : {convertString(item.text)}} } } else { if(inCode) { childView = {item.text} } else { childView = {isEmptyString(item.text) ? item.text : {convertString(item.text)}} } } } else if (tag === 'view') { if(id) { childView = {item.child && } } else { childView = {item.child && } } } else if (tag === 'code') { childView = {item.child && } } else if (tag === 'video') { childView = () } else if (tag === 'text') { childView = {item.child ? : item.text} } else if (tag === 'image') { childView = { this.imgClick(item.attr.src) }} mode={item.attr.mode || 'widthFix'} lazyLoad={item.attr['lazy-load']} > {item.child && } } else if (tag === 'navigator') { let url = decodeURIComponent(item.attr.href); let isTextChild = item.child.length > 0 && item.child[0].type === 'text'; let isLocation = url?.startsWith("位置:"); let isMap = url?.startsWith("地图:"); let isShiPinHao = url?.startsWith("视频号:"); if(id) { childView = { this.linkClick(item.attr.href) }} > { isTextChild && isLocation && } { isTextChild && isMap && } { isTextChild && isShiPinHao && } {item.child && } } else { childView = { this.linkClick(item.attr.href) }} > { isTextChild && isLocation && } { isTextChild && isMap && } { isTextChild && isShiPinHao && } {item.child && } } if(onCopyLink) { let childText = item.child.map((item)=>item.text).reduce((pre,cur)=>{ let ret; if(pre) { ret = pre+ cur; } else { ret = cur; } return ret; }) || ''; childView = {childView} { onCopyLink(item.attr.href, childText); }}/> } } else if (tag === 'swiper') { childView = {item.child && } } else if (tag === 'swiper-item') { childView = {item.child && } } else if (tag === 'block') { childView = {item.child && } } else if (tag === 'button') { childView = } else if (tag === 'audio-player') { childView = } else if (tag === 'latex') { childView = } else if (tag === 'table') { childView = } else if (tag === 'yuml') { childView = } else if (tag === 'img') { childView = } else if (tag === 'todogroup') { childView = } return childView }) } return } render() { const node = this.buildChildView() return ( {node} ) } }