✨ feat(Table|LoadMore组件): 新增Table和LoadMore组件
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
.loadMore{
|
||||
display: flex;
|
||||
flex-flow: row nowrap;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
font-size: 28px;
|
||||
color: $color_font_three;
|
||||
padding: 24px 0;
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import { View, Text } from '@tarojs/components'
|
||||
import { FC } from 'react'
|
||||
import Iconfont from '../iconfont/iconfont'
|
||||
import LoadingCard from '../loadingCard/index'
|
||||
import styles from './index.module.scss'
|
||||
|
||||
export type LoadMoreStatus = 'more' | 'loading' | 'noMore'
|
||||
|
||||
interface LoadMoreEvent {
|
||||
onClick?: () => void
|
||||
}
|
||||
|
||||
interface LoadMorePropsType extends LoadMoreEvent {
|
||||
status: LoadMoreStatus
|
||||
moreText?: string
|
||||
loadingText?: string
|
||||
noMoreText?: string
|
||||
}
|
||||
|
||||
const LoadMore: FC<LoadMorePropsType> = props => {
|
||||
const { status, moreText = '查看更多', loadingText = '加载中', noMoreText = '没有更多', onClick } = props
|
||||
|
||||
const handleShowMore = () => {
|
||||
onClick && onClick()
|
||||
}
|
||||
|
||||
let component: JSX.Element | null = null
|
||||
if (status === 'loading') {
|
||||
component = <LoadingCard title={loadingText}></LoadingCard>
|
||||
} else if (status === 'more') {
|
||||
component = (
|
||||
<View onClick={handleShowMore}>
|
||||
<Text style={{ marginRight: '5px' }}>{moreText}</Text>
|
||||
<Iconfont name='icon-zhankai' size={32}></Iconfont>
|
||||
</View>
|
||||
)
|
||||
} else {
|
||||
component = <Text>{noMoreText}</Text>
|
||||
}
|
||||
return <View className={styles.loadMore}>{component}</View>
|
||||
}
|
||||
export default LoadMore
|
||||
@@ -2,5 +2,5 @@
|
||||
padding: 24px 40px;
|
||||
display: grid;
|
||||
grid-gap: 24px 24px;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
grid-template-columns: 1fr 1fr 1fr;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import FilterButton from '../filterButton'
|
||||
import { EnumMarketingDepartmentApi } from '@/api/index'
|
||||
import { View } from '@tarojs/components'
|
||||
import styles from './index.module.scss'
|
||||
import classnames from 'classnames'
|
||||
|
||||
type ChangedValue = string | number
|
||||
|
||||
@@ -52,7 +53,7 @@ const SelectSaleRankingIndicators: FC<SelectSaleTypeProps> = props => {
|
||||
|
||||
return (
|
||||
<DropDownItem title={displayTitle} value={currentValue} activeColor='#337fff' showOverlay={false}>
|
||||
<View className={styles.grid}>
|
||||
<View className={classnames(styles.grid)}>
|
||||
{!!enumList.length &&
|
||||
enumList.map((item: EnumList) => {
|
||||
return (
|
||||
|
||||
@@ -4,12 +4,10 @@ import style from "./index.module.scss"
|
||||
import { memo } from "react";
|
||||
|
||||
type Params = {
|
||||
styleLoading?: Object,
|
||||
title?: string,
|
||||
loadingIcon?: false|true
|
||||
}
|
||||
export default memo(({
|
||||
styleLoading = {},
|
||||
title = "加载中...", //显示的文字
|
||||
loadingIcon = true //是否显示加载图标
|
||||
}:Params) => {
|
||||
@@ -22,4 +20,4 @@ export default memo(({
|
||||
</View>
|
||||
</>
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -70,8 +70,9 @@ $am-ms: 200ms;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
min-height: 200px;
|
||||
width: 100vw;
|
||||
width: 100%;
|
||||
border-radius: 20px 20px 0px 0px;
|
||||
box-shadow: 1px 1px 1px 1px #f2f2f2;
|
||||
transform: translate3d(0, 100%, 0);
|
||||
}
|
||||
|
||||
@@ -79,8 +80,9 @@ $am-ms: 200ms;
|
||||
top: 0;
|
||||
left: 0;
|
||||
min-height: 200px;
|
||||
width: 100vw;
|
||||
width: 100%;
|
||||
border-radius: 0 0 20px 20px;
|
||||
box-shadow: 6px 6px 5px 14px red;
|
||||
transform: translate3d(0, -100%, 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
.table {
|
||||
border: 0px solid darkgray;
|
||||
border-radius: 5px;
|
||||
font-size: 22px;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.tr {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
padding: 24px 0;
|
||||
border-bottom: 1px solid #f7f7f7;
|
||||
}
|
||||
|
||||
.td {
|
||||
justify-content: center;
|
||||
text-align: center;
|
||||
align-items: center;
|
||||
display: flex;
|
||||
font-size: 26px;
|
||||
}
|
||||
|
||||
.th{
|
||||
font-size: 26px;
|
||||
}
|
||||
|
||||
.bg-line {
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.bg-header {
|
||||
justify-content: center;
|
||||
background: #f6f7fb;
|
||||
color: $color_font_three;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.ellipsis_1{
|
||||
@include common_ellipsis(1)
|
||||
}
|
||||
.ellipsis_2{
|
||||
@include common_ellipsis(2)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
import { ScrollView, View, Text } from '@tarojs/components'
|
||||
import classnames from 'classnames'
|
||||
import { FC, useState } from 'react'
|
||||
import Iconfont from '../iconfont/iconfont'
|
||||
import InfiniteScroll from '../infiniteScroll'
|
||||
import LoadMore, { LoadMoreStatus } from '../LoadMore'
|
||||
import styles from './index.module.scss'
|
||||
|
||||
type ColumnsType = {
|
||||
title: string
|
||||
dataIndex: string
|
||||
width: string
|
||||
key: string
|
||||
render?: (text?: string, record?: RecordType, index?: number) => React.ReactNode
|
||||
ellipsis?: boolean | { isEllipsis: boolean; rows: number }
|
||||
}
|
||||
|
||||
type RecordType = {
|
||||
key: string
|
||||
[Property: string]: any
|
||||
}
|
||||
|
||||
interface TablePropsType {
|
||||
columns: ColumnsType[]
|
||||
dataSource: RecordType[]
|
||||
}
|
||||
|
||||
const Table: FC<TablePropsType> = props => {
|
||||
const { columns, dataSource } = props
|
||||
|
||||
|
||||
const [showMore, setShowMore] = useState(false)
|
||||
|
||||
const [loadMoreStatus, setLoadMoreStatus] = useState<LoadMoreStatus>('loading')
|
||||
|
||||
const handleShowMore = () => {
|
||||
|
||||
}
|
||||
|
||||
const getColumnStyle = (columnConfig: ColumnsType) => {
|
||||
const columnStyle = {}
|
||||
if (typeof columnConfig.ellipsis === 'boolean' && columnConfig.ellipsis) {
|
||||
columnStyle[styles.ellipsis_1] = true
|
||||
}
|
||||
if (typeof columnConfig.ellipsis === 'object' && columnConfig.ellipsis.isEllipsis) {
|
||||
const rows = columnConfig.ellipsis.rows
|
||||
if (rows === 2) {
|
||||
columnStyle[styles.ellipsis_2] = true
|
||||
} else {
|
||||
columnStyle[styles.ellipsis_1] = true
|
||||
}
|
||||
}
|
||||
return columnStyle
|
||||
}
|
||||
|
||||
const sourceContainer = () => {
|
||||
return (
|
||||
<>
|
||||
{!!dataSource.length &&
|
||||
dataSource.map(source => {
|
||||
return (
|
||||
<View className={classnames(styles.tr, styles['bg-line'])} key={source.key}>
|
||||
{columns.map(column => {
|
||||
if (column.render) {
|
||||
return (
|
||||
<View className={styles.td} style={{ width: column.width }}>
|
||||
{/* 判断表头是不是有render 有就执行render */}
|
||||
{column.render(source[column.dataIndex])}
|
||||
</View>
|
||||
)
|
||||
} else {
|
||||
return (
|
||||
<View className={classnames(styles.td, getColumnStyle(column))} style={{ width: column.width }}>
|
||||
{
|
||||
source[column.dataIndex] //根据表头填数据
|
||||
}
|
||||
</View>
|
||||
)
|
||||
}
|
||||
})}
|
||||
</View>
|
||||
)
|
||||
})}
|
||||
{showMore && (
|
||||
<LoadMore status={loadMoreStatus} onClick={handleShowMore}></LoadMore>
|
||||
)}
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<View className={styles.table}>
|
||||
<View className={classnames(styles.tr, styles['bg-header'])}>
|
||||
{columns.map(column => {
|
||||
return (
|
||||
<View className={styles.th} style={{ width: column.width }} key={column.key}>
|
||||
{column.title}
|
||||
</View>
|
||||
)
|
||||
})}
|
||||
</View>
|
||||
<ScrollView>{sourceContainer()}</ScrollView>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
export default Table
|
||||
Reference in New Issue
Block a user