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 {