use-form.ts 3.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
/*
 * 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 { reactive, ref } from 'vue'
import { useI18n } from 'vue-i18n'
import type { FormRules } from 'naive-ui'

export const useForm = () => {
  const { t } = useI18n()
  const date = new Date()
  const year = date.getFullYear()
  const month = date.getMonth()
  const day = date.getDate()

  const importState = reactive({
    importFormRef: ref(),
    importForm: {
      name: '',
      file: ''
    },
35
    saving: false,
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
    importRules: {
      file: {
        required: true,
        trigger: ['input', 'blur'],
        validator() {
          if (importState.importForm.name === '') {
            return new Error(t('project.workflow.enter_name_tips'))
          }
        }
      }
    } as FormRules
  })

  const startState = reactive({
    startFormRef: ref(),
    startForm: {
      processDefinitionCode: -1,
      startEndTime: [new Date(year, month, day), new Date(year, month, day)],
      scheduleTime: null,
      failureStrategy: 'CONTINUE',
      warningType: 'NONE',
      warningGroupId: null,
58
      execType: 'START_PROCESS',
59 60
      startNodeList: '',
      taskDependType: 'TASK_POST',
61
      dependentMode: 'OFF_MODE',
62 63 64 65 66 67 68
      runMode: 'RUN_MODE_SERIAL',
      processInstancePriority: 'MEDIUM',
      workerGroup: 'default',
      environmentCode: null,
      startParams: null,
      expectedParallelismNumber: '',
      dryRun: 0
69 70
    },
    saving: false
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
  })

  const timingState = reactive({
    timingFormRef: ref(),
    timingForm: {
      startEndTime: [
        new Date(year, month, day),
        new Date(year + 100, month, day)
      ],
      crontab: '0 0 * * * ? *',
      timezoneId: Intl.DateTimeFormat().resolvedOptions().timeZone,
      failureStrategy: 'CONTINUE',
      warningType: 'NONE',
      processInstancePriority: 'MEDIUM',
      warningGroupId: '',
      workerGroup: 'default',
      environmentCode: null
88 89
    },
    saving: false
90
  })
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110

  const copyState = reactive({
    copyFormRef: ref(),
    copyForm: {
      projectCode: null
    },
    saving: false,
    copyRules: {
      projectCode: {
        required: true,
        trigger: ['input', 'blur'],
        validator() {
          if (copyState.copyForm.projectCode === '') {
            return new Error(t('project.workflow.project_name_required'))
          }
        }
      }
    } as FormRules
  })

111 112 113
  return {
    importState,
    startState,
114 115
    timingState,
    copyState
116 117
  }
}