优化分页配置

This commit is contained in:
夜未央
2025-08-24 22:17:20 +08:00
parent 439037d94f
commit 1048d9e4db
@@ -2,13 +2,12 @@
import { ListController } from "@web/views/list/list_controller";
import { patch } from "@web/core/utils/patch";
import { onWillStart, useState, useRef, useExternalListener, onWillRender } from "@odoo/owl";
import { onWillStart, useState, useRef, useExternalListener, onMounted } from "@odoo/owl";
import { Dropdown } from "@web/core/dropdown/dropdown";
import { CheckBox } from "@web/core/checkbox/checkbox";
import { useSortable } from "@web/core/utils/sortable_owl";
import { useService } from "@web/core/utils/hooks";
import { usePosition } from "@web/core/position_hook";
import { usePager } from "@web/search/pager_hook";
patch(ListController.prototype, {
setup() {
@@ -36,6 +35,27 @@ patch(ListController.prototype, {
return column.name
})
});
onMounted(async () => {
if (this.ooManager.default_page_size > 0) {
const limit = this.ooManager.default_page_size || 80;
if (this.ooManager.default_order_field && this.model.config.limit != this.ooManager.default_page_size) {
this.model.config.orderBy = [{
name: this.ooManager.default_order_field,
[this.ooManager.default_order_type || 'asc']: true
}];
this.model.config.limit = limit;
await this.model.root.load();
}
} else {
if (this.ooManager.default_order_field) {
this.model.config.orderBy = [{
name: this.ooManager.default_order_field,
[this.ooManager.default_order_type || 'asc']: true
}];
await this.model.root.load();
}
}
});
onWillStart(async () => {
const manager_data = await this.orm.call('ir.ui.view', 'get_manager_data', [this.env.config.viewId]);
if (!Object.keys(manager_data).length || !manager_data.columns) {
@@ -63,14 +83,6 @@ patch(ListController.prototype, {
}
this.ooManager.show = manager_data.show;
})
onWillRender(async() => {
if (this.ooManager.default_order_field) {
this.model.config.orderBy = [{
name: this.ooManager.default_order_field,
[this.ooManager.default_order_type || 'asc']: true
}]
}
})
usePosition('ooListRef', () => this.ooManagerRef.el, {
position: "bottom-start",
})
@@ -83,36 +95,6 @@ patch(ListController.prototype, {
onDrop: (params) => this.sortColumnDrop(params)
})
useExternalListener(window, "click", this.onGlobalClick.bind(this));
usePager(() => {
if (this.model.useSampleModel) {
return;
}
const { count, hasLimitedCount, isGrouped, offset } = this.model.root;
let { limit } = this.model.root;
limit = this.ooManager.default_page_size > 0
? this.ooManager.default_page_size
: limit;
return {
offset,
limit,
total: count,
onUpdate: async ({ offset, limit }, hasNavigated) => {
if (this.editedRecord) {
if (!(await this.editedRecord.save())) {
return;
}
}
await this.model.root.load({ limit, offset });
if (hasNavigated) {
this.onPageChangeScroll();
}
},
updateTotal:
!isGrouped && hasLimitedCount
? () => this.model.root.fetchCount()
: undefined,
};
});
},
onGlobalClick(ev) {
if (this.ooListRef.el && !this.ooListRef.el.contains(ev.target)) {