feat: 更新新闻管理功能,新增摘要和排序顺序字段,优化上传组件逻辑
This commit is contained in:
@@ -55,7 +55,7 @@ async function handleCustomRequest({ file, onProgress, onFinish, onError }: Uplo
|
||||
}
|
||||
|
||||
// 验证文件数量
|
||||
if (fileList.value.length >= props.maxFiles) {
|
||||
if (fileList.value.length > props.maxFiles) {
|
||||
window.$message?.error(`最多只能上传 ${props.maxFiles} 个文件`);
|
||||
onError();
|
||||
return;
|
||||
|
||||
@@ -96,6 +96,19 @@ const rules: FormRules = {
|
||||
trigger: ['blur', 'input']
|
||||
}
|
||||
],
|
||||
summary: [
|
||||
{
|
||||
required: true,
|
||||
message: '请输入新闻摘要',
|
||||
trigger: ['blur', 'input']
|
||||
},
|
||||
{
|
||||
min: 10,
|
||||
max: 200,
|
||||
message: '摘要长度应在10-200个字符之间',
|
||||
trigger: ['blur', 'input']
|
||||
}
|
||||
],
|
||||
content: [
|
||||
{
|
||||
required: true,
|
||||
@@ -144,24 +157,42 @@ async function handleSubmit() {
|
||||
require-mark-placement="left"
|
||||
>
|
||||
<NFormItem label="新闻标题" path="title">
|
||||
<NInput v-model:value="form.title" placeholder="请输入新闻标题" maxlength="200" show-count />
|
||||
<NInput v-model:value="form.title" placeholder="请输入新闻标题" maxlength="50" show-count />
|
||||
</NFormItem>
|
||||
|
||||
<NFormItem label="新闻分类" path="categoryId">
|
||||
<NSelect v-model:value="form.categoryId" :options="categoryOptions" placeholder="请选择新闻分类" class="flex-1">
|
||||
<template #action>
|
||||
<div class="px-3 py-2">
|
||||
<NButton size="small" type="primary" block @click.stop="handleAddCategory">
|
||||
<template #icon>
|
||||
<icon-ic-round-plus class="text-icon" />
|
||||
</template>
|
||||
新增分类
|
||||
</NButton>
|
||||
</div>
|
||||
</template>
|
||||
</NSelect>
|
||||
<NFormItem label="缩略图" path="thumbnailId">
|
||||
<UploadS3
|
||||
:model-value="form.thumbnailId ? [form.thumbnailId] : undefined"
|
||||
:max-size="20"
|
||||
:max-files="1"
|
||||
accept="image/*"
|
||||
placeholder="上传图片"
|
||||
:fetch-options="{ businessType: 'news_attachment' }"
|
||||
@update:model-value="evt => (form.thumbnailId = evt.length > 0 ? evt[0] : undefined)"
|
||||
/>
|
||||
</NFormItem>
|
||||
|
||||
<NGrid :cols="2">
|
||||
<NFormItemGi label="新闻分类" path="categoryId">
|
||||
<NSelect v-model:value="form.categoryId" :options="categoryOptions" placeholder="请选择新闻分类" class="flex-1">
|
||||
<template #action>
|
||||
<div class="px-3 py-2">
|
||||
<NButton size="small" type="primary" block @click.stop="handleAddCategory">
|
||||
<template #icon>
|
||||
<icon-ic-round-plus class="text-icon" />
|
||||
</template>
|
||||
新增分类
|
||||
</NButton>
|
||||
</div>
|
||||
</template>
|
||||
</NSelect>
|
||||
</NFormItemGi>
|
||||
|
||||
<NFormItemGi label="新闻摘要" path="summary">
|
||||
<NInput v-model:value="form.summary" placeholder="请输入新闻摘要" maxlength="100" show-count />
|
||||
</NFormItemGi>
|
||||
</NGrid>
|
||||
|
||||
<NFormItem label="新闻内容" path="content">
|
||||
<MarkdownEditor v-model:value="form.content" placeholder="请输入新闻内容" :preview="false" />
|
||||
</NFormItem>
|
||||
@@ -178,12 +209,22 @@ async function handleSubmit() {
|
||||
/>
|
||||
</NFormItem>
|
||||
|
||||
<NFormItem label="置顶显示" path="isPinned">
|
||||
<NSwitch v-model:value="form.isPinned">
|
||||
<template #checked>是</template>
|
||||
<template #unchecked>否</template>
|
||||
</NSwitch>
|
||||
</NFormItem>
|
||||
<NGrid :cols="2">
|
||||
<NFormItemGi label="置顶显示" path="isPinned">
|
||||
<NSwitch v-model:value="form.isPinned">
|
||||
<template #checked>是</template>
|
||||
<template #unchecked>否</template>
|
||||
</NSwitch>
|
||||
</NFormItemGi>
|
||||
|
||||
<NFormItemGi label="排序顺序" path="sortOrder">
|
||||
<NInputNumber v-model:value="form.sortOrder" :min="0" :step="1" placeholder="请输入排序顺序" class="w-full">
|
||||
<template #suffix>
|
||||
<span class="text-12px text-gray-400">数字越小越靠前</span>
|
||||
</template>
|
||||
</NInputNumber>
|
||||
</NFormItemGi>
|
||||
</NGrid>
|
||||
|
||||
<NSpace justify="end" class="mt-4">
|
||||
<NButton @click="$emit('close')">取消</NButton>
|
||||
|
||||
@@ -98,6 +98,19 @@ const rules: FormRules = {
|
||||
trigger: ['blur', 'input']
|
||||
}
|
||||
],
|
||||
summary: [
|
||||
{
|
||||
required: true,
|
||||
message: '请输入新闻摘要',
|
||||
trigger: ['blur', 'input']
|
||||
},
|
||||
{
|
||||
min: 10,
|
||||
max: 200,
|
||||
message: '摘要长度应在10-200个字符之间',
|
||||
trigger: ['blur', 'input']
|
||||
}
|
||||
],
|
||||
content: [
|
||||
{
|
||||
required: true,
|
||||
@@ -149,23 +162,41 @@ async function handleSubmit() {
|
||||
<NInput v-model:value="form.title" placeholder="请输入新闻标题" maxlength="200" show-count />
|
||||
</NFormItem>
|
||||
|
||||
<NFormItem label="新闻分类" path="categoryId">
|
||||
<NSelect v-model:value="form.categoryId" :options="categoryOptions" placeholder="请选择新闻分类" class="flex-1">
|
||||
<template #action>
|
||||
<div class="px-3 py-2">
|
||||
<NButton size="small" type="primary" block @click.stop="handleAddCategory">
|
||||
<template #icon>
|
||||
<icon-ic-round-plus class="text-icon" />
|
||||
</template>
|
||||
新增分类
|
||||
</NButton>
|
||||
</div>
|
||||
</template>
|
||||
</NSelect>
|
||||
<NFormItem label="缩略图" path="thumbnailId">
|
||||
<UploadS3
|
||||
:model-value="[form.thumbnailId || '']"
|
||||
:max-size="20"
|
||||
:max-files="1"
|
||||
accept="image/*"
|
||||
placeholder="上传图片"
|
||||
:fetch-options="{ businessType: 'news_attachment' }"
|
||||
@update:model-value="evt => (form.thumbnailId = evt[0] || '')"
|
||||
/>
|
||||
</NFormItem>
|
||||
|
||||
<NGrid :cols="2">
|
||||
<NFormItemGi label="新闻分类" path="categoryId">
|
||||
<NSelect v-model:value="form.categoryId" :options="categoryOptions" placeholder="请选择新闻分类" class="flex-1">
|
||||
<template #action>
|
||||
<div class="px-3 py-2">
|
||||
<NButton size="small" type="primary" block @click.stop="handleAddCategory">
|
||||
<template #icon>
|
||||
<icon-ic-round-plus class="text-icon" />
|
||||
</template>
|
||||
新增分类
|
||||
</NButton>
|
||||
</div>
|
||||
</template>
|
||||
</NSelect>
|
||||
</NFormItemGi>
|
||||
|
||||
<NFormItemGi label="新闻摘要" path="summary">
|
||||
<NInput v-model:value="form.summary" placeholder="请输入新闻摘要" maxlength="100" show-count />
|
||||
</NFormItemGi>
|
||||
</NGrid>
|
||||
|
||||
<NFormItem label="新闻内容" path="content">
|
||||
<MarkdownEditor v-model:value="form.content" placeholder="请输入新闻内容" :preview="false" />
|
||||
<MarkdownEditor v-model:value="form.content" placeholder="请输入新闻内容" :preview="false" class="h-400px!" />
|
||||
</NFormItem>
|
||||
|
||||
<NFormItem label="附件上传" path="attachmentIds">
|
||||
@@ -180,12 +211,22 @@ async function handleSubmit() {
|
||||
/>
|
||||
</NFormItem>
|
||||
|
||||
<NFormItem label="置顶显示" path="isPinned">
|
||||
<NSwitch v-model:value="form.isPinned">
|
||||
<template #checked>是</template>
|
||||
<template #unchecked>否</template>
|
||||
</NSwitch>
|
||||
</NFormItem>
|
||||
<NGrid :cols="2">
|
||||
<NFormItemGi label="置顶显示" path="isPinned">
|
||||
<NSwitch v-model:value="form.isPinned">
|
||||
<template #checked>是</template>
|
||||
<template #unchecked>否</template>
|
||||
</NSwitch>
|
||||
</NFormItemGi>
|
||||
|
||||
<NFormItemGi label="排序顺序" path="sortOrder">
|
||||
<NInputNumber v-model:value="form.sortOrder" :min="0" :step="1" placeholder="请输入排序顺序" class="w-full">
|
||||
<template #suffix>
|
||||
<span class="text-12px text-gray-400">数字越小越靠前</span>
|
||||
</template>
|
||||
</NInputNumber>
|
||||
</NFormItemGi>
|
||||
</NGrid>
|
||||
|
||||
<NSpace justify="end" class="mt-4">
|
||||
<NButton @click="$emit('close')">取消</NButton>
|
||||
|
||||
@@ -41,6 +41,12 @@ const columns: TableBaseColumns = [
|
||||
key: 'category.name',
|
||||
width: 120
|
||||
},
|
||||
{
|
||||
title: '摘要',
|
||||
key: 'summary',
|
||||
width: 300,
|
||||
ellipsis: { tooltip: true }
|
||||
},
|
||||
{
|
||||
title: '内容预览',
|
||||
key: 'content',
|
||||
@@ -64,6 +70,11 @@ const columns: TableBaseColumns = [
|
||||
{ default: () => (row.isPinned ? '是' : '否') }
|
||||
)
|
||||
},
|
||||
{
|
||||
title: '排序顺序',
|
||||
key: 'sortOrder',
|
||||
width: 80
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
key: 'createdAt',
|
||||
@@ -150,7 +161,7 @@ function handleEdit(row: any) {
|
||||
tableInst.value?.reload();
|
||||
}
|
||||
}),
|
||||
style: { width: '800px' },
|
||||
style: { width: '1200px' },
|
||||
showIcon: false
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user