🌈 style(eslint): add eslint rules
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
import { ScrollView, View, Text } from '@tarojs/components'
|
||||
import { ScrollView, Text, View } from '@tarojs/components'
|
||||
import classnames from 'classnames'
|
||||
import { FC, useCallback, useMemo, useState } from 'react'
|
||||
import type { FC } from 'react'
|
||||
import { useCallback, useMemo, useState } from 'react'
|
||||
import Iconfont from '../iconfont/iconfont'
|
||||
import InfiniteScroll from '../infiniteScroll'
|
||||
import LoadMore, { LoadMoreStatus } from '../LoadMore'
|
||||
import styles from './index.module.scss'
|
||||
|
||||
export type ColumnsType = {
|
||||
export interface ColumnsType {
|
||||
title: string
|
||||
dataIndex: string
|
||||
width: string
|
||||
@@ -15,7 +16,7 @@ export type ColumnsType = {
|
||||
ellipsis?: boolean | { isEllipsis: boolean; rows: number }
|
||||
}
|
||||
|
||||
export type RecordType = {
|
||||
export interface RecordType {
|
||||
key: string
|
||||
[Property: string]: any
|
||||
}
|
||||
@@ -27,8 +28,8 @@ export interface TablePropsType {
|
||||
height?: number
|
||||
}
|
||||
|
||||
const Table: FC<TablePropsType> = props => {
|
||||
const { columns, dataSource, onLoadMore, height=400 } = props
|
||||
const Table: FC<TablePropsType> = (props) => {
|
||||
const { columns, dataSource, onLoadMore, height = 400 } = props
|
||||
|
||||
const handleShowMore = () => {
|
||||
onLoadMore && onLoadMore()
|
||||
@@ -43,7 +44,8 @@ const Table: FC<TablePropsType> = props => {
|
||||
const rows = columnConfig.ellipsis.rows
|
||||
if (rows === 2) {
|
||||
columnStyle[styles.ellipsis_2] = true
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
columnStyle[styles.ellipsis_1] = true
|
||||
}
|
||||
}
|
||||
@@ -53,23 +55,25 @@ const Table: FC<TablePropsType> = props => {
|
||||
const loadMoreComponent = useMemo(() => {
|
||||
if (dataSource) {
|
||||
if (dataSource.list.length < dataSource.total) {
|
||||
return <LoadMore status='more' onClick={handleShowMore}></LoadMore>
|
||||
} else if (dataSource.list.length >= dataSource.total) {
|
||||
return <LoadMore status='noMore' onClick={handleShowMore}></LoadMore>
|
||||
return <LoadMore status="more" onClick={handleShowMore}></LoadMore>
|
||||
}
|
||||
} else {
|
||||
return <LoadMore status='loading' onClick={handleShowMore}></LoadMore>
|
||||
else if (dataSource.list.length >= dataSource.total) {
|
||||
return <LoadMore status="noMore" onClick={handleShowMore}></LoadMore>
|
||||
}
|
||||
}
|
||||
else {
|
||||
return <LoadMore status="loading" onClick={handleShowMore}></LoadMore>
|
||||
}
|
||||
}, [dataSource])
|
||||
|
||||
const sourceContainer = () => {
|
||||
return (
|
||||
<>
|
||||
{!!dataSource?.list?.length &&
|
||||
dataSource.list.map(source => {
|
||||
{!!dataSource?.list?.length
|
||||
&& dataSource.list.map((source) => {
|
||||
return (
|
||||
<View className={classnames(styles.tr, styles['bg-line'])} key={source.key}>
|
||||
{columns.map(column => {
|
||||
{columns.map((column) => {
|
||||
if (column.render) {
|
||||
return (
|
||||
<View className={styles.td} style={{ width: column.width }}>
|
||||
@@ -77,11 +81,12 @@ const Table: FC<TablePropsType> = props => {
|
||||
{column.render(source[column.dataIndex])}
|
||||
</View>
|
||||
)
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return (
|
||||
<View className={classnames(styles.td, getColumnStyle(column))} style={{ width: column.width }}>
|
||||
{
|
||||
source[column.dataIndex] //根据表头填数据
|
||||
source[column.dataIndex] // 根据表头填数据
|
||||
}
|
||||
</View>
|
||||
)
|
||||
@@ -98,7 +103,7 @@ const Table: FC<TablePropsType> = props => {
|
||||
return (
|
||||
<View className={styles.table}>
|
||||
<View className={classnames(styles.tr, styles['bg-header'])}>
|
||||
{columns.map(column => {
|
||||
{columns.map((column) => {
|
||||
return (
|
||||
<View className={styles.th} style={{ width: column.width }} key={column.key}>
|
||||
{column.title}
|
||||
@@ -106,7 +111,7 @@ const Table: FC<TablePropsType> = props => {
|
||||
)
|
||||
})}
|
||||
</View>
|
||||
<InfiniteScroll enableLoadMoreStatus={false} safeAreaInsetBottom={true}>
|
||||
<InfiniteScroll enableLoadMoreStatus={false} safeAreaInsetBottom>
|
||||
{sourceContainer()}
|
||||
</InfiniteScroll>
|
||||
</View>
|
||||
|
||||
Reference in New Issue
Block a user