batch-task.tsx 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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 {
  18. defineComponent,
  19. getCurrentInstance,
  20. onMounted,
  21. toRefs,
  22. watch
  23. } from 'vue'
  24. import {
  25. NSpace,
  26. NInput,
  27. NSelect,
  28. NDatePicker,
  29. NButton,
  30. NIcon,
  31. NDataTable,
  32. NPagination
  33. } from 'naive-ui'
  34. import { SearchOutlined } from '@vicons/antd'
  35. import { useTable } from './use-table'
  36. import { useI18n } from 'vue-i18n'
  37. import { useAsyncState } from '@vueuse/core'
  38. import { queryLog } from '@/service/modules/log'
  39. import { stateType } from '@/common/common'
  40. import Card from '@/components/card'
  41. import LogModal from '@/components/log-modal'
  42. const BatchTaskInstance = defineComponent({
  43. name: 'task-instance',
  44. setup() {
  45. const { t, variables, getTableData, createColumns } = useTable()
  46. const requestTableData = () => {
  47. getTableData({
  48. pageSize: variables.pageSize,
  49. pageNo: variables.page,
  50. searchVal: variables.searchVal,
  51. processInstanceId: variables.processInstanceId,
  52. host: variables.host,
  53. stateType: variables.stateType,
  54. datePickerRange: variables.datePickerRange,
  55. executorName: variables.executorName,
  56. processInstanceName: variables.processInstanceName
  57. })
  58. }
  59. const onUpdatePageSize = () => {
  60. variables.page = 1
  61. requestTableData()
  62. }
  63. const onSearch = () => {
  64. variables.page = 1
  65. requestTableData()
  66. }
  67. const onConfirmModal = () => {
  68. variables.showModalRef = false
  69. }
  70. const getLogs = (row: any) => {
  71. const { state } = useAsyncState(
  72. queryLog({
  73. taskInstanceId: Number(row.id),
  74. limit: variables.limit,
  75. skipLineNum: variables.skipLineNum
  76. }).then((res: any) => {
  77. if (res?.message) {
  78. variables.logRef += res.message
  79. variables.limit += 1000
  80. variables.skipLineNum += res.lineNum
  81. getLogs(row)
  82. } else {
  83. variables.logLoadingRef = false
  84. }
  85. }),
  86. {}
  87. )
  88. return state
  89. }
  90. const refreshLogs = (row: any) => {
  91. variables.logRef = ''
  92. variables.limit = 1000
  93. variables.skipLineNum = 0
  94. getLogs(row)
  95. }
  96. const trim = getCurrentInstance()?.appContext.config.globalProperties.trim
  97. onMounted(() => {
  98. createColumns(variables)
  99. requestTableData()
  100. })
  101. watch(useI18n().locale, () => {
  102. createColumns(variables)
  103. })
  104. watch(
  105. () => variables.showModalRef,
  106. () => {
  107. if (variables.showModalRef) {
  108. getLogs(variables.row)
  109. } else {
  110. variables.row = {}
  111. variables.logRef = ''
  112. variables.logLoadingRef = true
  113. variables.skipLineNum = 0
  114. variables.limit = 1000
  115. }
  116. }
  117. )
  118. return {
  119. t,
  120. ...toRefs(variables),
  121. requestTableData,
  122. onUpdatePageSize,
  123. onSearch,
  124. onConfirmModal,
  125. refreshLogs,
  126. trim
  127. }
  128. },
  129. render() {
  130. const {
  131. t,
  132. requestTableData,
  133. onUpdatePageSize,
  134. onSearch,
  135. onConfirmModal,
  136. loadingRef,
  137. refreshLogs
  138. } = this
  139. return (
  140. <NSpace vertical>
  141. <Card>
  142. <NSpace justify='end' wrap={false}>
  143. <NInput
  144. allowInput={this.trim}
  145. v-model={[this.searchVal, 'value']}
  146. size='small'
  147. placeholder={t('project.task.task_name')}
  148. clearable
  149. />
  150. <NInput
  151. allowInput={this.trim}
  152. v-model={[this.processInstanceName, 'value']}
  153. size='small'
  154. placeholder={t('project.task.workflow_instance')}
  155. clearable
  156. />
  157. <NInput
  158. allowInput={this.trim}
  159. v-model={[this.executorName, 'value']}
  160. size='small'
  161. placeholder={t('project.task.executor')}
  162. clearable
  163. />
  164. <NInput
  165. allowInput={this.trim}
  166. v-model={[this.host, 'value']}
  167. size='small'
  168. placeholder={t('project.task.host')}
  169. clearable
  170. />
  171. <NSelect
  172. v-model={[this.stateType, 'value']}
  173. size='small'
  174. options={stateType(t).slice(1)}
  175. placeholder={t('project.task.state')}
  176. style={{ width: '180px' }}
  177. clearable
  178. />
  179. <NDatePicker
  180. v-model={[this.datePickerRange, 'value']}
  181. type='datetimerange'
  182. size='small'
  183. start-placeholder={t('project.task.start_time')}
  184. end-placeholder={t('project.task.end_time')}
  185. clearable
  186. />
  187. <NButton size='small' type='primary' onClick={onSearch}>
  188. <NIcon>
  189. <SearchOutlined />
  190. </NIcon>
  191. </NButton>
  192. </NSpace>
  193. </Card>
  194. <Card title={t('project.task.batch_task')}>
  195. <NSpace vertical>
  196. <NDataTable
  197. loading={loadingRef}
  198. columns={this.columns}
  199. data={this.tableData}
  200. scrollX={this.tableWidth}
  201. />
  202. <NSpace justify='center'>
  203. <NPagination
  204. v-model:page={this.page}
  205. v-model:page-size={this.pageSize}
  206. page-count={this.totalPage}
  207. show-size-picker
  208. page-sizes={[10, 30, 50]}
  209. show-quick-jumper
  210. onUpdatePage={requestTableData}
  211. onUpdatePageSize={onUpdatePageSize}
  212. />
  213. </NSpace>
  214. </NSpace>
  215. </Card>
  216. <LogModal
  217. showModalRef={this.showModalRef}
  218. logRef={this.logRef}
  219. row={this.row}
  220. logLoadingRef={this.logLoadingRef}
  221. onConfirmModal={onConfirmModal}
  222. onRefreshLogs={refreshLogs}
  223. />
  224. </NSpace>
  225. )
  226. }
  227. })
  228. export default BatchTaskInstance