mp:素材管理,增加【语音】【视频】

This commit is contained in:
YunaiV 2023-01-14 16:55:36 +08:00
parent 5a1d02dffd
commit bf5dcdd582
2 changed files with 126 additions and 190 deletions

View File

@ -12,7 +12,7 @@
<template> <template>
<div class="wx-voice-div" @click="playVoice"> <div class="wx-voice-div" @click="playVoice">
<i :class="playing !== true ? 'el-icon-video-play': 'el-icon-video-pause'"> <i :class="playing !== true ? 'el-icon-video-play': 'el-icon-video-pause'">
<span class="amr-duration" v-if="duration">{{ duration }}</span> <span class="amr-duration" v-if="duration">{{ duration }} </span>
</i> </i>
<div v-if="content"> <div v-if="content">
<el-tag type="success" size="mini">语音识别</el-tag> <el-tag type="success" size="mini">语音识别</el-tag>

View File

@ -20,6 +20,10 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
芋道源码
清理冗余 css 内容清理冗余 data 变量
美化样式支持播放提升使用体验
优化代码特别是方法名和变量提升可读性
--> -->
<template> <template>
<div class="app-container"> <div class="app-container">
@ -63,152 +67,102 @@ SOFTWARE.
<pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize" <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
@pagination="getList"/> @pagination="getList"/>
</el-tab-pane> </el-tab-pane>
<!-- tab 2语音 -->
<el-tab-pane name="voice"> <el-tab-pane name="voice">
<span slot="label"><i class="el-icon-microphone"></i> 语音</span> <span slot="label"><i class="el-icon-microphone"></i> 语音</span>
<div class="add_but"> <div class="add_but" v-hasPermi="['mp:material:upload-permanent']">
<el-upload <el-upload :action="actionUrl" :headers="headers" multiple :limit="1" :file-list="fileList" :data="uploadData"
:action="actionUrl" :on-success="handleUploadSuccess" :before-upload="beforeVoiceUpload">
:headers="headers"
multiple
:limit="1"
:on-success="handleUploadSuccess"
:file-list="fileList"
:before-upload="beforeVoiceUpload"
:data="uploadData">
<el-button size="mini" type="primary">点击上传</el-button> <el-button size="mini" type="primary">点击上传</el-button>
<div slot="tip" class="el-upload__tip"> <span slot="tip" class="el-upload__tip" style="margin-left: 5px">格式支持 mp3/wma/wav/amr文件大小不超过 2M播放长度不超过 60s</span>
格式支持mp3/wma/wav/amr文件大小不超过2M播放长度不超过60s
</div>
</el-upload> </el-upload>
</div> </div>
<el-table <el-table :data="list" stripe border v-loading="loading" style="margin-top: 10px;">
:data="list" <el-table-column label="编号" align="center" prop="mediaId" />
stripe <el-table-column label="文件名" align="center" prop="name" />
border <el-table-column label="语音" align="center">
v-loading="loading"> <template v-slot="scope">
<el-table-column <wx-voice-player :url="scope.row.url" />
prop="mediaId" </template>
label="media_id">
</el-table-column> </el-table-column>
<el-table-column <el-table-column label="上传时间" align="center" prop="createTime" width="180">
prop="name" <template v-slot="scope">
label="名称"> <span>{{ parseTime(scope.row.createTime) }}</span>
</template>
</el-table-column> </el-table-column>
<el-table-column <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
prop="updateTime"
label="更新时间">
</el-table-column>
<el-table-column
fixed="right"
label="操作">
<template slot-scope="scope"> <template slot-scope="scope">
<el-button type="text" <el-button type="text" icon="el-icon-download" size="small" plain @click="handleDownload(scope.row)">下载</el-button>
icon="el-icon-download" <el-button type="text" icon="el-icon-delete" size="small" plain @click="handleDelete(scope.row)"
size="small" v-hasPermi="['mp:material:delete']">删除</el-button>
plain
@click="handleDown(scope.row)">下载</el-button>
<el-button type="text"
icon="el-icon-delete"
size="small"
plain
@click="handleDelete(scope.row)">删除</el-button>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
<el-pagination <!-- 分页组件 -->
@size-change="sizeChange" <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
@current-change="currentChange" @pagination="getList"/>
:current-page.sync="queryParams.currentPage"
:page-sizes="[10, 20]"
:page-size="queryParams.pageSize"
layout="total, sizes, prev, pager, next, jumper"
:total="queryParams.total"
class="pagination"
>
</el-pagination>
</el-tab-pane> </el-tab-pane>
<!-- tab 3视频 -->
<el-tab-pane name="video"> <el-tab-pane name="video">
<span slot="label"><i class="el-icon-video-play"></i> 视频</span> <span slot="label"><i class="el-icon-video-play"></i> 视频</span>
<div class="add_but"> <div class="add_but" v-hasPermi="['mp:material:upload-permanent']">
<el-button size="mini" type="primary" @click="handleAddVideo">新建</el-button> <el-button size="mini" type="primary" @click="handleAddVideo">新建视频</el-button>
</div> </div>
<el-dialog title="新建视频" :visible.sync="dialogVideoVisible" v-loading="addMaterialLoading"> <!-- 新建视频的弹窗 -->
<el-upload <el-dialog title="新建视频" :visible.sync="dialogVideoVisible" append-to-body width="600px"
ref="uploadVideo" v-loading="addMaterialLoading">
:action="actionUrl" <el-upload :action="actionUrl" :headers="headers" multiple :limit="1" :file-list="fileList" :data="uploadData"
:headers="headers" :before-upload="beforeVideoUpload" :on-success="handleUploadSuccess"
multiple ref="uploadVideo" :auto-upload="false">
:limit="1"
:on-success="handleUploadSuccess"
:file-list="fileList"
:before-upload="beforeVideoUpload"
:auto-upload="false"
:data="uploadData">
<el-button slot="trigger" size="mini" type="primary">选择视频</el-button> <el-button slot="trigger" size="mini" type="primary">选择视频</el-button>
<div class="el-upload__tip"> <span class="el-upload__tip" style="margin-left: 10px;">格式支持 MP4文件大小不超过 10MB</span>
格式支持MP4文件大小不超过10MB
</div>
</el-upload> </el-upload>
<el-form :model="uploadData" <el-form :model="uploadData" :rules="uploadRules" ref="uploadForm" label-width="80px">
:rules="uploadRules" <el-row>
ref="uploadForm">
<el-form-item label="标题" prop="title"> <el-form-item label="标题" prop="title">
<el-input v-model="uploadData.title" placeholder="标题将展示在相关播放页面,建议填写清晰、准确、生动的标题"></el-input> <el-input v-model="uploadData.title" placeholder="标题将展示在相关播放页面,建议填写清晰、准确、生动的标题" />
</el-form-item> </el-form-item>
</el-row>
<el-row>
<el-form-item label="描述" prop="introduction"> <el-form-item label="描述" prop="introduction">
<el-input :rows="3" type="textarea" v-model="uploadData.introduction" placeholder="介绍语将展示在相关播放页面,建议填写简洁明确、有信息量的内容"></el-input> <el-input :rows="3" type="textarea" v-model="uploadData.introduction"
placeholder="介绍语将展示在相关播放页面,建议填写简洁明确、有信息量的内容" />
</el-form-item> </el-form-item>
</el-row>
</el-form> </el-form>
<div slot="footer" class="dialog-footer"> <div slot="footer" class="dialog-footer">
<el-button @click="dialogVideoVisible = false"> </el-button> <el-button @click="cancelVideo"> </el-button>
<el-button type="primary" @click="subVideo"> </el-button> <el-button type="primary" @click="submitVideo"> </el-button>
</div> </div>
</el-dialog> </el-dialog>
<el-table <el-table :data="list" stripe border v-loading="loading" style="margin-top: 10px;">
:data="list" <el-table-column label="编号" align="center" prop="mediaId" />
stripe <el-table-column label="文件名" align="center" prop="name" />
border <el-table-column label="标题" align="center" prop="title" />
v-loading="loading"> <el-table-column label="介绍" align="center" prop="introduction" />
<el-table-column <el-table-column label="视频" align="center">
prop="mediaId" <template v-slot="scope">
label="media_id"> <wx-video-player :url="scope.row.url" />
</template>
</el-table-column> </el-table-column>
<el-table-column <el-table-column label="上传时间" align="center" prop="createTime" width="180">
prop="name" <template v-slot="scope">
label="名称"> <span>{{ parseTime(scope.row.createTime) }}</span>
</template>
</el-table-column> </el-table-column>
<el-table-column <el-table-column label="操作" align="center" fixed="right" class-name="small-padding fixed-width">
prop="updateTime" <template v-slot="scope">
label="更新时间"> <el-button type="text" icon="el-icon-download" size="small" plain @click="handleDownload(scope.row)">下载</el-button>
</el-table-column> <el-button type="text" icon="el-icon-delete" size="small" plain @click="handleDelete(scope.row)"
<el-table-column v-hasPermi="['mp:material:delete']">删除</el-button>
fixed="right"
label="操作">
<template slot-scope="scope">
<el-button type="text"
icon="el-icon-view"
size="small"
plain
@click="handleInfo(scope.row)">查看</el-button>
<el-button type="text"
icon="el-icon-delete"
size="small"
plain
@click="handleDelete(scope.row)">删除</el-button>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
<el-pagination <!-- 分页组件 -->
@size-change="sizeChange" <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
@current-change="currentChange" @pagination="getList"/>
:current-page.sync="queryParams.currentPage"
:page-sizes="[10, 20]"
:page-size="queryParams.pageSize"
layout="total, sizes, prev, pager, next, jumper"
:total="queryParams.total"
class="pagination"
>
</el-pagination>
</el-tab-pane> </el-tab-pane>
</el-tabs> </el-tabs>
</div> </div>
@ -243,26 +197,23 @@ export default {
pageNo: 1, pageNo: 1,
pageSize: 10, pageSize: 10,
accountId: undefined, accountId: undefined,
permanent: true,
}, },
actionUrl: process.env.VUE_APP_BASE_API + '/admin-api/mp/material/upload-permanent', actionUrl: process.env.VUE_APP_BASE_API + '/admin-api/mp/material/upload-permanent',
headers: { Authorization: "Bearer " + getAccessToken() }, // headers: { Authorization: "Bearer " + getAccessToken() }, //
fileList:[], fileList:[],
dialogVideoVisible:false,
dialogNewsVisible:false,
addMaterialLoading:false,
uploadData: { uploadData: {
"type": 'image', "type": 'image',
"title":'', "title":'',
"introduction":'' "introduction":''
}, },
uploadRules:{ // === ===
title: [ dialogVideoVisible: false,
{ required: true, message: '请输入标题', trigger: 'blur' } addMaterialLoading: false,
], uploadRules: { //
introduction: [ title: [{ required: true, message: '请输入标题', trigger: 'blur' }],
{ required: true, message: '请输入描述', trigger: 'blur' } introduction: [{ required: true, message: '请输入描述', trigger: 'blur' }],
],
}, },
// //
@ -284,7 +235,6 @@ export default {
// ======================== ======================== // ======================== ========================
/** 设置账号编号 */ /** 设置账号编号 */
setAccountId(accountId) { setAccountId(accountId) {
console.log('奥特曼!')
this.queryParams.accountId = accountId; this.queryParams.accountId = accountId;
this.uploadData.accountId = accountId; this.uploadData.accountId = accountId;
}, },
@ -333,53 +283,6 @@ export default {
}, },
// ======================== ======================== // ======================== ========================
handleInfo(row){
this.loading = true
getMaterialVideo({
mediaId:row.mediaId
}).then((response) => {
this.loading = false
if(response.code == 200){
let downUrl = response.data.downUrl
window.open(downUrl, '_blank');
}else{
this.$message.error('获取微信视频素材出错:' + response.data.msg)
}
}).catch(() => {
this.loading = false
})
},
handleDown(row){
this.loading = true
getMaterialOther({
mediaId:row.mediaId,
fileName:row.name
}).then(response => {
this.loading = false
let url = window.URL.createObjectURL(new Blob([response.data]))
let link = document.createElement('a')
link.style.display = 'none'
link.href = url
link.setAttribute('download', row.name)
document.body.appendChild(link)
link.click()
}).catch(() => {
this.loading = false
})
},
subVideo(){
this.$refs['uploadForm'].validate((valid) => {
if (valid) {
this.$refs.uploadVideo.submit()
} else {
return false
}
})
},
handleAddVideo(){
this.dialogVideoVisible = true
},
beforeImageUpload(file) { beforeImageUpload(file) {
const isType = file.type === 'image/jpeg' const isType = file.type === 'image/jpeg'
|| file.type === 'image/png' || file.type === 'image/png'
@ -388,42 +291,46 @@ export default {
|| file.type === 'image/jpg'; || file.type === 'image/jpg';
if (!isType) { if (!isType) {
this.$message.error('上传图片格式不对!') this.$message.error('上传图片格式不对!')
this.loading = false
return false; return false;
} }
const isLt = file.size / 1024 / 1024 < 2 const isLt = file.size / 1024 / 1024 < 2
if (!isLt) { if (!isLt) {
this.$message.error('上传图片大小不能超过 2M!') this.$message.error('上传图片大小不能超过 2M!')
this.loading = false
return false; return false;
} }
this.loading = true this.loading = true
return true; return true;
}, },
beforeVoiceUpload(file){ beforeVoiceUpload(file){
const isType = file.type === 'audio/mp3' || file.type === 'audio/wma' || file.type === 'audio/wav' || file.type === 'audio/amr'; const isType = file.type === 'audio/mp3'
|| file.type === 'audio/wma'
|| file.type === 'audio/wav'
|| file.type === 'audio/amr';
const isLt = file.size / 1024 / 1024 < 2 const isLt = file.size / 1024 / 1024 < 2
if (!isType) { if (!isType) {
this.$message.error('上传语音格式不对!') this.$message.error('上传语音格式不对!')
return false;
} }
if (!isLt) { if (!isLt) {
this.$message.error('上传语音大小不能超过2M!') this.$message.error('上传语音大小不能超过 2M!')
return false;
} }
this.loading = false this.loading = true
return isType && isLt; return true;
}, },
beforeVideoUpload(file){ beforeVideoUpload(file){
this.addMaterialLoading = true
const isType = file.type === 'video/mp4' const isType = file.type === 'video/mp4'
const isLt = file.size / 1024 / 1024 < 10
if (!isType) { if (!isType) {
this.$message.error('上传视频格式不对!') this.$message.error('上传视频格式不对!')
return false;
} }
const isLt = file.size / 1024 / 1024 < 10
if (!isLt) { if (!isLt) {
this.$message.error('上传视频大小不能超过10M!') this.$message.error('上传视频大小不能超过 10M!')
return false
} }
this.addMaterialLoading = false this.addMaterialLoading = true
return isType && isLt; return true
}, },
handleUploadSuccess(response, file, fileList) { handleUploadSuccess(response, file, fileList) {
this.loading = false this.loading = false
@ -442,6 +349,35 @@ export default {
// //
this.getList() this.getList()
}, },
//
handleDownload(row) {
window.open(row.url,'_blank')
},
// video
submitVideo() {
this.$refs['uploadForm'].validate((valid) => {
if (!valid) {
return false;
}
this.$refs.uploadVideo.submit()
})
},
handleAddVideo() {
this.resetVideo();
this.dialogVideoVisible = true
},
/** 取消按钮 */
cancelVideo() {
this.dialogVideoVisible = false;
this.resetVideo();
},
/** 表单重置 */
resetVideo() {
this.fileList = []
this.uploadData.title = ''
this.uploadData.introduction = ''
this.resetForm("uploadForm");
},
// ======================== ======================== // ======================== ========================
handleDelete(item) { handleDelete(item) {