diff --git a/app/controller/admin/system/ConfigController.php b/app/controller/admin/system/ConfigController.php index f1ead3d..56383bf 100644 --- a/app/controller/admin/system/ConfigController.php +++ b/app/controller/admin/system/ConfigController.php @@ -5,6 +5,8 @@ namespace app\controller\admin\system; use app\BaseController; use app\entity\SysConfig; use app\service\CurdService; +use think\db\exception\DataNotFoundException; +use think\db\exception\ModelNotFoundException; use think\response\Json; class ConfigController extends BaseController @@ -29,7 +31,22 @@ class ConfigController extends BaseController return $this->writeSuccess('success', $config->toArray()); } - + public function existence() + { + $id = $this->request->get('id/d',0); + $field = $this->request->get('field/s', ''); + $value = $this->request->get('value/s', ''); + try { + $model = SysConfig::field('id'); + if($id > 0) { + $model = $model->where('id', '<>', $id); + } + $model->where([$field => $value])->findOrFail(); + } catch (ModelNotFoundException|DataNotFoundException) { + return $this->writeError("配置不存在"); + } + return $this->writeSuccess('配置已存在'); + } public function add() { $data = $this->request->post([ diff --git a/route/api.php b/route/api.php index 03c0c79..569a499 100644 --- a/route/api.php +++ b/route/api.php @@ -70,6 +70,8 @@ Route::group("adminapi", function () { */ Route::get('config$', [ConfigController::class, "list"])->name("system.listConfig"); Route::get('config/data', [ConfigController::class, "data"])->name("system.getConfigData"); + Route::get('config/existence', [ConfigController::class, "existence"])->name("system.configExistence"); + Route::post("config", [ConfigController::class, "add"])->name("system.addConfig"); Route::put("config$", [ConfigController::class, "update"])->name("system.updateConfig"); Route::delete("config/batch", [ConfigController::class, "batchDelete"])->name("system.batchDeleteConfig"); diff --git a/z_ele/src/api/system/config/index.ts b/z_ele/src/api/system/config/index.ts index 4c37775..760dc10 100644 --- a/z_ele/src/api/system/config/index.ts +++ b/z_ele/src/api/system/config/index.ts @@ -77,3 +77,19 @@ export async function removeConfigs(ids: number[]) { } return Promise.reject(new Error(res.data.message)); } +/** + * 检查配置是否存在 + */ +export async function checkExistence( + field: string, + value: string, + id?: number +) { + const res = await request.get>('/system/config/existence', { + params: { field, value, id } + }); + if (res.data.code === 0) { + return res.data.message; + } + return Promise.reject(new Error(res.data.message)); +} diff --git a/z_ele/src/views/system/config/components/config-edit.vue b/z_ele/src/views/system/config/components/config-edit.vue index 13cdee6..181371b 100644 --- a/z_ele/src/views/system/config/components/config-edit.vue +++ b/z_ele/src/views/system/config/components/config-edit.vue @@ -82,7 +82,7 @@ - + - + - - + - +