From 1acd01d9f1977c9d1cbef534b8b7733f14d8979a Mon Sep 17 00:00:00 2001 From: walkor Date: Fri, 9 Dec 2022 11:49:49 +0800 Subject: [PATCH] save --- src/plugin/admin/app/controller/DictController.php | 14 +++++++++++--- src/plugin/admin/app/view/dict/insert.html | 2 +- src/plugin/admin/app/view/dict/update.html | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/plugin/admin/app/controller/DictController.php b/src/plugin/admin/app/controller/DictController.php index 7a2df96..8366b10 100644 --- a/src/plugin/admin/app/controller/DictController.php +++ b/src/plugin/admin/app/controller/DictController.php @@ -35,7 +35,11 @@ class DictController extends Base public function insert(Request $request): Response { if ($request->method() === 'POST') { - $option_name = $this->dictNameToOptionName($request->post('name')); + $name = $request->post('name'); + if (!preg_match('/[a-zA-Z]/', $name)) { + return $this->json(1, '字典名只能包含字母'); + } + $option_name = $this->dictNameToOptionName($name); if (Option::where('name', $option_name)->first()) { return $this->json(1, '字典已经存在' . $option_name); } @@ -59,14 +63,18 @@ class DictController extends Base public function update(Request $request): Response { if ($request->method() === 'POST') { - $name = $this->dictNameToOptionName($request->post('name', '')); + $name = $request->post('name'); + if (!preg_match('/[a-zA-Z]/', $name)) { + return $this->json(1, '字典名只能包含字母'); + } + $name = $this->dictNameToOptionName($name); $option = Option::where('name', $name)->first(); if (!$option) { return $this->json(1, '字典不存在'); } $format_values = $this->filterValue($request->post('value')); $option->name = $this->dictNameToOptionName($request->post('name')); - $option->value = $format_values; + $option->value = json_encode($format_values, JSON_UNESCAPED_UNICODE); $option->save(); } return view('dict/update'); diff --git a/src/plugin/admin/app/view/dict/insert.html b/src/plugin/admin/app/view/dict/insert.html index 5040b79..9be9286 100644 --- a/src/plugin/admin/app/view/dict/insert.html +++ b/src/plugin/admin/app/view/dict/insert.html @@ -41,7 +41,7 @@
- +
diff --git a/src/plugin/admin/app/view/dict/update.html b/src/plugin/admin/app/view/dict/update.html index d990c36..ea3e54a 100644 --- a/src/plugin/admin/app/view/dict/update.html +++ b/src/plugin/admin/app/view/dict/update.html @@ -41,7 +41,7 @@
- +