courseLook.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. import Request from '../common/request.js';
  2. let request = new Request().http
  3. //微信小程序登录
  4. export function loginByMiniApp(data) {
  5. //return request('/course_uniapp/app/wx/miniapp/loginByMa',data,'POST','application/json;charset=UTF-8');
  6. return request('/app/wx/loginByMiniApp',data,'POST','application/json;charset=UTF-8');
  7. }
  8. // 播放错误上报
  9. export function getErrMsg(data) {
  10. return request('/course_uniapp/app/course/wx/h5/getErrMsg', data, 'POST', 'application/x-www-form-urlencoded','https://h5api.his.cdwjyyh.com');
  11. }
  12. // h5课程简介
  13. export function getH5CourseByVideoId(data) {
  14. return request('/course_uniapp/app/course/wx/h5/getH5CourseByVideoId', data, 'GET','','https://h5api.his.cdwjyyh.com');
  15. }
  16. // h5课程详情加问答
  17. export function getH5CourseVideoDetails(data) {
  18. return request('/course_uniapp/app/course/wx/h5/videoDetails', data, 'GET','','https://h5api.his.cdwjyyh.com');
  19. }
  20. // 答题发红包
  21. export function courseAnswer(data) {
  22. return request('/course_uniapp/app/course/wx/h5/courseAnswer', data, 'POST', 'application/json;charset=UTF-8','https://h5api.his.cdwjyyh.com');
  23. }
  24. // 记录看课时间(新)
  25. export function getFinishCourseVideo(data) {
  26. return request('/course_uniapp/app/course/wx/h5/updateWatchDuration', data, 'POST', 'application/json;charset=UTF-8','https://h5api.his.cdwjyyh.com');
  27. }
  28. // 关注客服 是否添加客服
  29. export function getIsAddKf(data) {
  30. return request('/course_uniapp/app/course/wx/h5/isAddKf', data, 'POST', 'application/json;charset=UTF-8','https://h5api.his.cdwjyyh.com');
  31. }
  32. // 流量(缓冲百分比)
  33. export function getInternetTraffic(data) {
  34. return request('/course_uniapp/app/course/wx/h5/getInternetTraffic', data, 'POST', 'application/json;charset=UTF-8','https://h5api.his.cdwjyyh.com');
  35. }
  36. // 每十分钟获得积分
  37. export function getIntegralByH5Video(data) {
  38. return request('/app/course/getIntegralByH5Video', data, 'POST', 'application/json;charset=UTF-8','https://h5api.his.cdwjyyh.com');
  39. }
  40. // 发送奖励
  41. export function sendReward(data) {
  42. return request('/course_uniapp/app/course/wx/h5/sendReward', data, 'POST', 'application/json;charset=UTF-8','https://h5api.his.cdwjyyh.com');
  43. }
  44. // 获取真实链接
  45. export function getRealLink(data) {
  46. return request('/app/course/getRealLink', data, 'GET','','https://h5api.his.cdwjyyh.com');
  47. }
  48. //检查是否有头像以及昵称
  49. export function checkUserInfo(data) {
  50. return request('/course_uniapp/app/user/checkUserInfo',data,'GET','application/json;charset=UTF-8');
  51. }
  52. //更改用户头像以及昵称
  53. export function editUser(data) {
  54. return request('/course_uniapp/app/user/editUser',data,'POST','application/json;charset=UTF-8');
  55. }
  56. // 成为会员
  57. export function registerCourses(data) {
  58. return request('/course_uniapp/companyapp/app/fs/user/beMember',data,'POST','application/json;charset=UTF-8');
  59. }
  60. //获取头像以及昵称信息
  61. export function getusername(data) {
  62. return request('/companyapp/app/wx/h5/mp/userInfo',data,'POST','application/json;charset=UTF-8');
  63. }
  64. //h5授权登录
  65. export function handleFsUserWx(data) {
  66. return request('/course_uniapp/app/wx/h5/mp/handleFsUserWx',data,'POST','application/json;charset=UTF-8');
  67. }
  68. //h5授权登录
  69. export function H5logoinApp(data,type) {
  70. if(type&&type==1) {
  71. return request('/app/wx/h5/mp/courseLoginByMp',data,'POST','application/json;charset=UTF-8');
  72. } else {
  73. return request('/app/wx/h5/mp/loginByMp',data,'POST','application/json;charset=UTF-8');
  74. }
  75. }
  76. //获取弹窗时间
  77. export function getRemainTime(data) {
  78. return request('/course_uniapp/app/course/wx/h5/getRemainTime',data,'POST','application/json;charset=UTF-8');
  79. }
  80. //查询评论
  81. export function getCommentList(data) {
  82. return request('/course_uniapp/app/course/comment/myList',data,'GET','application/json;charset=UTF-8');
  83. }
  84. /** 取首个文件路径(兼容误传数组) */
  85. function _firstPathArg(v) {
  86. if (v == null) return ''
  87. if (typeof v === 'string') return v.trim()
  88. if (Array.isArray(v) && v.length) {
  89. const x = v[0]
  90. return x != null && typeof x === 'string' ? x.trim() : ''
  91. }
  92. return ''
  93. }
  94. /**
  95. * 是否应使用 uni.uploadFile 上传的本地临时路径。
  96. * 注意:微信/uni 下相册临时路径常为 http(s)://tmp/...,若以「是否 http」判断会误判为网络图,导致不走上传、图片未传参。
  97. */
  98. function _isLocalMediaFilePath(p) {
  99. if (p == null || p === '') return false
  100. if (typeof p !== 'string') return false
  101. const s = p.trim()
  102. if (!s) return false
  103. if (/^blob:/i.test(s)) return false
  104. if (/^https?:\/\/tmp\//i.test(s)) return true
  105. if (/^wxfile:\/\//i.test(s)) return true
  106. if (/^file:\/\//i.test(s)) return true
  107. if (/^https?:\/\//i.test(s)) return false
  108. return true
  109. }
  110. function _addCommentWithMediaUploadBaseUrl() {
  111. const base = uni.getStorageSync('requestPath') || 'https://userapp.klbycp.com'
  112. return String(base).replace(/\/$/, '') + '/app/course/comment/addCommentWithMedia'
  113. }
  114. /** courseId、type、content、toUserId 拼到请求路径(query),值均 encodeURIComponent */
  115. function _buildAddCommentWithMediaQuery(d) {
  116. const courseId = encodeURIComponent(d.courseId != null ? String(d.courseId) : '')
  117. const videoId = encodeURIComponent(d.videoId != null ? String(d.videoId) : '')
  118. const type = encodeURIComponent(d.type != null ? String(d.type) : '1')
  119. const content = encodeURIComponent(d.content != null ? String(d.content) : '')
  120. const toUserId = encodeURIComponent(d.toUserId != null ? String(d.toUserId) : '')
  121. return `?courseId=${courseId}&videoId=${videoId}&type=${type}&content=${content}&toUserId=${toUserId}`
  122. }
  123. /**
  124. * 发布评论:业务参数均在 URL query;带本地图/视频时仅 multipart body 传 imageFiles 或 videoFiles
  125. */
  126. export function addCommentWithMedia(data) {
  127. const d = data || {}
  128. const imageArg = _firstPathArg(d.imageFiles)
  129. const videoArg = _firstPathArg(d.videoFiles)
  130. const imagePath = _isLocalMediaFilePath(imageArg) ? imageArg : ''
  131. const videoPath = _isLocalMediaFilePath(videoArg) ? videoArg : ''
  132. if (imagePath || videoPath) {
  133. return new Promise((resolve, reject) => {
  134. const token =
  135. uni.getStorageSync('TOKEN_WEXIN') ||
  136. uni.getStorageSync('AppTokenmini_AutoCourse') ||
  137. ''
  138. // 与 common/request.js 中 uni.request 一致;multipart 的 boundary 由客户端自动带,勿手写 Content-Type
  139. const header = {
  140. AppToken: token
  141. }
  142. try {
  143. if (typeof wx !== 'undefined' && wx.getAccountInfoSync) {
  144. header['appid'] = wx.getAccountInfoSync().miniProgram.appId
  145. }
  146. } catch (e) {}
  147. const filePath = imagePath || videoPath
  148. // 与后端 multipart 字段名一致:imageFiles / videoFiles(Content-Disposition: form-data; name="imageFiles"; filename="...")
  149. const name = imagePath ? 'imageFiles' : 'videoFiles'
  150. const url = _addCommentWithMediaUploadBaseUrl() + _buildAddCommentWithMediaQuery(d)
  151. uni.uploadFile({
  152. url,
  153. filePath,
  154. name,
  155. header,
  156. success: (uploadFileRes) => {
  157. try {
  158. const raw = uploadFileRes.data
  159. const body = typeof raw === 'string' ? JSON.parse(raw) : raw
  160. resolve(body)
  161. } catch (e) {
  162. reject(e)
  163. }
  164. },
  165. fail: (err) => {
  166. reject(err || new Error('发布失败'))
  167. }
  168. })
  169. })
  170. }
  171. const router =
  172. '/course_uniapp/app/course/comment/addCommentWithMedia' + _buildAddCommentWithMediaQuery(d)
  173. return request(router, {}, 'POST')
  174. }