| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
- var Controller = {
- index: function () {
- // 初始化表格参数配置
- Table.api.init({
- extend: {
- index_url: 'ps/template/index' + location.search,
- add_url: 'ps/template/add',
- edit_url: 'ps/template/edit',
- del_url: 'ps/template/del',
- multi_url: 'ps/template/multi',
- import_url: 'ps/template/import',
- table: 'ps_template',
- }
- });
- var table = $("#table");
- // 初始化表格
- table.bootstrapTable({
- url: $.fn.bootstrapTable.defaults.extend.index_url,
- pk: 'id',
- sortName: 'template.id',
- fixedColumns: true,
- fixedRightNumber: 1,
- columns: [
- [
- {checkbox: true},
- {field: 'id', title: __('Id')},
- {field: 'factory.name', title: __('Factory_id'), operate: 'LIKE', formatter: function (value, row) {
- if (!row.factory_id || parseInt(row.factory_id, 10) === 0) {
- return '官方';
- }
- return value || '';
- }},
- {field: 'name', title: __('Name'), operate: 'LIKE'},
- {field: 'cover', title: __('Cover'), events: Table.api.events.image, formatter: Table.api.formatter.image, operate: false},
- {field: 'paper_size', title: __('Paper_size'), operate: 'LIKE'},
- {field: 'page_w', title: __('Page_w'), operate: false},
- {field: 'page_h', title: __('Page_h'), operate: false},
- {field: 'source', title: __('Source'), searchList: {"manual":__('Manual'),"ai":__('Ai'),"system":__('System'),"market":__('Market')}, formatter: Table.api.formatter.normal},
- {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},
- {field: 'locked', title: __('Locked'), searchList: {"1":__('Yes'),"0":__('No')}, formatter: Table.api.formatter.toggle},
- {field: 'is_system', title: __('Is_system'), searchList: {"1":__('Yes'),"0":__('No')}, formatter: Table.api.formatter.toggle},
- {field: 'status', title: __('Status'), searchList: {"normal":__('Normal'),"hidden":__('Hidden')}, formatter: Table.api.formatter.status},
- {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
- {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate, buttons: [
- {
- name: 'preview',
- text: '识版结果',
- title: '识版结果',
- classname: 'btn btn-xs btn-info btn-dialog',
- icon: 'fa fa-th',
- url: 'ps/template/preview',
- extend: 'data-area=\'["96%","96%"]\''
- },
- {
- name: 'rebuild',
- text: '重新识别',
- classname: 'btn btn-xs btn-warning btn-ajax',
- icon: 'fa fa-refresh',
- url: 'ps/template/rebuild',
- confirm: '将按当前标准图和色块图重新识版并覆盖格子,确定继续?',
- success: function () {
- table.bootstrapTable('refresh');
- }
- }
- ]}
- ]
- ]
- });
- // 为表格绑定事件
- Table.api.bindevent(table);
- $(".btn-add").data("area", ["920px", "92%"]);
- },
- add: function () {
- var papers = {
- A4: {w: 210, h: 297, pxw: 2480, pxh: 3508},
- A5: {w: 148, h: 210, pxw: 1748, pxh: 2480}
- };
- var $size = $("#c-paper_size");
- var $w = $("#c-page_w");
- var $h = $("#c-page_h");
- var $hint = $("#paper-px-hint");
- var applyPaper = function () {
- var key = $size.val();
- var item = papers[key];
- if (item) {
- $w.val(item.w).prop("readonly", true);
- $h.val(item.h).prop("readonly", true);
- $hint.text("300DPI 建议像素约 " + item.pxw + " × " + item.pxh + "。标准图应铺满整张纸,比例需与纸张一致。");
- return;
- }
- $w.prop("readonly", false);
- $h.prop("readonly", false);
- var mmW = parseFloat($w.val()) || 0;
- var mmH = parseFloat($h.val()) || 0;
- var pxw = Math.round(mmW / 25.4 * 300);
- var pxh = Math.round(mmH / 25.4 * 300);
- $hint.text("自定义 " + mmW + " × " + mmH + " mm,300DPI 约 " + pxw + " × " + pxh + " px。");
- };
- $size.on("change", applyPaper);
- $w.add($h).on("input", applyPaper);
- applyPaper();
- Form.api.bindevent($("form[role=form]"), function (data, ret) {
- var id = ret.data && ret.data.template_id;
- if (id) {
- parent.Fast.api.open("ps/template/preview?ids=" + id, "识版结果", {area: ["96%", "96%"]});
- }
- });
- },
- edit: function () {
- Controller.api.bindevent();
- },
- preview: function () {
- var id = $(".ps-preview").data("id");
- $("#btn-rebuild").on("click", function () {
- Layer.confirm("将按当前标准图和色块图重新识版并覆盖格子,确定继续?", function (index) {
- Layer.close(index);
- var load = Layer.load(1, {shade: [0.2, "#000"]});
- Fast.api.ajax({
- url: "ps/template/rebuild",
- data: {ids: id},
- timeout: 180000
- }, function (data, ret) {
- Layer.close(load);
- Toastr.success(ret.msg || "已重新识别");
- location.reload();
- return false;
- }, function () {
- Layer.close(load);
- });
- });
- });
- },
- api: {
- bindevent: function () {
- Form.api.bindevent($("form[role=form]"));
- }
- }
- };
- return Controller;
- });
|