initData.js
3.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import { initData } from '@/api/data'
import { isBlank, isInteger } from '@/utils/validate'
import { deepCopy } from '../utils/common-util'
export default {
data() {
return {
loading: true, copyData: [], data: [], page: 0, size: 10, sort: 'id,desc', total: 0, url: '', params: {}, query: { type: '', value: '' }, time: 170, isAdd: false, curQueryType: undefined, downloadLoading: false
}
},
methods: {
async init(type) {
if (!await this.beforeInit()) {
this.loading = false
return
}
// console.log(this.params, 'sdfhisdjkf')
return new Promise((resolve, reject) => {
this.loading = true
initData(this.url, this.params).then(res => {
this.total = res.totalElements
this.data = res.content
this.copyData = deepCopy(this.data)
if (type && type === 'input') {
this.data.forEach(item => {
item.copyEpisodeC2Status = []
for (const key in item.episodeC2Status) {
const obj = {
name: key
}
const sobj = {}
Object.assign(sobj, obj, item.episodeC2Status[key])
sobj.successNum = sobj.episodeCount ? Math.ceil((sobj.successCount / sobj.episodeCount) * 130) : 0
sobj.failNum = sobj.episodeCount ? Math.ceil((sobj.failureCount / sobj.episodeCount) * 130) : 0
item.copyEpisodeC2Status.push(sobj)
}
})
} else if (type && type === 'hasInput') {
this.data.forEach(item => {
item.successNum = item.cmdCount ? Math.ceil((item.successCount / item.cmdCount) * 130) : 0
item.failNum = item.cmdCount ? Math.ceil((item.failureCount / item.cmdCount) * 130) : 0
})
}
setTimeout(() => {
this.loading = false
}, this.time)
resolve(res)
}).catch(err => {
this.loading = false
reject(err)
}).finally(() => {
if (this.codesResultList !== null && this.codesResultList !== undefined) {
this.codesResultList = []
}
})
})
},
beforeInit() {
return true
},
pageChange(e, type) {
this.page = e - 1
this.init(type)
},
sizeChange(e, type) {
this.page = 0
this.size = e
this.init(type)
},
sortChange(data) {
const { prop, order } = data
let direction
if (order === 'ascending') {
direction = 'asc'
} else {
direction = 'desc'
}
this.sort = prop + ',' + direction
this.page = 0
// console.log(this.sort)
this.init()
},
// 预防删除第二页最后一条数据时,或者多选删除第二页的数据时,页码错误导致请求无数据
dleChangePage(size) {
if (size === undefined) {
size = 1
}
if (this.data.length === size && this.page !== 0) {
this.page = this.page - 1
}
},
toQuery(type) {
if (this.curQueryType) {
const value = this.query.value
const display = this.curQueryType.display_name
// 在queryTypeOptions需要校验的对象加上type='number'
if (this.curQueryType.type === 'number') {
// 如果值非空且不为数字则弹出错误提示
if (!isBlank(value) && !isInteger(value)) {
this.$message.error(display + '必须为整数')
return
}
}
}
this.page = 0
this.init(type)
},
// el-select change函数,为curQueryType赋值,为查询输入内容进行类型校验
typeChange(val, options) {
this.curQueryType = options.find(item => {
return item.key === val
})
}
}
}