From a86fb9803a0c9014ebba4761d318d1783b87da3f Mon Sep 17 00:00:00 2001 From: SZCJW <792430652@qq.com> Date: Sun, 15 Mar 2026 22:13:51 +0800 Subject: [PATCH] x --- static/vue-app.js | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/static/vue-app.js b/static/vue-app.js index 42bec82..afdf169 100644 --- a/static/vue-app.js +++ b/static/vue-app.js @@ -1531,6 +1531,29 @@ const InventoryView = { } }; + const ensureStockBaseData = async () => { + if (!state.products.length) { + await loadProducts(); + } + if (!state.warehouses.length) { + await loadWarehouses(); + } + if (!state.warehouses.length) { + try { + await apiRequest('/api/warehouses', { + method: 'POST', + body: JSON.stringify({ + name: '默认仓库' + }) + }); + await loadWarehouses(); + addNotification('已自动创建默认仓库', 'success'); + } catch (e) { + handleApiError(e, '自动创建默认仓库'); + } + } + }; + const loadSuppliers = async () => { state.loading = true; try { @@ -1645,12 +1668,7 @@ const InventoryView = { } else { state.form = {}; if (type === 'stockIn' || type === 'stockOut') { - if (!state.products.length) { - await loadProducts(); - } - if (!state.warehouses.length) { - await loadWarehouses(); - } + await ensureStockBaseData(); state.form = { product_id: state.products[0]?.id || null, warehouse_id: state.warehouses.find(w => w.is_default)?.id || state.warehouses[0]?.id || null, @@ -2359,6 +2377,7 @@ const InventoryView = {