index.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. <template>
  2. <div class="system-task">
  3. <el-container>
  4. <el-header class="position_relative">
  5. <div class="header-tabs">
  6. <el-tabs v-model="activeName" type="card">
  7. <el-tab-pane label="实时进度" name="0"></el-tab-pane>
  8. <el-tab-pane label="任务列表" name="1"></el-tab-pane>
  9. </el-tabs>
  10. </div>
  11. </el-header>
  12. <el-main class="system-task-main">
  13. <div v-if="activeName === '0'" key="task1">
  14. <el-table :data="taskData" border header-row-class-name="custom-table-header">
  15. <el-table-column v-if="form === 1" label="文件名称" prop="oldName" align="center" show-overflow-tooltip></el-table-column>
  16. <el-table-column label="任务数量" prop="total" align="center" show-overflow-tooltip></el-table-column>
  17. <el-table-column label="当前条数" prop="index" align="center" show-overflow-tooltip></el-table-column>
  18. <el-table-column label="实时进度" align="center" min-width="200px" show-overflow-tooltip>
  19. <template slot-scope="scope">
  20. <el-progress :text-inside="true" :stroke-width="20" :percentage="scope.row.percentage" :color="customColors"></el-progress>
  21. </template>
  22. </el-table-column>
  23. <el-table-column v-if="form === 2" label="操作" align="center" width="120" show-overflow-tooltip>
  24. <template slot-scope="scope">
  25. <span v-if="!scope.row.url">等待中</span>
  26. <el-link v-else type="primary" @click.native="handleDownload(scope.row)">下载文件</el-link>
  27. </template>
  28. </el-table-column>
  29. </el-table>
  30. </div>
  31. <div v-else key="task2">
  32. <el-form inline>
  33. <el-form-item label="创建人">
  34. <el-input v-model="queryParams.createUserName" size="small" placeholder="请输入创建人名称"></el-input>
  35. </el-form-item>
  36. <el-form-item>
  37. <el-button size="small" type="" @click="getList">搜索</el-button>
  38. </el-form-item>
  39. </el-form>
  40. <el-table v-loading="loading" :data="tableData" border header-row-class-name="custom-table-header">
  41. <el-table-column v-if="form === 1" label="文件名称" prop="taskName" align="center" show-overflow-tooltip></el-table-column>
  42. <el-table-column v-else label="#" type="index" align="center" width="55"></el-table-column>
  43. <el-table-column label="开始时间" align="center" show-overflow-tooltip>
  44. <template slot-scope="scope">
  45. <span>{{ scope.row.createDate }}</span>
  46. </template>
  47. </el-table-column>
  48. <el-table-column label="结束时间" align="center" show-overflow-tooltip>
  49. <template slot-scope="scope">
  50. <span>{{ scope.row.finishTime }}</span>
  51. </template>
  52. </el-table-column>
  53. <el-table-column label="任务状态" align="center" show-overflow-tooltip>
  54. <template slot-scope="scope">
  55. <span>{{ statusObj[scope.row.state] }}</span>
  56. </template>
  57. </el-table-column>
  58. <el-table-column prop="createUserName" label="创建人" align="center" width="120" show-overflow-tooltip></el-table-column>
  59. <el-table-column label="操作" align="center" width="120" show-overflow-tooltip>
  60. <template slot-scope="scope" v-if="scope.row.status !== 0">
  61. <el-link type="primary" @click.native="handleDownload(scope.row)" v-if="$permission('/workspace/common/taskDownload')">下载</el-link>
  62. <el-link class="margin-left_10" type="danger" @click.native="handleDelete(scope.row)" >删除</el-link>
  63. </template>
  64. </el-table-column>
  65. </el-table>
  66. <div class="pagination">
  67. <el-pagination :current-page.sync="queryParams.current" :page-size="queryParams.size" :total="total" @current-change="handleCurrentChange" layout="total, prev, pager, next, jumper" background></el-pagination>
  68. </div>
  69. </div>
  70. </el-main>
  71. </el-container>
  72. </div>
  73. </template>
  74. <script>
  75. import { mapGetters } from "vuex";
  76. import { downLoad2, getFileName } from "@/utils";
  77. export default {
  78. // props: {
  79. // form: Number,
  80. // },
  81. props:['form','reportId'],
  82. data() {
  83. return {
  84. activeName: '0',
  85. taskData: [],
  86. loading: false,
  87. total: 0,
  88. tableData: [],
  89. queryParams: {
  90. // status: null,
  91. state:0,
  92. size: 10,
  93. current: 1,
  94. // projectName: '',
  95. // type: 0,
  96. // order: 'desc',
  97. // createName: '',
  98. reportId: 0
  99. },
  100. statusObj: {
  101. 0: '队列中',
  102. 1: '进行中',
  103. 2: '成功',
  104. 3: '失败',
  105. },
  106. customColors: [
  107. {color: '#f56c6c', percentage: 20},
  108. {color: '#e6a23c', percentage: 40},
  109. {color: '#5cb87a', percentage: 60},
  110. {color: '#1989fa', percentage: 80},
  111. {color: '#6f7ad3', percentage: 100}
  112. ],
  113. taskType: {
  114. 1: '专利导入',
  115. 2: '专利导出',
  116. 3: '说明书导入',
  117. }
  118. }
  119. },
  120. computed: {
  121. ...mapGetters(['webSocket', 'userinfo'])
  122. },
  123. watch:{
  124. activeName(val){
  125. if(val==1){
  126. this.getList()
  127. }else{
  128. this.getQueueList()
  129. }
  130. },
  131. },
  132. mounted() {
  133. // this.queryParams.type = this.form
  134. // this.queryParams.reportId = this.reportId
  135. this.getQueueList()
  136. this.initTask()
  137. },
  138. methods: {
  139. initTask() {
  140. if(this.webSocket){
  141. this.webSocket.onmessage = (e) => {
  142. // console.log(e)
  143. const { code, data, message } = JSON.parse(e.data)
  144. // console.log(JSON.parse(e.data))
  145. if (code === 903 || code === 904) {
  146. const index = this.taskData.map(item => item.taskId).indexOf(data.taskId)
  147. if (index === -1) {
  148. // this.taskData.push(data)
  149. } else {
  150. this.$set(this.taskData, index, data)
  151. }
  152. if (data.complete) {
  153. if(this.form==1){
  154. this.$message.success(`导入任务完成`)
  155. for(var i = 0;i<this.taskData.length;i++){
  156. if(this.taskData[i].complete==true){
  157. this.taskData.splice(i,1)
  158. }
  159. }
  160. }else{
  161. this.$message.success(`导出任务完成`)
  162. }
  163. // console.log(this.form)
  164. this.getList()
  165. }
  166. } else if (code === 803 || code === 804) {
  167. this.$message.error(message)
  168. this.getList()
  169. }
  170. }
  171. }
  172. },
  173. getQueueList() {
  174. this.taskData = []
  175. this.queryParams.reportId = this.reportId
  176. this.queryParams.state=0
  177. this.$api.reImportTask(this.queryParams).then(response => {
  178. response.data.records.map(item => {
  179. this.taskData.push({
  180. reportId: item.reportId,
  181. total: item.importCount,
  182. index: 0,
  183. taskId: item.id,
  184. oldName: item.taskName,
  185. complete: false,
  186. url: '',
  187. fileName: '',
  188. taskType: item.type,
  189. percentage: 0
  190. })
  191. })
  192. })
  193. },
  194. handleDownload(row) {
  195. downLoad2(row.filePath)
  196. },
  197. handleDelete(row) {
  198. this.$confirm('确认删除本条数据吗?', '提示', {
  199. confirmButtonText: '确定',
  200. cancelButtonText: '取消',
  201. type: 'warning'
  202. }).then(() => {
  203. this.loading = true
  204. this.$api.deleteImportTask({ id: row.id }).then(response => {
  205. this.$message.success('删除成功')
  206. this.loading = false
  207. this.getList()
  208. }).catch(error => {
  209. this.loading = false
  210. })
  211. })
  212. },
  213. handleCurrentChange(val) {
  214. this.queryParams.current = val;
  215. this.getList();
  216. },
  217. getList() {
  218. this.loading = true
  219. this.queryParams.state = 2
  220. this.queryParams.reportId = this.reportId
  221. this.$api.reImportTask(this.queryParams).then(response => {
  222. this.tableData = response.data.records
  223. this.total = response.data.total
  224. this.loading = false
  225. }).catch(error => {
  226. this.loading = false
  227. })
  228. },
  229. }
  230. }
  231. </script>
  232. <style lang="scss">
  233. .system-task {
  234. height: 100%;
  235. .system-task-main {
  236. background: #fff;
  237. padding: 5px 20px;
  238. margin-top: 20px;
  239. }
  240. .header-tabs {
  241. position: absolute;
  242. bottom: 0;
  243. height: 100%;
  244. padding-right: 9px;
  245. left: 12px;
  246. .el-tabs {
  247. margin-top: 19px;
  248. }
  249. .el-tabs__header {
  250. margin-bottom: 0 !important;
  251. }
  252. }
  253. .pagination {
  254. text-align: center;
  255. margin: 20px 0;
  256. }
  257. }
  258. </style>