releaseVideo.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. <template>
  2. <view>
  3. <!-- <u-sticky offsetTop="0" customNavHeight="0" zIndex="999">
  4. <view class="content-header-sticky x-c">
  5. <image class="bg-img" src="/static/image/home/home_top_bg.png" style="z-index: -1;"></image>
  6. <uni-icons type="left" size="26" color="#fff" class="backicon" @click="$navBack()"></uni-icons>
  7. <text class="textOne" style="width: 50%;text-align: center;color: #fff;">编辑视频信息</text>
  8. </view>
  9. </u-sticky>
  10. <image class="bg-img" src="/static/image/home/home_top_bg.png"></image> -->
  11. <bgNavBar title="编辑视频信息"></bgNavBar>
  12. <view class="videobox x-c">
  13. <video v-if="fileList1.length>0" :src="fileList1[0].url" :poster="fileList1[0].thumbnailUrl"
  14. :autoplay='true' class="video"></video>
  15. <view class="closeempty" v-if="fileList1.length>0" @click="deletePic($event,'myevent')"><uni-icons
  16. type="trash" size="28" color="red"></uni-icons></view>
  17. <view v-else>
  18. <u-upload :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" name="1" multiple
  19. :maxCount="1" accept="video">
  20. <view class="uploadbox">
  21. <uni-icons type="plusempty" size="30"></uni-icons>
  22. <text>上传视频</text>
  23. </view>
  24. </u-upload>
  25. </view>
  26. </view>
  27. <view style="position: relative;">
  28. <view class="es-pl-24 es-pr-24 es-pt-24 es-pb-24">
  29. <view class="box es-br-24 es-mb-24">
  30. <view class="box-title x-bc">
  31. <text class="name">分区或标签</text>
  32. <uni-icons type="right" size="16" color="#222"></uni-icons>
  33. </view>
  34. <view class="tags">
  35. <u-tag
  36. v-for="i in 5"
  37. text="中医药"
  38. closable
  39. color="#666"
  40. bgColor="#ffe8dc"
  41. borderColor="#ffe8dc"
  42. :show="true"
  43. @close="close1 = false"
  44. ></u-tag>
  45. </view>
  46. </view>
  47. <view class="box es-br-24 es-mb-24">
  48. <view class="box-title x-bc es-mb-24">
  49. <text class="name">标题</text>
  50. <uni-icons type="right" size="16" color="#222"></uni-icons>
  51. </view>
  52. <u--input placeholder="请输入标题" border="none" v-model.trim="form.title" clearable
  53. maxlength="50"></u--input>
  54. </view>
  55. <view class="box es-br-24">
  56. <view class="box-title x-bc es-mb-24">
  57. <text class="name">描述</text>
  58. <uni-icons type="right" size="16" color="#222"></uni-icons>
  59. </view>
  60. <u--textarea v-model.trim="form.description" border="none" autoHeight placeholder="介绍你的视频,让更多人了解你的作品"
  61. maxlength="300"></u--textarea>
  62. </view>
  63. <view class="footer-btn">
  64. <view @click="submit">发布</view>
  65. </view>
  66. </view>
  67. </view>
  68. </view>
  69. </template>
  70. <script>
  71. import bgNavBar from "./components/bgNavBar.vue"
  72. import { navBack } from "../../utils/common";
  73. import { uploadOSSTalent,talentVideo } from "@/api/expert.js"
  74. export default {
  75. components: {
  76. bgNavBar
  77. },
  78. data() {
  79. return {
  80. current: 1,
  81. interval: 3000,
  82. duration: 1000,
  83. autoplay: true,
  84. advImgs: [{}],
  85. form: {
  86. duration: null,
  87. url: '',
  88. thumbnailUrl: '',
  89. title: '',
  90. description: ''
  91. },
  92. value: '',
  93. value1: '',
  94. videoUrl: '',
  95. thumbnail: '',
  96. fileList1: [],
  97. }
  98. },
  99. onLoad() {
  100. this.uploadVideo()
  101. },
  102. methods: {
  103. uploadVideo() {
  104. let self = this
  105. // #ifdef APP-PLUS
  106. if (!plus.runtime.isAgreePrivacy()) {
  107. uni.showToast({
  108. title: "请同意隐私政策",
  109. icon: "none"
  110. });
  111. return;
  112. }
  113. // #endif
  114. uni.chooseVideo({
  115. sourceType: ['album'],
  116. success: async (res) => {
  117. const result = await this.uploadFilePromise(res.tempFilePath)
  118. this.fileList1 = [{
  119. url: result.url,
  120. thumbnailUrl: result.thumbnailUrl,
  121. duration: result.videoInfo.duration
  122. }]
  123. }
  124. });
  125. },
  126. submit() {
  127. if(this.fileList1.length==0) {
  128. uni.showToast({
  129. title: "请上传视频",
  130. icon: "none"
  131. })
  132. return
  133. }
  134. if(!this.form.title.trim()) {
  135. uni.showToast({
  136. title: "请输入标题",
  137. icon: "none"
  138. })
  139. return
  140. }
  141. if(!this.form.description.trim()) {
  142. uni.showToast({
  143. title: "请输入描述",
  144. icon: "none"
  145. })
  146. return
  147. }
  148. const form = {
  149. title: this.form.title,
  150. description: this.form.description,
  151. url: this.fileList1[0].url,
  152. thumbnail: this.fileList1[0].thumbnailUrl,
  153. duration: this.fileList1[0].duration,
  154. tags: '中医药'
  155. }
  156. uni.showLoading({
  157. title: '发布中',
  158. })
  159. talentVideo(form).then(res=>{
  160. uni.hideLoading()
  161. if(res.code == 200) {
  162. uni.showToast({
  163. title: '发布成功,待管理员审核',
  164. icon: 'none'
  165. })
  166. setTimeout(()=>{
  167. this.$navBack()
  168. },1500)
  169. }
  170. }).catch(()=>{
  171. uni.hideLoading()
  172. })
  173. },
  174. deletePic(event, type) {
  175. if (type == 'myevent') {
  176. this.fileList1.splice(0, 1)
  177. } else {
  178. this[`fileList${event.name}`].splice(event.index, 1)
  179. }
  180. },
  181. async afterRead(event) {
  182. // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
  183. let lists = [].concat(event.file)
  184. let fileListLen = this[`fileList${event.name}`].length
  185. lists.map((item) => {
  186. this[`fileList${event.name}`].push({
  187. ...item,
  188. status: 'uploading',
  189. message: '上传中'
  190. })
  191. })
  192. for (let i = 0; i < lists.length; i++) {
  193. const result = await this.uploadFilePromise(lists[i].url)
  194. let item = this[`fileList${event.name}`][fileListLen]
  195. this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
  196. status: 'success',
  197. message: '',
  198. url: result.url,
  199. thumbnailUrl: result.thumbnailUrl,
  200. duration: result.videoInfo.duration
  201. }))
  202. fileListLen++
  203. }
  204. },
  205. uploadFilePromise(url) {
  206. return new Promise((resolve, reject) => {
  207. uni.showLoading({
  208. title: '上传中',
  209. })
  210. let a = uni.uploadFile({
  211. url: uni.getStorageSync('requestPath') +
  212. '/app/talent/uploadOSSTalent', // 仅为示例,非真实的接口地址
  213. filePath: url,
  214. name: 'file',
  215. success: (res) => {
  216. resolve(JSON.parse(res.data))
  217. },
  218. fail: (err) => {
  219. uni.showToast({
  220. title: '上传视频失败',
  221. icon: 'error'
  222. })
  223. },
  224. complete: () => {
  225. uni.hideLoading()
  226. }
  227. });
  228. })
  229. },
  230. }
  231. }
  232. </script>
  233. <style scoped lang="scss">
  234. @mixin u-flex($flexD, $alignI, $justifyC) {
  235. display: flex;
  236. flex-direction: $flexD;
  237. align-items: $alignI;
  238. justify-content: $justifyC;
  239. }
  240. .videobox {
  241. width: 694rpx;
  242. height: 390rpx;
  243. margin: 0 auto 16rpx auto;
  244. border-radius: 20rpx;
  245. overflow: hidden;
  246. position: relative;
  247. background-color: #fff;
  248. .video {
  249. width: 694rpx;
  250. height: 390rpx;
  251. border-radius: 20rpx;
  252. overflow: hidden;
  253. }
  254. .closeempty {
  255. position: absolute;
  256. z-index: 99;
  257. right: 0;
  258. top: 0;
  259. background-color: #fff;
  260. border-radius: 0 20rpx 0 20rpx;
  261. }
  262. }
  263. .uploadbox {
  264. width: 200rpx;
  265. height: 200rpx;
  266. @include u-flex(column, center, center);
  267. }
  268. .box {
  269. padding: 24rpx;
  270. background-color: #fff;
  271. font-family: PingFang SC, PingFang SC;
  272. font-weight: 500;
  273. font-size: 34rpx;
  274. color: #222222;
  275. }
  276. .tags {
  277. @include u-flex(row, center, flex-start);
  278. flex-wrap: wrap;
  279. font-family: PingFang SC, PingFang SC;
  280. font-weight: 400;
  281. font-size: 24rpx;
  282. color: #555;
  283. }
  284. .footer-btn {
  285. @include u-flex(row, center, center);
  286. font-family: PingFang SC, PingFang SC;
  287. margin-top: 60rpx;
  288. view {
  289. width: 602rpx;
  290. height: 88rpx;
  291. background: #FF5C03;
  292. border-radius: 26rpx;
  293. font-family: PingFang SC, PingFang SC;
  294. font-weight: 600;
  295. font-size: 32rpx;
  296. color: #FFFFFF;
  297. @include u-flex(row, center, center);
  298. }
  299. }
  300. </style>