chore(merge): 剧集列表改为服务端分页
This commit is contained in:
commit
99bb666e47
3 files changed
+127
-39
No files matched your search
@@ -1,10 +1,17 @@
|
|||||||
// Author: fruit.com.cn
|
// Author: fruit.com.cn
|
||||||
|
|
||||||
import request from '@/axios'
|
import request from '@/axios'
|
||||||
import type { EpisodeItem, EpisodeSaveData } from './types'
|
import type { EpisodeItem, EpisodeSaveData, PageResult } from './types'
|
||||||
|
|
||||||
export const listEpisodesApi = (dramaId: number, status?: string) => {
|
export interface EpisodePageParams {
|
||||||
return request.get<EpisodeItem[]>({ url: '/admin/episodes', params: { dramaId, status } })
|
dramaId: number
|
||||||
|
status?: string
|
||||||
|
pageIndex?: number
|
||||||
|
pageSize?: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export const listEpisodesApi = (params: EpisodePageParams) => {
|
||||||
|
return request.get<PageResult<EpisodeItem>>({ url: '/admin/episodes', params })
|
||||||
}
|
}
|
||||||
|
|
||||||
export const createEpisodeApi = (data: EpisodeSaveData) => {
|
export const createEpisodeApi = (data: EpisodeSaveData) => {
|
||||||
|
|||||||
@@ -560,13 +560,16 @@ body {
|
|||||||
gap: 6px;
|
gap: 6px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.drama-select {
|
.drama-select,
|
||||||
|
.status-select {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
.drama-select .el-input__wrapper {
|
.drama-select .el-input__wrapper,
|
||||||
|
.status-select .el-input__wrapper {
|
||||||
box-shadow: 0 0 0 1px #efedf3 inset !important;
|
box-shadow: 0 0 0 1px #efedf3 inset !important;
|
||||||
}
|
}
|
||||||
.drama-select .el-input__inner {
|
.drama-select .el-input__inner,
|
||||||
|
.status-select .el-input__inner {
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ import BatchUploadDialog from './upload/BatchUploadDialog.vue'
|
|||||||
import EpisodeFormDialog from './upload/EpisodeFormDialog.vue'
|
import EpisodeFormDialog from './upload/EpisodeFormDialog.vue'
|
||||||
import { listPendingSessions } from './upload/uploadSessions'
|
import { listPendingSessions } from './upload/uploadSessions'
|
||||||
|
|
||||||
|
/** 排序/批量建集需要全集快照,单次请求不超过接口 pageSize 上限。 */
|
||||||
|
const SNAPSHOT_PAGE_SIZE = 200
|
||||||
const DEFAULT_PAGE_SIZE = 100
|
const DEFAULT_PAGE_SIZE = 100
|
||||||
const PAGE_SIZE_OPTIONS = [50, 100, 200]
|
const PAGE_SIZE_OPTIONS = [50, 100, 200]
|
||||||
|
|
||||||
@@ -25,29 +27,27 @@ const { t } = useI18n()
|
|||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const dramas = ref([])
|
const dramas = ref([])
|
||||||
const episodes = ref([])
|
const episodes = ref([])
|
||||||
|
const total = ref(0)
|
||||||
const selectedDramaId = ref(undefined)
|
const selectedDramaId = ref(undefined)
|
||||||
|
const statusFilter = ref(undefined)
|
||||||
const pageIndex = ref(1)
|
const pageIndex = ref(1)
|
||||||
const pageSize = ref(DEFAULT_PAGE_SIZE)
|
const pageSize = ref(DEFAULT_PAGE_SIZE)
|
||||||
const batchUploadVisible = ref(false)
|
const batchUploadVisible = ref(false)
|
||||||
const previewVisible = ref(false)
|
const previewVisible = ref(false)
|
||||||
const previewEpisode = ref(null)
|
const previewEpisode = ref(null)
|
||||||
const formDialogRef = ref()
|
const formDialogRef = ref()
|
||||||
|
/** 上移/下移与批量建集用的全集快照。 */
|
||||||
|
const snapshotEpisodes = ref([])
|
||||||
|
|
||||||
const batchNextNumber = computed(() => nextNumber())
|
const batchNextNumber = computed(() => nextNumber())
|
||||||
const selectedDrama = computed(() => dramas.value.find((item) => item.id === selectedDramaId.value))
|
const selectedDrama = computed(() => dramas.value.find((item) => item.id === selectedDramaId.value))
|
||||||
const existingEpisodeNumbers = computed(() =>
|
const existingEpisodeNumbers = computed(() =>
|
||||||
episodes.value.map((item) => Number(item.number)).filter((n) => Number.isFinite(n))
|
snapshotEpisodes.value.map((item) => Number(item.number)).filter((n) => Number.isFinite(n))
|
||||||
)
|
)
|
||||||
|
|
||||||
const pagedEpisodes = computed(() => {
|
|
||||||
const start = (pageIndex.value - 1) * pageSize.value
|
|
||||||
return episodes.value.slice(start, start + pageSize.value)
|
|
||||||
})
|
|
||||||
|
|
||||||
const showPagination = computed(() => {
|
const showPagination = computed(() => {
|
||||||
const total = episodes.value.length
|
if (total.value <= 0) return false
|
||||||
if (total <= 0) return false
|
return Math.ceil(total.value / pageSize.value) > 1
|
||||||
return Math.ceil(total / pageSize.value) > 1
|
|
||||||
})
|
})
|
||||||
|
|
||||||
async function loadDramas() {
|
async function loadDramas() {
|
||||||
@@ -65,31 +65,73 @@ async function loadDramas() {
|
|||||||
async function loadEpisodes() {
|
async function loadEpisodes() {
|
||||||
if (!selectedDramaId.value) {
|
if (!selectedDramaId.value) {
|
||||||
episodes.value = []
|
episodes.value = []
|
||||||
|
total.value = 0
|
||||||
|
snapshotEpisodes.value = []
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
loading.value = true
|
loading.value = true
|
||||||
try {
|
try {
|
||||||
const res = await listEpisodesApi(selectedDramaId.value)
|
const res = await listEpisodesApi({
|
||||||
episodes.value = res.data || []
|
dramaId: selectedDramaId.value,
|
||||||
clampPageIndex()
|
status: statusFilter.value || undefined,
|
||||||
|
pageIndex: pageIndex.value,
|
||||||
|
pageSize: pageSize.value
|
||||||
|
})
|
||||||
|
episodes.value = res.data?.list || []
|
||||||
|
total.value = res.data?.total || 0
|
||||||
|
await clampOrRetreatPage()
|
||||||
} finally {
|
} finally {
|
||||||
loading.value = false
|
loading.value = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 刷新后若当前页越界(如删除末页最后一条),夹到最后一页。 */
|
/** 拉当前剧全集快照,供排序与批量建集集号计算。不过滤 status,按页取完。 */
|
||||||
function clampPageIndex() {
|
async function refreshSnapshot() {
|
||||||
const total = episodes.value.length
|
if (!selectedDramaId.value) {
|
||||||
const maxPage = Math.max(1, Math.ceil(total / pageSize.value) || 1)
|
snapshotEpisodes.value = []
|
||||||
if (pageIndex.value > maxPage) pageIndex.value = maxPage
|
return
|
||||||
|
}
|
||||||
|
const collected = []
|
||||||
|
let page = 1
|
||||||
|
let totalCount = 0
|
||||||
|
do {
|
||||||
|
const res = await listEpisodesApi({
|
||||||
|
dramaId: selectedDramaId.value,
|
||||||
|
pageIndex: page,
|
||||||
|
pageSize: SNAPSHOT_PAGE_SIZE
|
||||||
|
})
|
||||||
|
const list = res.data?.list || []
|
||||||
|
totalCount = Number(res.data?.total || 0)
|
||||||
|
collected.push(...list)
|
||||||
|
if (!list.length) break
|
||||||
|
page += 1
|
||||||
|
} while (collected.length < totalCount)
|
||||||
|
snapshotEpisodes.value = collected
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除后若当前页空且仍有数据,回退上一页再拉;否则夹页。
|
||||||
|
*/
|
||||||
|
async function clampOrRetreatPage() {
|
||||||
|
const maxPage = Math.max(1, Math.ceil(total.value / pageSize.value) || 1)
|
||||||
|
if (episodes.value.length === 0 && total.value > 0 && pageIndex.value > 1) {
|
||||||
|
pageIndex.value = Math.min(pageIndex.value - 1, maxPage)
|
||||||
|
await loadEpisodes()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (pageIndex.value > maxPage) {
|
||||||
|
pageIndex.value = maxPage
|
||||||
|
await loadEpisodes()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function nextNumber() {
|
function nextNumber() {
|
||||||
return episodes.value.reduce((max, item) => Math.max(max, item.number || 0), 0) + 1
|
return snapshotEpisodes.value.reduce((max, item) => Math.max(max, item.number || 0), 0) + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
function openBatchUpload() {
|
async function openBatchUpload() {
|
||||||
if (!selectedDramaId.value) return
|
if (!selectedDramaId.value) return
|
||||||
|
await refreshSnapshot()
|
||||||
batchUploadVisible.value = true
|
batchUploadVisible.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,7 +139,8 @@ async function onBatchEpisodesCreated() {
|
|||||||
await loadEpisodes()
|
await loadEpisodes()
|
||||||
}
|
}
|
||||||
|
|
||||||
function openCreate() {
|
async function openCreate() {
|
||||||
|
await refreshSnapshot()
|
||||||
formDialogRef.value?.openCreate()
|
formDialogRef.value?.openCreate()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,6 +161,9 @@ async function confirmDelete(row) {
|
|||||||
}
|
}
|
||||||
await deleteEpisodeApi(row.id)
|
await deleteEpisodeApi(row.id)
|
||||||
ElMessage.success('剧集已删除')
|
ElMessage.success('剧集已删除')
|
||||||
|
if (episodes.value.length === 1 && pageIndex.value > 1) {
|
||||||
|
pageIndex.value -= 1
|
||||||
|
}
|
||||||
await loadEpisodes()
|
await loadEpisodes()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,25 +192,32 @@ function stopThumb(event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function episodeIndexInFullList(row) {
|
function pageLocalIndex(row) {
|
||||||
return episodes.value.findIndex((item) => item.id === row.id)
|
return episodes.value.findIndex((item) => item.id === row.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function globalIndex(row) {
|
||||||
|
const local = pageLocalIndex(row)
|
||||||
|
if (local < 0) return -1
|
||||||
|
return (pageIndex.value - 1) * pageSize.value + local
|
||||||
|
}
|
||||||
|
|
||||||
function canMoveUp(row) {
|
function canMoveUp(row) {
|
||||||
return episodeIndexInFullList(row) > 0
|
return globalIndex(row) > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
function canMoveDown(row) {
|
function canMoveDown(row) {
|
||||||
const index = episodeIndexInFullList(row)
|
const index = globalIndex(row)
|
||||||
return index >= 0 && index < episodes.value.length - 1
|
return index >= 0 && index < total.value - 1
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 上移/下移后把新顺序整表提交,由后端重排 sort。 */
|
/** 上移/下移后把快照新顺序整表提交,由后端重排 sort。 */
|
||||||
async function move(row, offset) {
|
async function move(row, offset) {
|
||||||
const index = episodeIndexInFullList(row)
|
await refreshSnapshot()
|
||||||
|
const index = snapshotEpisodes.value.findIndex((item) => item.id === row.id)
|
||||||
const target = index + offset
|
const target = index + offset
|
||||||
if (index < 0 || target < 0 || target >= episodes.value.length) return
|
if (index < 0 || target < 0 || target >= snapshotEpisodes.value.length) return
|
||||||
const next = [...episodes.value]
|
const next = [...snapshotEpisodes.value]
|
||||||
const [moved] = next.splice(index, 1)
|
const [moved] = next.splice(index, 1)
|
||||||
next.splice(target, 0, moved)
|
next.splice(target, 0, moved)
|
||||||
await sortEpisodesApi(next.map((item) => item.id))
|
await sortEpisodesApi(next.map((item) => item.id))
|
||||||
@@ -174,12 +227,23 @@ async function move(row, offset) {
|
|||||||
|
|
||||||
async function onDramaChange() {
|
async function onDramaChange() {
|
||||||
pageIndex.value = 1
|
pageIndex.value = 1
|
||||||
|
statusFilter.value = undefined
|
||||||
await loadEpisodes()
|
await loadEpisodes()
|
||||||
openBatchIfPendingSessions()
|
openBatchIfPendingSessions()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onStatusChange() {
|
||||||
|
pageIndex.value = 1
|
||||||
|
loadEpisodes()
|
||||||
|
}
|
||||||
|
|
||||||
function handleSizeChange() {
|
function handleSizeChange() {
|
||||||
pageIndex.value = 1
|
pageIndex.value = 1
|
||||||
|
loadEpisodes()
|
||||||
|
}
|
||||||
|
|
||||||
|
function handlePageChange() {
|
||||||
|
loadEpisodes()
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 进入页面或切换短剧时,若有 24h 内未完成上传则打开批量上传弹窗以提示续传。 */
|
/** 进入页面或切换短剧时,若有 24h 内未完成上传则打开批量上传弹窗以提示续传。 */
|
||||||
@@ -220,7 +284,7 @@ onMounted(async () => {
|
|||||||
<span class="episode-context-label">当前短剧</span>
|
<span class="episode-context-label">当前短剧</span>
|
||||||
<b class="episode-context-title">{{ selectedDrama?.title || '暂无短剧' }}</b>
|
<b class="episode-context-title">{{ selectedDrama?.title || '暂无短剧' }}</b>
|
||||||
<small class="episode-context-count"
|
<small class="episode-context-count"
|
||||||
>共 {{ selectedDrama?.episodes ?? episodes.length }} 集 · 收藏
|
>共 {{ selectedDrama?.episodes ?? total }} 集 · 收藏
|
||||||
{{ formatCount(selectedDrama?.favoriteCount ?? 0) }} · 热度
|
{{ formatCount(selectedDrama?.favoriteCount ?? 0) }} · 热度
|
||||||
{{ formatCount(selectedDrama?.views ?? 0) }}</small
|
{{ formatCount(selectedDrama?.views ?? 0) }}</small
|
||||||
>
|
>
|
||||||
@@ -240,15 +304,28 @@ onMounted(async () => {
|
|||||||
:value="item.id"
|
:value="item.id"
|
||||||
/>
|
/>
|
||||||
</el-select>
|
</el-select>
|
||||||
|
<span class="episode-context-label">状态</span>
|
||||||
|
<el-select
|
||||||
|
v-model="statusFilter"
|
||||||
|
clearable
|
||||||
|
placeholder="全部状态"
|
||||||
|
class="status-select"
|
||||||
|
@change="onStatusChange"
|
||||||
|
>
|
||||||
|
<el-option label="草稿" value="draft" />
|
||||||
|
<el-option label="已上线" value="published" />
|
||||||
|
<el-option label="已下线" value="offline" />
|
||||||
|
</el-select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="episode-toolbar"
|
<div class="episode-toolbar"
|
||||||
><div
|
><div
|
||||||
><h2>剧集列表({{ episodes.length }})</h2><p>按列表顺序播放</p></div
|
><h2>剧集列表({{ total }})</h2><p>按列表顺序播放</p></div
|
||||||
></div>
|
></div
|
||||||
|
>
|
||||||
<el-table
|
<el-table
|
||||||
v-loading="loading"
|
v-loading="loading"
|
||||||
:data="pagedEpisodes"
|
:data="episodes"
|
||||||
row-key="id"
|
row-key="id"
|
||||||
empty-text="该短剧暂无剧集"
|
empty-text="该短剧暂无剧集"
|
||||||
class="drama-el-table episode-el-table"
|
class="drama-el-table episode-el-table"
|
||||||
@@ -356,11 +433,12 @@ onMounted(async () => {
|
|||||||
v-model:current-page="pageIndex"
|
v-model:current-page="pageIndex"
|
||||||
v-model:page-size="pageSize"
|
v-model:page-size="pageSize"
|
||||||
:page-sizes="PAGE_SIZE_OPTIONS"
|
:page-sizes="PAGE_SIZE_OPTIONS"
|
||||||
:total="episodes.length"
|
:total="total"
|
||||||
:pager-count="7"
|
:pager-count="7"
|
||||||
layout="total, sizes, prev, pager, next, jumper"
|
layout="total, sizes, prev, pager, next, jumper"
|
||||||
background
|
background
|
||||||
@size-change="handleSizeChange"
|
@size-change="handleSizeChange"
|
||||||
|
@current-change="handlePageChange"
|
||||||
/></div>
|
/></div>
|
||||||
</section>
|
</section>
|
||||||
<EpisodeFormDialog
|
<EpisodeFormDialog
|
||||||
|
|||||||
Reference in new issue
Block a user