Commit f7d3ebf3 authored by 田翔's avatar 田翔

fix: 解析json

parent 476da5c3
...@@ -3,37 +3,12 @@ import { Table, Tooltip } from 'antd' ...@@ -3,37 +3,12 @@ import { Table, Tooltip } from 'antd'
const TablePack = (props) => { const TablePack = (props) => {
const { loading, showField, formJson, dataSource } = props const { } = props
const columns = useMemo(() => { // console.log('props', props)
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])
return ( return (
<Table <div>{JSON.stringify(props)}</div>
size='small'
bordered
loading={loading}
columns={columns}
dataSource={dataSource}
pagination={false}
scroll={{ y: 'calc(100% - 50px)' }}
/>
) )
} }
......
import React, { useEffect, useMemo, useState } from 'react' import React, { useEffect, useMemo, useState } from 'react'
import styles from './index.less' 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 TablePack from './components/TablePack'
import { GetAccountConfigInfo, GetAccountPageList, getStationListByUserID, GetTableJson } from '../../apis/process' 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) => { const TableRender = (props) => {
...@@ -12,9 +33,27 @@ const TableRender = (props) => { ...@@ -12,9 +33,27 @@ const TableRender = (props) => {
const [config, setConfig] = useState({ webShowFieldGroup: '', formJson: '' }) const [config, setConfig] = useState({ webShowFieldGroup: '', formJson: '' })
const [dataSource, setDataSource] = useState([]) const [dataSource, setDataSource] = useState([])
const showField = useMemo(() => { const columns = useMemo(() => {
const { webShowFieldGroup } = config const { webShowFieldGroup, formJson } = config
return webShowFieldGroup.split(',').filter(v => v) 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]) }, [config])
const getConfig = async () => { const getConfig = async () => {
...@@ -58,14 +97,17 @@ const TableRender = (props) => { ...@@ -58,14 +97,17 @@ const TableRender = (props) => {
return ( return (
<div className={styles.tableRender}> <div className={styles.tableRender}>
<div className={styles.top}> <div className={styles.top}>
<Search /> <SearchGroup />
</div> </div>
<div className={styles.bottom}> <div className={styles.bottom}>
<TablePack <Table
size='small'
bordered
loading={loading} loading={loading}
showField={showField} columns={columns}
formJson={config.formJson}
dataSource={dataSource} dataSource={dataSource}
pagination={false}
scroll={{ y: 'calc(100% - 50px)' }}
/> />
</div> </div>
</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