fix: correct excel export formatting (timezone, spec, user, location) and add auto-polling for collaborative stocktake
This commit is contained in:
@ -349,7 +349,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted, nextTick } from 'vue'
|
||||
import { ref, computed, onMounted, onUnmounted, nextTick } from 'vue'
|
||||
import { getAllStock } from '@/api/inbound/stock'
|
||||
import QrScanner from '@/components/QrScanner/index.vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
@ -418,6 +418,51 @@ const currentItem = ref<StockItem | null>(null)
|
||||
const inputQty = ref<number | undefined>(undefined)
|
||||
const qtyInputRef = ref()
|
||||
|
||||
// ★ 新增: 多人协同心跳刷新定时器
|
||||
let syncTimer: any = null
|
||||
|
||||
// ★ 新增: 静默刷新数据(不弹loading)
|
||||
const syncData = async () => {
|
||||
try {
|
||||
// 仅刷新差异列表数据,不显示loading
|
||||
const res = await getAllStock()
|
||||
if (!res) return
|
||||
|
||||
const processItem = (item: any, type: string) => {
|
||||
const stock = parseFloat(item.stock_quantity || item.qty_stock || 0)
|
||||
if (stock <= 0) return
|
||||
const name = item.material_name || item.product_name || item.name || '未知物品'
|
||||
const uuid = item.uuid || item.sku || ''
|
||||
const isScanned = scannedMap.value.has(uuid)
|
||||
return {
|
||||
...item,
|
||||
name: name,
|
||||
standard: item.spec_model || item.standard || item.model || '',
|
||||
sku: item.sku || '',
|
||||
uuid: uuid,
|
||||
bar_code: item.bar_code || item.barcode || '',
|
||||
qty_stock: stock,
|
||||
qty_actual: isScanned ? scannedMap.value.get(uuid)! : 0,
|
||||
scanned: isScanned,
|
||||
uniqueKey: `${type}_${item.id}`,
|
||||
source_table: typeToSourceTable(type),
|
||||
stock_id: item.id
|
||||
}
|
||||
}
|
||||
|
||||
const list: StockItem[] = []
|
||||
if (res.materials) res.materials.forEach((i: any) => { const item = processItem(i, 'material'); if (item) list.push(item) })
|
||||
if (res.semis) res.semis.forEach((i: any) => { const item = processItem(i, 'semi'); if (item) list.push(item) })
|
||||
if (res.products) res.products.forEach((i: any) => { const item = processItem(i, 'product'); if (item) list.push(item) })
|
||||
|
||||
// 静默更新数据(不触发loading)
|
||||
allData.value = list
|
||||
await fetchBorrowedQuantities(list)
|
||||
} catch (e) {
|
||||
// 静默失败,不弹错误
|
||||
}
|
||||
}
|
||||
|
||||
const api = {
|
||||
getDrafts: (sessionId?: string) => request({
|
||||
url: '/v1/inbound/stock/draft/list',
|
||||
@ -498,6 +543,18 @@ async function fetchBorrowedQuantities(items: StockItem[]): Promise<void> {
|
||||
|
||||
onMounted(async () => {
|
||||
await checkServerDraft()
|
||||
// ★ 启动多人协同心跳轮询(每5秒静默刷新)
|
||||
syncTimer = setInterval(() => {
|
||||
syncData()
|
||||
}, 5000)
|
||||
})
|
||||
|
||||
// ★ 新增: 组件卸载时清除定时器
|
||||
onUnmounted(() => {
|
||||
if (syncTimer) {
|
||||
clearInterval(syncTimer)
|
||||
syncTimer = null
|
||||
}
|
||||
})
|
||||
|
||||
const checkServerDraft = async () => {
|
||||
|
||||
Reference in New Issue
Block a user