sale_vod_edit.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <template>
  2. <div class="mainContainer">
  3. <div class="pform-head">
  4. <h3>编辑课程</h3>
  5. </div>
  6. <div class="pform-body">
  7. <el-form :model="vodForm" label-width="100px">
  8. <el-form-item label="课程所属UID">
  9. <el-input v-model="vodForm.uid" placeholder="用户UID" style="width:200px"></el-input>
  10. </el-form-item>
  11. <el-form-item label="课程标题">
  12. <el-input v-model="vodForm.title"></el-input>
  13. </el-form-item>
  14. <el-form-item label="课程大纲">
  15. <el-input type="textarea" v-model="vodForm.content" placeholder="请输入内容"
  16. minlength="5"
  17. maxlength="5000" rows="6"
  18. show-word-limit></el-input>
  19. </el-form-item>
  20. <el-form-item label="课程价格">
  21. <el-input v-model="vodForm.price" placeholder="单位:元" style="width:200px"></el-input>
  22. </el-form-item>
  23. <el-form-item label="课程首页图">
  24. <el-upload
  25. class="img-uploader"
  26. action="/api/admin/sale/uploadImg"
  27. :show-file-list="false"
  28. :on-success="handleImgSuccess"
  29. :before-upload="beforeImgUpload"
  30. >
  31. <img v-if="vodForm.img_icon" :src="vodForm.img_icon" class="img" />
  32. <i v-else class="el-icon-plus img-uploader-icon"></i>
  33. </el-upload>
  34. </el-form-item>
  35. <el-form-item label="试看视频">
  36. <el-upload
  37. action=""
  38. :show-file-list="false"
  39. :http-request="fileChange"
  40. >
  41. <el-button size="small" type="primary">点击上传</el-button>
  42. </el-upload>
  43. <div class="file-upload">
  44. <span>上传进度: {{statusText}}</span>
  45. <el-progress :text-inside="true" :stroke-width="20" :percentage="authProgress"></el-progress>
  46. </div>
  47. </el-form-item>
  48. </el-form>
  49. <div slot="footer">
  50. <el-button type="primary" style="margin-left: 100px;" @click="submitVod">保存</el-button>
  51. </div>
  52. </div>
  53. </div>
  54. </template>
  55. <script>
  56. import '@/assets/js/aliyun-upload-sdk/aliyun-upload-sdk-1.5.2.min.js';
  57. export default {
  58. head() {
  59. return {
  60. script: [
  61. {src: 'https://gosspublic.alicdn.com/aliyun-oss-sdk-6.13.0.min.js'},
  62. ]
  63. }
  64. },
  65. data() {
  66. return {
  67. vodForm:{
  68. title:'',
  69. content:'',
  70. uid:'',
  71. price:'',
  72. img_icon:'',
  73. },
  74. videoFile: null,
  75. videoId:0,
  76. videoUrl:'',
  77. authProgress: 0,
  78. uploader: null,
  79. statusText: ''
  80. }
  81. },
  82. computed: {
  83. },
  84. mounted() {
  85. this.getData();
  86. },
  87. methods: {
  88. handleImgSuccess(res, file) {
  89. this.vodForm.img_icon = res.data.file_url_abs
  90. },
  91. beforeImgUpload(file) {
  92. return true
  93. },
  94. fileChange (e) {
  95. this.videoFile = e.file
  96. if (this.uploader) {
  97. this.uploader.stopUpload()
  98. this.authProgress = 0
  99. this.statusText = ""
  100. }
  101. this.uploader = this.createUploader()
  102. this.uploader.addFile(this.videoFile)
  103. this.authUpload();
  104. },
  105. authUpload () {
  106. // 然后调用 startUpload 方法, 开始上传
  107. if (this.uploader !== null) {
  108. this.uploader.startUpload()
  109. this.uploadDisabled = true
  110. }
  111. },
  112. createUploader (type) {
  113. let self = this
  114. let uploader = new AliyunUpload.Vod({
  115. timeout: 60000,
  116. partSize: 1048576,
  117. parallel: 5,
  118. retryCount: 3,
  119. retryDuration: 2,
  120. region: 'cn-shanghai',
  121. userId: '1024',
  122. // 添加文件成功
  123. addFileSuccess: function (uploadInfo) {
  124. self.statusText = '添加文件成功, 等待上传...'
  125. console.log("addFileSuccess: " + uploadInfo.file.name)
  126. },
  127. // 开始上传
  128. onUploadstarted: function (uploadInfo) {
  129. self.$post("/api/admin/upload/video", {filename: uploadInfo.file.name}).then(({data}) => {
  130. let uploadAuth = data.UploadAuth;
  131. let uploadAddress = data.UploadAddress;
  132. let videoId = data.VideoId;
  133. self.videoId = data.VideoId;
  134. uploader.setUploadAuthAndAddress(uploadInfo, uploadAuth, uploadAddress, videoId)
  135. })
  136. self.statusText = '文件开始上传...'
  137. console.log("onUploadStarted:" + uploadInfo.file.name + ", endpoint:" + uploadInfo.endpoint + ", bucket:" + uploadInfo.bucket + ", object:" + uploadInfo.object)
  138. },
  139. // 文件上传成功
  140. onUploadSucceed: function (uploadInfo) {
  141. // self.getVideo();
  142. console.log("onUploadSucceed: " + uploadInfo.file.name + ", endpoint:" + uploadInfo.endpoint + ", bucket:" + uploadInfo.bucket + ", object:" + uploadInfo.object)
  143. self.statusText = '文件上传成功!'
  144. },
  145. // 文件上传进度,单位:字节, 可以在这个函数中拿到上传进度并显示在页面上
  146. onUploadProgress: function (uploadInfo, totalSize, progress) {
  147. console.log("onUploadProgress:file:" + uploadInfo.file.name + ", fileSize:" + totalSize + ", percent:" + Math.ceil(progress * 100) + "%")
  148. let progressPercent = Math.ceil(progress * 100)
  149. self.authProgress = progressPercent
  150. self.statusText = '文件上传中...'
  151. },
  152. })
  153. return uploader
  154. },
  155. // async getVideo() {
  156. // var res = await this.$post("/api/admin/upload/getVideo", {video_id: this.videoId});
  157. // if (res && res.status === 1) {
  158. // console.log(res);
  159. // // this.videoUrl = res.data;
  160. // }
  161. // }
  162. async submitVod() {
  163. var data = this.vodForm;
  164. data.video_id = this.videoId;
  165. data.id = this.$route.query.id;
  166. var res = await this.$post("/api/admin/sale/updateVideo", data);
  167. if (res && res.status === 1) {
  168. this.$message.success('更新成功')
  169. }else{
  170. this.$message.error('更新失败')
  171. }
  172. },
  173. async getData() {
  174. let query = this.$route.query;
  175. var res = await this.$post("/api/admin/sale/content", {id:query.id});
  176. if (res && res.status === 1) {
  177. let data = res.data;
  178. this.vodForm = {
  179. title:data.title,
  180. content:data.content,
  181. uid:data.uid,
  182. price:data.price,
  183. img_icon:data.img,
  184. };
  185. this.videoId = data.video_id;
  186. }
  187. },
  188. }
  189. };
  190. </script>
  191. <style>
  192. .pform-head{
  193. text-align: center;
  194. }
  195. .pform-body{
  196. margin: 20px 200px;
  197. }
  198. .img-uploader .el-upload {
  199. border: 1px dashed #d9d9d9;
  200. border-radius: 6px;
  201. cursor: pointer;
  202. position: relative;
  203. overflow: hidden;
  204. }
  205. .img-uploader .el-upload:hover {
  206. border-color: #409eff;
  207. }
  208. .img-uploader-icon {
  209. font-size: 28px;
  210. color: #8c939d;
  211. width: 178px;
  212. height: 178px;
  213. line-height: 178px;
  214. text-align: center;
  215. }
  216. .img {
  217. width: 270px;
  218. height: 190px;
  219. display: block;
  220. }
  221. .file-upload {
  222. width:300px;
  223. }
  224. </style>