add.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. // 引入 QCloud 小程序增强 SDK
  2. var qcloud = require('../../../../vendor/qcloud-weapp-client-sdk/index');
  3. // 引入配置
  4. var config = require('../../../../config');
  5. // 显示繁忙提示
  6. var showBusy = text => wx.showToast({
  7. title: text,
  8. icon: 'loading',
  9. duration: 10000
  10. });
  11. // 显示成功提示
  12. var showSuccess = text => {
  13. wx.hideToast();
  14. wx.showToast({
  15. title: text,
  16. icon: 'success'
  17. });
  18. };
  19. // 显示失败提示
  20. var showModel = (title, content) => {
  21. wx.hideToast();
  22. wx.showModal({
  23. title,
  24. content: JSON.stringify(content),
  25. showCancel: false
  26. });
  27. };
  28. var showMsg = (title, content) => {
  29. wx.hideToast();
  30. wx.showModal({
  31. title,
  32. content: content,
  33. showCancel: false
  34. });
  35. };
  36. //获取应用实例
  37. var app = getApp()
  38. Page({
  39. data: {
  40. "videoSrc":'',
  41. "busy":false,
  42. "busy1":false,
  43. "busy2":false,
  44. "textarea":false,
  45. "upload_busy":false
  46. },
  47. onLoad: function () {
  48. console.log('onLoad');
  49. app.getUserInfo(function(userInfo){
  50. console.log(userInfo);
  51. });
  52. this.chooseVideo();
  53. },
  54. onShow: function () {
  55. console.log('onShow');
  56. },
  57. chooseVideo: function() {
  58. var self = this;
  59. if(self.data.upload_busy){
  60. return;
  61. }
  62. wx.chooseVideo({
  63. sourceType: ['album','camera'],
  64. maxDuration: 60,
  65. success: function(res) {
  66. console.log('chooseVideo success, temp path is', res.tempFilePath)
  67. console.log(res);
  68. if(res.size>50*1024*1000){
  69. showMsg('提示信息','视频大小不能大于50M');
  70. return;
  71. }
  72. var videoSrc = res.tempFilePath;
  73. self.setData({
  74. 'upload_busy':true,
  75. 'videoSrc':""
  76. })
  77. //上传图片到服务器
  78. wx.uploadFile({
  79. url: config.service.uploadUrl,
  80. filePath: videoSrc,
  81. name: 'file',
  82. success: function(res) {
  83. if(res.statusCode==200){
  84. var data=JSON.parse(res.data);
  85. console.log(data);
  86. if(data.success==true){
  87. self.setData({
  88. 'videoSrc':data.file.url,
  89. 'videoContext':wx.createVideoContext('myVideo')
  90. })
  91. showSuccess('上传成功');
  92. }else{
  93. showMsg('提示信息','上传失败');
  94. }
  95. }else if(res.statusCode==413){
  96. showMsg('提示信息','上传失败,文件过大');
  97. }else{
  98. showMsg('提示信息','上传失败');
  99. }
  100. },
  101. fail: function({errMsg}) {
  102. console.log('uploadVideo fail, errMsg is', errMsg);
  103. showMsg('提示信息','上传失败,'+errMsg);
  104. },
  105. complete:function(){
  106. self.setData({
  107. 'upload_busy':false
  108. })
  109. }
  110. })
  111. },
  112. fail: function({errMsg}) {
  113. console.log('chooseVideo fail, err is', errMsg)
  114. }
  115. })
  116. },
  117. formSubmit1: function(e) {
  118. // console.log(e);
  119. var self = this;
  120. if(self.data.upload_busy||self.data.busy1){
  121. return;
  122. }
  123. if(self.data.videoSrc==""){
  124. showMsg("提示信息","请先上传视频");
  125. return;
  126. }
  127. var data={};
  128. if(self.data.videoSrc!=""){
  129. data.image_url=self.data.videoSrc;
  130. }
  131. if(e.detail.formId!='the formId is a mock one'){
  132. data.form_id=e.detail.formId;
  133. }
  134. data.type=3
  135. data.is_qun=1
  136. self.setData({
  137. 'busy1':true
  138. })
  139. qcloud.request({
  140. // 要请求的地址
  141. url: config.service.messageAddUrl,
  142. method:"POST",
  143. data: data,
  144. success(result) {
  145. console.log(result);
  146. if(result.data.success==true){
  147. showSuccess("成功");
  148. self.data.videoContext.pause();
  149. wx.navigateTo({
  150. url: '/pages/person/video/view/view?hash_key='+result.data.id
  151. })
  152. }else{
  153. showMsg("提示信息","新建消息失败,"+result.data.message);
  154. }
  155. },
  156. fail(error) {
  157. console.log('request fail', error);
  158. showMsg("提示信息","新建消息失败");
  159. },
  160. complete() {
  161. self.setData({
  162. 'busy1':false
  163. })
  164. console.log('request complete');
  165. }
  166. });
  167. },
  168. formSubmit2: function(e) {
  169. // console.log(e);
  170. var self = this;
  171. if(self.data.upload_busy||self.data.busy2){
  172. return;
  173. }
  174. if(self.data.videoSrc==""){
  175. showMsg("提示信息","请先上传视频");
  176. return;
  177. }
  178. var data={};
  179. if(self.data.videoSrc!=""){
  180. data.image_url=self.data.videoSrc;
  181. }
  182. if(e.detail.formId!='the formId is a mock one'){
  183. data.form_id=e.detail.formId;
  184. }
  185. data.type=3
  186. data.is_qun=0
  187. self.setData({
  188. 'busy2':true
  189. })
  190. qcloud.request({
  191. // 要请求的地址
  192. url: config.service.messageAddUrl,
  193. method:"POST",
  194. data: data,
  195. success(result) {
  196. console.log(result);
  197. if(result.data.success==true){
  198. showSuccess("成功");
  199. self.data.videoContext.pause();
  200. wx.navigateTo({
  201. url: '/pages/person/video/view/view?hash_key='+result.data.id
  202. })
  203. }else{
  204. showMsg("提示信息","新建消息失败,"+result.data.message);
  205. }
  206. },
  207. fail(error) {
  208. console.log('request fail', error);
  209. showMsg("提示信息","新建消息失败");
  210. },
  211. complete() {
  212. self.setData({
  213. 'busy2':false
  214. })
  215. console.log('request complete');
  216. }
  217. });
  218. }
  219. })