result.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <template>
  2. <div class="app-container">
  3. <el-descriptions title="运行结果" :column='2' class="desc">
  4. <el-descriptions-item label="算法类型">
  5. <dict-tag :options="dict.type.algorithm_type" :value="resultData.type" />
  6. </el-descriptions-item>
  7. <el-descriptions-item label="算法子类型">{{ resultData.algoSubName }}</el-descriptions-item>
  8. <el-descriptions-item label="名称">{{ resultData.name }}</el-descriptions-item>
  9. <el-descriptions-item label="运行状态">
  10. <dict-tag :options="dict.type.algo_run_status" :value="resultData.status" />
  11. </el-descriptions-item>
  12. <el-descriptions-item label="开始时间">{{ parseTime(resultData.startTime) }}</el-descriptions-item>
  13. <el-descriptions-item label="完成时间">{{ parseTime(resultData.completedTime) }}</el-descriptions-item>
  14. <el-descriptions-item label="耗时(s)">{{ resultData.costSecond }}</el-descriptions-item>
  15. <el-descriptions-item label="备注">{{ resultData.remark }}</el-descriptions-item>
  16. </el-descriptions>
  17. <el-form ref="form" :model="form" label-width="80px" class="form">
  18. <el-form-item v-for="item in form.ioSubList" :key="item.id" :label="item.name">
  19. <!-- <file-upload v-model="form.path"/> -->
  20. <image-preview v-if="form.status == 2 && imageList.includes(item.path.split('.').pop())" :src="item.path"
  21. class="img" />
  22. <template v-else-if="form.status == 2 && textList.includes(item.path.split('.').pop())">
  23. <div>
  24. <div v-show="fileContent" class="file-content">
  25. {{ fileContent }}
  26. </div>
  27. </div>
  28. </template>
  29. <template v-if="form.status == 2 && item.path.split('.').pop() == 'csv'">
  30. <div>
  31. <el-link type="primary" style="fontSize:1.3em;marginRight:20px">{{ item.path.split('/').pop() }}</el-link>
  32. <el-button
  33. size="mini"
  34. type="text"
  35. icon="el-icon-download"
  36. @click="download(item.path)"
  37. >{{ "下载文件" }}
  38. </el-button>
  39. </div>
  40. </template>
  41. </el-form-item>
  42. </el-form>
  43. </div>
  44. </template>
  45. <script>
  46. import { getAlgorithmDto } from '@/api/algoManager/algorithm'
  47. import { getAlgoSubOption } from '@/api/algoManager/algorithm'
  48. import { getIoSubList } from '@/api/conf/field'
  49. import { getInputFileList } from '@/api/algoManager/file'
  50. import { isExternal } from '@/utils/validate'
  51. import axios from 'axios'
  52. export default {
  53. name: 'Result',
  54. dicts: ['algorithm_type', 'algo_run_status'],
  55. data() {
  56. return {
  57. // 遮罩层
  58. loading: true,
  59. // 算法运行结果信息
  60. resultData: [],
  61. // 算法特定类列表
  62. algoTypeList: [],
  63. // 具体算法输入输出文件列表
  64. ioSubList: [],
  65. typeMap: new Map(),
  66. imageList: ['jpg', 'jpeg', 'png', 'bmp', 'gif'],
  67. textList: ['txt', 'doc', 'hlp', 'wps'],
  68. fileContent: '',
  69. // 表单参数
  70. form: {},
  71. // 输入文件表格数据
  72. inputFileList: [],
  73. }
  74. },
  75. created() {
  76. this.getResultData()
  77. },
  78. methods: {
  79. getResultData() {
  80. this.loading = true
  81. let id = this.$route.params.resultID
  82. console.log(id)
  83. getAlgorithmDto(id).then(response => {
  84. this.form = response.data
  85. this.resultData = response.data
  86. this.algoTypeList = this.typeMap.get(this.resultData.type)
  87. this.fetchFileContent(this.resultData.ioSubList)
  88. // 判断是不是csv文件,是的话可以显示在线下载
  89. this.getInputFileList()
  90. this.loading = false
  91. })
  92. },
  93. getInputFileList() {
  94. getInputFileList(this.resultData.subTypeId).then(resp => {
  95. this.inputFileList = resp.data
  96. console.info(resp)
  97. console.info(this)
  98. })
  99. },
  100. changeQueryType() {
  101. this.resultData.subTypeId = null
  102. this.algoTypeList = this.typeMap.get(this.queryParams.type)
  103. },
  104. changeFormType() {
  105. this.resultData.subTypeId = null
  106. this.algoTypeList = this.typeMap.get(this.resultData.type)
  107. },
  108. changeFormSubType() {
  109. if (this.resultData.subTypeId) {
  110. getIoSubList(this.resultData.subTypeId, this.resultData.id).then(
  111. resp => {
  112. this.ioSubList = resp.data
  113. console.info(resp)
  114. }
  115. )
  116. this.getInputFileList()
  117. } else {
  118. this.inputFileList = []
  119. }
  120. },
  121. download(path) {
  122. this.$download.resource(path);
  123. },
  124. // 拿到文本文件里的内容
  125. async fetchFileContent(ioSubList) {
  126. try {
  127. let filePath
  128. for (const item of ioSubList) {
  129. if (this.textList.includes(item.path.split('.').pop())) {
  130. filePath = item.path
  131. }
  132. }
  133. if (filePath) {
  134. const response = await axios.get(this.realSrc(filePath), {
  135. responseType: 'text',
  136. })
  137. this.fileContent = response.data
  138. console.log(this.fileContent)
  139. }
  140. } catch (error) {
  141. console.error('Error fetching the file:', error)
  142. }
  143. },
  144. // 通过path得到绝对路径
  145. realSrc(src) {
  146. if (!src) {
  147. return
  148. }
  149. const real_src = src.split(',')[0]
  150. if (isExternal(real_src)) {
  151. return real_src
  152. }
  153. return process.env.VUE_APP_BASE_API + real_src
  154. },
  155. download(path) {
  156. this.$download.resource(path)
  157. },
  158. },
  159. }
  160. </script>
  161. <style scoped lang='scss'>
  162. .app-container {
  163. width: 100%;
  164. height: 100%;
  165. display: flex;
  166. flex-direction: column;
  167. align-items: center;
  168. justify-content: center;
  169. .desc {
  170. width: 80%;
  171. padding-left: 40px;
  172. }
  173. .form {
  174. width: 80%;
  175. }
  176. }
  177. .img {
  178. width: 100%;
  179. }
  180. </style>