import Taro, {Component} from '@tarojs/taro' import {Block, Button, Image, Navigator, Swiper, SwiperItem, 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' 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} = 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 : '') if (item.attr && item.attr.width) { style.width = item.attr.width } let childView; if (tag === 'undefined') { childView = {item.text} } else if (tag === 'view') { 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') { childView = { this.linkClick(item.attr.href) }} >{item.child && } } 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} ) } }