tv changes
This commit is contained in:
@@ -3,12 +3,13 @@ import { useFullscreen } from '@vueuse/core'
|
||||
import type { Product } from '@/models/products'
|
||||
import { getTvProducts } from '@/api/products'
|
||||
import { getConfigApp } from '@/utils/config'
|
||||
import { useSettingsStore } from '@/store/settingsStore'
|
||||
import { getTvProductBuyPrice, getTvProductSellPrice, isTvProductPriceInactive } from '@/utils/productPrice'
|
||||
import { getLastPrices, getTradeBuyPrice, getTradeSellPrice, lastPrice, startLastPricePolling, stopLastPricePolling } from '@/utils/price'
|
||||
import { usePriceWithoutType } from '@/utils/usePrice'
|
||||
import { getPriceDisplayMessage, getPriceDisplayState, NO_QUOTE_MESSAGE } from '@/utils/storeHours'
|
||||
import { isMeltedTradeGroup, isMetalCommodityGroup } from '@/utils/productCategories'
|
||||
import { priceSocketConnected, priceStreamLifecycle } from '@/utils/priceSocketState'
|
||||
import { usePrice } from '@/utils/usePrice'
|
||||
import logoFallback from '@/assets/img/logo_full_.png'
|
||||
//@ts-ignore
|
||||
import moment from 'moment-jalaali'
|
||||
@@ -21,6 +22,37 @@ moment.loadPersian({ usePersianDigits: false })
|
||||
const CURSOR_HIDE_MS = 2500
|
||||
const TV_HTML_CLASS = 'app-layout--tv'
|
||||
const REFRESH_MS = 15000
|
||||
/** دقت تابلو: هزار تومان = ۱۰٬۰۰۰ ریال — باقیمانده به پایین حذف میشود */
|
||||
const TV_TOMAN_STEP = 1000
|
||||
|
||||
function parseTvNews(raw: unknown): string[] {
|
||||
const text = String(raw ?? '').trim()
|
||||
if (!text) return []
|
||||
|
||||
try {
|
||||
const decoded = JSON.parse(text)
|
||||
if (Array.isArray(decoded)) {
|
||||
return decoded.map((item) => String(item ?? '').trim()).filter(Boolean)
|
||||
}
|
||||
} catch {
|
||||
// هر خط یک خبر
|
||||
}
|
||||
|
||||
return text
|
||||
.split(/\r?\n/)
|
||||
.map((line) => line.replace(/^[-•*]\s+/, '').trim())
|
||||
.filter(Boolean)
|
||||
}
|
||||
|
||||
function floorTvToman(rial: number): number {
|
||||
if (!Number.isFinite(rial) || rial <= 0) return 0
|
||||
return Math.floor(rial / 10 / TV_TOMAN_STEP) * TV_TOMAN_STEP
|
||||
}
|
||||
|
||||
function formatTvPrice(rial: number): string {
|
||||
const toman = floorTvToman(rial)
|
||||
return toman > 0 ? usePriceWithoutType(toman) : '—'
|
||||
}
|
||||
|
||||
function productText(product: Product) {
|
||||
return `${product.group_type ?? ''} ${product.title ?? ''}`
|
||||
@@ -70,6 +102,7 @@ function isGoldBar(product: Product) {
|
||||
}
|
||||
|
||||
export function useTvMonitorPage() {
|
||||
const settingsStore = useSettingsStore()
|
||||
const rootEl = ref<HTMLElement | null>(null)
|
||||
const { isFullscreen, enter: enterFullscreen, exit: exitFullscreen } = useFullscreen(rootEl)
|
||||
|
||||
@@ -143,11 +176,23 @@ export function useTvMonitorPage() {
|
||||
extraTickerProducts.value.length ? 'سایر مظنهها' : '',
|
||||
)
|
||||
|
||||
const tvNewsItems = computed(() => {
|
||||
void settingsStore.settingsRevision
|
||||
const raw = settingsStore.getSettingByKey('tv_news') ?? getConfigApp('tv_news')
|
||||
if (raw == null) {
|
||||
return ['تا حالا از اپ کشکول طلای آنلاین خریدی؟']
|
||||
}
|
||||
return parseTvNews(raw)
|
||||
})
|
||||
|
||||
const newsTickerTitle = computed(() => (tvNewsItems.value.length ? 'اخبار' : ''))
|
||||
|
||||
const hasBoardContent = computed(
|
||||
() =>
|
||||
hasCoinBoard.value
|
||||
|| tickerProducts.value.length > 0
|
||||
|| extraTickerProducts.value.length > 0,
|
||||
|| extraTickerProducts.value.length > 0
|
||||
|| tvNewsItems.value.length > 0,
|
||||
)
|
||||
|
||||
const statusBanner = computed(() => {
|
||||
@@ -258,18 +303,16 @@ export function useTvMonitorPage() {
|
||||
|
||||
function productBuyLabel(product: Product) {
|
||||
if (isProductTvInactive(product)) return NO_QUOTE_MESSAGE
|
||||
const value = getTvProductBuyPrice(product)
|
||||
return value > 0 ? usePrice(value) : '—'
|
||||
return formatTvPrice(getTvProductBuyPrice(product))
|
||||
}
|
||||
|
||||
function productSellLabel(product: Product) {
|
||||
if (isProductTvInactive(product)) return NO_QUOTE_MESSAGE
|
||||
const value = getTvProductSellPrice(product)
|
||||
return value > 0 ? usePrice(value) : '—'
|
||||
return formatTvPrice(getTvProductSellPrice(product))
|
||||
}
|
||||
|
||||
function liveQuoteLabel(value: number) {
|
||||
return value > 0 ? usePrice(value) : '—'
|
||||
return formatTvPrice(value)
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
@@ -318,6 +361,8 @@ export function useTvMonitorPage() {
|
||||
tickerTitle,
|
||||
extraTickerProducts,
|
||||
extraTickerTitle,
|
||||
tvNewsItems,
|
||||
newsTickerTitle,
|
||||
statusBanner,
|
||||
liveBuy,
|
||||
liveSell,
|
||||
|
||||
Reference in New Issue
Block a user