PublishAudio.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. <template>
  2. <el-row class="movie-list">
  3. <el-row style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
  4. <el-col :md="12" style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
  5. <el-card class="box-card">
  6. <div slot="header" class="clearfix">
  7. <span>上传音频文件</span>
  8. </div>
  9. <div class="text item">
  10. <uploader
  11. class="uploader-example"
  12. :options="options"
  13. :auto-start="true"
  14. @file-added="onFileAdded"
  15. @file-success="onFileSuccess"
  16. @file-progress="onFileProgress"
  17. @file-error="onFileError"
  18. >
  19. <uploader-unsupport />
  20. <uploader-drop>
  21. <p>拖动音频文件到此处或</p>
  22. <uploader-btn :attrs="attrs">选择音频文件</uploader-btn>
  23. </uploader-drop>
  24. <uploader-list />
  25. </uploader>
  26. </div>
  27. </el-card>
  28. </el-col>
  29. <el-col :md="12" style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
  30. <el-card class="box-card">
  31. <div slot="header" class="clearfix">
  32. <span>稿件信息</span>
  33. <el-button style="float: right; padding: 3px 0" type="text" @click="onSubmit">发布</el-button>
  34. </div>
  35. <div class="text item">
  36. <el-form ref="form" :model="form" label-width="80px">
  37. <el-form-item label="标题">
  38. <el-input v-model="form.title" style="padding-right: 1px" placeholder="标题不能超过 50 个字符" />
  39. </el-form-item>
  40. <el-form-item label="描述">
  41. <el-input v-model="form.description" type="textarea" autosize style="padding-right: 1px;" />
  42. </el-form-item>
  43. <el-form-item label="可见范围">
  44. <el-select v-model="form.scope" placeholder="选择稿件的可见范围">
  45. <el-option label="本人可见" value="1" />
  46. <el-option label="所有人可见" value="2" />
  47. <el-option label="VIP 可见" value="3" />
  48. <el-option label="验证码可见" value="4" />
  49. </el-select>
  50. </el-form-item>
  51. <el-form-item label="定时发布">
  52. <el-date-picker
  53. v-model="form.scheduledPubDate"
  54. type="datetime"
  55. placeholder="选择定时发布的时间"
  56. />
  57. </el-form-item>
  58. </el-form>
  59. </div>
  60. </el-card>
  61. </el-col>
  62. </el-row>
  63. </el-row>
  64. </template>
  65. <script>
  66. import { getServerInfo } from '@/api/content'
  67. import { addAudioPost } from '@/api/audio'
  68. export default {
  69. name: 'PublishAudio',
  70. data() {
  71. return {
  72. // ****************************************************************************************************************
  73. options: {
  74. target: process.env.VUE_APP_OSS_URL,
  75. chunkSize: 1024 * 1024 * 1024, // 1GiB
  76. fileParameterName: 'file',
  77. testChunks: false,
  78. query: (file, chunk) => {
  79. return {
  80. channelId: 3
  81. }
  82. },
  83. headers: {
  84. Authorization: ''
  85. }
  86. },
  87. attrs: {
  88. accept: 'audio/*'
  89. },
  90. // ****************************************************************************************************************
  91. form: {
  92. audioFileId: null,
  93. audioUrl: null,
  94. title: null,
  95. description: null,
  96. scope: '1',
  97. scheduledPubDate: null
  98. }
  99. }
  100. },
  101. created() {
  102. getServerInfo(3).then(res => {
  103. if (res.code === 0) {
  104. const resData = res.data
  105. this.options.target = resData.ossUrl
  106. this.options.chunkSize = resData.maxSize
  107. this.options.headers.Authorization = 'Bearer ' + resData.token
  108. } else {
  109. this.$notify({
  110. title: '提示',
  111. message: '获取 OSS 服务器地址失败, 暂时无法上传文件',
  112. type: 'error',
  113. duration: 3000
  114. })
  115. }
  116. }).catch(error => {
  117. this.$notify({
  118. title: '提示',
  119. message: error.message,
  120. type: 'warning',
  121. duration: 3000
  122. })
  123. })
  124. },
  125. methods: {
  126. // ****************************************************************************************************************
  127. onFileAdded(file) {
  128. this.setTitle(file.file.name)
  129. },
  130. onFileProgress(rootFile, file, chunk) {
  131. },
  132. onFileSuccess(rootFile, file, response, chunk) {
  133. const res = JSON.parse(response)
  134. if (res.code === 0) {
  135. const resData = res.data
  136. this.form.audioFileId = resData.uploadId
  137. this.form.audioUrl = resData.url
  138. this.$notify({
  139. title: '提示',
  140. message: '音频已上传',
  141. type: 'warning',
  142. duration: 3000
  143. })
  144. }
  145. },
  146. onFileError(rootFile, file, response, chunk) {
  147. console.log('文件上传错误')
  148. },
  149. // ****************************************************************************************************************
  150. setTitle(title) {
  151. if (title.length > 50) {
  152. this.form.title = title.substring(0, 50)
  153. this.form.description = title
  154. } else {
  155. this.form.title = title
  156. }
  157. },
  158. onSubmit() {
  159. if (!this.form.audioFileId) {
  160. this.$notify({
  161. title: '提示',
  162. message: '你还没有上传音频',
  163. type: 'warning',
  164. duration: 3000
  165. }
  166. )
  167. return
  168. }
  169. if (this.form.title === null) {
  170. this.$notify({
  171. title: '提示',
  172. message: '稿件标题不能为空',
  173. type: 'warning',
  174. duration: 3000
  175. }
  176. )
  177. return
  178. }
  179. addAudioPost(this.form).then(res => {
  180. if (res.code === 0) {
  181. this.$notify({
  182. title: '提示',
  183. message: '投稿成功',
  184. type: 'warning',
  185. duration: 3000
  186. })
  187. this.$router.push('/my/post/list/audio')
  188. } else {
  189. this.$notify({
  190. title: '提示',
  191. message: res.msg,
  192. type: 'warning',
  193. duration: 3000
  194. })
  195. }
  196. }).catch(error => {
  197. this.$notify({
  198. title: '提示',
  199. message: error.message,
  200. type: 'warning',
  201. duration: 3000
  202. })
  203. })
  204. }
  205. }
  206. }
  207. </script>
  208. <style>
  209. .uploader-example {
  210. width: 500px;
  211. padding: 15px;
  212. margin: 40px auto 0;
  213. font-size: 12px;
  214. box-shadow: 0 0 10px rgba(0, 0, 0, .4);
  215. }
  216. .uploader-example .uploader-btn {
  217. margin-right: 4px;
  218. }
  219. .uploader-example .uploader-list {
  220. max-height: 440px;
  221. overflow: auto;
  222. overflow-x: hidden;
  223. overflow-y: auto;
  224. }
  225. .avatar-uploader .el-upload {
  226. border: 1px dashed #d9d9d9;
  227. border-radius: 6px;
  228. cursor: pointer;
  229. position: relative;
  230. overflow: hidden;
  231. }
  232. .avatar-uploader .el-upload:hover {
  233. border-color: #409EFF;
  234. }
  235. .avatar-uploader-icon {
  236. font-size: 28px;
  237. color: #8c939d;
  238. width: 320px;
  239. height: 240px;
  240. line-height: 178px;
  241. text-align: center;
  242. }
  243. .avatar {
  244. width: 320px;
  245. height: 240px;
  246. display: block;
  247. }
  248. .uploader-example {
  249. width: 500px;
  250. padding: 15px;
  251. margin: 40px auto 0;
  252. font-size: 12px;
  253. box-shadow: 0 0 10px rgba(0, 0, 0, .4);
  254. }
  255. .uploader-example .uploader-btn {
  256. margin-right: 4px;
  257. }
  258. .uploader-example .uploader-list {
  259. max-height: 440px;
  260. overflow: auto;
  261. overflow-x: hidden;
  262. overflow-y: auto;
  263. }
  264. .avatar-uploader .el-upload {
  265. border: 1px dashed #d9d9d9;
  266. border-radius: 6px;
  267. cursor: pointer;
  268. position: relative;
  269. overflow: hidden;
  270. }
  271. .avatar-uploader .el-upload:hover {
  272. border-color: #409EFF;
  273. }
  274. .avatar-uploader-icon {
  275. font-size: 28px;
  276. color: #8c939d;
  277. width: 320px;
  278. height: 240px;
  279. line-height: 178px;
  280. text-align: center;
  281. }
  282. .avatar {
  283. width: 320px;
  284. height: 240px;
  285. display: block;
  286. }
  287. </style>