process-instance-condition.tsx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 { SearchOutlined } from '@vicons/antd'
  18. import { NInput, NButton, NDatePicker, NSelect, NIcon, NSpace } from 'naive-ui'
  19. import { defineComponent, getCurrentInstance, ref } from 'vue'
  20. import { useI18n } from 'vue-i18n'
  21. import { format } from 'date-fns'
  22. import { workflowExecutionStateType } from '@/common/common'
  23. export default defineComponent({
  24. name: 'ProcessInstanceCondition',
  25. emits: ['handleSearch'],
  26. setup(props, ctx) {
  27. const searchValRef = ref('')
  28. const executorNameRef = ref('')
  29. const hostRef = ref('')
  30. const stateTypeRef = ref('')
  31. const startEndTimeRef = ref()
  32. const handleSearch = () => {
  33. let startDate = ''
  34. let endDate = ''
  35. if (startEndTimeRef.value) {
  36. startDate = format(
  37. new Date(startEndTimeRef.value[0]),
  38. 'yyyy-MM-dd HH:mm:ss'
  39. )
  40. endDate = format(
  41. new Date(startEndTimeRef.value[1]),
  42. 'yyyy-MM-dd HH:mm:ss'
  43. )
  44. }
  45. ctx.emit('handleSearch', {
  46. searchVal: searchValRef.value,
  47. executorName: executorNameRef.value,
  48. host: hostRef.value,
  49. stateType: stateTypeRef.value,
  50. startDate,
  51. endDate
  52. })
  53. }
  54. const onClearSearchVal = () => {
  55. searchValRef.value = ''
  56. handleSearch()
  57. }
  58. const onClearSearchHost = () => {
  59. hostRef.value = ''
  60. handleSearch()
  61. }
  62. const onClearSearchExecutor = () => {
  63. executorNameRef.value = ''
  64. handleSearch()
  65. }
  66. const trim = getCurrentInstance()?.appContext.config.globalProperties.trim
  67. return {
  68. searchValRef,
  69. executorNameRef,
  70. hostRef,
  71. stateTypeRef,
  72. startEndTimeRef,
  73. handleSearch,
  74. onClearSearchVal,
  75. onClearSearchExecutor,
  76. onClearSearchHost,
  77. trim
  78. }
  79. },
  80. render() {
  81. const { t } = useI18n()
  82. const options = workflowExecutionStateType(t)
  83. return (
  84. <NSpace justify='end'>
  85. <NInput
  86. allowInput={this.trim}
  87. size='small'
  88. v-model:value={this.searchValRef}
  89. placeholder={t('project.workflow.name')}
  90. clearable
  91. onClear={this.onClearSearchVal}
  92. />
  93. <NInput
  94. allowInput={this.trim}
  95. size='small'
  96. v-model:value={this.executorNameRef}
  97. placeholder={t('project.workflow.executor')}
  98. clearable
  99. onClear={this.onClearSearchExecutor}
  100. />
  101. <NInput
  102. allowInput={this.trim}
  103. size='small'
  104. v-model:value={this.hostRef}
  105. placeholder={t('project.workflow.host')}
  106. clearable
  107. onClear={this.onClearSearchHost}
  108. />
  109. <NSelect
  110. options={options}
  111. size='small'
  112. style={{ width: '210px' }}
  113. defaultValue={''}
  114. v-model:value={this.stateTypeRef}
  115. />
  116. <NDatePicker
  117. type='datetimerange'
  118. size='small'
  119. clearable
  120. v-model:value={this.startEndTimeRef}
  121. />
  122. <NButton type='primary' size='small' onClick={this.handleSearch}>
  123. <NIcon>
  124. <SearchOutlined />
  125. </NIcon>
  126. </NButton>
  127. </NSpace>
  128. )
  129. }
  130. })