lib.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. function upload_icon() {
  2. var upfile = $("#upload_a_icon")[0].files[0];
  3. if (in_login < 1) {
  4. alert("请先登录");
  5. return false;
  6. }
  7. if (upfile.size > 1048576) {
  8. alert("图标不能大于1M");
  9. return false;
  10. }
  11. var fd = new FormData();
  12. fd.append("webview", upfile);
  13. var a_icon_xhr = new XMLHttpRequest();
  14. a_icon_xhr.open("post", in_path + "webview/ajax?fn=" + in_time + "-icon");
  15. a_icon_xhr.onload = complete_a_icon;
  16. a_icon_xhr.onerror = failed_a_icon;
  17. a_icon_xhr.upload.onprogress = progress_a_icon;
  18. a_icon_xhr.send(fd);
  19. }
  20. function progress_a_icon(evt) {
  21. var per = Math.round(evt.loaded / evt.total * 100);
  22. $("#tips_a_icon").text(per + "%");
  23. if (per > 99) {
  24. $("#tips_a_icon").text("请稍等...");
  25. }
  26. }
  27. function complete_a_icon(evt) {
  28. var response = evt.target.responseText;
  29. if (response == "return_0") {
  30. alert("请上传PNG图片");
  31. } else {
  32. $("#preview_a_icon").html('<img width="100" height="100" src="' + in_path + "data/tmp/" + response + '">');
  33. }
  34. }
  35. function failed_a_icon() {
  36. alert("上传异常");
  37. }
  38. function upload_launch() {
  39. var upfile = $("#upload_l_image")[0].files[0];
  40. if (in_login < 1) {
  41. alert("请先登录");
  42. return false;
  43. }
  44. if (upfile.size > 2097152) {
  45. alert("图片不能大于2M");
  46. return false;
  47. }
  48. var fd = new FormData();
  49. fd.append("webview", upfile);
  50. var l_image_xhr = new XMLHttpRequest();
  51. l_image_xhr.open("post", in_path + "webview/ajax?fn=" + in_time + "-launch");
  52. l_image_xhr.onload = complete_l_image;
  53. l_image_xhr.onerror = failed_l_image;
  54. l_image_xhr.upload.onprogress = progress_l_image;
  55. l_image_xhr.send(fd);
  56. }
  57. function progress_l_image(evt) {
  58. var per = Math.round(evt.loaded / evt.total * 100);
  59. $("#tips_l_image").text(per + "%");
  60. if (per > 99) {
  61. $("#tips_l_image").text("请稍等...");
  62. }
  63. }
  64. function complete_l_image(evt) {
  65. var response = evt.target.responseText;
  66. if (response == "return_0") {
  67. alert("请上传PNG图片");
  68. } else {
  69. $("#preview_l_image").html('<img width="200" height="200" src="' + in_path + "data/tmp/" + response + '">');
  70. }
  71. }
  72. function failed_l_image() {
  73. alert("上传异常");
  74. }
  75. function prev_view() {
  76. if (step > 1) {
  77. step--;
  78. $('.step' + step).show().siblings('.step-common').hide();
  79. $("#web_view_btn").text('下一步');
  80. if (step == 1) {
  81. $('#prev_view_btn').hide();
  82. $('#web_view_btn').addClass('h-100')
  83. }
  84. $('ul.fz-step-box li').eq(step - 1).addClass('active').siblings().removeClass('active')
  85. }
  86. }
  87. function next_view() {
  88. console.log('下一步');
  89. if (in_login < 1) {
  90. alert("请先登录后再操作!");
  91. return;
  92. }
  93. if (step == 1) {
  94. if ($("#in_title").val() == "") {
  95. $("#in_title").focus();
  96. return;
  97. }
  98. if ($("#in_url").val() == "") {
  99. $("#in_url").focus();
  100. return;
  101. }
  102. if ($("#in_b_color").val() == "") {
  103. $("#in_b_color").focus();
  104. return;
  105. }
  106. if ($("#in_t_color").val() == "") {
  107. $("#in_t_color").focus();
  108. return;
  109. }
  110. step++;
  111. $('.step' + step).show().siblings('.step-common').hide();
  112. $('#prev_view_btn').show();
  113. $('#web_view_btn').removeClass('h-100')
  114. $('ul.fz-step-box li').eq(step - 1).addClass('active').siblings().removeClass('active')
  115. return;
  116. }
  117. var type = $('input:radio[name=type]:checked').val();
  118. if (step == 2) {
  119. if ($("#preview_a_icon img").length < 1) {
  120. alert("请上传应用图标!");
  121. return;
  122. }
  123. $("#j_image").attr("src", $("#preview_a_icon img").attr("src"));
  124. if ($("#preview_l_image img").length < 1) {
  125. alert("请上传启动图片!");
  126. return;
  127. }
  128. step++;
  129. $('.step' + step).show().siblings('.step-common').hide();
  130. $('ul.fz-step-box li').eq(step - 1).addClass('active').siblings().removeClass('active')
  131. if (type > 0) $('.ios_unable').hide(); else $('.android_unable').hide();
  132. return;
  133. }
  134. if (step == 3) {
  135. // if (!$('input[name=edit]').val()) {
  136. // step++;
  137. // $('.step' + step).show().siblings('.step-common').hide();
  138. // $('ul.fz-step-box li').eq(step - 1).addClass('active').siblings().removeClass('active')
  139. // return;
  140. // }
  141. step++;
  142. $('.step' + step).show().siblings('.step-common').hide();
  143. $('ul.fz-step-box li').eq(step - 1).addClass('active').siblings().removeClass('active')
  144. if (type > 0) $('.ios_unable').hide(); else $('.android_unable').hide();
  145. return;
  146. }
  147. if (step == 4) {
  148. // if (!$('input[name=edit]').val()) {
  149. // step++;
  150. // $('.step' + step).show().siblings('.step-common').hide();
  151. // $('ul.fz-step-box li').eq(step - 1).addClass('active').siblings().removeClass('active')
  152. // return;
  153. // }
  154. }
  155. var limage = 0;
  156. if($("#preview_l_image img") != undefined && $("#preview_l_image img")[0] != undefined && $("#preview_l_image img")[0].src != undefined)
  157. {
  158. limage = $("#preview_l_image img")[0].src;
  159. }
  160. else
  161. {
  162. }
  163. var param = {
  164. id: $('input[name=id]').val(),
  165. type: type,
  166. title: escape($("#in_title").val()),
  167. url: $("#in_url").val(),
  168. screenOrientation: $("input[name=screenOrientation]:checked").val(),
  169. bundle_id: $("#bundle_id").val(),
  170. version: $("#version").val(),
  171. aicon: $("#preview_a_icon img")[0].src,
  172. limage: limage,
  173. splashTime: $("input[name=splashTime]:checked").val(),
  174. period: $('ul.period>li.active').attr('data-id'),
  175. };
  176. param = getParam(param);
  177. // return console.log(param);
  178. $('.ng-binding').attr("disabled", "disabled");
  179. $("#web_view_btn").text("生成中(勿离开)");
  180. $.post(
  181. in_path + "webview/ajax/webview", param,
  182. function (ret) {
  183. if (ret.code == -1) {
  184. $("#web_view_btn").text("请先登录");
  185. alert("请先登录!");
  186. } else if (ret.code == -2) {
  187. $("#web_view_btn").text("余额不足");
  188. alert("余额不足!", function () {
  189. window.location.href = "/index/item_price";
  190. });
  191. } else if (ret.code == -4) {
  192. $("#web_view_btn").text("应用容量不足!请升级VIP!");
  193. alert("应用容量不足!请升级VIP!", function () {
  194. window.location.href = "/index/item_price?type=2";
  195. });
  196. } else if (ret.data) {
  197. window.location.href = "/index/webview_log?id=" + ret.data.id;
  198. }
  199. }, 'json');
  200. }
  201. function getParam(param) {
  202. param = param || {}
  203. var hasChecked1 = $("#config1").find(".iconfont").hasClass("icon-checkbox-checked1"); // 加载动画
  204. var hasChecked2 = $("#config2").find(".iconfont").hasClass("icon-checkbox-checked1"); // 清理缓存
  205. var hasChecked3 = $("#config3").find(".iconfont").hasClass("icon-checkbox-checked1"); // 浏览器
  206. var hasChecked4 = $("#config4").find(".iconfont").hasClass("icon-checkbox-checked1"); // 退出提示
  207. var hasChecked5 = $("#config5").find(".iconfont").hasClass("icon-checkbox-checked1"); // 第三方分享
  208. var hasChecked6 = $("#config6").find(".iconfont").hasClass("icon-checkbox-checked1"); // 极光推送
  209. var hasChecked7 = $("#config7").find(".iconfont").hasClass("icon-checkbox-checked1"); // 友盟统计
  210. var hasChecked8 = $("#config8").find(".iconfont").hasClass("icon-checkbox-checked1"); // 导航栏
  211. var hasChecked9 = $("#config9").find(".iconfont").hasClass("icon-checkbox-checked1"); // 状态栏
  212. var hasChecked10 = $("#config10").find(".iconfont").hasClass("icon-checkbox-checked1"); // 标题栏
  213. var hasChecked11 = $("#config11").find(".iconfont").hasClass("icon-checkbox-checked1"); // 引导页
  214. var configAsideChecked = $("#configAside").find(".iconfont").hasClass("icon-checkbox-checked1"); // 左侧栏
  215. var longPressSavePictureChecked = $("#configPhotoSave").find(".iconfont").hasClass("icon-checkbox-checked1"); // 长按图片保存
  216. var qrcodeScanChecked = $("#configIdentifyCode").find(".iconfont").hasClass("icon-checkbox-checked1"); // 扫一扫
  217. var webZoomChecked = $("#configWebZoom").find(".iconfont").hasClass("icon-checkbox-checked1"); // 网页缩放
  218. var userAgentChecked = $("#userAgent").find(".iconfont").hasClass("icon-checkbox-checked1");
  219. var isSkidBack = $("#configSkidBack").find(".iconfont").hasClass("icon-checkbox-checked1"); // 侧滑返回
  220. var isNoNet = $("#configNoNet").find(".iconfont").hasClass("icon-checkbox-checked1"); // 无网提示
  221. var isInstallTip = $("#configInstallTip").find(".iconfont").hasClass("icon-checkbox-checked1"); // APK安装器
  222. var isKeepScreen = $("#configKeepScreen").find(".iconfont").hasClass("icon-checkbox-checked1"); // 屏幕常亮
  223. var isHideBottom = $("#configHideBottom").find(".iconfont").hasClass("icon-checkbox-checked1"); // 屏幕常亮
  224. var hasKeystore = $('#configKeystore').find(".iconfont").hasClass("icon-checkbox-checked1"); // 安卓证书
  225. param.supportLongPressSavePicture = 0;
  226. param.supportQrcodeScan = 0;
  227. param.supportZoom = 0;
  228. param.userAgent = {};
  229. param.skidBack = 0;
  230. param.noNet = 0;
  231. param.installTip = 0;
  232. param.keepScreen = 0;
  233. param.hideBottom = 0;
  234. if (longPressSavePictureChecked) param.supportLongPressSavePicture = $("#photoSaveModal").find("ul>li.active").data('photo-save');
  235. if (qrcodeScanChecked) param.supportQrcodeScan = $("#identifyCodeModal").find("ul>li.active").data('identify-code');
  236. if (webZoomChecked) param.supportZoom = $("#webZoomModal").find("ul>li.active").data('web-zoom');
  237. if (userAgentChecked) {
  238. $("#uaModal .plugin-save").trigger('click');
  239. param.userAgent = userAgent;
  240. }
  241. if (isSkidBack) param.skidBack = $("#skidBackModal").find("ul>li.active").data('skid-back');
  242. if (isNoNet) param.noNet = $("#noNetModal").find("ul>li.active").data('no-net');
  243. if (isInstallTip) param.installTip = $("#installTipModal").find("ul>li.active").data('install-tip');
  244. if (isKeepScreen) param.keepScreen = $("#keepScreenModal").find("ul>li.active").data('keep-screen');
  245. if (isHideBottom) param.hideBottom = $("#hideBottomModal").find("ul>li.active").data('hide-bottom');
  246. // 下拉刷新
  247. var hasCheckedRefresh = $("#configRefresh").find(".iconfont").hasClass("icon-checkbox-checked1");
  248. if (hasCheckedRefresh) {
  249. refreshVal = $("#refreshModal").find(".plugin-refresh").find(".active").attr("data-refresh");
  250. param.refresh = refreshVal;
  251. } else {
  252. param.refresh = 0;
  253. }
  254. // URL 拉起APP
  255. var hasCheckedUrlApp = $("#configUrlApp").find(".iconfont").hasClass("icon-checkbox-checked1");
  256. param.urlApp = 0;
  257. if (hasCheckedUrlApp) {
  258. urlAppVal = $("#urlAppModal").find(".plugin-url-app").find(".active").attr("data-url-app");
  259. param.urlApp = urlAppVal;
  260. }
  261. // 加载配置
  262. if (hasChecked1) {
  263. way = $("#loadingModal").find(".plugin-loading").find(".active").attr("data-way");
  264. color = $("#loadingModal").find(".plugin-loading").find(".sp-preview-inner").css("background-color");
  265. color = colorRGB2Hex(color);
  266. param.loading = {way: way, color: color};
  267. } else {
  268. param.loading = {};
  269. }
  270. // 清理缓存
  271. if (hasChecked2) {
  272. param.cache = $("#cacheModal").find(".plugin-cache").find(".active").attr("data-cache");
  273. } else {
  274. param.cache = 0;
  275. }
  276. // 浏览器内核
  277. if (hasChecked3) {
  278. android = $("#browserModal").find("#androidKernel").find(".active").attr("data-android-kernel");
  279. ios = $("#browserModal").find("#iosKernel").find(".active").attr("data-ios-kernel");
  280. param.browser = {android: android, ios: ios}
  281. } else {
  282. param.browser = {};
  283. }
  284. // 退出提示
  285. if (hasChecked4) {
  286. exit = $("#exitModal").find(".plugin-exit").find(".active").attr("data-exit");
  287. param.exit = exit;
  288. } else {
  289. param.exit = 0;
  290. }
  291. // 第三方分享
  292. if (hasChecked5) {
  293. $("#shareModal .plugin-save").trigger('click');
  294. param.share = share;
  295. }
  296. // 极光推送
  297. param.jPushId = '';
  298. if (hasChecked6) {
  299. jPushId = $.trim($('#auroraModal input[name="jPushId"]').val());
  300. if (jPushId) param.jPushId = jPushId;
  301. }
  302. // 友盟统计
  303. param.umengKey = '';
  304. if (hasChecked7) {
  305. umengIosKey = $.trim($('#alliesModal input[name="umeng_ios_key"]').val());
  306. umengAndroidKey = $.trim($('#alliesModal input[name="umeng_android_key"]').val());
  307. param.umengKey = {
  308. ios: umengIosKey,
  309. android: umengAndroidKey
  310. };
  311. }
  312. // 导航栏
  313. param.nav = '';
  314. if (hasChecked8) {
  315. $("#navModal .plugin-save").trigger('click');
  316. param.nav = navData;
  317. }
  318. // 状态标题栏
  319. param.titleBar = '';
  320. param.stateBar = '';
  321. if (hasChecked10) {
  322. $("#titleModal .plugin-save").trigger('click');
  323. param.titleBar = titleBar;
  324. param.stateBar = stateBar;
  325. }
  326. // 侧边栏
  327. param.asideData = '';
  328. if (configAsideChecked) {
  329. $("#asideModal .plugin-save").trigger('click')
  330. param.asideData = asideData;
  331. }
  332. // 引导页
  333. param.guide = {};
  334. if (hasChecked11) {
  335. $("#guideModal .plugin-save").trigger('click');
  336. param.guide = guide;
  337. param.support_guide_enter_main_page_button = supportGuideEnterMainPageButton;
  338. param.guide_enter_main_page_button_color = guideEnterMainPageButtonColor;
  339. }
  340. if (hasKeystore) {
  341. $("#keystoreModal .plugin-save").trigger('click');
  342. delete androidKey.save;
  343. param.androidKey = androidKey;
  344. }
  345. // 是否点击跳过
  346. //var isSkip = $(this).hasClass('skip');
  347. return param;
  348. }