fix some things
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { computed, onMounted, onUnmounted, ref } from 'vue'
|
||||
import { useFullscreen } from '@vueuse/core'
|
||||
import type { Product } from '@/models/products'
|
||||
import { getTvProducts } from '@/api/products'
|
||||
import { getTvProducts, getTvServerTime } from '@/api/products'
|
||||
import { getConfigApp } from '@/utils/config'
|
||||
import { useSettingsStore } from '@/store/settingsStore'
|
||||
import { getTvProductBuyPrice, getTvProductSellPrice, isTvProductPriceInactive } from '@/utils/productPrice'
|
||||
@@ -73,7 +73,10 @@ function isBankCoin(product: Product) {
|
||||
const title = (product.title ?? '').trim()
|
||||
if (group === 'سکه' || group === 'سکه بانکی') return true
|
||||
if (group.includes('سکه') && !group.includes('پارسیان')) return true
|
||||
return title.includes('بانکی')
|
||||
if (title.includes('بانکی')) return true
|
||||
// API سبک TV ممکن است group_type نداشته باشد
|
||||
if (title.includes('سکه') && !title.includes('پارسیان')) return true
|
||||
return false
|
||||
}
|
||||
|
||||
function bankCoinRank(product: Product) {
|
||||
@@ -116,6 +119,8 @@ export function useTvMonitorPage() {
|
||||
let clockTimer: ReturnType<typeof setInterval> | undefined
|
||||
let cursorTimer: ReturnType<typeof setTimeout> | undefined
|
||||
let listTimer: ReturnType<typeof setInterval> | undefined
|
||||
/** اختلاف میلیثانیهٔ ساعت سرور (Asia/Tehran) با Date.now محلی */
|
||||
let serverOffsetMs = 0
|
||||
|
||||
const brandName = computed(
|
||||
() => String(getConfigApp('name_fa') || getConfigApp('name') || 'تابلو قیمت'),
|
||||
@@ -130,6 +135,23 @@ export function useTvMonitorPage() {
|
||||
return marked.length ? marked : list
|
||||
})
|
||||
|
||||
function normalizeTvProduct(raw: Product): Product {
|
||||
const image = (raw as Product & { image?: string | null }).image
|
||||
if (image && !raw.img) {
|
||||
return { ...raw, img: image }
|
||||
}
|
||||
return raw
|
||||
}
|
||||
|
||||
async function syncServerClock() {
|
||||
const t0 = Date.now()
|
||||
const payload = await getTvServerTime()
|
||||
const t1 = Date.now()
|
||||
if (!payload?.unix) return
|
||||
const rttHalf = (t1 - t0) / 2
|
||||
serverOffsetMs = payload.unix * 1000 + rttHalf - t1
|
||||
}
|
||||
|
||||
const parsianCoins = computed(() =>
|
||||
catalogProducts.value
|
||||
.filter(isParsianCoin)
|
||||
@@ -207,7 +229,7 @@ export function useTvMonitorPage() {
|
||||
async function loadProducts() {
|
||||
try {
|
||||
const list = await getTvProducts()
|
||||
products.value = Array.isArray(list) ? list : []
|
||||
products.value = (Array.isArray(list) ? list : []).map(normalizeTvProduct)
|
||||
} catch {
|
||||
if (!products.value.length) {
|
||||
products.value = []
|
||||
@@ -218,7 +240,7 @@ export function useTvMonitorPage() {
|
||||
}
|
||||
|
||||
function updateClock() {
|
||||
const now = moment()
|
||||
const now = moment(Date.now() + serverOffsetMs).utcOffset(210)
|
||||
nowLabel.value = now.format('HH:mm:ss')
|
||||
dateLabel.value = now.format('dddd jD jMMMM jYYYY')
|
||||
}
|
||||
@@ -313,6 +335,7 @@ export function useTvMonitorPage() {
|
||||
|
||||
onMounted(async () => {
|
||||
document.documentElement.classList.add(TV_HTML_CLASS)
|
||||
await syncServerClock()
|
||||
updateClock()
|
||||
hideCursorSoon()
|
||||
clockTimer = setInterval(updateClock, 1000)
|
||||
@@ -325,6 +348,7 @@ export function useTvMonitorPage() {
|
||||
void loadProducts()
|
||||
listTimer = setInterval(() => {
|
||||
void loadProducts()
|
||||
void syncServerClock()
|
||||
}, REFRESH_MS)
|
||||
|
||||
document.title = `${brandName.value} | تابلو قیمت`
|
||||
|
||||
Reference in New Issue
Block a user