diff --git a/src/pages/video/index.tsx b/src/pages/video/index.tsx index 59a9c0e..c8adcad 100644 --- a/src/pages/video/index.tsx +++ b/src/pages/video/index.tsx @@ -8,10 +8,11 @@ import {clsx} from "clsx"; import {VideoListItem} from "@/components/video/video-list-item.tsx"; import ArticleEditModal from "@/components/article/edit-modal.tsx"; -import {deleteByIds, getList} from "@/service/api/video.ts"; +import {deleteByIds, getList, modifyOrder, push2room} from "@/service/api/video.ts"; import {formatDuration} from "@/util/strings.ts"; import ButtonPush2Room from "@/pages/video/components/button-push2room.tsx"; import ButtonBatch from "@/components/button-batch.tsx"; +import {showErrorToast, showToast} from "@/components/message.ts"; export default function VideoIndex() { @@ -28,6 +29,8 @@ export default function VideoIndex() { // 加载列表 const loadList = () => { getList().then((ret) => { + console.log('origin list', ret.list.map(s => s.id)) + setCheckedIdArray([]) setVideoData(ret.list || []) setState({checkedAll: false, playingIndex: -1}) }) @@ -35,8 +38,8 @@ export default function VideoIndex() { // 播放视频 const playVideo = (video: VideoInfo, playingIndex: number) => { - setState({playingIndex}) if (videoRef.current && video.oss_video_url) { + setState({playingIndex}) videoRef.current!.src = video.oss_video_url } } @@ -47,6 +50,15 @@ export default function VideoIndex() { checkedAll: !state.checkedAll }) } + const handleModifySort = () => { + + setVideoData((items) => { + modifyOrder(items.map(s => s.id)).catch(() => { + showToast('调整视频顺序失败,请重试!') + }).finally(loadList) + return items; + }) + } // useEffect(loadList, []) const totalDuration = useMemo(() => { @@ -95,6 +107,7 @@ export default function VideoIndex() { if (over && active.id !== over.id) { let oldIndex = -1, newIndex = -1; const originArr = [...videoData] + console.log(originArr.map(s => s.id)) setVideoData((items) => { oldIndex = items.findIndex(s => s.id == active.id); newIndex = items.findIndex(s => s.id == over.id); @@ -103,6 +116,7 @@ export default function VideoIndex() { modal.confirm({ title: '提示', content: '是否要移动到指定位置', + onOk: handleModifySort, onCancel: () => { setVideoData(originArr); } @@ -139,12 +153,20 @@ export default function VideoIndex() {