Commit f7d3ebf3 authored by 田翔's avatar 田翔

fix: 解析json

parent 476da5c3
......@@ -3,37 +3,12 @@ import { Table, Tooltip } from 'antd'
const TablePack = (props) => {
const { loading, showField, formJson, dataSource } = props
const { } = props
const columns = useMemo(() => {
let array = []
showField.forEach(v => {
array.push({
key: new Date().getTime(),
title: v,
dataIndex: v,
width: 120,
ellipsis: true,
render: (value, r) => {
return (
<Tooltip placement="top" title={value}>{value}</Tooltip>
)
}
})
})
return array
}, [showField])
// console.log('props', props)
return (
<Table
size='small'
bordered
loading={loading}
columns={columns}
dataSource={dataSource}
pagination={false}
scroll={{ y: 'calc(100% - 50px)' }}
/>
<div>{JSON.stringify(props)}</div>
)
}
......
import React, { useEffect, useMemo, useState } from 'react'
import styles from './index.less'
import Search from './components/Search'
import { Table, Tooltip } from 'antd'
import SearchGroup from './components/SearchGroup'
import TablePack from './components/TablePack'
import { GetAccountConfigInfo, GetAccountPageList, getStationListByUserID, GetTableJson } from '../../apis/process'
import { isJson, isObject } from '../../utils/index'
import { query } from 'express'
const getFileInfo = (formJson) => {
let obj = {}
let json = isJson(formJson) ? JSON.parse(formJson) : {}
let parent = json?.properties
if (isObject(parent)) {
for (let v in parent) {
let child = parent[v]?.properties
if (isObject(child)) {
for (let s in child) {
obj[s] = child[s]
}
}
}
}
console.log('obj', obj)
return obj
}
const TableRender = (props) => {
......@@ -12,9 +33,27 @@ const TableRender = (props) => {
const [config, setConfig] = useState({ webShowFieldGroup: '', formJson: '' })
const [dataSource, setDataSource] = useState([])
const showField = useMemo(() => {
const { webShowFieldGroup } = config
return webShowFieldGroup.split(',').filter(v => v)
const columns = useMemo(() => {
const { webShowFieldGroup, formJson } = config
let showField = webShowFieldGroup ? webShowFieldGroup.split(',').filter(v => v) : []
let json = getFileInfo(formJson)
let array = []
showField.forEach(v => {
array.push({
key: new Date().getTime(),
title: json[v]?.title || v,
dataIndex: v,
width: 120,
ellipsis: true,
render: (value, r) => {
let props = { ...json[v], value }
return (
<TablePack {...props} />
)
}
})
})
return array
}, [config])
const getConfig = async () => {
......@@ -58,14 +97,17 @@ const TableRender = (props) => {
return (
<div className={styles.tableRender}>
<div className={styles.top}>
<Search />
<SearchGroup />
</div>
<div className={styles.bottom}>
<TablePack
<Table
size='small'
bordered
loading={loading}
showField={showField}
formJson={config.formJson}
columns={columns}
dataSource={dataSource}
pagination={false}
scroll={{ y: 'calc(100% - 50px)' }}
/>
</div>
</div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment