From 69a7f0fabf45842eed4e28e0de129fc2a3c2243a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=92=8C?= <496631085@qq.com> Date: Fri, 12 May 2023 02:44:54 +0000 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=B8=80=E9=94=AE=E7=94=9F?= =?UTF-8?q?=E6=88=90=E4=BB=A3=E7=A0=81=20=E4=BD=BF=E7=94=A8=E5=A4=87?= =?UTF-8?q?=E6=B3=A8=E7=94=9F=E6=88=90=E4=B8=8B=E6=8B=89,=E5=8D=95?= =?UTF-8?q?=E9=80=89,=E5=A4=8D=E9=80=89=E7=AD=89=E5=AF=B9=E5=BA=94?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=20=E7=A4=BA=E4=BE=8B"=E7=8A=B6=E6=80=81:0=3D?= =?UTF-8?q?=E5=85=B3=E9=97=AD,1=3D=E5=BC=80=E5=90=AF,2=3D=E7=A6=81?= =?UTF-8?q?=E6=AD=A2",=E6=B3=A8=E9=87=8A=E9=87=8C=E9=9D=A2=E5=8C=85?= =?UTF-8?q?=E5=90=AB=E5=86=92=E5=8F=B7=E5=92=8C=E7=AD=89=E5=8F=B7(?= =?UTF-8?q?=E8=8B=B1=E6=96=87=E7=9A=84":","=3D")=E5=8D=B3=E5=8F=AF?= =?UTF-8?q?=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 小和 <496631085@qq.com> --- .../Service/System/AutocodeService.php | 39 ++++++++++++++++++- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/ApiServer/Backend/Service/System/AutocodeService.php b/ApiServer/Backend/Service/System/AutocodeService.php index e85c4a4..5a95ab7 100644 --- a/ApiServer/Backend/Service/System/AutocodeService.php +++ b/ApiServer/Backend/Service/System/AutocodeService.php @@ -284,7 +284,7 @@ class AutocodeService extends AbstractService foreach ($columns as $k => $column) { $row = $info; $row['key'] = $column['COLUMN_NAME']; - $row['name'] = $column['COLUMN_COMMENT'] ?: $row['key']; + $row['name'] = $this->getCommentName($column['COLUMN_COMMENT']) ?: $row['key']; $row['table'] = (bool)$this->getTableType($column); $row['table_type'] = $this->getTableType($column); $row['save'] = (bool)$this->getSaveType($column); @@ -404,7 +404,9 @@ class AutocodeService extends AbstractService protected function getSaveOption($v) { $type = $this->getSaveType($v); - if ($type == 'radio') { + if (str_contains($v['COLUMN_COMMENT'], ':') && str_contains($v['COLUMN_COMMENT'], '=')) { + return $this->getCommentJson($v['COLUMN_COMMENT']); + } elseif ($type == 'radio') { if (str_contains($v['COLUMN_TYPE'], 'enum(')) { $enum = str_replace(["enum(", ")", '"', "'"], '', $v['COLUMN_TYPE']); $enum = explode(',', $enum); @@ -492,4 +494,37 @@ class AutocodeService extends AbstractService include $path . $template . '.tpl'; return ob_get_clean(); } + + protected function getCommentName($comment = '') + { + if ($comment) { + if (str_contains($comment, ':') && str_contains($comment, '=')) { + list($commentName, $item) = explode(':', $comment); + } else { + return $comment; + } + return $commentName; + } + return false; + } + + protected function getCommentJson($comment) + { + list($commentName, $item) = explode(':', $comment); + $item = str_replace(",", ',', $item); + $arr = explode(',', $item); + $new = json_decode('{}'); + foreach ($arr as $val) { + $data = explode('=', $val); + if (sizeof($data) == 1) { + $k = $v = $data[0]; + } else { + $k = $data[0]; + $v = $data[1]; + } + $s = strval($k); + $new->$s = $v; + } + return json_encode($new, JSON_UNESCAPED_UNICODE); + } } -- Gitee