addVideo.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. <style>
  2. .plusForm div.btn {padding: 0px;}
  3. .plusForm .content div{margin-bottom: 0px;}
  4. #filePicker>.webuploader-pick,#fileVideo>.webuploader-pick{background: none; color: #000000; padding: 0px; height: 29px; line-height: 29px; width: 98px; border: none;}
  5. .progress{height: 30px; position: relative; display: none;}
  6. .schedule{float: right;}
  7. .totalProgress{height: 11px; background-color: #F0F0F0; border-radius: 11px;}
  8. .complete{width: 0%; height: 11px; position: absolute; left: 0px; top: 14px; background-color: #03C501; border-radius: 11px;}
  9. </style>
  10. <div class="plusForm photo">
  11. <div>
  12. <div class="title">Add Video Shot</div>
  13. <div class="close"><a href="javascript:;"><img src="<%=public_path%>/img/close-btn.png" alt=""/></a></div>
  14. </div>
  15. <div class="content">
  16. <div>Video cover <label>(PNG, JPEG and JPG format only, less than 6MB. Image size must be between 640 * 640 pixel and 6000 * 6000 pixel.)</label></div>
  17. <input class="uploadFile" id="uploadFile" disabled="disabled" style="background: none;" placeholder=""/>
  18. <div class="fileUpload btn btn-primary">
  19. <div id="filePicker">Video cover</div>
  20. <input type="hidden" name="img" value="">
  21. </div>
  22. <div>Video <label>(MP4 format only, less than 30MB. Recommended duration and pixel are 8 to 15 seconds and 640 to 1700 pixel.)</label></div>
  23. <input class="uploadFile" id="uploadVideo" disabled="disabled" style="background: none;" placeholder="">
  24. <div class="fileUpload btn btn-primary">
  25. <div id="fileVideo">Browse video</div>
  26. <input type="hidden" name="video" value="">
  27. </div>
  28. <div>
  29. <div>Description <label>(48 - 140 characters.)</label></div>
  30. <textarea name="paragraph" maxlength="140" placeholder="" style="width: 488px; height:100px; resize: none;"></textarea>
  31. <div class="tips" style="float: right;"><label id="descriptionNumber" style="color: red;">0</label> / 140</div>
  32. <div class="clear"></div>
  33. </div>
  34. <div style="margin-bottom: 15px;">
  35. <div>Appear to profile page:</div>
  36. <select name="is_show_profile" style="width: 209px;">
  37. <option value="1">Yes</option>
  38. <option value="0">No</option>
  39. </select>
  40. </div>
  41. <div class="progress" style="margin-bottom: 5px;">
  42. <div>Upload progress<span class="schedule">0%</span></div>
  43. <div class="totalProgress"></div>
  44. <div class="complete"></div>
  45. </div>
  46. <button class="Submit cursor">Submit</button>
  47. </div>
  48. </div>
  49. <script>
  50. $(function(){
  51. $('textarea[name="paragraph"]').on('input', function(){
  52. let description = $(this).val();
  53. $('#descriptionNumber').text(description.length);
  54. })
  55. var anchor_video_key = '';
  56. var server = '';
  57. //创建文件上传
  58. var uploader_video = WebUploader.create({
  59. auto: true,
  60. fileSingleSizeLimit: 1024*1024*30,//视频最大可以上传30M
  61. swf: '<%=public_path%>' + '/js/webuploader/Uploader.swf',
  62. server: server,
  63. pick: '#fileVideo',
  64. resize: false,
  65. timeout: 30 * 60 * 1000,
  66. accept: {
  67. title: 'Video',
  68. extensions: 'mp4',
  69. mimeTypes: 'video/mp4'
  70. },
  71. compress: null
  72. });
  73. /**
  74. * 上传前设置参数
  75. */
  76. uploader_video.on( 'startUpload', function() {
  77. anchor_video_key = getCodeKey();
  78. server = '<%=url%>/AnchorVideoUpload/AnchorVideoServlet.htm?siteID=8&anchorID=<%=userInfo.id%>&agentID=<%=anchorInfo.agency_id%>&anchor_video_key='+anchor_video_key+'&video_type=1';
  79. uploader_video.options.server = server;
  80. });
  81. // 文件上传中
  82. var uploadVideo = 0;//防止重复提示
  83. var loadVideo = '';
  84. uploader_video.on( 'uploadProgress', function( file, percentage ) {
  85. $('.progress').show();
  86. parent.layer.iframeAuto(index);
  87. $('.schedule').text(parseInt(percentage*100)+'%');
  88. $('.complete').css('width',parseInt(percentage*100)+'%');
  89. if (!uploadVideo) {
  90. loadVideo = layer.load(2);
  91. }
  92. uploadVideo = 1//等于1表示上传动作已经开启
  93. });
  94. //文件上传成功
  95. uploader_video.on( 'uploadSuccess', function( file, response) {
  96. uploader_video.removeFile( file );//从队列中移除上传的文件,以便可以重复上传
  97. uploadVideo =0;//重置开关
  98. layer.close(loadVideo);
  99. $('.progress').hide();
  100. if(response._raw){
  101. $('#uploadVideo').val(file.name);
  102. $('input[name="video"]').val(anchor_video_key);
  103. }else{
  104. myParentAlert("Failed to upload. Please try again.");
  105. }
  106. });
  107. //文件上传失败
  108. uploader_video.on( 'uploadError', function( file , reason) {
  109. uploadVideo = 0;//重置开关
  110. layer.close(loadVideo);
  111. $('.progress').hide();
  112. if(reason == 'timeout'){
  113. myParentAlert("Could not upload video. The process has timed out.");
  114. }else{
  115. myParentAlert("Failed to upload. Please try again.");
  116. }
  117. });
  118. //文件错误提示
  119. uploader_video.on("error", function (type) {
  120. $('.progress').hide();
  121. if(type == "Q_TYPE_DENIED"){
  122. myParentAlert("Only MP4 format allowed for video file.");
  123. }
  124. if(type == "F_EXCEED_SIZE"){
  125. myParentAlert("The file size can not larger than 30M.");
  126. }
  127. });
  128. //创建图片上传
  129. var uploader = WebUploader.create({
  130. auto: true,
  131. fileSingleSizeLimit: 1024*1024*6,
  132. swf: '<%=public_path%>' + '/js/webuploader/Uploader.swf',
  133. server: '<%=server_host%>/api/?act=uploadDynamicImg',
  134. pick: '#filePicker',
  135. accept: {
  136. title: 'Images',
  137. extensions: 'jpg,jpeg,png',
  138. mimeTypes: 'image/jpg,image/jpeg,image/png'
  139. },
  140. compress: null
  141. });
  142. // 图片上传中
  143. var uploadProgress = 0;//防止重复提示
  144. var load = '';
  145. uploader.on( 'uploadProgress', function( file, percentage ) {
  146. $('.progress').show();
  147. parent.layer.iframeAuto(index);
  148. $('.schedule').text(parseInt(percentage*100)+'%');
  149. $('.complete').css('width',parseInt(percentage*100)+'%');
  150. if (!uploadProgress) {
  151. load = layer.load(2);
  152. }
  153. uploadProgress = 1//等于1表示不上传动作已经开启
  154. });
  155. //图片上传成功
  156. uploader.on( 'uploadSuccess', function( file, response) {
  157. $('.progress').hide();
  158. if(response.errno == 13){
  159. myParentAlert("The image size must be larger than 640px(width) * 640px(height).");
  160. }
  161. if(response.errno == 14){
  162. myParentAlert("The photo resolution can not be larger than 6000 * 6000.");
  163. }
  164. uploader.removeFile( file );//从队列中移除上传的文件,以便可以重复上传
  165. if(response.errno == 0){
  166. $('#uploadFile').val(file.name);
  167. $('input[name="img"]').val(response.data.url);
  168. }
  169. uploadProgress =0;//重置开关
  170. layer.close(load);
  171. });
  172. //图片上传失败
  173. uploader.on( 'uploadError', function( file ) {
  174. $('.progress').hide();
  175. uploadProgress = 0;//重置开关
  176. layer.close(load);
  177. myParentAlert("Failed to upload. Please try again.");
  178. });
  179. //错误提示
  180. uploader.on("error", function (type) {
  181. $('.progress').hide();
  182. if(type == "Q_TYPE_DENIED"){
  183. myParentAlert("Incorrect format. Only JPG, JPEG and PNG format allowed. File size must be 6M or less.");
  184. }
  185. if(type == "F_EXCEED_SIZE"){
  186. myParentAlert("Incorrect format. Only JPG, JPEG and PNG format allowed. File size must be 6M or less.");
  187. }
  188. });
  189. var index = parent.layer.getFrameIndex(window.name);
  190. parent.layer.iframeAuto(index);
  191. $('.close').click(function(){
  192. parent.layer.close(index);
  193. })
  194. var change_status = 0;//防止多次点击
  195. $('.Submit').click(function(){
  196. if(change_status){
  197. return false;
  198. }
  199. change_status = 1;
  200. var img = $('input[name="img"]').val();
  201. var video = $('input[name="video"]').val();
  202. if(!img){
  203. myParentAlert('Please select a video cover image.');
  204. change_status = 0;
  205. return false;
  206. }else if(!video){
  207. myParentAlert('Please select an valid video file.');
  208. change_status = 0;
  209. return false;
  210. }
  211. var paragraph = $('textarea[name="paragraph"]').val();
  212. paragraph = paragraph.trim();
  213. if(paragraph.length<48){
  214. myParentAlert('Please enter at least 48 characters of description.');
  215. change_status = 0;
  216. return false;
  217. }
  218. var is_show_profile = $('select[name="is_show_profile"]').val();
  219. $.post('/broadcast/shotsLayer/addVideo', {img:img, video:video,paragraph:paragraph,is_show_profile:is_show_profile}, function(data){
  220. if(data.errno == 0){
  221. Cookies.set('add_success_video', {status:1});
  222. parent.layer.close(index);
  223. parent.layer.msg('Submit successfully. Auditing soon.');
  224. }else{
  225. myParentAlert('Failed to submit. Please try again.');
  226. change_status = 0;
  227. }
  228. })
  229. })
  230. })
  231. </script>