detail.tsx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. import { defineComponent, ref, watch, inject, Ref, unref } from 'vue'
  18. import Form from '@/components/form'
  19. import { useTask } from './use-task'
  20. import { useTaskNodeStore } from '@/store/project/task-node'
  21. import type { ITaskData, EditWorkflowDefinition } from './types'
  22. interface IDetailPanel {
  23. projectCode: number
  24. data: ITaskData
  25. readonly: false
  26. from: number
  27. detailRef?: Ref
  28. definition?: EditWorkflowDefinition
  29. }
  30. const NodeDetail = defineComponent({
  31. name: 'NodeDetail',
  32. emits: ['taskTypeChange'],
  33. setup(props, { expose, emit }) {
  34. const taskStore = useTaskNodeStore()
  35. const formRef = ref()
  36. const detailData: IDetailPanel = inject('data') || {
  37. projectCode: 0,
  38. data: {
  39. taskType: 'SHELL'
  40. },
  41. readonly: false,
  42. from: 0
  43. }
  44. const { data, projectCode, from, readonly, definition } = unref(detailData)
  45. const { elementsRef, rulesRef, model } = useTask({
  46. data,
  47. projectCode,
  48. from,
  49. readonly,
  50. definition
  51. })
  52. watch(
  53. () => model.taskType,
  54. async (taskType) => {
  55. taskStore.updateName(model.name || '')
  56. emit('taskTypeChange', taskType)
  57. }
  58. )
  59. expose(formRef)
  60. return () => (
  61. <Form
  62. ref={formRef}
  63. meta={{
  64. model,
  65. rules: rulesRef.value,
  66. elements: elementsRef.value,
  67. disabled: unref(readonly)
  68. }}
  69. layout={{
  70. xGap: 10
  71. }}
  72. />
  73. )
  74. }
  75. })
  76. export default NodeDetail