feat: dynamic assets banner price stats alignment intrinsic value labels and closed store text
This commit is contained in:
@@ -25,9 +25,12 @@
|
|||||||
:placeHolder="props.placeHolder"
|
:placeHolder="props.placeHolder"
|
||||||
:size="props.size"
|
:size="props.size"
|
||||||
:type="props.type === 'price'? 'tel':props.type"
|
:type="props.type === 'price'? 'tel':props.type"
|
||||||
:inputmode="props.inputmode"
|
:inputmode="props.onlyPersian ? 'text' : props.inputmode"
|
||||||
:pattern="props.pattern"
|
:pattern="props.pattern"
|
||||||
|
:dir="props.onlyPersian ? 'rtl' : undefined"
|
||||||
|
:lang="props.onlyPersian ? 'fa' : undefined"
|
||||||
class=""
|
class=""
|
||||||
|
@keypress="handleKeyPress"
|
||||||
@input="handlerChange"
|
@input="handlerChange"
|
||||||
@change="handlerChange"
|
@change="handlerChange"
|
||||||
/>
|
/>
|
||||||
@@ -59,6 +62,7 @@ interface Prop {
|
|||||||
addonBgColor?: String
|
addonBgColor?: String
|
||||||
addonTextColor?: String
|
addonTextColor?: String
|
||||||
placeHolder?: String
|
placeHolder?: String
|
||||||
|
onlyPersian?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
//emits
|
//emits
|
||||||
@@ -74,7 +78,8 @@ const localValue = computed({
|
|||||||
})
|
})
|
||||||
|
|
||||||
const props = withDefaults(defineProps<Prop>(), {
|
const props = withDefaults(defineProps<Prop>(), {
|
||||||
isPassword: false
|
isPassword: false,
|
||||||
|
onlyPersian: false
|
||||||
})
|
})
|
||||||
const emits = defineEmits(['update:value', 'onchange'])
|
const emits = defineEmits(['update:value', 'onchange'])
|
||||||
|
|
||||||
@@ -83,6 +88,12 @@ function normalizeValue(value: unknown) {
|
|||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (props.onlyPersian) {
|
||||||
|
return String(value)
|
||||||
|
.replace(/[a-zA-Z0-9]/g, '')
|
||||||
|
.replace(/[^\u0600-\u06FF\s\u200C]/g, '')
|
||||||
|
}
|
||||||
|
|
||||||
if (shouldNormalizeDecimalSeparators(props)) {
|
if (shouldNormalizeDecimalSeparators(props)) {
|
||||||
const isPrice = String(props.type ?? '').trim().toLowerCase() === 'price'
|
const isPrice = String(props.type ?? '').trim().toLowerCase() === 'price'
|
||||||
return normalizeDecimalInput(value as string | number, {
|
return normalizeDecimalInput(value as string | number, {
|
||||||
@@ -93,6 +104,14 @@ function normalizeValue(value: unknown) {
|
|||||||
return persianToEnglishDigits(String(value))
|
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 handlerChange = (e: Event | string) => {
|
||||||
const target = typeof e === 'string' ? null : (e.target as HTMLInputElement | null)
|
const target = typeof e === 'string' ? null : (e.target as HTMLInputElement | null)
|
||||||
const raw = typeof e === 'string' ? e : target?.value
|
const raw = typeof e === 'string' ? e : target?.value
|
||||||
|
|||||||
+22
-3
@@ -133,10 +133,29 @@ export const persianValidation = computed(() => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
export const isValidPersian = () => {
|
export const isValidPersian = (title?: string) => {
|
||||||
return {
|
return {
|
||||||
pattern: /^[\u0600-\u06FF\s]+$/,
|
pattern: /^[\u0600-\u06FF\s\u200C]+$/,
|
||||||
message: 'فقط حروف فارسی مجاز است'
|
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'],
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -257,21 +257,17 @@ export function stripHtmlMessage(message: string): string {
|
|||||||
return replaceMazanehTerminology(message.replace(/<[^>]*>/g, '').trim())
|
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() : ''
|
const custom = typeof customMessage === 'string' ? customMessage.trim() : ''
|
||||||
if (custom) {
|
if (custom) {
|
||||||
return stripHtmlMessage(custom)
|
return stripHtmlMessage(custom)
|
||||||
}
|
}
|
||||||
return ''
|
return STORE_CLOSED_TITLE
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getStoreClosedMessage(): string {
|
export function getStoreClosedHint(customMessage?: unknown): string {
|
||||||
return ''
|
return resolveStoreClosedNotice(customMessage)
|
||||||
}
|
|
||||||
|
|
||||||
/** برای toast/اعلان: پیام ادمین یا عنوان پیشفرض */
|
|
||||||
export function resolveStoreClosedNotice(customMessage?: unknown): string {
|
|
||||||
return getStoreClosedHint(customMessage) || STORE_CLOSED_TITLE
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isMarketClosedForDisplay(): boolean {
|
export function isMarketClosedForDisplay(): boolean {
|
||||||
|
|||||||
@@ -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<AssetBannerItem[]>([])
|
||||||
|
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<string, unknown>).assetsBanner)) {
|
||||||
|
list = (parsed as Record<string, unknown>).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<AssetBannerItem | null>(() => {
|
||||||
|
// 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,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -125,15 +125,24 @@
|
|||||||
</article>
|
</article>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<button type="button" class="assets-banner-slot" @click="go('buyProduct')">
|
<button
|
||||||
|
v-if="displayBanner"
|
||||||
|
type="button"
|
||||||
|
class="assets-banner-slot"
|
||||||
|
@click="handleBannerClick(displayBanner)"
|
||||||
|
>
|
||||||
<img
|
<img
|
||||||
:src="assetsCopperBanner"
|
:src="displayBanner.icon || assetsCopperBanner"
|
||||||
alt="مس، قدم بعدی سبد دارایی شما — خرید و فروش شمش مس، ساده و آنلاین"
|
:alt="displayBanner.caption || 'مس، قدم بعدی سبد دارایی شما — خرید و فروش شمش مس، ساده و آنلاین'"
|
||||||
loading="lazy"
|
loading="lazy"
|
||||||
decoding="async"
|
decoding="async"
|
||||||
/>
|
/>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
<BasicModal v-model:visible="showModal" :custom-footer="true" destroy-on-close>
|
||||||
|
<div class="max-h-[54vh] ql-editor p-4" v-html="modalContent" />
|
||||||
|
</BasicModal>
|
||||||
|
|
||||||
<section class="assets-card assets-table-wrap">
|
<section class="assets-card assets-table-wrap">
|
||||||
<div class="assets-table-wrap__head">
|
<div class="assets-table-wrap__head">
|
||||||
<h2>داراییها</h2>
|
<h2>داراییها</h2>
|
||||||
@@ -163,6 +172,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, onMounted } from 'vue'
|
import { computed, onMounted } from 'vue'
|
||||||
import router from '@/router'
|
import router from '@/router'
|
||||||
|
import BasicModal from '@/components/BasicPacks/BasicModal.vue'
|
||||||
import MobilePageHeader from '@/layouts/components/MobilePageHeader.vue'
|
import MobilePageHeader from '@/layouts/components/MobilePageHeader.vue'
|
||||||
import DesktopPageTopbar from '@/layouts/components/DesktopPageTopbar.vue'
|
import DesktopPageTopbar from '@/layouts/components/DesktopPageTopbar.vue'
|
||||||
import { useDesktopBreakpoint } from '@/layouts/composables/useResponsiveLayout'
|
import { useDesktopBreakpoint } from '@/layouts/composables/useResponsiveLayout'
|
||||||
@@ -181,6 +191,7 @@ import {
|
|||||||
import { formatWeightAmount } from '@/utils/usePrice'
|
import { formatWeightAmount } from '@/utils/usePrice'
|
||||||
import type { WalletMetalTotal } from '@/models/walletAssets'
|
import type { WalletMetalTotal } from '@/models/walletAssets'
|
||||||
import { useAssetsPortfolioChart } from './composables/useAssetsPortfolioChart'
|
import { useAssetsPortfolioChart } from './composables/useAssetsPortfolioChart'
|
||||||
|
import { useAssetsBanner } from './composables/useAssetsBanner'
|
||||||
import assetsCopperBanner from '@/assets/img/assets-copper-banner.webp'
|
import assetsCopperBanner from '@/assets/img/assets-copper-banner.webp'
|
||||||
import { getBoursecuActionIconSrc } from '@/utils/config'
|
import { getBoursecuActionIconSrc } from '@/utils/config'
|
||||||
|
|
||||||
@@ -334,7 +345,16 @@ function go(name: string, query?: Record<string, string>) {
|
|||||||
router.push(query ? { name, query } : { name })
|
router.push(query ? { name, query } : { name })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const {
|
||||||
|
displayBanner,
|
||||||
|
showModal,
|
||||||
|
modalContent,
|
||||||
|
loadBanner,
|
||||||
|
handleBannerClick,
|
||||||
|
} = useAssetsBanner()
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
|
void loadBanner()
|
||||||
await loadWalletAssets(true)
|
await loadWalletAssets(true)
|
||||||
await initAssetsPortfolioChart()
|
await initAssetsPortfolioChart()
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -23,8 +23,7 @@
|
|||||||
color="#ffffff"
|
color="#ffffff"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="status-box__title">{{ statusTitle }}</div>
|
<div class="status-box__title whitespace-pre-line text-center px-3">{{ statusText }}</div>
|
||||||
<div v-if="statusHint" class="status-box__hint">{{ statusHint }}</div>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -49,10 +48,9 @@ import { useUserStore } from '@/store/userStore'
|
|||||||
import { useHomeQuoteRows } from '@/views/base/home/composables/useHomeQuoteRows'
|
import { useHomeQuoteRows } from '@/views/base/home/composables/useHomeQuoteRows'
|
||||||
import {
|
import {
|
||||||
NO_QUOTE_MESSAGE,
|
NO_QUOTE_MESSAGE,
|
||||||
STORE_CLOSED_TITLE,
|
|
||||||
getPriceDisplayState,
|
getPriceDisplayState,
|
||||||
getStoreClosedHint,
|
|
||||||
isHomeQuotePending,
|
isHomeQuotePending,
|
||||||
|
resolveStoreClosedNotice,
|
||||||
} from '@/utils/storeHours'
|
} from '@/utils/storeHours'
|
||||||
|
|
||||||
const userStore = useUserStore()
|
const userStore = useUserStore()
|
||||||
@@ -60,15 +58,11 @@ const userStore = useUserStore()
|
|||||||
const displayState = computed(() => getPriceDisplayState())
|
const displayState = computed(() => getPriceDisplayState())
|
||||||
const quotePending = computed(() => isHomeQuotePending())
|
const quotePending = computed(() => isHomeQuotePending())
|
||||||
|
|
||||||
const statusTitle = computed(() =>
|
const statusText = computed(() => {
|
||||||
displayState.value === 'closed' ? STORE_CLOSED_TITLE : NO_QUOTE_MESSAGE
|
|
||||||
)
|
|
||||||
|
|
||||||
const statusHint = computed(() => {
|
|
||||||
if (displayState.value === 'closed') {
|
if (displayState.value === 'closed') {
|
||||||
return getStoreClosedHint(userStore.getValueByKey('closed_message'))
|
return resolveStoreClosedNotice(userStore.getValueByKey('closed_message'))
|
||||||
}
|
}
|
||||||
return 'در حال حاضر قیمتی برای نمایش وجود ندارد.'
|
return NO_QUOTE_MESSAGE
|
||||||
})
|
})
|
||||||
|
|
||||||
const containerClass = computed(() => {
|
const containerClass = computed(() => {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
>
|
>
|
||||||
<div class="text-center w-full">
|
<div class="text-center w-full">
|
||||||
<div>بالاترین قیمت امروز</div>
|
<div>بالاترین قیمت امروز</div>
|
||||||
<div v-if="price" class="flex flex-col items-center mt-3">
|
<div v-if="hasPrice" class="flex flex-col items-center mt-3">
|
||||||
<div class="text-green-600 flex gap-1 text-xs items-center">
|
<div class="text-green-600 flex gap-1 text-xs items-center">
|
||||||
<div class="text-base">{{ usePriceWithoutType(highPrice) }}</div>
|
<div class="text-base">{{ usePriceWithoutType(highPrice) }}</div>
|
||||||
ریال
|
ریال
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
<div class="text-center w-full">
|
<div class="text-center w-full">
|
||||||
<div>پایین ترین قیمت امروز</div>
|
<div>پایین ترین قیمت امروز</div>
|
||||||
<div class="flex w-full mt-3 justify-evenly">
|
<div class="flex w-full mt-3 justify-evenly">
|
||||||
<div v-if="price" class="flex flex-col items-center">
|
<div v-if="hasPrice" class="flex flex-col items-center">
|
||||||
<div class="text-red-600 flex gap-1 text-xs items-center">
|
<div class="text-red-600 flex gap-1 text-xs items-center">
|
||||||
<div class="text-base">{{ usePriceWithoutType(lowPrice) }}</div>
|
<div class="text-base">{{ usePriceWithoutType(lowPrice) }}</div>
|
||||||
ریال
|
ریال
|
||||||
@@ -35,6 +35,7 @@ import { computed } from 'vue'
|
|||||||
import { usePriceWithoutType } from '../../../../utils/usePrice'
|
import { usePriceWithoutType } from '../../../../utils/usePrice'
|
||||||
import { price } from '@/utils/price'
|
import { price } from '@/utils/price'
|
||||||
import { resolveMetalDayRangePrices, usePriceChart } from '../composables/usePriceChart'
|
import { resolveMetalDayRangePrices, usePriceChart } from '../composables/usePriceChart'
|
||||||
|
import { useLandingLiveChart } from '../composables/useLandingLiveChart'
|
||||||
|
|
||||||
withDefaults(
|
withDefaults(
|
||||||
defineProps<{
|
defineProps<{
|
||||||
@@ -46,8 +47,9 @@ withDefaults(
|
|||||||
)
|
)
|
||||||
|
|
||||||
const { selectedChartMetal, selectedMetalChartRatio } = usePriceChart()
|
const { selectedChartMetal, selectedMetalChartRatio } = usePriceChart()
|
||||||
|
const { dayHighPrice, dayLowPrice, liveUnitPrice } = useLandingLiveChart()
|
||||||
|
|
||||||
const rangePrices = computed(() =>
|
const fallbackRange = computed(() =>
|
||||||
resolveMetalDayRangePrices({
|
resolveMetalDayRangePrices({
|
||||||
price: price.value,
|
price: price.value,
|
||||||
metal: selectedChartMetal.value,
|
metal: selectedChartMetal.value,
|
||||||
@@ -55,6 +57,21 @@ const rangePrices = computed(() =>
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
const highPrice = computed(() => rangePrices.value.high)
|
const highPrice = computed(() => {
|
||||||
const lowPrice = computed(() => rangePrices.value.low)
|
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
|
||||||
|
})
|
||||||
|
|
||||||
|
const hasPrice = computed(() =>
|
||||||
|
Boolean((highPrice.value && highPrice.value > 0) || price.value || (liveUnitPrice.value && liveUnitPrice.value > 0))
|
||||||
|
)
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -110,8 +110,8 @@ export function useHomeQuoteRows() {
|
|||||||
return [
|
return [
|
||||||
{ label: 'قیمت مس جهانی', value: text(copper), unit: copper > 0 ? 'دلار' : '' },
|
{ label: 'قیمت مس جهانی', value: text(copper), unit: copper > 0 ? 'دلار' : '' },
|
||||||
{ label: 'قیمت دلار بازار آزاد', value: text(dollar), unit: dollar > 0 ? 'ریال' : '' },
|
{ label: 'قیمت دلار بازار آزاد', value: text(dollar), unit: dollar > 0 ? 'ریال' : '' },
|
||||||
{ label: 'قیمت تن', value: text(ton), unit: ton > 0 ? 'ریال' : '' },
|
{ label: 'ارزش ذاتی هر تن', value: text(ton), unit: ton > 0 ? 'ریال' : '' },
|
||||||
{ label: 'قیمت کیلوگرم', value: text(kilo), unit: kilo > 0 ? 'ریال' : '' },
|
{ label: 'ارزش ذاتی هر کیلوگرم', value: text(kilo), unit: kilo > 0 ? 'ریال' : '' },
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -340,6 +340,46 @@ const dayChangeAmountLabel = computed(() => {
|
|||||||
return `${delta > 0 ? '+' : '−'}${abs} ریال`
|
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(
|
function resolveHoverFromEvent(
|
||||||
event: PointerEvent,
|
event: PointerEvent,
|
||||||
chart: { samples: ChartPlotSample[]; hasData: boolean },
|
chart: { samples: ChartPlotSample[]; hasData: boolean },
|
||||||
@@ -439,14 +479,24 @@ function setupLiveChartDraw() {
|
|||||||
observer.observe(liveChartPlotEl.value)
|
observer.observe(liveChartPlotEl.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
function setLiveProduct(productId: number) {
|
watch(
|
||||||
if (!chartProductTabs.value.some((product) => product.id === productId)) return
|
selectedChartProduct,
|
||||||
activeProductId.value = productId
|
(product) => {
|
||||||
liveChartHover.value = null
|
if (product) {
|
||||||
const product = selectedChartProduct.value
|
|
||||||
if (!product) return
|
|
||||||
const { setChartMetal } = usePriceChart()
|
const { setChartMetal } = usePriceChart()
|
||||||
setChartMetal(metalFromProductTitle(product.title))
|
setChartMetal(metalFromProductTitle(product.title))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ immediate: true },
|
||||||
|
)
|
||||||
|
|
||||||
|
function setLiveProduct(productId: number) {
|
||||||
|
const targetProduct = chartProductTabs.value.find((product) => product.id === productId)
|
||||||
|
if (!targetProduct) return
|
||||||
|
activeProductId.value = productId
|
||||||
|
liveChartHover.value = null
|
||||||
|
const { setChartMetal } = usePriceChart()
|
||||||
|
setChartMetal(metalFromProductTitle(targetProduct.title))
|
||||||
}
|
}
|
||||||
|
|
||||||
async function setLiveChartRange(range: LandingHistoryRange) {
|
async function setLiveChartRange(range: LandingHistoryRange) {
|
||||||
@@ -536,6 +586,9 @@ export function useLandingLiveChart() {
|
|||||||
liveChartPlotEl,
|
liveChartPlotEl,
|
||||||
liveSectionChart,
|
liveSectionChart,
|
||||||
formattedLivePrice,
|
formattedLivePrice,
|
||||||
|
liveUnitPrice,
|
||||||
|
dayHighPrice,
|
||||||
|
dayLowPrice,
|
||||||
liveProductLabel,
|
liveProductLabel,
|
||||||
liveChartRangeLabel,
|
liveChartRangeLabel,
|
||||||
liveMarketState,
|
liveMarketState,
|
||||||
|
|||||||
@@ -57,8 +57,28 @@ export function resolveMetalDayRangePrices(options: {
|
|||||||
metal: ChartMetalType
|
metal: ChartMetalType
|
||||||
metalRatio: number
|
metalRatio: number
|
||||||
}) {
|
}) {
|
||||||
const baseHigh = options.price?.up?.buy ?? getTradeBuyPrice(options.price as Parameters<typeof getTradeBuyPrice>[0])
|
let baseHigh = options.price?.up?.buy ?? getTradeBuyPrice(options.price as Parameters<typeof getTradeBuyPrice>[0])
|
||||||
const baseLow = options.price?.up?.sell ?? getTradeSellPrice(options.price as Parameters<typeof getTradeSellPrice>[0])
|
let baseLow = options.price?.up?.sell ?? getTradeSellPrice(options.price as Parameters<typeof getTradeSellPrice>[0])
|
||||||
|
const tradePrice = getTradeBuyPrice(options.price as Parameters<typeof getTradeBuyPrice>[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]
|
const ratio = options.metalRatio || CHART_METAL_MARKUP_RATIO[options.metal]
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -26,8 +26,7 @@
|
|||||||
color="#ffffff"
|
color="#ffffff"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<p class="dhome-hero-price__closed-title">{{ statusTitle }}</p>
|
<p class="dhome-hero-price__closed-title whitespace-pre-line text-center px-3">{{ statusText }}</p>
|
||||||
<p v-if="statusHint" class="dhome-hero-price__closed-hint">{{ statusHint }}</p>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -52,10 +51,9 @@ import { useUserStore } from '@/store/userStore'
|
|||||||
import { useHomeQuoteRows } from '@/views/base/home/composables/useHomeQuoteRows'
|
import { useHomeQuoteRows } from '@/views/base/home/composables/useHomeQuoteRows'
|
||||||
import {
|
import {
|
||||||
NO_QUOTE_MESSAGE,
|
NO_QUOTE_MESSAGE,
|
||||||
STORE_CLOSED_TITLE,
|
|
||||||
getPriceDisplayState,
|
getPriceDisplayState,
|
||||||
getStoreClosedHint,
|
|
||||||
isHomeQuotePending,
|
isHomeQuotePending,
|
||||||
|
resolveStoreClosedNotice,
|
||||||
} from '@/utils/storeHours'
|
} from '@/utils/storeHours'
|
||||||
|
|
||||||
const userStore = useUserStore()
|
const userStore = useUserStore()
|
||||||
@@ -63,15 +61,11 @@ const userStore = useUserStore()
|
|||||||
const displayState = computed(() => getPriceDisplayState())
|
const displayState = computed(() => getPriceDisplayState())
|
||||||
const quotePending = computed(() => isHomeQuotePending())
|
const quotePending = computed(() => isHomeQuotePending())
|
||||||
|
|
||||||
const statusTitle = computed(() =>
|
const statusText = computed(() => {
|
||||||
displayState.value === 'closed' ? STORE_CLOSED_TITLE : NO_QUOTE_MESSAGE
|
|
||||||
)
|
|
||||||
|
|
||||||
const statusHint = computed(() => {
|
|
||||||
if (displayState.value === 'closed') {
|
if (displayState.value === 'closed') {
|
||||||
return getStoreClosedHint(userStore.getValueByKey('closed_message'))
|
return resolveStoreClosedNotice(userStore.getValueByKey('closed_message'))
|
||||||
}
|
}
|
||||||
return 'در حال حاضر قیمتی برای نمایش وجود ندارد.'
|
return NO_QUOTE_MESSAGE
|
||||||
})
|
})
|
||||||
|
|
||||||
const { quoteRows } = useHomeQuoteRows()
|
const { quoteRows } = useHomeQuoteRows()
|
||||||
|
|||||||
@@ -3,10 +3,12 @@ import { computed } from 'vue'
|
|||||||
import { price } from '@/utils/price'
|
import { price } from '@/utils/price'
|
||||||
import { usePriceWithoutType } from '@/utils/usePrice'
|
import { usePriceWithoutType } from '@/utils/usePrice'
|
||||||
import { resolveMetalDayRangePrices, usePriceChart } from '../../composables/usePriceChart'
|
import { resolveMetalDayRangePrices, usePriceChart } from '../../composables/usePriceChart'
|
||||||
|
import { useLandingLiveChart } from '../../composables/useLandingLiveChart'
|
||||||
|
|
||||||
const { selectedChartMetal, selectedMetalChartRatio } = usePriceChart()
|
const { selectedChartMetal, selectedMetalChartRatio } = usePriceChart()
|
||||||
|
const { dayHighPrice, dayLowPrice } = useLandingLiveChart()
|
||||||
|
|
||||||
const rangePrices = computed(() =>
|
const fallbackRange = computed(() =>
|
||||||
resolveMetalDayRangePrices({
|
resolveMetalDayRangePrices({
|
||||||
price: price.value,
|
price: price.value,
|
||||||
metal: selectedChartMetal.value,
|
metal: selectedChartMetal.value,
|
||||||
@@ -14,8 +16,19 @@ const rangePrices = computed(() =>
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
const highPrice = computed(() => rangePrices.value.high)
|
const highPrice = computed(() => {
|
||||||
const lowPrice = computed(() => rangePrices.value.low)
|
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
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ export function useProductsPageProvider() {
|
|||||||
const isAfterCloseTime = ref(false)
|
const isAfterCloseTime = ref(false)
|
||||||
const isProductInactive = ref(false)
|
const isProductInactive = ref(false)
|
||||||
const storeClosedMessage = computed(() =>
|
const storeClosedMessage = computed(() =>
|
||||||
getStoreClosedHint(userStore.getValueByKey('closed_message')),
|
resolveStoreClosedNotice(userStore.getValueByKey('closed_message')),
|
||||||
)
|
)
|
||||||
|
|
||||||
function openStoreClosedModal() {
|
function openStoreClosedModal() {
|
||||||
|
|||||||
@@ -10,8 +10,7 @@
|
|||||||
<!-- بنر بسته بودن فروشگاه -->
|
<!-- بنر بسته بودن فروشگاه -->
|
||||||
<div v-if="storeClosed" class="dproducts-closed-banner">
|
<div v-if="storeClosed" class="dproducts-closed-banner">
|
||||||
<span>🔒</span>
|
<span>🔒</span>
|
||||||
<span class="dproducts-closed-banner__title">{{ STORE_CLOSED_TITLE }}</span>
|
<span class="dproducts-closed-banner__title">{{ storeClosedMessage || STORE_CLOSED_TITLE }}</span>
|
||||||
<span v-if="storeClosedMessage" class="dproducts-closed-banner__hint">— {{ storeClosedMessage }}</span>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="dproducts-tabs">
|
<div class="dproducts-tabs">
|
||||||
|
|||||||
@@ -9,8 +9,7 @@
|
|||||||
<div v-if="storeClosed" class="mx-4 mt-4 closed-banner">
|
<div v-if="storeClosed" class="mx-4 mt-4 closed-banner">
|
||||||
<div class="closed-banner__icon">🔒</div>
|
<div class="closed-banner__icon">🔒</div>
|
||||||
<div class="closed-banner__body">
|
<div class="closed-banner__body">
|
||||||
<div class="closed-banner__title">{{ STORE_CLOSED_TITLE }}</div>
|
<div class="closed-banner__title">{{ storeClosedMessage || STORE_CLOSED_TITLE }}</div>
|
||||||
<div v-if="storeClosedMessage" class="closed-banner__hint">{{ storeClosedMessage }}</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -34,19 +34,19 @@
|
|||||||
@finish="registerAccount"
|
@finish="registerAccount"
|
||||||
>
|
>
|
||||||
<template v-if="variant === 'desktop'">
|
<template v-if="variant === 'desktop'">
|
||||||
<a-form-item :rules="[required()]" label="نام" name="fname">
|
<a-form-item :rules="[required('نام'), persianNameValidation('نام')]" label="نام" name="fname">
|
||||||
<BasicInput v-model:value="userFormState.fname" place-holder="نام" size="large" />
|
<BasicInput v-model:value="userFormState.fname" only-persian place-holder="نام" size="large" />
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
<a-form-item :rules="[required()]" label="نام خانوادگی" name="lname">
|
<a-form-item :rules="[required('نام خانوادگی'), persianNameValidation('نام خانوادگی')]" label="نام خانوادگی" name="lname">
|
||||||
<BasicInput v-model:value="userFormState.lname" place-holder="نام خانوادگی" size="large" />
|
<BasicInput v-model:value="userFormState.lname" only-persian place-holder="نام خانوادگی" size="large" />
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
</template>
|
</template>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<a-form-item :rules="[required()]" class="home_appear_fade_in_down" label="نام" name="fname">
|
<a-form-item :rules="[required('نام'), persianNameValidation('نام')]" class="home_appear_fade_in_down" label="نام" name="fname">
|
||||||
<BasicInput v-model:value="userFormState.fname" place-holder="نام" />
|
<BasicInput v-model:value="userFormState.fname" only-persian place-holder="نام" />
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
<a-form-item :rules="[required()]" class="home_appear_fade_in_down" label="نام خانوادگی" name="lname">
|
<a-form-item :rules="[required('نام خانوادگی'), persianNameValidation('نام خانوادگی')]" class="home_appear_fade_in_down" label="نام خانوادگی" name="lname">
|
||||||
<BasicInput v-model:value="userFormState.lname" place-holder="نام خانوادگی" />
|
<BasicInput v-model:value="userFormState.lname" only-persian place-holder="نام خانوادگی" />
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
</template>
|
</template>
|
||||||
<a-form-item
|
<a-form-item
|
||||||
@@ -218,7 +218,7 @@
|
|||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
|
|
||||||
import {mobileValidation, required} from '@/utils/inputRules'
|
import {mobileValidation, required, persianNameValidation} from '@/utils/inputRules'
|
||||||
import type { User } from '@/models/login'
|
import type { User } from '@/models/login'
|
||||||
import BasicInput from '@/components/BasicPacks/BasicInput.vue'
|
import BasicInput from '@/components/BasicPacks/BasicInput.vue'
|
||||||
import BasicButton from '@/components/BasicPacks/BasicButton.vue'
|
import BasicButton from '@/components/BasicPacks/BasicButton.vue'
|
||||||
@@ -284,6 +284,13 @@ function registerAccount() {
|
|||||||
// console.log('test')
|
// console.log('test')
|
||||||
formRef.value?.validateFields().then(async () => {
|
formRef.value?.validateFields().then(async () => {
|
||||||
try {
|
try {
|
||||||
|
const fname = String(userFormState.fname ?? '').trim()
|
||||||
|
const lname = String(userFormState.lname ?? '').trim()
|
||||||
|
if (/[a-zA-Z]/.test(fname) || /[a-zA-Z]/.test(lname)) {
|
||||||
|
message.error('نام و نام خانوادگی باید فقط به زبان فارسی باشد')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// console.log('test',stepTwoVerify.value)
|
// console.log('test',stepTwoVerify.value)
|
||||||
loading.value = true
|
loading.value = true
|
||||||
// if (!stepTwoVerify.value) {
|
// if (!stepTwoVerify.value) {
|
||||||
|
|||||||
@@ -32,6 +32,13 @@ export function useRegisterForm() {
|
|||||||
function registerAccount() {
|
function registerAccount() {
|
||||||
formRef.value?.validateFields().then(async () => {
|
formRef.value?.validateFields().then(async () => {
|
||||||
try {
|
try {
|
||||||
|
const fname = String(userFormState.fname ?? '').trim()
|
||||||
|
const lname = String(userFormState.lname ?? '').trim()
|
||||||
|
if (/[a-zA-Z]/.test(fname) || /[a-zA-Z]/.test(lname)) {
|
||||||
|
message.error('نام و نام خانوادگی باید فقط به زبان فارسی باشد')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
loading.value = true
|
loading.value = true
|
||||||
URLUserType() === 'single' ? (userFormState.type = 2) : (userFormState.type = 1)
|
URLUserType() === 'single' ? (userFormState.type = 2) : (userFormState.type = 1)
|
||||||
// فیلد مخفی + بدون لینک دعوت → کد را نفرست
|
// فیلد مخفی + بدون لینک دعوت → کد را نفرست
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed } from 'vue'
|
import { computed } from 'vue'
|
||||||
import { mobileValidation, required } from '@/utils/inputRules'
|
import { mobileValidation, required, persianNameValidation } from '@/utils/inputRules'
|
||||||
import BasicInput from '@/components/BasicPacks/BasicInput.vue'
|
import BasicInput from '@/components/BasicPacks/BasicInput.vue'
|
||||||
import BasicButton from '@/components/BasicPacks/BasicButton.vue'
|
import BasicButton from '@/components/BasicPacks/BasicButton.vue'
|
||||||
import DialogVantOneButton from '@/components/DialogVantOneButton.vue'
|
import DialogVantOneButton from '@/components/DialogVantOneButton.vue'
|
||||||
@@ -65,12 +65,13 @@ function handleSuccessDismiss() {
|
|||||||
name="desktop-register"
|
name="desktop-register"
|
||||||
@finish="registerAccount"
|
@finish="registerAccount"
|
||||||
>
|
>
|
||||||
<a-form-item :rules="[required()]" label="نام" name="fname">
|
<a-form-item :rules="[required('نام'), persianNameValidation('نام')]" label="نام" name="fname">
|
||||||
<BasicInput v-model:value="userFormState.fname" place-holder="نام" size="large" />
|
<BasicInput v-model:value="userFormState.fname" only-persian place-holder="نام" size="large" />
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
<a-form-item :rules="[required()]" label="نام خانوادگی" name="lname">
|
<a-form-item :rules="[required('نام خانوادگی'), persianNameValidation('نام خانوادگی')]" label="نام خانوادگی" name="lname">
|
||||||
<BasicInput
|
<BasicInput
|
||||||
v-model:value="userFormState.lname"
|
v-model:value="userFormState.lname"
|
||||||
|
only-persian
|
||||||
place-holder="نام خانوادگی"
|
place-holder="نام خانوادگی"
|
||||||
size="large"
|
size="large"
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user