2021-11-15 10:29:05 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<div class="addPlay">
|
|
|
|
|
|
<div v-if="type == '1'">
|
|
|
|
|
|
<div class="content">
|
|
|
|
|
|
<div class="item">
|
|
|
|
|
|
<div class="label">音频文件</div>
|
|
|
|
|
|
<div class="value" @click="toRecord">
|
|
|
|
|
|
<span class="color-999" :style="{ color: file ? '#333' : '' }">{{ file ? '已选择' : '请选择' }}</span>
|
2021-12-24 21:20:52 +08:00
|
|
|
|
<img src="img/right-img.png" alt="">
|
2021-11-15 10:29:05 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="radio-content">
|
|
|
|
|
|
<div class="title">素材标题</div>
|
2021-12-15 14:37:20 +08:00
|
|
|
|
<textarea rows="2" placeholder="请输入(30字以内)" v-model="name" style="width:100%;height:80px;"
|
|
|
|
|
|
maxlength="30"></textarea>
|
2021-11-15 10:29:05 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div v-else>
|
|
|
|
|
|
<div class="radio-content mar-b16">
|
|
|
|
|
|
<div class="title">素材标题</div>
|
2021-12-15 14:37:20 +08:00
|
|
|
|
<textarea rows="2" placeholder="请输入(30字以内)" v-model="name" style="width:100%;height:80px;"
|
|
|
|
|
|
maxlength="30"></textarea>
|
2021-11-15 10:29:05 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
<div class="radio-content">
|
|
|
|
|
|
<div class="title">文本内容</div>
|
2021-12-15 14:37:20 +08:00
|
|
|
|
<textarea rows="8" placeholder="请输入文本内容(12000字以内)" v-model="content" style="width:100%;height:300px;"
|
|
|
|
|
|
maxlength="12000"></textarea>
|
2021-11-15 10:29:05 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="btn" @click="confirm">确认</div>
|
2021-12-24 10:02:37 +08:00
|
|
|
|
|
2021-11-15 10:29:05 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
|
|
2021-12-15 14:37:20 +08:00
|
|
|
|
export default {
|
|
|
|
|
|
name: "addPlay",
|
|
|
|
|
|
data() {
|
|
|
|
|
|
return {
|
|
|
|
|
|
type: '1',
|
|
|
|
|
|
file: null,
|
|
|
|
|
|
name: '',
|
|
|
|
|
|
content: ''
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2021-11-15 10:29:05 +08:00
|
|
|
|
|
2021-12-15 14:37:20 +08:00
|
|
|
|
onLoad(query) {
|
|
|
|
|
|
this.type = query.type
|
|
|
|
|
|
uni.$on('record', e => {
|
|
|
|
|
|
this.file = e
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
|
|
toRecord() {
|
|
|
|
|
|
uni.navigateTo({
|
2021-12-16 18:30:17 +08:00
|
|
|
|
url: `./recording`
|
2021-11-15 10:29:05 +08:00
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
|
2021-12-15 14:37:20 +08:00
|
|
|
|
dataURLtoFile(dataurl, filename) {
|
|
|
|
|
|
var arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1]
|
|
|
|
|
|
var bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n)
|
2021-11-15 10:29:05 +08:00
|
|
|
|
|
2021-12-15 14:37:20 +08:00
|
|
|
|
while (n--) {
|
|
|
|
|
|
u8arr[n] = bstr.charCodeAt(n)
|
|
|
|
|
|
}
|
2021-11-15 10:29:05 +08:00
|
|
|
|
|
2021-12-15 14:37:20 +08:00
|
|
|
|
return new File([u8arr], filename, {type: mime})
|
|
|
|
|
|
},
|
2021-11-15 10:29:05 +08:00
|
|
|
|
|
2021-12-15 14:37:20 +08:00
|
|
|
|
confirm() {
|
|
|
|
|
|
if (!this.file && this.type === '1') {
|
|
|
|
|
|
return this.$u.toast('请选择音频文件')
|
|
|
|
|
|
}
|
2021-11-15 10:29:05 +08:00
|
|
|
|
|
2021-12-15 14:37:20 +08:00
|
|
|
|
if (!this.name) {
|
|
|
|
|
|
return this.$u.toast('请输入素材标题')
|
|
|
|
|
|
}
|
2021-11-15 10:29:05 +08:00
|
|
|
|
|
2021-12-15 14:37:20 +08:00
|
|
|
|
if (!this.content && this.type === '3') {
|
|
|
|
|
|
return this.$u.toast('请输入文本内容')
|
|
|
|
|
|
}
|
2021-11-15 10:29:05 +08:00
|
|
|
|
|
2021-12-15 14:37:20 +08:00
|
|
|
|
uni.showLoading()
|
|
|
|
|
|
let formData = {}
|
|
|
|
|
|
formData = new FormData()
|
|
|
|
|
|
if (this.type === '1') {
|
|
|
|
|
|
formData.append('file', this.dataURLtoFile(this.file, this.name + '.mp3'))
|
|
|
|
|
|
formData.append('type', this.type)
|
|
|
|
|
|
formData.append('content', this.content)
|
|
|
|
|
|
formData.append('name', this.name)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
formData.append('type', this.type)
|
|
|
|
|
|
formData.append('content', this.content)
|
|
|
|
|
|
formData.append('name', this.name)
|
2021-11-15 10:29:05 +08:00
|
|
|
|
}
|
2021-12-15 14:37:20 +08:00
|
|
|
|
this.$http.post(`/app/appdlbresource/addResourceWithFile`, formData).then((res) => {
|
|
|
|
|
|
uni.hideLoading()
|
|
|
|
|
|
if (res.code === 0) {
|
|
|
|
|
|
this.$u.toast('添加成功')
|
|
|
|
|
|
uni.$emit('getList')
|
|
|
|
|
|
uni.navigateBack({
|
|
|
|
|
|
delta: 1
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
2021-12-24 18:54:59 +08:00
|
|
|
|
}).catch(err => {
|
|
|
|
|
|
this.$u.toast('添加失败')
|
2021-12-15 14:37:20 +08:00
|
|
|
|
uni.hideLoading()
|
|
|
|
|
|
})
|
2021-11-15 10:29:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-12-15 14:37:20 +08:00
|
|
|
|
}
|
2021-11-15 10:29:05 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
|
.addPlay {
|
|
|
|
|
|
padding-bottom: 128px;
|
2021-12-15 14:37:20 +08:00
|
|
|
|
|
|
|
|
|
|
.content {
|
2021-11-15 10:29:05 +08:00
|
|
|
|
padding-left: 32px;
|
|
|
|
|
|
background-color: #fff;
|
2021-12-15 14:37:20 +08:00
|
|
|
|
|
|
|
|
|
|
.item {
|
2021-11-15 10:29:05 +08:00
|
|
|
|
width: 100%;
|
|
|
|
|
|
padding: 34px 0;
|
|
|
|
|
|
font-size: 32px;
|
|
|
|
|
|
font-family: PingFangSC-Regular, PingFang SC;
|
|
|
|
|
|
font-weight: 400;
|
|
|
|
|
|
line-height: 44px;
|
|
|
|
|
|
border-bottom: 1px solid #ddd;
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
color: #333;
|
|
|
|
|
|
justify-content: space-between;
|
2021-12-15 14:37:20 +08:00
|
|
|
|
|
|
|
|
|
|
.label {
|
2021-11-15 10:29:05 +08:00
|
|
|
|
width: 198px;
|
|
|
|
|
|
font-size: 32px;
|
|
|
|
|
|
}
|
2021-12-15 14:37:20 +08:00
|
|
|
|
|
|
|
|
|
|
.value {
|
2021-11-15 10:29:05 +08:00
|
|
|
|
font-size: 28px;
|
|
|
|
|
|
width: calc(100% - 198px);
|
|
|
|
|
|
padding-right: 32px;
|
|
|
|
|
|
box-sizing: border-box;
|
|
|
|
|
|
text-align: right;
|
|
|
|
|
|
|
2021-12-15 14:37:20 +08:00
|
|
|
|
img {
|
2021-11-15 10:29:05 +08:00
|
|
|
|
width: 32px;
|
|
|
|
|
|
height: 32px;
|
|
|
|
|
|
vertical-align: middle;
|
|
|
|
|
|
margin-left: 6px;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-12-15 14:37:20 +08:00
|
|
|
|
|
|
|
|
|
|
.color-999 {
|
2021-11-15 10:29:05 +08:00
|
|
|
|
color: #999;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-12-15 14:37:20 +08:00
|
|
|
|
|
|
|
|
|
|
.radio-content {
|
2021-11-15 10:29:05 +08:00
|
|
|
|
padding: 34px 32px 38px;
|
|
|
|
|
|
background-color: #fff;
|
2021-12-15 14:37:20 +08:00
|
|
|
|
|
|
|
|
|
|
.title {
|
2021-11-15 10:29:05 +08:00
|
|
|
|
font-size: 32px;
|
|
|
|
|
|
font-family: PingFangSC-Regular, PingFang SC;
|
|
|
|
|
|
font-weight: 400;
|
|
|
|
|
|
color: #333;
|
|
|
|
|
|
line-height: 44px;
|
|
|
|
|
|
margin-bottom: 32px;
|
2021-12-15 14:37:20 +08:00
|
|
|
|
|
|
|
|
|
|
span {
|
2021-11-15 10:29:05 +08:00
|
|
|
|
font-size: 24px;
|
|
|
|
|
|
font-weight: 400;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-12-15 14:37:20 +08:00
|
|
|
|
|
|
|
|
|
|
.mar-b16 {
|
2021-11-15 10:29:05 +08:00
|
|
|
|
margin-bottom: 16px;
|
|
|
|
|
|
}
|
2021-12-15 14:37:20 +08:00
|
|
|
|
|
|
|
|
|
|
.btn {
|
2021-11-15 10:29:05 +08:00
|
|
|
|
position: fixed;
|
|
|
|
|
|
bottom: 0;
|
|
|
|
|
|
left: 0;
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
height: 112px;
|
|
|
|
|
|
line-height: 112px;
|
|
|
|
|
|
text-align: center;
|
|
|
|
|
|
background: #3975C6;
|
|
|
|
|
|
font-size: 32px;
|
|
|
|
|
|
font-family: PingFangSC-Medium, PingFang SC;
|
|
|
|
|
|
font-weight: 500;
|
|
|
|
|
|
color: #FFFFFF;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-12-15 14:37:20 +08:00
|
|
|
|
</style>
|