diff --git a/src/components/BasicPacks/BasicInput.vue b/src/components/BasicPacks/BasicInput.vue index bc5933f..b763b23 100644 --- a/src/components/BasicPacks/BasicInput.vue +++ b/src/components/BasicPacks/BasicInput.vue @@ -25,9 +25,12 @@ :placeHolder="props.placeHolder" :size="props.size" :type="props.type === 'price'? 'tel':props.type" - :inputmode="props.inputmode" + :inputmode="props.onlyPersian ? 'text' : props.inputmode" :pattern="props.pattern" + :dir="props.onlyPersian ? 'rtl' : undefined" + :lang="props.onlyPersian ? 'fa' : undefined" class="" + @keypress="handleKeyPress" @input="handlerChange" @change="handlerChange" /> @@ -59,6 +62,7 @@ interface Prop { addonBgColor?: String addonTextColor?: String placeHolder?: String + onlyPersian?: boolean } //emits @@ -74,7 +78,8 @@ const localValue = computed({ }) const props = withDefaults(defineProps(), { - isPassword: false + isPassword: false, + onlyPersian: false }) const emits = defineEmits(['update:value', 'onchange']) @@ -83,6 +88,12 @@ function normalizeValue(value: unknown) { return value } + if (props.onlyPersian) { + return String(value) + .replace(/[a-zA-Z0-9]/g, '') + .replace(/[^\u0600-\u06FF\s\u200C]/g, '') + } + if (shouldNormalizeDecimalSeparators(props)) { const isPrice = String(props.type ?? '').trim().toLowerCase() === 'price' return normalizeDecimalInput(value as string | number, { @@ -93,6 +104,14 @@ function normalizeValue(value: unknown) { return persianToEnglishDigits(String(value)) } +function handleKeyPress(e: KeyboardEvent) { + if (props.onlyPersian) { + if (/[a-zA-Z0-9]/.test(e.key)) { + e.preventDefault() + } + } +} + const handlerChange = (e: Event | string) => { const target = typeof e === 'string' ? null : (e.target as HTMLInputElement | null) const raw = typeof e === 'string' ? e : target?.value diff --git a/src/utils/inputRules.ts b/src/utils/inputRules.ts index 8668188..d540fa3 100644 --- a/src/utils/inputRules.ts +++ b/src/utils/inputRules.ts @@ -133,10 +133,29 @@ export const persianValidation = computed(() => { } }) -export const isValidPersian = () => { +export const isValidPersian = (title?: string) => { return { - pattern: /^[\u0600-\u06FF\s]+$/, - message: 'فقط حروف فارسی مجاز است' + pattern: /^[\u0600-\u06FF\s\u200C]+$/, + message: title ? `${title} باید فقط با حروف فارسی وارد شود` : 'فقط حروف فارسی مجاز است' + } +}; + +export const persianNameValidation = (title = 'نام'): Rule => { + return { + validator: (_rule, value) => { + const text = String(value ?? '').trim() + if (!text) { + return Promise.resolve() + } + if (/[a-zA-Z]/.test(text)) { + return Promise.reject(`${title} باید فقط با حروف فارسی وارد شود`) + } + if (!/^[\u0600-\u06FF\s\u200C]+$/.test(text)) { + return Promise.reject(`${title} باید فقط شامل حروف فارسی باشد`) + } + return Promise.resolve() + }, + trigger: ['change', 'blur'], } }; diff --git a/src/utils/storeHours.ts b/src/utils/storeHours.ts index a9c6ee1..255e834 100644 --- a/src/utils/storeHours.ts +++ b/src/utils/storeHours.ts @@ -257,21 +257,17 @@ export function stripHtmlMessage(message: string): string { return replaceMazanehTerminology(message.replace(/<[^>]*>/g, '').trim()) } -export function getStoreClosedHint(customMessage?: unknown): string { +/** متن واحد بسته بودن فروشگاه — مستقیماً از تنظیمات ادمین (closed_message) یا پیش‌فرض */ +export function resolveStoreClosedNotice(customMessage?: unknown): string { const custom = typeof customMessage === 'string' ? customMessage.trim() : '' if (custom) { return stripHtmlMessage(custom) } - return '' + return STORE_CLOSED_TITLE } -export function getStoreClosedMessage(): string { - return '' -} - -/** برای toast/اعلان: پیام ادمین یا عنوان پیش‌فرض */ -export function resolveStoreClosedNotice(customMessage?: unknown): string { - return getStoreClosedHint(customMessage) || STORE_CLOSED_TITLE +export function getStoreClosedHint(customMessage?: unknown): string { + return resolveStoreClosedNotice(customMessage) } export function isMarketClosedForDisplay(): boolean { diff --git a/src/views/base/assets/composables/useAssetsBanner.ts b/src/views/base/assets/composables/useAssetsBanner.ts new file mode 100644 index 0000000..128e496 --- /dev/null +++ b/src/views/base/assets/composables/useAssetsBanner.ts @@ -0,0 +1,153 @@ +import { ref, computed } from 'vue' +import { useRouter } from 'vue-router' +import { getConstByKey } from '@/api/const' +import { normalizePublicFileUrl } from '@/utils/file' +import assetsCopperBanner from '@/assets/img/assets-copper-banner.webp' + +export interface AssetBannerItem { + icon?: string | null + show?: boolean + link?: string | null + typeClick?: 'link' | 'modal' | 'share' | null + modalText?: string | null + caption?: string | null +} + +const loaded = ref(false) +const rawBanners = ref([]) +const hasCustomConfig = ref(false) +const bannerLoading = ref(false) + +export function useAssetsBanner() { + const router = useRouter() + const showModal = ref(false) + const modalContent = ref('') + + async function loadBanner(force = false) { + if (!force && loaded.value) return + bannerLoading.value = true + try { + // 1. Try 'assets_banner' key first + const res = await getConstByKey('assets_banner') + let list: unknown[] = [] + + if (res) { + hasCustomConfig.value = true + if (typeof res === 'string') { + try { + list = JSON.parse(res) + } catch { + list = [] + } + } else if (typeof res === 'object' && !Array.isArray(res) && 'value' in res) { + const val = (res as { value?: unknown }).value + if (typeof val === 'string') { + try { + list = JSON.parse(val) + } catch { + list = [] + } + } else if (Array.isArray(val)) { + list = val + } + } else if (Array.isArray(res)) { + list = res + } + } else { + // Fallback: check 'app_banners' + const appBannersRes = await getConstByKey('app_banners') + if (appBannersRes) { + let parsed: unknown = appBannersRes + if (typeof appBannersRes === 'string') { + try { + parsed = JSON.parse(appBannersRes) + } catch { + parsed = null + } + } else if (typeof appBannersRes === 'object' && !Array.isArray(appBannersRes) && 'value' in appBannersRes) { + const val = (appBannersRes as { value?: unknown }).value + parsed = typeof val === 'string' ? JSON.parse(val) : val + } + if (parsed && typeof parsed === 'object' && Array.isArray((parsed as Record).assetsBanner)) { + list = (parsed as Record).assetsBanner as unknown[] + hasCustomConfig.value = true + } + } + } + + if (Array.isArray(list)) { + rawBanners.value = list.map((item) => { + if (!item || typeof item !== 'object') return item as AssetBannerItem + const obj = item as AssetBannerItem + return { + ...obj, + icon: obj.icon ? (normalizePublicFileUrl(obj.icon) ?? obj.icon) : null, + } + }) + } + loaded.value = true + } catch (e) { + console.error('Error loading assets banner:', e) + } finally { + bannerLoading.value = false + } + } + + const displayBanner = computed(() => { + // If admin has configured banners in DB + if (hasCustomConfig.value && rawBanners.value.length > 0) { + const active = rawBanners.value.find((b) => b.show !== false) + if (active) { + return active + } + // If admin configured banners but all are show: false, hide the banner completely + return null + } + + // Default copper banner if not configured yet by admin + return { + icon: assetsCopperBanner, + show: true, + link: 'buyProduct', + typeClick: 'link', + caption: 'مس، قدم بعدی سبد دارایی شما — خرید و فروش شمش مس، ساده و آنلاین', + } + }) + + function handleBannerClick(banner: AssetBannerItem | null) { + if (!banner) return + const type = banner.typeClick + if (type === 'modal') { + if (banner.modalText) { + modalContent.value = banner.modalText + showModal.value = true + } + return + } + + const targetLink = banner.link || (banner.typeClick === 'link' ? 'buyProduct' : null) + if (targetLink) { + if (targetLink.startsWith('http://') || targetLink.startsWith('https://')) { + window.open(targetLink, '_blank') + } else if (targetLink.startsWith('/')) { + router.push(targetLink) + } else { + try { + router.push({ name: targetLink }) + } catch { + router.push(targetLink) + } + } + } + } + + return { + bannerLoading, + displayBanner, + showModal, + modalContent, + loadBanner, + handleBannerClick, + } +} + diff --git a/src/views/base/assets/index.vue b/src/views/base/assets/index.vue index 433fbf6..75ac684 100644 --- a/src/views/base/assets/index.vue +++ b/src/views/base/assets/index.vue @@ -125,15 +125,24 @@ - + +
+ +

دارایی‌ها

@@ -163,6 +172,7 @@ diff --git a/src/views/base/home/composables/useHomeQuoteRows.ts b/src/views/base/home/composables/useHomeQuoteRows.ts index eefa58c..dc34e37 100644 --- a/src/views/base/home/composables/useHomeQuoteRows.ts +++ b/src/views/base/home/composables/useHomeQuoteRows.ts @@ -110,8 +110,8 @@ export function useHomeQuoteRows() { return [ { label: 'قیمت مس جهانی', value: text(copper), unit: copper > 0 ? 'دلار' : '' }, { label: 'قیمت دلار بازار آزاد', value: text(dollar), unit: dollar > 0 ? 'ریال' : '' }, - { label: 'قیمت تن', value: text(ton), unit: ton > 0 ? 'ریال' : '' }, - { label: 'قیمت کیلوگرم', value: text(kilo), unit: kilo > 0 ? 'ریال' : '' }, + { label: 'ارزش ذاتی هر تن', value: text(ton), unit: ton > 0 ? 'ریال' : '' }, + { label: 'ارزش ذاتی هر کیلوگرم', value: text(kilo), unit: kilo > 0 ? 'ریال' : '' }, ] }) diff --git a/src/views/base/home/composables/useLandingLiveChart.ts b/src/views/base/home/composables/useLandingLiveChart.ts index 36fc3e0..fcf2384 100644 --- a/src/views/base/home/composables/useLandingLiveChart.ts +++ b/src/views/base/home/composables/useLandingLiveChart.ts @@ -340,6 +340,46 @@ const dayChangeAmountLabel = computed(() => { return `${delta > 0 ? '+' : '−'}${abs} ریال` }) +function isPointRecordedToday(timeMs: number): boolean { + try { + const tehranFormatter = new Intl.DateTimeFormat('en-CA', { + timeZone: 'Asia/Tehran', + year: 'numeric', + month: '2-digit', + day: '2-digit', + }) + return tehranFormatter.format(new Date(timeMs)) === tehranFormatter.format(new Date()) + } catch { + return Date.now() - timeMs < 24 * 60 * 60 * 1000 + } +} + +const todayChartPoints = computed(() => { + const points = chartPoints.value + const todayOnly = points.filter((p) => isPointRecordedToday(p.timeMs)) + return todayOnly.length >= 2 ? todayOnly : points +}) + +const todayChartValues = computed(() => + todayChartPoints.value.map((p) => p.price).filter((p) => Number.isFinite(p) && p > 0), +) + +const dayRange = computed(() => { + const values = todayChartValues.value + const current = Number.isFinite(liveUnitPrice.value) && liveUnitPrice.value > 0 ? liveUnitPrice.value : 0 + const allValues = current > 0 ? [...values, current] : values + if (!allValues.length) { + return { high: current, low: current } + } + return { + high: Math.max(...allValues), + low: Math.min(...allValues), + } +}) + +const dayHighPrice = computed(() => dayRange.value.high) +const dayLowPrice = computed(() => dayRange.value.low) + function resolveHoverFromEvent( event: PointerEvent, chart: { samples: ChartPlotSample[]; hasData: boolean }, @@ -439,14 +479,24 @@ function setupLiveChartDraw() { observer.observe(liveChartPlotEl.value) } +watch( + selectedChartProduct, + (product) => { + if (product) { + const { setChartMetal } = usePriceChart() + setChartMetal(metalFromProductTitle(product.title)) + } + }, + { immediate: true }, +) + function setLiveProduct(productId: number) { - if (!chartProductTabs.value.some((product) => product.id === productId)) return + const targetProduct = chartProductTabs.value.find((product) => product.id === productId) + if (!targetProduct) return activeProductId.value = productId liveChartHover.value = null - const product = selectedChartProduct.value - if (!product) return const { setChartMetal } = usePriceChart() - setChartMetal(metalFromProductTitle(product.title)) + setChartMetal(metalFromProductTitle(targetProduct.title)) } async function setLiveChartRange(range: LandingHistoryRange) { @@ -536,6 +586,9 @@ export function useLandingLiveChart() { liveChartPlotEl, liveSectionChart, formattedLivePrice, + liveUnitPrice, + dayHighPrice, + dayLowPrice, liveProductLabel, liveChartRangeLabel, liveMarketState, diff --git a/src/views/base/home/composables/usePriceChart.ts b/src/views/base/home/composables/usePriceChart.ts index e1b2590..11ccb62 100644 --- a/src/views/base/home/composables/usePriceChart.ts +++ b/src/views/base/home/composables/usePriceChart.ts @@ -57,8 +57,28 @@ export function resolveMetalDayRangePrices(options: { metal: ChartMetalType metalRatio: number }) { - const baseHigh = options.price?.up?.buy ?? getTradeBuyPrice(options.price as Parameters[0]) - const baseLow = options.price?.up?.sell ?? getTradeSellPrice(options.price as Parameters[0]) + let baseHigh = options.price?.up?.buy ?? getTradeBuyPrice(options.price as Parameters[0]) + let baseLow = options.price?.up?.sell ?? getTradeSellPrice(options.price as Parameters[0]) + const tradePrice = getTradeBuyPrice(options.price as Parameters[0]) + + // اگر سقف و کف بر اساس تن (بیش از ۱۰۰ میلیون ریال) آمده باشند، به مقیاس کیلوگرم تبدیل کن + if (baseHigh > 100_000_000) { + baseHigh = Math.round(baseHigh / 1000) + } + if (baseLow > 100_000_000) { + baseLow = Math.round(baseLow / 1000) + } + + // اگر مقادیر نامعتبر باشند یا به دلیل مغایرت منبع فاصله غیرمنطقی داشته باشند + if (tradePrice > 0) { + if (baseHigh <= 0 || (baseHigh / tradePrice > 2.5) || (tradePrice / baseHigh > 2.5)) { + baseHigh = tradePrice + } + if (baseLow <= 0 || (baseLow / tradePrice > 2.5) || (tradePrice / baseLow > 2.5)) { + baseLow = tradePrice + } + } + const ratio = options.metalRatio || CHART_METAL_MARKUP_RATIO[options.metal] return { diff --git a/src/views/base/home/desktop/components/DesktopLivePrice.vue b/src/views/base/home/desktop/components/DesktopLivePrice.vue index 845bf8f..69846fb 100644 --- a/src/views/base/home/desktop/components/DesktopLivePrice.vue +++ b/src/views/base/home/desktop/components/DesktopLivePrice.vue @@ -26,8 +26,7 @@ color="#ffffff" />
-

{{ statusTitle }}

-

{{ statusHint }}

+

{{ statusText }}

@@ -52,10 +51,9 @@ import { useUserStore } from '@/store/userStore' import { useHomeQuoteRows } from '@/views/base/home/composables/useHomeQuoteRows' import { NO_QUOTE_MESSAGE, - STORE_CLOSED_TITLE, getPriceDisplayState, - getStoreClosedHint, isHomeQuotePending, + resolveStoreClosedNotice, } from '@/utils/storeHours' const userStore = useUserStore() @@ -63,15 +61,11 @@ const userStore = useUserStore() const displayState = computed(() => getPriceDisplayState()) const quotePending = computed(() => isHomeQuotePending()) -const statusTitle = computed(() => - displayState.value === 'closed' ? STORE_CLOSED_TITLE : NO_QUOTE_MESSAGE -) - -const statusHint = computed(() => { +const statusText = computed(() => { if (displayState.value === 'closed') { - return getStoreClosedHint(userStore.getValueByKey('closed_message')) + return resolveStoreClosedNotice(userStore.getValueByKey('closed_message')) } - return 'در حال حاضر قیمتی برای نمایش وجود ندارد.' + return NO_QUOTE_MESSAGE }) const { quoteRows } = useHomeQuoteRows() diff --git a/src/views/base/home/desktop/components/DesktopPriceRange.vue b/src/views/base/home/desktop/components/DesktopPriceRange.vue index a5cc68a..e04be36 100644 --- a/src/views/base/home/desktop/components/DesktopPriceRange.vue +++ b/src/views/base/home/desktop/components/DesktopPriceRange.vue @@ -3,10 +3,12 @@ import { computed } from 'vue' import { price } from '@/utils/price' import { usePriceWithoutType } from '@/utils/usePrice' import { resolveMetalDayRangePrices, usePriceChart } from '../../composables/usePriceChart' +import { useLandingLiveChart } from '../../composables/useLandingLiveChart' const { selectedChartMetal, selectedMetalChartRatio } = usePriceChart() +const { dayHighPrice, dayLowPrice } = useLandingLiveChart() -const rangePrices = computed(() => +const fallbackRange = computed(() => resolveMetalDayRangePrices({ price: price.value, metal: selectedChartMetal.value, @@ -14,8 +16,19 @@ const rangePrices = computed(() => }) ) -const highPrice = computed(() => rangePrices.value.high) -const lowPrice = computed(() => rangePrices.value.low) +const highPrice = computed(() => { + if (dayHighPrice.value && dayHighPrice.value > 0) { + return dayHighPrice.value + } + return fallbackRange.value.high +}) + +const lowPrice = computed(() => { + if (dayLowPrice.value && dayLowPrice.value > 0) { + return dayLowPrice.value + } + return fallbackRange.value.low +})