data/report

This commit is contained in:
yulixing 2019-08-16 16:46:17 +08:00
parent b52e17989a
commit 2c390df47d

View File

@ -64,11 +64,17 @@ router.get('/report', async (req, res, next) => {
category.map(item => {
if (!categoryInfo[item.methods]) {
categoryInfo[item.methods] = {}
categoryInfo[item.methods].fields = {}
categoryInfo[item.methods].fields_order = {}
categoryInfo[item.methods].order = ''
categoryInfo[item.methods].method_name = item.method_display
methods.push(item.methods)
}
categoryInfo[item.methods][item.fields] = item.comment
if (item.need_sort) categoryInfo[item.methods].order = item.fields
categoryInfo[item.methods].fields[item.fields] = item.comment
categoryInfo[item.methods].fields_order[item.fields] = item.sort_num
})
// 请求各类数据
@ -79,52 +85,75 @@ router.get('/report', async (req, res, next) => {
const methodDataRes = await Promise.all(getMethodDataArr)
methodDataRes.forEach(item => {
const methodData = []
const methodData = categoryInfo[item.method]
// 道具排序
if (item.method === 'items_produce' || item.method === 'items_consum') {
// // 排序
if (methodData.order) {
const orderField = methodData.order
item.data.sort(function(a, b) {
a = JSON.parse(a)
b = JSON.parse(b)
if (a.item_id >= b.item_id) {
return 1
} else if (a.item_id < b.item_id) {
return -1
}
return a[orderField] >= b[orderField] ? 1 : -1
})
} else {
item.data.sort()
}
item.data.forEach(d => {
const obj = {}
d = JSON.parse(d)
for (const key in d) {
if (d.hasOwnProperty(key)) {
const ele = d[key]
if (key !== 'name' && categoryInfo[item.method][key]) {
if (key === 'item_id') {
obj['道具名称'] = itemList[ele]
? `${itemList[ele]}(${ele})`
: ele
} else {
obj[categoryInfo[item.method][key]] = ele
}
} else if (key === 'name') {
obj.name = ele
const fields_name = []
const records = []
if (item.data[0]) {
const record = JSON.parse(item.data[0])
for (const key in record) {
if (record.hasOwnProperty(key)) {
const idx = methodData.fields_order[key]
if (idx) {
const field_name =
key === 'item_id' ? '道具名称/ID' : methodData.fields[key]
fields_name[idx]
? fields_name.splice(idx, 0, field_name)
: (fields_name[idx] = field_name)
} else {
fields_name.push(field_name)
}
}
}
methodData.push(obj)
fields_name.splice(0, 1)
}
item.data.forEach(d => {
d = JSON.parse(d)
const record = []
for (const key in d) {
if (d.hasOwnProperty(key)) {
const val = key === 'item_id' ? itemList[d[key]] || d[key] : d[key]
const idx = methodData.fields_order[key]
// 若idx为0 不处理排序直接push
if (idx) {
record[idx] ? record.splice(idx, 0, val) : (record[idx] = val)
} else {
record.push(val)
}
}
}
record.splice(0, 1)
records.push(record)
})
result.push({
method: item.method,
method_name: categoryInfo[item.method].method_name,
method_data: methodData,
method_name: methodData.method_name,
fields_name: fields_name,
records: records,
})
})
res.send({
errcode: 0,
// categoryInfo: categoryInfo,
// methods: methods,
// methodDataRes: methodDataRes,
result: result,
})
} catch (err) {