From ee53941fb02d6011b77f3c5ab6b7517f17a47208 Mon Sep 17 00:00:00 2001 From: fit2bot <68588906+fit2bot@users.noreply.github.com> Date: Thu, 10 Jun 2021 19:05:08 +0800 Subject: [PATCH] =?UTF-8?q?fix(settings):=20=E4=BF=AE=E5=A4=8Dldap?= =?UTF-8?q?=E6=8F=90=E4=BA=A4=E6=97=B6=EF=BC=8Cjson=E6=8A=A5=E9=94=99=20(#?= =?UTF-8?q?836)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * perf: 修改命令存储创建 * fix(settings): 修复ldap提交时,json报错 Co-authored-by: ibuler --- src/components/DataForm/rules/index.js | 13 +++++++++++++ src/i18n/langs/cn.json | 3 ++- src/i18n/langs/en.json | 3 ++- src/views/settings/Ldap/index.vue | 6 ++++-- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/components/DataForm/rules/index.js b/src/components/DataForm/rules/index.js index 57fc7a3fe..eedbaa340 100644 --- a/src/components/DataForm/rules/index.js +++ b/src/components/DataForm/rules/index.js @@ -19,3 +19,16 @@ export default { RequiredChange, EmailCheck } + +export const JsonRequired = { + required: true, + trigger: 'change', + validator: (rule, value, callback) => { + try { + JSON.parse(value) + callback() + } catch (e) { + callback(new Error(i18n.t('common.InvalidJson'))) + } + } +} diff --git a/src/i18n/langs/cn.json b/src/i18n/langs/cn.json index 4f42a6262..15d4327d3 100644 --- a/src/i18n/langs/cn.json +++ b/src/i18n/langs/cn.json @@ -385,7 +385,8 @@ "SPECIAL_CHAR_REQUIRED": "须包含特殊字符", "MIN_LENGTH_ERROR": "密码最小长度 {0} 位" }, - "lastCannotBeDeleteMsg": "最后一项,不能被删除" + "lastCannotBeDeleteMsg": "最后一项,不能被删除", + "InvalidJson": "不是合法 JSON" }, "dashboard": { "ActiveAsset": "近期被登录过", diff --git a/src/i18n/langs/en.json b/src/i18n/langs/en.json index a29f36cc8..8894ff87d 100644 --- a/src/i18n/langs/en.json +++ b/src/i18n/langs/en.json @@ -383,7 +383,8 @@ "SPECIAL_CHAR_REQUIRED": "Special char required", "MIN_LENGTH_ERROR": "Password minimum length {}" }, - "lastCannotBeDeleteMsg": "The last one can't be delete" + "lastCannotBeDeleteMsg": "The last one can't be delete", + "InvalidJson": "Not a valid json format" }, "dashboard": { "ActiveAsset": "Asset active", diff --git a/src/views/settings/Ldap/index.vue b/src/views/settings/Ldap/index.vue index 1d4f17a39..f5f571123 100644 --- a/src/views/settings/Ldap/index.vue +++ b/src/views/settings/Ldap/index.vue @@ -20,6 +20,7 @@ import { testLdapSetting } from '@/api/settings' import ImportDialog from './ImportDialog' import TestLoginDialog from './TestLoginDialog' import { IBox } from '@/components' +import { JsonRequired } from '@/components/DataForm/rules' export default { name: 'Ldap', @@ -61,7 +62,8 @@ export default { el: { type: 'textarea' }, - label: this.$t('setting.authLdapUserAttrMap') + label: this.$t('setting.authLdapUserAttrMap'), + rules: [JsonRequired] } }, url: '/api/v1/settings/setting/?category=ldap', @@ -121,7 +123,7 @@ export default {