1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
| import React from 'react' import { ListView, Flex, Icon, } from 'antd-mobile' import { Component as RefastComponent } from 'refast'
export default class extends RefastComponent {
constructor(props) { super(props, logic) const dataSource = new ListView.DataSource({ rowHasChanged: (row1, row2) => { return row1 == row2 } }) this.state = { dataSource: dataSource.cloneWithRows({}), originValue: [], fetchLoading: false, page: 1, pageSize: 10, total: 0, } }
row = (rowData, sectionID, rowID) => { const { originValue } = this.state const { } = rowData return ( <div>
</div> ) }
componentDidMount = async () => { this.add_list_Listener() await this.fetchData() }
componentWillUnmount () { this.remove_list_Listener() }
add_list_Listener = () => { if (this.lv && typeof this.lv.getInnerViewNode == "function") { this.lv.getInnerViewNode().addEventListener('touchstart', this.ts = (e) => { this.tsPageY = e.touches[0].pageY; }); const scrollNode = document.scrollingElement ? document.scrollingElement : document.body; this.lv.getInnerViewNode().addEventListener('touchmove', this.tm = (e) => { this.tmPageY = e.touches[0].pageY; if (this.tmPageY > this.tsPageY && this.scrollerTop <= 0 && scrollNode.scrollTop > 0) { this.domScroller.options.preventDefaultOnTouchMove = false; } else { this.domScroller.options.preventDefaultOnTouchMove = undefined; } }) } }
remove_list_Listener = () => { if (this.lv && typeof this.lv.getInnerViewNode == "function") { this.lv.getInnerViewNode().removeEventListener('touchstart', this.ts); this.lv.getInnerViewNode().removeEventListener('touchmove', this.tm); } }
fetchData = async (init = false) => { this.setState({ fetchLoading: true }) const { originValue, dataSource, page, pageSize, name, cameraId, startTime, stopTime, status, algoModelType } = this.state this.dispatch("queryWarnEvent", { algoModel, page, pageSize, algoModelType, status, name, cameraId, startTime, stopTime, }, (content) => { const data = content?.data?.list if (status === "0") { this.setState({ todoCount: content?.data.total }) } const newValue = init ? [...data] : [...originValue, ...data] let newDataSource = dataSource if (init) { newDataSource = new ListView.DataSource({ rowHasChanged: (row1, row2) => row1 == row2, }) } newDataSource = newDataSource.cloneWithRows(newValue) this.setState({ originValue: newValue, dataSource: newDataSource, fetchLoading: false, total: content?.data.total }) }) }
onEndReached = () => { let { fetchLoading, page, originValue, total } = this.state if (fetchLoading || originValue.length >= total) { return } this.setState({ page: page + 1 }, this.fetchData) }
render () { const { dataSource, fetchLoading } = this.state return ( <ListView className="warning-list" ref={el => this.lv = el} dataSource={dataSource} renderFooter={() => { return ( <div style={{ padding: 30, textAlign: 'center' }}> {fetchLoading ? <Icon type="loading" /> : '没有更多了'} </div> ) }} renderRow={this.row} style={{ height: '100vh', overflow: 'auto', }} pageSize={10} scrollRenderAheadDistance={500} onEndReached={this.onEndReached} onEndReachedThreshold={10} /> ) }
}
|