PageRenderTime 65ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/static/js/page/updateManage/add.js

https://gitlab.com/lyslys34/node_test1
JavaScript | 329 lines | 297 code | 32 blank | 0 comment | 43 complexity | ac557c4aa0942043c1a3f5604b4a95e1 MD5 | raw file
  1. require.config({
  2. baseUrl: MT.STATIC_ROOT + '/js',urlArgs: 'ver='+ pageVersion,
  3. shim: {
  4. 'lib/bootstrap': {
  5. deps: ['lib/jquery']
  6. }
  7. }
  8. });
  9. require(['module/root', 'module/validator','module/cookie'], function (t, validator,cookie) {
  10. $(document).ready(function() {
  11. getCityList();
  12. upload_ipa=function(){
  13. $('#upload-msg').remove();
  14. $('#upload-btn').attr('disabled','true')
  15. }
  16. upload_file = function () {
  17. $('#upload-msg').remove();
  18. $('#upload-btn').attr('disabled','true');
  19. var fileObj = document.getElementById("apk-file").files[0]; // 获取文件对象
  20. var FileController = "/file/apkupload"; // 接收上传文件的后台地址
  21. if($('#os_type').val()==2)
  22. FileController="/file/ipaupload";
  23. var form = new FormData();
  24. form.append("apk_file", fileObj); // 文件对象
  25. var app_type=$("#app_type").val();
  26. if(app_type==-1){
  27. alert("请选择众包或者自建");
  28. return ;
  29. }
  30. form.append("app_type",$('#app_type').val());
  31. if($('#os_type').val()==1){
  32. $.ajax({
  33. url: "/file/apkupload",
  34. type: "POST",
  35. data: form,
  36. processData: false,
  37. contentType: false
  38. })
  39. .done(function(data) {
  40. console.log("success");
  41. if (data.code==0) {
  42. $('#apk-file').parent().append('<div class="alert alert-sm alert-info" id="upload-msg" style="display: inline;padding: 5px;">上传成功</div>');
  43. apk = jQuery.parseJSON(data.data);
  44. console.log(apk.appVersion);
  45. $('#app_version').val(apk.appVersion);
  46. $('#code').val(apk.appVersionCode);
  47. $('#download_url').val(apk.downloadUrl);
  48. } else {
  49. $('#apk-file').parent().append('<div class="alert alert-sm alert-info" id="upload-msg" style="display: inline;padding: 5px;">上传失败</div>');
  50. };
  51. console.log(data.msg);
  52. })
  53. .fail(function() {
  54. $('#upload-btn').removeAttr('disabled');
  55. console.log("error");
  56. }).always(function () {
  57. });
  58. }
  59. else if($('#os_type').val()==2){
  60. $.ajax({
  61. url: "/file/ipaupload",
  62. type: "POST",
  63. data: form,
  64. processData: false,
  65. contentType: false
  66. })
  67. .done(function(data) {
  68. $('#upload-btn').removeAttr('disabled');
  69. console.log("success");
  70. if (data.code==0) {
  71. $('#apk-file').parent().append('<div class="alert alert-sm alert-info" id="upload-msg" style="display: inline;padding: 5px;">上传成功</div>');
  72. ipa = jQuery.parseJSON(data.data);
  73. console.log(ipa.bundleShoartVersionString);
  74. $('#app_version').val(ipa.bundleShortVersionString);
  75. $('#code').val(ipa.bundleVersionCode);
  76. $('#download_url').val(ipa.downloadUrl);
  77. } else {
  78. $('#apk-file').parent().append('<div class="alert alert-sm alert-info" id="upload-msg" style="display: inline;padding: 5px;">上传失败</div>');
  79. };
  80. console.log(data.msg);
  81. })
  82. .fail(function() {
  83. $('#upload-btn').removeAttr('disabled');
  84. console.log("error");
  85. }).always(function () {
  86. });
  87. }
  88. }
  89. $('#add-new-submit').click(function () {
  90. if ($('#download_url').val()=="") {
  91. alert("请上传文件");
  92. return false;
  93. }
  94. is_empty=0;
  95. $('input[type=text]:visible').each(function () {
  96. if ($(this).val()=='') {
  97. $(this).focus();
  98. $(this).attr('placeholder','不能为空');
  99. is_empty=1;
  100. return false;
  101. };
  102. });
  103. if (is_empty==1) {
  104. return;
  105. };
  106. $('#msg .col-sm-10').empty();
  107. $('#msg').hide();
  108. release_station = new Object();
  109. citys = new Array();
  110. orgs = new Array();
  111. release_device = new Array();
  112. release_station.citys = $('.city-select').val();
  113. release_station.orgs = $('.station-select').val();
  114. release_device = $('.device-select').val();
  115. all_null=1;
  116. if ($('#os_type').val() == 2) {
  117. release_device = $('.device-select-ios').val();
  118. }
  119. if (release_device == null) {
  120. release_device = new Array();
  121. }else{
  122. all_null=0;
  123. }
  124. if (!release_station.citys) {
  125. release_station.citys=new Array();
  126. }else{
  127. all_null=0;
  128. }
  129. if (!release_station.orgs) {
  130. release_station.orgs=new Array();
  131. }else{
  132. all_null=0;
  133. }
  134. if(!(mobiles.length==0)){
  135. all_null=0;
  136. }
  137. if($("input[name='release_type']:checked").val()==0){
  138. all_null=0;
  139. }
  140. if(all_null==1){
  141. alert("请输入灰度范围");
  142. return ;
  143. }
  144. console.log(JSON.stringify(release_station));
  145. console.log(JSON.stringify(release_device));
  146. $.ajax({
  147. url: '/updateManage/addNewVersion/',
  148. type: 'POST',
  149. dataType: 'json',
  150. data: { app_type: $('#app_type').val(),
  151. os_type: $('#os_type').val(),
  152. force_update: $("input[name='force_update']:checked").val(),
  153. code: $('#code').val(),
  154. release_type: $("input[name='release_type']:checked").val(),
  155. app_version: $('#app_version').val(),
  156. download_url: $('#download_url').val(),
  157. description: $('#description').val(),
  158. release_station: JSON.stringify(release_station),
  159. release_device: JSON.stringify(release_device),
  160. mobiles:$('#mobiles').val()
  161. },
  162. })
  163. .done(function(data) {
  164. console.log("success");
  165. if (data.code==0) {
  166. $("#success").fadeIn();
  167. $("#success").fadeOut(1000);
  168. setTimeout(function () {
  169. window.location.assign("/updateManage");
  170. }, 2000);
  171. } else {
  172. alert(data.msg);
  173. };
  174. console.log(data.msg);
  175. })
  176. .fail(function() {
  177. console.log("error");
  178. })
  179. .always(function() {
  180. console.log("complete");
  181. });
  182. })
  183. $("#os_type").change(function () {
  184. if ($(this).val()==2) {
  185. $('#apk_upload').show();
  186. $('#device').hide();
  187. $('#device-ios').show();
  188. $('#plist_upload').show();
  189. $("#apk_file").show();
  190. } else {
  191. $('#plist_upload').hide();
  192. $('#device').show();
  193. $('#device-ios').hide();
  194. $('#apk_upload').show();
  195. };
  196. })
  197. $('#description').blur(function () {
  198. if ($(this).val()=='') {
  199. $(this).focus();
  200. $(this).attr('placeholder','不能为空');
  201. };
  202. })
  203. $("[name='release_type']").change(function () {
  204. if ($("input[name='release_type']:checked").val()==1) {
  205. $('#gray').slideDown();
  206. } else {
  207. $('#gray').slideUp();
  208. };
  209. })
  210. });
  211. function getCityList () {
  212. $.getJSON('/updateManage/getAllDevice', {}, function(json, textStatus) {
  213. device_list = JSON.parse(json.data);
  214. for(var i in device_list){
  215. device = device_list[i];
  216. if (device.match('iPhone') != null || device.match('iPod') != null) {
  217. $('#device_option_ios').parent().append('<option value="'+device+'" >'+device+'</option>');
  218. continue;
  219. }
  220. $('#device_option').parent().append('<option value="'+device+'" >'+device+'</option>');
  221. }
  222. });
  223. initPost('/org/citySearchList', {}, function (data) {
  224. for(var i in data.data.data){
  225. city = data.data.data[i].value;
  226. id = data.data.data[i].id;
  227. $('#city_option').parent().append('<option value="'+id+'" >'+city+'</option>');
  228. }
  229. });
  230. initPost('/org/leafOrgSearchList', {}, function (data) {
  231. for(var i in data.data.data){
  232. station = data.data.data[i].value;
  233. id = data.data.data[i].id;
  234. $('#station_option').parent().append('<option value="'+id+'" >'+station+'</option>');
  235. }
  236. });
  237. }
  238. function initPost(url, data, callback)
  239. {
  240. if(typeof(data) == 'function') { callback = data; data = null; }
  241. $.ajax({ type: 'POST', url: url, data:data, success:function(r) {
  242. callback({ httpSuccess: true, data: r });
  243. }, error: function(XmlHttpRequest, textStatus, errorThrown) {
  244. callback({ httpSuccess: false, statusCode:XmlHttpRequest.status });
  245. } });
  246. }
  247. function btn_click (address) {
  248. window.location.href=address;
  249. }
  250. $("#percent-submit").on("click",function(){
  251. var releaseStation=new Object();
  252. citys=new Array();
  253. orgs=new Array();
  254. releaseStation.citys=$('.city-select').val();
  255. releaseStation.orgs=$('.station-select').val();
  256. if(!releaseStation.citys){
  257. releaseStation.citys=new Array();
  258. }
  259. if(!releaseStation.orgs){
  260. releaseStation.orgs=new Array();
  261. }
  262. var os_type=$('#os_type').val();
  263. var release_device=null
  264. if(os_type==1){
  265. release_device = $('.device-select').val();
  266. }
  267. else if(os_type==2){
  268. release_device = $('.device-select-ios').val();
  269. }
  270. if(release_device==null)
  271. {
  272. release_device =new Array();
  273. }
  274. console.log("release_device"+release_device);
  275. $.ajax({
  276. url: '/updateManage/getPercent',
  277. type:'POST',
  278. dataType:'json',
  279. data:{
  280. release_station:JSON.stringify(releaseStation),
  281. release_device: JSON.stringify(release_device),
  282. app_type: $('#app_type').val(),
  283. os_type:$('#os_type').val()
  284. }
  285. })
  286. .done(function(data){
  287. console.log("---success");
  288. $("#gray_percent").html(data.data);
  289. })
  290. .fail(function(){
  291. console.log("error");
  292. })
  293. .always(function(){
  294. console.log("success");
  295. })
  296. })
  297. });