define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) { var Controller = { index: function () { // 初始化表格参数配置 Table.api.init({ extend: { index_url: 'ps/ai_job/index' + location.search, add_url: 'ps/ai_job/add', edit_url: 'ps/ai_job/edit', del_url: 'ps/ai_job/del', multi_url: 'ps/ai_job/multi', import_url: 'ps/ai_job/import', table: 'ps_ai_job', } }); var table = $("#table"); // 初始化表格 table.bootstrapTable({ url: $.fn.bootstrapTable.defaults.extend.index_url, pk: 'id', sortName: 'ai_job.id', fixedColumns: true, fixedRightNumber: 1, columns: [ [ {checkbox: true}, {field: 'id', title: __('Id')}, {field: 'factory.name', title: __('Factory_id'), operate: 'LIKE'}, {field: 'user_id', title: __('User_id')}, {field: 'file_url', title: __('File_url'), operate: false, events: Table.api.events.image, formatter: function (value, row, index) { if (!value) { return '-'; } if (row.file_type === 'pdf') { return Table.api.formatter.url.call(this, value, row, index); } var url = Fast.api.cdnurl(value); return ''; }}, {field: 'file_type', title: __('File_type'), searchList: {"image":__('Image'),"pdf":__('Pdf')}, formatter: Table.api.formatter.normal}, {field: 'status', title: __('Status'), searchList: {"pending":__('Pending'),"running":__('Running'),"success":__('Success'),"fail":__('Fail')}, formatter: Table.api.formatter.status}, {field: 'model', title: __('Model'), operate: 'LIKE'}, {field: 'error_msg', title: __('Error_msg'), operate: 'LIKE'}, {field: 'template_id', title: __('Template_id')}, {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime}, {field: 'updatetime', title: __('Updatetime'), 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: __('Preview_template'), icon: 'fa fa-image', classname: 'btn btn-xs btn-success btn-click', visible: function (row) { return !!row.file_url && row.file_type !== 'pdf'; }, click: function (options, row) { Layer.photos({ photos: { data: [{src: Fast.api.cdnurl(row.file_url)}] } }); } }, { name: 'run', text: __('Recognize'), icon: 'fa fa-play', classname: 'btn btn-xs btn-info btn-ajax', url: 'ps/ai_job/run', refresh: true, confirm: __('Recognize_confirm'), extend: 'data-timeout="320000"', visible: function (row) { return row.status === 'pending' || row.status === 'fail'; } } ]} ] ] }); // 为表格绑定事件 Table.api.bindevent(table); }, add: function () { Controller.api.syncFileAndModel(); Controller.api.bindevent(); }, edit: function () { Controller.api.syncFileAndModel(); Controller.api.bindevent(); }, api: { bindevent: function () { Form.api.bindevent($("form[role=form]")); }, syncFileAndModel: function () { var apply = function (force) { var file = $("#c-file_url").val() || ''; if (/\.pdf$/i.test(file)) { $("input[name='row[file_type]'][value='pdf']").prop("checked", true); } else if (file) { $("input[name='row[file_type]'][value='image']").prop("checked", true); } var type = $("input[name='row[file_type]']:checked").val() || 'image'; var $model = $("#c-model"); if (!$model.length) { return; } var next = type === 'pdf' ? $model.data("text") : $model.data("vision"); if (next && (force || !$model.val())) { $model.val(next); } }; $("#c-file_url").on("change blur", function () { apply(true); }); $(document).on("change", "input[name='row[file_type]']", function () { apply(true); }); } } }; return Controller; });