index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  1. <template>
  2. <div class="table-box">
  3. <ProTable ref="proTable" :columns="columns" row-key="id" :data="bizProcessList">
  4. <!-- 表格 header 按钮 -->
  5. <template #tableHeader="scope">
  6. <el-button type="primary" v-auth="['task:bizProcess:add']" icon="CirclePlus" @click="openDialog(1, '算法业务处理新增')"> 新增 </el-button>
  7. <el-button type="primary" v-auth="['task:bizProcess:import']" icon="Upload" plain @click="batchAdd"> 导入 </el-button>
  8. <el-button type="primary" v-auth="['task:bizProcess:export']" icon="Download" plain @click="downloadFile"> 导出 </el-button>
  9. <el-button
  10. type="danger"
  11. v-auth="['task:bizProcess:remove']"
  12. icon="Delete"
  13. plain
  14. :disabled="!scope.isSelected"
  15. @click="batchDelete(scope.selectedListIds)"
  16. >
  17. 批量删除
  18. </el-button>
  19. <el-button type="primary" v-auth="['task:bizProcess:add']" icon="View" @click="contrastResults()"> 对比结果 </el-button>
  20. </template>
  21. <!-- 表格操作 -->
  22. <template #operation="scope">
  23. <el-button type="primary" link icon="View" v-auth="['task:bizProcess:query']" @click="openDialog(3, '算法业务处理查看', scope.row)">
  24. 查看
  25. </el-button>
  26. <el-button type="primary" link icon="EditPen" v-auth="['task:bizProcess:edit']" @click="openDialog(2, '算法业务处理编辑', scope.row)">
  27. 编辑
  28. </el-button>
  29. <el-button type="primary" link icon="Delete" v-auth="['task:bizProcess:remove']" @click="deleteBizProcess(scope.row)"> 删除 </el-button>
  30. <el-button type="primary" link icon="View" v-auth="['task:bizProcess:query']" @click="viewLog(scope.row)"> 查看日志 </el-button>
  31. </template>
  32. </ProTable>
  33. <FormDialog ref="formDialogRef" />
  34. <ImportExcel ref="dialogRef" />
  35. <el-dialog v-model="dialogVisible" title="日志" width="70%">
  36. <div class="log">
  37. <div class="p" v-for="(item, index) in logInfo" :key="index">{{ item }}</div>
  38. </div>
  39. </el-dialog>
  40. <el-dialog v-model="resultVisible" title="对比结果" width="70%">
  41. <div style="width: 100%" class="resultShow">
  42. <el-row class="headerRow">
  43. <el-col class="col" :span="4" v-for="(agloName, index) in resultsData['agNameList']" :key="index">
  44. <span>{{ agloName }}</span>
  45. </el-col>
  46. </el-row>
  47. <el-row class="row">
  48. <el-col class="col" :span="4" v-for="(RCurveUrl, index) in resultsData['rcureList']" :key="index">
  49. <div v-if="index !== 1" class="oneCol">{{ RCurveUrl }}</div>
  50. <ImagePreview
  51. class="img"
  52. v-else
  53. :width="100"
  54. :height="100"
  55. :src="'/api/profile' + RCurveUrl"
  56. :preview-src-list="['/api/profile' + RCurveUrl]"
  57. />
  58. </el-col>
  59. </el-row>
  60. <el-row class="row">
  61. <el-col class="col" :span="4" v-for="(PCurveUrl, index) in resultsData['pcureList']" :key="index">
  62. <div v-if="index !== 1" class="oneCol">{{ PCurveUrl }}</div>
  63. <ImagePreview
  64. class="img"
  65. v-else
  66. :width="100"
  67. :height="100"
  68. :src="'/api/profile' + PCurveUrl"
  69. :preview-src-list="['/api/profile' + PCurveUrl]"
  70. />
  71. </el-col>
  72. </el-row>
  73. <el-row class="row">
  74. <el-col class="col" :span="4" v-for="(F1CurveUrl, index) in resultsData['f1cureList']" :key="index">
  75. <div v-if="index !== 1" class="oneCol">{{ F1CurveUrl }}</div>
  76. <ImagePreview
  77. class="img"
  78. v-else
  79. :width="100"
  80. :height="100"
  81. :src="'/api/profile' + F1CurveUrl"
  82. :preview-src-list="['/api/profile' + F1CurveUrl]"
  83. />
  84. </el-col>
  85. </el-row>
  86. </div>
  87. </el-dialog>
  88. </div>
  89. </template>
  90. <script setup lang="tsx" name="BizProcess">
  91. import { ref, reactive, onMounted, onUnmounted, nextTick, watch } from 'vue'
  92. import { useHandleData } from '@/hooks/useHandleData'
  93. import { useDownload } from '@/hooks/useDownload'
  94. import { ElMessageBox, ElMessage } from 'element-plus'
  95. import ProTable from '@/components/ProTable/index.vue'
  96. import ImportExcel from '@/components/ImportExcel/index.vue'
  97. import FormDialog from '@/components/FormDialog/index.vue'
  98. import { ProTableInstance, ColumnProps } from '@/components/ProTable/interface'
  99. import {
  100. listBizProcessApi,
  101. delBizProcessApi,
  102. addBizProcessApi,
  103. updateBizProcessApi,
  104. importTemplateApi,
  105. importBizProcessDataApi,
  106. exportBizProcessApi,
  107. getBizProcessApi,
  108. getTrainResultApi,
  109. getVerifyResultApi,
  110. getTestResultApi
  111. } from '@/api/modules/task/bizProcess'
  112. import { getSubtaskApi } from '@/api/modules/task/subtask'
  113. import { getDictsApi } from '@/api/modules/system/dictData'
  114. import { useRoute } from 'vue-router'
  115. import ImagePreview from '@/components/ImagePreview/index.vue'
  116. const route = useRoute()
  117. const subTaskId = route.query.id as string
  118. // ProTable 实例
  119. const proTable = ref<ProTableInstance>()
  120. const dialogVisible = ref(false)
  121. const resultVisible = ref(false)
  122. let resultsData = ref({})
  123. let logList = ref()
  124. let logInfo = ref([] as string[])
  125. let taskType = ref()
  126. let taskStatus = ref()
  127. let bizProcessList = ref()
  128. // 每隔10秒请求一下列表
  129. const timer = ref() // 定时器
  130. const refreshList = () => {
  131. setTimeout(() => {
  132. listBizProcessApi({
  133. pageNum: 1,
  134. pageSize: 100,
  135. subTaskId
  136. }).then(res => {
  137. bizProcessList.value = res.data['list']
  138. })
  139. }, 0)
  140. }
  141. onMounted(() => {
  142. getSubtaskApi(subTaskId).then(res => {
  143. taskType.value = res.data.type
  144. taskStatus.value = res.data.status
  145. })
  146. refreshList()
  147. timer.value = setInterval(() => {
  148. refreshList()
  149. }, 100000)
  150. })
  151. // 删除算法业务处理信息
  152. const deleteBizProcess = async (params: any) => {
  153. await useHandleData(delBizProcessApi, params.id, '删除【' + params.id + '】算法业务处理')
  154. proTable.value?.getTableList()
  155. }
  156. // 批量删除算法业务处理信息
  157. const batchDelete = async (ids: string[]) => {
  158. await useHandleData(delBizProcessApi, ids, '删除所选算法业务处理信息')
  159. proTable.value?.clearSelection()
  160. proTable.value?.getTableList()
  161. }
  162. // 导出算法业务处理列表
  163. const downloadFile = async () => {
  164. ElMessageBox.confirm('确认导出算法业务处理数据?', '温馨提示', { type: 'warning' }).then(() =>
  165. useDownload(exportBizProcessApi, '算法业务处理列表', proTable.value?.searchParam)
  166. )
  167. }
  168. // 批量添加算法业务处理
  169. const dialogRef = ref<InstanceType<typeof ImportExcel> | null>(null)
  170. const batchAdd = () => {
  171. const params = {
  172. title: '算法业务处理',
  173. tempApi: importTemplateApi,
  174. importApi: importBizProcessDataApi,
  175. getTableList: proTable.value?.getTableList
  176. }
  177. dialogRef.value?.acceptParams(params)
  178. }
  179. // 对比结果
  180. const contrastResults = () => {
  181. // if (taskStatus.value !== '3') {
  182. // ElMessage.warning(`算法状态为${taskStatus.value},暂无对比结果`)
  183. // return
  184. // }
  185. switch (taskType.value) {
  186. case '1':
  187. getTrainResultApi(subTaskId).then(res => {
  188. handleResultData(res.data)
  189. })
  190. break
  191. case '2':
  192. getVerifyResultApi(subTaskId).then(res => {
  193. handleResultData(res.data)
  194. })
  195. break
  196. case '3':
  197. getTestResultApi(subTaskId).then(res => {
  198. console.log('333', res)
  199. })
  200. break
  201. default:
  202. break
  203. }
  204. resultVisible.value = true
  205. }
  206. const handleResultData = data => {
  207. resultsData.value = data
  208. resultsData.value['agNameList'].unshift('')
  209. resultsData.value['rcureList'].unshift('R_curve')
  210. resultsData.value['pcureList'].unshift('P_curve')
  211. resultsData.value['f1cureList'].unshift('F1_curve')
  212. }
  213. // 查看日志
  214. const viewLog = row => {
  215. // if (taskStatus.value !== '0') {
  216. // ElMessage.warning('算法状态为待处理,暂无日志')
  217. // return
  218. // }
  219. console.log(row.log)
  220. const url = '/api/profile/task/log.log'
  221. fetchLogFile(url)
  222. .then(text => {
  223. logList.value = text.split('\n')
  224. // console.log('logList.value', logList.value)
  225. // if (taskStatus.value === '1') {
  226. // info(logList.value)
  227. // dialogVisible.value = true
  228. // } else if (taskStatus.value === '2') {
  229. // logInfo.value = logList.value
  230. // dialogVisible.value = true
  231. // }
  232. info(logList.value)
  233. dialogVisible.value = true
  234. })
  235. .catch(error => {
  236. console.error('Failed to fetch the log file:', error)
  237. ElMessage.error('日志读取错误')
  238. })
  239. }
  240. const fetchLogFile = async url => {
  241. try {
  242. const response = await fetch(url, { method: 'GET' })
  243. if (!response.ok) {
  244. throw new Error(`HTTP error! status: ${response.status}`)
  245. }
  246. return await response.text()
  247. } catch (error) {
  248. throw error
  249. }
  250. }
  251. let timer2 = ref()
  252. const info = logText => {
  253. let index = 0
  254. const logContainer = document.querySelector('.log')
  255. timer2.value = setInterval(() => {
  256. if (index < logText.length) {
  257. logInfo.value.push(logText[index])
  258. index++
  259. nextTick(() => {
  260. if (logContainer) {
  261. logContainer.scrollTop = logContainer.scrollHeight
  262. }
  263. })
  264. } else {
  265. clearInterval(timer2.value)
  266. }
  267. }, 300)
  268. }
  269. const formDialogRef = ref<InstanceType<typeof FormDialog> | null>(null)
  270. // 打开弹框的功能
  271. const openDialog = async (type: number, title: string, row?: any) => {
  272. let res = { data: {} }
  273. if (row?.id) {
  274. res = await getBizProcessApi(row?.id || null)
  275. }
  276. // 重置表单
  277. setItemsOptions()
  278. const params = {
  279. title,
  280. width: 580,
  281. isEdit: type !== 3,
  282. itemsOptions: itemsOptions,
  283. model: type == 1 ? {} : res.data,
  284. api: type == 1 ? addBizProcessApi : updateBizProcessApi,
  285. getTableList: proTable.value?.getTableList
  286. }
  287. formDialogRef.value?.openDialog(params)
  288. }
  289. onUnmounted(() => {
  290. clearInterval(timer.value)
  291. timer.value = null
  292. })
  293. watch(
  294. () => dialogVisible.value,
  295. val => {
  296. if (!val) {
  297. clearInterval(timer2.value)
  298. timer2.value = null
  299. }
  300. }
  301. )
  302. // 表格配置项
  303. const columns = reactive<ColumnProps<any>[]>([
  304. { type: 'selection', fixed: 'left', width: 70 },
  305. { prop: 'id', label: '主键ID' },
  306. {
  307. prop: 'subTaskId',
  308. label: '子任务id',
  309. search: {
  310. el: 'input'
  311. },
  312. width: 120
  313. },
  314. {
  315. prop: 'name',
  316. label: '任务名称',
  317. search: {
  318. el: 'input'
  319. },
  320. width: 120
  321. },
  322. {
  323. prop: 'type',
  324. label: '任务类型',
  325. search: {
  326. el: 'input'
  327. },
  328. width: 120
  329. },
  330. {
  331. prop: 'status',
  332. label: '任务状态',
  333. tag: true,
  334. enum: () => getDictsApi('biz_task_status'),
  335. search: {
  336. el: 'tree-select'
  337. },
  338. width: 100,
  339. fieldNames: { label: 'dictLabel', value: 'dictValue' }
  340. },
  341. {
  342. prop: 'algorithmId',
  343. label: '算法',
  344. width: 120
  345. },
  346. {
  347. prop: 'modelId',
  348. label: '模型',
  349. width: 120
  350. },
  351. {
  352. prop: 'parameters',
  353. label: '调用算法时所用的参数',
  354. width: 120
  355. },
  356. {
  357. prop: 'preprocessPath',
  358. label: '预处理数据路径',
  359. width: 120
  360. },
  361. {
  362. prop: 'resultPath',
  363. label: '结果数据路径',
  364. width: 120
  365. },
  366. {
  367. prop: 'index',
  368. label: '序号',
  369. width: 120
  370. },
  371. {
  372. prop: 'startTime',
  373. label: '开始时间',
  374. width: 120
  375. },
  376. {
  377. prop: 'endTime',
  378. label: '结束时间',
  379. width: 120
  380. },
  381. {
  382. prop: 'costSecond',
  383. label: '耗时',
  384. width: 120
  385. },
  386. {
  387. prop: 'log',
  388. label: '日志',
  389. width: 120
  390. },
  391. { prop: 'operation', label: '操作', width: 230, fixed: 'right' }
  392. ])
  393. // 结果表格配置项
  394. // const resultColumns = reactive<ColumnProps<any>[]>([])
  395. // 表单配置项
  396. let itemsOptions: ProForm.ItemsOptions[] = []
  397. const setItemsOptions = () => {
  398. itemsOptions = [
  399. {
  400. label: '子任务id',
  401. prop: 'subTaskId',
  402. compOptions: {
  403. placeholder: '请输入子任务id'
  404. }
  405. },
  406. {
  407. label: '任务名称',
  408. prop: 'name',
  409. compOptions: {
  410. placeholder: '请输入任务名称'
  411. }
  412. },
  413. {
  414. label: '任务类型',
  415. prop: 'type',
  416. compOptions: {
  417. placeholder: '请输入任务类型'
  418. }
  419. },
  420. {
  421. label: '任务状态',
  422. prop: 'status',
  423. compOptions: {
  424. elTagName: 'select',
  425. labelKey: 'dictLabel',
  426. valueKey: 'dictValue',
  427. enum: () => getDictsApi('biz_task_status'),
  428. placeholder: '请选择任务状态'
  429. }
  430. },
  431. {
  432. label: '算法',
  433. prop: 'algorithmId',
  434. compOptions: {
  435. placeholder: '请输入算法'
  436. }
  437. },
  438. {
  439. label: '模型',
  440. prop: 'modelId',
  441. compOptions: {
  442. placeholder: '请输入模型'
  443. }
  444. },
  445. {
  446. label: '调用算法时所用的参数',
  447. prop: 'parameters',
  448. compOptions: {
  449. type: 'textarea',
  450. clearable: true,
  451. placeholder: '请输入内容'
  452. }
  453. },
  454. {
  455. label: '预处理数据路径',
  456. prop: 'preprocessPath',
  457. compOptions: {
  458. placeholder: '请输入预处理数据路径'
  459. }
  460. },
  461. {
  462. label: '结果数据路径',
  463. prop: 'resultPath',
  464. compOptions: {
  465. placeholder: '请输入结果数据路径'
  466. }
  467. },
  468. {
  469. label: '序号',
  470. prop: 'index',
  471. compOptions: {
  472. placeholder: '请输入序号'
  473. }
  474. },
  475. {
  476. label: '开始时间',
  477. prop: 'startTime',
  478. compOptions: {
  479. elTagName: 'date-picker',
  480. type: 'date',
  481. placeholder: '请选择开始时间'
  482. }
  483. },
  484. {
  485. label: '结束时间',
  486. prop: 'endTime',
  487. compOptions: {
  488. elTagName: 'date-picker',
  489. type: 'date',
  490. placeholder: '请选择结束时间'
  491. }
  492. },
  493. {
  494. label: '耗时',
  495. prop: 'costSecond',
  496. compOptions: {
  497. placeholder: '请输入耗时'
  498. }
  499. },
  500. {
  501. label: '日志',
  502. prop: 'log',
  503. compOptions: {
  504. type: 'textarea',
  505. clearable: true,
  506. placeholder: '请输入内容'
  507. }
  508. }
  509. ]
  510. }
  511. </script>
  512. <style scoped lang="scss">
  513. .log {
  514. width: 90%;
  515. height: 60vh; /* 根据需要调整 */
  516. padding: 10px;
  517. // padding-bottom: 80px;
  518. margin-left: 50px;
  519. overflow-y: auto;
  520. font-family: 'Courier New', monospace;
  521. color: #4aff84;
  522. background-color: #1e1e1e;
  523. }
  524. .p {
  525. padding-left: 10px;
  526. margin-bottom: 5px;
  527. border-left: 3px solid #4aff84;
  528. }
  529. .resultShow {
  530. width: 100%;
  531. height: 60vh;
  532. overflow: hidden;
  533. overflow: scroll scroll;
  534. .headerRow {
  535. height: 50px;
  536. font-size: 1.5rem;
  537. line-height: 50px;
  538. text-align: center;
  539. }
  540. .row {
  541. .col {
  542. text-align: center;
  543. .oneCol {
  544. margin-top: 45px;
  545. font-size: 1.2rem;
  546. }
  547. .img {
  548. margin: 10px 0;
  549. }
  550. }
  551. }
  552. }
  553. </style>