diff --git a/dolphinscheduler-ui-next/src/locales/modules/en_US.ts b/dolphinscheduler-ui-next/src/locales/modules/en_US.ts index 8ba27c7349..f61eb95d84 100644 --- a/dolphinscheduler-ui-next/src/locales/modules/en_US.ts +++ b/dolphinscheduler-ui-next/src/locales/modules/en_US.ts @@ -1242,7 +1242,8 @@ const datasource = { user_name: 'User Name', user_name_tips: 'Please enter your username', user_password: 'Password', - user_password_tips: 'Please enter your password' + user_password_tips: 'Please enter your password', + jdbc_format_tips: 'jdbc connection parameters is not a correct JSON format' } const data_quality = { diff --git a/dolphinscheduler-ui-next/src/locales/modules/zh_CN.ts b/dolphinscheduler-ui-next/src/locales/modules/zh_CN.ts index 73dbacbc4b..260c7e7dbe 100644 --- a/dolphinscheduler-ui-next/src/locales/modules/zh_CN.ts +++ b/dolphinscheduler-ui-next/src/locales/modules/zh_CN.ts @@ -1227,7 +1227,8 @@ const datasource = { user_name: '用户名', user_name_tips: '请输入用户名', user_password: '密码', - user_password_tips: '请输入密码' + user_password_tips: '请输入密码', + jdbc_format_tips: 'jdbc连接参数不是一个正确的JSON格式' } const data_quality = { diff --git a/dolphinscheduler-ui-next/src/utils/index.ts b/dolphinscheduler-ui-next/src/utils/index.ts index afce8157fc..f164e025fa 100644 --- a/dolphinscheduler-ui-next/src/utils/index.ts +++ b/dolphinscheduler-ui-next/src/utils/index.ts @@ -22,6 +22,7 @@ import log from './log' import downloadFile from './downloadFile' import copy from './clipboard' import removeUselessChildren from './tree-format' +import isJson from './json' const utils = { mapping, @@ -30,7 +31,8 @@ const utils = { log, downloadFile, copy, - removeUselessChildren + removeUselessChildren, + isJson } export default utils diff --git a/dolphinscheduler-ui-next/src/utils/json.ts b/dolphinscheduler-ui-next/src/utils/json.ts new file mode 100644 index 0000000000..3ce941ddb5 --- /dev/null +++ b/dolphinscheduler-ui-next/src/utils/json.ts @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Verify if it is in json format + */ +const isJson = (str: string) => { + if (typeof str === 'string') { + try { + const obj = JSON.parse(str) + if (typeof obj === 'object' && obj) { + return true + } else { + return false + } + } catch (e) { + return false + } + } +} + +export default isJson diff --git a/dolphinscheduler-ui-next/src/views/datasource/list/use-form.ts b/dolphinscheduler-ui-next/src/views/datasource/list/use-form.ts index 6ac6e31e5d..e1c427875f 100644 --- a/dolphinscheduler-ui-next/src/views/datasource/list/use-form.ts +++ b/dolphinscheduler-ui-next/src/views/datasource/list/use-form.ts @@ -26,6 +26,7 @@ import type { IDataBaseOptionKeys, IDataSource } from './types' +import utils from '@/utils' export function useForm(id?: number) { const { t } = useI18n() @@ -109,6 +110,14 @@ export function useForm(id?: number) { return new Error(t('datasource.oracle_connect_type_tips')) } } + }, + other: { + trigger: ['input', 'blur'], + validator() { + if (state.detailForm.other && !utils.isJson(state.detailForm.other)) { + return new Error(t('datasource.jdbc_format_tips')) + } + } } } as FormRules })