new_video_upload.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <template>
  2. <div class="box">
  3. <form @submit.prevent="onSubmit">
  4. <div class="top flex align-center">
  5. <van-field v-model="message" name="title" rows="5" autosize type="textarea" maxlength="150" placeholder="添加标题并使用合适的合集,能让更多人看到~"
  6. show-word-limit />
  7. <div>
  8. <van-uploader v-model="fileList" result-type="file" multiple accept="image/*" :max-count="1" :after-read="afterRead" />
  9. <p>选择封面</p>
  10. </div>
  11. </div>
  12. <div class="tip">
  13. <div>添加到合集</div>
  14. <van-field readonly clickable name="provier_id" :value="value.title" right-icon="arrow-down" placeholder="请选择"
  15. @click="showPicker = true" />
  16. <van-popup v-model="showPicker" position="bottom">
  17. <van-picker show-toolbar :columns="columns" value-key="title" @cancel="showPicker = false" @confirm="onConfirm"
  18. @change="onChange" />
  19. </van-popup>
  20. <van-button class="btn" native-type="button" type="info" block @click="createVideo()">发布</van-button>
  21. </div>
  22. </form>
  23. </div>
  24. </template>
  25. <script>
  26. import "@/assets/css/common.css";
  27. import Vue from "vue";
  28. import {
  29. Uploader,
  30. Icon,
  31. Form,
  32. Toast,
  33. Field
  34. } from "vant";
  35. export default {
  36. layout: "opacity_header",
  37. async asyncData({
  38. $axios,
  39. params,
  40. req
  41. }) {
  42. let id = params.id;
  43. let headers = req && req.headers;
  44. title: "发布视频";
  45. },
  46. head() {
  47. return {
  48. title: this.title,
  49. script: [{
  50. src: "https://hm.baidu.com/hm.js?18455f493c982100e5a82ec978a8d06e"
  51. }]
  52. };
  53. },
  54. data() {
  55. return {
  56. value: "",
  57. showPicker: false,
  58. message: "",
  59. src: "",
  60. fileList: [],
  61. columns: [],
  62. collectID: null,
  63. vid: this.$route.query.vid,
  64. file: null
  65. };
  66. },
  67. created() {
  68. this.needLogin();
  69. this.getCollect();
  70. },
  71. methods: {
  72. afterRead(file) {
  73. console.log(file);
  74. if (file.file.size > 1024 * 1024 * 5) {
  75. Toast.fail("图片文件超过5M,情重新上传!");
  76. this.fileList = [];
  77. return false;
  78. }
  79. let that = this;
  80. let par = new FormData();
  81. par.append("file", file.file);
  82. file.status = "uploading";
  83. file.message = "上传中...";
  84. this.$axios
  85. .$post("/upload_image", par, {
  86. headers: {
  87. "Content-Type": "multipart/form-data"
  88. }
  89. })
  90. .then(res => {
  91. that.fileList = [{
  92. url: res.filename
  93. }];
  94. file.status = "done";
  95. file.message = "上传成功";
  96. });
  97. },
  98. onChange(picker, value, index) {
  99. this.collectID = index;
  100. },
  101. createVideo() {
  102. let that = this;
  103. //检测描述的长度
  104. let message = that.message.replace(/(^\s*)|(\s*$)/g, "");
  105. if (message.length < 10) {
  106. Toast.fail("视频描述应大于10个字");
  107. return false;
  108. }
  109. if (message.length > 150) {
  110. Toast.fail("视频描述不能超过150字");
  111. return false;
  112. }
  113. Toast.loading({
  114. message: "正在发布...",
  115. forbidClick: true,
  116. loadingType: "spinner"
  117. });
  118. var pdata = {
  119. video_id: that.vid,
  120. title: that.message,
  121. provider_id: Number(that.value.id) ? Number(that.value.id) : ''
  122. }
  123. if (that.fileList[0]) {
  124. pdata.cover_url = that.fileList[0].url ? that.fileList[0].url : ''
  125. }
  126. this.$axios
  127. .$post("/api/jishuquan/create_video", pdata)
  128. .then(res => {
  129. Toast.setDefaultOptions({
  130. onClose: function() {
  131. window.location.href = "/";
  132. }
  133. });
  134. Toast.success("发布成功");
  135. Toast.resetDefaultOptions();
  136. });
  137. },
  138. getCollect() {
  139. let that = this;
  140. this.$axios
  141. .$post(
  142. "/api/jishuquan/get_collections", {
  143. uid: this.userinfo.uid
  144. }, {
  145. neverLogout: true
  146. }
  147. )
  148. .then(res => {
  149. that.columns = res.data;
  150. });
  151. },
  152. onConfirm(value) {
  153. this.value = value;
  154. this.showPicker = false;
  155. }
  156. }
  157. };
  158. </script>
  159. <style>
  160. .btn {
  161. margin: 0.86rem 0;
  162. }
  163. .van-cell.van-cell--clickable {
  164. margin-top: 0.1rem;
  165. padding: 0.2rem 0.2rem;
  166. border-radius: 0.06rem;
  167. font-weight: 400px;
  168. border: 1px solid rgba(215, 223, 232, 0.5);
  169. }
  170. .tip {
  171. font-size: 0.28rem;
  172. font-family: PingFangSC-Medium, PingFang SC;
  173. font-weight: 600;
  174. color: rgba(25, 34, 46, 1);
  175. line-height: 0.4rem;
  176. padding: 0.2rem 0.4rem;
  177. }
  178. .top {
  179. width: 100%;
  180. }
  181. .box {
  182. width: 95%;
  183. margin: 0.4rem auto;
  184. }
  185. body {
  186. background-color: white;
  187. }
  188. </style>
  189. <style lang='less' scoped>
  190. </style>