Skip to content

Commit

Permalink
Merge pull request #13 from kne-union/linzp
Browse files Browse the repository at this point in the history
添加了一些格式化参数
  • Loading branch information
zhipenglin authored Oct 17, 2024
2 parents fc347e3 + d9259a9 commit ba536ef
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kne/info-page",
"version": "0.1.4",
"version": "0.1.5",
"description": "一般用在复杂的详情展示页面,InfoPage提供了一个标准的展示信息的格式",
"syntax": {
"esmodules": true
Expand Down
35 changes: 32 additions & 3 deletions src/TableView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ const defaultFormat = {
const template = args[0] || 'YYYY-MM-DD HH:mm:ss';
return dayjs(value).format(template);
},
dateRange: (value, { args }) => {
const template = args[0] || 'YYYY-MM-DD',
allowNull = args[1];
if (!isEmpty(value[0]) && !isEmpty(value[1])) {
return `${dayjs(value[0]).format(template)}~${dayjs(value[1]).format(template)}`;
}
if (allowNull === 'allow' && !isEmpty(value[0])) {
return `${dayjs(value[0]).format(template)}以后`;
}
if (allowNull === 'allow' && !isEmpty(value[1])) {
return `${dayjs(value[1]).format(template)}以前`;
}
return '';
},
boolean: value => {
if (value) {
return '是';
Expand Down Expand Up @@ -105,11 +119,11 @@ const TableView = props => {

return (
<Row className={classnames(style['table-view'], className)}>
{renderColumns.map(item => {
{renderColumns.map((item, index) => {
return (
<Col
className={classnames(style['table-view-col'], 'table-view-col')}
key={item.name}
key={`${item.name}-${index}`}
style={{
'--col-width': `${(100 * item.span) / 24}%`
}}
Expand All @@ -123,7 +137,22 @@ const TableView = props => {
>
{item.title}
</Col>
<Col className={classnames(style['table-view-content'], 'table-view-content')}>{item.isEmpty ? item.placeholder || placeholder : typeof item.render === 'function' ? item.render(item.value) : item.value}</Col>
<Col className={classnames(style['table-view-content'], 'table-view-content')}>
{item.isEmpty
? typeof item.renderPlaceholder === 'function'
? item.renderPlaceholder({
column: item,
dataSource,
placeholder
})
: item.placeholder || placeholder
: typeof item.render === 'function'
? item.render(item.value, {
column: item,
dataSource
})
: item.value}
</Col>
</Row>
</Col>
);
Expand Down

0 comments on commit ba536ef

Please sign in to comment.