up
This commit is contained in:
@@ -0,0 +1,184 @@
|
||||
<template>
|
||||
<div class="series-manage">
|
||||
<el-card shadow="never">
|
||||
<template #header>
|
||||
<div class="header">
|
||||
<span>系列管理</span>
|
||||
<div>
|
||||
<el-input v-model="keyword" placeholder="搜索系列标题" clearable
|
||||
style="width: 200px; margin-right: 8px" @keyup.enter="load" />
|
||||
<el-button type="primary" @click="showCreate">+ 新建系列</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<el-table :data="list" v-loading="loading" stripe>
|
||||
<el-table-column prop="id" label="ID" width="70" />
|
||||
<el-table-column prop="title" label="系列标题" min-width="160">
|
||||
<template #default="{ row }">
|
||||
<div class="title-col">
|
||||
<img v-if="row.cover_url" :src="row.cover_url" class="cover" />
|
||||
<span>{{ row.title }}</span>
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="total_episodes" label="集数" width="90" />
|
||||
<el-table-column label="状态" width="80">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="row.status === 1 ? 'success' : 'info'" size="small">
|
||||
{{ row.status === 1 ? '正常' : '隐藏' }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="created_at" label="创建时间" width="170" />
|
||||
<el-table-column label="操作" width="180" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button link type="primary" @click="showEdit(row)">编辑</el-button>
|
||||
<el-button link type="primary" @click="toggleStatus(row)">
|
||||
{{ row.status === 1 ? '隐藏' : '恢复' }}
|
||||
</el-button>
|
||||
<el-button link type="danger" @click="del(row)">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<el-pagination
|
||||
v-model:current-page="page"
|
||||
:page-size="pageSize"
|
||||
:total="total"
|
||||
layout="total, prev, pager, next"
|
||||
style="margin-top: 12px; text-align: right"
|
||||
@current-change="load"
|
||||
/>
|
||||
</el-card>
|
||||
|
||||
<!-- 新建/编辑弹窗 -->
|
||||
<el-dialog v-model="dialogVisible" :title="editing ? '编辑系列' : '新建系列'" width="480px">
|
||||
<el-form :model="form" label-width="90px">
|
||||
<el-form-item label="标题">
|
||||
<el-input v-model="form.title" maxlength="100" show-word-limit />
|
||||
</el-form-item>
|
||||
<el-form-item label="封面图 URL">
|
||||
<el-input v-model="form.cover_url" placeholder="https://..." />
|
||||
</el-form-item>
|
||||
<el-form-item label="分类">
|
||||
<el-select v-model="form.category_id" placeholder="请选择" style="width: 100%">
|
||||
<el-option v-for="c in categories" :key="c.id" :label="c.name" :value="c.id" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="简介">
|
||||
<el-input v-model="form.description" type="textarea" :rows="3" maxlength="500" show-word-limit />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="dialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="submitting" @click="save">保存</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { reactive, ref, onMounted } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import request from '@/api/request'
|
||||
|
||||
const list = ref([])
|
||||
const total = ref(0)
|
||||
const page = ref(1)
|
||||
const pageSize = 20
|
||||
const loading = ref(false)
|
||||
const keyword = ref('')
|
||||
const categories = ref([])
|
||||
const dialogVisible = ref(false)
|
||||
const editing = ref(null)
|
||||
const submitting = ref(false)
|
||||
|
||||
const form = reactive({
|
||||
title: '', cover_url: '', description: '', category_id: 0,
|
||||
})
|
||||
|
||||
onMounted(async () => {
|
||||
load()
|
||||
try {
|
||||
const r = await request({ url: '/categories', method: 'get' })
|
||||
categories.value = r.data || []
|
||||
} catch (e) {}
|
||||
})
|
||||
|
||||
async function load() {
|
||||
loading.value = true
|
||||
try {
|
||||
const r = await request({
|
||||
url: '/admin/series', method: 'get',
|
||||
params: { keyword: keyword.value, page: page.value, page_size: pageSize },
|
||||
})
|
||||
list.value = r.data.list
|
||||
total.value = r.data.total
|
||||
} catch (e) {} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function showCreate() {
|
||||
editing.value = null
|
||||
Object.assign(form, { title: '', cover_url: '', description: '', category_id: 0 })
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
function showEdit(row) {
|
||||
editing.value = row
|
||||
Object.assign(form, {
|
||||
title: row.title, cover_url: row.cover_url,
|
||||
description: row.description, category_id: row.category_id ?? 0,
|
||||
})
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
async function save() {
|
||||
if (!form.title) { ElMessage.warning('请填标题'); return }
|
||||
submitting.value = true
|
||||
try {
|
||||
if (editing.value) {
|
||||
await request({
|
||||
url: `/admin/series/${editing.value.id}`, method: 'put', data: form,
|
||||
})
|
||||
ElMessage.success('已更新')
|
||||
} else {
|
||||
await request({ url: '/admin/series', method: 'post', data: form })
|
||||
ElMessage.success('已创建')
|
||||
}
|
||||
dialogVisible.value = false
|
||||
load()
|
||||
} catch (e) {} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function toggleStatus(row) {
|
||||
const next = row.status === 1 ? 0 : 1
|
||||
try {
|
||||
await request({
|
||||
url: `/admin/series/${row.id}`, method: 'put',
|
||||
data: { status: next },
|
||||
})
|
||||
ElMessage.success('已更新')
|
||||
load()
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
async function del(row) {
|
||||
await ElMessageBox.confirm(`确认删除「${row.title}」?`, '警告', { type: 'warning' })
|
||||
try {
|
||||
await request({ url: `/admin/series/${row.id}`, method: 'delete' })
|
||||
ElMessage.success('已删除')
|
||||
load()
|
||||
} catch (e) {}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.header { display: flex; justify-content: space-between; align-items: center; }
|
||||
.title-col { display: flex; align-items: center; gap: 8px; }
|
||||
.cover { width: 40px; height: 40px; border-radius: 4px; object-fit: cover; }
|
||||
</style>
|
||||
Reference in New Issue
Block a user