| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- 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 '<a href="javascript:"><img class="img-center" src="' + url + '" style="max-height:140px;max-width:200px;border:1px solid #eee;padding:2px;background:#fff;"></a>';
- }},
- {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;
- });
|