修复用户产线和工厂区域分页
This commit is contained in:
@@ -4,7 +4,7 @@ const BASE = 'production_configuration/factory_model/factory_area/'
|
|||||||
|
|
||||||
function apiParams (method, data = {}) {
|
function apiParams (method, data = {}) {
|
||||||
return {
|
return {
|
||||||
method: `production_master_data_factory_model_factory_area_${method}`,
|
method: `production_configuration_factory_model_factory_area_${method}`,
|
||||||
platform: 'background',
|
platform: 'background',
|
||||||
...data
|
...data
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ const BASE = 'production_configuration/factory_model/factory_line/'
|
|||||||
|
|
||||||
function apiParams (method, data = {}) {
|
function apiParams (method, data = {}) {
|
||||||
return {
|
return {
|
||||||
method: `production_master_data_factory_model_factory_line_${method}`,
|
method: `production_configuration_factory_model_factory_line_${method}`,
|
||||||
platform: 'background',
|
platform: 'background',
|
||||||
...data
|
...data
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,11 +25,12 @@
|
|||||||
:loading="loading"
|
:loading="loading"
|
||||||
:toolbar-buttons="toolbarButtons"
|
:toolbar-buttons="toolbarButtons"
|
||||||
:row-buttons="rowButtons"
|
:row-buttons="rowButtons"
|
||||||
:pagination="null"
|
:pagination="pagination"
|
||||||
:table-attrs="tableAttrs"
|
:table-attrs="tableAttrs"
|
||||||
help-url="/help/factory-area"
|
help-url="/help/factory-area"
|
||||||
:help-text="$t(ckey('help'))"
|
:help-text="$t(ckey('help'))"
|
||||||
auto-height
|
auto-height
|
||||||
|
@page-change="onPageChange"
|
||||||
@selection-change="onSelect"
|
@selection-change="onSelect"
|
||||||
>
|
>
|
||||||
</page-table>
|
</page-table>
|
||||||
@@ -82,6 +83,7 @@ export default {
|
|||||||
editId: '',
|
editId: '',
|
||||||
handleType: 'create',
|
handleType: 'create',
|
||||||
search: { code: '', name: '' },
|
search: { code: '', name: '' },
|
||||||
|
pagination: { current: 1, size: 10, total: 0 },
|
||||||
tableAttrs: { defaultExpandAll: true, treeProps: { children: 'children', hasChildren: 'hasChildren' } },
|
tableAttrs: { defaultExpandAll: true, treeProps: { children: 'children', hasChildren: 'hasChildren' } },
|
||||||
formData: { code: '', name: '', parent_id: '', remark: '' },
|
formData: { code: '', name: '', parent_id: '', remark: '' },
|
||||||
rules: {
|
rules: {
|
||||||
@@ -138,11 +140,22 @@ export default {
|
|||||||
return ''
|
return ''
|
||||||
},
|
},
|
||||||
normalizeResponse (res) {
|
normalizeResponse (res) {
|
||||||
const data = res && res.data !== undefined ? res.data : res
|
const getTotal = (source, fallback) => {
|
||||||
if (Array.isArray(data)) return { list: data, total: data.length }
|
if (!source) return fallback
|
||||||
if (data && Array.isArray(data.list)) return { list: data.list, total: Number(data.count || data.total || data.list.length) }
|
const total = source.count ?? source.total ?? source.total_count ?? source.record_count
|
||||||
if (data && Array.isArray(data.data)) return { list: data.data, total: Number(data.count || data.total || data.data.length) }
|
const value = Number(total)
|
||||||
if (data && data.data && Array.isArray(data.data.data)) return { list: data.data.data, total: Number(data.data.count || data.data.total || data.data.data.length) }
|
return Number.isNaN(value) ? fallback : value
|
||||||
|
}
|
||||||
|
const containers = [res, res && res.data, res && res.data && res.data.data].filter(Boolean)
|
||||||
|
for (const item of containers) {
|
||||||
|
if (Array.isArray(item)) {
|
||||||
|
return { list: item, total: getTotal(res, item.length) }
|
||||||
|
}
|
||||||
|
const list = item.data || item.list || item.rows || item.records || item.items
|
||||||
|
if (Array.isArray(list)) {
|
||||||
|
return { list, total: getTotal(item, getTotal(res, list.length)) }
|
||||||
|
}
|
||||||
|
}
|
||||||
return { list: [], total: 0 }
|
return { list: [], total: 0 }
|
||||||
},
|
},
|
||||||
normalizeNode (row, level = 0) {
|
normalizeNode (row, level = 0) {
|
||||||
@@ -185,19 +198,31 @@ export default {
|
|||||||
async fetchData () {
|
async fetchData () {
|
||||||
this.loading = true
|
this.loading = true
|
||||||
try {
|
try {
|
||||||
const res = await getFactoryAreaList({ ...this.search, page_no: 1, page_size: 10000 })
|
const res = await getFactoryAreaList({
|
||||||
|
...this.search,
|
||||||
|
page_no: this.pagination.current,
|
||||||
|
page_size: this.pagination.size
|
||||||
|
})
|
||||||
const data = this.normalizeResponse(res)
|
const data = this.normalizeResponse(res)
|
||||||
this.rawAreaData = data.list
|
this.rawAreaData = data.list
|
||||||
this.tableData = this.buildTree(data.list)
|
this.tableData = this.buildTree(data.list)
|
||||||
|
this.pagination.total = data.total
|
||||||
} finally {
|
} finally {
|
||||||
this.loading = false
|
this.loading = false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onSearch () {
|
onSearch () {
|
||||||
|
this.pagination.current = 1
|
||||||
this.fetchData()
|
this.fetchData()
|
||||||
},
|
},
|
||||||
onReset () {
|
onReset () {
|
||||||
this.search = { code: '', name: '' }
|
this.search = { code: '', name: '' }
|
||||||
|
this.pagination.current = 1
|
||||||
|
this.fetchData()
|
||||||
|
},
|
||||||
|
onPageChange (page) {
|
||||||
|
this.pagination.current = page.current
|
||||||
|
this.pagination.size = page.size
|
||||||
this.fetchData()
|
this.fetchData()
|
||||||
},
|
},
|
||||||
onSelect (rows) {
|
onSelect (rows) {
|
||||||
@@ -251,6 +276,7 @@ export default {
|
|||||||
const ok = await this.confirmAction(this.key('confirm_delete'), () => deleteFactoryArea({ id: [this.getId(row)] }))
|
const ok = await this.confirmAction(this.key('confirm_delete'), () => deleteFactoryArea({ id: [this.getId(row)] }))
|
||||||
if (!ok) return
|
if (!ok) return
|
||||||
this.$message.success(this.$t(this.key('operation_success')))
|
this.$message.success(this.$t(this.key('operation_success')))
|
||||||
|
this.pagination.current = Math.min(this.pagination.current, Math.ceil((this.pagination.total - 1) / this.pagination.size) || 1)
|
||||||
this.fetchData()
|
this.fetchData()
|
||||||
},
|
},
|
||||||
async handleExport () {
|
async handleExport () {
|
||||||
|
|||||||
@@ -176,11 +176,22 @@ export default {
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
normalizeResponse (res) {
|
normalizeResponse (res) {
|
||||||
const data = res && res.data !== undefined ? res.data : res
|
const getTotal = (source, fallback) => {
|
||||||
if (Array.isArray(data)) return { list: data, total: data.length }
|
if (!source) return fallback
|
||||||
if (data && Array.isArray(data.list)) return { list: data.list, total: Number(data.count || data.total || data.list.length) }
|
const total = source.count ?? source.total ?? source.total_count ?? source.record_count
|
||||||
if (data && Array.isArray(data.data)) return { list: data.data, total: Number(data.count || data.total || data.data.length) }
|
const value = Number(total)
|
||||||
if (data && data.data && Array.isArray(data.data.data)) return { list: data.data.data, total: Number(data.data.count || data.data.total || data.data.data.length) }
|
return Number.isNaN(value) ? fallback : value
|
||||||
|
}
|
||||||
|
const containers = [res, res && res.data, res && res.data && res.data.data].filter(Boolean)
|
||||||
|
for (const item of containers) {
|
||||||
|
if (Array.isArray(item)) {
|
||||||
|
return { list: item, total: getTotal(res, item.length) }
|
||||||
|
}
|
||||||
|
const list = item.data || item.list || item.rows || item.records || item.items
|
||||||
|
if (Array.isArray(list)) {
|
||||||
|
return { list, total: getTotal(item, getTotal(res, list.length)) }
|
||||||
|
}
|
||||||
|
}
|
||||||
return { list: [], total: 0 }
|
return { list: [], total: 0 }
|
||||||
},
|
},
|
||||||
async initAreaOptions () {
|
async initAreaOptions () {
|
||||||
|
|||||||
@@ -319,11 +319,22 @@ export default {
|
|||||||
} catch { /* 忽略 */ }
|
} catch { /* 忽略 */ }
|
||||||
},
|
},
|
||||||
normalizeResponse (res) {
|
normalizeResponse (res) {
|
||||||
const data = res && res.data !== undefined ? res.data : res
|
const getTotal = (source, fallback) => {
|
||||||
if (Array.isArray(data)) return { list: data, total: data.length }
|
if (!source) return fallback
|
||||||
if (data && Array.isArray(data.list)) return { list: data.list, total: Number(data.count || data.total || data.list.length) }
|
const total = source.count ?? source.total ?? source.total_count ?? source.record_count
|
||||||
if (data && Array.isArray(data.data)) return { list: data.data, total: Number(data.count || data.total || data.data.length) }
|
const value = Number(total)
|
||||||
if (data && data.data && Array.isArray(data.data.data)) return { list: data.data.data, total: Number(data.data.count || data.data.total || data.data.data.length) }
|
return Number.isNaN(value) ? fallback : value
|
||||||
|
}
|
||||||
|
const containers = [res, res && res.data, res && res.data && res.data.data].filter(Boolean)
|
||||||
|
for (const item of containers) {
|
||||||
|
if (Array.isArray(item)) {
|
||||||
|
return { list: item, total: getTotal(res, item.length) }
|
||||||
|
}
|
||||||
|
const list = item.data || item.list || item.rows || item.records || item.items
|
||||||
|
if (Array.isArray(list)) {
|
||||||
|
return { list, total: getTotal(item, getTotal(res, list.length)) }
|
||||||
|
}
|
||||||
|
}
|
||||||
return { list: [], total: 0 }
|
return { list: [], total: 0 }
|
||||||
},
|
},
|
||||||
async fetchData () {
|
async fetchData () {
|
||||||
|
|||||||
Reference in New Issue
Block a user