template.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. extend: {
  7. index_url: 'ps/template/index' + location.search,
  8. add_url: 'ps/template/add',
  9. edit_url: 'ps/template/edit',
  10. del_url: 'ps/template/del',
  11. multi_url: 'ps/template/multi',
  12. import_url: 'ps/template/import',
  13. table: 'ps_template',
  14. }
  15. });
  16. var table = $("#table");
  17. // 初始化表格
  18. table.bootstrapTable({
  19. url: $.fn.bootstrapTable.defaults.extend.index_url,
  20. pk: 'id',
  21. sortName: 'template.id',
  22. fixedColumns: true,
  23. fixedRightNumber: 1,
  24. columns: [
  25. [
  26. {checkbox: true},
  27. {field: 'id', title: __('Id')},
  28. {field: 'factory.name', title: __('Factory_id'), operate: 'LIKE', formatter: function (value, row) {
  29. if (!row.factory_id || parseInt(row.factory_id, 10) === 0) {
  30. return '官方';
  31. }
  32. return value || '';
  33. }},
  34. {field: 'name', title: __('Name'), operate: 'LIKE'},
  35. {field: 'cover', title: __('Cover'), events: Table.api.events.image, formatter: Table.api.formatter.image, operate: false},
  36. {field: 'paper_size', title: __('Paper_size'), operate: 'LIKE'},
  37. {field: 'page_w', title: __('Page_w'), operate: false},
  38. {field: 'page_h', title: __('Page_h'), operate: false},
  39. {field: 'source', title: __('Source'), searchList: {"manual":__('Manual'),"ai":__('Ai'),"system":__('System'),"market":__('Market')}, formatter: Table.api.formatter.normal},
  40. {field: 'license_type', title: __('License_type'), searchList: {"self":__('Self'),"system_copy":__('System_copy'),"market_single":__('Market_single'),"market_buyout":__('Market_buyout')}, formatter: Table.api.formatter.normal},
  41. {field: 'locked', title: __('Locked'), searchList: {"1":__('Yes'),"0":__('No')}, formatter: Table.api.formatter.toggle},
  42. {field: 'is_system', title: __('Is_system'), searchList: {"1":__('Yes'),"0":__('No')}, formatter: Table.api.formatter.toggle},
  43. {field: 'status', title: __('Status'), searchList: {"normal":__('Normal'),"hidden":__('Hidden')}, formatter: Table.api.formatter.status},
  44. {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  45. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate, buttons: [
  46. {
  47. name: 'preview',
  48. text: '识版结果',
  49. title: '识版结果',
  50. classname: 'btn btn-xs btn-info btn-dialog',
  51. icon: 'fa fa-th',
  52. url: 'ps/template/preview',
  53. extend: 'data-area=\'["96%","96%"]\''
  54. },
  55. {
  56. name: 'rebuild',
  57. text: '重新识别',
  58. classname: 'btn btn-xs btn-warning btn-ajax',
  59. icon: 'fa fa-refresh',
  60. url: 'ps/template/rebuild',
  61. confirm: '将按当前标准图和色块图重新识版并覆盖格子,确定继续?',
  62. success: function () {
  63. table.bootstrapTable('refresh');
  64. }
  65. }
  66. ]}
  67. ]
  68. ]
  69. });
  70. // 为表格绑定事件
  71. Table.api.bindevent(table);
  72. $(".btn-add").data("area", ["920px", "92%"]);
  73. },
  74. add: function () {
  75. var papers = {
  76. A4: {w: 210, h: 297, pxw: 2480, pxh: 3508},
  77. A5: {w: 148, h: 210, pxw: 1748, pxh: 2480}
  78. };
  79. var $size = $("#c-paper_size");
  80. var $w = $("#c-page_w");
  81. var $h = $("#c-page_h");
  82. var $hint = $("#paper-px-hint");
  83. var applyPaper = function () {
  84. var key = $size.val();
  85. var item = papers[key];
  86. if (item) {
  87. $w.val(item.w).prop("readonly", true);
  88. $h.val(item.h).prop("readonly", true);
  89. $hint.text("300DPI 建议像素约 " + item.pxw + " × " + item.pxh + "。标准图应铺满整张纸,比例需与纸张一致。");
  90. return;
  91. }
  92. $w.prop("readonly", false);
  93. $h.prop("readonly", false);
  94. var mmW = parseFloat($w.val()) || 0;
  95. var mmH = parseFloat($h.val()) || 0;
  96. var pxw = Math.round(mmW / 25.4 * 300);
  97. var pxh = Math.round(mmH / 25.4 * 300);
  98. $hint.text("自定义 " + mmW + " × " + mmH + " mm,300DPI 约 " + pxw + " × " + pxh + " px。");
  99. };
  100. $size.on("change", applyPaper);
  101. $w.add($h).on("input", applyPaper);
  102. applyPaper();
  103. Form.api.bindevent($("form[role=form]"), function (data, ret) {
  104. var id = ret.data && ret.data.template_id;
  105. if (id) {
  106. parent.Fast.api.open("ps/template/preview?ids=" + id, "识版结果", {area: ["96%", "96%"]});
  107. }
  108. });
  109. },
  110. edit: function () {
  111. Controller.api.bindevent();
  112. },
  113. preview: function () {
  114. var id = $(".ps-preview").data("id");
  115. $("#btn-rebuild").on("click", function () {
  116. Layer.confirm("将按当前标准图和色块图重新识版并覆盖格子,确定继续?", function (index) {
  117. Layer.close(index);
  118. var load = Layer.load(1, {shade: [0.2, "#000"]});
  119. Fast.api.ajax({
  120. url: "ps/template/rebuild",
  121. data: {ids: id},
  122. timeout: 180000
  123. }, function (data, ret) {
  124. Layer.close(load);
  125. Toastr.success(ret.msg || "已重新识别");
  126. location.reload();
  127. return false;
  128. }, function () {
  129. Layer.close(load);
  130. });
  131. });
  132. });
  133. },
  134. api: {
  135. bindevent: function () {
  136. Form.api.bindevent($("form[role=form]"));
  137. }
  138. }
  139. };
  140. return Controller;
  141. });