ai_job.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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/ai_job/index' + location.search,
  8. add_url: 'ps/ai_job/add',
  9. edit_url: 'ps/ai_job/edit',
  10. del_url: 'ps/ai_job/del',
  11. multi_url: 'ps/ai_job/multi',
  12. import_url: 'ps/ai_job/import',
  13. table: 'ps_ai_job',
  14. }
  15. });
  16. var table = $("#table");
  17. // 初始化表格
  18. table.bootstrapTable({
  19. url: $.fn.bootstrapTable.defaults.extend.index_url,
  20. pk: 'id',
  21. sortName: 'ai_job.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'},
  29. {field: 'user_id', title: __('User_id')},
  30. {field: 'file_url', title: __('File_url'), operate: false, events: Table.api.events.image, formatter: function (value, row, index) {
  31. if (!value) {
  32. return '-';
  33. }
  34. if (row.file_type === 'pdf') {
  35. return Table.api.formatter.url.call(this, value, row, index);
  36. }
  37. var url = Fast.api.cdnurl(value);
  38. 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>';
  39. }},
  40. {field: 'file_type', title: __('File_type'), searchList: {"image":__('Image'),"pdf":__('Pdf')}, formatter: Table.api.formatter.normal},
  41. {field: 'status', title: __('Status'), searchList: {"pending":__('Pending'),"running":__('Running'),"success":__('Success'),"fail":__('Fail')}, formatter: Table.api.formatter.status},
  42. {field: 'model', title: __('Model'), operate: 'LIKE'},
  43. {field: 'error_msg', title: __('Error_msg'), operate: 'LIKE'},
  44. {field: 'template_id', title: __('Template_id')},
  45. {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  46. {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  47. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate, buttons: [
  48. {
  49. name: 'preview',
  50. text: __('Preview_template'),
  51. icon: 'fa fa-image',
  52. classname: 'btn btn-xs btn-success btn-click',
  53. visible: function (row) {
  54. return !!row.file_url && row.file_type !== 'pdf';
  55. },
  56. click: function (options, row) {
  57. Layer.photos({
  58. photos: {
  59. data: [{src: Fast.api.cdnurl(row.file_url)}]
  60. }
  61. });
  62. }
  63. },
  64. {
  65. name: 'run',
  66. text: __('Recognize'),
  67. icon: 'fa fa-play',
  68. classname: 'btn btn-xs btn-info btn-ajax',
  69. url: 'ps/ai_job/run',
  70. refresh: true,
  71. confirm: __('Recognize_confirm'),
  72. extend: 'data-timeout="320000"',
  73. visible: function (row) {
  74. return row.status === 'pending' || row.status === 'fail';
  75. }
  76. }
  77. ]}
  78. ]
  79. ]
  80. });
  81. // 为表格绑定事件
  82. Table.api.bindevent(table);
  83. },
  84. add: function () {
  85. Controller.api.syncFileAndModel();
  86. Controller.api.bindevent();
  87. },
  88. edit: function () {
  89. Controller.api.syncFileAndModel();
  90. Controller.api.bindevent();
  91. },
  92. api: {
  93. bindevent: function () {
  94. Form.api.bindevent($("form[role=form]"));
  95. },
  96. syncFileAndModel: function () {
  97. var apply = function (force) {
  98. var file = $("#c-file_url").val() || '';
  99. if (/\.pdf$/i.test(file)) {
  100. $("input[name='row[file_type]'][value='pdf']").prop("checked", true);
  101. } else if (file) {
  102. $("input[name='row[file_type]'][value='image']").prop("checked", true);
  103. }
  104. var type = $("input[name='row[file_type]']:checked").val() || 'image';
  105. var $model = $("#c-model");
  106. if (!$model.length) {
  107. return;
  108. }
  109. var next = type === 'pdf' ? $model.data("text") : $model.data("vision");
  110. if (next && (force || !$model.val())) {
  111. $model.val(next);
  112. }
  113. };
  114. $("#c-file_url").on("change blur", function () {
  115. apply(true);
  116. });
  117. $(document).on("change", "input[name='row[file_type]']", function () {
  118. apply(true);
  119. });
  120. }
  121. }
  122. };
  123. return Controller;
  124. });