uploadVideos.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import {
  2. icommunity
  3. } from '../../../api/api.js';
  4. const app = getApp()
  5. Page({
  6. data: {
  7. article: {
  8. fileType: 2
  9. },
  10. imgUrl: app.globalData.imgUrl,
  11. },
  12. clickUpload() {
  13. let {article} = this.data
  14. if (!article.articleTitle) {
  15. return wx.showToast({
  16. icon: 'loading',
  17. title: '请输入标题'
  18. })
  19. }
  20. if (!article.filePath) {
  21. return wx.showToast({
  22. icon: 'loading',
  23. title: '请添加视频'
  24. })
  25. }
  26. if (!article.coverImage) {
  27. return wx.showToast({
  28. icon: 'loading',
  29. title: '请添加预览图'
  30. })
  31. }
  32. console.log(article);
  33. icommunity.loadPubArticle({reqdata:article}, r => {
  34. wx.showToast({
  35. mask: true,
  36. title: '提交成功',
  37. success() {
  38. setTimeout(wx.navigateBack, 1800)
  39. }
  40. })
  41. })
  42. },
  43. inputTitle(e) {
  44. this.setData({
  45. ['article.articleTitle']: e.detail.value
  46. })
  47. },
  48. inputContent(e) {
  49. this.setData({
  50. ['article.articleContent']: e.detail.value
  51. })
  52. },
  53. clickVideo(e) {
  54. if (e.currentTarget.dataset.t == 'poster') {
  55. this.setData({
  56. poster: false
  57. })
  58. } else {
  59. this.setData({
  60. ['article.video']: false
  61. })
  62. }
  63. },
  64. clickAddimg() {
  65. wx.chooseImage({
  66. count: 1,
  67. success: r => {
  68. icommunity.uploadPics(r.tempFilePaths[0], r => {
  69. wx.showToast({
  70. title: '添加成功'
  71. })
  72. console.log(r);
  73. this.setData({
  74. ['article.coverImage']: r.url
  75. })
  76. })
  77. },
  78. })
  79. },
  80. clickAddvideo() {
  81. wx.chooseVideo({
  82. compressed: false,
  83. success: v => {
  84. icommunity.uploadVideos(v.tempFilePath, r => {
  85. console.log(r);
  86. this.setData({
  87. ['article.filePath']: r.url,
  88. // ['article.video.poster']: {
  89. // url: v.thumbTempFilePath
  90. // }
  91. },()=>{
  92. console.log(this.data.article);
  93. })
  94. // if (v.thumbTempFilePath) {
  95. // icommunity.uploadPics(v.thumbTempFilePath, r => {
  96. // console.log(r);
  97. // this.setData({
  98. // ['article.video.poster']: r
  99. // })
  100. // })
  101. // }
  102. wx.showToast({
  103. title: '添加成功'
  104. })
  105. })
  106. }
  107. })
  108. },
  109. onLoad(args) {},
  110. })