index.tsx 3.9 KB

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