Przeglądaj źródła

feat(订单管理): 实现跨页选择功能

yz 1 tydzień temu
rodzic
commit
72aa5626fb

+ 421 - 0
src/utils/lifecycle-manager.js

@@ -0,0 +1,421 @@
+/**
+ * 生命周期管理器
+ * @fileoverview 处理跨页选择的生命周期管理和状态同步
+ */
+
+/**
+ * 生命周期管理器类
+ * 负责管理组件生命周期中的选择状态保存和恢复
+ */
+class LifecycleManager {
+  constructor(selectionManager, componentInstance) {
+    this.selectionManager = selectionManager;
+    this.component = componentInstance;
+
+    // 生命周期状态跟踪
+    this.currentState = 'idle'; // idle, page-changing, loading, exporting
+    this.lastPageNumber = 1;
+
+    // 性能优化
+    this.debounceTimers = new Map();
+  }
+
+  /**
+   * 页面变化前的处理
+   * @param {number} newPage 新页码
+   */
+  onPageChange(newPage) {
+    if (this.currentState === 'page-changing') {
+      console.warn('LifecycleManager: 页面正在切换中,忽略重复操作');
+      return;
+    }
+
+    try {
+      this.currentState = 'page-changing';
+
+      // 1. 保存当前页的选择状态
+      this.saveCurrentPageSelection();
+
+      // 2. 更新选择元数据(记录在哪一页选择的)
+      this.updateSelectionPageInfo(newPage);
+
+      // 3. 清理过期数据
+      this.cleanupExpiredData();
+
+      console.log(`LifecycleManager: 页面切换准备完成 ${this.lastPageNumber} -> ${newPage}`);
+
+    } catch (error) {
+      console.error('LifecycleManager: 页面切换处理失败', error);
+    } finally {
+      this.lastPageNumber = newPage;
+    }
+  }
+
+  /**
+   * 页面数据加载完成后的处理
+   * @param {Array} pageData 页面数据
+   */
+  onPageDataLoaded(pageData) {
+    if (this.currentState !== 'page-changing' && this.currentState !== 'loading') {
+      console.warn('LifecycleManager: 非预期状态下调用页面数据加载处理');
+    }
+
+    try {
+      this.currentState = 'loading';
+
+      // 1. 延迟恢复选择状态,确保DOM渲染完成
+      this.debounceAction('restoreSelection', () => {
+        this.restoreSelectionState(pageData);
+      }, 100);
+
+      // 2. 更新组件UI状态
+      this.updateComponentUI();
+
+      console.log(`LifecycleManager: 页面数据加载处理完成,共 ${pageData.length} 条数据`);
+
+    } catch (error) {
+      console.error('LifecycleManager: 页面数据加载处理失败', error);
+    } finally {
+      // 延迟重置状态,确保恢复操作完成
+      setTimeout(() => {
+        this.currentState = 'idle';
+      }, 200);
+    }
+  }
+
+  /**
+   * 导出前的处理
+   */
+  beforeExport() {
+    if (this.currentState === 'exporting') {
+      console.warn('LifecycleManager: 正在导出中,忽略重复操作');
+      return false;
+    }
+
+    try {
+      this.currentState = 'exporting';
+
+      // 1. 验证选择数据
+      const validation = this.selectionManager.validateSelections();
+      if (!validation.isValid) {
+        console.warn('LifecycleManager: 选择数据验证失败', validation.issues);
+        // 继续执行,但记录警告
+      }
+
+      // 2. 获取导出数据
+      const exportData = this.selectionManager.getAllSelections();
+
+      if (exportData.length === 0) {
+        console.warn('LifecycleManager: 没有选中任何订单');
+        this.currentState = 'idle';
+        return false;
+      }
+
+      // 3. 检查数据量限制
+      if (exportData.length > this.selectionManager.MAX_SELECTIONS) {
+        console.error(`LifecycleManager: 选择数量超出限制 ${exportData.length} > ${this.selectionManager.MAX_SELECTIONS}`);
+        this.currentState = 'idle';
+        return false;
+      }
+
+      console.log(`LifecycleManager: 导出准备完成,将导出 ${exportData.length} 个订单`);
+      return exportData;
+
+    } catch (error) {
+      console.error('LifecycleManager: 导出前处理失败', error);
+      this.currentState = 'idle';
+      return false;
+    }
+  }
+
+  /**
+   * 导出完成后的处理
+   * @param {boolean} success 导出是否成功
+   */
+  afterExport(success) {
+    try {
+      if (success) {
+        // 1. 清空所有选择
+        const clearedCount = this.selectionManager.clearAllSelections();
+        console.log(`LifecycleManager: 导出成功,已清理 ${clearedCount} 个选择`);
+
+        // 2. 重置组件状态
+        this.resetComponentState();
+
+        // 3. 显示成功提示
+        this.showSuccessMessage(clearedCount);
+      } else {
+        console.warn('LifecycleManager: 导出失败,保持选择状态');
+      }
+
+    } catch (error) {
+      console.error('LifecycleManager: 导出后处理失败', error);
+    } finally {
+      this.currentState = 'idle';
+    }
+  }
+
+  /**
+   * 组件销毁时的处理
+   */
+  onComponentDestroy() {
+    try {
+      // 1. 清理所有定时器
+      this.clearAllDebounceTimers();
+
+      // 2. 保存当前选择状态(可选,根据需求决定)
+      // this.saveCurrentPageSelection();
+
+      // 3. 清理选择管理器数据
+      this.selectionManager.clearAllSelections();
+
+      // 4. 清理组件引用
+      this.component = null;
+
+      console.log('LifecycleManager: 组件销毁处理完成');
+
+    } catch (error) {
+      console.error('LifecycleManager: 组件销毁处理失败', error);
+    }
+  }
+
+  /**
+   * 保存当前页选择状态
+   */
+  saveCurrentPageSelection() {
+    if (!this.component || !this.component.selectionList) {
+      return;
+    }
+
+    try {
+      const currentSelection = this.component.selectionList;
+      this.selectionManager.mergeWithCurrentPage(currentSelection);
+
+      console.log(`LifecycleManager: 已保存当前页 ${currentSelection.length} 个选择`);
+
+    } catch (error) {
+      console.error('LifecycleManager: 保存当前页选择失败', error);
+    }
+  }
+
+  /**
+   * 更新选择页面信息
+   * @param {number} pageNumber 页码
+   */
+  updateSelectionPageInfo(pageNumber) {
+    try {
+      const currentPageIds = this.selectionManager.currentPageSelections;
+
+      currentPageIds.forEach(orderId => {
+        this.selectionManager.updateSelectionMeta(orderId, {
+          selectedPage: pageNumber
+        });
+      });
+
+    } catch (error) {
+      console.error('LifecycleManager: 更新选择页面信息失败', error);
+    }
+  }
+
+  /**
+   * 恢复选择状态
+   * @param {Array} pageData 页面数据
+   */
+  restoreSelectionState(pageData) {
+    if (!this.component || !this.component.$refs || !this.component.$refs.crud) {
+      console.warn('LifecycleManager: 组件引用不完整,无法恢复选择状态');
+      return;
+    }
+
+    try {
+      // 1. 找出当前页面中被选中的订单
+      const selectedInPage = this.selectionManager.restorePageSelection(pageData);
+
+      if (selectedInPage.length === 0) {
+        console.log('LifecycleManager: 当前页面没有需要恢复的选择');
+        return;
+      }
+
+      // 2. 通过avue-crud设置选择状态
+      this.component.$nextTick(() => {
+        try {
+          const crudRef = this.component.$refs.crud;
+
+          // 查找对应的数据行
+          const selectedRows = pageData.filter(row => selectedInPage.includes(row.id));
+
+          // 设置选择状态
+          selectedRows.forEach(row => {
+            crudRef.toggleRowSelection(row, true);
+          });
+
+          console.log(`LifecycleManager: 已恢复 ${selectedRows.length} 个选择状态`);
+
+        } catch (error) {
+          console.error('LifecycleManager: 设置avue-crud选择状态失败', error);
+        }
+      });
+
+    } catch (error) {
+      console.error('LifecycleManager: 恢复选择状态失败', error);
+    }
+  }
+
+  /**
+   * 更新组件UI状态
+   */
+  updateComponentUI() {
+    if (!this.component) {
+      return;
+    }
+
+    try {
+      // 更新选择计数
+      this.component.selectionCount = this.selectionManager.getSelectionCount();
+
+      // 更新清空按钮显示状态
+      this.component.showClearButton = this.component.selectionCount > 0;
+
+      // 触发组件重新渲染
+      this.component.$forceUpdate();
+
+    } catch (error) {
+      console.error('LifecycleManager: 更新组件UI失败', error);
+    }
+  }
+
+  /**
+   * 重置组件状态
+   */
+  resetComponentState() {
+    if (!this.component) {
+      return;
+    }
+
+    try {
+      // 重置选择相关数据
+      this.component.selectionList = [];
+      this.component.selectionCount = 0;
+      this.component.showClearButton = false;
+
+      // 清除avue-crud的选择状态
+      if (this.component.$refs && this.component.$refs.crud) {
+        this.component.$refs.crud.clearSelection();
+      }
+
+      // 触发重新渲染
+      this.component.$forceUpdate();
+
+    } catch (error) {
+      console.error('LifecycleManager: 重置组件状态失败', error);
+    }
+  }
+
+  /**
+   * 清理过期数据
+   */
+  cleanupExpiredData() {
+    try {
+      const cleanedCount = this.selectionManager.autoCleanup();
+      if (cleanedCount > 0) {
+        console.log(`LifecycleManager: 已清理 ${cleanedCount} 个过期选择`);
+      }
+    } catch (error) {
+      console.error('LifecycleManager: 清理过期数据失败', error);
+    }
+  }
+
+  /**
+   * 显示成功提示
+   * @param {number} count 导出数量
+   */
+  showSuccessMessage(count) {
+    if (this.component && this.component.$message) {
+      this.component.$message.success(`成功导出 ${count} 个订单,已清空选择状态`);
+    }
+  }
+
+  /**
+   * 防抖操作
+   * @param {string} key 操作键
+   * @param {Function} action 操作函数
+   * @param {number} delay 延迟时间(毫秒)
+   */
+  debounceAction(key, action, delay = 100) {
+    // 清除之前的定时器
+    if (this.debounceTimers.has(key)) {
+      clearTimeout(this.debounceTimers.get(key));
+    }
+
+    // 设置新的定时器
+    const timer = setTimeout(() => {
+      try {
+        action();
+      } catch (error) {
+        console.error(`LifecycleManager: 防抖操作 ${key} 执行失败`, error);
+      } finally {
+        this.debounceTimers.delete(key);
+      }
+    }, delay);
+
+    this.debounceTimers.set(key, timer);
+  }
+
+  /**
+   * 清理所有防抖定时器
+   */
+  clearAllDebounceTimers() {
+    this.debounceTimers.forEach((timer, key) => {
+      clearTimeout(timer);
+    });
+    this.debounceTimers.clear();
+  }
+
+  /**
+   * 获取当前状态
+   */
+  getCurrentState() {
+    return {
+      currentState: this.currentState,
+      lastPageNumber: this.lastPageNumber,
+      selectionCount: this.selectionManager.getSelectionCount(),
+      activeTimers: this.debounceTimers.size
+    };
+  }
+
+  /**
+   * 健康检查
+   */
+  healthCheck() {
+    const issues = [];
+
+    // 检查选择管理器
+    if (!this.selectionManager) {
+      issues.push('缺少选择管理器引用');
+    }
+
+    // 检查组件引用
+    if (!this.component) {
+      issues.push('缺少组件引用');
+    }
+
+    // 检查状态
+    if (!['idle', 'page-changing', 'loading', 'exporting'].includes(this.currentState)) {
+      issues.push(`无效的当前状态: ${this.currentState}`);
+    }
+
+    // 检查定时器数量
+    if (this.debounceTimers.size > 5) {
+      issues.push(`活跃定时器过多: ${this.debounceTimers.size}`);
+    }
+
+    return {
+      isHealthy: issues.length === 0,
+      issues: issues,
+      state: this.getCurrentState()
+    };
+  }
+}
+
+// 导出类
+export default LifecycleManager;

+ 285 - 0
src/utils/selection-manager.js

@@ -0,0 +1,285 @@
+/**
+ * 选择管理器
+ * @fileoverview 处理跨页选择状态管理的核心类
+ */
+
+/**
+ * 选择管理器类
+ * 负责管理跨页选择状态,支持添加、移除、查询选择操作
+ */
+class SelectionManager {
+  constructor() {
+    // 核心数据存储
+    this.selections = new Map(); // orderId -> {orderData, meta}
+    this.currentPageSelections = new Set(); // 当前页选择ID集合
+    this.lastUpdateTime = null;
+
+    // 配置参数
+    this.MAX_SELECTIONS = 100; // 最大选择数量
+    this.MAX_AGE = 24 * 60 * 60 * 1000; // 24小时过期时间
+  }
+
+  /**
+   * 添加选择
+   * @param {Object} order 订单对象
+   */
+  addSelection(order) {
+    if (!order || !order.id) {
+      console.warn('SelectionManager: 无效的订单数据');
+      return false;
+    }
+
+    // 检查选择数量限制
+    if (this.selections.size >= this.MAX_SELECTIONS && !this.selections.has(order.id)) {
+      console.warn(`SelectionManager: 选择数量已达上限 ${this.MAX_SELECTIONS}`);
+      return false;
+    }
+
+    // 存储选择数据
+    this.selections.set(order.id, {
+      id: order.id,
+      orderCode: order.orderCode || '',
+      orgName: order.orgName || '',
+      customerName: order.customerName || '',
+      orderType: order.orderType,
+      status: order.status,
+      totalAmount: order.totalAmount,
+      totalQuantity: order.totalQuantity,
+      receiverName: order.receiverName || '',
+      receiverPhone: order.receiverPhone || '',
+      createTime: order.createTime || '',
+      meta: {
+        selectedPage: 1, // 将由LifecycleManager设置
+        selectedTime: Date.now()
+      }
+    });
+
+    this.lastUpdateTime = Date.now();
+    return true;
+  }
+
+  /**
+   * 移除选择
+   * @param {string|number} orderId 订单ID
+   */
+  removeSelection(orderId) {
+    const removed = this.selections.delete(orderId);
+    if (removed) {
+      this.currentPageSelections.delete(orderId);
+      this.lastUpdateTime = Date.now();
+    }
+    return removed;
+  }
+
+  /**
+   * 切换选择状态
+   * @param {Object} order 订单对象
+   */
+  toggleSelection(order) {
+    if (this.isOrderSelected(order.id)) {
+      return this.removeSelection(order.id);
+    } else {
+      return this.addSelection(order);
+    }
+  }
+
+  /**
+   * 检查订单是否被选中
+   * @param {string|number} orderId 订单ID
+   */
+  isOrderSelected(orderId) {
+    return this.selections.has(orderId);
+  }
+
+  /**
+   * 获取选中数量
+   */
+  getSelectionCount() {
+    return this.selections.size;
+  }
+
+  /**
+   * 获取所有选中的订单
+   * @returns {Array} 选中订单数组
+   */
+  getAllSelections() {
+    return Array.from(this.selections.values());
+  }
+
+  /**
+   * 获取选中订单的ID列表
+   * @returns {Array} 订单ID数组
+   */
+  getSelectionIds() {
+    return Array.from(this.selections.keys());
+  }
+
+  /**
+   * 清空所有选择
+   */
+  clearAllSelections() {
+    const count = this.selections.size;
+    this.selections.clear();
+    this.currentPageSelections.clear();
+    this.lastUpdateTime = Date.now();
+    return count;
+  }
+
+  /**
+   * 与当前页选择合并
+   * @param {Array} currentPageList 当前页选中的订单列表
+   */
+  mergeWithCurrentPage(currentPageList) {
+    if (!Array.isArray(currentPageList)) {
+      console.warn('SelectionManager: 当前页选择列表必须是数组');
+      return;
+    }
+
+    // 清除当前页选择标记
+    this.currentPageSelections.clear();
+
+    // 添加当前页选择
+    currentPageList.forEach(order => {
+      if (order && order.id) {
+        this.addSelection(order);
+        this.currentPageSelections.add(order.id);
+      }
+    });
+
+    this.lastUpdateTime = Date.now();
+  }
+
+  /**
+   * 恢复页面选择状态
+   * @param {Array} pageData 页面数据
+   * @returns {Array} 需要恢复选择的订单ID列表
+   */
+  restorePageSelection(pageData) {
+    if (!Array.isArray(pageData)) {
+      return [];
+    }
+
+    // 清除当前页选择标记
+    this.currentPageSelections.clear();
+
+    // 找出当前页面中已被选中的订单
+    const selectedInPage = pageData
+      .filter(order => order && this.selections.has(order.id))
+      .map(order => order.id);
+
+    // 标记当前页选择
+    selectedInPage.forEach(orderId => {
+      this.currentPageSelections.add(orderId);
+    });
+
+    return selectedInPage;
+  }
+
+  /**
+   * 更新选择元数据
+   * @param {string|number} orderId 订单ID
+   * @param {Object} metaUpdate 元数据更新
+   */
+  updateSelectionMeta(orderId, metaUpdate) {
+    const selection = this.selections.get(orderId);
+    if (selection) {
+      selection.meta = {
+        ...selection.meta,
+        ...metaUpdate,
+        updateTime: Date.now()
+      };
+      this.lastUpdateTime = Date.now();
+    }
+  }
+
+  /**
+   * 批量移除选择
+   * @param {Array} orderIds 订单ID数组
+   */
+  batchRemoveSelections(orderIds) {
+    if (!Array.isArray(orderIds)) {
+      return 0;
+    }
+
+    let removedCount = 0;
+    orderIds.forEach(orderId => {
+      if (this.removeSelection(orderId)) {
+        removedCount++;
+      }
+    });
+
+    return removedCount;
+  }
+
+  /**
+   * 自动清理过期数据
+   */
+  autoCleanup() {
+    const now = Date.now();
+    const expiredOrderIds = [];
+
+    for (const [orderId, data] of this.selections) {
+      if (now - data.meta.selectedTime > this.MAX_AGE) {
+        expiredOrderIds.push(orderId);
+      }
+    }
+
+    this.batchRemoveSelections(expiredOrderIds);
+    return expiredOrderIds.length;
+  }
+
+  /**
+   * 获取选择统计信息
+   */
+  getSelectionStats() {
+    const now = Date.now();
+    const selections = Array.from(this.selections.values());
+
+    return {
+      totalCount: selections.length,
+      currentPageCount: this.currentPageSelections.size,
+      lastUpdateTime: this.lastUpdateTime,
+      oldestSelection: selections.length > 0
+        ? Math.min(...selections.map(s => s.meta.selectedTime))
+        : null,
+      averageAge: selections.length > 0
+        ? selections.reduce((sum, s) => sum + (now - s.meta.selectedTime), 0) / selections.length
+        : 0
+    };
+  }
+
+  /**
+   * 验证选择数据完整性
+   */
+  validateSelections() {
+    const issues = [];
+    const selections = Array.from(this.selections.values());
+
+    selections.forEach((selection, index) => {
+      // 检查必要字段
+      if (!selection.id) {
+        issues.push(`选择 ${index}: 缺少订单ID`);
+      }
+      if (!selection.orderCode) {
+        issues.push(`选择 ${index}: 缺少订单编码`);
+      }
+
+      // 检查时间戳
+      if (!selection.meta || !selection.meta.selectedTime) {
+        issues.push(`选择 ${index}: 缺少选择时间`);
+      }
+    });
+
+    return {
+      isValid: issues.length === 0,
+      issues: issues,
+      totalChecked: selections.length
+    };
+  }
+}
+
+// 导出单例实例
+export const selectionManager = new SelectionManager();
+
+// 导出类
+export default SelectionManager;

+ 143 - 10
src/views/order/factory/index.vue

@@ -18,8 +18,21 @@
     >
       <!-- 工具栏左侧按钮 -->
       <template slot="menuLeft">
+        <!-- 选择状态显示 -->
+        <div v-if="selectionCount > 0" class="selection-info">
+          <span class="selection-text">已选择 {{ selectionCount }} 个订单</span>
+          <el-button
+            size="mini"
+            type="text"
+            icon="el-icon-close"
+            @click="handleClearSelection"
+            class="clear-button"
+          >
+            清空
+          </el-button>
+        </div>
         <ExportButton
-          :selected-count="selectedCount"
+          :selected-count="selectionCount"
           :loading="isExporting"
           @export="handleExport"
         />
@@ -94,6 +107,8 @@ import { getList as getOrderItemList } from '@/api/order/order-item'
 import ExportButton from '@/components/export/ExportButton.vue'
 import ExportProgressDialog from '@/components/export/ExportProgressDialog.vue'
 import { getExportService } from '@/api/export-service'
+import { selectionManager } from '@/utils/selection-manager'
+import LifecycleManager from '@/utils/lifecycle-manager'
 
 export default {
   name: 'FactoryOrderList',
@@ -140,7 +155,14 @@ export default {
         total: 0,
         remainingTime: ''
       },
-      exportService: null
+      exportService: null,
+
+      // 跨页选择相关状态
+      selectionCount: 0,           // 总选择数量
+      showClearButton: false,       // 是否显示清空按钮
+
+      // 管理器实例
+      lifecycleManager: null
     }
   },
   computed: {
@@ -148,14 +170,23 @@ export default {
     permissionList() {
       return { addBtn: false, viewBtn: false, editBtn: false, delBtn: false }
     },
-    // 选中的订单数量(简化为只使用本地选择
+    // 选中的订单数量(保持向后兼容
     selectedCount() {
-      return this.selectionList.length;
+      return this.selectionCount;
     }
   },
   created() {
     // 初始化导出服务(无需store依赖)
     this.exportService = getExportService();
+
+    // 初始化生命周期管理器
+    this.lifecycleManager = new LifecycleManager(selectionManager, this);
+  },
+  beforeDestroy() {
+    // 组件销毁时清理资源
+    if (this.lifecycleManager) {
+      this.lifecycleManager.onComponentDestroy();
+    }
   },
   methods: {
     // 常量/标签方法透传,供插槽使用
@@ -165,6 +196,40 @@ export default {
     getOrderStatusTagType,
     safeBigInt,
 
+    // ========== 跨页选择功能相关方法 ==========
+
+    /**
+     * 更新选择UI状态
+     */
+    updateSelectionUI() {
+      this.selectionCount = selectionManager.getSelectionCount();
+      this.showClearButton = this.selectionCount > 0;
+      this.$forceUpdate();
+    },
+
+    /**
+     * 清空所有选择
+     */
+    handleClearSelection() {
+      this.$confirm('确认清空所有已选择的订单?', '提示', {
+        confirmButtonText: '确定',
+        cancelButtonText: '取消',
+        type: 'warning'
+      }).then(() => {
+        const clearedCount = selectionManager.clearAllSelections();
+        this.updateSelectionUI();
+
+        // 清除avue-crud的选择状态
+        if (this.$refs.crud) {
+          this.$refs.crud.clearSelection();
+        }
+
+        this.$message.success(`已清空 ${clearedCount} 个选择`);
+      }).catch(() => {
+        // 用户取消操作
+      });
+    },
+
     /**
      * 加载表格数据(主列表)
      * 使用工厂订单接口:api/order/order.js#getList
@@ -224,6 +289,11 @@ export default {
           this.data = records.map((row, idx) => ({ ...row, detailCount: counts[idx] }))
           this.page.total = total
           this.loading = false
+
+          // 恢复选择状态
+          if (this.lifecycleManager) {
+            this.lifecycleManager.onPageDataLoaded(this.data);
+          }
         })
         .catch(() => { this.loading = false })
     },
@@ -248,11 +318,24 @@ export default {
     /** @param {FactoryOrderRecord[]} list */
     selectionChange(list) {
       console.log('Selection changed:', list.length, 'items selected');
+
+      // 保持原有逻辑(向后兼容)
       this.selectionList = list;
+
+      // 委托给选择管理器处理
+      if (selectionManager && this.lifecycleManager) {
+        selectionManager.mergeWithCurrentPage(list);
+        this.updateSelectionUI();
+      }
     },
     /** 页码变化:保持搜索条件不丢失并重新加载 */
     /** @param {number} currentPage */
     currentChange(currentPage) {
+      // 页面变化前保存选择状态
+      if (this.lifecycleManager) {
+        this.lifecycleManager.onPageChange(currentPage);
+      }
+
       this.page.currentPage = currentPage
       this.onLoad(this.page, this.lastQuery)
     },
@@ -279,11 +362,21 @@ export default {
         return;
       }
 
-      // 使用本地选择的订单
-      const selectedOrders = this.selectionList;
-      if (!selectedOrders || selectedOrders.length === 0) {
-        this.$message.warning('请先选择要导出的订单');
-        return;
+      // 导出前处理
+      let selectedOrders = [];
+      if (this.lifecycleManager) {
+        selectedOrders = this.lifecycleManager.beforeExport();
+        if (!selectedOrders) {
+          this.$message.warning('请先选择要导出的订单');
+          return;
+        }
+      } else {
+        // 降级处理:使用本地选择
+        selectedOrders = this.selectionList;
+        if (!selectedOrders || selectedOrders.length === 0) {
+          this.$message.warning('请先选择要导出的订单');
+          return;
+        }
       }
 
       console.log('开始导出', selectedOrders.length, '个订单');
@@ -297,12 +390,22 @@ export default {
           this.exportProgress = progress;
         });
 
-        // 执行导出(直接传入选中的订单)
+        // 执行导出(使用跨页选择的订单)
         await this.exportService.executeExport({ type }, selectedOrders);
 
+        // 导出后处理
+        if (this.lifecycleManager) {
+          this.lifecycleManager.afterExport(true);
+        }
+
       } catch (error) {
         console.error('导出失败:', error);
         this.$message.error(error.message || '导出失败,请稍后重试');
+
+        // 导出失败处理
+        if (this.lifecycleManager) {
+          this.lifecycleManager.afterExport(false);
+        }
       } finally {
         this.isExporting = false;
       }
@@ -346,4 +449,34 @@ export default {
 .order-expand-content { padding: 8px 12px; }
 .expand-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
 .order-code { color: #666; font-size: 12px; }
+
+/* 跨页选择状态样式 */
+.selection-info {
+  display: flex;
+  align-items: center;
+  padding: 8px 12px;
+  margin-right: 12px;
+  background-color: #f0f9ff;
+  border: 1px solid #bfdbfe;
+  border-radius: 4px;
+  font-size: 14px;
+}
+
+.selection-text {
+  color: #1e40af;
+  font-weight: 500;
+  margin-right: 8px;
+}
+
+.clear-button {
+  color: #dc2626 !important;
+  padding: 2px 6px !important;
+  margin-left: 8px;
+  font-size: 12px !important;
+}
+
+.clear-button:hover {
+  background-color: #fef2f2 !important;
+  color: #b91c1c !important;
+}
 </style>