From e702beced5edb567c5f14bec19be3b1697890145 Mon Sep 17 00:00:00 2001 From: songjianet <1778651752@qq.com> Date: Fri, 4 Nov 2022 13:38:40 +0800 Subject: [PATCH] [Feature][UI] Added form request parser. (#12691) --- .../dynamic-dag/task/use-form-field.ts | 2 +- .../dynamic-dag/task/use-form-request.ts | 39 +++++++++++++++++++ .../dynamic-dag/task/use-form-structure.ts | 2 +- .../dynamic-dag/task/use-form-validate.ts | 2 +- .../dynamic-dag/task/use-task-form.ts | 14 +++---- 5 files changed, 49 insertions(+), 10 deletions(-) create mode 100644 dolphinscheduler-ui/src/views/projects/workflow/components/dynamic-dag/task/use-form-request.ts diff --git a/dolphinscheduler-ui/src/views/projects/workflow/components/dynamic-dag/task/use-form-field.ts b/dolphinscheduler-ui/src/views/projects/workflow/components/dynamic-dag/task/use-form-field.ts index 0b195253e1..f4289158b6 100644 --- a/dolphinscheduler-ui/src/views/projects/workflow/components/dynamic-dag/task/use-form-field.ts +++ b/dolphinscheduler-ui/src/views/projects/workflow/components/dynamic-dag/task/use-form-field.ts @@ -18,7 +18,7 @@ import { ref } from 'vue' import type { Ref } from 'vue' -export function useFormField(forms: any) { +export function useFormField(forms: Array) { const model: any = {} const setField = (value: string, type: string): Ref => { diff --git a/dolphinscheduler-ui/src/views/projects/workflow/components/dynamic-dag/task/use-form-request.ts b/dolphinscheduler-ui/src/views/projects/workflow/components/dynamic-dag/task/use-form-request.ts new file mode 100644 index 0000000000..26cd524a94 --- /dev/null +++ b/dolphinscheduler-ui/src/views/projects/workflow/components/dynamic-dag/task/use-form-request.ts @@ -0,0 +1,39 @@ +/* + * 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. + */ + +import { axios } from '@/service/service' + +const reqFunction = (url: string, method: string) => { + return axios({ + url, + method + }) +} + +export function useFormRequest(apis: any, forms: Array) { + forms.map(f => { + if (f.api) { + reqFunction(apis[f.api].url, apis[f.api].method).then((res: any) => { + f.options = res.map((r: any) => { + return { label: r, value: r } + }) + }) + } + }) + + return forms +} \ No newline at end of file diff --git a/dolphinscheduler-ui/src/views/projects/workflow/components/dynamic-dag/task/use-form-structure.ts b/dolphinscheduler-ui/src/views/projects/workflow/components/dynamic-dag/task/use-form-structure.ts index dd6aa63c09..34166ac653 100644 --- a/dolphinscheduler-ui/src/views/projects/workflow/components/dynamic-dag/task/use-form-structure.ts +++ b/dolphinscheduler-ui/src/views/projects/workflow/components/dynamic-dag/task/use-form-structure.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -export function useFormStructure(forms: any) { +export function useFormStructure(forms: Array) { return forms.map((f: any) => { delete f.validate delete f.api diff --git a/dolphinscheduler-ui/src/views/projects/workflow/components/dynamic-dag/task/use-form-validate.ts b/dolphinscheduler-ui/src/views/projects/workflow/components/dynamic-dag/task/use-form-validate.ts index b829a5279b..c0a0c8210d 100644 --- a/dolphinscheduler-ui/src/views/projects/workflow/components/dynamic-dag/task/use-form-validate.ts +++ b/dolphinscheduler-ui/src/views/projects/workflow/components/dynamic-dag/task/use-form-validate.ts @@ -18,7 +18,7 @@ import { useI18n } from 'vue-i18n' import type { FormItemRule } from 'naive-ui' -export function useFormValidate(forms: any) { +export function useFormValidate(forms: Array) { const { t } = useI18n() const validate: any = {} diff --git a/dolphinscheduler-ui/src/views/projects/workflow/components/dynamic-dag/task/use-task-form.ts b/dolphinscheduler-ui/src/views/projects/workflow/components/dynamic-dag/task/use-task-form.ts index cefa0d839e..68d9ae752b 100644 --- a/dolphinscheduler-ui/src/views/projects/workflow/components/dynamic-dag/task/use-task-form.ts +++ b/dolphinscheduler-ui/src/views/projects/workflow/components/dynamic-dag/task/use-task-form.ts @@ -20,6 +20,7 @@ import { useDynamicLocales } from './use-dynamic-locales' import { useFormField } from './use-form-field' import { useFormValidate } from './use-form-validate' import { useFormStructure } from './use-form-structure' +import { useFormRequest } from './use-form-request' const data = { task: 'shell', @@ -49,13 +50,12 @@ const data = { script: 'Script' } }, - apis: [ - { - name: 'getWorkerGroupList', - uri: '/worker-groups/all', + apis: { + getWorkerGroupList: { + url: '/worker-groups/all', method: 'get' } - ], + }, forms: [ { label: 'task_components.node_name', @@ -121,10 +121,10 @@ export function useTaskForm() { rules: {} }) + useDynamicLocales(data.locales) variables.model = useFormField(data.forms) variables.rules = useFormValidate(data.forms) - useDynamicLocales(data.locales) - variables.formStructure = useFormStructure(data.forms) + variables.formStructure = useFormStructure(useFormRequest(data.apis, data.forms)) return { variables