ebook.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  1. define(['jquery', 'bootstrap', 'frontend', 'frontend-ebook', 'layer', 'config'], function ($, undefined, Frontend, Ebook, Layer, Config) {
  2. Ebook.setupMonthNav();
  3. Ebook.setupFunctionNav();
  4. Ebook.setupPlayWXVideo();
  5. var Controller = {
  6. index: function () {
  7. },
  8. buynow: function () {
  9. var pagecount = parseInt($("#pageCount").text()) + 1;
  10. var nums = Math.max(1, parseInt($('#nums').val()));
  11. var amount = 0;
  12. var get_amount = function () {
  13. if ($('#printtype').val() == 'fourcolor')
  14. {
  15. amount = pagecount * parseFloat(Config.product['printtype.fourcolor.price']);
  16. } else if ($('#printtype').val() == 'sixcolor') {
  17. amount = pagecount * parseFloat(Config.product['printtype.sixcolor.price']);
  18. }
  19. if ($('#bindtype').val() == 'paperback') {
  20. amount += parseFloat(Config.product['bindtype.paperback.price']) * parseFloat(Config.product['sale.discount']);
  21. } else if ($('#bindtype').val() == 'hardback') {
  22. amount += parseFloat(Config.product['bindtype.hardback.price']) * parseFloat(Config.product['sale.discount']);
  23. }
  24. amount = Math.floor(amount);
  25. amount *= nums;
  26. return amount;
  27. }
  28. var get_sale_amount = function () {
  29. return Math.floor(get_amount() * parseFloat(Config.product['sale.discount']));
  30. }
  31. var refreshamount = function () {
  32. $('#total_amount').text('¥' + get_amount());
  33. $('#sale_amount').text('¥' + get_sale_amount());
  34. $('#sale_desc').text('');
  35. }
  36. $("#buynow_form").submit(function () {
  37. if (parseInt($('#pageCount').text()) < 20) {
  38. layer.msg('您的作品少于20页不能装订成书,请补充内容重新提交。', {time: 3000, icon: 5});
  39. return false;
  40. } else if ($('#address').val() == '' || $('#receiver').val() == '' || $('#mobile').val() == '') {
  41. layer.msg('收货地址、收件人和联系方式不能为空。', {time: 3000, icon: 5});
  42. return false;
  43. } else {
  44. return true;
  45. }
  46. });
  47. refreshamount();
  48. //增减数量
  49. $(document).on('click', 'span[data-type]', function () {
  50. var spinnums = Math.max(parseInt($('#spinnums').val()), 1);
  51. $('#spinnums').val($(this).data("type") == 'plus' ? spinnums + 1 : Math.max(spinnums - 1, 1));
  52. $("input[name=nums]").val($('#spinnums').val());
  53. nums = Math.max(parseInt($('#spinnums').val()), 1);
  54. refreshamount();
  55. $('.spin_minus').toggleClass('minus_disabled', parseInt($('#spinnums').val()) > 1);
  56. });
  57. //类型选择
  58. $(document).on('click', 'span[data-value]', function () {
  59. var parent = $(this).parent();
  60. $("input", parent).val($(this).data("value"));
  61. refreshamount();
  62. $("span[data-value]", parent).removeClass("selected");
  63. $(this).addClass("selected");
  64. });
  65. if (Config.invokejson) {
  66. var onBridgeReady = function () {
  67. WeixinJSBridge.invoke('editAddress', Config.invokejson,
  68. function (res) {
  69. if (res.err_msg == "edit_address:ok") {
  70. $("input[name=address]").val(res.proviceFirstStageName + res.addressCitySecondStageName + res.addressCountiesThirdStageName + res.addressDetailInfo);
  71. $("input[name=receiver]").val(res.userName);
  72. $("input[name=mobile]").val(res.telNumber);
  73. $.post('service/save_address', {
  74. address: $("input[name=address]").val(), receiver: $("input[name=receiver]").val(), mobile: $("input[name=mobile]").val()
  75. });
  76. }
  77. }
  78. );
  79. }
  80. if (typeof WeixinJSBridge == "undefined") {
  81. if (document.addEventListener) {
  82. document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
  83. } else if (document.attachEvent) {
  84. document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
  85. document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
  86. }
  87. } else {
  88. onBridgeReady();
  89. }
  90. }
  91. $(".nav_bar .r_bar").html('<a class="btn btn-danger btn-block btn-submit" href="javascript:;"><span class="fa fa-check"></span>&nbsp;提交</a>');
  92. $(document).on('click', '.btn-submit', function(){
  93. $("#buynow_form").trigger('submit');
  94. });
  95. },
  96. preview: function () {
  97. window.imageLoaded = Ebook.imageLoaded;
  98. $(".ebook_container").on("load", "img", function () {
  99. $(this).parent().removeClass('img_loading');
  100. });
  101. require(['angular', 'angular-app', 'ngcontrol/preface', 'ngcontrol/preview'], function (angular, app) {
  102. angular.bootstrap(document, ["App"]);
  103. });
  104. },
  105. shelf: function () {
  106. require(['angular', 'angular-app', 'ngcontrol/shelf'], function (angular, app) {
  107. angular.bootstrap(document, ["App"]);
  108. });
  109. },
  110. order: function () {
  111. require(['angular', 'angular-app', 'ngcontrol/order'], function (angular, app) {
  112. angular.bootstrap(document, ["App"]);
  113. });
  114. },
  115. design: function () {
  116. require(['angular', 'angular-app', 'ngcontrol/design'], function (angular, app) {
  117. angular.bootstrap(document, ["App"]);
  118. });
  119. },
  120. preface: function () {
  121. require(['angular', 'angular-app', 'ngcontrol/preface'], function (angular, app) {
  122. angular.bootstrap(document, ["App"]);
  123. });
  124. },
  125. make: function () {
  126. require(['angular', 'angular-app', 'ngcontrol/common'], function (angular, app) {
  127. angular.bootstrap(document, ["App"]);
  128. });
  129. },
  130. import: function () {
  131. require(['angular', 'angular-app', 'ngcontrol/common'], function (angular, app) {
  132. angular.bootstrap(document, ["App"]);
  133. });
  134. },
  135. choosemonth: function () {
  136. $(document).on("click", "a.month_item", function () {
  137. var month = $(this).text().substr(0, 2);
  138. var year = $(this).closest(".month_list").prev().find(".pull-left").text().substr(0, 4);
  139. var that = $(this);
  140. layer.load(1);
  141. $.ajax({
  142. type: "POST",
  143. url: "/service/" + ($(this).hasClass("deleted") ? "recover_month" : "delete_month"),
  144. data: {"year": year, "month": month, "id": bookId},
  145. success: function (response) {
  146. if (response == "success") {
  147. layer.closeAll('loading');
  148. that.toggleClass('deleted');
  149. } else {
  150. layer.msg("操作失败");
  151. }
  152. },
  153. error: function () {
  154. layer.closeAll('loading');
  155. layer.msg("操作失败");
  156. }
  157. });
  158. });
  159. $(document).on("click", ".title_year a", function () {
  160. var year = $(this).parents().prev().text().substr(0, 4);
  161. var that = $(this);
  162. layer.load(1);
  163. $.ajax({
  164. type: "POST",
  165. url: "/service/" + ($(this).hasClass("deleted") ? "recover_year" : "delete_year"),
  166. data: {"year": year, "id": bookId},
  167. success: function (response) {
  168. if (response == "success") {
  169. var months = $(that).closest(".title_year").next().find("li a")
  170. if ($(that).hasClass("deleted")) {
  171. months.removeClass("deleted");
  172. } else {
  173. months.addClass("deleted");
  174. }
  175. layer.closeAll('loading');
  176. that.toggleClass('deleted');
  177. } else {
  178. layer.msg("操作失败");
  179. }
  180. },
  181. error: function () {
  182. layer.closeAll('loading');
  183. layer.msg("操作失败");
  184. }
  185. });
  186. });
  187. },
  188. additem: function () {
  189. if (Ebook.isSupportLocalStorage())
  190. {
  191. try {
  192. oldContent = localStorage.getItem(backupContentKey);
  193. if (oldContent != null)
  194. $('#msg_content').val(oldContent);
  195. } catch (e) {
  196. }
  197. Ebook.backupEditContent();
  198. }
  199. $('a#save_message').click(function () {
  200. $('a#save_message').text('保存中...').addClass('disabled');
  201. $.ajax({
  202. type: "POST",
  203. url: '/service/add_item/' + bookId,
  204. data: $('#add_message').serialize(),
  205. success: function (data) {
  206. if (data == "success")
  207. {
  208. $('a#save_message').text('保存').removeClass('disabled');
  209. alert('添加信息成功,您可以继续编写下一条。');
  210. if (Ebook.isSupportLocalStorage()) {
  211. if (timer != null)
  212. clearTimeout(timer);
  213. localStorage.removeItem(backupContentKey);
  214. }
  215. location.reload();
  216. } else {
  217. $('a#save_message').text('保存').removeClass('disabled');
  218. alert("操作失败,请稍后重试");
  219. }
  220. },
  221. error: function (jqXHR, textStatus, errorThrown)
  222. {
  223. $('a#save_message').text('保存').removeClass('disabled');
  224. alert("操作失败,请稍后重试");
  225. }
  226. });
  227. });
  228. require(["dropzone", "mobiscroll"], function (Dropzone, undefined) {
  229. $('#msg_time').mobiscroll().calendar({
  230. controls: ['calendar', 'date', 'time'],
  231. dateFormat: 'yy-mm-dd',
  232. timeFormat: 'HH:ii:ss',
  233. lang: 'zh',
  234. yearSuffix: '年',
  235. monthSuffix: '月',
  236. daySuffix: '日',
  237. display: 'bubble',
  238. });
  239. Dropzone.autoDiscover = false;
  240. $("#upload_photo").dropzone({
  241. paramName: "file",
  242. url: Config.upload.uploadurl,
  243. clickable: true,
  244. maxFiles: 1000,
  245. maxFilesize: 1000,
  246. acceptedFiles: "image/*",
  247. previewsContainer: "#upload_preview_area",
  248. parallelUploads: 1,
  249. dictMaxFilesExceeded: "已超过10张照片",
  250. dictFileTooBig: "照片大小不能超过10M",
  251. headers: {
  252. 'Cache-Control': null,
  253. 'X-Requested-With': null
  254. },
  255. params: {
  256. 'policy': Config.upload.multipart.policy,
  257. 'signature': Config.upload.multipart.signature,
  258. 'ext-param': '123'
  259. },
  260. init: function () {
  261. $(this.element).addClass("dropzone");
  262. this.on("maxfilesreached", function (file) {
  263. //this.removeFile(file);
  264. });
  265. this.on("sending", function (file) {
  266. $('a#save_message').text('正在上传图片...').addClass('disabled');
  267. });
  268. this.on("success", function (file, data) {
  269. var r = $.parseJSON(data);
  270. if (r.code == 200) {
  271. $('#add_message').append("<input type='hidden' name='photos[" + r['sign'] + "][url]' value='" + r['url'] + "'>");
  272. $('#add_message').append("<input type='hidden' name='photos[" + r['sign'] + "][width]' value='" + r['image-width'] + "'>");
  273. $('#add_message').append("<input type='hidden' name='photos[" + r['sign'] + "][height]' value='" + r['image-height'] + "'>");
  274. }
  275. });
  276. this.on("queuecomplete", function (file) {
  277. $('a#save_message').text('保存').removeClass('disabled');
  278. });
  279. this.on("error", function (file, errorMessage) {
  280. layer.msg(errorMessage);
  281. });
  282. }
  283. });
  284. });
  285. },
  286. edit: function () {
  287. var editImage = null;
  288. var imageWidth = 0;
  289. var imageHeight = 0;
  290. var layerWidth = 800;
  291. var layerHeight = 600;
  292. var weixinVideoHint = true;
  293. var checkCanDelete = function (item, id, delete_func) {
  294. layer.open({
  295. type: 0, //page层
  296. title: '确认',
  297. closeBtn: 0,
  298. content: '该信息为<strong style="color:green;">微信小视频</strong>内容,电子书中点击<strong style="color:green;">绿色二维码</strong>可以预览视频。手机扫描成品书中二维码可播放视频(<strong style="color:red;">依赖微信服务</strong>)。<br>确认要删除此信息嘛?',
  299. area: '200px',
  300. btn: ['删除', '保留'],
  301. yes: function (index, layero) {
  302. deleteItem(item, id);
  303. layer.close(index);
  304. },
  305. btn2: function (index, layero) {
  306. layer.close(index);
  307. }
  308. });
  309. weixinVideoHint = false;//弹出提示框只出现一次
  310. };
  311. var deletePhoto = function (item, photo_id) {
  312. var item_id = item.closest(".msg_item").attr("id");
  313. $.ajax({
  314. type: "POST",
  315. url: '/service/delete_photo/' + bookId,
  316. data: {id: bookId, action: "delete_photo", item_id: item_id, photo_id: photo_id},
  317. success: function (data) {
  318. item.parent().fadeTo(300, 0, function () {
  319. item.parent().remove();
  320. });
  321. },
  322. error: function (jqXHR, textStatus, errorThrown)
  323. {
  324. alert("操作失败,请稍后重试");
  325. }
  326. });
  327. };
  328. var deleteItem = function (item, item_id) {
  329. $.ajax({
  330. url: '/service/delete_item/' + bookId,
  331. type: "POST",
  332. data: {id: bookId, action: "delete_item", item_id: item_id},
  333. success: function (response) {
  334. var remove_item = item.parent().parent().parent();
  335. remove_item.fadeTo(300, 0, function () {
  336. remove_item.remove();
  337. });
  338. },
  339. error: function (jqXHR, textStatus, errorThrown)
  340. {
  341. alert("操作失败,请稍后重试");
  342. }
  343. });
  344. };
  345. var initDropzone = function (obj) {
  346. obj.dropzone({
  347. paramName: "file",
  348. //url: "/service/upload_photo/" + bookId,
  349. url: Config.upload.uploadurl,
  350. clickable: true,
  351. maxFiles: 1000,
  352. maxFilesize: 1000,
  353. acceptedFiles: "image/*",
  354. previewsContainer: false,
  355. parallelUploads: 1,
  356. dictMaxFilesExceeded: "已超过10张照片",
  357. dictFileTooBig: "照片大小不能超过10M",
  358. headers: {
  359. 'Cache-Control': null,
  360. 'X-Requested-With': null
  361. },
  362. params: {
  363. 'policy': Config.upload.multipart.policy,
  364. 'signature': Config.upload.multipart.signature,
  365. 'ext-param': '123'
  366. },
  367. init: function () {
  368. $(this.element).addClass("dropzone");
  369. this.old_addedfile = this.defaultOptions.addedfile;
  370. this.on("addedfile", function (file) {
  371. e = document.createElement('div');
  372. $(e).addClass('msg_photo').addClass('dropzone').addClass('dropzone-previews');
  373. file.wzw = e;
  374. $(this.element).parent().before(e);
  375. this.previewsContainer = e;
  376. this.old_addedfile(file);
  377. this.previewsContainer = false;
  378. });
  379. //this.on("uploadprogress", function(file, progress, bytesSent) {
  380. //$(file.wzw).html(bytesSent);
  381. //});
  382. this.on("success", function (file, data) {
  383. var template = '<div class="msg_photo" id="id_value"><a id="a_id_value" href="path_value"><img class="msg_photo_edit msg_photo_item" src="path_value"></a><a href="javascript:;" class="delete_photo"><span class="fa fa-close"></span></a></div>';
  384. var r = $.parseJSON(data);
  385. if (r.code == 200) {
  386. var item_id = obj.closest(".msg_item").attr("id");
  387. $.ajax({
  388. type: "POST",
  389. url: '/service/append_photo/' + bookId,
  390. data: {id: bookId, action: "append_photo", item_id: item_id, width: r['image-width'], height: r['image-height'], url: r['url']},
  391. dataType: 'json',
  392. success: function (data) {
  393. $(file.wzw).replaceWith($(template.replace(/id_value/g, data.id).replace(/path_value/g, Config.upload.cdnurl + r.url).replace(/a_id_value/g, 'a_' + data.id)));
  394. },
  395. error: function ()
  396. {
  397. layer.msg("操作失败,请稍后重试");
  398. }
  399. });
  400. } else {
  401. layer.msg("上传图片失败,请重试");
  402. }
  403. });
  404. this.on("error", function (file, errorMessage) {
  405. layer.msg(errorMessage);
  406. });
  407. this.on("maxfilesreached", function (file) {
  408. //this.removeFile(file);
  409. });
  410. }
  411. });
  412. };
  413. $(document).on('click', '.msg_photo_item', function () {
  414. var this_item = $(this);
  415. var item_id = this_item.closest(".msg_item").attr("id");
  416. var photo_id = $(this).parent().parent().attr('id');
  417. var imageSrc = $(this).attr("src").split('!')[0];
  418. var rotate = $(this).attr("data-rotate");
  419. if (rotate == null)
  420. rotate = 0;
  421. var originalRotate = rotate;
  422. var html = '<div class="editImageBox">\
  423. <image id="wangzw" onload="rotate(getRotate())" data-rotate=' + rotate + ' src="' + imageSrc + '" height = "' + layerHeight * 5 / 7 + '">\
  424. <a class="rotate_left_button" href="javascript:void(0)" onclick="javascript:turnLeft();"><span class="fa fa-rotate-left"></span> 向左旋转</a>\
  425. <a class="rotate_right_button" href="javascript:void(0)" onclick="javascript:turnRight();"><span class="fa fa-rotate-right"></span> 向右旋转</a>\
  426. </div>';
  427. layer.open({
  428. type: 1, //page层
  429. area: [layerWidth + 'px', layerHeight + 'px'],
  430. title: '编辑照片',
  431. shade: 0.6, //遮罩透明度
  432. moveType: false,
  433. shift: -1, //0-6的动画形式,-1不开启
  434. closeBtn: false,
  435. btn: ['确定', '取消'],
  436. content: html,
  437. yes: function (index, layero) {
  438. var rotate = getRotate();
  439. if (rotate != originalRotate) {
  440. var style = new Object();
  441. style.rotate = rotate;
  442. $.ajax({
  443. type: "POST",
  444. url: '/service/rotate_photo',
  445. data: {id: bookId, action: "rotate_photo", item_id: item_id, photo_id: photo_id, style: JSON.stringify(style)},
  446. success: function (data) {
  447. $('#' + photo_id + ' img').attr('src', data).attr("data-rotate", rotate);
  448. layer.close(index);
  449. editImage = null;
  450. },
  451. error: function (jqXHR, textStatus, errorThrown)
  452. {
  453. alert("操作失败,请稍后重试");
  454. }
  455. });
  456. } else {
  457. layer.close(index);
  458. editImage = null;
  459. }
  460. },
  461. btn2: function (index) {
  462. editImage = null;
  463. return true;
  464. }
  465. });
  466. return false;
  467. });
  468. $(document).on('click', '.delete_item', function () {
  469. var this_item = $(this);
  470. var cur_item_id = $(this).parent().parent().parent().attr('id');
  471. if (weixinVideoHint && $('.wx_video', this_item.parent().parent()).length > 0) {
  472. checkCanDelete(this_item, cur_item_id, deleteItem);
  473. } else {
  474. deleteItem(this_item, cur_item_id);
  475. }
  476. });
  477. $(document).on('click', '.delete_photo', function () {
  478. var this_item = $(this);
  479. var photo_id = $(this).parent().attr('id');
  480. if (weixinVideoHint && $('.wx_video', this_item.parent().parent()).length > 0) {
  481. checkCanDelete(this_item, photo_id, deletePhoto);
  482. } else {
  483. deletePhoto(this_item, photo_id);
  484. }
  485. });
  486. require(["dropzone", "mobiscroll"], function (Dropzone, undefined) {
  487. Dropzone.autoDiscover = false;
  488. initDropzone($(".upload_photo_form"));
  489. });
  490. $(document).on('click', '.edit_text', function () {
  491. var edit_item = $(this);
  492. var edit_item_id = $(this).parent().attr('id');
  493. var defaut_val = $(this).parent().find('.message_edit').text();
  494. layer.myPrompt({title: "修改信息文字", formType: 2, maxlength: 100000, value: defaut_val}, function (value, index, elem) {
  495. if (true) {
  496. $.ajax({
  497. url: '/service/edit_text/' + bookId,
  498. type: "POST",
  499. data: {id: bookId, action: "edit_text", item_id: edit_item_id, content: value},
  500. success: function (response)
  501. {
  502. edit_item.parent().find('.message_edit').text(value);
  503. },
  504. error: function (jqXHR, textStatus, errorThrown)
  505. {
  506. alert("保存失败,请稍后重试");
  507. }
  508. });
  509. layer.close(index);
  510. }
  511. });
  512. });
  513. load_more_res_selector = ".ebook .msg_item";
  514. load_more_end_string = "没有更多内容了...";
  515. load_more_res_callback = function (res) {
  516. initDropzone(res.find(".upload_photo_form"));
  517. };
  518. scroll_height_to_load = 50;
  519. scroll_each_selector = ".msg_item";
  520. scroll_each_callback = function ($item) {
  521. $('#nav_title_content').text($item.find('.page_header_title').text());
  522. };
  523. Ebook.setupDimension();
  524. Ebook.setupLoadMore();
  525. Ebook.setupScrolling();
  526. if (isMobile) {
  527. layerWidth = page_width;
  528. layerHeight = page_height;
  529. }
  530. window.getRotate = function () {
  531. if (editImage == null) {
  532. editImage = $("#wangzw")[0];
  533. imageWidth = editImage.width;
  534. imageHeight = editImage.height;
  535. $("#wangzw").css("display", "none");
  536. }
  537. return Number(editImage.getAttribute("data-rotate")) || 0;
  538. }
  539. window.turnLeft = function () {
  540. var r = getRotate();
  541. r -= 90;
  542. if (r < 0)
  543. r = 270;
  544. rotate(r);
  545. }
  546. window.turnRight = function () {
  547. var r = getRotate();
  548. r += 90;
  549. if (r >= 360)
  550. r = 0;
  551. rotate(r);
  552. }
  553. window.rotate = function (r) {
  554. //canvas旋转
  555. if (editImage == null) {
  556. editImage = $("#wangzw")[0];
  557. imageWidth = editImage.width;
  558. imageHeight = editImage.height;
  559. $("#wangzw").css("display", "none");
  560. }
  561. var canvas = $("#canvas_wangzw")[0] || document.createElement("canvas");
  562. canvas.width = layerWidth * 23 / 25;
  563. canvas.height = layerHeight - 140;
  564. canvasRate = canvas.height / canvas.width;
  565. canvas.id = "canvas_wangzw";
  566. //img.style.position = "absolute";
  567. //img.style.visibility = "hidden";
  568. context = canvas.getContext("2d");
  569. x = 0, y = 0;
  570. switch (r) {
  571. case 0:
  572. if (imageHeight / imageWidth > canvasRate)
  573. {
  574. drawHeight = canvas.height;
  575. drawWidth = imageWidth * (drawHeight / imageHeight);
  576. x = (canvas.width - drawWidth) / 2;
  577. y = 0;
  578. } else
  579. {
  580. drawWidth = canvas.width;
  581. drawHeight = imageHeight * (drawWidth / imageWidth);
  582. x = 0;
  583. y = (canvas.height - drawHeight) / 2;
  584. }
  585. break;
  586. case 90:
  587. if (imageWidth / imageHeight > canvasRate)
  588. {
  589. drawWidth = canvas.height;
  590. drawHeight = imageHeight * (drawWidth / imageWidth);
  591. x = 0;
  592. y = -(drawHeight + canvas.width) / 2;
  593. } else
  594. {
  595. drawHeight = canvas.width;
  596. drawWidth = imageWidth * (drawHeight / imageHeight);
  597. x = (canvas.height - drawWidth) / 2;
  598. y = -drawHeight;
  599. }
  600. break;
  601. case 180:
  602. if (imageHeight / imageWidth > canvasRate)
  603. {
  604. drawHeight = canvas.height;
  605. drawWidth = imageWidth * (drawHeight / imageHeight);
  606. x = -(drawWidth + canvas.width) / 2;
  607. y = -drawHeight;
  608. } else
  609. {
  610. drawWidth = canvas.width;
  611. drawHeight = imageHeight * (drawWidth / imageWidth);
  612. x = -drawWidth;
  613. y = -(drawHeight + canvas.height) / 2;
  614. }
  615. break;
  616. case 270:
  617. if (imageWidth / imageHeight > canvasRate)
  618. {
  619. drawWidth = canvas.height;
  620. drawHeight = imageHeight * (drawWidth / imageWidth);
  621. x = -drawWidth;
  622. y = (canvas.width - drawHeight) / 2;
  623. } else
  624. {
  625. drawHeight = canvas.width;
  626. drawWidth = imageWidth * (drawHeight / imageHeight);
  627. x = -(drawWidth + canvas.height) / 2;
  628. y = 0;
  629. }
  630. break;
  631. }
  632. context.clearRect(0, 0, canvas.width, canvas.height);
  633. context.save();
  634. context.rotate(r * Math.PI / 180);
  635. context.drawImage(editImage, x, y, drawWidth, drawHeight);
  636. context.restore();
  637. editImage.parentNode.insertBefore(canvas, editImage.parentNode.childNodes[0]);
  638. editImage.setAttribute("data-rotate", r);
  639. };
  640. layer.myPrompt = function (options, yes) {
  641. options = options || {};
  642. if (typeof options === 'function')
  643. yes = options;
  644. var prompt, content = options.formType == 2 ? '<textarea class="layui-layer-input">' + (options.value || '') + '</textarea>' : function () {
  645. return '<input type="' + (options.formType == 1 ? 'password' : 'text') + '" class="layui-layer-input" value="' + (options.value || '') + '">';
  646. }();
  647. return layer.open($.extend({
  648. btn: ['&#x786E;&#x5B9A;', '&#x53D6;&#x6D88;'],
  649. content: content,
  650. skin: 'layui-layer-prompt',
  651. success: function (layero) {
  652. prompt = layero.find('.layui-layer-input');
  653. prompt.focus();
  654. }, yes: function (index) {
  655. var value = prompt.val();
  656. if (value.length > (options.maxlength || 500)) {
  657. layer.tips('&#x6700;&#x591A;&#x8F93;&#x5165;' + (options.maxlength || 500) + '&#x4E2A;&#x5B57;&#x6570;', prompt, {tips: 1});
  658. } else {
  659. yes && yes(value, index, prompt);
  660. }
  661. }
  662. }, options));
  663. };
  664. },
  665. recyclebin: function () {
  666. $(document).on('click', '.recover_item', function () {
  667. var this_item = $(this);
  668. var item_id = $(this).parent().parent().parent().attr('id');
  669. $.ajax({
  670. url: '/service/recover_item/' + bookId,
  671. type: "POST",
  672. data: {id: bookId, action: "recover_item", item_id: item_id},
  673. success: function (response) {
  674. var remove_item = this_item.parent().parent().parent();
  675. remove_item.fadeTo(300, 0, function () {
  676. remove_item.remove();
  677. });
  678. }
  679. });
  680. });
  681. $(document).on('click', '.recover_photo', function () {
  682. var this_item = $(this);
  683. var item_id = $(this).parent().parent().parent().attr('id');
  684. var photo_id = $(this).parent().attr('id');
  685. $.ajax({
  686. url: '/service/recover_photo/' + bookId,
  687. type: "POST",
  688. data: {id: bookId, action: "recover_photo", item_id: item_id, photo_id: photo_id},
  689. success: function (response) {
  690. if (this_item.parent().parent().find('.msg_photo').length == 1) {
  691. this_item.parent().parent().parent().fadeTo(300, 0, function () {
  692. this_item.parent().parent().parent().remove();
  693. });
  694. } else {
  695. this_item.parent().fadeTo(300, 0, function () {
  696. this_item.parent().remove();
  697. });
  698. }
  699. }
  700. });
  701. });
  702. }
  703. };
  704. return Controller;
  705. });