index.vue 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962
  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="['identification:identificationSubtaskDetails:add']" icon="CirclePlus" @click="openDialog(1, '算法业务处理新增')"> 新增 </el-button>
  7. <el-button type="primary" v-auth="['identification:identificationSubtaskDetails:import']" icon="Upload" plain @click="batchAdd"> 导入 </el-button> -->
  8. <el-button type="primary" v-auth="['identification:identificationSubtaskDetails:export']" icon="Download" plain @click="downloadFile">
  9. 导出
  10. </el-button>
  11. <el-button
  12. type="danger"
  13. v-auth="['identification:identificationSubtaskDetails:remove']"
  14. icon="Delete"
  15. plain
  16. :disabled="!scope.isSelected"
  17. @click="batchDelete(scope.selectedListIds)"
  18. >
  19. 批量删除
  20. </el-button>
  21. <el-button type="primary" icon="View" @click="showCompareResult"> 验证指标对比 </el-button>
  22. <!-- <el-button type="primary" icon="View" @click="showValResult(true)"> 验证结果 </el-button>-->
  23. <el-button type="primary" icon="View" @click="showValResult(false)"> 测试结果 </el-button>
  24. <el-button type="primary" icon="View" @click="showValResult(true)"> 验证结果 </el-button>
  25. </template>
  26. <!-- 表格操作 -->
  27. <template #operation="scope">
  28. <el-button
  29. type="primary"
  30. link
  31. icon="View"
  32. v-auth="['identification:identificationSubtaskDetails:query']"
  33. @click="openDialog(3, '算法业务处理查看', scope.row)"
  34. >
  35. 查看详情
  36. </el-button>
  37. <el-button type="primary" link icon="finished" @click="showResult(scope.row)"> 执行结果 </el-button>
  38. <el-button v-show="scope.row.name.indexOf('训练') === -1" type="primary" link icon="search" @click="showExecutedTime(scope.row)">
  39. 执行时间
  40. </el-button>
  41. <el-button v-if="scope.row.name.indexOf('训练') === -1" type="primary" link icon="Refresh" @click="reRunTask(scope.row)">
  42. 执行训练
  43. </el-button>
  44. <el-button v-else type="primary" link icon="Refresh" @click="startTask(scope.row)"> 开始训练 </el-button>
  45. <el-button type="primary" link icon="Refresh" @click="exportData(scope.row)"> 导出结果 </el-button>
  46. <!-- <el-button type="primary" link icon="EditPen" v-auth="['identification:identificationSubtaskDetails:edit']" @click="openDialog(2, '算法业务处理编辑', scope.row)">-->
  47. <!-- 编辑-->
  48. <!-- </el-button>-->
  49. <!-- <el-button type="primary" link icon="Delete" v-auth="['identification:identificationSubtaskDetails:remove']" @click="deleteBizProcess(scope.row)"> 删除 </el-button>-->
  50. <el-button type="primary" link icon="document" v-auth="['identification:identificationSubtaskDetails:query']" @click="viewLog(scope.row)">
  51. 查看日志
  52. </el-button>
  53. </template>
  54. </ProTable>
  55. <FormDialog ref="formDialogRef" />
  56. <ImportExcel ref="dialogRef" />
  57. <el-dialog v-model="executedTimeVisible" title="执行时间统计" width="70%">
  58. <el-container v-for="(item, index) in executedTimeData.data" :key="index">
  59. <el-container style="display: flex; flex-direction: column">
  60. <h4 v-if="index === 0" style="color: greenyellow">单幅图像最短运行时间</h4>
  61. <h4 v-else-if="index === 1" style="color: greenyellow">单幅图像最长运行时间</h4>
  62. <h4 v-else-if="index === 2" style="color: greenyellow">单幅图像平均运行时间</h4>
  63. <div style="display: flex; flex-direction: row">
  64. <h5>前处理用时: {{ item['preprocess'] }}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</h5>
  65. <h5>推理用时: {{ item['inference'] }}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</h5>
  66. <h5>后处理用时: {{ item['postprocess'] }}</h5>
  67. </div>
  68. </el-container>
  69. </el-container>
  70. <el-container>
  71. <div v-if="executedTimeData.isVal">
  72. <h4 style="color: greenyellow">虚警率</h4>
  73. <h5>{{ executedTimeData.falseAlarmRate }} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</h5>
  74. <h4 style="color: greenyellow">漏检率</h4>
  75. <h5>{{ executedTimeData.omitDetectRate }}</h5>
  76. </div>
  77. </el-container>
  78. </el-dialog>
  79. <el-dialog v-model="dialogVisible" title="日志" width="70%">
  80. <div class="log" ref="logRef">
  81. <div class="p" v-for="(item, index) in logInfo" :key="index">{{ item }}</div>
  82. </div>
  83. </el-dialog>
  84. <el-dialog v-model="resultVisible" title="对比结果" width="70%">
  85. <div v-if="!resultsFlag" class="resultShow">
  86. <el-row class="headerRow">
  87. <el-col class="col" :span="spanNum" v-for="(agloName, index) in resultsData['agNameList']" :key="index">
  88. <span>{{ agloName }}</span>
  89. </el-col>
  90. </el-row>
  91. <el-row class="row">
  92. <el-col class="col" :span="spanNum" v-for="(RCurveUrl, index) in resultsData['rcureList']" :key="index">
  93. <div v-if="index === 0" :span="4" class="oneCol">{{ RCurveUrl }}</div>
  94. <ImagePreview
  95. class="img"
  96. v-else
  97. :width="100"
  98. :height="100"
  99. :src="'/api/profile' + RCurveUrl"
  100. :preview-src-list="['/api/profile' + RCurveUrl]"
  101. />
  102. </el-col>
  103. </el-row>
  104. <el-row class="row">
  105. <el-col class="col" :span="spanNum" v-for="(PCurveUrl, index) in resultsData['pcureList']" :key="index">
  106. <div v-if="index === 0" class="oneCol">{{ PCurveUrl }}</div>
  107. <ImagePreview
  108. class="img"
  109. v-else
  110. :width="100"
  111. :height="100"
  112. :src="'/api/profile' + PCurveUrl"
  113. :preview-src-list="['/api/profile' + PCurveUrl]"
  114. />
  115. </el-col>
  116. </el-row>
  117. <el-row class="row">
  118. <el-col class="col" :span="spanNum" v-for="(F1CurveUrl, index) in resultsData['f1cureList']" :key="index">
  119. <div v-if="index === 0" class="oneCol">{{ F1CurveUrl }}</div>
  120. <ImagePreview
  121. class="img"
  122. v-else
  123. :width="100"
  124. :height="100"
  125. :src="'/api/profile' + F1CurveUrl"
  126. :preview-src-list="['/api/profile' + F1CurveUrl]"
  127. />
  128. </el-col>
  129. </el-row>
  130. </div>
  131. <div v-if="resultsFlag" class="resultShow">
  132. <el-row class="headerRow">
  133. <el-col class="col" :span="spanNum" v-for="(agloName, index) in testResultsData['agNameList']" :key="index">
  134. <span>{{ agloName }}</span>
  135. </el-col>
  136. </el-row>
  137. <el-row class="row" v-for="(item, index) in testResultsData['resultList']" :key="index">
  138. <el-col class="col" :span="spanNum" v-for="(url, index1) in item" :key="index1">
  139. <!-- <span>{{ url }}</span> -->
  140. <ImagePreview class="img" :width="100" :height="100" :src="'/api/profile' + url" :preview-src-list="['/api/profile' + url]" />
  141. </el-col>
  142. </el-row>
  143. </div>
  144. </el-dialog>
  145. <el-dialog v-model="resultDialogVisible" title="执行结果">
  146. <!-- style="width: 70vw"-->
  147. <el-card :body-style="{ padding: '0px' }">
  148. <div style="padding: 14px">
  149. <span>P_curve</span>
  150. </div>
  151. <el-image :src="PATH_PREFIX + refSelectData.resultPath + '/P_curve.png'"></el-image>
  152. </el-card>
  153. <el-card :body-style="{ padding: '0px' }" style="margin-top: 10px">
  154. <div style="padding: 14px">
  155. <span>R_curve</span>
  156. </div>
  157. <el-image :src="PATH_PREFIX + refSelectData.resultPath + '/R_curve.png'"></el-image>
  158. </el-card>
  159. <el-card :body-style="{ padding: '0px' }" style="margin-top: 10px">
  160. <div style="padding: 14px">
  161. <span>PR_curve</span>
  162. </div>
  163. <el-image :src="PATH_PREFIX + refSelectData.resultPath + '/PR_curve.png'"></el-image>
  164. </el-card>
  165. <el-card :body-style="{ padding: '0px' }" style="margin-top: 10px">
  166. <div style="padding: 14px">
  167. <span>F1_curve</span>
  168. </div>
  169. <el-image :src="PATH_PREFIX + refSelectData.resultPath + '/F1_curve.png'"></el-image>
  170. </el-card>
  171. </el-dialog>
  172. <el-dialog v-model="compareDialogVisible" title="验证指标对比">
  173. <!-- style="width: 70vw"-->
  174. <el-container style="display: flex; flex-direction: row">
  175. <el-container v-for="(item, index) in valListData" :key="index" style="display: flex; flex-direction: column">
  176. <!-- <el-button @click="console.log(item)">test</el-button>-->
  177. <span style="font-size: 18px"> {{ item.name }} </span>
  178. <el-card :body-style="{ padding: '0px' }" style="margin-top: 3px">
  179. <div style="padding: 14px">
  180. <span>P_curve</span>
  181. </div>
  182. <el-image :src="PATH_PREFIX + item.resultPath + '/P_curve.png'"></el-image>
  183. </el-card>
  184. <el-card :body-style="{ padding: '0px' }" style="margin-top: 10px">
  185. <div style="padding: 14px">
  186. <span>R_curve</span>
  187. </div>
  188. <el-image :src="PATH_PREFIX + item.resultPath + '/R_curve.png'"></el-image>
  189. </el-card>
  190. <el-card :body-style="{ padding: '0px' }" style="margin-top: 10px">
  191. <div style="padding: 14px">
  192. <span>PR_curve</span>
  193. </div>
  194. <el-image :src="PATH_PREFIX + item.resultPath + '/PR_curve.png'"></el-image>
  195. </el-card>
  196. <el-card :body-style="{ padding: '0px' }" style="margin-top: 10px">
  197. <div style="padding: 14px">
  198. <span>F1_curve</span>
  199. </div>
  200. <el-image :src="PATH_PREFIX + item.resultPath + '/F1_curve.png'"></el-image>
  201. </el-card>
  202. </el-container>
  203. </el-container>
  204. </el-dialog>
  205. <el-dialog v-model="valDialogVisible" :title="titleMsg" style="width: 85vw; height: 85vh">
  206. <!-- style="width: 70vw"-->
  207. <el-container style="display: flex; flex-direction: row">
  208. <el-container v-for="(item, index) in imgDataList" :key="index" style="display: flex; flex-direction: column">
  209. <!-- <el-button @click="console.log(item)">test</el-button>-->
  210. <el-container v-for="(_item, _index) in item" :key="_index">
  211. <span
  212. v-if="_item.name"
  213. :style="{
  214. color: _item.color ? _item.color : '#ffffff',
  215. width: '80px',
  216. 'margin-right': '20px'
  217. }"
  218. >
  219. {{ _item.name }}
  220. </span>
  221. <el-image v-if="_item.srcUrl" :src="_item.srcUrl" style="width: 200px; height: 200px"></el-image>
  222. <span v-if="_item.imgUrl">标签</span>
  223. <ImgMaker
  224. :canvas-id="_item.name + '_' + _index"
  225. style="width: 200px; height: 200px"
  226. ref="imgMaker"
  227. v-if="_item.imgUrl"
  228. :is-pic-only="true"
  229. :src="_item.imgUrl"
  230. :width="200"
  231. :height="200"
  232. :c-width="200"
  233. :c-height="200"
  234. :class-def="typeDefs"
  235. :json-data="_item.jsonData"
  236. ></ImgMaker>
  237. <el-image v-if="_item.resUrl" :src="_item.resUrl" style="width: 200px; height: 200px"></el-image>
  238. </el-container>
  239. </el-container>
  240. </el-container>
  241. </el-dialog>
  242. </div>
  243. </template>
  244. <script setup lang="tsx" name="BizProcess">
  245. import { ref, reactive, onMounted, onUnmounted, watch, nextTick } from 'vue'
  246. import { useHandleData } from '@/hooks/useHandleData'
  247. import { useDownload } from '@/hooks/useDownload'
  248. import { ElMessageBox, ElMessage } from 'element-plus'
  249. import ProTable from '@/components/ProTable/index.vue'
  250. import ImportExcel from '@/components/ImportExcel/index.vue'
  251. import FormDialog from '@/components/FormDialog/index.vue'
  252. import { ProTableInstance, ColumnProps } from '@/components/ProTable/interface'
  253. import ImgMaker from '../../demo/components/img-maker'
  254. import {
  255. listBizProcessApi,
  256. delBizProcessApi,
  257. addBizProcessApi,
  258. updateBizProcessApi,
  259. exportBizProcessApi,
  260. getBizProcessApi,
  261. getTrainResultApi,
  262. getVerifyResultApi,
  263. getTestResultApi,
  264. getImgList
  265. } from '@/api/modules/task/bizProcessNew'
  266. // getTrainResultApi,getVerifyResultApi,getTestResultApi
  267. import { getSubtaskApi } from '@/api/modules/task/subtask'
  268. import { getDictsApi, listDataApi as listDictDataApi } from '@/api/modules/system/dictData'
  269. import { useRoute } from 'vue-router'
  270. import ImagePreview from '@/components/ImagePreview/index.vue'
  271. import http from '@/api'
  272. const route = useRoute()
  273. const PATH_PREFIX = 'api/profile/task'
  274. let resultDialogVisible = ref(false)
  275. let refSelectData = ref(reactive({}))
  276. const reRunTask = row => {
  277. http.post<any>('/identification/identificationSubtaskDetails/execute', { taskId: row.id }, { loading: false }).then(res => {
  278. if (res.code !== 200) {
  279. ElMessage.error(res.msg)
  280. } else {
  281. ElMessage.success('启动成功')
  282. }
  283. })
  284. }
  285. const startTask = row => {
  286. http.post<any>('/identification/identificationSubtaskDetails/startTask', { taskId: row.id }, { loading: false }).then(res => {
  287. if (res.code !== 200) {
  288. ElMessage.error(res.msg)
  289. } else {
  290. ElMessage.success('启动成功')
  291. }
  292. })
  293. }
  294. const typeDefs = ref(reactive([]))
  295. const exportData = row => {
  296. http.get<any>('/identification/identificationSubtaskDetails/resultZip', { taskId: row.id }, { loading: false }).then(res => {
  297. console.log(res)
  298. if (res.code === 200) {
  299. window.open(res.msg, '_blank')
  300. }
  301. })
  302. }
  303. let executedTimeVisible = ref(false)
  304. let executedTimeData = ref({})
  305. const showExecutedTime = row => {
  306. try {
  307. console.log('row', row)
  308. executedTimeData.value.isVal = row.name.includes('验证')
  309. http.get('/profile/task' + row.resultPath + '/time.json').then(res => {
  310. executedTimeData.value.data = []
  311. executedTimeData.value.data.push(res[0].min)
  312. executedTimeData.value.data.push(res[0].max)
  313. executedTimeData.value.data.push(res[0].average)
  314. if (executedTimeData.value.isVal) {
  315. setTimeout(() => {
  316. http.get('/profile/task' + row.resultPath + '/matrics.json').then(res => {
  317. executedTimeData.value.omitDetectRate = res[1].omit_detect_rate
  318. executedTimeData.value.falseAlarmRate = res[0].false_alarm_rate
  319. })
  320. }, 550)
  321. }
  322. })
  323. } catch (e) {
  324. ElMessage.error('解析JSON错误,请检查任务是否已完成')
  325. return
  326. }
  327. executedTimeVisible.value = true
  328. }
  329. let imgDataList = ref(reactive([]))
  330. let titleMsg = ref('')
  331. let valDialogVisible = ref(false)
  332. const showValResult = async isVal => {
  333. let hasInit = false
  334. titleMsg.value = isVal ? '验证结果对比' : '测试结果对比'
  335. imgDataList.value = reactive([])
  336. for (let i = 0; i < listData.value.length; i++) {
  337. if (listData.value[i].name.indexOf(isVal ? '验证' : '测试') !== -1) {
  338. console.log(listData.value[i])
  339. if (!hasInit) {
  340. hasInit = true
  341. let res = await getImgList({
  342. taskId: listData.value[i].preprocessPath.substring(1).split('/')[0],
  343. subPath: 'images'
  344. })
  345. console.log('res data', res)
  346. imgDataList.value.push([])
  347. for (let j = 0; j < res.data.length; j++) {
  348. let jList = res.data[j].split('.')
  349. jList[jList.length - 1] = 'txt'
  350. let obj = {
  351. name: res.data[j],
  352. srcUrl: 'api/profile/task' + listData.value[i].preprocessPath + (isVal ? '/images/' : '/') + res.data[j]
  353. // imgUrl: 'api/profile/task' + listData.value[i].preprocessPath + '/images/' + res.data[j],
  354. // labelUrl: 'api/profile/task' + listData.value[i].preprocessPath + '/labels/' + jList.join('.')
  355. }
  356. imgDataList.value[imgDataList.value.length - 1].push(obj)
  357. if (isVal) {
  358. obj.imgUrl = 'api/profile/task' + listData.value[i].preprocessPath + '/images/' + res.data[j]
  359. obj.labelUrl = '/profile/task' + listData.value[i].preprocessPath + '/labels/' + jList.join('.')
  360. console.log('url is', obj.labelUrl)
  361. setDetail(obj)
  362. }
  363. }
  364. }
  365. let res = await getImgList({
  366. taskId: listData.value[i].preprocessPath.substring(1).split('/')[0],
  367. subPath: 'images'
  368. })
  369. console.log(res.data)
  370. if (isVal) {
  371. await loadVerifyResult(listData.value[i].name, '/profile/task' + listData.value[i].preprocessPath + '/result/verify_result.txt')
  372. }
  373. console.log('load result', verifyResult.value)
  374. imgDataList.value.push([])
  375. for (let j = 0; j < res.data.length; j++) {
  376. console.log('temp log', verifyResult.value)
  377. let jList = res.data[j].split('.')
  378. jList[jList - 1] = 'txt'
  379. imgDataList.value[imgDataList.value.length - 1].push({
  380. resUrl: 'api/profile/task' + listData.value[i].resultPath + '/' + res.data[j],
  381. name: listData.value[i].name,
  382. picName: res.data[j],
  383. color: verifyResult.value[res.data[j]] ? '#00ff00' : '#ff0000'
  384. })
  385. }
  386. }
  387. }
  388. console.log('datalist', imgDataList)
  389. valDialogVisible.value = true
  390. }
  391. const verifyResult = ref({})
  392. const loadVerifyResult = async (name, filepath) => {
  393. // console.log('filepath', filepath)
  394. try {
  395. verifyResult.value = {}
  396. let res = await http.get(filepath)
  397. console.log(res)
  398. // verifyResult.value[name] = {}
  399. let arr = res.replace('\r', '').split('\n')
  400. arr.forEach(str => {
  401. let vals = str.split(' ')
  402. verifyResult.value[vals[0]] = vals[1] === '1'
  403. })
  404. console.log('verifyResult', verifyResult.value)
  405. } catch (e) {
  406. verifyResult.value = {}
  407. }
  408. }
  409. const setDetail = obj => {
  410. http.get<any>(obj.labelUrl).then(res => {
  411. obj.jsonData = []
  412. // console.log('result', res)
  413. let arr = res.replace('\r', '').split('\n')
  414. // console.log(arr)
  415. for (let i = 0; i < arr.length; i++) {
  416. let subArr = arr[i].split(' ')
  417. // console.log(subArr)
  418. let cssVal = '#000000'
  419. let label = '-1'
  420. for (let j = 0; j < typeDefs.value.length; j++) {
  421. if (typeDefs.value[j].label === subArr[0]) {
  422. cssVal = typeDefs.value[j].color
  423. label = typeDefs.value[j].label
  424. break
  425. }
  426. }
  427. const ww = 200
  428. const hh = 200
  429. obj.jsonData.push({
  430. subArr: subArr,
  431. pathString:
  432. 'M ' +
  433. subArr[1] * ww +
  434. ' ' +
  435. subArr[2] * hh +
  436. ' L ' +
  437. subArr[3] * ww +
  438. ' ' +
  439. subArr[4] * hh +
  440. ' L ' +
  441. subArr[5] * ww +
  442. ' ' +
  443. subArr[6] * hh +
  444. ' L ' +
  445. subArr[7] * ww +
  446. ' ' +
  447. subArr[8] * hh +
  448. ' z',
  449. // left: 0,
  450. // top: 0,
  451. fill: '',
  452. stroke: cssVal,
  453. strokeWidth: 5,
  454. label: label
  455. })
  456. }
  457. })
  458. }
  459. let compareDialogVisible = ref(false)
  460. const valListData = ref([])
  461. let listData = ref(reactive([]))
  462. const showCompareResult = () => {
  463. console.log(listData.value)
  464. valListData.value = listData.value.filter(item => {
  465. return item.name.includes('验证')
  466. })
  467. compareDialogVisible.value = true
  468. console.log('vallist', valListData.value)
  469. }
  470. const showResult = row => {
  471. refSelectData.value = reactive(row)
  472. resultDialogVisible.value = true
  473. console.log(row)
  474. }
  475. const subTaskId = route.query.id as string
  476. // ProTable 实例
  477. const proTable = ref<ProTableInstance>()
  478. const dialogVisible = ref(false)
  479. const resultVisible = ref(false)
  480. let resultsData = ref({})
  481. let testResultsData = ref({})
  482. let resultsFlag = ref(false)
  483. let spanNum = ref<number>(4)
  484. // let logList = ref()
  485. const logRef = ref<HTMLElement | null>(null) // 显式声明 logRef 的类型;
  486. let logInfo = ref([] as any[])
  487. let taskType = ref()
  488. let taskStatus = ref()
  489. let bizProcessList = ref()
  490. // 每隔10秒请求一下列表
  491. const timer = ref() // 定时器
  492. const refreshList = () => {
  493. setTimeout(() => {
  494. listBizProcessApi({
  495. pageNum: 1,
  496. pageSize: 100,
  497. subtaskId: subTaskId
  498. }).then(res => {
  499. bizProcessList.value = res.data['list'].sort((a, b) => b.index - a.index)
  500. listData.value = reactive(res.data['list'].sort((a, b) => b.index - a.index))
  501. })
  502. }, 0)
  503. }
  504. onMounted(() => {
  505. listDictDataApi({
  506. pageNum: 1,
  507. pageSize: 10,
  508. dictType: 'class_definition'
  509. }).then(res => {
  510. // console.log(res)
  511. for (let i = 0; i < res.data.list.length; i++) {
  512. typeDefs.value.push({
  513. name: res.data.list[i].dictLabel,
  514. color: res.data.list[i].cssClass,
  515. label: res.data.list[i].dictValue
  516. })
  517. }
  518. })
  519. getSubtaskApi(subTaskId).then(res => {
  520. taskType.value = res.data.type
  521. taskStatus.value = res.data.status
  522. })
  523. refreshList()
  524. timer.value = setInterval(() => {
  525. refreshList()
  526. }, 10000)
  527. // 组件挂载后,logRef 将指向实际的 DOM 元素
  528. if (logRef.value) {
  529. // 操作 logRef 对应的 DOM 元素
  530. logRef.value.scrollTop = logRef.value.scrollHeight
  531. }
  532. })
  533. // 删除算法业务处理信息
  534. const deleteBizProcess = async (params: any) => {
  535. await useHandleData(delBizProcessApi, params.id, '删除【' + params.id + '】算法业务处理')
  536. proTable.value?.getTableList()
  537. }
  538. // 批量删除算法业务处理信息
  539. const batchDelete = async (ids: string[]) => {
  540. await useHandleData(delBizProcessApi, ids, '删除所选算法业务处理信息')
  541. proTable.value?.clearSelection()
  542. proTable.value?.getTableList()
  543. }
  544. // 导出算法业务处理列表
  545. const downloadFile = async () => {
  546. ElMessageBox.confirm('确认导出算法业务处理数据?', '温馨提示', { type: 'warning' }).then(() =>
  547. useDownload(exportBizProcessApi, '算法业务处理列表', proTable.value?.searchParam)
  548. )
  549. }
  550. // 批量添加算法业务处理
  551. const dialogRef = ref<InstanceType<typeof ImportExcel> | null>(null)
  552. // const batchAdd = () => {
  553. // const params = {
  554. // title: '算法业务处理',
  555. // tempApi: importTemplateApi,
  556. // importApi: importBizProcessDataApi,
  557. // getTableList: proTable.value?.getTableList
  558. // }
  559. // dialogRef.value?.acceptParams(params)
  560. // }
  561. // 对比结果
  562. const contrastResults = () => {
  563. const statusFlag = bizProcessList.value.every(item => {
  564. return item.status == '2'
  565. })
  566. if (statusFlag) {
  567. switch (taskType.value) {
  568. case '1':
  569. getTrainResultApi(subTaskId).then(res => {
  570. resultsFlag.value = false
  571. handleResultData(res.data)
  572. resultVisible.value = true
  573. })
  574. break
  575. case '2':
  576. getVerifyResultApi(subTaskId).then(res => {
  577. resultsFlag.value = false
  578. handleResultData(res.data)
  579. resultVisible.value = true
  580. })
  581. break
  582. case '3':
  583. getTestResultApi(subTaskId).then(res => {
  584. console.log('333', res)
  585. resultsFlag.value = true
  586. testResultsData.value = res.data as any
  587. const num = testResultsData.value['agNameList'].length
  588. spanNum.value = 24 / num <= 4 ? 4 : Math.floor(24 / num)
  589. resultVisible.value = true
  590. })
  591. break
  592. default:
  593. break
  594. }
  595. } else {
  596. ElMessage.warning(`所有算法状态为‘已完成’,才可以对比`)
  597. }
  598. }
  599. const handleResultData = data => {
  600. resultsData.value = data
  601. resultsData.value['agNameList'].unshift('')
  602. const num = resultsData.value['agNameList'].length + 1
  603. spanNum.value = 24 / num <= 4 ? 4 : Math.floor(24 / num)
  604. resultsData.value['rcureList'].unshift('R_curve')
  605. resultsData.value['pcureList'].unshift('P_curve')
  606. resultsData.value['f1cureList'].unshift('F1_curve')
  607. }
  608. // 查看日志
  609. let timer2 = ref()
  610. const viewLog = row => {
  611. // if (row.status === '0') {
  612. // ElMessage.warning('算法状态为待处理,暂无日志')
  613. // return
  614. // }
  615. const url = `/api/profile/task` + row.resultPath + '/log/log.log'
  616. logShow(url)
  617. dialogVisible.value = true
  618. timer2.value = setInterval(() => {
  619. if (dialogVisible.value) {
  620. logShow(url)
  621. }
  622. }, 5000)
  623. }
  624. // 日志读取
  625. const logShow = (url: any) => {
  626. fetchLogFile(url)
  627. .then(text => {
  628. logInfo.value = []
  629. logInfo.value = text.split('\n')
  630. nextTick(() => {
  631. const logContainer = logRef.value
  632. if (logContainer) {
  633. ;(logContainer as HTMLElement).scrollTop = (logContainer as HTMLElement).scrollHeight
  634. }
  635. })
  636. })
  637. .catch(error => {
  638. console.error('Failed to fetch the log file:', error)
  639. ElMessage.error('日志读取错误')
  640. })
  641. }
  642. const fetchLogFile = async url => {
  643. try {
  644. const response = await fetch(url, { method: 'GET' })
  645. if (!response.ok) {
  646. throw new Error(`HTTP error! status: ${response.status}`)
  647. }
  648. return await response.text()
  649. } catch (error) {
  650. throw error
  651. }
  652. }
  653. const formDialogRef = ref<InstanceType<typeof FormDialog> | null>(null)
  654. // 打开弹框的功能
  655. const openDialog = async (type: number, title: string, row?: any) => {
  656. let res = { data: {} }
  657. if (row?.id) {
  658. res = await getBizProcessApi(row?.id || null)
  659. }
  660. // 重置表单
  661. setItemsOptions()
  662. const params = {
  663. title,
  664. width: 580,
  665. isEdit: type !== 3,
  666. itemsOptions: itemsOptions,
  667. model: type == 1 ? {} : res.data,
  668. api: type == 1 ? addBizProcessApi : updateBizProcessApi,
  669. getTableList: proTable.value?.getTableList
  670. }
  671. formDialogRef.value?.openDialog(params)
  672. }
  673. onUnmounted(() => {
  674. clearInterval(timer.value)
  675. timer.value = null
  676. })
  677. watch(
  678. () => dialogVisible.value,
  679. val => {
  680. if (!val) {
  681. clearInterval(timer2.value)
  682. timer2.value = null
  683. }
  684. }
  685. )
  686. // 表格配置项
  687. const columns = reactive<ColumnProps<any>[]>([
  688. { type: 'selection', fixed: 'left', width: 70 },
  689. // { prop: 'id', label: '主键ID' },
  690. // {
  691. // prop: 'subTaskId',
  692. // label: '子任务id',
  693. // search: {
  694. // el: 'input'
  695. // },
  696. // width: 120
  697. // },
  698. {
  699. prop: 'name',
  700. label: '任务名称',
  701. search: {
  702. el: 'input'
  703. },
  704. width: 120
  705. },
  706. // {
  707. // prop: 'type',
  708. // label: '任务类型',
  709. // search: {
  710. // el: 'input'
  711. // },
  712. // width: 120
  713. // },
  714. {
  715. prop: 'status',
  716. label: '任务状态',
  717. tag: true,
  718. enum: () => getDictsApi('biz_task_status'),
  719. search: {
  720. el: 'tree-select'
  721. },
  722. width: 100,
  723. fieldNames: { label: 'dictLabel', value: 'dictValue' }
  724. },
  725. // {
  726. // prop: 'algorithmId',
  727. // label: '算法',
  728. // width: 120
  729. // },
  730. // {
  731. // prop: 'modelId',
  732. // label: '模型',
  733. // width: 120
  734. // },
  735. {
  736. prop: 'parameters',
  737. label: '调用算法时所用的参数'
  738. },
  739. {
  740. prop: 'preprocessPath',
  741. label: '预处理数据路径'
  742. },
  743. {
  744. prop: 'resultPath',
  745. label: '结果数据路径'
  746. },
  747. {
  748. prop: 'index',
  749. label: '序号',
  750. width: 120
  751. },
  752. {
  753. prop: 'startTime',
  754. label: '开始时间'
  755. },
  756. {
  757. prop: 'endTime',
  758. label: '结束时间'
  759. },
  760. {
  761. prop: 'costSecond',
  762. label: '耗时(ms)'
  763. },
  764. {
  765. prop: 'remarks',
  766. label: '日志'
  767. },
  768. { prop: 'operation', label: '操作', width: 230, fixed: 'right' }
  769. ])
  770. // 结果表格配置项
  771. // const resultColumns = reactive<ColumnProps<any>[]>([])
  772. // 表单配置项
  773. let itemsOptions: ProForm.ItemsOptions[] = []
  774. const setItemsOptions = () => {
  775. itemsOptions = [
  776. {
  777. label: '子任务id',
  778. prop: 'subTaskId',
  779. compOptions: {
  780. placeholder: '请输入子任务id'
  781. }
  782. },
  783. {
  784. label: '任务名称',
  785. prop: 'name',
  786. compOptions: {
  787. placeholder: '请输入任务名称'
  788. }
  789. },
  790. {
  791. label: '任务类型',
  792. prop: 'type',
  793. compOptions: {
  794. placeholder: '请输入任务类型'
  795. }
  796. },
  797. {
  798. label: '任务状态',
  799. prop: 'status',
  800. compOptions: {
  801. elTagName: 'select',
  802. labelKey: 'dictLabel',
  803. valueKey: 'dictValue',
  804. enum: () => getDictsApi('biz_task_status'),
  805. placeholder: '请选择任务状态'
  806. }
  807. },
  808. {
  809. label: '算法',
  810. prop: 'algorithmId',
  811. compOptions: {
  812. placeholder: '请输入算法'
  813. }
  814. },
  815. {
  816. label: '模型',
  817. prop: 'modelId',
  818. compOptions: {
  819. placeholder: '请输入模型'
  820. }
  821. },
  822. {
  823. label: '调用算法时所用的参数',
  824. prop: 'parameters',
  825. compOptions: {
  826. type: 'textarea',
  827. clearable: true,
  828. placeholder: '请输入内容'
  829. }
  830. },
  831. {
  832. label: '预处理数据路径',
  833. prop: 'preprocessPath',
  834. compOptions: {
  835. placeholder: '请输入预处理数据路径'
  836. }
  837. },
  838. {
  839. label: '结果数据路径',
  840. prop: 'resultPath',
  841. compOptions: {
  842. placeholder: '请输入结果数据路径'
  843. }
  844. },
  845. {
  846. label: '序号',
  847. prop: 'index',
  848. compOptions: {
  849. placeholder: '请输入序号'
  850. }
  851. },
  852. {
  853. label: '开始时间',
  854. prop: 'startTime',
  855. compOptions: {
  856. elTagName: 'date-picker',
  857. type: 'date',
  858. placeholder: '请选择开始时间'
  859. }
  860. },
  861. {
  862. label: '结束时间',
  863. prop: 'endTime',
  864. compOptions: {
  865. elTagName: 'date-picker',
  866. type: 'date',
  867. placeholder: '请选择结束时间'
  868. }
  869. },
  870. {
  871. label: '耗时',
  872. prop: 'costSecond',
  873. compOptions: {
  874. placeholder: '请输入耗时'
  875. }
  876. },
  877. {
  878. label: '日志',
  879. prop: 'log',
  880. compOptions: {
  881. type: 'textarea',
  882. clearable: true,
  883. placeholder: '请输入内容'
  884. }
  885. }
  886. ]
  887. }
  888. </script>
  889. <style scoped lang="scss">
  890. .log {
  891. width: 90%;
  892. height: 60vh; /* 根据需要调整 */
  893. padding: 10px;
  894. // padding-bottom: 80px;
  895. margin-left: 50px;
  896. overflow-y: auto;
  897. font-family: 'Courier New', monospace;
  898. color: #4aff84;
  899. background-color: #1e1e1e;
  900. }
  901. .p {
  902. padding-left: 10px;
  903. margin-bottom: 5px;
  904. border-left: 3px solid #4aff84;
  905. }
  906. .resultShow {
  907. width: 100%;
  908. height: 60vh;
  909. overflow: hidden;
  910. overflow: scroll scroll;
  911. .headerRow {
  912. height: 50px;
  913. font-size: 1.2rem;
  914. line-height: 50px;
  915. text-align: center;
  916. }
  917. .row {
  918. .col {
  919. text-align: center;
  920. .oneCol {
  921. margin-top: 45px;
  922. font-size: 1.2rem;
  923. }
  924. .img {
  925. margin: 10px 0;
  926. }
  927. }
  928. }
  929. }
  930. </style>