189 lines
5.8 KiB
Vue
189 lines
5.8 KiB
Vue
<!-- Author: fruit.com.cn -->
|
||
<!-- 分类管理弹窗:编辑分类,以及把短剧关联进分类。 -->
|
||
|
||
<script setup>
|
||
import { statusClass } from '@/utils/status'
|
||
import LocaleTextFields from '@/views/components/LocaleTextFields.vue'
|
||
import { AppIcon } from '@/components/AppIcon'
|
||
import { AppIcons } from '@/constants/icons'
|
||
|
||
const SORT_MAX = 9999
|
||
|
||
const STATUS_TEXT = {
|
||
draft: '草稿',
|
||
reviewing: '审核中',
|
||
approved: '待发布',
|
||
published: '已上线',
|
||
offline: '已下线'
|
||
}
|
||
|
||
defineProps({
|
||
editorVisible: { type: Boolean, default: false },
|
||
editingId: { type: [String, Number], default: null },
|
||
languages: { type: Array, default: () => ['zh'] },
|
||
form: { type: Object, required: true },
|
||
saving: { type: Boolean, default: false },
|
||
candidateVisible: { type: Boolean, default: false },
|
||
candidateLoading: { type: Boolean, default: false },
|
||
candidates: { type: Array, default: () => [] },
|
||
candidateKeyword: { type: String, default: '' },
|
||
candidatePage: { type: Number, default: 1 },
|
||
candidatePageSize: { type: Number, default: 10 },
|
||
candidateTotal: { type: Number, default: 0 },
|
||
binding: { type: Boolean, default: false },
|
||
selectedCount: { type: Number, default: 0 }
|
||
})
|
||
|
||
const emit = defineEmits([
|
||
'update:editorVisible',
|
||
'update:languages',
|
||
'update:form',
|
||
'update:candidateVisible',
|
||
'update:candidateKeyword',
|
||
'save',
|
||
'search',
|
||
'page',
|
||
'selection',
|
||
'confirm'
|
||
])
|
||
</script>
|
||
|
||
<template>
|
||
<el-dialog
|
||
:model-value="editorVisible"
|
||
:title="editingId ? '编辑分类' : '新建分类'"
|
||
width="560px"
|
||
@update:model-value="emit('update:editorVisible', $event)"
|
||
>
|
||
<el-form label-position="top">
|
||
<LocaleTextFields
|
||
:languages="languages"
|
||
:locales="form.locales"
|
||
label="名称"
|
||
:maxlength="64"
|
||
@update:languages="emit('update:languages', $event)"
|
||
@update:locales="emit('update:form', { ...form, locales: $event })"
|
||
/>
|
||
<el-form-item label="展示样式">
|
||
<el-radio-group
|
||
:model-value="form.layoutType"
|
||
@update:model-value="emit('update:form', { ...form, layoutType: $event })"
|
||
>
|
||
<el-radio-button label="GRID">普通分类</el-radio-button>
|
||
<el-radio-button label="RANKING">推荐榜</el-radio-button>
|
||
</el-radio-group>
|
||
</el-form-item>
|
||
<el-form-item label="分类编码">
|
||
<el-input
|
||
:model-value="form.code"
|
||
maxlength="64"
|
||
placeholder="例如 RECOMMEND_RANKING"
|
||
@update:model-value="emit('update:form', { ...form, code: $event.toUpperCase() })"
|
||
/>
|
||
</el-form-item>
|
||
<div class="classification-form-row">
|
||
<el-form-item label="排序">
|
||
<el-input-number
|
||
:model-value="form.sort"
|
||
:min="0"
|
||
:max="SORT_MAX"
|
||
controls-position="right"
|
||
@update:model-value="emit('update:form', { ...form, sort: $event })"
|
||
/>
|
||
</el-form-item>
|
||
<el-form-item label="状态">
|
||
<el-switch
|
||
:model-value="form.status"
|
||
:active-value="1"
|
||
:inactive-value="0"
|
||
@update:model-value="emit('update:form', { ...form, status: $event })"
|
||
/>
|
||
</el-form-item>
|
||
</div>
|
||
</el-form>
|
||
<template #footer>
|
||
<el-button @click="emit('update:editorVisible', false)">取消</el-button>
|
||
<el-button type="primary" :loading="saving" @click="emit('save')">保存</el-button>
|
||
</template>
|
||
</el-dialog>
|
||
|
||
<el-dialog
|
||
:model-value="candidateVisible"
|
||
title="添加关联短剧"
|
||
width="760px"
|
||
@update:model-value="emit('update:candidateVisible', $event)"
|
||
>
|
||
<div class="classification-toolbar__search">
|
||
<el-input
|
||
:model-value="candidateKeyword"
|
||
placeholder="搜索短剧名称"
|
||
clearable
|
||
style="width: 220px"
|
||
@update:model-value="emit('update:candidateKeyword', $event)"
|
||
@keyup.enter="emit('search')"
|
||
@clear="emit('search')"
|
||
/>
|
||
<el-button type="primary" plain @click="emit('search')">查询</el-button>
|
||
</div>
|
||
<el-table
|
||
v-loading="candidateLoading"
|
||
:data="candidates"
|
||
row-key="id"
|
||
border
|
||
max-height="380"
|
||
empty-text="没有可关联的短剧"
|
||
@selection-change="emit('selection', $event)"
|
||
>
|
||
<el-table-column type="selection" width="48" />
|
||
<el-table-column prop="title" label="短剧名称" min-width="220" />
|
||
<el-table-column label="集数" width="90">
|
||
<template #default="{ row }">{{ row.totalEpisodes || 0 }}</template>
|
||
</el-table-column>
|
||
<el-table-column label="状态" width="110">
|
||
<template #default="{ row }">
|
||
<span class="status-dot" :class="statusClass(row.status)">
|
||
{{ STATUS_TEXT[row.status] || row.status }}
|
||
</span>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column prop="sort" label="排序" width="90" />
|
||
</el-table>
|
||
<div class="classification-pagination">
|
||
<el-pagination
|
||
:current-page="candidatePage"
|
||
:page-size="candidatePageSize"
|
||
:total="candidateTotal"
|
||
layout="total, prev, pager, next"
|
||
@current-change="emit('page', $event)"
|
||
/>
|
||
</div>
|
||
<template #footer>
|
||
<el-button @click="emit('update:candidateVisible', false)">取消</el-button>
|
||
<el-button type="primary" :loading="binding" @click="emit('confirm')">
|
||
确定关联{{ selectedCount ? `(${selectedCount})` : '' }}
|
||
</el-button>
|
||
</template>
|
||
</el-dialog>
|
||
</template>
|
||
|
||
<style scoped>
|
||
.classification-form-row {
|
||
display: grid;
|
||
grid-template-columns: 1fr 1fr;
|
||
gap: 12px;
|
||
}
|
||
|
||
.classification-toolbar__search {
|
||
display: flex;
|
||
gap: 8px;
|
||
flex-wrap: wrap;
|
||
margin-bottom: 12px;
|
||
}
|
||
|
||
.classification-pagination {
|
||
display: flex;
|
||
justify-content: flex-end;
|
||
margin-top: 14px;
|
||
}
|
||
</style>
|