chore: sync project updates
This commit is contained in:
@@ -282,21 +282,28 @@ export function notifyPriceLastFetchFailed() {
|
||||
void maybeShowNetworkAlert()
|
||||
}
|
||||
|
||||
function onTvBoard() {
|
||||
if (typeof window === 'undefined') return false
|
||||
const path = window.location.pathname.replace(/\/+$/, '') || '/'
|
||||
return path === '/tv' || path.endsWith('/tv') || path === '/monitor' || path.endsWith('/monitor')
|
||||
}
|
||||
|
||||
async function runFallbackPoll() {
|
||||
if (!priceWssEnabled.value || priceSocketConnected.value) {
|
||||
if (onTvBoard() || tvStreamKey || !priceWssEnabled.value || priceSocketConnected.value) {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const { getLastPrices, hasRecentPriceFromSource } = await import('@/utils/price')
|
||||
const { refreshProductsPageData } = await import(
|
||||
'@/views/base/products/composables/useProductsPageData'
|
||||
)
|
||||
const jobs: Promise<unknown>[] = [getLastPrices()]
|
||||
if (!tvStreamKey) {
|
||||
const { refreshProductsPageData } = await import(
|
||||
'@/views/base/products/composables/useProductsPageData'
|
||||
)
|
||||
jobs.push(refreshProductsPageData())
|
||||
}
|
||||
|
||||
const [priceResult] = await Promise.allSettled([
|
||||
getLastPrices(),
|
||||
refreshProductsPageData(),
|
||||
])
|
||||
const [priceResult] = await Promise.allSettled(jobs)
|
||||
|
||||
const priceOk =
|
||||
priceResult.status === 'fulfilled'
|
||||
@@ -743,6 +750,10 @@ function unbindBrowserNetworkListeners() {
|
||||
window.removeEventListener('offline', onBrowserOffline)
|
||||
}
|
||||
|
||||
export function isTvStreamActive() {
|
||||
return Boolean(tvStreamKey)
|
||||
}
|
||||
|
||||
export function startTvPriceStream(
|
||||
settingGetter: (key: string) => unknown,
|
||||
key: string,
|
||||
|
||||
@@ -182,14 +182,24 @@ function applyProductsList(products: Product[]) {
|
||||
productsPageLoading.value = false
|
||||
}
|
||||
|
||||
function onTvBoard() {
|
||||
if (typeof window === 'undefined') return false
|
||||
const path = window.location.pathname.replace(/\/+$/, '') || '/'
|
||||
return path === '/tv' || path.endsWith('/tv') || path === '/monitor' || path.endsWith('/monitor')
|
||||
}
|
||||
|
||||
/** قیمت enrich شده فقط در HTTP کامل است؛ slim SSE برای پرچمهاست */
|
||||
function scheduleCatalogRefreshFromStream() {
|
||||
if (onTvBoard()) return
|
||||
if (catalogStreamRefreshTimer) {
|
||||
clearTimeout(catalogStreamRefreshTimer)
|
||||
}
|
||||
catalogStreamRefreshTimer = setTimeout(() => {
|
||||
catalogStreamRefreshTimer = undefined
|
||||
void refreshProductsPageData()
|
||||
void import('@/utils/priceSocket').then(({ isTvStreamActive }) => {
|
||||
if (isTvStreamActive()) return
|
||||
void refreshProductsPageData()
|
||||
})
|
||||
}, 150)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import { computed, onMounted, onUnmounted, ref } from 'vue'
|
||||
import { computed, onMounted, onUnmounted, ref, watch } from 'vue'
|
||||
import { useFullscreen } from '@vueuse/core'
|
||||
import type { Product } from '@/models/products'
|
||||
import { getTvProducts, getTvServerTime } from '@/api/products'
|
||||
import { getConfigApp } from '@/utils/config'
|
||||
import { useSettingsStore } from '@/store/settingsStore'
|
||||
import { getProductBuyPrice, getProductSellPrice, getTvProductBuyPrice, getTvProductSellPrice } from '@/utils/productPrice'
|
||||
import { getLastPrices, lastPrice, startLastPricePolling, stopLastPricePolling } from '@/utils/price'
|
||||
import { getTvProductBuyPrice, getTvProductSellPrice } from '@/utils/productPrice'
|
||||
import { usePriceWithoutType } from '@/utils/usePrice'
|
||||
import { getStoreClosedMessage, isStoreClosedBySchedule, NO_QUOTE_MESSAGE } from '@/utils/storeHours'
|
||||
import { isMeltedTradeGroup, isMetalCommodityGroup } from '@/utils/productCategories'
|
||||
@@ -227,8 +226,7 @@ export function useTvMonitorPage() {
|
||||
|
||||
const mainTvProduct = computed(() => {
|
||||
void settingsStore.settingsRevision
|
||||
const raw = String(settingsStore.getSettingByKey('main_product') ?? '').trim()
|
||||
if (!raw) return null
|
||||
const raw = String(settingsStore.getSettingByKey('main_product') ?? '').trim() || '13'
|
||||
const match = catalogProducts.value.find(
|
||||
(product) => String(product.id) === raw || String(product.reading_method ?? '') === raw,
|
||||
)
|
||||
@@ -239,16 +237,8 @@ export function useTvMonitorPage() {
|
||||
|
||||
const showMainQuote = computed(() => !!mainTvProduct.value)
|
||||
|
||||
const liveBuy = computed(() => {
|
||||
void lastPrice.value
|
||||
const product = mainTvProduct.value
|
||||
return product ? getProductBuyPrice(product) : 0
|
||||
})
|
||||
const liveSell = computed(() => {
|
||||
void lastPrice.value
|
||||
const product = mainTvProduct.value
|
||||
return product ? getProductSellPrice(product) : 0
|
||||
})
|
||||
const liveBuy = computed(() => Number(mainTvProduct.value?.tv_price ?? 0) || 0)
|
||||
const liveSell = computed(() => Number(mainTvProduct.value?.tv_sell_price ?? 0) || 0)
|
||||
|
||||
const mainQuoteReady = computed(() => liveBuy.value > 0 || liveSell.value > 0)
|
||||
|
||||
@@ -374,6 +364,19 @@ export function useTvMonitorPage() {
|
||||
return label === '—' ? NO_QUOTE_MESSAGE : label
|
||||
}
|
||||
|
||||
function streamIsUp() {
|
||||
return priceSocketConnected.value || priceStreamLifecycle.value === 'open'
|
||||
}
|
||||
|
||||
function pollTvProducts() {
|
||||
if (streamIsUp()) return
|
||||
void loadProducts()
|
||||
}
|
||||
|
||||
watch(priceSocketConnected, (up) => {
|
||||
if (!up) pollTvProducts()
|
||||
})
|
||||
|
||||
onMounted(async () => {
|
||||
document.documentElement.classList.add(TV_HTML_CLASS)
|
||||
await syncServerClock()
|
||||
@@ -384,12 +387,10 @@ export function useTvMonitorPage() {
|
||||
document.addEventListener('visibilitychange', onVisibilityChange)
|
||||
await requestWakeLock()
|
||||
|
||||
startLastPricePolling()
|
||||
void getLastPrices()
|
||||
void loadProducts()
|
||||
listTimer = setInterval(() => {
|
||||
void loadProducts()
|
||||
void syncServerClock()
|
||||
pollTvProducts()
|
||||
}, REFRESH_MS)
|
||||
|
||||
document.title = `${brandName.value} | تابلو قیمت`
|
||||
@@ -404,7 +405,6 @@ export function useTvMonitorPage() {
|
||||
window.removeEventListener('mousemove', hideCursorSoon)
|
||||
document.removeEventListener('visibilitychange', onVisibilityChange)
|
||||
void releaseWakeLock()
|
||||
stopLastPricePolling()
|
||||
stopTvPriceStream()
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user