index.tsx 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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 Card from '@/components/card'
  18. import { SearchOutlined } from '@vicons/antd'
  19. import {
  20. NButton,
  21. NDataTable,
  22. NIcon,
  23. NInput,
  24. NPagination,
  25. NSpace,
  26. NTooltip,
  27. NPopconfirm
  28. } from 'naive-ui'
  29. import { defineComponent, onMounted, toRefs, watch } from 'vue'
  30. import { useI18n } from 'vue-i18n'
  31. import { useTable } from './use-table'
  32. import ImportModal from './components/import-modal'
  33. import StartModal from './components/start-modal'
  34. import TimingModal from './components/timing-modal'
  35. import VersionModal from './components/version-modal'
  36. import CopyModal from './components/copy-modal'
  37. import { useRouter, useRoute } from 'vue-router'
  38. import type { Router } from 'vue-router'
  39. import styles from './index.module.scss'
  40. export default defineComponent({
  41. name: 'WorkflowDefinitionList',
  42. setup() {
  43. const router: Router = useRouter()
  44. const route = useRoute()
  45. const projectCode = Number(route.params.projectCode)
  46. const {
  47. variables,
  48. createColumns,
  49. getTableData,
  50. batchDeleteWorkflow,
  51. batchExportWorkflow,
  52. batchCopyWorkflow
  53. } = useTable()
  54. const requestData = () => {
  55. getTableData({
  56. pageSize: variables.pageSize,
  57. pageNo: variables.page,
  58. searchVal: variables.searchVal
  59. })
  60. }
  61. const handleUpdateList = () => {
  62. requestData()
  63. }
  64. const handleCopyUpdateList = () => {
  65. variables.checkedRowKeys = []
  66. requestData()
  67. }
  68. const handleSearch = () => {
  69. variables.page = 1
  70. requestData()
  71. }
  72. const handleChangePageSize = () => {
  73. variables.page = 1
  74. requestData()
  75. }
  76. const createDefinition = () => {
  77. router.push({
  78. path: `/projects/${projectCode}/workflow/definitions/create`
  79. })
  80. }
  81. watch(useI18n().locale, () => {
  82. createColumns(variables)
  83. })
  84. onMounted(() => {
  85. createColumns(variables)
  86. requestData()
  87. })
  88. return {
  89. requestData,
  90. handleSearch,
  91. handleUpdateList,
  92. createDefinition,
  93. handleChangePageSize,
  94. batchDeleteWorkflow,
  95. batchExportWorkflow,
  96. batchCopyWorkflow,
  97. handleCopyUpdateList,
  98. ...toRefs(variables)
  99. }
  100. },
  101. render() {
  102. const { t } = useI18n()
  103. return (
  104. <div class={styles.content}>
  105. <Card class={styles.card}>
  106. <div class={styles.header}>
  107. <NSpace>
  108. <NButton
  109. type='primary'
  110. onClick={this.createDefinition}
  111. class='btn-create-process'
  112. >
  113. {t('project.workflow.create_workflow')}
  114. </NButton>
  115. <NButton strong secondary onClick={() => (this.showRef = true)}>
  116. {t('project.workflow.import_workflow')}
  117. </NButton>
  118. </NSpace>
  119. <div class={styles.right}>
  120. <div class={styles.search}>
  121. <div class={styles.list}>
  122. <NButton type='primary' onClick={this.handleSearch}>
  123. <NIcon>
  124. <SearchOutlined />
  125. </NIcon>
  126. </NButton>
  127. </div>
  128. <div class={styles.list}>
  129. <NInput
  130. placeholder={t('resource.function.enter_keyword_tips')}
  131. v-model={[this.searchVal, 'value']}
  132. />
  133. </div>
  134. </div>
  135. </div>
  136. </div>
  137. </Card>
  138. <Card title={t('project.workflow.workflow_definition')}>
  139. <NDataTable
  140. rowKey={(row) => row.code}
  141. columns={this.columns}
  142. data={this.tableData}
  143. striped
  144. class={styles.table}
  145. v-model:checked-row-keys={this.checkedRowKeys}
  146. row-class-name='items'
  147. scrollX={this.tableWidth}
  148. />
  149. <div class={styles.pagination}>
  150. <NPagination
  151. v-model:page={this.page}
  152. v-model:page-size={this.pageSize}
  153. page-count={this.totalPage}
  154. show-size-picker
  155. page-sizes={[10, 30, 50]}
  156. show-quick-jumper
  157. onUpdatePage={this.requestData}
  158. onUpdatePageSize={this.handleChangePageSize}
  159. />
  160. </div>
  161. <div class={styles['batch-button']}>
  162. <NTooltip>
  163. {{
  164. default: () => t('project.workflow.delete'),
  165. trigger: () => (
  166. <NPopconfirm onPositiveClick={this.batchDeleteWorkflow}>
  167. {{
  168. default: () => t('project.workflow.delete_confirm'),
  169. trigger: () => (
  170. <NButton
  171. tag='div'
  172. type='primary'
  173. disabled={this.checkedRowKeys.length <= 0}
  174. class='btn-delete-all'
  175. >
  176. {t('project.workflow.delete')}
  177. </NButton>
  178. )
  179. }}
  180. </NPopconfirm>
  181. )
  182. }}
  183. </NTooltip>
  184. <NTooltip>
  185. {{
  186. default: () => t('project.workflow.export'),
  187. trigger: () => (
  188. <NButton
  189. tag='div'
  190. type='primary'
  191. disabled={this.checkedRowKeys.length <= 0}
  192. onClick={this.batchExportWorkflow}
  193. class='btn-delete-all'
  194. >
  195. {t('project.workflow.export')}
  196. </NButton>
  197. )
  198. }}
  199. </NTooltip>
  200. <NTooltip>
  201. {{
  202. default: () => t('project.workflow.batch_copy'),
  203. trigger: () => (
  204. <NButton
  205. tag='div'
  206. type='primary'
  207. disabled={this.checkedRowKeys.length <= 0}
  208. onClick={() => (this.copyShowRef = true)}
  209. class='btn-delete-all'
  210. >
  211. {t('project.workflow.batch_copy')}
  212. </NButton>
  213. )
  214. }}
  215. </NTooltip>
  216. </div>
  217. </Card>
  218. <ImportModal
  219. v-model:show={this.showRef}
  220. onUpdateList={this.handleUpdateList}
  221. />
  222. <StartModal
  223. v-model:row={this.row}
  224. v-model:show={this.startShowRef}
  225. onUpdateList={this.handleUpdateList}
  226. />
  227. <TimingModal
  228. v-model:row={this.row}
  229. v-model:show={this.timingShowRef}
  230. onUpdateList={this.handleUpdateList}
  231. />
  232. <VersionModal
  233. v-model:row={this.row}
  234. v-model:show={this.versionShowRef}
  235. onUpdateList={this.handleUpdateList}
  236. />
  237. <CopyModal
  238. v-model:codes={this.checkedRowKeys}
  239. v-model:show={this.copyShowRef}
  240. onUpdateList={this.handleCopyUpdateList}
  241. />
  242. </div>
  243. )
  244. }
  245. })