import React, { Component } from 'react'; import { Table } from 'antd'; import json5 from 'json5'; import PropTypes from 'prop-types'; import { schemaTransformToTable } from '../../../common/schema-transformTo-table.js'; import _ from 'underscore'; import './index.scss'; const messageMap = { desc: '备注', default: '实例', maximum: '最大值', minimum: '最小值', maxItems: '最大数量', minItems: '最小数量', maxLength: '最大长度', minLength: '最小长度', enum: '枚举', enumDesc: '枚举备注', uniqueItems: '元素是否都不同', itemType: 'item 类型', format: 'format', itemFormat: 'format', mock: 'mock' }; const columns = [ { title: '名称', dataIndex: 'name', key: 'name', width: 200 }, { title: '类型', dataIndex: 'type', key: 'type', width: 100, render: (text, item) => { // console.log('text',item.sub); return text === 'array' ? ( {item.sub ? item.sub.itemType || '' : 'array'} [] ) : ( {text} ); } }, { title: '是否必须', dataIndex: 'required', key: 'required', width: 80, render: text => { return
{name}: {value.toString()}
) ); }); } } ]; class SchemaTable extends Component { static propTypes = { dataSource: PropTypes.string }; constructor(props) { super(props); } render() { let product; try { product = json5.parse(this.props.dataSource); } catch (e) { product = null; } if (!product) { return null; } let data = schemaTransformToTable(product); data = _.isArray(data) ? data : []; return