common.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. var $zip;
  2. var domain = "https://aspx.bssji.com/";
  3. zip.useWebWorkers = false;
  4. zip.workerScriptsPath = "/Content/js/jszip/";
  5. $(function () {
  6. var myDropzone = new Dropzone("#dropz", {
  7. url: '/u.aspx',
  8. maxFiles: 1,
  9. maxFilesize: 51200,
  10. autoProcessQueue: false,
  11. acceptedFiles: ".apk,.ipa",
  12. //上传成功回调
  13. success: function (file, data) {
  14. console.log(data);
  15. },
  16. error: function (a, b, c) {
  17. console.log(a);
  18. console.log(b);
  19. console.log(c);
  20. },
  21. init: function () {
  22. this.on("addedfile", function (file) {
  23. processZipFile(file);
  24. });
  25. }
  26. });
  27. //提交上传
  28. $("#submit").on("click", function () {
  29. $("input[name='hlogo']").val($("#image").val());
  30. $("input[name='happName']").val($("#appName").val());
  31. $("input[name='hversion']").val($("#version").val());
  32. $("input[name='hpackageName']").val($("#packageName").val());
  33. $("input[name='hversionCode']").val($("#versionCode").val());
  34. myDropzone.processQueue();
  35. });
  36. //重新选择
  37. $("#reset").on("click", function () {
  38. location = location;
  39. });
  40. function parse(infoplist, resoucesArsc, androidManifest) {
  41. var data = {};
  42. if (androidManifest.length > 0) {
  43. data.system = "android";
  44. resoucesArsc[0].async("uint8array").then(function (arsc) {
  45. androidManifest[0].async("uint8array").then(function (mainifest) {
  46. data.arsc = Base64.encode(arsc);
  47. data.mainifest = Base64.encode(mainifest);
  48. callback(data);
  49. });
  50. });
  51. } else if (infoplist.length > 0) {
  52. data.system = "ios";
  53. infoplist[0].async("uint8array").then(function (d) {
  54. data.plist = Base64.encode(d);
  55. callback(data);
  56. });
  57. }
  58. }
  59. });
  60. function showLoading() {
  61. $("#full,#loading").fadeIn();
  62. }
  63. function hideLoading() {
  64. $("#full,#loading").fadeOut();
  65. }
  66. function ajaxCallBack(d, sys) {
  67. $("input[name='hsysname']").val(sys);
  68. //切换
  69. $(".zone,.tip").hide();
  70. $(".info").show();
  71. //给字段赋值
  72. $("#appName").val(d.Name);
  73. $("#version").val(d.Version);
  74. $("#packageName").val(d.PackageName);
  75. $("#versionCode").val(d.VersionCode);
  76. //$("#logo").val(d.LogoName);
  77. var logoType = logotype(d.LogoName);
  78. //如果是ios并且没有扩展名称
  79. if (sys == "ios" && d.LogoName.indexOf(".") == -1) {
  80. d.LogoName = "/" + d.LogoName + "([\\d]+x[\\d]+)?(@[\\d]x)?.png";
  81. } else if (sys == "ios") {
  82. d.LogoName = "/" + d.LogoName;
  83. }
  84. //图片
  85. if (d.LogoName) {
  86. var logo = getIconFile(d.LogoName);
  87. if (logo) {
  88. logo.getData(new zip.BlobWriter(), function (blob) {
  89. var reader = new FileReader();
  90. reader.addEventListener("loadend", function () {
  91. var dd = Base64.encode(new Uint8Array(reader.result));
  92. $.ajax({
  93. url: domain + "GetString.ashx",
  94. type: "POST",
  95. cache: false,
  96. data: { image: dd, system: sys },
  97. complete: function () {
  98. hideLoading();
  99. },
  100. error: function () {
  101. alert("获取Logo失败")
  102. },
  103. success: function (abc) {
  104. $("input[name='logo']").val(abc);
  105. $("#image").attr("src", "data:" + logoType + ";base64," + abc);
  106. }
  107. });
  108. });
  109. reader.readAsArrayBuffer(blob);
  110. });
  111. }
  112. else {
  113. hideLoading();
  114. $("input[name='logo']").val("");
  115. $("#image").attr("src", "./Content/default.png");
  116. }
  117. }
  118. else {
  119. hideLoading();
  120. $("input[name='logo']").val("");
  121. $("#image").attr("src", "./Content/default.png");
  122. }
  123. }
  124. function logotype(filename) {
  125. if (/(\.|\/)(png)$/i.test(filename)) {
  126. return 'image/png';
  127. }
  128. if (/(\.|\/)(ico)$/i.test(filename)) {
  129. return 'image/x-icon';
  130. }
  131. if (/(\.|\/)(gif)$/i.test(filename)) {
  132. return 'image/gif';
  133. }
  134. if (/(\.|\/)(bmp)$/i.test(filename)) {
  135. return 'image/bmp';
  136. }
  137. if (/(\.|\/)(jpeg|jpg|jpe)$/i.test(filename)) {
  138. return 'image/jpeg';
  139. }
  140. return 'image/png';
  141. }
  142. function processZipFile(file) {
  143. zip.createReader(new zip.BlobReader(file), function (reader) {
  144. reader.getEntries(function (entries) {
  145. $zip = entries;
  146. var infoplist = null, resoucesArsc = null, androidManifest = null;
  147. for (var i = 0; i < entries.length; i++) {
  148. if (entries[i].filename.match(/^(([^\\\?\/\*\|<>:"]+\/){2})Info\.plist/) || entries[i].filename.indexOf('.app/Info.plist') != -1) {
  149. infoplist = entries[i];
  150. continue;
  151. }
  152. if (entries[i].filename.match(/AndroidManifest.xml/)) {
  153. androidManifest = entries[i];
  154. continue;
  155. }
  156. if (entries[i].filename.match(/resources.arsc/)) {
  157. resoucesArsc = entries[i];
  158. continue;
  159. }
  160. }
  161. processZipFileSubmit(infoplist, resoucesArsc, androidManifest);
  162. });
  163. }, function (error) {
  164. console.log(error);
  165. alert("读取安装包信息失败!");
  166. });
  167. }
  168. function processZipFileSubmit(infoplist, resoucesArsc, androidManifest) {
  169. var data = {};
  170. if (infoplist != null) {
  171. data.system = "ios";
  172. infoplist.getData(new zip.BlobWriter(), function (blob) {
  173. var reader = new FileReader();
  174. reader.addEventListener("loadend", function () {
  175. var bytes = new Uint8Array(reader.result);
  176. data.plist = Base64.encode(bytes);
  177. callback(data);
  178. });
  179. reader.readAsArrayBuffer(blob);
  180. });
  181. }
  182. else if (resoucesArsc != null && androidManifest != null) {
  183. data.system = "android";
  184. function readArsc() {
  185. resoucesArsc.getData(new zip.BlobWriter(), function (blob) {
  186. var reader = new FileReader();
  187. reader.addEventListener("loadend", function () {
  188. data.arsc = Base64.encode(new Uint8Array(reader.result));
  189. readManifest();
  190. });
  191. reader.readAsArrayBuffer(blob);
  192. });
  193. }
  194. function readManifest() {
  195. androidManifest.getData(new zip.BlobWriter(), function (blob) {
  196. var reader = new FileReader();
  197. reader.addEventListener("loadend", function () {
  198. data.mainifest = Base64.encode(new Uint8Array(reader.result));
  199. callback(data);
  200. });
  201. reader.readAsArrayBuffer(blob);
  202. });
  203. }
  204. readArsc();
  205. } else {
  206. alert("上传的文件不正确,无法读取!");
  207. return;
  208. }
  209. }
  210. function callback(data) {
  211. showLoading();
  212. $.ajax({
  213. url: domain + "GetAppInfo.ashx",
  214. type: "POST",
  215. data: data,
  216. cache: false,
  217. success: function (d) {
  218. if (d.Success) {
  219. ajaxCallBack(d, data.system);
  220. } else {
  221. hideLoading();
  222. alert("获取不到安装包信息!");
  223. }
  224. },
  225. error: function () {
  226. hideLoading();
  227. alert("error");
  228. }
  229. });
  230. }
  231. function getIconFile(fileName) {
  232. var iconFile = null;
  233. for (var i = 0; i < $zip.length; i++) {
  234. if ($zip[i].filename.match(new RegExp(fileName, "i"))) {
  235. iconFile = $zip[i];
  236. break;
  237. }
  238. }
  239. return iconFile;
  240. }
  241. Uint8Array.prototype.toString = function () {
  242. if (this.join) {
  243. return this.join(',');
  244. } else {
  245. var a = Array.prototype.slice.call(this);
  246. return a.join(',');
  247. }
  248. }