功能增强:支持配置排序字段,Limit数量
This commit is contained in:
@@ -1,13 +1,13 @@
|
|||||||
/** @odoo-module **/
|
/** @odoo-module **/
|
||||||
|
|
||||||
import {ListController} from "@web/views/list/list_controller";
|
import { ListController } from "@web/views/list/list_controller";
|
||||||
import {patch} from "@web/core/utils/patch";
|
import { patch } from "@web/core/utils/patch";
|
||||||
import {onWillStart, useState, useRef, useExternalListener} from "@odoo/owl";
|
import { onWillStart, useState, useRef, useExternalListener,onWillRender} from "@odoo/owl";
|
||||||
import {Dropdown} from "@web/core/dropdown/dropdown";
|
import { Dropdown } from "@web/core/dropdown/dropdown";
|
||||||
import {CheckBox} from "@web/core/checkbox/checkbox";
|
import { CheckBox } from "@web/core/checkbox/checkbox";
|
||||||
import {useSortable} from "@web/core/utils/sortable_owl";
|
import { useSortable } from "@web/core/utils/sortable_owl";
|
||||||
import {useService} from "@web/core/utils/hooks";
|
import { useService } from "@web/core/utils/hooks";
|
||||||
import {usePosition} from "@web/core/position_hook";
|
import { usePosition } from "@web/core/position_hook";
|
||||||
|
|
||||||
|
|
||||||
patch(ListController.prototype, {
|
patch(ListController.prototype, {
|
||||||
@@ -18,13 +18,15 @@ patch(ListController.prototype, {
|
|||||||
this.ooColumnsRef = useRef('ooColumnsRef');
|
this.ooColumnsRef = useRef('ooColumnsRef');
|
||||||
this.ooManagerRef = useRef('ooManagerRef');
|
this.ooManagerRef = useRef('ooManagerRef');
|
||||||
this.ooListRef = useRef('ooListRef');
|
this.ooListRef = useRef('ooListRef');
|
||||||
|
|
||||||
this.ooManager = useState({
|
this.ooManager = useState({
|
||||||
state: false,
|
state: false,
|
||||||
key: '',
|
key: '',
|
||||||
filter: false,
|
filter: false,
|
||||||
serial_num: false,
|
serial_num: false,
|
||||||
sticky_end: false,
|
sticky_end: false,
|
||||||
|
default_order_field: '',
|
||||||
|
default_order_type: 'asc',
|
||||||
|
default_page_size: 0,
|
||||||
columns: this.archInfo.columns.filter((column) => {
|
columns: this.archInfo.columns.filter((column) => {
|
||||||
if (column.type === "field" && column.widget !== 'handle') {
|
if (column.type === "field" && column.widget !== 'handle') {
|
||||||
return column
|
return column
|
||||||
@@ -34,28 +36,20 @@ patch(ListController.prototype, {
|
|||||||
return column.name
|
return column.name
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(this.ooManager.columns)
|
|
||||||
|
|
||||||
onWillStart(async () => {
|
onWillStart(async () => {
|
||||||
const manager_data = await this.orm.call('ir.ui.view', 'get_manager_data', [this.env.config.viewId]);
|
const manager_data = await this.orm.call('ir.ui.view', 'get_manager_data', [this.env.config.viewId]);
|
||||||
console.log(manager_data)
|
|
||||||
if (!Object.keys(manager_data).length || !manager_data.columns) {
|
if (!Object.keys(manager_data).length || !manager_data.columns) {
|
||||||
this.ooManager.columns.forEach(val => {
|
this.ooManager.columns.forEach(val => {
|
||||||
val.visibility = !!!val.column_invisible;
|
val.visibility = !!!val.column_invisible;
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// 简化逻辑:如果字段不一致(字段名判断),则重置视图
|
// 简化逻辑:如果字段不一致(字段名判断),则重置视图
|
||||||
const currentColumns = this.ooManager.columns;
|
const currentColumns = this.ooManager.columns;
|
||||||
const savedColumns = manager_data.columns || [];
|
const savedColumns = manager_data.columns || [];
|
||||||
|
|
||||||
// 比较字段名是否一致
|
// 比较字段名是否一致
|
||||||
const currentColumnNames = currentColumns.map(col => col.name).sort();
|
const currentColumnNames = currentColumns.map(col => col.name).sort();
|
||||||
const savedColumnNames = savedColumns.map(col => col.name).sort();
|
const savedColumnNames = savedColumns.map(col => col.name).sort();
|
||||||
|
|
||||||
const isFieldConsistent = JSON.stringify(currentColumnNames) === JSON.stringify(savedColumnNames);
|
const isFieldConsistent = JSON.stringify(currentColumnNames) === JSON.stringify(savedColumnNames);
|
||||||
|
|
||||||
if (!isFieldConsistent) {
|
if (!isFieldConsistent) {
|
||||||
// 字段不一致,重置视图配置
|
// 字段不一致,重置视图配置
|
||||||
this.ooManager.columns.forEach(val => {
|
this.ooManager.columns.forEach(val => {
|
||||||
@@ -69,7 +63,19 @@ patch(ListController.prototype, {
|
|||||||
}
|
}
|
||||||
this.ooManager.show = manager_data.show;
|
this.ooManager.show = manager_data.show;
|
||||||
})
|
})
|
||||||
|
onWillRender(() => {
|
||||||
|
if (this.ooManager.default_page_size>0) {
|
||||||
|
this.model.config.limit = this.ooManager.default_page_size;
|
||||||
|
// this.model.load();
|
||||||
|
}
|
||||||
|
if (this.ooManager.default_order_field) {
|
||||||
|
this.model.config.orderBy = [];
|
||||||
|
this.model.config.orderBy.push({
|
||||||
|
name: this.ooManager.default_order_field,
|
||||||
|
[this.ooManager.default_order_type]: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
usePosition('ooListRef', () => this.ooManagerRef.el, {
|
usePosition('ooListRef', () => this.ooManagerRef.el, {
|
||||||
position: "bottom-start",
|
position: "bottom-start",
|
||||||
})
|
})
|
||||||
@@ -84,7 +90,6 @@ patch(ListController.prototype, {
|
|||||||
|
|
||||||
useExternalListener(window, "click", this.onGlobalClick.bind(this));
|
useExternalListener(window, "click", this.onGlobalClick.bind(this));
|
||||||
},
|
},
|
||||||
|
|
||||||
onGlobalClick(ev) {
|
onGlobalClick(ev) {
|
||||||
if (this.ooListRef.el && !this.ooListRef.el.contains(ev.target)) {
|
if (this.ooListRef.el && !this.ooListRef.el.contains(ev.target)) {
|
||||||
this.ooManager.state = false;
|
this.ooManager.state = false;
|
||||||
@@ -169,7 +174,7 @@ patch(ListController.prototype, {
|
|||||||
* @param params
|
* @param params
|
||||||
*/
|
*/
|
||||||
sortColumnDrop(params) {
|
sortColumnDrop(params) {
|
||||||
const {element, previous} = params;
|
const { element, previous } = params;
|
||||||
|
|
||||||
const fromId = element.dataset.id;
|
const fromId = element.dataset.id;
|
||||||
const toId = previous ? previous.dataset.id : null;
|
const toId = previous ? previous.dataset.id : null;
|
||||||
@@ -192,7 +197,6 @@ patch(ListController.prototype, {
|
|||||||
this.ooManager.columns = columns;
|
this.ooManager.columns = columns;
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存
|
* 保存
|
||||||
* @returns {*}
|
* @returns {*}
|
||||||
@@ -208,7 +212,10 @@ patch(ListController.prototype, {
|
|||||||
columns: this.ooManager.columns,
|
columns: this.ooManager.columns,
|
||||||
filter: this.ooManager.filter,
|
filter: this.ooManager.filter,
|
||||||
serial_num: this.ooManager.serial_num,
|
serial_num: this.ooManager.serial_num,
|
||||||
sticky_end: this.ooManager.sticky_end
|
sticky_end: this.ooManager.sticky_end,
|
||||||
|
default_order_field: this.ooManager.default_order_field,
|
||||||
|
default_order_type: this.ooManager.default_order_type,
|
||||||
|
default_page_size: this.ooManager.default_page_size,
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -39,6 +39,41 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<!-- 新增配置:默认页数和默认排序 -->
|
||||||
|
<div class="d-flex align-items-center pb-2">
|
||||||
|
<div class="d-flex align-items-center me-3">
|
||||||
|
<label class="me-1">默认页数:</label>
|
||||||
|
<input type="number" min="0" class="form-control"
|
||||||
|
t-model.number="ooManager.default_page_size"
|
||||||
|
t-on-blur="onChangeColumns"
|
||||||
|
style="width: 100px;"/>
|
||||||
|
</div>
|
||||||
|
<div class="d-flex align-items-center">
|
||||||
|
<label class="me-1">默认排序:</label>
|
||||||
|
<select class="form-select"
|
||||||
|
t-model="ooManager.default_order_field"
|
||||||
|
t-on-change="onChangeColumns"
|
||||||
|
style="width: 150px;">
|
||||||
|
<option t-att-value="''">默认</option>
|
||||||
|
<option t-foreach="ooManager.columns"
|
||||||
|
t-as="col"
|
||||||
|
t-key="col.id"
|
||||||
|
t-att-value="col.name">
|
||||||
|
<t t-esc="col.string"/>
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="d-flex align-items-center">
|
||||||
|
<label class="me-1">排序方式:</label>
|
||||||
|
<select class="form-select"
|
||||||
|
t-model="ooManager.default_order_type"
|
||||||
|
t-on-change="onChangeColumns"
|
||||||
|
style="width: 150px;">
|
||||||
|
<option value="asc">升序</option>
|
||||||
|
<option value='desc'>降序</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="d-flex align-items-center pb-2">
|
<div class="d-flex align-items-center pb-2">
|
||||||
<input type="text" class="form-control" t-model="ooManager.key"/>
|
<input type="text" class="form-control" t-model="ooManager.key"/>
|
||||||
<i class="btn btn-primary fa fa-refresh ms-2" t-on-click="()=>this.ooManager.key = ''"/>
|
<i class="btn btn-primary fa fa-refresh ms-2" t-on-click="()=>this.ooManager.key = ''"/>
|
||||||
|
|||||||
@@ -206,7 +206,6 @@ patch(ListRenderer.prototype, {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.props.ooManagerStickyEnd) {
|
if (this.props.ooManagerStickyEnd) {
|
||||||
console.log('ooManagerStickyEnd')
|
|
||||||
let rightOffset = 0;
|
let rightOffset = 0;
|
||||||
const rightStickyIndices = [];
|
const rightStickyIndices = [];
|
||||||
|
|
||||||
@@ -262,7 +261,6 @@ patch(ListRenderer.prototype, {
|
|||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
get hasOptionalFields() {
|
get hasOptionalFields() {
|
||||||
console.log('hasOptionalFields')
|
|
||||||
return false
|
return false
|
||||||
},
|
},
|
||||||
get displayOptionalFields() {
|
get displayOptionalFields() {
|
||||||
@@ -272,7 +270,6 @@ patch(ListRenderer.prototype, {
|
|||||||
|
|
||||||
getActiveColumns(list) {
|
getActiveColumns(list) {
|
||||||
if (this.props.ooManagerColumns) {
|
if (this.props.ooManagerColumns) {
|
||||||
console.log(this.allColumns)
|
|
||||||
const columns = this.allColumns.filter((col) => {
|
const columns = this.allColumns.filter((col) => {
|
||||||
if (list.isGrouped && col.widget === "handle") return false;
|
if (list.isGrouped && col.widget === "handle") return false;
|
||||||
const mColumn = this.props.ooManagerColumns.find(item => item.id === col.id);
|
const mColumn = this.props.ooManagerColumns.find(item => item.id === col.id);
|
||||||
|
|||||||
Reference in New Issue
Block a user