template.js 5.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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}
  46. ]
  47. ]
  48. });
  49. // 为表格绑定事件
  50. Table.api.bindevent(table);
  51. $(".btn-add").data("area", ["920px", "92%"]);
  52. },
  53. add: function () {
  54. var papers = {
  55. A4: {w: 210, h: 297, pxw: 2480, pxh: 3508},
  56. A5: {w: 148, h: 210, pxw: 1748, pxh: 2480}
  57. };
  58. var $size = $("#c-paper_size");
  59. var $w = $("#c-page_w");
  60. var $h = $("#c-page_h");
  61. var $hint = $("#paper-px-hint");
  62. var applyPaper = function () {
  63. var key = $size.val();
  64. var item = papers[key];
  65. if (item) {
  66. $w.val(item.w).prop("readonly", true);
  67. $h.val(item.h).prop("readonly", true);
  68. $hint.text("300DPI 建议像素约 " + item.pxw + " × " + item.pxh + "。标准图应铺满整张纸,比例需与纸张一致。");
  69. return;
  70. }
  71. $w.prop("readonly", false);
  72. $h.prop("readonly", false);
  73. var mmW = parseFloat($w.val()) || 0;
  74. var mmH = parseFloat($h.val()) || 0;
  75. var pxw = Math.round(mmW / 25.4 * 300);
  76. var pxh = Math.round(mmH / 25.4 * 300);
  77. $hint.text("自定义 " + mmW + " × " + mmH + " mm,300DPI 约 " + pxw + " × " + pxh + " px。");
  78. };
  79. $size.on("change", applyPaper);
  80. $w.add($h).on("input", applyPaper);
  81. applyPaper();
  82. Controller.api.bindevent();
  83. },
  84. edit: function () {
  85. Controller.api.bindevent();
  86. },
  87. api: {
  88. bindevent: function () {
  89. Form.api.bindevent($("form[role=form]"));
  90. }
  91. }
  92. };
  93. return Controller;
  94. });