setup()

in dolphinscheduler-ui/src/views/projects/workflow/instance/components/variables-view.tsx [29:125]


  setup(props, ctx) {
    const paramsRef = ref<any>()
    const route = useRoute()

    const projectCode = Number(route.params.projectCode)

    const instanceId = Number(route.params.id)

    const workflowCode = Number(route.params.code)

    const globalParams = computed(() => {
      return paramsRef.value && paramsRef.value.globalParams
        ? paramsRef.value.globalParams
        : []
    })

    const localParams = computed(() => {
      return paramsRef.value && paramsRef.value.localParams
        ? paramsRef.value.localParams
        : {}
    })

    const getViewVariables = () => {
      if (Number.isNaN(instanceId)) {
        viewWorkflowDefinitionVariables(projectCode, workflowCode).then(
          (res: any) => {
            paramsRef.value = res
          }
        )
      } else {
        viewVariables(instanceId, projectCode).then((res: any) => {
          paramsRef.value = res
        })
      }
    }

    const handleCopy = (text: string) => {
      ctx.emit('copy', text)
    }

    /**
     * Copyed text processing
     */
    const rtClipboard = (el: any, taskType: string) => {
      const arr: Array<string> = []
      Object.keys(el).forEach((key) => {
        if (taskType === 'SQL' || taskType === 'PROCEDURE') {
          if (key !== 'direct' && key !== 'type') {
            arr.push(`${key}=${el[key]}`)
          }
        } else {
          arr.push(`${key}=${el[key]}`)
        }
      })
      return arr.join(' ')
    }

    const localButton = (index: number, taskType: string, el: any) => {
      return (
        <NButton
          key={index}
          type='primary'
          style={'margin-right: 10px'}
          onClick={() => handleCopy(rtClipboard(el, taskType))}
        >
          {Object.keys(el).map((key: string) => {
            if (taskType === 'SQL' || taskType === 'PROCEDURE') {
              return key !== 'direct' && key !== 'type' ? (
                <span style={'margin-right: 5px'}>
                  <strong style='color: #2A455B;'>{key}</strong> = {el[key]}
                </span>
              ) : (
                ''
              )
            } else {
              return (
                <span style={'margin-right: 5px'}>
                  <strong style='color: #2A455B;'>{key}</strong> = {el[key]}
                </span>
              )
            }
          })}
        </NButton>
      )
    }

    onMounted(() => {
      getViewVariables()
    })

    return {
      globalParams,
      localParams,
      localButton,
      handleCopy
    }
  },