From 137f793ae0468f6b5b421c7cdd3eb663d6229894 Mon Sep 17 00:00:00 2001 From: adonis Date: Wed, 17 Jun 2026 17:39:41 +0330 Subject: [PATCH] fix bugs --- components.d.ts | 3 + src/app/bootstrap.ts | 6 ++ src/utils/config.ts | 102 ------------------ src/utils/referralShare.ts | 95 ++++++++++++++++ .../earnMoney/composables/useEarnMoneyPage.ts | 7 +- .../base/home/components/ReferralSection.vue | 4 +- src/views/base/home/components/ShareModal.vue | 4 +- .../base/home/composables/useHomePage.ts | 11 +- .../base/user/composables/useUserPage.ts | 17 ++- 9 files changed, 124 insertions(+), 125 deletions(-) create mode 100644 src/utils/referralShare.ts diff --git a/components.d.ts b/components.d.ts index 0e26d2b..751269f 100644 --- a/components.d.ts +++ b/components.d.ts @@ -20,8 +20,10 @@ declare module 'vue' { ARadioGroup: typeof import('ant-design-vue/es')['RadioGroup'] ASelect: typeof import('ant-design-vue/es')['Select'] ASelectOption: typeof import('ant-design-vue/es')['SelectOption'] + ASlider: typeof import('ant-design-vue/es')['Slider'] ASpin: typeof import('ant-design-vue/es')['Spin'] ASwitch: typeof import('ant-design-vue/es')['Switch'] + ATag: typeof import('ant-design-vue/es')['Tag'] ATextarea: typeof import('ant-design-vue/es')['Textarea'] ATooltip: typeof import('ant-design-vue/es')['Tooltip'] BaseDatePicker: typeof import('./src/components/BasicPacks/BaseDatePicker/src/BaseDatePicker.vue')['default'] @@ -68,5 +70,6 @@ declare module 'vue' { TransactionSkeleton: typeof import('./src/components/TransactionSkeleton.vue')['default'] VanActionSheet: typeof import('vant/es')['ActionSheet'] VanDialog: typeof import('vant/es')['Dialog'] + VanField: typeof import('vant/es')['Field'] } } diff --git a/src/app/bootstrap.ts b/src/app/bootstrap.ts index 90d4b89..00187e3 100644 --- a/src/app/bootstrap.ts +++ b/src/app/bootstrap.ts @@ -7,6 +7,7 @@ import { setupRouterGuards } from '@/app/setupRouter' import router from '@/router' import { applyProjectTheme } from '@/utils/config' import { useSettingsStore } from '@/store/settingsStore' +import { useUserStore } from '@/store/userStore' import { getToken } from '@/utils' type BootWindow = Window & { @@ -93,9 +94,14 @@ export async function bootstrapApp() { const { app } = createVueApp() const settingsStore = useSettingsStore() + const userStore = useUserStore() await withTimeout(settingsStore.fetchSettings(), 45000, 'Settings loading timeout') + if (getToken()) { + await withTimeout(userStore.getMyInfo(), 45000, 'User session loading timeout') + } + setupRouterGuards() app.mount('#app') diff --git a/src/utils/config.ts b/src/utils/config.ts index d371e54..7c1dadf 100644 --- a/src/utils/config.ts +++ b/src/utils/config.ts @@ -12,8 +12,6 @@ import bazretalaNavLogo from '@/assets/img/bazretala-nav-logo.png' import bazretalaFundBg from '@/assets/img/bazretala-fund-bg.png' import bazretalaEmptyFund from '@/assets/img/bazretala-empty-fund.png' -import { useSettingsStore } from '@/store/settingsStore' - export function getConfigApp(key: string) { const config = window.__APP_CONFIG__ ? window.__APP_CONFIG__.user:{} @@ -241,103 +239,3 @@ export function applyProjectTheme() { document.documentElement.style.setProperty('--App-brand-red-100', '#f0d8d8') document.documentElement.style.setProperty('--App-brand-red-700', '#963130') } - -export function getReferralShareTitle(projectName?: string | null) { - return projectName ?? getConfigApp('name_fa') ?? getConfigApp('name') ?? 'طلا' -} - -/** جایگزینی ٪نام / %نام و ٪لینک / %لینک در قالب متن دعوت */ -export function renderInviteLinkText( - template: string, - options: { userName?: string | null; link?: string | null }, -): string { - const userName = String(options.userName ?? '').trim() - const link = String(options.link ?? '').trim() - - return template - .replace(/[%٪]\s*لینک/gu, link) - .replace(/[%٪]\s*نام/gu, userName) -} - -function resolveReferralLoginLink(referralId?: string | number | null): string { - const id = String(referralId ?? '').trim() - if (!id) return '' - - let base = '' - try { - base = String(useSettingsStore().getSettingByKey('app_url') ?? '').trim() - } catch { - base = '' - } - - if (base) { - return `${base.replace(/\/+$/, '')}/login?id=${encodeURIComponent(id)}` - } - - if (typeof window !== 'undefined' && window.location?.origin) { - return `${window.location.origin}/login?id=${encodeURIComponent(id)}` - } - - return `/login?id=${encodeURIComponent(id)}` -} - -export function getReferralShareText(options: { - userName?: string | null - projectName?: string | null - referralId?: string | number | null -}) { - const userName = options.userName ?? '' - const referralId = options.referralId ?? '' - const link = resolveReferralLoginLink(referralId) - const marketText = options.projectName - ? `بازار طلای ${options.projectName}` - : 'بازار طلا' - - let template = '' - try { - template = String(useSettingsStore().getSettingByKey('invite_link_text') ?? '').trim() - } catch { - template = '' - } - - if (template) { - return renderInviteLinkText(template, { userName, link }) - } - - if (isBoursecuProject()) { - return `مس؛ فلز آینده جهان - -⭐️ امروز در آینده مس سرمایه‌گذاری کن؛ ثمره آن را در سال‌های پیش رو برداشت کن! - -رشد صنایع انرژی پاک، خودروهای برقی و زیرساخت‌های نوین، تقاضا برای مس را در سال‌های آینده افزایش خواهد داد. - -با سرمایه‌گذاری تدریجی و مستمر در بازار مس، از رشد بلندمدت یکی از مهم‌ترین فلزات استراتژیک جهان بهره‌مند شوید. - -این دعوت‌نامه از طرف «${userName}» برای شما ارسال شده است تا شما نیز از فرصت‌های سرمایه‌گذاری در بورس مس جا نمانید. - -برای مشاهده قیمت‌ها، تحلیل بازار و تکمیل ثبت‌نام، روی لینک زیر کلیک کنید - -${link}` - } - - if (isBazretalaProject()) { - return `️سلام به مناسبت افتتاحیه بذرطلا وایّام عیدغدیر ومباهله با ثبت نام آنلاین واَمن بدون کارمزد0/5% از بذرطلا با تائیدمُعرف خرید کنید و نذارین پول خُرداتون خاک بخوره (عضویت فقط ازطریق مُعرف امکان پذیرمیباشد) -بذرش کن بکار،پس اندازکن هروقت خواستی -طلا برداشت کن بدون مالیات -با پول های کوچک و بیکارت -ی پس انداز طلایی برای خودت و خونوادت درست کن ما در بذرطلا آنلاین کنارت هستیم - -این دعوت نامه از طرف "${userName}" عضوفعالِ اَپ بذرطلا برای شما ارسال شده تا شما هم از کاشت بذر طلای خودتون جا نمونید. -روی لینک زیر کلیک کنید و کاشت بذرطلای خودتونو با ثبت نام و خرید اول تکمیل کنید. - -${link}` - } - - return `⭐️الان طلا بخر؛ آخر ماه سودشو ببر! -با خرید طلای آبشده در مقدارهای کم ولی مستمر، سود بیشتری ببر! - -این دعوت نامه از طرف "${userName}" عزیز برای شما ارسال شده تا شما هم از ${marketText} جا نمونید. -روی لینک زیر کلیک کنید و ثبت نام خود را تکمیل کنید. - -${link}` -} diff --git a/src/utils/referralShare.ts b/src/utils/referralShare.ts new file mode 100644 index 0000000..4c8cfa2 --- /dev/null +++ b/src/utils/referralShare.ts @@ -0,0 +1,95 @@ +import { message } from 'ant-design-vue' +import { useSettingsStore } from '@/store/settingsStore' +import { getConfigApp } from '@/utils/config' + +export function getReferralShareTitle(projectName?: string | null) { + return projectName ?? getConfigApp('name_fa') ?? getConfigApp('name') ?? 'طلا' +} + +export const DEFAULT_INVITE_LINK_TEXT = `⭐️الان طلا بخر؛ آخر ماه سودشو ببر! +با خرید طلای آبشده در مقدارهای کم ولی مستمر، سود بیشتری ببر! + +این دعوت نامه از طرف "٪نام" عزیز برای شما ارسال شده تا شما هم از بازار طلای ما جا نمونید. +روی لینک زیر کلیک کنید و ثبت نام خود را تکمیل کنید. + +٪لینک` + +export function getInviteLinkTemplate(): string { + try { + const fromSettings = String(useSettingsStore().getSettingByKey('invite_link_text') ?? '').trim() + if (fromSettings) { + return fromSettings + } + } catch { + // settings store may not be ready yet + } + return DEFAULT_INVITE_LINK_TEXT +} + +/** جایگزینی ٪نام / %نام و ٪لینک / %لینک در قالب متن دعوت */ +export function renderInviteLinkText( + template: string, + options: { userName?: string | null; link?: string | null }, +): string { + const userName = String(options.userName ?? '').trim() + const link = String(options.link ?? '').trim() + + return template + .replace(/[%٪]\s*لینک/gu, link) + .replace(/[%٪]\s*نام/gu, userName) +} + +function resolveReferralLoginLink(referralId?: string | number | null): string { + const id = String(referralId ?? '').trim() + if (!id) return '' + + let base = '' + try { + base = String(useSettingsStore().getSettingByKey('app_url') ?? '').trim() + } catch { + base = '' + } + + if (base) { + return `${base.replace(/\/+$/, '')}/login?id=${encodeURIComponent(id)}` + } + + if (typeof window !== 'undefined' && window.location?.origin) { + return `${window.location.origin}/login?id=${encodeURIComponent(id)}` + } + + return `/login?id=${encodeURIComponent(id)}` +} + +export function getReferralShareText(options: { + userName?: string | null + projectName?: string | null + referralId?: string | number | null +}) { + const userName = options.userName ?? '' + const link = resolveReferralLoginLink(options.referralId) + return renderInviteLinkText(getInviteLinkTemplate(), { userName, link }) +} + +export async function shareReferralText(text: string, title?: string | null): Promise { + const shareTitle = title ?? getReferralShareTitle() + + if (typeof navigator !== 'undefined' && typeof navigator.share === 'function') { + try { + await navigator.share({ title: shareTitle, text }) + return + } catch (err) { + if ((err as Error)?.name === 'AbortError') { + return + } + } + } + + if (typeof navigator !== 'undefined' && navigator.clipboard?.writeText) { + await navigator.clipboard.writeText(text) + message.info('متن دعوتنامه رونوشت شد') + return + } + + message.error('اشتراک‌گذاری در این مرورگر پشتیبانی نمی‌شود') +} diff --git a/src/views/base/earnMoney/composables/useEarnMoneyPage.ts b/src/views/base/earnMoney/composables/useEarnMoneyPage.ts index 2e66a21..fd50266 100644 --- a/src/views/base/earnMoney/composables/useEarnMoneyPage.ts +++ b/src/views/base/earnMoney/composables/useEarnMoneyPage.ts @@ -4,7 +4,7 @@ import { getEarnMoney } from '@/api/earnMoney' import type { EarnMoney } from '@/models/earnMoney' import { useUserStore } from '@/store/userStore' import { useConfigStore } from '@/store/configStore' -import { getReferralShareText, getReferralShareTitle } from '@/utils/config' +import { getReferralShareText, getReferralShareTitle, shareReferralText } from '@/utils/referralShare' import { loading } from '@/utils' export interface EarnMoneyPageContext { @@ -44,10 +44,7 @@ export function useEarnMoneyPage() { projectName: nameProject, referralId: userStore.userInfo?.referral_id, }) - navigator.share({ - title: getReferralShareTitle(nameProject), - text: val, - }) + void shareReferralText(val, getReferralShareTitle(nameProject)) } async function loadEarnMoney() { diff --git a/src/views/base/home/components/ReferralSection.vue b/src/views/base/home/components/ReferralSection.vue index 7f4b328..028b5dc 100644 --- a/src/views/base/home/components/ReferralSection.vue +++ b/src/views/base/home/components/ReferralSection.vue @@ -35,7 +35,7 @@ import { useUserStore } from '@/store/userStore' import BasicButton from '@/components/BasicPacks/BasicButton.vue' import { message } from 'ant-design-vue' -import { getReferralShareText, getReferralShareTitle } from '@/utils/config' +import { getReferralShareText, getReferralShareTitle, shareReferralText } from '@/utils/referralShare' const userStore = useUserStore() @@ -45,7 +45,7 @@ const shareCode = () => { referralId: userStore.userInfo?.referral_id, }) - navigator.share({ title: getReferralShareTitle(), text }) + void shareReferralText(text, getReferralShareTitle()) } const copyCode = () => { diff --git a/src/views/base/home/components/ShareModal.vue b/src/views/base/home/components/ShareModal.vue index c1fd5a7..7f1a898 100644 --- a/src/views/base/home/components/ShareModal.vue +++ b/src/views/base/home/components/ShareModal.vue @@ -40,7 +40,7 @@ import BasicModal from '@/components/BasicPacks/BasicModal.vue' import BasicButton from '@/components/BasicPacks/BasicButton.vue' import { message } from 'ant-design-vue' import { useUserStore } from '@/store/userStore' -import { getReferralShareText, getReferralShareTitle } from '@/utils/config' +import { getReferralShareText, getReferralShareTitle, shareReferralText } from '@/utils/referralShare' const props = withDefaults( defineProps<{ @@ -69,7 +69,7 @@ const shareCode = () => { referralId: props.referralId, }) - navigator.share({ title: getReferralShareTitle(), text }) + void shareReferralText(text, getReferralShareTitle()) } const copyCode = () => { diff --git a/src/views/base/home/composables/useHomePage.ts b/src/views/base/home/composables/useHomePage.ts index dac5e02..1a645d3 100644 --- a/src/views/base/home/composables/useHomePage.ts +++ b/src/views/base/home/composables/useHomePage.ts @@ -15,7 +15,7 @@ import { useConfigStore } from '@/store/configStore' import { getTradeBuyPrice, lastPrice, stopLastPricePolling } from '@/utils/price' import { getStoreClosedMessage, isStoreClosed } from '@/utils/storeHours' import { message, Modal } from 'ant-design-vue' -import { getReferralShareText, getReferralShareTitle } from '@/utils/config' +import { getReferralShareText, getReferralShareTitle, shareReferralText } from '@/utils/referralShare' import { useBanners } from './useBanners' import { usePriceChart, type ChartMetalType } from './usePriceChart' import type { HomeActionItem } from '../layouts/types' @@ -122,14 +122,7 @@ export function useHomePage() { referralId: userStore.userInfo?.referral_id, }) - try { - await navigator.share({ - title: getReferralShareTitle(configStore.config.name), - text, - }) - } catch { - copyCode() - } + await shareReferralText(text, getReferralShareTitle(configStore.config.name)) } function copyCode() { diff --git a/src/views/base/user/composables/useUserPage.ts b/src/views/base/user/composables/useUserPage.ts index 401bfbe..36df022 100644 --- a/src/views/base/user/composables/useUserPage.ts +++ b/src/views/base/user/composables/useUserPage.ts @@ -14,7 +14,8 @@ import { updateMe, updatePass } from '@/api/me' import { useUserStore } from '@/store/userStore' import { getUserAvatarUrl } from '@/utils/file' import { useConfigStore } from '@/store/configStore' -import { getConfigApp, getReferralShareText, getReferralShareTitle, isBoursecuProject, getBoursecuActionIconSrc } from '@/utils/config' +import { getConfigApp, isBoursecuProject, getBoursecuActionIconSrc } from '@/utils/config' +import { getReferralShareText, getReferralShareTitle, shareReferralText } from '@/utils/referralShare' export interface UserMenuAction { id: string @@ -199,10 +200,7 @@ export function useUserPage() { projectName: nameProject, referralId: userStore.userInfo?.referral_id, }) - navigator.share({ - title: getReferralShareTitle(nameProject), - text: val, - }) + void shareReferralText(val, getReferralShareTitle(nameProject)) } function ok() { @@ -246,6 +244,15 @@ export function useUserPage() { } }) + watch( + () => userStore.userInfo, + (info) => { + if (!info) return + setForm() + }, + { immediate: true }, + ) + const context: UserPageContext = { userStore, userFormState,