-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix #463
- Loading branch information
Showing
7 changed files
with
176 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import React, { useState, useRef, useEffect } from 'react'; | ||
import { Cell, List, Loading } from 'tdesign-mobile-react'; | ||
|
||
export default function ListDemo() { | ||
const listError = useRef<string[]>([]); | ||
const [loading, setLoading] = useState(''); | ||
const [showError, setShowError] = useState(false); | ||
|
||
const onLoadError = () => { | ||
setLoading('loading'); | ||
|
||
setTimeout(() => { | ||
const newVal: string[] = [...listError.current]; | ||
for (let i = listError.current.length; i < 8; i++) { | ||
newVal.push(`${i}`); | ||
} | ||
listError.current = newVal; | ||
|
||
setShowError(true); | ||
setLoading(''); | ||
}, 1000); | ||
}; | ||
|
||
const onLoadMore = () => { | ||
setShowError(false); | ||
if (listError.current.length >= 60 || loading) { | ||
return; | ||
} | ||
setLoading('loading'); | ||
|
||
setTimeout(() => { | ||
for (let i = 0; i < 15; i++) { | ||
listError.current.push(`${listError.current.length + 1}`); | ||
} | ||
setLoading(''); | ||
}, 1000); | ||
}; | ||
|
||
useEffect(() => { | ||
onLoadError(); | ||
}, []); | ||
|
||
return ( | ||
<List | ||
asyncLoading={loading} | ||
onScroll={onLoadMore} | ||
footer={ | ||
showError && ( | ||
<Loading indicator={false}> | ||
<div className="custom-error"> | ||
请求失败,点击重新<span onClick={onLoadMore}>加载</span> | ||
</div> | ||
</Loading> | ||
) | ||
} | ||
> | ||
{listError.current.map((item) => ( | ||
<Cell key={item} align="middle"> | ||
<span className="cell">{item}</span> | ||
</Cell> | ||
))} | ||
</List> | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import React, { useState } from 'react'; | ||
import { Button } from 'tdesign-mobile-react'; | ||
import TDemoBlock from '../../../site/mobile/components/DemoBlock'; | ||
// import TDemoHeader from '../../../site/mobile/components/DemoHeader'; | ||
import './style/index.less'; | ||
|
||
import BaseList from './base.jsx'; | ||
import ErrTipDemo from './err-tip.jsx'; | ||
import PullRefreshDemo from './pull-refresh.jsx'; | ||
|
||
export default function ListDemo() { | ||
const [currentTab, setCurrentTab] = useState('info'); | ||
|
||
const onChangeTab = (val) => { | ||
setCurrentTab(val); | ||
history.pushState({}, '', '?tab=demo'); | ||
}; | ||
|
||
return ( | ||
<div className="tdesign-mobile-demo"> | ||
<div className="list-demo"> | ||
{currentTab === 'info' && ( | ||
<div> | ||
<h1 className="title">List 列表</h1> | ||
<p className="summary"> | ||
瀑布流滚动加载,用于展示同一类型信息的长列表。当列表即将滚动到底部时,会触发事件并加载更多列表项。 | ||
</p> | ||
<TDemoBlock title="01 类型" summary="基础列表"> | ||
<Button size="large" variant="outline" theme="primary" onClick={() => onChangeTab('base')}> | ||
{' '} | ||
基础列表{' '} | ||
</Button> | ||
<Button size="large" variant="outline" theme="primary" onClick={() => onChangeTab('pull-refresh')}> | ||
下拉刷新 | ||
</Button> | ||
<Button size="large" variant="outline" theme="primary" onClick={() => onChangeTab('error-tip')}> | ||
错误提示 | ||
</Button> | ||
</TDemoBlock> | ||
</div> | ||
)} | ||
{currentTab === 'base' && <BaseList></BaseList>} | ||
{currentTab === 'error-tip' && <ErrTipDemo></ErrTipDemo>} | ||
{currentTab === 'pull-refresh' && ( | ||
<div className="pull-refresh-wrap"> | ||
<PullRefreshDemo /> | ||
</div> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.