releaseVideo.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. <template>
  2. <view>
  3. <bgNavBar title="编辑视频信息"></bgNavBar>
  4. <view class="videobox x-c">
  5. <video v-if="fileList1.length>0" :src="fileList1[0].url" :poster="fileList1[0].thumbnailUrl"
  6. :autoplay='true' class="video">
  7. <cover-view class="closeempty" v-if="fileList1.length>0">
  8. <cover-image class="closeempty-img" src="/static/images/del.png" @click="deletePic($event,'myevent')"></cover-image>
  9. </cover-view></video>
  10. <view v-else>
  11. <u-upload :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" name="1" multiple
  12. :maxCount="1" accept="video">
  13. <view class="uploadbox" v-if="!loading">
  14. <uni-icons type="plusempty" size="30"></uni-icons>
  15. <text>上传视频</text>
  16. </view>
  17. <view class="uploadbox" v-else>
  18. <u-loading-icon></u-loading-icon>
  19. <text style="color: #999;">上传中...</text>
  20. </view>
  21. </u-upload>
  22. </view>
  23. </view>
  24. <view style="position: relative;">
  25. <view class="es-pl-24 es-pr-24 es-pt-24 es-pb-24">
  26. <view class="box es-br-24 es-mb-24">
  27. <view class="box-title x-bc" @click="showPop">
  28. <text class="name">分区或标签</text>
  29. <uni-icons type="right" size="16" color="#222"></uni-icons>
  30. </view>
  31. <view class="tags">
  32. <u-tag v-for="(tag,index) in chooseTagList" :key="index" :text="tag.label" closable
  33. color="#2583EB" bgColor="#ffe8dc" borderColor="#ffe8dc" :show="tag.checked"
  34. @close="closeTag(index)"></u-tag>
  35. </view>
  36. </view>
  37. <view class="box es-br-24 es-mb-24">
  38. <view class="box-title x-bc es-mb-24">
  39. <text class="name">标题</text>
  40. </view>
  41. <u--input placeholder="请输入标题" border="none" v-model.trim="form.title" clearable
  42. maxlength="50"></u--input>
  43. </view>
  44. <view class="box es-br-24">
  45. <view class="box-title x-bc es-mb-24">
  46. <text class="name">描述</text>
  47. </view>
  48. <u--textarea v-model.trim="form.description" border="none" autoHeight
  49. placeholder="介绍你的视频,让更多人了解你的作品" maxlength="300"></u--textarea>
  50. </view>
  51. <view class="footer-btn">
  52. <view @click="submit">发布</view>
  53. </view>
  54. </view>
  55. </view>
  56. <u-popup :show="show" mode="bottom" closeable :round="16" @close="close">
  57. <view class="tagpop">
  58. <view class="tagpop-title">选择标签</view>
  59. <view class="tagpop-box">
  60. <scroll-view scroll-y="true" style="height: 50vh;">
  61. <view v-for="(item,index) in tags" :key="index" class="tag-group">
  62. <view class="tag-label">{{ item.label }}</view>
  63. <view class="child-label-box">
  64. <u-tag class="child-label" v-for="(it,idx) in item.children" :key="idx" :text="it.label"
  65. :color="it.checked?'#2583EB':'#666'" :bgColor="it.checked?'#ffe8dc':'#fff'"
  66. :borderColor="it.checked?'#ffe8dc':'#eee'" @click="chooseTag(index,idx)"></u-tag>
  67. </view>
  68. </view>
  69. </scroll-view>
  70. </view>
  71. </view>
  72. </u-popup>
  73. <!-- <tagpop ref="tagpop"></tagpop> -->
  74. </view>
  75. </template>
  76. <script>
  77. // import tagpop from "./components/tagpop.nvue"
  78. import bgNavBar from "./components/bgNavBar.vue"
  79. import {
  80. navBack
  81. } from "../../utils/common";
  82. import {
  83. uploadOSSTalent,
  84. talentVideo,
  85. getTag
  86. } from "@/api/expert.js"
  87. export default {
  88. components: {
  89. bgNavBar,
  90. // tagpop
  91. },
  92. data() {
  93. return {
  94. current: 1,
  95. interval: 3000,
  96. duration: 1000,
  97. autoplay: true,
  98. advImgs: [{}],
  99. form: {
  100. duration: null,
  101. url: '',
  102. thumbnailUrl: '',
  103. title: '',
  104. description: ''
  105. },
  106. value: '',
  107. value1: '',
  108. videoUrl: '',
  109. thumbnail: '',
  110. fileList1: [],
  111. tags: [],
  112. chooseTagList: [],
  113. show: false,
  114. loading: false
  115. }
  116. },
  117. onLoad() {
  118. // #ifdef APP-PLUS
  119. const subNVue = uni.getSubNVueById('tagpop');
  120. subNVue.hide('slide-out-bottom');
  121. // #endif
  122. uni.$on("chooseTag",data=>{
  123. this.tags = data
  124. this.chooseTagList = this.findCheckedItems(this.tags)
  125. })
  126. this.uploadVideo()
  127. // #ifndef APP-PLUS
  128. this.getTags()
  129. // #endif
  130. },
  131. onUnload() {
  132. uni.$off("chooseTag")
  133. },
  134. methods: {
  135. showPop() {
  136. // #ifndef APP-PLUS
  137. this.show = true
  138. // #endif
  139. // #ifdef APP-PLUS
  140. const subNVue = uni.getSubNVueById('tagpop');
  141. subNVue.show('slide-in-bottom', 250);
  142. // #endif
  143. },
  144. close() {
  145. this.show = false
  146. this.chooseTagList = this.findCheckedItems(this.tags)
  147. },
  148. findCheckedItems(tags) {
  149. let checkedItems = [];
  150. // 遍历tags数组
  151. tags.forEach(tag => {
  152. // 如果当前标签的children存在且有checked为true的item
  153. if (tag.children) {
  154. tag.children.forEach(child => {
  155. if (child.checked) {
  156. checkedItems.push(child); // 将符合条件的item加入数组
  157. }
  158. });
  159. }
  160. });
  161. return checkedItems;
  162. },
  163. closeTag(index) {
  164. this.chooseTagList[index].checked = false
  165. },
  166. chooseTag(index, idx) {
  167. this.tags[index].children[idx].checked = !this.tags[index].children[idx].checked
  168. },
  169. uploadVideo() {
  170. let self = this
  171. // #ifdef APP-PLUS
  172. if (!plus.runtime.isAgreePrivacy()) {
  173. uni.showToast({
  174. title: "请同意隐私政策",
  175. icon: "none"
  176. });
  177. return;
  178. }
  179. // #endif
  180. uni.chooseVideo({
  181. sourceType: ['album'],
  182. success: async (res) => {
  183. const result = await this.uploadFilePromise(res.tempFilePath)
  184. this.fileList1 = [{
  185. url: result.url,
  186. thumbnailUrl: result.thumbnailUrl,
  187. duration: result.videoInfo.duration
  188. }]
  189. }
  190. });
  191. },
  192. getTags() {
  193. getTag().then(res => {
  194. if (res.code == 200) {
  195. this.tags = res.data || []
  196. this.tags = this.addCheckedProperty(this.tags)
  197. }
  198. })
  199. },
  200. addCheckedProperty(tags) {
  201. return tags.map(tag => {
  202. // 为当前对象添加checked属性
  203. const updatedTag = {
  204. ...tag,
  205. checked: false
  206. };
  207. // 如果有子对象,递归处理
  208. if (updatedTag.children) {
  209. updatedTag.children = this.addCheckedProperty(updatedTag.children);
  210. }
  211. return updatedTag;
  212. });
  213. },
  214. submit() {
  215. if (this.fileList1.length == 0) {
  216. uni.showToast({
  217. title: "请上传视频",
  218. icon: "none"
  219. })
  220. return
  221. }
  222. let arry = this.chooseTagList.filter(item=>item.checked)
  223. let tags = []
  224. if(arry&&arry.length>0) {
  225. tags = arry.map(it=>it.value)
  226. }
  227. if (!this.form.title.trim()) {
  228. uni.showToast({
  229. title: "请输入标题",
  230. icon: "none"
  231. })
  232. return
  233. }
  234. if (!this.form.description.trim()) {
  235. uni.showToast({
  236. title: "请输入描述",
  237. icon: "none"
  238. })
  239. return
  240. }
  241. const form = {
  242. title: this.form.title,
  243. description: this.form.description,
  244. url: this.fileList1[0].url,
  245. thumbnail: this.fileList1[0].thumbnailUrl,
  246. duration: this.fileList1[0].duration,
  247. tags: tags.join(',')
  248. }
  249. uni.showLoading({
  250. title: '发布中',
  251. })
  252. talentVideo(form).then(res => {
  253. uni.hideLoading()
  254. if (res.code == 200) {
  255. uni.showToast({
  256. title: '发布成功,待管理员审核',
  257. icon: 'none'
  258. })
  259. uni.$emit("resetData")
  260. setTimeout(() => {
  261. this.$navBack()
  262. }, 1500)
  263. }
  264. }).catch(() => {
  265. uni.hideLoading()
  266. })
  267. },
  268. deletePic(event, type) {
  269. uni.hideToast()
  270. if (type == 'myevent') {
  271. this.fileList1.splice(0, 1)
  272. } else {
  273. this[`fileList${event.name}`].splice(event.index, 1)
  274. }
  275. },
  276. async afterRead(event) {
  277. // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
  278. let lists = [].concat(event.file)
  279. let fileListLen = this[`fileList${event.name}`].length
  280. lists.map((item) => {
  281. this[`fileList${event.name}`].push({
  282. ...item,
  283. status: 'uploading',
  284. message: '上传中'
  285. })
  286. })
  287. for (let i = 0; i < lists.length; i++) {
  288. const result = await this.uploadFilePromise(lists[i].url)
  289. if (result.code != 200) {
  290. uni.showToast({
  291. title: '上传视频失败',
  292. icon: 'error'
  293. })
  294. return
  295. }
  296. let item = this[`fileList${event.name}`][fileListLen]
  297. this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
  298. status: 'success',
  299. message: '',
  300. url: result.url,
  301. thumbnailUrl: result.thumbnailUrl,
  302. duration: result.videoInfo.duration
  303. }))
  304. fileListLen++
  305. }
  306. },
  307. uploadFilePromise(url) {
  308. return new Promise((resolve, reject) => {
  309. uni.showLoading({
  310. title: '上传中',
  311. })
  312. this.loading = true
  313. let a = uni.uploadFile({
  314. url: uni.getStorageSync('requestPath') +
  315. '/app/talent/uploadOSSTalent', // 仅为示例,非真实的接口地址
  316. filePath: url,
  317. name: 'file',
  318. success: (res) => {
  319. resolve(JSON.parse(res.data))
  320. },
  321. fail: (err) => {
  322. uni.showToast({
  323. title: '上传视频失败',
  324. icon: 'error'
  325. })
  326. },
  327. complete: () => {
  328. uni.hideLoading()
  329. this.loading = false
  330. }
  331. });
  332. })
  333. }
  334. }
  335. }
  336. </script>
  337. <style scoped lang="scss">
  338. @mixin u-flex($flexD, $alignI, $justifyC) {
  339. display: flex;
  340. flex-direction: $flexD;
  341. align-items: $alignI;
  342. justify-content: $justifyC;
  343. }
  344. .tagpop {
  345. background-color: #fff;
  346. overflow: hidden;
  347. border-radius: 16rpx 16rpx 0 0;
  348. padding: 24rpx;
  349. &-title {
  350. text-align: center;
  351. }
  352. .tag-group {
  353. // background-color: #ffffff;
  354. // border: 1px solid #ddd;
  355. // margin-bottom: 10px;
  356. // padding: 10px;
  357. // border-radius: 5px;
  358. }
  359. .tag-label {
  360. font-size: 16px;
  361. font-weight: bold;
  362. margin-bottom: 5px;
  363. // background-color: #f7f7f7;
  364. }
  365. .child-label-box {
  366. @include u-flex(row, center, flex-start);
  367. flex-wrap: wrap;
  368. }
  369. .child-label {
  370. margin: 0 16rpx 16rpx 0;
  371. }
  372. }
  373. .video {
  374. width: 694rpx;
  375. height: 390rpx;
  376. border-radius: 20rpx;
  377. overflow: hidden;
  378. }
  379. .videobox {
  380. width: 694rpx;
  381. height: 390rpx;
  382. margin: 32rpx auto 16rpx auto;
  383. border-radius: 20rpx;
  384. overflow: hidden;
  385. position: relative;
  386. background-color: #fff;
  387. .closeempty {
  388. position: absolute;
  389. z-index: 99;
  390. right: 0;
  391. top: 0;
  392. background-color: #fff;
  393. border-radius: 0 20rpx 0 20rpx;
  394. padding: 10rpx;
  395. .closeempty-img {
  396. width: 40rpx;
  397. height: 40rpx;
  398. }
  399. }
  400. }
  401. .uploadbox {
  402. width: 200rpx;
  403. height: 200rpx;
  404. @include u-flex(column, center, center);
  405. text {
  406. margin-top: 16rpx;
  407. }
  408. }
  409. .box {
  410. padding: 24rpx;
  411. background-color: #fff;
  412. font-family: PingFang SC, PingFang SC;
  413. font-weight: 500;
  414. font-size: 34rpx;
  415. color: #222222;
  416. }
  417. .tags {
  418. @include u-flex(row, center, flex-start);
  419. flex-wrap: wrap;
  420. font-family: PingFang SC, PingFang SC;
  421. font-weight: 400;
  422. font-size: 24rpx;
  423. color: #555;
  424. }
  425. .footer-btn {
  426. @include u-flex(row, center, center);
  427. font-family: PingFang SC, PingFang SC;
  428. margin-top: 60rpx;
  429. view {
  430. width: 602rpx;
  431. height: 88rpx;
  432. background: #2583EB;
  433. border-radius: 26rpx;
  434. font-family: PingFang SC, PingFang SC;
  435. font-weight: 600;
  436. font-size: 32rpx;
  437. color: #FFFFFF;
  438. @include u-flex(row, center, center);
  439. }
  440. }
  441. </style>