This commit is contained in:
55
src/api/spring/blessing/music/index.js
Normal file
55
src/api/spring/blessing/music/index.js
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
import request from '@/utils/request'
|
||||||
|
|
||||||
|
export function getList(data) {
|
||||||
|
return request({
|
||||||
|
url: '/management/api/spring/card-music/list',
|
||||||
|
method: 'get',
|
||||||
|
params: data,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function doAdd(data) {
|
||||||
|
return request({
|
||||||
|
url: '/management/api/spring/card-music',
|
||||||
|
method: 'post',
|
||||||
|
data,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function doEdit(id, data) {
|
||||||
|
return request({
|
||||||
|
url: `/management/api/spring/card-music/${id}`,
|
||||||
|
method: 'put',
|
||||||
|
data,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function doDelete(data) {
|
||||||
|
return request({
|
||||||
|
url: '/management/api/spring/card-music/delete',
|
||||||
|
method: 'put',
|
||||||
|
data,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function doMoveUp(id) {
|
||||||
|
return request({
|
||||||
|
url: `/management/api/spring/card-music/moveUp/${id}`,
|
||||||
|
method: 'patch',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function doMoveDown(id) {
|
||||||
|
return request({
|
||||||
|
url: `/management/api/spring/card-music/moveDown/${id}`,
|
||||||
|
method: 'patch',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function toggleEnable(id, isEnabled) {
|
||||||
|
return request({
|
||||||
|
url: `/management/api/spring/card-music/enable/${id}`,
|
||||||
|
method: 'patch',
|
||||||
|
data: { isEnabled },
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -149,6 +149,12 @@ export const asyncRoutes = [
|
|||||||
component: () => import('@/views/spring/blessing/titleTemplate/index'),
|
component: () => import('@/views/spring/blessing/titleTemplate/index'),
|
||||||
meta: { title: '图片标题模版' },
|
meta: { title: '图片标题模版' },
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: 'music',
|
||||||
|
name: 'Music',
|
||||||
|
component: () => import('@/views/spring/blessing/music/index'),
|
||||||
|
meta: { title: '背景音乐' },
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: 'contentTemplate',
|
path: 'contentTemplate',
|
||||||
name: 'contentTemplate',
|
name: 'contentTemplate',
|
||||||
@@ -201,18 +207,18 @@ export const asyncRoutes = [
|
|||||||
permissions: ['admin'],
|
permissions: ['admin'],
|
||||||
},
|
},
|
||||||
children: [
|
children: [
|
||||||
{
|
|
||||||
path: 'systemAvatar',
|
|
||||||
name: 'SystemAvatar',
|
|
||||||
component: () => import('@/views/spring/avatar/systemAvatar/index'),
|
|
||||||
meta: { title: '系统头像' },
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
path: 'avatarCategory',
|
path: 'avatarCategory',
|
||||||
name: 'AvatarCategory',
|
name: 'AvatarCategory',
|
||||||
component: () => import('@/views/spring/avatar/category/index'),
|
component: () => import('@/views/spring/avatar/category/index'),
|
||||||
meta: { title: '头像类型' },
|
meta: { title: '头像类型' },
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: 'systemAvatar',
|
||||||
|
name: 'SystemAvatar',
|
||||||
|
component: () => import('@/views/spring/avatar/systemAvatar/index'),
|
||||||
|
meta: { title: '系统头像' },
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: 'avatarFrame',
|
path: 'avatarFrame',
|
||||||
name: 'AvatarFrame',
|
name: 'AvatarFrame',
|
||||||
|
|||||||
183
src/views/spring/blessing/music/components/AppManagementEdit.vue
Normal file
183
src/views/spring/blessing/music/components/AppManagementEdit.vue
Normal file
@@ -0,0 +1,183 @@
|
|||||||
|
<template>
|
||||||
|
<el-dialog :title="title" :visible.sync="dialogFormVisible" width="500px" @close="close">
|
||||||
|
<el-form ref="form" label-width="80px" :model="form" :rules="rules">
|
||||||
|
<el-form-item label="音乐名称" prop="name">
|
||||||
|
<el-input v-model="form.name" autocomplete="off" placeholder="请输入音乐名称" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="场景" prop="scene">
|
||||||
|
<el-select v-model="form.scene" clearable placeholder="请选择场景(可为空)" style="width: 100%">
|
||||||
|
<el-option v-for="item in sceneList" :key="item.scene" :label="item.sceneName" :value="item.scene" />
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="标签" prop="tag">
|
||||||
|
<el-input v-model="form.tag" autocomplete="off" placeholder="请输入标签(可选)" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="音乐文件" prop="musicUrl">
|
||||||
|
<el-upload
|
||||||
|
accept="audio/*"
|
||||||
|
:action="uploadUrl"
|
||||||
|
:before-upload="beforeUpload"
|
||||||
|
:headers="uploadHeaders"
|
||||||
|
:on-error="handleUploadError"
|
||||||
|
:on-success="handleUploadSuccess"
|
||||||
|
:show-file-list="false"
|
||||||
|
>
|
||||||
|
<el-button size="small" type="primary">点击上传</el-button>
|
||||||
|
<div slot="tip" class="el-upload__tip">只能上传音频文件,且不超过 10MB</div>
|
||||||
|
</el-upload>
|
||||||
|
<div v-if="form.musicUrl" style="margin-top: 10px">
|
||||||
|
<audio controls :src="form.musicUrl" style="width: 100%"></audio>
|
||||||
|
</div>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item v-if="!form.id" label="是否启用" prop="isEnabled">
|
||||||
|
<el-switch v-model="form.isEnabled" active-text="启用" :active-value="true" inactive-text="禁用" :inactive-value="false" />
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
|
||||||
|
<div slot="footer" class="dialog-footer">
|
||||||
|
<el-button @click="close">取 消</el-button>
|
||||||
|
<el-button :loading="loading" type="primary" @click="save">确 定</el-button>
|
||||||
|
</div>
|
||||||
|
</el-dialog>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { doEdit, doAdd } from '@/api/spring/blessing/music/index'
|
||||||
|
import { getAll as getAllScenes } from '@/api/spring/blessing/scene'
|
||||||
|
import { getAccessToken } from '@/utils/accessToken'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'MusicManagementEdit',
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
id: '',
|
||||||
|
form: {
|
||||||
|
name: '',
|
||||||
|
scene: '',
|
||||||
|
musicUrl: '',
|
||||||
|
tag: '',
|
||||||
|
isEnabled: true,
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
name: [{ required: true, trigger: 'blur', message: '请输入音乐名称' }],
|
||||||
|
musicUrl: [{ required: true, trigger: 'change', message: '请上传音乐文件' }],
|
||||||
|
},
|
||||||
|
title: '',
|
||||||
|
dialogFormVisible: false,
|
||||||
|
sceneList: [],
|
||||||
|
token: getAccessToken() || '',
|
||||||
|
loading: false,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
uploadUrl() {
|
||||||
|
return `${process.env.VUE_APP_API_BASE_URL}/management/api/common/upload`
|
||||||
|
},
|
||||||
|
uploadHeaders() {
|
||||||
|
let userId = ''
|
||||||
|
let appId = ''
|
||||||
|
if (this.$store.state?.user?.userId) {
|
||||||
|
userId = this.$store.state?.user?.userId
|
||||||
|
}
|
||||||
|
if (this.$store.state?.user?.appId) {
|
||||||
|
appId = this.$store.state?.user?.appId
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
Authorization: `${this.token}`,
|
||||||
|
'x-user-id': userId,
|
||||||
|
'x-app-id': appId,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
this.fetchSceneList()
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
async fetchSceneList() {
|
||||||
|
try {
|
||||||
|
const { data } = await getAllScenes()
|
||||||
|
this.sceneList = data || []
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
beforeUpload(file) {
|
||||||
|
const isValidSize = file.size / 1024 / 1024 < 10
|
||||||
|
if (!isValidSize) {
|
||||||
|
this.$message.error('文件大小不能超过 10MB!')
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
this.loading = true
|
||||||
|
return true
|
||||||
|
},
|
||||||
|
handleUploadSuccess(response) {
|
||||||
|
this.loading = false
|
||||||
|
if (response.code === 200) {
|
||||||
|
this.form.musicUrl = `https://file.lihailezzc.com/${response.data.key}`
|
||||||
|
this.$message.success('上传成功!')
|
||||||
|
} else {
|
||||||
|
this.$message.error('上传失败,请重试!')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
handleUploadError() {
|
||||||
|
this.loading = false
|
||||||
|
this.$message.error('上传失败,请重试!')
|
||||||
|
},
|
||||||
|
showEdit(row) {
|
||||||
|
if (!row) {
|
||||||
|
this.title = '添加'
|
||||||
|
this.id = ''
|
||||||
|
this.form = {
|
||||||
|
name: '',
|
||||||
|
scene: '',
|
||||||
|
musicUrl: '',
|
||||||
|
tag: '',
|
||||||
|
isEnabled: true,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.title = '编辑'
|
||||||
|
this.id = row.id
|
||||||
|
this.form = {
|
||||||
|
id: row.id,
|
||||||
|
name: row.name,
|
||||||
|
scene: row.scene,
|
||||||
|
musicUrl: row.musicUrl,
|
||||||
|
tag: row.tag,
|
||||||
|
isEnabled: row.isEnabled,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.dialogFormVisible = true
|
||||||
|
},
|
||||||
|
close() {
|
||||||
|
this.$refs['form'].resetFields()
|
||||||
|
this.form = this.$options.data().form
|
||||||
|
this.id = ''
|
||||||
|
this.dialogFormVisible = false
|
||||||
|
},
|
||||||
|
save() {
|
||||||
|
this.$refs['form'].validate(async (valid) => {
|
||||||
|
if (valid) {
|
||||||
|
this.loading = true
|
||||||
|
try {
|
||||||
|
if (this.id) {
|
||||||
|
const { msg } = await doEdit(this.id, this.form)
|
||||||
|
this.$baseMessage(msg, 'success')
|
||||||
|
} else {
|
||||||
|
const { msg } = await doAdd(this.form)
|
||||||
|
this.$baseMessage(msg, 'success')
|
||||||
|
}
|
||||||
|
this.$emit('fetch-data')
|
||||||
|
this.close()
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
} finally {
|
||||||
|
this.loading = false
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
</script>
|
||||||
228
src/views/spring/blessing/music/index.vue
Normal file
228
src/views/spring/blessing/music/index.vue
Normal file
@@ -0,0 +1,228 @@
|
|||||||
|
<template>
|
||||||
|
<div class="music-management-container">
|
||||||
|
<vab-query-form>
|
||||||
|
<vab-query-form-left-panel :span="12">
|
||||||
|
<el-button icon="el-icon-plus" type="primary" @click="handleEdit">添加</el-button>
|
||||||
|
<el-button icon="el-icon-delete" type="danger" @click="handleDelete">批量删除</el-button>
|
||||||
|
</vab-query-form-left-panel>
|
||||||
|
<vab-query-form-right-panel :span="12">
|
||||||
|
<el-form :inline="true" :model="queryForm" @submit.native.prevent>
|
||||||
|
<el-form-item>
|
||||||
|
<el-select v-model="queryForm.scene" clearable placeholder="请选择场景" @change="queryData">
|
||||||
|
<el-option v-for="item in sceneList" :key="item.scene" :label="item.sceneName" :value="item.scene" />
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item>
|
||||||
|
<el-input v-model.trim="queryForm.keyword" clearable placeholder="请输入查询条件" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item>
|
||||||
|
<el-button icon="el-icon-search" type="primary" @click="queryData">查询</el-button>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
</vab-query-form-right-panel>
|
||||||
|
</vab-query-form>
|
||||||
|
|
||||||
|
<el-table v-loading="listLoading" :data="list" :element-loading-text="elementLoadingText" @selection-change="setSelectRows">
|
||||||
|
<el-table-column align="center" show-overflow-tooltip type="selection" width="55" />
|
||||||
|
<el-table-column align="center" label="排序" prop="sort" sortable width="100" />
|
||||||
|
|
||||||
|
<el-table-column align="center" label="音乐名称" prop="name" show-overflow-tooltip />
|
||||||
|
|
||||||
|
<el-table-column align="center" label="场景" show-overflow-tooltip>
|
||||||
|
<template #default="{ row }">
|
||||||
|
{{ getSceneName(row.scene) }}
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
|
||||||
|
<el-table-column align="center" label="试听" width="300">
|
||||||
|
<template slot-scope="scope">
|
||||||
|
<audio controls :src="scope.row.musicUrl" style="width: 250px; height: 40px"></audio>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
|
||||||
|
<el-table-column align="center" label="标签" prop="tag" show-overflow-tooltip />
|
||||||
|
|
||||||
|
<el-table-column align="center" label="状态" prop="isEnabled" width="100">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<el-switch active-color="#13ce66" inactive-color="#ff4949" :value="row.isEnabled" @change="handleToggleEnable(row, $event)" />
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
|
||||||
|
<el-table-column align="center" fixed="right" label="操作" width="200">
|
||||||
|
<template slot-scope="scope">
|
||||||
|
<el-button type="text" @click="handleEdit(scope.row)">编辑</el-button>
|
||||||
|
<el-button :disabled="!scope.row.isEnabled || isFirstEnabled(scope.row)" type="text" @click="handleMoveUp(scope.row)">
|
||||||
|
上移
|
||||||
|
</el-button>
|
||||||
|
<el-button :disabled="!scope.row.isEnabled || isLastEnabled(scope.row)" type="text" @click="handleMoveDown(scope.row)">
|
||||||
|
下移
|
||||||
|
</el-button>
|
||||||
|
<el-button type="text" @click="handleDelete(scope.row)">删除</el-button>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
<el-pagination
|
||||||
|
background
|
||||||
|
:current-page="queryForm.pageNo"
|
||||||
|
:layout="layout"
|
||||||
|
:page-size="queryForm.pageSize"
|
||||||
|
:total="total"
|
||||||
|
@current-change="handleCurrentChange"
|
||||||
|
@size-change="handleSizeChange"
|
||||||
|
/>
|
||||||
|
<edit ref="edit" @fetch-data="fetchData" />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { doDelete, getList, toggleEnable, doMoveUp, doMoveDown } from '@/api/spring/blessing/music/index'
|
||||||
|
import { getAll as getAllScenes } from '@/api/spring/blessing/scene'
|
||||||
|
import Edit from './components/AppManagementEdit'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'MusicManagement',
|
||||||
|
components: { Edit },
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
list: [],
|
||||||
|
listLoading: true,
|
||||||
|
layout: 'total, sizes, prev, pager, next, jumper',
|
||||||
|
total: 0,
|
||||||
|
selectRows: [],
|
||||||
|
elementLoadingText: '正在加载...',
|
||||||
|
queryForm: {
|
||||||
|
pageNo: 1,
|
||||||
|
pageSize: 10,
|
||||||
|
keyword: '',
|
||||||
|
scene: '',
|
||||||
|
},
|
||||||
|
sceneList: [],
|
||||||
|
}
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
this.fetchSceneList()
|
||||||
|
this.fetchData()
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
setSelectRows(val) {
|
||||||
|
this.selectRows = val
|
||||||
|
},
|
||||||
|
handleEdit(row) {
|
||||||
|
if (row && row.id) {
|
||||||
|
this.$refs['edit'].showEdit(row)
|
||||||
|
} else {
|
||||||
|
this.$refs['edit'].showEdit()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
handleDelete(row) {
|
||||||
|
if (row && row.id) {
|
||||||
|
this.$baseConfirm('你确定要删除当前项吗', null, async () => {
|
||||||
|
try {
|
||||||
|
const { msg } = await doDelete({ ids: [row.id] })
|
||||||
|
this.$baseMessage(msg, 'success')
|
||||||
|
this.fetchData()
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
if (this.selectRows.length > 0) {
|
||||||
|
const ids = this.selectRows.map((item) => item.id)
|
||||||
|
this.$baseConfirm('你确定要删除选中项吗', null, async () => {
|
||||||
|
try {
|
||||||
|
const { msg } = await doDelete({ ids })
|
||||||
|
this.$baseMessage(msg, 'success')
|
||||||
|
this.fetchData()
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
this.$baseMessage('未选中任何行', 'error')
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
handleSizeChange(val) {
|
||||||
|
this.queryForm.pageSize = val
|
||||||
|
this.fetchData()
|
||||||
|
},
|
||||||
|
handleCurrentChange(val) {
|
||||||
|
this.queryForm.pageNo = val
|
||||||
|
this.fetchData()
|
||||||
|
},
|
||||||
|
queryData() {
|
||||||
|
this.queryForm.pageNo = 1
|
||||||
|
this.fetchData()
|
||||||
|
},
|
||||||
|
async fetchData() {
|
||||||
|
this.listLoading = true
|
||||||
|
try {
|
||||||
|
const { data } = await getList(this.queryForm)
|
||||||
|
this.list = data.list
|
||||||
|
this.total = data.totalCount
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
} finally {
|
||||||
|
this.listLoading = false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async handleToggleEnable(row, value) {
|
||||||
|
this.$baseConfirm(`你确定要${value ? '启用' : '禁用'}当前项吗`, null, async () => {
|
||||||
|
try {
|
||||||
|
const { msg } = await toggleEnable(row.id, value)
|
||||||
|
this.$baseMessage(msg, 'success')
|
||||||
|
this.fetchData()
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
async handleMoveUp(row) {
|
||||||
|
try {
|
||||||
|
const { msg } = await doMoveUp(row.id)
|
||||||
|
this.$baseMessage(msg, 'success')
|
||||||
|
this.fetchData()
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async handleMoveDown(row) {
|
||||||
|
try {
|
||||||
|
const { msg } = await doMoveDown(row.id)
|
||||||
|
this.$baseMessage(msg, 'success')
|
||||||
|
this.fetchData()
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
isFirstEnabled(row) {
|
||||||
|
const enabledList = this.list.filter((item) => item.isEnabled)
|
||||||
|
return enabledList.length > 0 && enabledList[0].id === row.id
|
||||||
|
},
|
||||||
|
isLastEnabled(row) {
|
||||||
|
const enabledList = this.list.filter((item) => item.isEnabled)
|
||||||
|
return enabledList.length > 0 && enabledList[enabledList.length - 1].id === row.id
|
||||||
|
},
|
||||||
|
async fetchSceneList() {
|
||||||
|
try {
|
||||||
|
const { data } = await getAllScenes()
|
||||||
|
this.sceneList = data || []
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
getSceneName(scene) {
|
||||||
|
if (!scene) return '通用'
|
||||||
|
const found = this.sceneList.find((item) => item.scene === scene)
|
||||||
|
return found ? found.sceneName : scene
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.music-management-container {
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
Reference in New Issue
Block a user