Bladeren bron

模板识别优化

unknown 1 maand geleden
bovenliggende
commit
c83504e3b2

+ 75 - 0
fastadmin/application/admin/controller/ps/Template.php

@@ -6,6 +6,7 @@ use app\common\controller\Backend;
 use app\common\library\ps\PaperSize;
 use app\common\library\ps\PrintPlanner;
 use app\common\library\ps\TemplateIngest;
+use think\Db;
 
 /**
  * 流程单-模板
@@ -70,6 +71,80 @@ class Template extends Backend
         $this->success($msg, null, $result);
     }
 
+    /**
+     * 识版结果:底图叠加格子,可重新识别
+     */
+    public function preview($ids = null)
+    {
+        $row = $this->model->get($ids);
+        if (!$row) {
+            $this->error(__('No Results were found'));
+        }
+        $versionId = (int)$row['current_version_id'];
+        $schemaJson = '';
+        if ($versionId > 0) {
+            $schemaJson = (string)Db::name('ps_template_version')->where('id', $versionId)->value('schema_json');
+        }
+        $schema = PrintPlanner::decodeSchema($schemaJson, (string)$row['cover']);
+        $raw = [];
+        if (!empty($schema['elements']) && is_array($schema['elements'])) {
+            $raw = $schema['elements'];
+        } elseif (!empty($schema['cells']) && is_array($schema['cells'])) {
+            $raw = $schema['cells'];
+        }
+        $cells = [];
+        $unlabeled = 0;
+        foreach ($raw as $i => $el) {
+            if (!is_array($el)) {
+                continue;
+            }
+            $key = trim((string)($el['key'] ?? ''));
+            if ($key === '') {
+                $unlabeled++;
+            }
+            $cells[] = [
+                'n'       => $i + 1,
+                'id'      => (string)($el['id'] ?? ''),
+                'label'   => (string)($el['label'] ?? $el['text'] ?? ''),
+                'key'     => $key,
+                'x'       => round((float)($el['x'] ?? 0), 2),
+                'y'       => round((float)($el['y'] ?? 0), 2),
+                'w'       => round((float)($el['w'] ?? 0), 2),
+                'h'       => round((float)($el['h'] ?? 0), 2),
+                'unbound' => $key === '',
+            ];
+        }
+        $this->view->assign('row', $row);
+        $this->view->assign('cells', $cells);
+        $this->view->assign('cellCount', count($cells));
+        $this->view->assign('unlabeled', $unlabeled);
+        $this->view->assign('cover', (string)$row['cover']);
+        $this->view->assign('markCover', (string)$row['mark_cover']);
+        $this->view->assign('paper', trim((string)$row['paper_size'] . ' ' . $row['page_w'] . '×' . $row['page_h'] . 'mm'));
+        return $this->view->fetch();
+    }
+
+    /**
+     * 按当前标准图 / 色块图重新识版
+     */
+    public function rebuild($ids = null)
+    {
+        $ids = $ids ?: $this->request->param('ids');
+        if (!$ids) {
+            $this->error(__('Parameter %s can not be empty', 'ids'));
+        }
+        try {
+            $result = TemplateIngest::rebuild($ids);
+        } catch (\Exception $e) {
+            $this->error($e->getMessage());
+        }
+        $msg = '已重新识别,共 ' . $result['cells'] . ' 个格';
+        if (!empty($result['unlabeled'])) {
+            $msg .= ',其中 ' . $result['unlabeled'] . ' 个未绑定字段';
+        }
+        $this->success($msg, null, $result);
+    }
+
     /**
      * 查看
      */

+ 2 - 0
fastadmin/application/admin/lang/zh-cn/ps/template.php

@@ -31,4 +31,6 @@ return [
     'Market_buyout'      => '商城买断',
     'Createtime'         => '创建时间',
     'Updatetime'         => '更新时间',
+    'Preview'            => '识版结果',
+    'Rebuild'            => '重新识别',
 ];

+ 16 - 3
fastadmin/application/common/library/ps/TemplateIngest.php

@@ -201,7 +201,7 @@ class TemplateIngest
                 'h'      => $cell['h'],
                 'border' => false,
             ], 1);
-        }
+        } 
         $schema = PrintPlanner::decodeSchema(json_encode([
             'name'       => $row['name'],
             'title'      => $row['name'],
@@ -223,12 +223,25 @@ class TemplateIngest
 
         $versionId = (int)$row['current_version_id'];
         $now = time();
+        $payload = json_encode($schema, JSON_UNESCAPED_UNICODE);
         if ($versionId > 0) {
             Db::name('ps_template_version')->where('id', $versionId)->update([
-                'schema_json' => json_encode($schema, JSON_UNESCAPED_UNICODE),
+                'schema_json' => $payload,
+            ]);
+        } else {
+            $versionId = (int)Db::name('ps_template_version')->insertGetId([
+                'template_id' => (int)$templateId,
+                'factory_id'  => (int)$row['factory_id'],
+                'version'     => 1,
+                'schema_json' => $payload,
+                'remark'      => '重新识版',
+                'createtime'  => $now,
             ]);
         }
-        Db::name('ps_template')->where('id', (int)$templateId)->update(['updatetime' => $now]);
+        Db::name('ps_template')->where('id', (int)$templateId)->update([
+            'current_version_id' => $versionId,
+            'updatetime'         => $now,
+        ]);
         $unlabeled = 0;
         foreach ($schema['cells'] as $cell) {
             if (trim((string)($cell['key'] ?? '')) === '') {

+ 49 - 2
fastadmin/public/assets/js/backend/ps/template.js

@@ -45,7 +45,28 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                         {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}
+                        {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');
+                                }
+                            }
+                        ]}
                     ]
                 ]
             });
@@ -83,11 +104,37 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
             $size.on("change", applyPaper);
             $w.add($h).on("input", applyPaper);
             applyPaper();
-            Controller.api.bindevent();
+            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]"));

File diff suppressed because it is too large
+ 1462 - 1500
vue/package-lock.json


Some files were not shown because too many files changed in this diff