works.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. import httpRequestApi from '../../../utils/APIClient';
  2. import {formatDate} from '../../../utils/util';
  3. Page({
  4. data: {
  5. fullScreenBtn: false,
  6. playBtn: false,
  7. gesture: true,
  8. author: '',
  9. videoSrc: '',
  10. total: '',
  11. authorAvatar: '',
  12. user: [],
  13. inputValue: 'smdx',
  14. replyList: [],
  15. },
  16. onLoad: function (option) {
  17. if (option.title) {
  18. wx.setNavigationBarTitle({
  19. title: option.title //页面标题为路由参数
  20. })
  21. this.setData({
  22. title: option.title,
  23. id: option.id
  24. })
  25. }
  26. let uid = wx.getStorageSync('uid');
  27. this.getWorks(uid, option.id);
  28. },
  29. getWorks: function (uid, id) {
  30. httpRequestApi.getWorksDetail(uid, id).success((res) => {
  31. const others = res.data.data.otherRead;
  32. const author = res.data.data.user;
  33. const works = res.data.data.userRead;
  34. const othersTemp = [];
  35. others.forEach((item) => {
  36. const temp = {};
  37. temp.image = item.user.avatar;
  38. temp.nickName = item.user.wechatName;
  39. othersTemp.push(temp);
  40. });
  41. this.setData({
  42. user: othersTemp,
  43. author: author.wechatName,
  44. authorAvatar: author.avatar,
  45. videoSrc: works.originVideo,
  46. audioSrc: works.audioPath
  47. })
  48. // 设置音频路径
  49. this.innerAudioContext = wx.createInnerAudioContext();
  50. this.innerAudioContext.onError((res) => {
  51. // 播放音频失败的回调
  52. })
  53. this.innerAudioContext.src = this.data.audioSrc; // 这里可以是录音的临时路径
  54. this.getReply();
  55. });
  56. },
  57. videoPlay: function () {
  58. this.innerAudioContext.play();
  59. },
  60. videoEnd: function () {
  61. this.innerAudioContext.stop();
  62. },
  63. videoPause: function () {
  64. this.innerAudioContext.pause();
  65. },
  66. goToReading: function () {
  67. let id = this.data.id;
  68. let title = this.data.title;
  69. wx.navigateTo({
  70. url: `../../main/reading/reading?id=${id}&title=${title}`
  71. })
  72. },
  73. onShareAppMessage: function (res) {
  74. if (res.from === 'button') {
  75. // 来自页面内转发按钮
  76. console.log(res.target)
  77. }
  78. return {
  79. title: '测试',
  80. path: '/pages/social/works/works'
  81. }
  82. },
  83. follow: function () {
  84. let uid = wx.getStorageSync('uid');
  85. let followUid = 2;
  86. httpRequestApi.followUser(uid, followUid).success((res) => {
  87. console.log(res)
  88. });
  89. },
  90. // 去其他用户的作品页
  91. goToOthers: function (e) {
  92. wx.navigateTo({
  93. url: `../../main/reading/reading?id=${id}&title=${title}`
  94. })
  95. },
  96. // 查询回复
  97. getReply: function () {
  98. let uid = wx.getStorageSync('uid');
  99. let columnId = this.data.id;
  100. let pageNo = 1;
  101. let pageSize = 10;
  102. httpRequestApi.getReply(uid, columnId, pageNo, pageSize).success((res) => {
  103. console.log(res.data.data.list);
  104. const replyList = res.data.data.list;
  105. const replyTemp = [];
  106. replyList.forEach((item)=>{
  107. const temp = {};
  108. temp.nickName = item.user.wechatName;
  109. temp.avatar = item.user.avatar;
  110. temp.text = item.detailDesc;
  111. temp.id = item.id;
  112. temp.replyCount=item.replyCount;
  113. temp.time = formatDate(item.gmtCreated,3);
  114. console.log(temp.time)
  115. replyTemp.push(temp);
  116. });
  117. this.setData({
  118. replyList: replyTemp,
  119. total: res.data.data.totalSize
  120. })
  121. });
  122. },
  123. // 打开回复详情页
  124. goToDetail: function (e) {
  125. let id = e.currentTarget.dataset.id;
  126. let count = e.currentTarget.dataset.count;
  127. console.log(e);
  128. wx.navigateTo({
  129. url: `../../social/replyDetail/replyDetail?id=${id}&count=${count}`
  130. })
  131. },
  132. // 绑定输入框内容
  133. inputValue: function (e) {
  134. this.setData({
  135. inputValue: e.detail.value
  136. });
  137. },
  138. // 发布回复
  139. sendHandler: function () {
  140. console.log(this.data.inputValue);
  141. if (this.data.inputValue !== '') {
  142. let uid = wx.getStorageSync('uid');
  143. let data = {
  144. "columnId": this.data.id,
  145. colunmNames: 'what',
  146. "detailDesc": this.data.inputValue
  147. }
  148. httpRequestApi.postReply(uid, data).success(res => {
  149. console.log(res);
  150. });
  151. }
  152. }
  153. })