data/report
This commit is contained in:
parent
b52e17989a
commit
2c390df47d
@ -64,11 +64,17 @@ router.get('/report', async (req, res, next) => {
|
|||||||
category.map(item => {
|
category.map(item => {
|
||||||
if (!categoryInfo[item.methods]) {
|
if (!categoryInfo[item.methods]) {
|
||||||
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
|
categoryInfo[item.methods].method_name = item.method_display
|
||||||
methods.push(item.methods)
|
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)
|
const methodDataRes = await Promise.all(getMethodDataArr)
|
||||||
methodDataRes.forEach(item => {
|
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) {
|
item.data.sort(function(a, b) {
|
||||||
a = JSON.parse(a)
|
a = JSON.parse(a)
|
||||||
b = JSON.parse(b)
|
b = JSON.parse(b)
|
||||||
if (a.item_id >= b.item_id) {
|
return a[orderField] >= b[orderField] ? 1 : -1
|
||||||
return 1
|
|
||||||
} else if (a.item_id < b.item_id) {
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
} else {
|
||||||
|
item.data.sort()
|
||||||
}
|
}
|
||||||
|
|
||||||
item.data.forEach(d => {
|
const fields_name = []
|
||||||
const obj = {}
|
const records = []
|
||||||
d = JSON.parse(d)
|
|
||||||
for (const key in d) {
|
if (item.data[0]) {
|
||||||
if (d.hasOwnProperty(key)) {
|
const record = JSON.parse(item.data[0])
|
||||||
const ele = d[key]
|
for (const key in record) {
|
||||||
if (key !== 'name' && categoryInfo[item.method][key]) {
|
if (record.hasOwnProperty(key)) {
|
||||||
if (key === 'item_id') {
|
const idx = methodData.fields_order[key]
|
||||||
obj['道具名称'] = itemList[ele]
|
if (idx) {
|
||||||
? `${itemList[ele]}(${ele})`
|
const field_name =
|
||||||
: ele
|
key === 'item_id' ? '道具名称/ID' : methodData.fields[key]
|
||||||
} else {
|
fields_name[idx]
|
||||||
obj[categoryInfo[item.method][key]] = ele
|
? fields_name.splice(idx, 0, field_name)
|
||||||
}
|
: (fields_name[idx] = field_name)
|
||||||
} else if (key === 'name') {
|
} else {
|
||||||
obj.name = ele
|
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({
|
result.push({
|
||||||
method: item.method,
|
method: item.method,
|
||||||
method_name: categoryInfo[item.method].method_name,
|
method_name: methodData.method_name,
|
||||||
method_data: methodData,
|
fields_name: fields_name,
|
||||||
|
records: records,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
res.send({
|
res.send({
|
||||||
errcode: 0,
|
errcode: 0,
|
||||||
|
// categoryInfo: categoryInfo,
|
||||||
|
// methods: methods,
|
||||||
|
// methodDataRes: methodDataRes,
|
||||||
result: result,
|
result: result,
|
||||||
})
|
})
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user