feat: 优化内容管理模块,简化新增和修改Banner、分类、推荐的接口,统一使用JSON格式,增强用户体验。
This commit is contained in:
@@ -19,47 +19,35 @@ export function getBanner(id) {
|
|||||||
|
|
||||||
// 新增Banner
|
// 新增Banner
|
||||||
export function addBanner(data) {
|
export function addBanner(data) {
|
||||||
const formData = new FormData()
|
|
||||||
formData.append('name', data.name)
|
|
||||||
formData.append('sort', data.sort)
|
|
||||||
formData.append('jumpUrl', data.jumpUrl || '')
|
|
||||||
if (data.file) {
|
|
||||||
formData.append('file', data.file)
|
|
||||||
}
|
|
||||||
return request({
|
return request({
|
||||||
url: '/back/banner/add',
|
url: '/back/banner/add',
|
||||||
method: 'post',
|
method: 'post',
|
||||||
data: formData,
|
data: {
|
||||||
|
name: data.name,
|
||||||
|
sort: data.sort,
|
||||||
|
jumpUrl: data.jumpUrl || '',
|
||||||
|
bannerAddr: data.bannerAddr
|
||||||
|
},
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'multipart/form-data'
|
'Content-Type': 'application/json'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改Banner
|
// 修改Banner
|
||||||
export function updateBanner(data) {
|
export function updateBanner(data) {
|
||||||
const formData = new FormData()
|
|
||||||
formData.append('id', data.id)
|
|
||||||
formData.append('name', data.name)
|
|
||||||
formData.append('sort', data.sort)
|
|
||||||
formData.append('jumpUrl', data.jumpUrl || '')
|
|
||||||
|
|
||||||
// 如果有新图片文件,上传新图片
|
|
||||||
if (data.file) {
|
|
||||||
formData.append('file', data.file)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 传递图片路径(原图片或新图片的路径)
|
|
||||||
if (data.bannerAddr) {
|
|
||||||
formData.append('bannerAddr', data.bannerAddr)
|
|
||||||
}
|
|
||||||
|
|
||||||
return request({
|
return request({
|
||||||
url: '/back/banner/update',
|
url: '/back/banner',
|
||||||
method: 'post',
|
method: 'put',
|
||||||
data: formData,
|
data: {
|
||||||
|
id: data.id,
|
||||||
|
name: data.name,
|
||||||
|
sort: data.sort,
|
||||||
|
jumpUrl: data.jumpUrl || '',
|
||||||
|
bannerAddr: data.bannerAddr
|
||||||
|
},
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'multipart/form-data'
|
'Content-Type': 'application/json'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,43 +19,31 @@ export function getCategory(id) {
|
|||||||
|
|
||||||
// 新增分类
|
// 新增分类
|
||||||
export function addCategory(data) {
|
export function addCategory(data) {
|
||||||
const formData = new FormData()
|
|
||||||
formData.append('name', data.name)
|
|
||||||
if (data.file) {
|
|
||||||
formData.append('file', data.file)
|
|
||||||
}
|
|
||||||
return request({
|
return request({
|
||||||
url: '/back/category',
|
url: '/back/category',
|
||||||
method: 'post',
|
method: 'post',
|
||||||
data: formData,
|
data: {
|
||||||
|
name: data.name,
|
||||||
|
backImg: data.backImg
|
||||||
|
},
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'multipart/form-data'
|
'Content-Type': 'application/json'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改分类
|
// 修改分类
|
||||||
export function updateCategory(data) {
|
export function updateCategory(data) {
|
||||||
const formData = new FormData()
|
|
||||||
formData.append('id', data.id)
|
|
||||||
formData.append('name', data.name)
|
|
||||||
|
|
||||||
// 如果有新图片文件,上传新图片
|
|
||||||
if (data.file) {
|
|
||||||
formData.append('file', data.file)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 传递图片路径(原图片或新图片的路径)
|
|
||||||
if (data.backImg) {
|
|
||||||
formData.append('backImg', data.backImg)
|
|
||||||
}
|
|
||||||
|
|
||||||
return request({
|
return request({
|
||||||
url: '/back/category/update',
|
url: '/back/category',
|
||||||
method: 'post',
|
method: 'put',
|
||||||
data: formData,
|
data: {
|
||||||
|
id: data.id,
|
||||||
|
name: data.name,
|
||||||
|
backImg: data.backImg
|
||||||
|
},
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'multipart/form-data'
|
'Content-Type': 'application/json'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,41 +19,33 @@ export function getRecommend(id) {
|
|||||||
|
|
||||||
// 新增推荐
|
// 新增推荐
|
||||||
export function addRecommend(data) {
|
export function addRecommend(data) {
|
||||||
const formData = new FormData()
|
|
||||||
formData.append('name', data.name)
|
|
||||||
if (data.file) {
|
|
||||||
formData.append('file', data.file)
|
|
||||||
}
|
|
||||||
if (data.backImg) {
|
|
||||||
formData.append('backImg', data.backImg)
|
|
||||||
}
|
|
||||||
return request({
|
return request({
|
||||||
url: '/back/re',
|
url: '/back/re',
|
||||||
method: 'post',
|
method: 'post',
|
||||||
data: formData,
|
data: {
|
||||||
|
name: data.name,
|
||||||
|
desc: data.desc,
|
||||||
|
backImg: data.backImg
|
||||||
|
},
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'multipart/form-data'
|
'Content-Type': 'application/json'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改推荐
|
// 修改推荐
|
||||||
export function updateRecommend(data) {
|
export function updateRecommend(data) {
|
||||||
const formData = new FormData()
|
|
||||||
formData.append('id', data.id)
|
|
||||||
formData.append('name', data.name)
|
|
||||||
if (data.file) {
|
|
||||||
formData.append('file', data.file)
|
|
||||||
}
|
|
||||||
if (data.backImg) {
|
|
||||||
formData.append('backImg', data.backImg)
|
|
||||||
}
|
|
||||||
return request({
|
return request({
|
||||||
url: '/back/re/update',
|
url: '/back/re',
|
||||||
method: 'post',
|
method: 'put',
|
||||||
data: formData,
|
data: {
|
||||||
|
id: data.id,
|
||||||
|
name: data.name,
|
||||||
|
desc: data.desc,
|
||||||
|
backImg: data.backImg
|
||||||
|
},
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'multipart/form-data'
|
'Content-Type': 'application/json'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +1,18 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="app-container">
|
<div class="app-container">
|
||||||
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
|
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
|
||||||
<el-form-item label="Banner名称" prop="name">
|
<el-form-item label="Banner名称" prop="name">
|
||||||
<el-input
|
<el-input
|
||||||
v-model="queryParams.name"
|
v-model="queryParams.name"
|
||||||
placeholder="请输入Banner名称"
|
placeholder="请输入Banner名称"
|
||||||
clearable
|
clearable
|
||||||
|
style="width: 200px"
|
||||||
@keyup.enter.native="handleQuery"
|
@keyup.enter.native="handleQuery"
|
||||||
/>
|
/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item>
|
<el-form-item>
|
||||||
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
|
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
|
||||||
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
|
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
|
||||||
</el-form-item>
|
|
||||||
</el-form>
|
|
||||||
|
|
||||||
<el-row :gutter="10" class="mb8">
|
|
||||||
<el-col :span="1.5">
|
|
||||||
<el-button
|
<el-button
|
||||||
type="primary"
|
type="primary"
|
||||||
plain
|
plain
|
||||||
@@ -25,17 +21,20 @@
|
|||||||
@click="handleAdd"
|
@click="handleAdd"
|
||||||
v-hasPermi="['content:banner:add']"
|
v-hasPermi="['content:banner:add']"
|
||||||
>新增</el-button>
|
>新增</el-button>
|
||||||
</el-col>
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
|
||||||
|
<el-row :gutter="10" class="mb8">
|
||||||
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
|
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
|
||||||
</el-row>
|
</el-row>
|
||||||
|
|
||||||
<el-table v-loading="loading" :data="bannerList" @selection-change="handleSelectionChange">
|
<el-table v-loading="loading" :data="bannerList" @selection-change="handleSelectionChange" style="width: 100%">
|
||||||
<el-table-column type="selection" width="55" align="center" />
|
<el-table-column type="selection" width="55" align="center" />
|
||||||
<el-table-column label="Banner ID" align="center" prop="id" />
|
<el-table-column label="Banner ID" align="center" prop="id" min-width="100" />
|
||||||
<el-table-column label="Banner名称" align="center" prop="name" />
|
<el-table-column label="Banner名称" align="center" prop="name" min-width="150" />
|
||||||
<el-table-column label="排序" align="center" prop="sort" />
|
<el-table-column label="排序" align="center" prop="sort" min-width="80" />
|
||||||
<el-table-column label="跳转链接" align="center" prop="jumpUrl" :show-overflow-tooltip="true" />
|
<el-table-column label="跳转链接" align="center" prop="jumpUrl" min-width="200" :show-overflow-tooltip="true" />
|
||||||
<el-table-column label="Banner图片" align="center" prop="bannerAddr" width="100">
|
<el-table-column label="Banner图片" align="center" prop="bannerAddr" min-width="120">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<el-image
|
<el-image
|
||||||
style="width: 80px; height: 50px"
|
style="width: 80px; height: 50px"
|
||||||
@@ -45,12 +44,12 @@
|
|||||||
</el-image>
|
</el-image>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
|
<el-table-column label="创建时间" align="center" prop="createTime" min-width="180">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
|
<span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
<el-table-column label="操作" align="center" class-name="small-padding fixed-width" min-width="150">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<el-button
|
<el-button
|
||||||
size="mini"
|
size="mini"
|
||||||
@@ -116,6 +115,7 @@
|
|||||||
<script>
|
<script>
|
||||||
import { listBanner, getBanner, delBanner, addBanner, updateBanner } from "@/api/content/banner";
|
import { listBanner, getBanner, delBanner, addBanner, updateBanner } from "@/api/content/banner";
|
||||||
import { getImageUrl } from "@/utils/image.js";
|
import { getImageUrl } from "@/utils/image.js";
|
||||||
|
import request from '@/utils/request';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "Banner",
|
name: "Banner",
|
||||||
@@ -237,7 +237,7 @@ export default {
|
|||||||
// 手动检查图片字段
|
// 手动检查图片字段
|
||||||
if (!this.form.id) {
|
if (!this.form.id) {
|
||||||
// 新增操作:必须上传图片
|
// 新增操作:必须上传图片
|
||||||
if (!this.form.file) {
|
if (!this.form.bannerAddr) {
|
||||||
this.$message.error('Banner图片不能为空');
|
this.$message.error('Banner图片不能为空');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -252,7 +252,7 @@ export default {
|
|||||||
this.$refs["form"].validate(valid => {
|
this.$refs["form"].validate(valid => {
|
||||||
if (valid) {
|
if (valid) {
|
||||||
if (this.form.id != null) {
|
if (this.form.id != null) {
|
||||||
// 编辑操作:直接使用bannerAddr字段
|
// 编辑操作:使用bannerAddr字段(上传后的地址)
|
||||||
updateBanner(this.form).then(response => {
|
updateBanner(this.form).then(response => {
|
||||||
this.$modal.msgSuccess("修改成功");
|
this.$modal.msgSuccess("修改成功");
|
||||||
this.open = false;
|
this.open = false;
|
||||||
@@ -284,12 +284,39 @@ export default {
|
|||||||
this.form.file = file.raw;
|
this.form.file = file.raw;
|
||||||
// 创建本地预览URL
|
// 创建本地预览URL
|
||||||
this.form.previewUrl = URL.createObjectURL(file.raw);
|
this.form.previewUrl = URL.createObjectURL(file.raw);
|
||||||
// 将新图片路径保存到bannerAddr字段,保持字段一致
|
|
||||||
this.form.bannerAddr = file.name; // 或者使用其他方式生成路径
|
// 上传图片到服务器
|
||||||
|
this.uploadImage(file.raw);
|
||||||
|
|
||||||
// 强制更新视图
|
// 强制更新视图
|
||||||
this.$forceUpdate();
|
this.$forceUpdate();
|
||||||
},
|
},
|
||||||
|
// 上传图片到服务器
|
||||||
|
uploadImage(file) {
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append('file', file);
|
||||||
|
|
||||||
|
// 调用上传接口
|
||||||
|
request({
|
||||||
|
url: '/back/upload/config/file',
|
||||||
|
method: 'post',
|
||||||
|
data: formData,
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'multipart/form-data'
|
||||||
|
}
|
||||||
|
}).then(response => {
|
||||||
|
if (response.code === 200) {
|
||||||
|
// 上传成功,保存返回的图片地址
|
||||||
|
this.form.bannerAddr = response.data;
|
||||||
|
this.$message.success('图片上传成功');
|
||||||
|
} else {
|
||||||
|
this.$message.error('图片上传失败:' + response.msg);
|
||||||
|
}
|
||||||
|
}).catch(error => {
|
||||||
|
console.error('图片上传失败:', error);
|
||||||
|
this.$message.error('图片上传失败');
|
||||||
|
});
|
||||||
|
},
|
||||||
// 图片上传前的处理
|
// 图片上传前的处理
|
||||||
beforeImageUpload(file) {
|
beforeImageUpload(file) {
|
||||||
const isJPG = file.type === 'image/jpeg' || file.type === 'image/png' || file.type === 'image/gif';
|
const isJPG = file.type === 'image/jpeg' || file.type === 'image/png' || file.type === 'image/gif';
|
||||||
|
|||||||
@@ -12,11 +12,6 @@
|
|||||||
<el-form-item>
|
<el-form-item>
|
||||||
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
|
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
|
||||||
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
|
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
|
||||||
</el-form-item>
|
|
||||||
</el-form>
|
|
||||||
|
|
||||||
<el-row :gutter="10" class="mb8">
|
|
||||||
<el-col :span="1.5">
|
|
||||||
<el-button
|
<el-button
|
||||||
type="primary"
|
type="primary"
|
||||||
plain
|
plain
|
||||||
@@ -25,15 +20,18 @@
|
|||||||
@click="handleAdd"
|
@click="handleAdd"
|
||||||
v-hasPermi="['content:category:add']"
|
v-hasPermi="['content:category:add']"
|
||||||
>新增</el-button>
|
>新增</el-button>
|
||||||
</el-col>
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
|
||||||
|
<el-row :gutter="10" class="mb8">
|
||||||
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
|
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
|
||||||
</el-row>
|
</el-row>
|
||||||
|
|
||||||
<el-table v-loading="loading" :data="categoryList" @selection-change="handleSelectionChange">
|
<el-table v-loading="loading" :data="categoryList" @selection-change="handleSelectionChange" style="width: 100%">
|
||||||
<el-table-column type="selection" width="55" align="center" />
|
<el-table-column type="selection" width="55" align="center" />
|
||||||
<el-table-column label="分类ID" align="center" prop="categoryId" />
|
<el-table-column label="分类ID" align="center" prop="categoryId" min-width="120" />
|
||||||
<el-table-column label="分类名称" align="center" prop="name" />
|
<el-table-column label="分类名称" align="center" prop="name" min-width="150" />
|
||||||
<el-table-column label="分类图片" align="center" prop="backImg" width="100">
|
<el-table-column label="分类图片" align="center" prop="backImg" min-width="120">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<el-image
|
<el-image
|
||||||
style="width: 50px; height: 50px"
|
style="width: 50px; height: 50px"
|
||||||
@@ -43,12 +41,12 @@
|
|||||||
</el-image>
|
</el-image>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
|
<el-table-column label="创建时间" align="center" prop="createTime" min-width="180">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
|
<span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
<el-table-column label="操作" align="center" class-name="small-padding fixed-width" min-width="200">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<el-button
|
<el-button
|
||||||
size="mini"
|
size="mini"
|
||||||
@@ -176,6 +174,7 @@
|
|||||||
import { listCategory, getCategory, delCategory, addCategory, updateCategory } from "@/api/content/category";
|
import { listCategory, getCategory, delCategory, addCategory, updateCategory } from "@/api/content/category";
|
||||||
import { listMusic, bindMusicToCategory, getCategoryBoundMusic } from "@/api/content/music";
|
import { listMusic, bindMusicToCategory, getCategoryBoundMusic } from "@/api/content/music";
|
||||||
import { getImageUrl } from "@/utils/image.js";
|
import { getImageUrl } from "@/utils/image.js";
|
||||||
|
import request from '@/utils/request';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "Category",
|
name: "Category",
|
||||||
@@ -302,7 +301,7 @@ export default {
|
|||||||
// 手动检查图片字段
|
// 手动检查图片字段
|
||||||
if (!this.form.id) {
|
if (!this.form.id) {
|
||||||
// 新增操作:必须上传图片
|
// 新增操作:必须上传图片
|
||||||
if (!this.form.file) {
|
if (!this.form.backImg) {
|
||||||
this.$message.error('分类图片不能为空');
|
this.$message.error('分类图片不能为空');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -317,7 +316,7 @@ export default {
|
|||||||
this.$refs["form"].validate(valid => {
|
this.$refs["form"].validate(valid => {
|
||||||
if (valid) {
|
if (valid) {
|
||||||
if (this.form.id != null) {
|
if (this.form.id != null) {
|
||||||
// 编辑操作:直接使用backImg字段
|
// 编辑操作:使用backImg字段(上传后的地址)
|
||||||
updateCategory(this.form).then(response => {
|
updateCategory(this.form).then(response => {
|
||||||
this.$modal.msgSuccess("修改成功");
|
this.$modal.msgSuccess("修改成功");
|
||||||
this.open = false;
|
this.open = false;
|
||||||
@@ -349,12 +348,39 @@ export default {
|
|||||||
this.form.file = file.raw;
|
this.form.file = file.raw;
|
||||||
// 创建本地预览URL
|
// 创建本地预览URL
|
||||||
this.form.previewUrl = URL.createObjectURL(file.raw);
|
this.form.previewUrl = URL.createObjectURL(file.raw);
|
||||||
// 将新图片路径保存到backImg字段,保持字段一致
|
|
||||||
this.form.backImg = file.name; // 或者使用其他方式生成路径
|
// 上传图片到服务器
|
||||||
|
this.uploadImage(file.raw);
|
||||||
|
|
||||||
// 强制更新视图
|
// 强制更新视图
|
||||||
this.$forceUpdate();
|
this.$forceUpdate();
|
||||||
},
|
},
|
||||||
|
// 上传图片到服务器
|
||||||
|
uploadImage(file) {
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append('file', file);
|
||||||
|
|
||||||
|
// 调用上传接口
|
||||||
|
request({
|
||||||
|
url: '/back/upload/config/file',
|
||||||
|
method: 'post',
|
||||||
|
data: formData,
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'multipart/form-data'
|
||||||
|
}
|
||||||
|
}).then(response => {
|
||||||
|
if (response.code === 200) {
|
||||||
|
// 上传成功,保存返回的图片地址
|
||||||
|
this.form.backImg = response.data;
|
||||||
|
this.$message.success('图片上传成功');
|
||||||
|
} else {
|
||||||
|
this.$message.error('图片上传失败:' + response.msg);
|
||||||
|
}
|
||||||
|
}).catch(error => {
|
||||||
|
console.error('图片上传失败:', error);
|
||||||
|
this.$message.error('图片上传失败');
|
||||||
|
});
|
||||||
|
},
|
||||||
// 图片上传前的处理
|
// 图片上传前的处理
|
||||||
beforeImageUpload(file) {
|
beforeImageUpload(file) {
|
||||||
const isJPG = file.type === 'image/jpeg' || file.type === 'image/png' || file.type === 'image/gif';
|
const isJPG = file.type === 'image/jpeg' || file.type === 'image/png' || file.type === 'image/gif';
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="app-container">
|
<div class="app-container">
|
||||||
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
|
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="80px">
|
||||||
<el-form-item label="推荐名称" prop="name">
|
<el-form-item label="推荐名称" prop="name">
|
||||||
<el-input
|
<el-input
|
||||||
v-model="queryParams.name"
|
v-model="queryParams.name"
|
||||||
@@ -12,11 +12,6 @@
|
|||||||
<el-form-item>
|
<el-form-item>
|
||||||
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
|
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
|
||||||
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
|
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
|
||||||
</el-form-item>
|
|
||||||
</el-form>
|
|
||||||
|
|
||||||
<el-row :gutter="10" class="mb8">
|
|
||||||
<el-col :span="1.5">
|
|
||||||
<el-button
|
<el-button
|
||||||
type="primary"
|
type="primary"
|
||||||
plain
|
plain
|
||||||
@@ -25,15 +20,18 @@
|
|||||||
@click="handleAdd"
|
@click="handleAdd"
|
||||||
v-hasPermi="['content:recommend:add']"
|
v-hasPermi="['content:recommend:add']"
|
||||||
>新增</el-button>
|
>新增</el-button>
|
||||||
</el-col>
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
|
||||||
|
<el-row :gutter="10" class="mb8">
|
||||||
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
|
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
|
||||||
</el-row>
|
</el-row>
|
||||||
|
|
||||||
<el-table v-loading="loading" :data="recommendList" @selection-change="handleSelectionChange">
|
<el-table v-loading="loading" :data="recommendList" @selection-change="handleSelectionChange" style="width: 100%">
|
||||||
<el-table-column type="selection" width="55" align="center" />
|
<el-table-column type="selection" width="55" align="center" />
|
||||||
<el-table-column label="推荐ID" align="center" prop="categoryId" />
|
<el-table-column label="推荐ID" align="center" prop="id" min-width="120" />
|
||||||
<el-table-column label="推荐名称" align="center" prop="name" />
|
<el-table-column label="推荐名称" align="center" prop="name" min-width="150" />
|
||||||
<el-table-column label="推荐图片" align="center" prop="backImg" width="100">
|
<el-table-column label="推荐图片" align="center" prop="backImg" min-width="120">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<el-image
|
<el-image
|
||||||
style="width: 50px; height: 50px"
|
style="width: 50px; height: 50px"
|
||||||
@@ -43,12 +41,12 @@
|
|||||||
</el-image>
|
</el-image>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
|
<el-table-column label="创建时间" align="center" prop="createTime" min-width="180">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
|
<span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
<el-table-column label="操作" align="center" class-name="small-padding fixed-width" min-width="200">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<el-button
|
<el-button
|
||||||
size="mini"
|
size="mini"
|
||||||
@@ -89,6 +87,9 @@
|
|||||||
<el-form-item label="推荐名称" prop="name" required>
|
<el-form-item label="推荐名称" prop="name" required>
|
||||||
<el-input v-model="form.name" placeholder="请输入推荐名称" />
|
<el-input v-model="form.name" placeholder="请输入推荐名称" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
<el-form-item label="推荐描述" prop="desc">
|
||||||
|
<el-input v-model="form.desc" type="textarea" :rows="3" placeholder="请输入推荐描述" />
|
||||||
|
</el-form-item>
|
||||||
<el-form-item label="推荐图片" required>
|
<el-form-item label="推荐图片" required>
|
||||||
<el-upload
|
<el-upload
|
||||||
action=""
|
action=""
|
||||||
@@ -102,6 +103,9 @@
|
|||||||
<img v-else-if="form.backImg" :src="getImageUrlMethod(form.backImg)" class="avatar">
|
<img v-else-if="form.backImg" :src="getImageUrlMethod(form.backImg)" class="avatar">
|
||||||
<i v-else class="el-icon-plus avatar-uploader-icon"></i>
|
<i v-else class="el-icon-plus avatar-uploader-icon"></i>
|
||||||
</el-upload>
|
</el-upload>
|
||||||
|
<div v-if="imageUploading" style="margin-top: 10px; color: #409EFF;">
|
||||||
|
<i class="el-icon-loading"></i> 图片上传中...
|
||||||
|
</div>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-form>
|
</el-form>
|
||||||
<div slot="footer" class="dialog-footer">
|
<div slot="footer" class="dialog-footer">
|
||||||
@@ -176,6 +180,7 @@
|
|||||||
import { listRecommend, getRecommend, delRecommend, addRecommend, updateRecommend, getRecommendBoundMusic, bindMusicToRecommend } from "@/api/content/recommend";
|
import { listRecommend, getRecommend, delRecommend, addRecommend, updateRecommend, getRecommendBoundMusic, bindMusicToRecommend } from "@/api/content/recommend";
|
||||||
import { listMusic } from "@/api/content/music";
|
import { listMusic } from "@/api/content/music";
|
||||||
import { getImageUrl } from "@/utils/image.js";
|
import { getImageUrl } from "@/utils/image.js";
|
||||||
|
import request from '@/utils/request';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "Recommend",
|
name: "Recommend",
|
||||||
@@ -213,6 +218,8 @@ export default {
|
|||||||
{ required: true, message: "推荐名称不能为空", trigger: "blur" }
|
{ required: true, message: "推荐名称不能为空", trigger: "blur" }
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
// 图片上传状态
|
||||||
|
imageUploading: false,
|
||||||
// 绑定音乐相关
|
// 绑定音乐相关
|
||||||
bindMusicOpen: false,
|
bindMusicOpen: false,
|
||||||
musicLoading: false,
|
musicLoading: false,
|
||||||
@@ -255,10 +262,12 @@ export default {
|
|||||||
this.form = {
|
this.form = {
|
||||||
id: null,
|
id: null,
|
||||||
name: null,
|
name: null,
|
||||||
|
desc: null,
|
||||||
backImg: null,
|
backImg: null,
|
||||||
previewUrl: null,
|
previewUrl: null,
|
||||||
file: null
|
file: null
|
||||||
};
|
};
|
||||||
|
this.imageUploading = false; // 重置上传状态
|
||||||
this.resetForm("form");
|
this.resetForm("form");
|
||||||
},
|
},
|
||||||
/** 搜索按钮操作 */
|
/** 搜索按钮操作 */
|
||||||
@@ -299,10 +308,16 @@ export default {
|
|||||||
},
|
},
|
||||||
/** 提交按钮 */
|
/** 提交按钮 */
|
||||||
submitForm() {
|
submitForm() {
|
||||||
|
// 检查图片是否正在上传
|
||||||
|
if (this.imageUploading) {
|
||||||
|
this.$message.warning('图片正在上传中,请稍候...');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// 手动检查图片字段
|
// 手动检查图片字段
|
||||||
if (!this.form.id) {
|
if (!this.form.id) {
|
||||||
// 新增操作:必须上传图片
|
// 新增操作:必须上传图片
|
||||||
if (!this.form.file) {
|
if (!this.form.backImg) {
|
||||||
this.$message.error('推荐图片不能为空');
|
this.$message.error('推荐图片不能为空');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -314,10 +329,12 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('提交表单数据:', this.form); // 添加调试日志
|
||||||
|
|
||||||
this.$refs["form"].validate(valid => {
|
this.$refs["form"].validate(valid => {
|
||||||
if (valid) {
|
if (valid) {
|
||||||
if (this.form.id != null) {
|
if (this.form.id != null) {
|
||||||
// 编辑操作:直接使用backImg字段
|
// 编辑操作:使用backImg字段(上传后的地址)
|
||||||
updateRecommend(this.form).then(response => {
|
updateRecommend(this.form).then(response => {
|
||||||
this.$modal.msgSuccess("修改成功");
|
this.$modal.msgSuccess("修改成功");
|
||||||
this.open = false;
|
this.open = false;
|
||||||
@@ -349,12 +366,56 @@ export default {
|
|||||||
this.form.file = file.raw;
|
this.form.file = file.raw;
|
||||||
// 创建本地预览URL
|
// 创建本地预览URL
|
||||||
this.form.previewUrl = URL.createObjectURL(file.raw);
|
this.form.previewUrl = URL.createObjectURL(file.raw);
|
||||||
// 将新图片路径保存到backImg字段,保持字段一致
|
|
||||||
this.form.backImg = file.name; // 或者使用其他方式生成路径
|
// 清空之前的图片地址,等待新图片上传完成
|
||||||
|
this.form.backImg = null;
|
||||||
|
|
||||||
|
// 设置上传状态
|
||||||
|
this.imageUploading = true;
|
||||||
|
|
||||||
|
// 上传图片到服务器
|
||||||
|
this.uploadImage(file.raw);
|
||||||
|
|
||||||
// 强制更新视图
|
// 强制更新视图
|
||||||
this.$forceUpdate();
|
this.$forceUpdate();
|
||||||
},
|
},
|
||||||
|
// 上传图片到服务器
|
||||||
|
uploadImage(file) {
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append('file', file);
|
||||||
|
|
||||||
|
// 调用上传接口
|
||||||
|
request({
|
||||||
|
url: '/back/upload/config/file',
|
||||||
|
method: 'post',
|
||||||
|
data: formData,
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'multipart/form-data'
|
||||||
|
}
|
||||||
|
}).then(response => {
|
||||||
|
if (response.code === 200) {
|
||||||
|
// 上传成功,保存返回的图片地址
|
||||||
|
this.form.backImg = response.data;
|
||||||
|
this.$message.success('图片上传成功');
|
||||||
|
console.log('图片上传成功,地址:', this.form.backImg); // 添加调试日志
|
||||||
|
} else {
|
||||||
|
this.$message.error('图片上传失败:' + response.msg);
|
||||||
|
// 上传失败时清空预览
|
||||||
|
this.form.previewUrl = null;
|
||||||
|
this.form.backImg = null;
|
||||||
|
}
|
||||||
|
// 无论成功失败都要重置上传状态
|
||||||
|
this.imageUploading = false;
|
||||||
|
}).catch(error => {
|
||||||
|
console.error('图片上传失败:', error);
|
||||||
|
this.$message.error('图片上传失败');
|
||||||
|
// 上传失败时清空预览
|
||||||
|
this.form.previewUrl = null;
|
||||||
|
this.form.backImg = null;
|
||||||
|
// 重置上传状态
|
||||||
|
this.imageUploading = false;
|
||||||
|
});
|
||||||
|
},
|
||||||
// 图片上传前的处理
|
// 图片上传前的处理
|
||||||
beforeImageUpload(file) {
|
beforeImageUpload(file) {
|
||||||
const isJPG = file.type === 'image/jpeg' || file.type === 'image/png' || file.type === 'image/gif';
|
const isJPG = file.type === 'image/jpeg' || file.type === 'image/png' || file.type === 'image/gif';
|
||||||
@@ -372,10 +433,10 @@ export default {
|
|||||||
},
|
},
|
||||||
// 绑定音乐
|
// 绑定音乐
|
||||||
handleBindMusic(row) {
|
handleBindMusic(row) {
|
||||||
this.musicQueryParams.categoryId = row.categoryId;
|
this.musicQueryParams.categoryId = row.id;
|
||||||
this.selectedMusicIds = []; // 重置选中的音乐
|
this.selectedMusicIds = []; // 重置选中的音乐
|
||||||
this.boundMusicIds = []; // 重置已绑定的音乐ID
|
this.boundMusicIds = []; // 重置已绑定的音乐ID
|
||||||
this.getBoundMusic(row.categoryId); // 先获取已绑定的音乐
|
this.getBoundMusic(row.id); // 先获取已绑定的音乐
|
||||||
this.getMusicList();
|
this.getMusicList();
|
||||||
this.bindMusicOpen = true;
|
this.bindMusicOpen = true;
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="app-container">
|
<div class="app-container">
|
||||||
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
|
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="80px">
|
||||||
<el-form-item label="标签名称" prop="name">
|
<el-form-item label="标签名称" prop="name">
|
||||||
<el-input
|
<el-input
|
||||||
v-model="queryParams.name"
|
v-model="queryParams.name"
|
||||||
@@ -12,11 +12,6 @@
|
|||||||
<el-form-item>
|
<el-form-item>
|
||||||
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
|
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
|
||||||
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
|
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
|
||||||
</el-form-item>
|
|
||||||
</el-form>
|
|
||||||
|
|
||||||
<el-row :gutter="10" class="mb8">
|
|
||||||
<el-col :span="1.5">
|
|
||||||
<el-button
|
<el-button
|
||||||
type="primary"
|
type="primary"
|
||||||
plain
|
plain
|
||||||
@@ -25,20 +20,23 @@
|
|||||||
@click="handleAdd"
|
@click="handleAdd"
|
||||||
v-hasPermi="['content:tag:add']"
|
v-hasPermi="['content:tag:add']"
|
||||||
>新增</el-button>
|
>新增</el-button>
|
||||||
</el-col>
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
|
||||||
|
<el-row :gutter="10" class="mb8">
|
||||||
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
|
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
|
||||||
</el-row>
|
</el-row>
|
||||||
|
|
||||||
<el-table v-loading="loading" :data="tagList" @selection-change="handleSelectionChange">
|
<el-table v-loading="loading" :data="tagList" @selection-change="handleSelectionChange" style="width: 100%">
|
||||||
<el-table-column type="selection" width="55" align="center" />
|
<el-table-column type="selection" width="55" align="center" />
|
||||||
<el-table-column label="标签ID" align="center" prop="id" />
|
<el-table-column label="标签ID" align="center" prop="id" min-width="120" />
|
||||||
<el-table-column label="标签名称" align="center" prop="name" />
|
<el-table-column label="标签名称" align="center" prop="name" min-width="200" />
|
||||||
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
|
<el-table-column label="创建时间" align="center" prop="createTime" min-width="180">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
|
<span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
<el-table-column label="操作" align="center" class-name="small-padding fixed-width" min-width="150">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<el-button
|
<el-button
|
||||||
size="mini"
|
size="mini"
|
||||||
|
|||||||
Reference in New Issue
Block a user