From 6321e7ef23747bdc4d04cfa201b9a0dac2861214 Mon Sep 17 00:00:00 2001 From: "huziyang@jikimo.com" Date: Thu, 12 Jun 2025 15:38:56 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B4=A7=E4=BD=8D=E7=9C=8B=E6=9D=BF=E8=AF=A6?= =?UTF-8?q?=E6=83=85=E5=9B=9E=E9=80=80=E4=BF=AE=E5=A4=8D=EF=BC=8C=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E5=B9=BD=E7=81=B5=E5=8D=A1=E7=89=87=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../static/src/js/custom_kanban_controller.js | 53 +++++++++++++------ 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/sf_warehouse/static/src/js/custom_kanban_controller.js b/sf_warehouse/static/src/js/custom_kanban_controller.js index cea5b2d4..ab3a57d6 100644 --- a/sf_warehouse/static/src/js/custom_kanban_controller.js +++ b/sf_warehouse/static/src/js/custom_kanban_controller.js @@ -5,7 +5,7 @@ import { KanbanRenderer } from "@web/views/kanban/kanban_renderer"; import { kanbanView } from "@web/views/kanban/kanban_view"; import { registry } from "@web/core/registry"; import { useService } from "@web/core/utils/hooks"; -import { useState, onWillStart,onWillUnmount,onMounted } from "@odoo/owl"; +import { useState, onWillStart, onWillUnmount, onMounted } from "@odoo/owl"; // 自定义看板渲染器 @@ -23,30 +23,45 @@ class CustomKanbanController extends KanbanController { this._onUpdate = (payload) => { this._handleSearchUpdate(payload); }; - + this.env.services.user.updateContext({ isBaseStyle: true }); let self = this; // 获取货架分层数据 onWillStart(async () => { - this.searchModel.on('update',self,self._onUpdate); + this.searchModel.on('update', self, self._onUpdate); await this.loadShelfLayersData(); }); // 组件销毁时移除监听 onWillUnmount(() => { - this.searchModel.off('update',self,self._onUpdate); + this.searchModel.off('update', self, self._onUpdate); }); - + + // 监听视图切换事件以监控面包屑 + onMounted(() => { + this.handleRouteChange() + }); + } + + handleRouteChange() { + this.render(true); + let domain = this.searchModel.domain; + if (domain.length > 0) { + let shelfDomain = domain.find(item => item[0] === 'shelf_id'); + this.onShelfChange(shelfDomain[2]); + } else { + this.setKanbanStyle('sf_kanban_location_style'); + } } _handleSearchUpdate() { try { let domain = this.searchModel.domain; - if(domain.length > 0){ + if (domain.length > 0) { let shelfDomain = domain.find(item => item[0] === 'shelf_id'); - if(shelfDomain){ + if (shelfDomain) { let shelfId = shelfDomain[2]; // 如果货架ID存在,则设置相应的样式 if (shelfId) { @@ -60,7 +75,7 @@ class CustomKanbanController extends KanbanController { this.setKanbanStyle('sf_kanban_location_style'); } catch (error) { } - + } // 加载所有货架的层数数据 @@ -68,13 +83,13 @@ class CustomKanbanController extends KanbanController { this.shelfLayersMap = {}; const shelfIds = await this.orm.search('sf.shelf', []); const shelves = await this.orm.read('sf.shelf', shelfIds, ['id', 'layer_capacity']); - + shelves.forEach(shelf => { this.shelfLayersMap[shelf.id] = shelf.layer_capacity; }); } - setKanbanStyle(style){ + setKanbanStyle(style) { this.env.services.user.updateContext({ isBaseStyle: style === 'sf_kanban_location_style' }); @@ -88,10 +103,14 @@ class CustomKanbanController extends KanbanController { isHave = true; } }); - + // 添加新类 - if(isHave)kanbanViewEl.classList.add(style); + if (isHave) kanbanViewEl.classList.add(style); } + const ghostCards = document.querySelectorAll('.o_kanban_ghost'); + ghostCards.forEach(card => { + card.remove(); + }); } updatePagerLimit(limit) { @@ -111,7 +130,7 @@ class CustomKanbanController extends KanbanController { const [shelf] = await this.orm.read('sf.shelf', [shelfId], ['layer_capacity']); this.shelfLayersMap[shelfId] = shelf.layer_capacity; } - + // 获取该货架的层数 const layerCapacity = this.shelfLayersMap[shelfId]; // 根据层数设置不同的样式 @@ -120,10 +139,10 @@ class CustomKanbanController extends KanbanController { isBaseStyle = false; } } - if(isBaseStyle){ + if (isBaseStyle) { this.updatePagerLimit(this.defaultPagerLimit); } - else{ + else { this.updatePagerLimit(500); } this.setKanbanStyle(style); @@ -135,12 +154,12 @@ class CustomKanbanController extends KanbanController { getSystemDefaultLimit() { // 方法1:从用户服务获取默认值 const userService = this.env.services.user; - + // 获取用户配置的默认分页大小 if (userService && userService.user_context && userService.user_context.limit) { return userService.user_context.limit; } - + // 方法3:使用Odoo核心默认值(通常为80) return 80; }