|
@@ -1,10 +1,15 @@
|
|
|
<template>
|
|
|
- <CommonPage back :title="detail.title ">
|
|
|
+ <CommonPage back :title="detail.title">
|
|
|
<template #action>
|
|
|
- <NButton type="primary" @click="handleAdd()">
|
|
|
- <i class="i-material-symbols:add mr-4 text-18" />
|
|
|
- 新增子菜单
|
|
|
- </NButton>
|
|
|
+ <n-space>
|
|
|
+ <NButton type="tertiary" @click="handleTopMenuEdit">
|
|
|
+ 编辑
|
|
|
+ </NButton>
|
|
|
+ <NButton type="primary" @click="handleSubAdd()">
|
|
|
+ <i class="i-material-symbols:add mr-4 text-18" />
|
|
|
+ 新增子菜单
|
|
|
+ </NButton>
|
|
|
+ </n-space>
|
|
|
</template>
|
|
|
|
|
|
<MeCrud ref="$table" v-model:query-items="queryItems" :scroll-x="1200" :columns="columns" :get-data="api.read">
|
|
@@ -24,7 +29,7 @@
|
|
|
</MeCrud>
|
|
|
|
|
|
<MeModal ref="modalRef" width="520px">
|
|
|
- <n-form ref="modalFormRef" label-placement="left" label-align="left" :label-width="80" :model="modalForm">
|
|
|
+ <n-form ref="modalFormRef" label-placement="left" label-align="left" :label-width="95" :model="modalForm">
|
|
|
<n-form-item
|
|
|
label="名称" path="title" :rule="{
|
|
|
required: true,
|
|
@@ -34,7 +39,7 @@
|
|
|
>
|
|
|
<n-input v-model:value="modalForm.title" />
|
|
|
</n-form-item>
|
|
|
- <n-form-item label="封面" path="cover">
|
|
|
+ <n-form-item v-if="modalForm.level !== 0" label="封面" path="cover">
|
|
|
<n-upload
|
|
|
:multiple="false"
|
|
|
:default-upload="true"
|
|
@@ -66,7 +71,12 @@
|
|
|
v-model:value="modalForm.categoryId" :options="allCategory" clearable filterable tag
|
|
|
/>
|
|
|
</n-form-item>
|
|
|
-
|
|
|
+ <n-form-item
|
|
|
+ v-if="modalForm.level === 0"
|
|
|
+ label="一行显示数" path="grid"
|
|
|
+ >
|
|
|
+ <n-input-number v-model:value="modalForm.grid" style="width:100%" />
|
|
|
+ </n-form-item>
|
|
|
<n-form-item label="是否显示" path="isPublish">
|
|
|
<NSwitch v-model:value="modalForm.isPublish">
|
|
|
<template #checked>
|
|
@@ -97,7 +107,7 @@ import { MeCrud, MeModal, MeQueryItem } from '@/components'
|
|
|
import { useCrud } from '@/composables'
|
|
|
import { useUserStore } from '@/store/index.js'
|
|
|
import { formatDateTime } from '@/utils'
|
|
|
-import { NButton, NSwitch } from 'naive-ui'
|
|
|
+import { NButton, NImage, NSwitch } from 'naive-ui'
|
|
|
import { useRoute, useRouter } from 'vue-router'
|
|
|
import categoryApi from '../category/api'
|
|
|
import api from './api.js'
|
|
@@ -142,6 +152,17 @@ const columns = [
|
|
|
{ title: '标题名', key: 'title', width: '200' },
|
|
|
{ title: '分类', key: 'category.title' },
|
|
|
{
|
|
|
+ title: '封面图',
|
|
|
+ key: 'cover',
|
|
|
+ render: row => row.cover
|
|
|
+ ? h(NImage, {
|
|
|
+ src: row.cover,
|
|
|
+ height: 60,
|
|
|
+ width: 80,
|
|
|
+ })
|
|
|
+ : null,
|
|
|
+ },
|
|
|
+ {
|
|
|
title: '创建时间',
|
|
|
key: 'createTime',
|
|
|
render: row => h('span', formatDateTime(row.createTime)),
|
|
@@ -224,7 +245,9 @@ async function handleEnable(row) {
|
|
|
watchEffect(() => {
|
|
|
if (userId) {
|
|
|
modalForm.value.userId = userId
|
|
|
- modalForm.value.parentId = detail.value.id
|
|
|
+ if (modalForm.value.level !== 0) {
|
|
|
+ modalForm.value.parentId = detail.value.id
|
|
|
+ }
|
|
|
}
|
|
|
})
|
|
|
onMounted(() => {
|
|
@@ -276,6 +299,24 @@ function handleCoverRemove() {
|
|
|
previewImageUrl.value = ''
|
|
|
}
|
|
|
|
|
|
+function handleSubAdd() {
|
|
|
+ modalForm.value.level = 1
|
|
|
+ handleAdd({ level: 1 })
|
|
|
+}
|
|
|
+
|
|
|
+function handleTopMenuEdit() {
|
|
|
+ modalForm.value = {
|
|
|
+ cover: '',
|
|
|
+ ...detail.value,
|
|
|
+ userId,
|
|
|
+ level: 0,
|
|
|
+ parentId: null,
|
|
|
+ }
|
|
|
+ handleEdit(modalForm.value, '编辑顶层菜单', () => {
|
|
|
+ getMenuDetail()
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
const allCategory = ref([])
|
|
|
categoryApi.getAll().then(({ data = [] }) => (allCategory.value = data.map(item => ({ label: item.title, value: item.id }))))
|
|
|
</script>
|