index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. <template>
  2. <div class="height_100">
  3. <el-container v-if="showView">
  4. <el-header>
  5. <div id="step1">
  6. <mySearch style="width: 500px" :SearchFields="searchFiled" @search="search" :searchValue="searchOption"></mySearch>
  7. </div>
  8. </el-header>
  9. <el-main>
  10. <el-table v-loading="loading" :data="tableData" border header-row-class-name="custom-table-header" @sort-change="sortChange">
  11. <el-table-column label="#" type="index" align="center" width="55">
  12. <template slot-scope="scope">
  13. <span>{{ (scope.$index + 1) + ((queryParams.current - 1) * queryParams.size) }}</span>
  14. </template>
  15. </el-table-column>
  16. <el-table-column v-for="item in columnList.filter(item=>!item.ifHidden)" :key="item.value" :label="item.name" :prop="item.value" :min-width="item.value == 'percentage'?'200':'100'" align="center" sortable="custom">
  17. <template slot-scope="scope">
  18. <div v-if="item.value == 'type'" v-html="$commonJS.getColumnData(scope.row, item,null,{data:importType})"></div>
  19. <div v-else-if="item.value == 'state'" v-html="$commonJS.getColumnData(scope.row, item,null,{data:state})"></div>
  20. <div v-else-if="item.value == 'percentage'" style="display:flex;">
  21. <div style="width:100%">
  22. <el-progress :text-inside="true" :stroke-width="20" :percentage="scope.row.percentage>100?100:scope.row.percentage" :color="customColors"></el-progress>
  23. </div>
  24. <div style="min-width: 50px;">{{ scope.row.doneNum }}/{{ scope.row.allNum }}</div>
  25. </div>
  26. <div v-else v-html="$commonJS.getColumnData(scope.row, item)"></div>
  27. </template>
  28. </el-table-column>
  29. <el-table-column label="操作" align="center" width="150">
  30. <template slot-scope="scope" >
  31. <div class="operate">
  32. <!-- <el-link type="primary" @click.native="details(scope.row)">
  33. <el-tooltip class="item" effect="dark" content="下载" placement="top">
  34. <i class="el-icon-document"></i>
  35. </el-tooltip>
  36. </el-link> -->
  37. <el-link type="primary" @click.native="handleDownload(scope.row)" v-if="$permission('/workspace/common/taskDownload') && ((scope.row.type == 1 || scope.row.type == 2) && (scope.row.state !== 0 || scope.row.state !== 1))">
  38. <el-tooltip class="item" effect="dark" content="下载" placement="top">
  39. <i class="iconfont icon-xiazai"></i>
  40. </el-tooltip>
  41. </el-link>
  42. <el-link class="margin-left_10" type="primary" @click="updateImportTaskState(scope.row,4)" v-if="scope.row.state==1 || scope.row.state==0">
  43. <el-tooltip class="item" effect="dark" content="暂停" placement="top">
  44. <i class="iconfont icon-zanting1"></i>
  45. </el-tooltip>
  46. </el-link>
  47. <el-link class="margin-left_10" type="primary" @click="updateImportTaskState(scope.row,0)" v-if="scope.row.state==4">
  48. <el-tooltip class="item" type="primary" effect="dark" content="继续" placement="top">
  49. <i class="iconfont icon-zanting" ></i>
  50. </el-tooltip>
  51. </el-link>
  52. <el-link class="margin-left_10" type="primary" v-if="scope.row.taskType == 1" @click="updateLog(scope.row)">
  53. <el-tooltip class="item" effect="dark" content="更新记录" placement="top">
  54. <i class="iconfont icon-banbengengxinjilu" style="font-size:18px"></i>
  55. </el-tooltip>
  56. </el-link>
  57. <el-link class="margin-left_10" type="danger" @click.native="updateImportTaskState(scope.row,5)" v-if="(scope.row.state!=2 && scope.row.state!=5) || scope.row.taskType == 1" >
  58. <el-tooltip class="item" effect="dark" content="取消" placement="top">
  59. <i class="iconfont icon-quxiaorenwu1"></i>
  60. </el-tooltip>
  61. </el-link>
  62. </div>
  63. </template>
  64. </el-table-column>
  65. </el-table>
  66. </el-main>
  67. <el-footer class="pagination">
  68. <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>
  69. </el-footer>
  70. </el-container>
  71. </div>
  72. </template>
  73. <script>
  74. import { mapGetters } from "vuex";
  75. export default {
  76. components: {},
  77. props: {
  78. importToId:''
  79. },
  80. data() {
  81. return {
  82. //固定检索字段
  83. searchFiled2:{
  84. projectId:this.importToId
  85. },
  86. //检索字段
  87. searchFiled: [],
  88. //检索条件
  89. searchOption: {},
  90. //加载中
  91. loading: false,
  92. //任务的数据集合
  93. tableData: [],
  94. //分页信息
  95. queryParams: {
  96. current: 1,
  97. size: 10
  98. },
  99. //总条数
  100. total: 0,
  101. //排序
  102. sort: [
  103. {
  104. "orderBy": "createTime",
  105. "orderType": 1
  106. }
  107. ],
  108. columnList:[],//搜索的栏位
  109. showView:false,
  110. customColors: [
  111. {color: '#f56c6c', percentage: 20},
  112. {color: '#e6a23c', percentage: 40},
  113. {color: '#5cb87a', percentage: 60},
  114. {color: '#1989fa', percentage: 80},
  115. {color: '#6f7ad3', percentage: 100}
  116. ],
  117. };
  118. },
  119. watch: {},
  120. computed: {
  121. ...mapGetters(['webSocket', 'userinfo']),
  122. importType(){
  123. var a = this.$store.state.dictMessage.dictMessage.IMPORT_TASK_TYPE || []
  124. if(a.length>0){
  125. var obj = this.searchFiled.find(item=>{
  126. return item.value == 'type'
  127. })
  128. if(obj){
  129. obj.options = a
  130. }
  131. }
  132. return this.$store.state.dictMessage.dictMessage.IMPORT_TASK_TYPE || []
  133. },
  134. state(){
  135. var a = this.$store.state.dictMessage.dictMessage.IMPORT_TASK_TYPE || []
  136. if(a.length>0){
  137. var obj = this.searchFiled.find(item=>{
  138. return item.value == 'state'
  139. })
  140. if(obj){
  141. obj.options = a
  142. }
  143. }
  144. return this.$store.state.dictMessage.dictMessage.IMPORT_TASk_STATE
  145. }
  146. },
  147. created() {},
  148. async mounted() {
  149. this.initTask()
  150. this.columnList = await this.$commonJS.getCustomField('importTask')
  151. //获取table栏位及分组字段
  152. await this.getColumn()
  153. this.getList()
  154. },
  155. methods: {
  156. initTask() {
  157. // var webSocket = this.webSocket
  158. // console.log(webSocket)
  159. this.webSocket.onmessage = (e) => {
  160. if(e.data.indexOf('{') == -1){
  161. return false
  162. }
  163. const { code, data, message } = JSON.parse(e.data)
  164. // console.log({ code, data, message });
  165. // var a = {
  166. // "code": 903,
  167. // "data": {
  168. // "total": 9,
  169. // "index": 0,
  170. // "taskId": 117,
  171. // "taskStatus": 1,
  172. // "complete": false,
  173. // "url": "",
  174. // "fileName": "cd30d6d6285d49229be2a73c6812f457",
  175. // "taskType": 1,
  176. // "percentage": 0,
  177. // "oldName": ""
  178. // },
  179. // "message": "WebSocket请求成功"
  180. // }
  181. if(code === 900){
  182. if(data.doneType == -1){
  183. const index = this.tableData.findIndex(item=>{return item.id == data.taskId})
  184. if (index === -1) {
  185. } else {
  186. this.$set(this.tableData[index],'doneNum',data.index)
  187. this.$set(this.tableData[index],'percentage',data.percentage)
  188. this.$set(this.tableData[index],'state',data.taskStatus)
  189. }
  190. }
  191. }
  192. if (code === 903) {
  193. const index = this.tableData.findIndex(item=>{return item.id == data.taskId})
  194. if (index === -1) {
  195. } else {
  196. this.$set(this.tableData[index],'doneNum',data.index)
  197. this.$set(this.tableData[index],'percentage',data.percentage)
  198. this.$set(this.tableData[index],'state',data.taskStatus)
  199. }
  200. if (data.complete) {
  201. // if(data.taskType!=2){
  202. // this.$message.success(`导入任务完成`)
  203. // for(var i = 0;i<this.tableData.length;i++){
  204. // if(this.tableData[i].complete==true){
  205. // this.tableData.splice(i,1)
  206. // }
  207. // }
  208. // }else{
  209. // this.$message.success(`导出任务完成`)
  210. // }
  211. // console.log(this.form)
  212. // this.getList()
  213. }
  214. }
  215. // else if (code === 803 || code === 804) {
  216. // this.$message.error(message)
  217. // this.getList()
  218. // }
  219. }
  220. },
  221. //显示视图?
  222. showViews() {
  223. this.showView = false
  224. this.$nextTick(() => {
  225. this.showView = true
  226. })
  227. },
  228. //获取table栏位及分组字段、检索字段
  229. async getColumn() {
  230. let params = ['importTask']
  231. await this.$api.getParamsCommon(params).then(res => {
  232. if (res.code == 200) {
  233. let conditionDTOList= JSON.parse(JSON.stringify(res.data[0].conditionDTOList))
  234. // 搜索字段
  235. this.searchFiled = this.$commonJS.getField(conditionDTOList,(u)=> u.ifSearch == true ,{
  236. label: 'name',
  237. value: 'value',
  238. type:'type',
  239. })
  240. var options = ['type','state']
  241. options.forEach(item=>{
  242. this.getOption(item)
  243. })
  244. }
  245. })
  246. this.showViews()
  247. },
  248. getOption(type){
  249. var obj = this.searchFiled.find(item=>{
  250. return item.value == type
  251. })
  252. if(!obj){
  253. return false
  254. }
  255. switch(type){
  256. case 'type':
  257. obj.options = this.importType
  258. break;
  259. case 'state':
  260. obj.options = this.state
  261. break;
  262. }
  263. },
  264. //获取检索条件检索
  265. search(val) {
  266. let params = {}
  267. val.forEach(item => {
  268. if (item.type == 3) {
  269. params[item.value]=item.searchValue.map(itemValue => {
  270. return itemValue.value
  271. })
  272. } else {
  273. params[item.value]=item.searchValue.label
  274. }
  275. })
  276. // 返回条件对象
  277. this.searchOption=params
  278. // 调用查询接口
  279. this.queryParams.current=1
  280. this.getList()
  281. },
  282. //获取任务
  283. getList(){
  284. var params = {
  285. ...this.searchFiled2,
  286. ...this.searchOption
  287. }
  288. var params = {
  289. ...this.queryParams,
  290. searchQuery:this.$commonJS.objectToString(params),
  291. orderDTOList:this.sort
  292. }
  293. this.$api.queryImportTask(params).then(res => {
  294. if (res.code == 200) {
  295. this.tableData = res.data.data
  296. this.total=res.data.total
  297. }
  298. }).catch(err => {
  299. this.tableData = []
  300. this.total=0
  301. })
  302. },
  303. //分页
  304. handleCurrentChange(val){
  305. this.queryParams.current = val
  306. this.getList()
  307. },
  308. //排序
  309. sortChange({ column, prop, order }) {
  310. //如需要多个字段排序,则不需要清空
  311. var params = {
  312. sort:this.sort,
  313. column,
  314. prop,
  315. order,
  316. }
  317. this.sort = this.$commonJS.getSortData(params)
  318. this.queryParams.current = 0
  319. this.disabled = false
  320. this.tableData=[]
  321. this.getList()
  322. },
  323. // 网站导入暂停,继续任务操作
  324. async updateImportTaskState(row,state) {
  325. this.$api.updateImportTaskState({taskId:row.id,state:state}).then(response=>{
  326. if(response.code == 200){
  327. this.$set(row,'state',state)
  328. this.$message.success('操作成功')
  329. }
  330. })
  331. },
  332. //任务详情
  333. details(){
  334. },
  335. //下载附件
  336. handleDownload(row){
  337. }
  338. },
  339. };
  340. </script>
  341. <style lang="scss" scoped>
  342. </style>