yarn add rc-virtual-list
import React, { PureComponent } from 'react'
import { connect } from 'react-redux'
import { PlayScreen } from './style'
import { PlayCircleFilled, DeleteOutlined } from '@ant-design/icons'
import {
changeCurrentIndexAction,
removeSongList,
GetSongLyric,
clearSongList,
} from '../store/createActionType'
// 时间格式化函数
import VirtualList from 'rc-virtual-list'
import 'react-virtualized/styles.css';
import { formatMinuteSecond } from '../../../assets/js/format-utils'
// 全局变量
import '../global'
class Index extends PureComponent {
// 歌词所在的位置
isPosition = React.createRef()
// 歌词内容
isContent = React.createRef()
// 左边栏列表高度
isSongs = React.createRef()
state = {
currentIndex: -1,
}
// 组件挂载函数
componentDidMount() {
// 初始化时确保滚动位置同步
// 控制右侧歌词滚动位置
this.isPosition.current &&
this.isContent.current.scrollTo(0, this.isPosition.current.offsetTop)
// 控制左侧歌曲列表滚动位置
this.isSongs.current &&
this.isSongs.current.scrollTo({
index: this.props.currentIndex,
offset: 150,
align: 'auto',
})
}
// 组件更新函数
componentDidUpdate(preVal) {
if (preVal.currentNumber !== this.props.currentNumber) {
// 控制右侧歌词滚动位置
this.isPosition.current &&
this.isContent