index.tsx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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, onMounted, toRefs, watch } from 'vue'
  18. import { useI18n } from 'vue-i18n'
  19. import { useRoute } from 'vue-router'
  20. import { NSelect, NButton, NIcon, NSpace, NTooltip } from 'naive-ui'
  21. import { ReloadOutlined, EyeOutlined } from '@vicons/antd'
  22. import { useRelation } from './use-relation'
  23. import Card from '@/components/card'
  24. import Graph from './components/Graph'
  25. import Result from '@/components/result'
  26. const workflowRelation = defineComponent({
  27. name: 'workflow-relation',
  28. setup() {
  29. const { t, locale } = useI18n()
  30. const route = useRoute()
  31. const { variables, getWorkflowName, getOneWorkflow, getWorkflowList } =
  32. useRelation()
  33. onMounted(() => {
  34. getWorkflowList(Number(route.params.projectCode))
  35. getWorkflowName(Number(route.params.projectCode))
  36. })
  37. const handleResetDate = () => {
  38. variables.seriesData = []
  39. variables.workflow && variables.workflow !== 0
  40. ? getOneWorkflow(
  41. Number(variables.workflow),
  42. Number(route.params.projectCode)
  43. )
  44. : getWorkflowList(Number(route.params.projectCode))
  45. }
  46. watch(
  47. () => [variables.workflow, variables.labelShow, locale.value],
  48. () => {
  49. handleResetDate()
  50. }
  51. )
  52. return { t, handleResetDate, ...toRefs(variables) }
  53. },
  54. render() {
  55. const { t, handleResetDate } = this
  56. return (
  57. (this.seriesData.length === 0 && (
  58. <Result
  59. title={t('project.workflow.workflow_relation_no_data_result_title')}
  60. description={t(
  61. 'project.workflow.workflow_relation_no_data_result_desc'
  62. )}
  63. status={'info'}
  64. size={'medium'}
  65. />
  66. )) ||
  67. (this.seriesData.length > 0 && (
  68. <Card title={t('project.workflow.workflow_relation')}>
  69. {{
  70. default: () =>
  71. Object.keys(this.seriesData).length > 0 && (
  72. <Graph
  73. seriesData={this.seriesData}
  74. labelShow={this.labelShow}
  75. links={this.links}
  76. />
  77. ),
  78. 'header-extra': () => (
  79. <NSpace>
  80. <NSelect
  81. clearable
  82. style={{ width: '300px' }}
  83. placeholder={t('project.workflow.workflow_name')}
  84. options={this.workflowOptions}
  85. v-model={[this.workflow, 'value']}
  86. />
  87. <NTooltip trigger={'hover'}>
  88. {{
  89. default: () => t('project.workflow.refresh'),
  90. trigger: () => (
  91. <NButton
  92. strong
  93. secondary
  94. circle
  95. type='info'
  96. onClick={handleResetDate}
  97. >
  98. <NIcon>
  99. <ReloadOutlined />
  100. </NIcon>
  101. </NButton>
  102. )
  103. }}
  104. </NTooltip>
  105. <NTooltip trigger={'hover'}>
  106. {{
  107. default: () => t('project.workflow.show_hide_label'),
  108. trigger: () => (
  109. <NButton
  110. strong
  111. secondary
  112. circle
  113. type='info'
  114. onClick={() => (this.labelShow = !this.labelShow)}
  115. >
  116. <NIcon>
  117. <EyeOutlined />
  118. </NIcon>
  119. </NButton>
  120. )
  121. }}
  122. </NTooltip>
  123. </NSpace>
  124. )
  125. }}
  126. </Card>
  127. ))
  128. )
  129. }
  130. })
  131. export default workflowRelation