Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
12382656e8 |
@@ -16,12 +16,16 @@ declare module 'vue' {
|
||||
AInput: typeof import('ant-design-vue/es')['Input']
|
||||
AInputPassword: typeof import('ant-design-vue/es')['InputPassword']
|
||||
AModal: typeof import('ant-design-vue/es')['Modal']
|
||||
ARadio: typeof import('ant-design-vue/es')['Radio']
|
||||
ARadioButton: typeof import('ant-design-vue/es')['RadioButton']
|
||||
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']
|
||||
Basic: typeof import('./src/components/BasicPacks/BaseDatePicker/src/datePick/demo/basic.vue')['default']
|
||||
@@ -49,13 +53,10 @@ declare module 'vue' {
|
||||
ExtraFooter: typeof import('./src/components/BasicPacks/BaseDatePicker/src/datePick/demo/extra-footer.vue')['default']
|
||||
Format: typeof import('./src/components/BasicPacks/BaseDatePicker/src/datePick/demo/format.vue')['default']
|
||||
GoldLoading: typeof import('./src/components/GoldLoading.vue')['default']
|
||||
InstallButton: typeof import('./src/components/InstallButton.vue')['default']
|
||||
ListAnim: typeof import('./src/components/ListAnim.vue')['default']
|
||||
Mode: typeof import('./src/components/BasicPacks/BaseDatePicker/src/datePick/demo/mode.vue')['default']
|
||||
PresettedRanges: typeof import('./src/components/BasicPacks/BaseDatePicker/src/datePick/demo/presetted-ranges.vue')['default']
|
||||
ProductImage: typeof import('./src/components/ProductImage.vue')['default']
|
||||
PwaInstallGuideModal: typeof import('./src/components/pwa/PwaInstallGuideModal.vue')['default']
|
||||
PwaInstallStepIllustration: typeof import('./src/components/pwa/PwaInstallStepIllustration.vue')['default']
|
||||
RangePicker: typeof import('./src/components/BasicPacks/BaseDatePicker/src/datePick/demo/range-picker.vue')['default']
|
||||
RouterLink: typeof import('vue-router')['RouterLink']
|
||||
RouterView: typeof import('vue-router')['RouterView']
|
||||
@@ -63,15 +64,12 @@ declare module 'vue' {
|
||||
Size: typeof import('./src/components/BasicPacks/BaseDatePicker/src/datePick/demo/size.vue')['default']
|
||||
StartEnd: typeof import('./src/components/BasicPacks/BaseDatePicker/src/datePick/demo/start-end.vue')['default']
|
||||
Suffix: typeof import('./src/components/BasicPacks/BaseDatePicker/src/datePick/demo/suffix.vue')['default']
|
||||
SupportContactBar: typeof import('./src/components/SupportContactBar.vue')['default']
|
||||
SupportMessengerBrandIcon: typeof import('./src/components/SupportMessengerBrandIcon.vue')['default']
|
||||
SupportMessengerPicker: typeof import('./src/components/SupportMessengerPicker.vue')['default']
|
||||
Switchable: typeof import('./src/components/BasicPacks/BaseDatePicker/src/datePick/demo/switchable.vue')['default']
|
||||
Text: typeof import('./src/components/BasicPacks/BaseDatePicker/src/datePick/demo/text.vue')['default']
|
||||
Time: typeof import('./src/components/BasicPacks/BaseDatePicker/src/datePick/demo/time.vue')['default']
|
||||
TradeFeeConfirmSummary: typeof import('./src/components/TradeFeeConfirmSummary.vue')['default']
|
||||
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']
|
||||
}
|
||||
}
|
||||
|
||||
@@ -325,63 +325,28 @@
|
||||
return window.location.protocol === 'https:' ? 'https:' : 'http:'
|
||||
}
|
||||
|
||||
function resolveTenantDomain() {
|
||||
var host = String(window.location.hostname || '').trim()
|
||||
if (!host || host === 'localhost' || host === '127.0.0.1') {
|
||||
return 'k.montzar.ir'
|
||||
}
|
||||
return host
|
||||
}
|
||||
function getVersionUrls() {
|
||||
var protocol = getProtocol()
|
||||
|
||||
function getSuperAdminBases() {
|
||||
return [
|
||||
'https://adm.montzar.ir',
|
||||
'https://adm.montech.ir',
|
||||
'https://adm.montest.ir'
|
||||
'https://nerkh.gold/get_version',
|
||||
'https://tablo.talasevin.ir/get_version',
|
||||
'https://abshode-service.montgit.ir/server/get_version',
|
||||
protocol + '//212.23.201.173:8381/get_version',
|
||||
protocol + '//91.212.174.137:4040/server/get_version'
|
||||
]
|
||||
}
|
||||
|
||||
function isDevHost() {
|
||||
var host = String(window.location.hostname || '').trim()
|
||||
return host === 'localhost' || host === '127.0.0.1'
|
||||
}
|
||||
|
||||
function getVersionUrls() {
|
||||
var domain = encodeURIComponent(resolveTenantDomain())
|
||||
var urls = getSuperAdminBases().map(function (base) {
|
||||
return base + '/get_version?domain=' + domain
|
||||
})
|
||||
|
||||
if (isDevHost()) {
|
||||
var protocol = getProtocol()
|
||||
urls = urls.concat([
|
||||
'https://tablo.talasevin.ir/get_version',
|
||||
'https://abshode-service.montgit.ir/server/get_version',
|
||||
protocol + '//212.23.201.173:8381/get_version',
|
||||
protocol + '//91.212.174.137:4040/server/get_version'
|
||||
])
|
||||
}
|
||||
|
||||
return urls
|
||||
}
|
||||
|
||||
function getConfigUrls() {
|
||||
var domain = encodeURIComponent(resolveTenantDomain())
|
||||
var urls = getSuperAdminBases().map(function (base) {
|
||||
return base + '/get_user?domain=' + domain
|
||||
})
|
||||
var protocol = getProtocol()
|
||||
|
||||
if (isDevHost()) {
|
||||
var protocol = getProtocol()
|
||||
urls = urls.concat([
|
||||
protocol + '//tablo.talasevin.ir/get_user',
|
||||
protocol + '//abshode-service.montgit.ir/server/get_user',
|
||||
protocol + '//212.23.201.173:8381/get_user',
|
||||
protocol + '//91.212.174.137:4040/server/get_user'
|
||||
])
|
||||
}
|
||||
|
||||
return urls
|
||||
return [
|
||||
protocol + '//nerkh.gold/get_user',
|
||||
protocol + '//tablo.talasevin.ir/get_user',
|
||||
protocol + '//abshode-service.montgit.ir/server/get_user',
|
||||
protocol + '//212.23.201.173:8381/get_user',
|
||||
protocol + '//91.212.174.137:4040/server/get_user'
|
||||
]
|
||||
}
|
||||
|
||||
function sortVersionUrls(urls) {
|
||||
@@ -659,10 +624,10 @@
|
||||
'<div style="font-size: 42px; margin-bottom: 12px;">⚠️</div>' +
|
||||
'<h2 style="margin: 0 0 12px; font-size: 20px;">خطا در بارگذاری برنامه</h2>' +
|
||||
'<p style="margin: 0 0 20px; color: var(--boot-muted); line-height: 2; font-size: 14px;">' +
|
||||
'برقراری ارتباط با سرور امکانپذیر نیست. لطفاً اتصال اینترنت خود را بررسی کرده و صفحه را تازهسازی نمایید.' +
|
||||
'ارتباط با سرور برقرار نشد یا فایلهای برنامه بهدرستی دریافت نشدند.' +
|
||||
'</p>' +
|
||||
'<button onclick="window.__APP_BOOT_SIMPLE_RETRY__()" style="padding: 11px 22px; border: 0; border-radius: 12px; background: var(--boot-accent); color: white; cursor: pointer; font-weight: 700;">' +
|
||||
'تازهسازی صفحه' +
|
||||
'تلاش مجدد' +
|
||||
'</button>' +
|
||||
'<button onclick="window.__APP_BOOT_CLEAN_RELOAD__()" style="margin-right: 8px; padding: 11px 18px; border: 1px solid var(--boot-border); border-radius: 12px; background: transparent; color: var(--boot-text); cursor: pointer; font-weight: 700;">' +
|
||||
'پاکسازی و تلاش مجدد' +
|
||||
@@ -674,8 +639,8 @@
|
||||
async function cleanFetchAndReload() {
|
||||
renderRecovering('در حال دریافت تنظیمات جدید برنامه...')
|
||||
|
||||
var version = await loadRemoteVersion(3)
|
||||
var freshConfigResult = await fetchFreshConfig(3)
|
||||
var version = await loadRemoteVersion(5)
|
||||
var freshConfigResult = await fetchFreshConfig(5)
|
||||
|
||||
clearReadableCookies()
|
||||
// clearLocalStorageExceptToken()
|
||||
|
||||
@@ -39,8 +39,7 @@
|
||||
"vue3-apexcharts": "^1.4.4",
|
||||
"vue3-lazyload": "^0.3.8",
|
||||
"vue3-odometer": "^0.1.3",
|
||||
"vue3-otp-input": "^0.4.1",
|
||||
"wavesurfer.js": "^7.12.6"
|
||||
"vue3-otp-input": "^0.4.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@rushstack/eslint-patch": "^1.3.2",
|
||||
|
||||
@@ -3,14 +3,7 @@
|
||||
<transition mode="out-in" name="fade">
|
||||
<AConfigProvider
|
||||
v-if="!showSplash"
|
||||
:theme="{
|
||||
token: {
|
||||
colorPrimary: colors.primary,
|
||||
colorLink: colors.primary,
|
||||
colorLinkActive: colors.primary,
|
||||
colorLinkHover: colors['primary-rgba']
|
||||
}
|
||||
}"
|
||||
:theme="antDesignTheme"
|
||||
direction="rtl"
|
||||
>
|
||||
<router-view v-slot="{ Component, route }">
|
||||
@@ -46,11 +39,10 @@
|
||||
</transition>
|
||||
|
||||
<div
|
||||
v-if="showSupportButton && !showSplash && route.name !== 'support'"
|
||||
v-if="showSupportButton && !showSplash"
|
||||
id="support-button"
|
||||
ref="supportButtonEl"
|
||||
class="draggable-support-button"
|
||||
:class="{ 'is-dragging': supportDragging, 'is-picker-open': supportPickerOpen }"
|
||||
:class="{ 'is-dragging': supportDragging }"
|
||||
:style="supportButtonStyle"
|
||||
title="پشتیبانی"
|
||||
@pointerdown="onSupportPointerDown"
|
||||
@@ -61,55 +53,29 @@
|
||||
<div class="support-button-inner" :style="{ '--support-accent': supportAccentColor }">
|
||||
<BasicIcon :icon="supportIcon" size="18" class="support-button-icon" />
|
||||
<span class="support-button-label">پشتیبانی</span>
|
||||
<span
|
||||
v-if="supportChatUnreadCount > 0"
|
||||
class="support-fab-badge"
|
||||
>
|
||||
{{ supportChatUnreadCount > 99 ? '99+' : supportChatUnreadCount }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<SupportMessengerPicker
|
||||
v-model:open="supportPickerOpen"
|
||||
:entries="supportMessengerEntries"
|
||||
:anchor-el="pickerAnchorEl"
|
||||
@select="openMessengerEntry"
|
||||
/>
|
||||
|
||||
<VersionUpdateModal />
|
||||
|
||||
<PwaInstallGuideModal
|
||||
v-model:open="guideOpen"
|
||||
:platform="platform"
|
||||
@complete="completeGuide()"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { colors } from './themeConfig'
|
||||
import pkg from '../package.json'
|
||||
import { getDisplayAppVersion } from '@/config/config-cache'
|
||||
import { computed, defineAsyncComponent, h, onMounted, ref, watch } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { showBrowserNotification } from '@/utils/browserNotification'
|
||||
import { computed, defineAsyncComponent, h, onMounted, ref } from 'vue'
|
||||
import pkg from '../package.json'
|
||||
import img_topGradiant from '@/views/login/assets/img/gr_top_white.svg'
|
||||
import img_pattern from '@/views/login/assets/img/pattern.svg'
|
||||
import { LoadingOutlined } from '@ant-design/icons-vue'
|
||||
import BasicIcon from '@/components/BasicPacks/BasicIcon.vue'
|
||||
import { useSupportMessenger } from '@/composables/useSupportMessenger'
|
||||
import { loadSupportMessengerFromSettings } from '@/utils/supportMessenger'
|
||||
import SupportMessengerPicker from '@/components/SupportMessengerPicker.vue'
|
||||
import {
|
||||
buildSupportMessengerUrl,
|
||||
loadSupportMessengerFromSettings,
|
||||
supportMessengerSettings,
|
||||
} from '@/utils/supportMessenger'
|
||||
import { useDraggableFloatingButton } from '@/utils/useDraggableFloatingButton'
|
||||
import { useApplyDesktopLayoutClass } from '@/layouts/composables/useAppLayout'
|
||||
import { usePwaInstall } from '@/composables/usePwaInstall'
|
||||
import PwaInstallGuideModal from '@/components/pwa/PwaInstallGuideModal.vue'
|
||||
import { useUserStore } from '@/store/userStore'
|
||||
import { useSettingsStore } from '@/store/settingsStore'
|
||||
import { connectChatIfExists, disconnectChat, isSettingFlagOn, unreadSupportCount, useChatService } from '@/utils/chat'
|
||||
import { getToken } from '@/utils'
|
||||
import { getProjectBranding } from '@/utils/project'
|
||||
|
||||
import img_bottomGradiant from '@/views/login/assets/img/gr_bottom_white.svg'
|
||||
import logoFull from '@/assets/img/logo_full_.png'
|
||||
@@ -126,41 +92,64 @@ const indicator = h(LoadingOutlined, {
|
||||
})
|
||||
const displayVersion = getDisplayAppVersion(pkg.version)
|
||||
const showSplash = ref(true)
|
||||
const route = useRoute()
|
||||
|
||||
const antDesignTheme = computed(() => {
|
||||
const primary = getProjectBranding().accentColor
|
||||
|
||||
return {
|
||||
token: {
|
||||
colorPrimary: primary,
|
||||
colorLink: primary,
|
||||
colorLinkActive: primary,
|
||||
colorLinkHover: primary,
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
useApplyDesktopLayoutClass()
|
||||
|
||||
const {
|
||||
guideOpen,
|
||||
platform,
|
||||
completeGuide,
|
||||
} = usePwaInstall()
|
||||
|
||||
const {
|
||||
supportPickerOpen,
|
||||
supportPickerAnchor,
|
||||
supportMessengerEntries,
|
||||
messengerMeta,
|
||||
isChatEnabled,
|
||||
hasMessengerLink: showSupportButton,
|
||||
openMessengerEntry,
|
||||
openSupportMessenger,
|
||||
} = useSupportMessenger()
|
||||
|
||||
const supportButtonEl = ref<HTMLElement | null>(null)
|
||||
const pickerAnchorEl = computed(() => supportPickerAnchor.value ?? supportButtonEl.value)
|
||||
|
||||
const supportChatUnreadCount = computed(() =>
|
||||
isChatEnabled.value ? Number(unreadSupportCount.value) || 0 : 0,
|
||||
const supportLink = computed(() =>
|
||||
buildSupportMessengerUrl(
|
||||
supportMessengerSettings.value.messenger,
|
||||
supportMessengerSettings.value.messengerId
|
||||
)
|
||||
)
|
||||
|
||||
const supportIcon = computed(() => messengerMeta.value.icon)
|
||||
const showSupportButton = computed(() => !!supportLink.value)
|
||||
|
||||
const supportAccentColor = computed(() =>
|
||||
(messengerMeta.value.accent !== '#334155'
|
||||
? messengerMeta.value.accent
|
||||
: colors.primary) || '#334155',
|
||||
)
|
||||
const supportIcon = computed(() => {
|
||||
const messenger = (supportMessengerSettings.value.messenger ?? '').toLowerCase()
|
||||
switch (messenger) {
|
||||
case 'whatsapp':
|
||||
return 'vuesax-linear:whatsapp'
|
||||
case 'telegram':
|
||||
return 'vuesax-linear:send-2'
|
||||
case 'bale':
|
||||
return 'vuesax-linear:messages-2'
|
||||
default:
|
||||
return 'vuesax-linear:messages-2'
|
||||
}
|
||||
})
|
||||
|
||||
const supportAccentColor = computed(() => {
|
||||
const messenger = (supportMessengerSettings.value.messenger ?? '').toLowerCase()
|
||||
switch (messenger) {
|
||||
case 'whatsapp':
|
||||
return '#22c55e'
|
||||
case 'telegram':
|
||||
return '#0ea5e9'
|
||||
case 'bale':
|
||||
return '#16a34a'
|
||||
case 'rubika':
|
||||
return '#7c3aed'
|
||||
case 'eitaa':
|
||||
return '#f59e0b'
|
||||
case 'soroush':
|
||||
return '#2563eb'
|
||||
default:
|
||||
return getProjectBranding().accentColor
|
||||
}
|
||||
})
|
||||
|
||||
const {
|
||||
dragging: supportDragging,
|
||||
@@ -176,11 +165,15 @@ const {
|
||||
defaultRightOffset: 16,
|
||||
})
|
||||
|
||||
function openSupportLink() {
|
||||
if (!supportLink.value) return
|
||||
window.open(supportLink.value, '_blank', 'noopener,noreferrer')
|
||||
}
|
||||
|
||||
function handleSupportPointerUp(event: PointerEvent) {
|
||||
const clicked = supportPointerUp(event)
|
||||
if (!clicked) return
|
||||
event.stopPropagation()
|
||||
void openSupportMessenger(supportButtonEl.value)
|
||||
if (supportPointerUp(event)) {
|
||||
openSupportLink()
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
@@ -190,70 +183,11 @@ onMounted(async () => {
|
||||
}, 2000)
|
||||
})
|
||||
|
||||
const userStore = useUserStore()
|
||||
const settingsStore = useSettingsStore()
|
||||
const { latestIncomingNotification } = useChatService()
|
||||
let lastConnectedChatSessionKey = ''
|
||||
let lastSupportToastAt = 0
|
||||
|
||||
watch(
|
||||
() => [
|
||||
userStore.userInfo?.chat_room_id,
|
||||
userStore.userInfo?.chat_user_id,
|
||||
settingsStore.getSettingByKey('chat_api_key'),
|
||||
settingsStore.getSettingByKey('show_to_users_chat'),
|
||||
settingsStore.getSettingByKey('has_chat'),
|
||||
getToken(),
|
||||
],
|
||||
async ([roomId, chatUserId, chatApiKey, chatAdminFlag, chatCustomerFlag, token]) => {
|
||||
const chatOn =
|
||||
isSettingFlagOn(chatAdminFlag) && isSettingFlagOn(chatCustomerFlag)
|
||||
if (!token || !chatOn || !chatApiKey || !roomId || !chatUserId) {
|
||||
lastConnectedChatSessionKey = ''
|
||||
disconnectChat()
|
||||
return
|
||||
}
|
||||
|
||||
const sessionKey = `${roomId}:${chatUserId}:${chatApiKey}`
|
||||
if (lastConnectedChatSessionKey === sessionKey) return
|
||||
|
||||
try {
|
||||
await connectChatIfExists()
|
||||
lastConnectedChatSessionKey = sessionKey
|
||||
} catch (error) {
|
||||
lastConnectedChatSessionKey = ''
|
||||
console.error('connectChatIfExists failed:', error)
|
||||
}
|
||||
},
|
||||
{ immediate: true },
|
||||
)
|
||||
|
||||
watch(latestIncomingNotification, (payload) => {
|
||||
if (!payload) return
|
||||
if (payload.at === lastSupportToastAt) return
|
||||
lastSupportToastAt = payload.at
|
||||
|
||||
// فقط وقتی خارج از صفحهٔ چت (گیت داخل chat.ts)؛ داخل چت نوتیف نمیآید
|
||||
if (typeof document === 'undefined' || document.visibilityState === 'visible') {
|
||||
message.info({
|
||||
content: `پیام جدید پشتیبانی: ${payload.body}`,
|
||||
duration: 3,
|
||||
})
|
||||
}
|
||||
|
||||
void showBrowserNotification({
|
||||
title: payload.title || 'پشتیبانی',
|
||||
body: payload.body || 'پیام جدید',
|
||||
tag: 'support-chat-message',
|
||||
url: '/support',
|
||||
})
|
||||
})
|
||||
|
||||
</script>
|
||||
|
||||
<style lang="less">
|
||||
.updateButton .van-dialog__confirm .van-button__text {
|
||||
color: @primary-color !important;
|
||||
color: @theme-primary !important;
|
||||
font-weight: 600;
|
||||
font-size: 15px;
|
||||
}
|
||||
@@ -271,7 +205,6 @@ watch(latestIncomingNotification, (payload) => {
|
||||
}
|
||||
|
||||
.support-button-inner {
|
||||
position: relative;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
@@ -297,24 +230,6 @@ watch(latestIncomingNotification, (payload) => {
|
||||
}
|
||||
}
|
||||
|
||||
.support-fab-badge {
|
||||
position: absolute;
|
||||
top: -6px;
|
||||
left: -4px;
|
||||
z-index: 2;
|
||||
min-width: 18px;
|
||||
height: 18px;
|
||||
padding: 0 5px;
|
||||
border-radius: 999px;
|
||||
background: #dc2626;
|
||||
color: #fff;
|
||||
font-size: 10px;
|
||||
font-weight: 700;
|
||||
line-height: 18px;
|
||||
text-align: center;
|
||||
box-shadow: 0 0 0 2px #fff;
|
||||
}
|
||||
|
||||
#support-button:not(.is-dragging):hover .support-button-inner {
|
||||
transform: translateY(-1px);
|
||||
box-shadow: 0 8px 24px rgba(15, 23, 42, 0.18);
|
||||
@@ -323,17 +238,4 @@ watch(latestIncomingNotification, (payload) => {
|
||||
#support-button.is-dragging .support-button-inner {
|
||||
box-shadow: 0 10px 28px rgba(15, 23, 42, 0.22);
|
||||
}
|
||||
|
||||
#support-button.is-picker-open .support-button-inner {
|
||||
transform: scale(0.94);
|
||||
box-shadow: 0 4px 14px rgba(15, 23, 42, 0.12);
|
||||
}
|
||||
|
||||
/* در دسکتاپ، دکمه پشتیبانی کنار سایدبار و پایین صفحه قرار میگیرد (مانند khaneghi_user) */
|
||||
html.app-layout--desktop {
|
||||
#support-button {
|
||||
bottom: 12px;
|
||||
right: calc(var(--app-desktop-sidebar-width, 260px) + 20px);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
import useAxios from '@/utils/useAxios'
|
||||
|
||||
export type AppNotificationSeverity = 'info' | 'success' | 'warning' | 'danger'
|
||||
|
||||
export interface CustomerAppNotification {
|
||||
id: number
|
||||
title: string
|
||||
body: string
|
||||
severity: AppNotificationSeverity
|
||||
created_at?: string
|
||||
is_read: boolean
|
||||
}
|
||||
|
||||
export const getAppNotifications = async () =>
|
||||
await useAxios.get<CustomerAppNotification[]>(`/customer/app_notifications`)
|
||||
|
||||
export const getAppNotificationsUnreadCount = async () =>
|
||||
await useAxios.get<{ unread_count: number }>(`/customer/app_notifications/unread-count`)
|
||||
|
||||
export const markAppNotificationRead = async (id: number) =>
|
||||
await useAxios.post(`/customer/app_notifications/${id}/read`)
|
||||
|
||||
export const markAllAppNotificationsRead = async () =>
|
||||
await useAxios.post(`/customer/app_notifications/read-all`)
|
||||
@@ -1,6 +0,0 @@
|
||||
import useAxios from '@/utils/useAxios'
|
||||
import type { User } from '@/models/login'
|
||||
|
||||
export const startChat = async (): Promise<{ message: string; user: User }> => {
|
||||
return await useAxios.get<{ message: string; user: User }>(`/customer/start-chat`)
|
||||
}
|
||||
@@ -6,10 +6,6 @@ import type { PWallet, Wallet } from '@/models/wallet'
|
||||
export const getProducts = async (): Promise<any> => {
|
||||
return await useAxios.get<Product[]>(`/customer/product/list`, { timeout: 15000 })
|
||||
}
|
||||
export const getTvProducts = async (): Promise<Product[]> => {
|
||||
const response = await useAxios.get<unknown>(`/customer/tv/products`, { timeout: 15000 })
|
||||
return Array.isArray(response) ? (response as Product[]) : []
|
||||
}
|
||||
export const getProductById = async ( id:number|null): Promise<any> => {
|
||||
return await useAxios.get<Product[]>(`/customer/product/list/${id}`, { timeout: 15000 })
|
||||
}
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
import {
|
||||
fetchSuperAdminJson,
|
||||
resolveTenantDomain,
|
||||
SA_PROGRAM_SETTINGS_PATH,
|
||||
} from '@/config/superadmin'
|
||||
|
||||
export type SuperAdminSettingRow = {
|
||||
id?: number
|
||||
key?: string
|
||||
value?: string | number
|
||||
title_fa?: string
|
||||
description?: string
|
||||
is_active?: boolean | number | string
|
||||
type?: string
|
||||
can_edit?: number | boolean | string
|
||||
}
|
||||
|
||||
function parseSettingsPayload(data: unknown): SuperAdminSettingRow[] {
|
||||
if (Array.isArray(data)) return data as SuperAdminSettingRow[]
|
||||
if (data && typeof data === 'object') {
|
||||
const obj = data as Record<string, unknown>
|
||||
if (Array.isArray(obj.settings)) return obj.settings as SuperAdminSettingRow[]
|
||||
if (Array.isArray(obj.items)) return obj.items as SuperAdminSettingRow[]
|
||||
if (Array.isArray(obj.data)) return obj.data as SuperAdminSettingRow[]
|
||||
}
|
||||
return []
|
||||
}
|
||||
|
||||
/** کلید قفلشده در get_settings محلی — باید از سوپرادمین بیاید */
|
||||
export function isLockedCanEdit(canEdit: unknown): boolean {
|
||||
return canEdit === 0 || canEdit === false || canEdit === '0'
|
||||
}
|
||||
|
||||
/** تنظیمات پیشرفته نسخه از سوپرادمین — فقط GET /api/public/program-settings?domain= */
|
||||
export async function fetchSuperAdminProgramSettings(): Promise<SuperAdminSettingRow[]> {
|
||||
const domain = encodeURIComponent(resolveTenantDomain())
|
||||
const data = await fetchSuperAdminJson(
|
||||
(base) => `${base}${SA_PROGRAM_SETTINGS_PATH}?domain=${domain}`,
|
||||
)
|
||||
return parseSettingsPayload(data)
|
||||
}
|
||||
@@ -48,13 +48,13 @@ function showBootstrapError(error: unknown) {
|
||||
<div style="font-size: 42px; margin-bottom: 12px;">⚠️</div>
|
||||
<h2 style="margin: 0 0 12px; font-size: 20px;">خطا در راهاندازی برنامه</h2>
|
||||
<p style="margin: 0 0 20px; color: var(--boot-muted, rgba(15,23,42,0.62)); line-height: 2; font-size: 14px;">
|
||||
برقراری ارتباط با سرور امکانپذیر نیست. لطفاً اتصال اینترنت خود را بررسی کرده و صفحه را تازهسازی نمایید.
|
||||
لطفاً اتصال اینترنت خود را بررسی کنید و دوباره تلاش کنید.
|
||||
</p>
|
||||
<button
|
||||
onclick="location.reload()"
|
||||
style="padding: 11px 22px; border: 0; border-radius: 12px; background: var(--boot-accent, #2563eb); color: white; cursor: pointer; font-weight: 700;"
|
||||
>
|
||||
تازهسازی صفحه
|
||||
تلاش مجدد
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
setHasFingerPrint
|
||||
} from '@/app/authBoot'
|
||||
import { recoverMobileViewportAfterAuth } from '@/layouts/composables/useMobileScrollReset'
|
||||
import { getProjectDefaultRoute, isGhatreProject } from '@/utils/project'
|
||||
|
||||
export function setupRouterGuards() {
|
||||
const userStore = useUserStore()
|
||||
@@ -34,7 +35,7 @@ export function setupRouterGuards() {
|
||||
}
|
||||
|
||||
function goToLogin(to: RouteLocationNormalized, next: NavigationGuardNext) {
|
||||
if (to.name === 'buyProduct' || to.name === 'productDetail' || to.name === 'about' || to.name === 'cart' || to.name === 'tv') {
|
||||
if (to.name === 'buyProduct' || to.name === 'productDetail' || to.name === 'about' || to.name === 'cart') {
|
||||
return next()
|
||||
}
|
||||
if (to.name !== 'login') {
|
||||
@@ -44,50 +45,21 @@ export function setupRouterGuards() {
|
||||
}
|
||||
|
||||
function goToHome(to: RouteLocationNormalized, next: NavigationGuardNext) {
|
||||
if (to.name !== 'buyProduct') {
|
||||
return next({ name: 'buyProduct' })
|
||||
const defaultRoute = getProjectDefaultRoute()
|
||||
if (to.name !== defaultRoute) {
|
||||
return next({ name: defaultRoute })
|
||||
}
|
||||
return next()
|
||||
}
|
||||
|
||||
router.beforeEach(async (to, from, next) => {
|
||||
if (to.name === 'home' && isGhatreProject()) {
|
||||
return next({ name: 'buyProduct' })
|
||||
}
|
||||
authStore.setLoading(true)
|
||||
clearFingerTimeout()
|
||||
setFingerTimeOut(to)
|
||||
|
||||
if (to.name === 'notifyTrigger' && getToken()) {
|
||||
const { useSettingsStore } = await import('@/store/settingsStore')
|
||||
const settingsStore = useSettingsStore()
|
||||
if (!settingsStore.loaded) {
|
||||
await settingsStore.fetchSettings()
|
||||
}
|
||||
if (!settingsStore.isSettingTruthy('has_page_price_trigger')) {
|
||||
return next({ name: (from.name as string) || 'user' })
|
||||
}
|
||||
}
|
||||
|
||||
if (to.name === 'appNotifications' && getToken()) {
|
||||
const { useSettingsStore } = await import('@/store/settingsStore')
|
||||
const settingsStore = useSettingsStore()
|
||||
if (!settingsStore.loaded) {
|
||||
await settingsStore.fetchSettings()
|
||||
}
|
||||
if (!settingsStore.isSettingTruthy('has_page_notification')) {
|
||||
return next({ name: (from.name as string) || 'home' })
|
||||
}
|
||||
}
|
||||
|
||||
if (to.name === 'giftCard' && getToken()) {
|
||||
const { useSettingsStore } = await import('@/store/settingsStore')
|
||||
const settingsStore = useSettingsStore()
|
||||
if (!settingsStore.loaded) {
|
||||
await settingsStore.fetchSettings()
|
||||
}
|
||||
if (!settingsStore.isSettingTruthy('has_page_gift_card')) {
|
||||
return next({ name: (from.name as string) || 'user' })
|
||||
}
|
||||
}
|
||||
|
||||
if (isFirst) {
|
||||
isFirst = false
|
||||
|
||||
@@ -112,7 +84,7 @@ export function setupRouterGuards() {
|
||||
return next()
|
||||
}
|
||||
} else {
|
||||
if (['login', '404', 'buyProduct', 'productDetail', 'about', 'cart', 'tv'].includes(to.name as string)) {
|
||||
if (['login', '404', 'buyProduct', 'productDetail', 'about', 'cart'].includes(to.name as string)) {
|
||||
return next()
|
||||
}
|
||||
goToLogin(to, next)
|
||||
@@ -121,12 +93,12 @@ export function setupRouterGuards() {
|
||||
if (getFingerPosition()) {
|
||||
if (getToken()) {
|
||||
if (to.name === 'login') {
|
||||
return next({ name: from.name || 'buyProduct' })
|
||||
return next({ name: from.name || getProjectDefaultRoute() })
|
||||
}
|
||||
return next()
|
||||
}
|
||||
|
||||
if (['login', '404', 'buyProduct', 'productDetail', 'about', 'cart', 'tv'].includes(to.name as string)) {
|
||||
if (['login', '404', 'buyProduct', 'productDetail', 'about', 'cart'].includes(to.name as string)) {
|
||||
return next()
|
||||
}
|
||||
return next({ name: 'login' })
|
||||
|
||||
@@ -10,8 +10,6 @@
|
||||
@import (less) '../../views/base/user/desktop/styles/desktop-user.less';
|
||||
@import (less) '../../views/base/priceTrigger/desktop/styles/desktop-price-trigger.less';
|
||||
@import (less) '../../views/base/home/desktop/styles/desktop-home.less';
|
||||
@import (less) '../../views/base/gold/desktop/styles/desktop-gold.less';
|
||||
@import (less) '../../views/login/desktop/styles/desktop-login.less';
|
||||
@import (less) '../../layouts/desktop/styles/desktop-inner-pages.less';
|
||||
|
||||
html {
|
||||
@@ -63,6 +61,8 @@ body {
|
||||
|
||||
:root {
|
||||
color-scheme: only light;
|
||||
--app-primary-color: #a72b77;
|
||||
--project-hero-gradient: linear-gradient(145deg, #a72b77 0%, #711d4d 40%, #a72b77 100%);
|
||||
--app-safe-top: env(safe-area-inset-top, 0px);
|
||||
--app-safe-bottom: env(safe-area-inset-bottom, 0px);
|
||||
--app-credit-bar-inner: 0px;
|
||||
@@ -80,6 +80,16 @@ body {
|
||||
--app-z-modal: 5500;
|
||||
}
|
||||
|
||||
:root[data-project='ghatre'] {
|
||||
--app-primary-color: #521620;
|
||||
--project-hero-gradient: linear-gradient(145deg, #521620 0%, #7a2a1e 40%, #521620 100%);
|
||||
}
|
||||
|
||||
:root[data-project='kashkool'] {
|
||||
--app-primary-color: #a72b77;
|
||||
--project-hero-gradient: linear-gradient(145deg, #a72b77 0%, #711d4d 40%, #a72b77 100%);
|
||||
}
|
||||
|
||||
.ant-form-item {
|
||||
margin-bottom: 10px !important;
|
||||
|
||||
@@ -166,7 +176,7 @@ body {
|
||||
background-color: #fff;
|
||||
//display: none;
|
||||
outline: none;
|
||||
border: 1px solid #a72b77 !important;
|
||||
border: 1px solid var(--app-primary-color, #a72b77) !important;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -364,18 +374,18 @@ body {
|
||||
}
|
||||
.ant-radio-group-solid
|
||||
.ant-radio-button-wrapper-checked:not(.ant-radio-button-wrapper-disabled):hover{
|
||||
color: #a72b77 !important;
|
||||
color: var(--app-primary-color, #a72b77) !important;
|
||||
}
|
||||
.ant-input-group-addon{
|
||||
background-color: #a72b77 !important;
|
||||
background-color: var(--app-primary-color, #a72b77) !important;
|
||||
color: #e0be7f !important;
|
||||
}
|
||||
.ant-slider-track{
|
||||
background-color: #a72b77 !important;
|
||||
background-color: var(--app-primary-color, #a72b77) !important;
|
||||
|
||||
}
|
||||
.ant-slider-handle {
|
||||
background-color: #a72b77 !important;
|
||||
background-color: var(--app-primary-color, #a72b77) !important;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
@primary-color: #a72b77;
|
||||
@secondary-color: #a72b77;
|
||||
@App-primary-color: #a72b77;
|
||||
@theme-primary: var(--app-primary-color, #a72b77);
|
||||
@prefixCls-font-family: 'iran-sans';
|
||||
@prefixCls-background-color: #fff;
|
||||
|
||||
|
||||
|
Before Width: | Height: | Size: 607 B |
|
Before Width: | Height: | Size: 37 KiB |
|
Before Width: | Height: | Size: 40 KiB |
@@ -1,10 +0,0 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="256" height="256" viewBox="0 0 256 256">
|
||||
<circle cx="128" cy="128" r="124" fill="#12B76A"/>
|
||||
<!-- Bootstrap Icons telephone-fill — گوشی کامل -->
|
||||
<g transform="translate(48 48) scale(10)">
|
||||
<path
|
||||
fill="#fff"
|
||||
d="M1.885.511a1.745 1.745 0 0 1 2.612.163L6.29 2.98c.329.423.445.967.315 1.49l-.547 2.19a.678.678 0 0 0 .178.643l2.457 2.457a.678.678 0 0 0 .644.178l2.189-.547a1.745 1.745 0 0 1 1.49.315l2.306 1.794c.829.645.905 1.87.163 2.611l-1.034 1.034c-.74.74-1.846 1.065-2.877.702a18.634 18.634 0 0 1-7.01-4.42 18.634 18.634 0 0 1-4.42-7.009c-.362-1.03-.038-2.137.703-2.877L1.885.511z"
|
||||
/>
|
||||
</g>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 680 B |
|
Before Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 3.0 KiB |
@@ -1,7 +0,0 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="256" height="256" viewBox="0 0 256 256" fill="none">
|
||||
<circle cx="128" cy="128" r="128" fill="#3B82F6"/>
|
||||
<path
|
||||
fill="#fff"
|
||||
d="M78 76h100c11 0 20 9 20 20v64c0 11-9 20-20 20h-52l-30 26v-26H78c-11 0-20-9-20-20V96c0-11 9-20 20-20zm16 40h68v14H94v-14zm0 28h48v14H94v-14z"
|
||||
/>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 337 B |
@@ -1,7 +0,0 @@
|
||||
<svg viewBox="0 0 48 48" xmlns="http://www.w3.org/2000/svg">
|
||||
<rect width="48" height="48" rx="12" fill="#1CA0E2"/>
|
||||
<g transform="translate(12 12)">
|
||||
<path d="M14.4501 0.922337C14.4249 0.922337 14.3996 0.922337 14.3749 0.922337C13.9177 0.865759 13.4564 0.848106 12.9962 0.869568C12.3937 0.891042 11.7968 0.992415 11.2211 1.17103C10.5799 1.36599 9.98324 1.6851 9.46511 2.11021C9.27918 2.26684 9.10383 2.43563 8.94023 2.61545C8.62473 2.95789 8.39401 3.35478 8.19696 3.77245C8.09086 3.997 7.99543 4.22773 7.8955 4.45565C7.88203 4.48764 7.8708 4.5202 7.86014 4.55333C7.82589 4.66167 7.79558 4.77114 7.75853 4.87836C7.65492 5.2025 7.5737 5.53337 7.51545 5.86863C7.45552 6.17826 7.41539 6.4914 7.39532 6.80613C7.37904 7.03574 7.36669 7.2659 7.36613 7.49607C7.36593 7.89339 7.3888 8.29039 7.43461 8.68506C7.49075 9.19592 7.58787 9.70059 7.69341 10.2036C7.81298 10.7756 7.99094 11.3303 8.1644 11.8877C8.33787 12.4452 8.5394 12.9847 8.73757 13.5297C8.89756 13.9716 9.04576 14.4167 9.16702 14.8709C9.24027 15.1385 9.29245 15.4114 9.32309 15.6871C9.37053 16.0792 9.35422 16.4763 9.27481 16.8632C9.26358 16.9126 9.25179 16.9614 9.23719 17.0097C9.17854 17.206 9.10843 17.3987 9.02724 17.5868C8.97171 17.7142 8.90383 17.8359 8.82458 17.95C8.54294 18.3624 8.19617 18.7262 7.79782 19.0273C7.33066 19.3746 6.78803 19.6066 6.21418 19.7043C5.97198 19.7479 5.72653 19.7708 5.48046 19.7728C4.65255 19.785 3.84735 19.5021 3.20913 18.9745C3.06738 18.8636 2.93586 18.7402 2.81616 18.6057C2.79988 18.5866 2.78024 18.5704 2.76003 18.553C2.73982 18.5355 2.73701 18.5479 2.72578 18.553C2.70445 18.5423 2.69715 18.5198 2.68536 18.5019C2.53435 18.2655 2.37492 18.0348 2.23289 17.7923C2.02466 17.4393 1.83484 17.0758 1.66422 16.7032C1.4634 16.2612 1.29071 15.8068 1.14719 15.343C1.028 14.9577 0.929988 14.5662 0.853591 14.1703C0.802506 13.9081 0.760402 13.6437 0.730649 13.3776C0.707633 13.171 0.686862 12.9644 0.674512 12.7567C0.663846 12.6024 0.663846 12.448 0.655425 12.2942C0.647566 12.1645 0.644197 12.0354 0.647004 11.9062C0.650934 11.7204 0.654302 11.5341 0.666091 11.3488C0.679564 11.1349 0.696405 10.921 0.722229 10.7088C0.800805 10.0199 0.942301 9.33971 1.14495 8.67664C1.27499 8.25508 1.42887 7.84124 1.60584 7.43712C1.89207 6.78413 2.23982 6.15987 2.64438 5.57279C3.12563 4.87288 3.68354 4.22892 4.30774 3.65288C5.11591 2.9082 6.02747 2.28423 7.01414 1.80033C7.73201 1.44668 8.48602 1.17169 9.26302 0.980159C9.59984 0.898198 9.93667 0.829149 10.2814 0.776941C10.4554 0.750369 10.6303 0.728288 10.8062 0.710698C10.9943 0.691611 11.1829 0.681506 11.371 0.663542C11.4367 0.657367 11.5035 0.65849 11.5697 0.657367C11.9065 0.649508 12.2383 0.649508 12.5723 0.661297C12.7015 0.665788 12.83 0.681506 12.9586 0.69105C13.0338 0.696664 13.109 0.703962 13.1831 0.711259C13.4533 0.737083 13.7213 0.774508 13.987 0.823535C14.1229 0.848797 14.2587 0.875743 14.3951 0.901566C14.4154 0.901603 14.4349 0.908983 14.4501 0.922337Z" fill="#ffffff"/>
|
||||
<path d="M5.25874 21.1173C5.27981 21.122 5.29921 21.1323 5.31488 21.1471C5.63283 21.3639 5.96476 21.5595 6.30852 21.7326C6.92863 22.0651 7.58142 22.3326 8.2565 22.5309C8.68006 22.6535 9.11143 22.7472 9.54766 22.8116C10.1444 22.8977 10.748 22.9264 11.3502 22.8974C11.7252 22.8804 12.0987 22.8397 12.4685 22.7756C12.6768 22.7403 12.8834 22.6976 13.0894 22.6516C13.6547 22.5202 14.2077 22.3411 14.7426 22.116C15.2004 21.927 15.6441 21.7057 16.0703 21.4536C16.5961 21.1443 17.0675 20.7507 17.4659 20.2887C17.8669 19.8343 18.2251 19.3438 18.5359 18.8235C19.0119 18.0108 19.35 17.1247 19.5362 16.2013C19.5979 15.8984 19.6419 15.5921 19.6682 15.2841C19.6987 14.9384 19.7084 14.5912 19.6974 14.2444C19.6623 13.1958 19.4489 12.1608 19.0664 11.1838C18.9917 10.9929 18.9131 10.8037 18.8351 10.614C18.8194 10.5763 18.8008 10.5399 18.7818 10.5017C18.4002 9.77858 17.9286 9.1067 17.3783 8.50205C17.0213 8.10516 16.6334 7.7397 16.2449 7.37481C15.9642 7.1132 15.6661 6.87687 15.3658 6.64109C15.1553 6.47267 14.938 6.31829 14.7365 6.1409C14.6708 6.07719 14.6006 6.01828 14.5265 5.96463C14.5033 5.94836 14.482 5.92953 14.4631 5.90849C14.3716 5.81306 14.2778 5.71931 14.1897 5.62106C13.9048 5.30938 13.7133 4.9238 13.6373 4.50841C13.5599 4.04993 13.605 3.57914 13.7681 3.14371C14.0347 2.46051 14.5209 2.00355 15.2063 1.7571C15.6623 1.58876 16.1576 1.55753 16.6311 1.66728C16.6586 1.67346 16.6873 1.67683 16.7148 1.68132C16.716 1.68322 16.7176 1.68484 16.7195 1.68607C16.7214 1.68729 16.7235 1.68809 16.7258 1.68841C16.728 1.68873 16.7303 1.68856 16.7325 1.68792C16.7346 1.68728 16.7366 1.68617 16.7383 1.68469C16.8039 1.70602 16.8668 1.73484 16.9258 1.77058C17.6094 2.10085 18.2582 2.4986 18.8626 2.95789C19.1186 3.1525 19.366 3.35834 19.6047 3.57541C19.8577 3.8037 20.1001 4.04303 20.3317 4.29341C21.5814 5.64007 22.4838 7.27123 22.9606 9.04547C23.0482 9.37163 23.1201 9.70059 23.1801 10.0324C23.2149 10.2277 23.2434 10.424 23.2655 10.6213C23.2885 10.8312 23.3087 11.0412 23.3216 11.2517C23.3312 11.3836 23.3345 11.5161 23.339 11.6486C23.3424 11.7608 23.3508 11.8686 23.3491 11.9792C23.3463 12.1998 23.3441 12.421 23.33 12.6411C23.3147 12.8858 23.2926 13.1304 23.2638 13.3748C23.0982 14.7647 22.6752 16.1116 22.0164 17.3466C21.8345 17.6892 21.6334 18.0213 21.4141 18.3413C21.3957 18.3665 21.3825 18.3952 21.3754 18.4255C21.3682 18.4559 21.3673 18.4874 21.3725 18.5181C21.3966 18.677 21.4185 18.8359 21.4404 18.9953C21.4623 19.1547 21.4837 19.3198 21.505 19.482C21.528 19.6566 21.551 19.8318 21.5735 20.0064C21.5886 20.1287 21.6016 20.2506 21.6167 20.3724C21.633 20.5071 21.6509 20.6413 21.6672 20.7754C21.6835 20.9096 21.6975 21.032 21.7127 21.16C21.7279 21.288 21.7413 21.4042 21.7565 21.526C21.7722 21.6574 21.789 21.7887 21.8053 21.919C21.8233 22.0627 21.8407 22.207 21.8581 22.3507C21.8733 22.4759 21.8873 22.6005 21.9019 22.7257C21.9097 22.7913 21.9182 22.857 21.926 22.9227C21.9339 22.9884 21.9182 23.0064 21.8463 22.9884C21.7851 22.9732 21.7245 22.9558 21.6639 22.9396L20.2486 22.5612C19.7995 22.4416 19.3538 22.3232 18.9069 22.2025C18.5662 22.111 18.226 22.0166 17.8858 21.9218C17.8224 21.9044 17.7578 21.8881 17.6949 21.8656C17.6773 21.8594 17.6585 21.8573 17.6399 21.8594C17.6213 21.8616 17.6035 21.8679 17.5877 21.878C17.3474 22.0172 17.0993 22.1424 16.8489 22.262C16.493 22.4309 16.1283 22.5808 15.7565 22.7111C15.361 22.8498 14.958 22.9664 14.5495 23.0602C14.3008 23.1164 14.051 23.1686 13.7984 23.204C13.6395 23.2264 13.4812 23.255 13.3218 23.2724C13.1467 23.291 12.9709 23.3073 12.7947 23.319C12.4674 23.3404 12.1395 23.3544 11.8117 23.3482C11.6444 23.3449 11.4775 23.3385 11.3109 23.3291C11.1599 23.3202 11.0089 23.3089 10.8585 23.2921C10.6429 23.2674 10.4273 23.241 10.2129 23.2068C9.96701 23.1675 9.72281 23.122 9.4831 23.067C8.84985 22.9227 8.23008 22.7246 7.63056 22.4747C7.28999 22.3321 6.9571 22.1735 6.63187 21.9987C6.17367 21.752 5.73289 21.4742 5.31264 21.1673C5.28962 21.1555 5.26492 21.1448 5.25874 21.1173Z" fill="#ffffff"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 6.7 KiB |
@@ -1 +0,0 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 256 256"><defs><linearGradient id="SVG6DaOZcwt" x1="50%" x2="50%" y1="0%" y2="100%"><stop offset="0%" stop-color="#2aabee"/><stop offset="100%" stop-color="#229ed9"/></linearGradient></defs><path fill="url(#SVG6DaOZcwt)" d="M128 0C94.06 0 61.48 13.494 37.5 37.49A128.04 128.04 0 0 0 0 128c0 33.934 13.5 66.514 37.5 90.51C61.48 242.506 94.06 256 128 256s66.52-13.494 90.5-37.49c24-23.996 37.5-56.576 37.5-90.51s-13.5-66.514-37.5-90.51C194.52 13.494 161.94 0 128 0"/><path fill="#fff" d="M57.94 126.648q55.98-24.384 74.64-32.152c35.56-14.786 42.94-17.354 47.76-17.441c1.06-.017 3.42.245 4.96 1.49c1.28 1.05 1.64 2.47 1.82 3.467c.16.996.38 3.266.2 5.038c-1.92 20.24-10.26 69.356-14.5 92.026c-1.78 9.592-5.32 12.808-8.74 13.122c-7.44.684-13.08-4.912-20.28-9.63c-11.26-7.386-17.62-11.982-28.56-19.188c-12.64-8.328-4.44-12.906 2.76-20.386c1.88-1.958 34.64-31.748 35.26-34.45c.08-.338.16-1.598-.6-2.262c-.74-.666-1.84-.438-2.64-.258c-1.14.256-19.12 12.152-54 35.686c-5.1 3.508-9.72 5.218-13.88 5.128c-4.56-.098-13.36-2.584-19.9-4.708c-8-2.606-14.38-3.984-13.82-8.41c.28-2.304 3.46-4.662 9.52-7.072"/></svg>
|
||||
|
Before Width: | Height: | Size: 1.1 KiB |
@@ -1 +0,0 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 256 258"><defs><linearGradient id="SVGK3KZq49U" x1="50%" x2="50%" y1="100%" y2="0%"><stop offset="0%" stop-color="#1faf38"/><stop offset="100%" stop-color="#60d669"/></linearGradient><linearGradient id="SVGefMkoEOd" x1="50%" x2="50%" y1="100%" y2="0%"><stop offset="0%" stop-color="#f9f9f9"/><stop offset="100%" stop-color="#fff"/></linearGradient></defs><path fill="url(#SVGK3KZq49U)" d="M5.463 127.456c-.006 21.677 5.658 42.843 16.428 61.499L4.433 252.697l65.232-17.104a123 123 0 0 0 58.8 14.97h.054c67.815 0 123.018-55.183 123.047-123.01c.013-32.867-12.775-63.773-36.009-87.025c-23.23-23.25-54.125-36.061-87.043-36.076c-67.823 0-123.022 55.18-123.05 123.004"/><path fill="url(#SVGefMkoEOd)" d="M1.07 127.416c-.007 22.457 5.86 44.38 17.014 63.704L0 257.147l67.571-17.717c18.618 10.151 39.58 15.503 60.91 15.511h.055c70.248 0 127.434-57.168 127.464-127.423c.012-34.048-13.236-66.065-37.3-90.15C194.633 13.286 162.633.014 128.536 0C58.276 0 1.099 57.16 1.071 127.416m40.24 60.376l-2.523-4.005c-10.606-16.864-16.204-36.352-16.196-56.363C22.614 69.029 70.138 21.52 128.576 21.52c28.3.012 54.896 11.044 74.9 31.06c20.003 20.018 31.01 46.628 31.003 74.93c-.026 58.395-47.551 105.91-105.943 105.91h-.042c-19.013-.01-37.66-5.116-53.922-14.765l-3.87-2.295l-40.098 10.513z"/><path fill="#fff" d="M96.678 74.148c-2.386-5.303-4.897-5.41-7.166-5.503c-1.858-.08-3.982-.074-6.104-.074c-2.124 0-5.575.799-8.492 3.984c-2.92 3.188-11.148 10.892-11.148 26.561s11.413 30.813 13.004 32.94c1.593 2.123 22.033 35.307 54.405 48.073c26.904 10.609 32.379 8.499 38.218 7.967c5.84-.53 18.844-7.702 21.497-15.139c2.655-7.436 2.655-13.81 1.859-15.142c-.796-1.327-2.92-2.124-6.105-3.716s-18.844-9.298-21.763-10.361c-2.92-1.062-5.043-1.592-7.167 1.597c-2.124 3.184-8.223 10.356-10.082 12.48c-1.857 2.129-3.716 2.394-6.9.801c-3.187-1.598-13.444-4.957-25.613-15.806c-9.468-8.442-15.86-18.867-17.718-22.056c-1.858-3.184-.199-4.91 1.398-6.497c1.431-1.427 3.186-3.719 4.78-5.578c1.588-1.86 2.118-3.187 3.18-5.311c1.063-2.126.531-3.986-.264-5.579c-.798-1.593-6.987-17.343-9.819-23.64"/></svg>
|
||||
|
Before Width: | Height: | Size: 2.1 KiB |
@@ -26,7 +26,7 @@ const _attrs = computed(() => {
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
value: '',
|
||||
format: 'YYYY-MM-DD'
|
||||
format: 'YYYY/MM/DD'
|
||||
})
|
||||
|
||||
const emit = defineEmits<{
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
:type="props.type"
|
||||
class=""
|
||||
@change="handlerChange"
|
||||
@input="handlerChange"
|
||||
/>
|
||||
<a-input
|
||||
v-else
|
||||
@@ -29,7 +28,6 @@
|
||||
:pattern="props.pattern"
|
||||
class=""
|
||||
@change="handlerChange"
|
||||
@input="handlerChange"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
@@ -38,12 +36,7 @@
|
||||
import {usePrefix} from "@/utils/usePrefix";
|
||||
import {computed} from "vue";
|
||||
import {usePrice} from "@/components/BasicPacks/BasicPriceInput/src/utils/usePrice";
|
||||
import {
|
||||
normalizeDecimalInput,
|
||||
persianToEnglishDigits,
|
||||
shouldNormalizeDecimalSeparators,
|
||||
shouldNormalizeInputDigits,
|
||||
} from '@/utils/persianDigits';
|
||||
import {persianToEnglishDigits, shouldNormalizeInputDigits} from '@/utils/persianDigits';
|
||||
|
||||
//Props
|
||||
interface Prop {
|
||||
@@ -86,27 +79,18 @@ function normalizeValue(value: unknown) {
|
||||
return value
|
||||
}
|
||||
|
||||
if (shouldNormalizeDecimalSeparators(props)) {
|
||||
const isPrice = String(props.type ?? '').trim().toLowerCase() === 'price'
|
||||
return normalizeDecimalInput(value as string | number, {
|
||||
commaAsThousand: isPrice,
|
||||
})
|
||||
}
|
||||
|
||||
let normalized = String(value)
|
||||
if (shouldNormalizeInputDigits(props)) {
|
||||
normalized = persianToEnglishDigits(normalized)
|
||||
}
|
||||
if (props.type === 'price') {
|
||||
normalized = normalized.replaceAll(',', '')
|
||||
}
|
||||
return normalized
|
||||
}
|
||||
|
||||
const handlerChange = (e: Event | string) => {
|
||||
const target = typeof e === 'string' ? null : (e.target as HTMLInputElement | null)
|
||||
const raw = typeof e === 'string' ? e : target?.value
|
||||
const normalized = normalizeValue(raw)
|
||||
if (target && typeof normalized === 'string' && target.value !== normalized) {
|
||||
target.value = normalized
|
||||
}
|
||||
const handlerChange = (e: any) => {
|
||||
const normalized = normalizeValue(e.target.value)
|
||||
emits('update:value', normalized)
|
||||
emits('onchange', normalized)
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
import {usePrice} from './utils/usePrice'
|
||||
import {computed} from "vue";
|
||||
import BasicInput from "../../BasicInput.vue";
|
||||
import {normalizeDecimalInput} from '@/utils/persianDigits'
|
||||
import {persianToEnglishDigits} from '@/utils/persianDigits'
|
||||
|
||||
interface Props {
|
||||
value?: string | number
|
||||
@@ -24,7 +24,7 @@ const props = withDefaults(defineProps<Props>(), {})
|
||||
|
||||
const _val = computed({
|
||||
set(val: string) {
|
||||
emit('update:value', normalizeDecimalInput(val))
|
||||
emit('update:value', persianToEnglishDigits(val).replaceAll(',', ''))
|
||||
},
|
||||
get() {
|
||||
return props.value ? usePrice(props.value as number, true, '').trim() : ''
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
<template>
|
||||
<van-dialog
|
||||
v-model:show="show"
|
||||
class="gold-loading-dialog updateButton"
|
||||
teleport="body"
|
||||
:z-index="zIndex"
|
||||
class="updateButton"
|
||||
confirm-button-text="متوجه شدم"
|
||||
:show-confirm-button="false"
|
||||
:close-on-click-overlay="false"
|
||||
:close-on-popstate="false"
|
||||
@confirm="update()"
|
||||
>
|
||||
<div class="flex flex-col items-center p-2">
|
||||
<DotLottieVue class="w-15rem h-15rem" autoplay loop src="/animIsTracking.json" />
|
||||
@@ -19,27 +16,21 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import BasicIcon from '@/components/BasicPacks/BasicIcon.vue'
|
||||
import { update } from 'lodash'
|
||||
import { ref } from 'vue'
|
||||
import anim from '@/assets/img/anim/anim1.json'
|
||||
import { DotLottieVue } from '@lottiefiles/dotlottie-vue'
|
||||
import { APP_Z_OVERLAY } from '@/utils/zIndex'
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
show?: boolean
|
||||
zIndex?: number
|
||||
}>(),
|
||||
{
|
||||
show: false,
|
||||
zIndex: APP_Z_OVERLAY,
|
||||
},
|
||||
)
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:show': [value: boolean]
|
||||
}>()
|
||||
|
||||
const show = computed({
|
||||
get: () => props.show,
|
||||
set: (value: boolean) => emit('update:show', value),
|
||||
interface Prop {
|
||||
title: string
|
||||
info?: string
|
||||
infoHead?: string
|
||||
isLine?: boolean
|
||||
value?: string | number
|
||||
}
|
||||
const props = withDefaults(defineProps<Prop>(), {
|
||||
isLine: false
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped lang="less"></style>
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
<template>
|
||||
<div v-if="showInstallEntry" class="mt-2 w-full">
|
||||
<BasicButton class="!w-full" @click="onClick">
|
||||
{{ canNativeInstall ? 'نصب اپلیکیشن' : 'آموزش نصب' }}
|
||||
</BasicButton>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onMounted, onUnmounted, ref } from 'vue'
|
||||
import BasicButton from '@/components/BasicPacks/BasicButton.vue'
|
||||
import { usePwaInstall } from '@/composables/usePwaInstall'
|
||||
import { PWA_MANIFEST_READY_EVENT } from '@/modules/pwa/manifest'
|
||||
import {
|
||||
hasNativeInstallPrompt,
|
||||
initPwaInstallPromptListener,
|
||||
} from '@/modules/pwa/pwaInstall'
|
||||
|
||||
const { tryInstallOrOpenGuide, showInstallEntry } = usePwaInstall()
|
||||
const canNativeInstall = ref(false)
|
||||
|
||||
function refreshCanInstall() {
|
||||
canNativeInstall.value = hasNativeInstallPrompt()
|
||||
}
|
||||
|
||||
async function onClick() {
|
||||
await tryInstallOrOpenGuide()
|
||||
refreshCanInstall()
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
initPwaInstallPromptListener()
|
||||
refreshCanInstall()
|
||||
window.addEventListener(PWA_MANIFEST_READY_EVENT, refreshCanInstall)
|
||||
window.addEventListener('appinstalled', refreshCanInstall)
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
window.removeEventListener(PWA_MANIFEST_READY_EVENT, refreshCanInstall)
|
||||
window.removeEventListener('appinstalled', refreshCanInstall)
|
||||
})
|
||||
</script>
|
||||
@@ -1,89 +0,0 @@
|
||||
<template>
|
||||
<div :class="variant === 'desktop' ? desktopRootClass : mobileRootClass">
|
||||
<button
|
||||
ref="triggerEl"
|
||||
type="button"
|
||||
class="support-contact-bar__btn"
|
||||
:disabled="!canContactSupport"
|
||||
@click="onSupportClick"
|
||||
>
|
||||
<BasicIcon icon="vuesax-linear:messages-2" size="20" color="#fff" />
|
||||
<span>ارتباط با پشتیبانی</span>
|
||||
</button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import BasicIcon from '@/components/BasicPacks/BasicIcon.vue'
|
||||
import { useSupportMessenger } from '@/composables/useSupportMessenger'
|
||||
import { computed, ref } from 'vue'
|
||||
|
||||
withDefaults(
|
||||
defineProps<{
|
||||
variant?: 'mobile' | 'desktop'
|
||||
mobileRootClass?: string
|
||||
desktopRootClass?: string
|
||||
}>(),
|
||||
{
|
||||
variant: 'mobile',
|
||||
mobileRootClass: 'wrap-fix bottom-0 px-10 pb-3rem flex bg-white',
|
||||
desktopRootClass: 'dpage-support',
|
||||
},
|
||||
)
|
||||
|
||||
const {
|
||||
supportPhoneLink,
|
||||
hasMessengerLink,
|
||||
hasSupportPhoneLink,
|
||||
openSupportMessenger,
|
||||
} = useSupportMessenger()
|
||||
|
||||
const triggerEl = ref<HTMLElement | null>(null)
|
||||
|
||||
const canContactSupport = computed(() => hasMessengerLink.value || hasSupportPhoneLink.value)
|
||||
|
||||
async function onSupportClick() {
|
||||
// همان رفتار دکمه شناور پشتیبانی — بدون پیشنویس واریز
|
||||
if (hasMessengerLink.value) {
|
||||
await openSupportMessenger(triggerEl.value)
|
||||
return
|
||||
}
|
||||
|
||||
if (hasSupportPhoneLink.value && supportPhoneLink.value) {
|
||||
window.location.href = supportPhoneLink.value
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
.support-contact-bar__btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 0.5rem;
|
||||
width: 100%;
|
||||
min-height: 2.75rem;
|
||||
padding: 0.65rem 1rem;
|
||||
border: 0;
|
||||
border-radius: 0.75rem;
|
||||
background: var(--App-primary, @App-primary-color);
|
||||
color: #fff;
|
||||
font-size: 0.9375rem;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: opacity 0.15s ease, transform 0.15s ease;
|
||||
|
||||
&:active {
|
||||
transform: scale(0.98);
|
||||
}
|
||||
|
||||
&:disabled {
|
||||
opacity: 0.55;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
}
|
||||
|
||||
.dpage-support {
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
@@ -1,72 +0,0 @@
|
||||
<template>
|
||||
<span
|
||||
class="support-brand-icon"
|
||||
:class="{ 'support-brand-icon--eitaa': normalized === 'eitaa' }"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<img
|
||||
v-if="logoSrc"
|
||||
:src="logoSrc"
|
||||
:alt="normalized"
|
||||
class="support-brand-icon__img"
|
||||
draggable="false"
|
||||
/>
|
||||
<svg v-else viewBox="0 0 48 48" xmlns="http://www.w3.org/2000/svg" class="support-brand-icon__svg">
|
||||
<circle cx="24" cy="24" r="24" fill="#64748B" />
|
||||
<path fill="#fff" d="M16 18h16v2H16v-2zm0 5h16v2H16v-2zm0 5h10v2H16v-2z" />
|
||||
</svg>
|
||||
</span>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { computed } from 'vue'
|
||||
import baleLogo from '@/assets/messengers/bale.png'
|
||||
import callLogo from '@/assets/messengers/call.svg'
|
||||
import eitaaLogo from '@/assets/messengers/eitaa.png'
|
||||
import rubikaLogo from '@/assets/messengers/rubika.png'
|
||||
import smsLogo from '@/assets/messengers/sms.svg'
|
||||
import soroushLogo from '@/assets/messengers/soroush.svg'
|
||||
import telegramLogo from '@/assets/messengers/telegram.svg'
|
||||
import whatsappLogo from '@/assets/messengers/whatsapp.svg'
|
||||
|
||||
const LOGOS: Record<string, string> = {
|
||||
bale: baleLogo,
|
||||
telegram: telegramLogo,
|
||||
whatsapp: whatsappLogo,
|
||||
rubika: rubikaLogo,
|
||||
eitaa: eitaaLogo,
|
||||
soroush: soroushLogo,
|
||||
call: callLogo,
|
||||
sms: smsLogo,
|
||||
}
|
||||
|
||||
const props = defineProps<{ messenger: string }>()
|
||||
const normalized = computed(() => (props.messenger ?? '').trim().toLowerCase())
|
||||
const logoSrc = computed(() => LOGOS[normalized.value])
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
.support-brand-icon {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border-radius: 50%;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.support-brand-icon--eitaa {
|
||||
background: #e37600;
|
||||
|
||||
.support-brand-icon__img {
|
||||
filter: brightness(0) invert(1);
|
||||
}
|
||||
}
|
||||
|
||||
.support-brand-icon__img,
|
||||
.support-brand-icon__svg {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
</style>
|
||||
@@ -1,300 +0,0 @@
|
||||
<template>
|
||||
<Teleport to="body">
|
||||
<Transition name="support-picker-backdrop">
|
||||
<div
|
||||
v-if="open"
|
||||
class="support-messenger-picker__backdrop"
|
||||
:class="{ 'is-active': backdropActive }"
|
||||
@click="onBackdropClick"
|
||||
/>
|
||||
</Transition>
|
||||
|
||||
<div
|
||||
v-show="open || closing"
|
||||
class="support-messenger-picker__stack"
|
||||
:class="[
|
||||
{ 'is-open': open },
|
||||
expandUp ? 'support-messenger-picker__stack--up' : 'support-messenger-picker__stack--down',
|
||||
]"
|
||||
:style="stackStyle"
|
||||
role="menu"
|
||||
aria-label="انتخاب پیامرسان"
|
||||
>
|
||||
<button
|
||||
v-for="(entry, index) in entries"
|
||||
:key="`${entry.messenger}-${entry.id}`"
|
||||
type="button"
|
||||
class="support-messenger-picker__btn"
|
||||
:style="{ '--i': index, '--total': entries.length }"
|
||||
:title="entry.label"
|
||||
:aria-label="entry.label"
|
||||
@click.stop="select(entry)"
|
||||
>
|
||||
<SupportMessengerBrandIcon v-if="entry.messenger !== 'chat'" :messenger="entry.messenger" />
|
||||
<BasicIcon
|
||||
v-else
|
||||
:icon="entry.icon || 'vuesax-linear:messages-2'"
|
||||
size="22"
|
||||
:color="entry.accent || '#16a34a'"
|
||||
/>
|
||||
</button>
|
||||
</div>
|
||||
</Teleport>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { nextTick, onBeforeUnmount, ref, watch } from 'vue'
|
||||
import SupportMessengerBrandIcon from '@/components/SupportMessengerBrandIcon.vue'
|
||||
import BasicIcon from '@/components/BasicPacks/BasicIcon.vue'
|
||||
import type { ResolvedSupportMessengerEntry } from '@/utils/supportMessenger'
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
open: boolean
|
||||
entries: ResolvedSupportMessengerEntry[]
|
||||
anchorEl?: HTMLElement | null
|
||||
}>(),
|
||||
{
|
||||
anchorEl: null,
|
||||
},
|
||||
)
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:open': [value: boolean]
|
||||
select: [entry: ResolvedSupportMessengerEntry]
|
||||
}>()
|
||||
|
||||
const BTN_SIZE = 46
|
||||
const GAP = 12
|
||||
const STACK_GAP = 10
|
||||
const CLOSE_MS = 220
|
||||
const BACKDROP_GUARD_MS = 380
|
||||
|
||||
const stackStyle = ref<Record<string, string>>({})
|
||||
const closing = ref(false)
|
||||
const expandUp = ref(true)
|
||||
const backdropActive = ref(false)
|
||||
let closeTimer: ReturnType<typeof setTimeout> | null = null
|
||||
let backdropTimer: ReturnType<typeof setTimeout> | null = null
|
||||
|
||||
function close() {
|
||||
emit('update:open', false)
|
||||
}
|
||||
|
||||
function select(entry: ResolvedSupportMessengerEntry) {
|
||||
emit('select', entry)
|
||||
close()
|
||||
}
|
||||
|
||||
function clearTimers() {
|
||||
if (closeTimer) {
|
||||
clearTimeout(closeTimer)
|
||||
closeTimer = null
|
||||
}
|
||||
if (backdropTimer) {
|
||||
clearTimeout(backdropTimer)
|
||||
backdropTimer = null
|
||||
}
|
||||
}
|
||||
|
||||
function onBackdropClick() {
|
||||
if (!backdropActive.value) return
|
||||
close()
|
||||
}
|
||||
|
||||
function armBackdropGuard() {
|
||||
backdropActive.value = false
|
||||
if (backdropTimer) clearTimeout(backdropTimer)
|
||||
backdropTimer = setTimeout(() => {
|
||||
backdropActive.value = true
|
||||
backdropTimer = null
|
||||
}, BACKDROP_GUARD_MS)
|
||||
}
|
||||
|
||||
async function reposition() {
|
||||
await nextTick()
|
||||
|
||||
const anchor = props.anchorEl
|
||||
const count = props.entries.length
|
||||
if (!anchor || count === 0) {
|
||||
expandUp.value = true
|
||||
stackStyle.value = {
|
||||
top: '50%',
|
||||
left: '50%',
|
||||
transform: 'translate(-50%, -50%)',
|
||||
right: 'auto',
|
||||
bottom: 'auto',
|
||||
'--stack-rise': '56px',
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
const rect = anchor.getBoundingClientRect()
|
||||
const stackHeight = count * BTN_SIZE + Math.max(0, count - 1) * GAP
|
||||
const anchorCenterX = rect.left + rect.width / 2
|
||||
const anchorCenterY = rect.top + rect.height / 2
|
||||
const right = Math.max(12, window.innerWidth - anchorCenterX - BTN_SIZE / 2)
|
||||
|
||||
expandUp.value = anchorCenterY > window.innerHeight / 2
|
||||
|
||||
if (expandUp.value) {
|
||||
const bottom = Math.max(12, window.innerHeight - rect.top + STACK_GAP)
|
||||
stackStyle.value = {
|
||||
right: `${right}px`,
|
||||
bottom: `${bottom}px`,
|
||||
left: 'auto',
|
||||
top: 'auto',
|
||||
transform: 'none',
|
||||
'--stack-rise': `${Math.min(stackHeight + 6, 220)}px`,
|
||||
}
|
||||
} else {
|
||||
const top = Math.max(12, rect.bottom + STACK_GAP)
|
||||
stackStyle.value = {
|
||||
right: `${right}px`,
|
||||
top: `${top}px`,
|
||||
left: 'auto',
|
||||
bottom: 'auto',
|
||||
transform: 'none',
|
||||
'--stack-rise': `${Math.min(stackHeight + 6, 220)}px`,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.open,
|
||||
(isOpen) => {
|
||||
clearTimers()
|
||||
if (isOpen) {
|
||||
closing.value = false
|
||||
armBackdropGuard()
|
||||
void reposition()
|
||||
return
|
||||
}
|
||||
|
||||
backdropActive.value = false
|
||||
closing.value = true
|
||||
const delay = CLOSE_MS + Math.max(0, props.entries.length - 1) * 28
|
||||
closeTimer = setTimeout(() => {
|
||||
closing.value = false
|
||||
closeTimer = null
|
||||
}, delay)
|
||||
},
|
||||
{ flush: 'post' },
|
||||
)
|
||||
|
||||
watch(
|
||||
() => [props.entries.length, props.anchorEl] as const,
|
||||
() => {
|
||||
if (props.open) void reposition()
|
||||
},
|
||||
)
|
||||
|
||||
function onViewportChange() {
|
||||
if (props.open || closing.value) void reposition()
|
||||
}
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
window.addEventListener('resize', onViewportChange, { passive: true })
|
||||
window.addEventListener('scroll', onViewportChange, { passive: true, capture: true })
|
||||
}
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
clearTimers()
|
||||
if (typeof window === 'undefined') return
|
||||
window.removeEventListener('resize', onViewportChange, { capture: true })
|
||||
window.removeEventListener('scroll', onViewportChange, { capture: true })
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
.support-messenger-picker__backdrop {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 5195;
|
||||
background: rgba(15, 23, 42, 0.2);
|
||||
pointer-events: none;
|
||||
|
||||
&.is-active {
|
||||
pointer-events: auto;
|
||||
}
|
||||
}
|
||||
|
||||
.support-messenger-picker__stack {
|
||||
position: fixed;
|
||||
z-index: 5205;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.support-messenger-picker__stack--up {
|
||||
flex-direction: column-reverse;
|
||||
}
|
||||
|
||||
.support-messenger-picker__stack--down {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.support-messenger-picker__btn {
|
||||
--i: 0;
|
||||
--total: 1;
|
||||
--stack-rise: 56px;
|
||||
pointer-events: auto;
|
||||
width: 46px;
|
||||
height: 46px;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
border-radius: 50%;
|
||||
background: transparent;
|
||||
cursor: pointer;
|
||||
box-shadow: 0 6px 16px rgba(15, 23, 42, 0.2);
|
||||
opacity: 0;
|
||||
will-change: transform, opacity;
|
||||
transition:
|
||||
transform 0.22s cubic-bezier(0.2, 1, 0.3, 1),
|
||||
opacity 0.16s ease,
|
||||
box-shadow 0.16s ease;
|
||||
transition-delay: calc(var(--i) * 38ms);
|
||||
}
|
||||
|
||||
.support-messenger-picker__stack--up .support-messenger-picker__btn {
|
||||
transform-origin: center bottom;
|
||||
transform: translateY(calc(var(--stack-rise) * 0.55)) scale(0.2);
|
||||
}
|
||||
|
||||
.support-messenger-picker__stack--down .support-messenger-picker__btn {
|
||||
transform-origin: center top;
|
||||
transform: translateY(calc(var(--stack-rise) * -0.55)) scale(0.2);
|
||||
}
|
||||
|
||||
.support-messenger-picker__stack.is-open .support-messenger-picker__btn {
|
||||
opacity: 1;
|
||||
transform: translateY(0) scale(1);
|
||||
}
|
||||
|
||||
.support-messenger-picker__stack:not(.is-open) .support-messenger-picker__btn {
|
||||
transition-delay: calc((var(--total) - 1 - var(--i)) * 24ms);
|
||||
transition-duration: 0.18s, 0.14s, 0.14s;
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.support-messenger-picker__stack--up:not(.is-open) .support-messenger-picker__btn {
|
||||
transform: translateY(calc(var(--stack-rise) * 0.4)) scale(0.15);
|
||||
}
|
||||
|
||||
.support-messenger-picker__stack--down:not(.is-open) .support-messenger-picker__btn {
|
||||
transform: translateY(calc(var(--stack-rise) * -0.4)) scale(0.15);
|
||||
}
|
||||
|
||||
.support-picker-backdrop-enter-active,
|
||||
.support-picker-backdrop-leave-active {
|
||||
transition: opacity 0.16s ease;
|
||||
}
|
||||
|
||||
.support-picker-backdrop-enter-from,
|
||||
.support-picker-backdrop-leave-to {
|
||||
opacity: 0;
|
||||
}
|
||||
</style>
|
||||
@@ -1,227 +0,0 @@
|
||||
<template>
|
||||
<div class="trade-fee-summary">
|
||||
<div class="trade-fee-summary__quote">
|
||||
<div class="trade-fee-summary__label">مظنه هر {{ weightUnit }}</div>
|
||||
<div class="trade-fee-summary__value trade-fee-summary__value--strong">
|
||||
<span>{{ formattedUnitPrice }}</span>
|
||||
<span class="trade-fee-summary__unit">ریال</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-for="(section, index) in breakdown.sections"
|
||||
:key="section.heading"
|
||||
class="trade-fee-summary__section"
|
||||
:class="{ 'trade-fee-summary__section--divided': index > 0 }"
|
||||
>
|
||||
<div class="trade-fee-summary__heading">{{ section.heading }}</div>
|
||||
|
||||
<div
|
||||
v-for="(row, rowIndex) in section.rows"
|
||||
:key="`${section.heading}-${rowIndex}`"
|
||||
class="trade-fee-summary__row"
|
||||
:class="{
|
||||
'trade-fee-summary__row--divider': row.dividerBefore,
|
||||
'trade-fee-summary__row--bold': row.bold,
|
||||
}"
|
||||
>
|
||||
<div
|
||||
class="trade-fee-summary__label"
|
||||
:class="{ 'trade-fee-summary__label--strong': row.bold }"
|
||||
>
|
||||
<span v-if="row.plus" class="trade-fee-summary__sign trade-fee-summary__sign--plus">+</span>
|
||||
<span v-else-if="row.minus && !row.bold" class="trade-fee-summary__sign trade-fee-summary__sign--minus">−</span>
|
||||
{{ row.label }}
|
||||
</div>
|
||||
<div
|
||||
class="trade-fee-summary__value"
|
||||
:class="{
|
||||
'trade-fee-summary__value--minus': row.minus && !row.bold,
|
||||
'trade-fee-summary__value--plus': row.plus,
|
||||
'trade-fee-summary__value--strong': row.bold,
|
||||
}"
|
||||
>
|
||||
<template v-if="row.gram != null">
|
||||
<span>{{ formatTradeGramDisplay(row.gram) }}</span>
|
||||
<span class="trade-fee-summary__unit">{{ weightUnit }}</span>
|
||||
</template>
|
||||
<template v-else-if="row.rial != null">
|
||||
<span v-if="row.minus && row.bold">−</span>
|
||||
<span>{{ formatRial(row.rial) }}</span>
|
||||
<span class="trade-fee-summary__unit">ریال</span>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="section.footnote" class="trade-fee-summary__footnote">
|
||||
{{ section.footnote }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { computed } from 'vue'
|
||||
import { usePriceWithoutType } from '@/utils/usePrice'
|
||||
import {
|
||||
buildTradeConfirmBreakdown,
|
||||
formatTradeGramDisplay,
|
||||
type TradeInputLock,
|
||||
} from '@/utils/serviceFee'
|
||||
|
||||
const props = defineProps<{
|
||||
isBuy: boolean
|
||||
inputLock: TradeInputLock
|
||||
displayTradeGoldAmount: number | string
|
||||
weightUnit: string
|
||||
unitPriceRial: number
|
||||
feeInGrams: number
|
||||
equivalentPrice: string
|
||||
payablePrice: number
|
||||
orderGoldAmount: number
|
||||
feeInRial: number
|
||||
sellGoldDebit?: number
|
||||
}>()
|
||||
|
||||
const formattedUnitPrice = computed(() =>
|
||||
usePriceWithoutType(Math.round(props.unitPriceRial)),
|
||||
)
|
||||
|
||||
function formatRial(value: number) {
|
||||
return usePriceWithoutType(Math.round(value))
|
||||
}
|
||||
|
||||
const breakdown = computed(() =>
|
||||
buildTradeConfirmBreakdown({
|
||||
isBuy: props.isBuy,
|
||||
inputLock: props.inputLock,
|
||||
orderGoldAmount: props.orderGoldAmount,
|
||||
feeInGrams: props.feeInGrams,
|
||||
feeInRial: props.feeInRial,
|
||||
payablePrice: props.payablePrice,
|
||||
unitPriceRial: props.unitPriceRial,
|
||||
sellGoldDebit: props.sellGoldDebit,
|
||||
}),
|
||||
)
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
.trade-fee-summary {
|
||||
width: 100%;
|
||||
padding: 0.75rem;
|
||||
border-radius: 0.75rem;
|
||||
background: var(--app-surface-inset, var(--app-surface));
|
||||
border: 1px solid var(--app-border);
|
||||
}
|
||||
|
||||
.trade-fee-summary__quote {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 0.75rem;
|
||||
padding-bottom: 0.75rem;
|
||||
border-bottom: 1px solid var(--app-border);
|
||||
}
|
||||
|
||||
.trade-fee-summary__section {
|
||||
margin-top: 0.75rem;
|
||||
|
||||
&--divided {
|
||||
padding-top: 0.75rem;
|
||||
border-top: 1px solid var(--app-border);
|
||||
}
|
||||
}
|
||||
|
||||
.trade-fee-summary__heading {
|
||||
margin-bottom: 0.5rem;
|
||||
font-size: 0.8125rem;
|
||||
font-weight: 700;
|
||||
color: var(--app-text-primary);
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.trade-fee-summary__row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 0.75rem;
|
||||
padding: 0.25rem 0;
|
||||
|
||||
&--divider {
|
||||
margin-top: 0.25rem;
|
||||
padding-top: 0.5rem;
|
||||
border-top: 1px dashed var(--app-border);
|
||||
}
|
||||
|
||||
&--bold {
|
||||
font-size: 0.9375rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
}
|
||||
|
||||
.trade-fee-summary__label {
|
||||
font-size: 0.8125rem;
|
||||
font-weight: 500;
|
||||
color: var(--app-text-secondary);
|
||||
text-align: right;
|
||||
|
||||
&--strong {
|
||||
font-weight: 700;
|
||||
color: var(--app-text-primary);
|
||||
}
|
||||
}
|
||||
|
||||
.trade-fee-summary__value {
|
||||
display: inline-flex;
|
||||
align-items: baseline;
|
||||
gap: 0.25rem;
|
||||
font-size: 0.8125rem;
|
||||
font-weight: 600;
|
||||
color: var(--app-text-primary);
|
||||
text-align: left;
|
||||
direction: ltr;
|
||||
|
||||
&--strong {
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
&--minus {
|
||||
color: var(--app-down, #ef4444);
|
||||
}
|
||||
|
||||
&--plus {
|
||||
color: var(--app-up, #22c55e);
|
||||
}
|
||||
}
|
||||
|
||||
.trade-fee-summary__unit {
|
||||
font-size: 0.6875rem;
|
||||
font-weight: 500;
|
||||
color: var(--app-text-muted);
|
||||
}
|
||||
|
||||
.trade-fee-summary__sign {
|
||||
margin-left: 0.25rem;
|
||||
|
||||
&--plus {
|
||||
color: var(--app-up, #22c55e);
|
||||
}
|
||||
|
||||
&--minus {
|
||||
color: var(--app-down, #ef4444);
|
||||
}
|
||||
}
|
||||
|
||||
.trade-fee-summary__footnote {
|
||||
margin-top: 0.5rem;
|
||||
padding: 0.5rem 0.625rem;
|
||||
border-radius: 0.625rem;
|
||||
background: var(--app-surface, rgba(255, 255, 255, 0.04));
|
||||
border: 1px solid var(--app-border);
|
||||
font-size: 0.75rem;
|
||||
font-weight: 500;
|
||||
line-height: 1.7;
|
||||
color: var(--app-text-secondary);
|
||||
text-align: right;
|
||||
}
|
||||
</style>
|
||||
@@ -1,375 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import BasicButton from '@/components/BasicPacks/BasicButton.vue'
|
||||
import {
|
||||
PWA_GUIDE_STEP_LABELS,
|
||||
PWA_INSTALL_GUIDE,
|
||||
type PwaPlatform,
|
||||
} from '@/modules/pwa/pwaInstallGuideSteps'
|
||||
import { getDefaultPwaPlatform } from '@/modules/pwa/pwaInstall'
|
||||
import PwaInstallStepIllustration from '@/components/pwa/PwaInstallStepIllustration.vue'
|
||||
|
||||
const props = defineProps<{
|
||||
open: boolean
|
||||
platform?: PwaPlatform
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:open': [value: boolean]
|
||||
complete: []
|
||||
close: []
|
||||
}>()
|
||||
|
||||
const activePlatform = ref<PwaPlatform>(props.platform ?? getDefaultPwaPlatform())
|
||||
const stepIndex = ref(0)
|
||||
|
||||
const guide = computed(() => PWA_INSTALL_GUIDE[activePlatform.value])
|
||||
const currentStep = computed(() => guide.value.steps[stepIndex.value])
|
||||
const totalSteps = computed(() => guide.value.steps.length)
|
||||
const isFirstStep = computed(() => stepIndex.value === 0)
|
||||
const isLastStep = computed(() => stepIndex.value === totalSteps.value - 1)
|
||||
const stepLabel = computed(() => PWA_GUIDE_STEP_LABELS[stepIndex.value] ?? String(stepIndex.value + 1))
|
||||
|
||||
watch(
|
||||
() => props.open,
|
||||
(visible) => {
|
||||
if (!visible) return
|
||||
activePlatform.value = props.platform ?? getDefaultPwaPlatform()
|
||||
stepIndex.value = 0
|
||||
},
|
||||
)
|
||||
|
||||
watch(
|
||||
() => props.platform,
|
||||
(value) => {
|
||||
if (value) activePlatform.value = value
|
||||
},
|
||||
)
|
||||
|
||||
function close() {
|
||||
emit('update:open', false)
|
||||
emit('close')
|
||||
}
|
||||
|
||||
function selectPlatform(next: PwaPlatform) {
|
||||
if (activePlatform.value === next) return
|
||||
activePlatform.value = next
|
||||
stepIndex.value = 0
|
||||
}
|
||||
|
||||
function goNext() {
|
||||
if (isLastStep.value) {
|
||||
emit('complete')
|
||||
close()
|
||||
return
|
||||
}
|
||||
|
||||
stepIndex.value += 1
|
||||
}
|
||||
|
||||
function goPrev() {
|
||||
if (isFirstStep.value) return
|
||||
stepIndex.value -= 1
|
||||
}
|
||||
|
||||
function completeGuide() {
|
||||
emit('complete')
|
||||
close()
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Teleport to="body">
|
||||
<div
|
||||
v-if="open"
|
||||
class="pwa-install-guide"
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-labelledby="pwa-install-guide-title"
|
||||
@click.self="close"
|
||||
>
|
||||
<div class="pwa-install-guide__card">
|
||||
<div class="pwa-install-guide__tabs">
|
||||
<button
|
||||
type="button"
|
||||
class="pwa-install-guide__tab"
|
||||
:class="{ 'pwa-install-guide__tab--active': activePlatform === 'ios' }"
|
||||
@click="selectPlatform('ios')"
|
||||
>
|
||||
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" aria-hidden="true">
|
||||
<rect x="7" y="2" width="10" height="20" rx="2.5" stroke="currentColor" stroke-width="1.5" />
|
||||
<circle cx="12" cy="18.5" r="1" fill="currentColor" />
|
||||
</svg>
|
||||
<span>آیفون</span>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="pwa-install-guide__tab"
|
||||
:class="{ 'pwa-install-guide__tab--active': activePlatform === 'android' }"
|
||||
@click="selectPlatform('android')"
|
||||
>
|
||||
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" aria-hidden="true">
|
||||
<path d="M12 4v12" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" />
|
||||
<path d="M8.5 8.5 12 5l3.5 3.5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" />
|
||||
<path d="M6 16h12v3a1 1 0 0 1-1 1H7a1 1 0 0 1-1-1v-3Z" stroke="currentColor" stroke-width="1.5" />
|
||||
</svg>
|
||||
<span>اندروید</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="pwa-install-guide__header">
|
||||
<span class="pwa-install-guide__progress">
|
||||
مرحله {{ stepLabel }} از {{ PWA_GUIDE_STEP_LABELS.length }}
|
||||
</span>
|
||||
<h2 id="pwa-install-guide-title" class="pwa-install-guide__title">
|
||||
{{ guide.title }}
|
||||
</h2>
|
||||
</div>
|
||||
|
||||
<div class="pwa-install-guide__content">
|
||||
<span class="pwa-install-guide__badge">{{ stepLabel }}</span>
|
||||
|
||||
<PwaInstallStepIllustration :type="currentStep.illustration" />
|
||||
|
||||
<p class="pwa-install-guide__text">{{ currentStep.text }}</p>
|
||||
<p v-if="currentStep.hint" class="pwa-install-guide__hint">{{ currentStep.hint }}</p>
|
||||
</div>
|
||||
|
||||
<div class="pwa-install-guide__nav">
|
||||
<template v-if="isLastStep">
|
||||
<BasicButton class="pwa-install-guide__primary" type="primary" @click="completeGuide">
|
||||
متوجه شدم
|
||||
</BasicButton>
|
||||
</template>
|
||||
<template v-else>
|
||||
<button
|
||||
type="button"
|
||||
class="pwa-install-guide__nav-btn"
|
||||
:disabled="isFirstStep"
|
||||
aria-label="مرحله قبل"
|
||||
@click="goPrev"
|
||||
>
|
||||
‹
|
||||
</button>
|
||||
|
||||
<div class="pwa-install-guide__dots" aria-hidden="true">
|
||||
<span
|
||||
v-for="(_, index) in totalSteps"
|
||||
:key="index"
|
||||
class="pwa-install-guide__dot"
|
||||
:class="{ 'pwa-install-guide__dot--active': index === stepIndex }"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
class="pwa-install-guide__nav-btn"
|
||||
aria-label="مرحله بعد"
|
||||
@click="goNext"
|
||||
>
|
||||
›
|
||||
</button>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<template v-if="!isLastStep">
|
||||
<BasicButton class="pwa-install-guide__primary" type="primary" @click="goNext">
|
||||
بعدی
|
||||
<span class="pwa-install-guide__primary-chevron">›</span>
|
||||
</BasicButton>
|
||||
|
||||
<button type="button" class="pwa-install-guide__close" @click="close">
|
||||
بستن
|
||||
</button>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
</Teleport>
|
||||
</template>
|
||||
|
||||
<style scoped lang="less">
|
||||
.pwa-install-guide {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: var(--app-z-modal, 5500);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 16px;
|
||||
background: rgba(15, 23, 42, 0.45);
|
||||
}
|
||||
|
||||
.pwa-install-guide__card {
|
||||
width: min(100%, 360px);
|
||||
background: #fff;
|
||||
border-radius: 24px;
|
||||
padding: 14px 16px 18px;
|
||||
box-shadow: 0 24px 48px rgba(15, 23, 42, 0.18);
|
||||
}
|
||||
|
||||
.pwa-install-guide__tabs {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 4px;
|
||||
padding: 4px;
|
||||
border-radius: 14px;
|
||||
background: #f1f5f9;
|
||||
}
|
||||
|
||||
.pwa-install-guide__tab {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 6px;
|
||||
border: none;
|
||||
border-radius: 10px;
|
||||
padding: 10px 8px;
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
color: #64748b;
|
||||
background: transparent;
|
||||
cursor: pointer;
|
||||
transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
|
||||
|
||||
&--active {
|
||||
color: #0f172a;
|
||||
background: #fff;
|
||||
box-shadow: 0 2px 8px rgba(15, 23, 42, 0.08);
|
||||
}
|
||||
}
|
||||
|
||||
.pwa-install-guide__header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
margin: 14px 2px 10px;
|
||||
}
|
||||
|
||||
.pwa-install-guide__progress {
|
||||
font-size: 12px;
|
||||
color: #94a3b8;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.pwa-install-guide__title {
|
||||
margin: 0;
|
||||
font-size: 14px;
|
||||
font-weight: 700;
|
||||
color: #0f172a;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.pwa-install-guide__content {
|
||||
position: relative;
|
||||
border: 1px solid #e2e8f0;
|
||||
border-radius: 18px;
|
||||
background: #f8fafc;
|
||||
padding: 14px 14px 16px;
|
||||
min-height: 280px;
|
||||
}
|
||||
|
||||
.pwa-install-guide__badge {
|
||||
position: absolute;
|
||||
top: 12px;
|
||||
right: 12px;
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
border-radius: 999px;
|
||||
background: #2563eb;
|
||||
color: #fff;
|
||||
font-size: 13px;
|
||||
font-weight: 700;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.pwa-install-guide__text {
|
||||
margin: 10px 0 0;
|
||||
font-size: 13px;
|
||||
line-height: 1.8;
|
||||
color: #334155;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.pwa-install-guide__hint {
|
||||
margin: 8px 0 0;
|
||||
font-size: 11px;
|
||||
line-height: 1.7;
|
||||
color: #64748b;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.pwa-install-guide__nav {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 12px;
|
||||
margin: 14px 0 12px;
|
||||
|
||||
.pwa-install-guide__primary {
|
||||
width: 100%;
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.pwa-install-guide__nav-btn {
|
||||
width: 34px;
|
||||
height: 34px;
|
||||
border: 1px solid #e2e8f0;
|
||||
border-radius: 10px;
|
||||
background: #fff;
|
||||
color: #334155;
|
||||
font-size: 20px;
|
||||
line-height: 1;
|
||||
cursor: pointer;
|
||||
|
||||
&:disabled {
|
||||
opacity: 0.35;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
}
|
||||
|
||||
.pwa-install-guide__dots {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.pwa-install-guide__dot {
|
||||
width: 7px;
|
||||
height: 7px;
|
||||
border-radius: 999px;
|
||||
background: #cbd5e1;
|
||||
transition: width 0.15s ease, background 0.15s ease;
|
||||
|
||||
&--active {
|
||||
width: 22px;
|
||||
background: #2563eb;
|
||||
}
|
||||
}
|
||||
|
||||
.pwa-install-guide__primary {
|
||||
width: 100%;
|
||||
height: 44px;
|
||||
border-radius: 14px !important;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.pwa-install-guide__primary-chevron {
|
||||
margin-right: 4px;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.pwa-install-guide__close {
|
||||
display: block;
|
||||
width: 100%;
|
||||
margin-top: 10px;
|
||||
border: none;
|
||||
background: transparent;
|
||||
color: #64748b;
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
}
|
||||
</style>
|
||||
@@ -1,413 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import type { PwaGuideIllustration } from '@/modules/pwa/pwaInstallGuideSteps'
|
||||
import shareAppleIcon from '@/assets/img/share-apple.png'
|
||||
import addToHomeScreenIcon from '@/assets/img/Add-to-homeScreen.png'
|
||||
|
||||
defineProps<{
|
||||
type: PwaGuideIllustration
|
||||
}>()
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
class="pwa-step-illustration"
|
||||
:class="{
|
||||
'pwa-step-illustration--android-menu': type === 'android-menu',
|
||||
'pwa-step-illustration--ios-safari': type === 'ios-safari',
|
||||
}"
|
||||
>
|
||||
<div
|
||||
class="pwa-step-illustration__phone"
|
||||
:class="{
|
||||
'pwa-step-illustration__phone--android-menu': type === 'android-menu',
|
||||
'pwa-step-illustration__phone--ios-safari': type === 'ios-safari',
|
||||
}"
|
||||
>
|
||||
<div
|
||||
class="pwa-step-illustration__screen"
|
||||
:class="{
|
||||
'pwa-step-illustration__screen--android-menu': type === 'android-menu',
|
||||
'pwa-step-illustration__screen--ios-safari': type === 'ios-safari',
|
||||
}"
|
||||
>
|
||||
<template v-if="type === 'android-chrome'">
|
||||
<div class="pwa-step-illustration__browser-bar">
|
||||
<span class="pwa-step-illustration__dot pwa-step-illustration__dot--red" />
|
||||
<span class="pwa-step-illustration__dot pwa-step-illustration__dot--yellow" />
|
||||
<span class="pwa-step-illustration__dot pwa-step-illustration__dot--green" />
|
||||
</div>
|
||||
<div class="pwa-step-illustration__chrome-body" />
|
||||
<div class="pwa-step-illustration__chrome-label">باز در Chrome</div>
|
||||
</template>
|
||||
|
||||
<template v-else-if="type === 'android-menu'">
|
||||
<div class="android-menu-scene">
|
||||
<div class="android-menu-scene__toolbar">
|
||||
<div class="android-menu-scene__url-bar" />
|
||||
<div class="android-menu-scene__menu-target" aria-hidden="true">
|
||||
<span class="android-menu-scene__menu-dots">⋮</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="android-menu-scene__viewport">
|
||||
<div class="android-menu-scene__dropdown">
|
||||
<div class="android-menu-scene__dropdown-line" />
|
||||
<div class="android-menu-scene__dropdown-line android-menu-scene__dropdown-line--short" />
|
||||
<div class="android-menu-scene__dropdown-install">
|
||||
Install app
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template v-else-if="type === 'android-install'">
|
||||
<div class="pwa-step-illustration__install-btn">Install</div>
|
||||
</template>
|
||||
|
||||
<template v-else-if="type === 'android-confirm'">
|
||||
<div class="pwa-step-illustration__app-icon" />
|
||||
<div class="pwa-step-illustration__home-label">روی صفحه اصلی</div>
|
||||
</template>
|
||||
|
||||
<template v-else-if="type === 'ios-safari'">
|
||||
<div class="ios-safari-scene">
|
||||
<div class="ios-safari-scene__toolbar">
|
||||
<span class="ios-safari-scene__toolbar-label">Safari</span>
|
||||
</div>
|
||||
|
||||
<div class="ios-safari-scene__viewport">
|
||||
<div class="ios-safari-scene__placeholder" />
|
||||
</div>
|
||||
|
||||
<div class="ios-safari-scene__caption">باز در Safari</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template v-else-if="type === 'ios-share'">
|
||||
<div class="pwa-step-illustration__share-wrap">
|
||||
<img :src="shareAppleIcon" alt="" class="pwa-step-illustration__share-icon" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template v-else-if="type === 'ios-add-home'">
|
||||
<div class="pwa-step-illustration__sheet">
|
||||
<div class="pwa-step-illustration__sheet-item">Share</div>
|
||||
<div class="pwa-step-illustration__sheet-item pwa-step-illustration__sheet-item--active">
|
||||
<img :src="addToHomeScreenIcon" alt="" class="pwa-step-illustration__sheet-icon" />
|
||||
Add to Home Screen
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template v-else-if="type === 'ios-confirm'">
|
||||
<div class="pwa-step-illustration__app-icon" />
|
||||
<div class="pwa-step-illustration__home-label">روی صفحه اصلی</div>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped lang="less">
|
||||
.pwa-step-illustration {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
padding: 8px 0 4px;
|
||||
}
|
||||
|
||||
.pwa-step-illustration__phone {
|
||||
width: 148px;
|
||||
height: 220px;
|
||||
border: 2px solid #cbd5e1;
|
||||
border-radius: 22px;
|
||||
padding: 10px 8px;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.pwa-step-illustration__screen {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border: 1px solid #e2e8f0;
|
||||
border-radius: 14px;
|
||||
background: #f8fafc;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.pwa-step-illustration__browser-bar {
|
||||
position: absolute;
|
||||
top: 10px;
|
||||
left: 12px;
|
||||
display: flex;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.pwa-step-illustration__dot {
|
||||
width: 7px;
|
||||
height: 7px;
|
||||
border-radius: 999px;
|
||||
|
||||
&--red { background: #ef4444; }
|
||||
&--yellow { background: #f59e0b; }
|
||||
&--green { background: #22c55e; }
|
||||
}
|
||||
|
||||
.pwa-step-illustration__chrome-body {
|
||||
width: 78%;
|
||||
height: 42%;
|
||||
border-radius: 8px;
|
||||
background: linear-gradient(180deg, #dbeafe 0%, #bfdbfe 100%);
|
||||
margin-top: 18px;
|
||||
}
|
||||
|
||||
.pwa-step-illustration__chrome-label,
|
||||
.pwa-step-illustration__home-label {
|
||||
font-size: 10px;
|
||||
color: #64748b;
|
||||
}
|
||||
|
||||
.pwa-step-illustration--android-menu,
|
||||
.pwa-step-illustration--ios-safari {
|
||||
padding: 12px 0 0;
|
||||
}
|
||||
|
||||
.pwa-step-illustration__phone--android-menu,
|
||||
.pwa-step-illustration__phone--ios-safari {
|
||||
width: 132px;
|
||||
height: 208px;
|
||||
padding: 0;
|
||||
border-width: 1.5px;
|
||||
border-color: #cbd5e1;
|
||||
border-radius: 20px;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.pwa-step-illustration__screen--android-menu,
|
||||
.pwa-step-illustration__screen--ios-safari {
|
||||
border: none;
|
||||
border-radius: 18px;
|
||||
background: #fff;
|
||||
display: block;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.ios-safari-scene {
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.ios-safari-scene__toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 28px;
|
||||
padding: 8px 10px 6px;
|
||||
border-bottom: 1px solid #eef2f7;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.ios-safari-scene__toolbar-label {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-width: 72px;
|
||||
padding: 4px 10px;
|
||||
border-radius: 999px;
|
||||
background: #eef2f7;
|
||||
color: #64748b;
|
||||
font-size: 9px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.ios-safari-scene__viewport {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 14px 12px 8px;
|
||||
background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
|
||||
}
|
||||
|
||||
.ios-safari-scene__placeholder {
|
||||
width: 78%;
|
||||
height: 58%;
|
||||
border-radius: 12px;
|
||||
background: linear-gradient(180deg, #dbeafe 0%, #bfdbfe 100%);
|
||||
box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.08);
|
||||
}
|
||||
|
||||
.ios-safari-scene__caption {
|
||||
padding: 0 10px 10px;
|
||||
text-align: center;
|
||||
font-size: 9px;
|
||||
color: #64748b;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.android-menu-scene {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.android-menu-scene__toolbar {
|
||||
position: relative;
|
||||
z-index: 2;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 6px;
|
||||
padding: 10px 8px 8px;
|
||||
border-bottom: 1px solid #eef2f7;
|
||||
}
|
||||
|
||||
.android-menu-scene__url-bar {
|
||||
flex: 1;
|
||||
height: 8px;
|
||||
border-radius: 999px;
|
||||
background: #e8edf5;
|
||||
}
|
||||
|
||||
.android-menu-scene__menu-target {
|
||||
flex: 0 0 auto;
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
border: 1.5px dashed #2563eb;
|
||||
border-radius: 999px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: rgba(37, 99, 235, 0.04);
|
||||
}
|
||||
|
||||
.android-menu-scene__menu-dots {
|
||||
font-size: 14px;
|
||||
line-height: 1;
|
||||
font-weight: 700;
|
||||
color: #334155;
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
.android-menu-scene__viewport {
|
||||
position: relative;
|
||||
height: calc(100% - 41px);
|
||||
background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
|
||||
}
|
||||
|
||||
.android-menu-scene__dropdown {
|
||||
position: absolute;
|
||||
top: 6px;
|
||||
right: 8px;
|
||||
width: 78px;
|
||||
padding: 8px 8px 10px;
|
||||
border-radius: 10px;
|
||||
background: #fff;
|
||||
border: 1px solid #e2e8f0;
|
||||
box-shadow: 0 8px 20px rgba(15, 23, 42, 0.12);
|
||||
}
|
||||
|
||||
.android-menu-scene__dropdown-line {
|
||||
height: 4px;
|
||||
border-radius: 999px;
|
||||
background: #e2e8f0;
|
||||
margin-bottom: 6px;
|
||||
|
||||
&--short {
|
||||
width: 72%;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
}
|
||||
|
||||
.android-menu-scene__dropdown-install {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 22px;
|
||||
padding: 4px 6px;
|
||||
border-radius: 6px;
|
||||
background: #eff6ff;
|
||||
border: 1px solid #bfdbfe;
|
||||
color: #2563eb;
|
||||
font-size: 8px;
|
||||
font-weight: 700;
|
||||
line-height: 1.2;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.pwa-step-illustration__install-btn {
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
color: #2563eb;
|
||||
border: 1px solid #2563eb;
|
||||
border-radius: 8px;
|
||||
padding: 6px 14px;
|
||||
background: #eff6ff;
|
||||
}
|
||||
|
||||
.pwa-step-illustration__app-icon {
|
||||
width: 42px;
|
||||
height: 42px;
|
||||
border-radius: 12px;
|
||||
background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
|
||||
}
|
||||
|
||||
.pwa-step-illustration__share-wrap {
|
||||
position: absolute;
|
||||
bottom: 14px;
|
||||
width: 34px;
|
||||
height: 34px;
|
||||
border: 2px dashed #2563eb;
|
||||
border-radius: 999px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.pwa-step-illustration__share-icon {
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
object-fit: contain;
|
||||
}
|
||||
|
||||
.pwa-step-illustration__sheet {
|
||||
width: 88%;
|
||||
border-radius: 10px;
|
||||
background: #fff;
|
||||
border: 1px solid #e2e8f0;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.pwa-step-illustration__sheet-item {
|
||||
padding: 8px 10px;
|
||||
font-size: 9px;
|
||||
color: #64748b;
|
||||
border-bottom: 1px solid #f1f5f9;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
|
||||
&--active {
|
||||
color: #2563eb;
|
||||
border: 1px solid #2563eb;
|
||||
border-radius: 8px;
|
||||
margin: 6px;
|
||||
font-weight: 600;
|
||||
}
|
||||
}
|
||||
|
||||
.pwa-step-illustration__sheet-icon {
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
object-fit: contain;
|
||||
}
|
||||
</style>
|
||||
@@ -1,220 +0,0 @@
|
||||
import { computed, onMounted, onUnmounted, ref, watch } from 'vue'
|
||||
import { notification } from 'ant-design-vue'
|
||||
import { getAppNotificationsUnreadCount } from '@/api/appNotifications'
|
||||
import { useSettingsStore } from '@/store/settingsStore'
|
||||
import { getToken } from '@/utils'
|
||||
import { showBrowserNotification } from '@/utils/browserNotification'
|
||||
import { priceSocketConnected, priceWssEnabled } from '@/utils/priceSocketState'
|
||||
import { APP_Z_TOAST } from '@/utils/zIndex'
|
||||
|
||||
const unreadCount = ref(0)
|
||||
let started = false
|
||||
let lastStreamNotifId = 0
|
||||
let hydratedUnread = false
|
||||
let lastShownNotifId = 0
|
||||
let toastConfigured = false
|
||||
let hydrateFallbackTimer: ReturnType<typeof setTimeout> | null = null
|
||||
|
||||
function ensureNotifToastConfig() {
|
||||
if (toastConfigured) return
|
||||
toastConfigured = true
|
||||
notification.config({
|
||||
placement: 'topRight',
|
||||
top: 'calc(var(--app-home-header-offset, 4.25rem) + 0.5rem)',
|
||||
duration: 5,
|
||||
})
|
||||
}
|
||||
|
||||
function notificationsEnabled(): boolean {
|
||||
return Boolean(getToken()) && useSettingsStore().isSettingTruthy('has_page_notification')
|
||||
}
|
||||
|
||||
function clearHydrateFallback() {
|
||||
if (hydrateFallbackTimer) {
|
||||
clearTimeout(hydrateFallbackTimer)
|
||||
hydrateFallbackTimer = null
|
||||
}
|
||||
}
|
||||
|
||||
/** از SSE رویداد unread-count — بدون HTTP */
|
||||
function applyUnreadCountFromStream(payload: Record<string, unknown>) {
|
||||
if (!notificationsEnabled()) {
|
||||
unreadCount.value = 0
|
||||
hydratedUnread = false
|
||||
return
|
||||
}
|
||||
|
||||
const next = Number(payload.unread_count ?? 0) || 0
|
||||
unreadCount.value = Math.max(0, next)
|
||||
hydratedUnread = true
|
||||
clearHydrateFallback()
|
||||
}
|
||||
|
||||
/** فقط وقتی SSE در دسترس نیست یا برای ریفرش دستی صفحه اعلانها */
|
||||
async function refreshUnreadCount() {
|
||||
if (!notificationsEnabled()) {
|
||||
unreadCount.value = 0
|
||||
hydratedUnread = false
|
||||
return
|
||||
}
|
||||
try {
|
||||
const data = await getAppNotificationsUnreadCount()
|
||||
unreadCount.value = Number(data?.unread_count ?? 0) || 0
|
||||
hydratedUnread = true
|
||||
} catch {
|
||||
// silent — badge optional
|
||||
}
|
||||
}
|
||||
|
||||
function clearUnreadLocally() {
|
||||
unreadCount.value = 0
|
||||
}
|
||||
|
||||
function showInAppToast(title: string, body: string) {
|
||||
try {
|
||||
ensureNotifToastConfig()
|
||||
notification.open({
|
||||
message: title || 'اعلان جدید',
|
||||
description: body || undefined,
|
||||
placement: 'topRight',
|
||||
duration: 5,
|
||||
class: 'app-notif-toast',
|
||||
style: { zIndex: APP_Z_TOAST },
|
||||
onClick: () => {
|
||||
void import('@/router').then((mod) => {
|
||||
mod.default.push({ name: 'appNotifications' }).catch(() => undefined)
|
||||
})
|
||||
},
|
||||
})
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
async function presentNotification(payload: {
|
||||
id?: number
|
||||
title?: string
|
||||
body?: string
|
||||
}) {
|
||||
const id = Number(payload.id ?? 0)
|
||||
if (id > 0 && id === lastShownNotifId) {
|
||||
return
|
||||
}
|
||||
if (id > 0) {
|
||||
lastShownNotifId = id
|
||||
}
|
||||
|
||||
const title = String(payload.title ?? '').trim() || 'اعلان جدید'
|
||||
const body = String(payload.body ?? '').trim()
|
||||
|
||||
showInAppToast(title, body)
|
||||
await showBrowserNotification({
|
||||
title,
|
||||
body,
|
||||
tag: id > 0 ? `app-notification-${id}` : undefined,
|
||||
url: '/appNotifications',
|
||||
})
|
||||
}
|
||||
|
||||
/** از SSE رویداد app_notification — بدون polling HTTP */
|
||||
function bumpUnreadFromStream(payload: Record<string, unknown>) {
|
||||
if (!notificationsEnabled()) {
|
||||
return
|
||||
}
|
||||
|
||||
const id = Number(payload.id ?? 0)
|
||||
if (id > 0 && id === lastStreamNotifId) {
|
||||
return
|
||||
}
|
||||
if (id > 0) {
|
||||
lastStreamNotifId = id
|
||||
}
|
||||
|
||||
if (payload.unread_count !== undefined && payload.unread_count !== null) {
|
||||
applyUnreadCountFromStream(payload)
|
||||
} else {
|
||||
unreadCount.value = Math.max(0, unreadCount.value) + 1
|
||||
hydratedUnread = true
|
||||
clearHydrateFallback()
|
||||
}
|
||||
|
||||
void presentNotification({
|
||||
id,
|
||||
title: String(payload.title ?? ''),
|
||||
body: String(payload.body ?? ''),
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* بدون interval: اگر استریم قیمت روشن است منتظر رویداد SSE میمانیم؛
|
||||
* فقط وقتی wss خاموش است یا SSE تا ۱۲ثانیه نیامد، یکبار HTTP میزنیم.
|
||||
*/
|
||||
function scheduleHydrate() {
|
||||
if (!notificationsEnabled()) {
|
||||
unreadCount.value = 0
|
||||
hydratedUnread = false
|
||||
clearHydrateFallback()
|
||||
return
|
||||
}
|
||||
|
||||
if (!priceWssEnabled.value) {
|
||||
void refreshUnreadCount()
|
||||
return
|
||||
}
|
||||
|
||||
if (priceSocketConnected.value || hydratedUnread) {
|
||||
clearHydrateFallback()
|
||||
return
|
||||
}
|
||||
|
||||
clearHydrateFallback()
|
||||
hydrateFallbackTimer = setTimeout(() => {
|
||||
hydrateFallbackTimer = null
|
||||
if (!hydratedUnread && notificationsEnabled() && !priceSocketConnected.value) {
|
||||
void refreshUnreadCount()
|
||||
}
|
||||
}, 12000)
|
||||
}
|
||||
|
||||
export function useAppNotificationBadge() {
|
||||
const settingsStore = useSettingsStore()
|
||||
const enabled = computed(() => settingsStore.isSettingTruthy('has_page_notification'))
|
||||
|
||||
onMounted(() => {
|
||||
started = true
|
||||
scheduleHydrate()
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
// module-level badge — keep state for other headers
|
||||
})
|
||||
|
||||
watch(enabled, (on) => {
|
||||
if (!on) {
|
||||
unreadCount.value = 0
|
||||
hydratedUnread = false
|
||||
clearHydrateFallback()
|
||||
} else {
|
||||
scheduleHydrate()
|
||||
}
|
||||
})
|
||||
|
||||
watch([priceSocketConnected, priceWssEnabled], () => {
|
||||
if (!started) return
|
||||
scheduleHydrate()
|
||||
})
|
||||
|
||||
return {
|
||||
enabled,
|
||||
unreadCount,
|
||||
refreshUnreadCount,
|
||||
clearUnreadLocally,
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
refreshUnreadCount,
|
||||
clearUnreadLocally,
|
||||
bumpUnreadFromStream,
|
||||
applyUnreadCountFromStream,
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import { computed } from 'vue'
|
||||
import {
|
||||
getProjectBranding,
|
||||
getProjectId,
|
||||
isBoursecuProject,
|
||||
isGhatreProject,
|
||||
isKashkoolProject,
|
||||
type ProjectBranding,
|
||||
type ProjectId,
|
||||
} from '@/utils/project'
|
||||
|
||||
export function useProject() {
|
||||
const projectId = computed<ProjectId>(() => getProjectId())
|
||||
const branding = computed<ProjectBranding>(() => getProjectBranding())
|
||||
|
||||
const isGhatre = computed(() => isGhatreProject())
|
||||
const isKashkool = computed(() => isKashkoolProject())
|
||||
const isBoursecu = computed(() => isBoursecuProject())
|
||||
|
||||
const projectNameFa = computed(() => branding.value.nameFa)
|
||||
const heroGradient = computed(() => branding.value.heroGradient)
|
||||
const accentColor = computed(() => branding.value.accentColor)
|
||||
const fundLabel = computed(() => branding.value.fundLabel)
|
||||
const showHomeRoute = computed(() => branding.value.showHomeRoute)
|
||||
const defaultRoute = computed(() => branding.value.defaultRoute)
|
||||
|
||||
return {
|
||||
projectId,
|
||||
branding,
|
||||
isGhatre,
|
||||
isKashkool,
|
||||
isBoursecu,
|
||||
projectNameFa,
|
||||
heroGradient,
|
||||
accentColor,
|
||||
fundLabel,
|
||||
showHomeRoute,
|
||||
defaultRoute,
|
||||
}
|
||||
}
|
||||
@@ -1,132 +0,0 @@
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import type { PwaPlatform } from '@/modules/pwa/pwaInstallGuideSteps'
|
||||
import {
|
||||
getDefaultPwaPlatform,
|
||||
initPwaInstallPromptListener,
|
||||
isPwaInstallBannerDismissed,
|
||||
markPwaInstallBannerAsShown,
|
||||
shouldOfferPwaInstall,
|
||||
shouldShowPwaInstallPrompt,
|
||||
triggerNativePwaInstall,
|
||||
} from '@/modules/pwa/pwaInstall'
|
||||
|
||||
const guideOpen = ref(false)
|
||||
const bannerVisible = ref(false)
|
||||
const platform = ref<PwaPlatform>(getDefaultPwaPlatform())
|
||||
const installBannerConsumed = ref(isPwaInstallBannerDismissed())
|
||||
/** false وقتی اپ بهصورت PWA/TWA باز شده یا همین الان نصب شده */
|
||||
const offerInstall = ref(shouldOfferPwaInstall())
|
||||
let listenerReady = false
|
||||
let offerListenersBound = false
|
||||
|
||||
function refreshOfferInstall() {
|
||||
offerInstall.value = shouldOfferPwaInstall()
|
||||
}
|
||||
|
||||
function bindOfferInstallListeners() {
|
||||
if (offerListenersBound || typeof window === 'undefined') return
|
||||
offerListenersBound = true
|
||||
|
||||
refreshOfferInstall()
|
||||
|
||||
const onInstalled = () => {
|
||||
offerInstall.value = false
|
||||
}
|
||||
window.addEventListener('appinstalled', onInstalled)
|
||||
|
||||
const modes = ['standalone', 'fullscreen', 'minimal-ui', 'window-controls-overlay'] as const
|
||||
const mediaLists = modes.map((mode) => window.matchMedia(`(display-mode: ${mode})`))
|
||||
const onDisplayModeChange = () => refreshOfferInstall()
|
||||
for (const mql of mediaLists) {
|
||||
mql.addEventListener('change', onDisplayModeChange)
|
||||
}
|
||||
}
|
||||
|
||||
function ensureListener() {
|
||||
if (listenerReady) return
|
||||
listenerReady = true
|
||||
initPwaInstallPromptListener()
|
||||
bindOfferInstallListeners()
|
||||
}
|
||||
|
||||
export function usePwaInstall() {
|
||||
ensureListener()
|
||||
|
||||
onMounted(() => {
|
||||
refreshOfferInstall()
|
||||
})
|
||||
|
||||
const canPrompt = computed(() => {
|
||||
if (installBannerConsumed.value) return false
|
||||
return shouldShowPwaInstallPrompt()
|
||||
})
|
||||
|
||||
const showInstallEntry = computed(() => offerInstall.value)
|
||||
|
||||
function consumeInstallBanner() {
|
||||
if (installBannerConsumed.value) return
|
||||
markPwaInstallBannerAsShown()
|
||||
installBannerConsumed.value = true
|
||||
bannerVisible.value = false
|
||||
}
|
||||
|
||||
function openGuide(nextPlatform?: PwaPlatform) {
|
||||
if (!offerInstall.value) return
|
||||
consumeInstallBanner()
|
||||
platform.value = nextPlatform ?? getDefaultPwaPlatform()
|
||||
guideOpen.value = true
|
||||
}
|
||||
|
||||
function closeGuide() {
|
||||
guideOpen.value = false
|
||||
}
|
||||
|
||||
function showBanner() {
|
||||
if (!canPrompt.value) return
|
||||
bannerVisible.value = true
|
||||
markPwaInstallBannerAsShown()
|
||||
installBannerConsumed.value = true
|
||||
}
|
||||
|
||||
function hideBanner() {
|
||||
bannerVisible.value = false
|
||||
}
|
||||
|
||||
function dismissBanner() {
|
||||
consumeInstallBanner()
|
||||
}
|
||||
|
||||
async function completeGuide() {
|
||||
await triggerNativePwaInstall()
|
||||
consumeInstallBanner()
|
||||
closeGuide()
|
||||
}
|
||||
|
||||
/** نصب مستقیم مرورگر؛ اگر ممکن نبود مدال آموزش. */
|
||||
async function tryInstallOrOpenGuide(nextPlatform?: PwaPlatform) {
|
||||
if (!offerInstall.value) return false
|
||||
const installed = await triggerNativePwaInstall()
|
||||
if (installed) {
|
||||
offerInstall.value = false
|
||||
consumeInstallBanner()
|
||||
return true
|
||||
}
|
||||
openGuide(nextPlatform)
|
||||
return false
|
||||
}
|
||||
|
||||
return {
|
||||
guideOpen,
|
||||
bannerVisible,
|
||||
platform,
|
||||
canPrompt,
|
||||
showInstallEntry,
|
||||
openGuide,
|
||||
closeGuide,
|
||||
showBanner,
|
||||
hideBanner,
|
||||
dismissBanner,
|
||||
completeGuide,
|
||||
tryInstallOrOpenGuide,
|
||||
}
|
||||
}
|
||||
@@ -1,296 +0,0 @@
|
||||
import { computed, ref } from 'vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import {
|
||||
buildDepositSmsUrl,
|
||||
buildSupportPhoneUrl,
|
||||
loadSupportMessengerFromSettings,
|
||||
messengerNeedsClipboardCopy,
|
||||
openSupportMessengerEntry,
|
||||
resolveDepositGuideText,
|
||||
resolveDepositSupportMessage,
|
||||
resolveSupportMessengerEntries,
|
||||
resolveSupportMessengerLink,
|
||||
resolveSupportMessengerMeta,
|
||||
supportMessengerPickerAnchor,
|
||||
supportMessengerPickerOpen,
|
||||
supportMessengerSettings,
|
||||
type ResolvedSupportMessengerEntry,
|
||||
} from '@/utils/supportMessenger'
|
||||
import {
|
||||
copyDepositFieldValue,
|
||||
displayDepositCardNumber,
|
||||
displayDepositSheba,
|
||||
getDepositGuideVarsFromSettings,
|
||||
getDepositSettingLabel,
|
||||
hasDepositFieldValue,
|
||||
} from '@/utils/depositGuideText'
|
||||
import { useSettingsStore } from '@/store/settingsStore'
|
||||
import { isUserSupportChatEnabled } from '@/utils/chat'
|
||||
|
||||
/** plain: منوی شناور / درباره ما — بدون پیشمتن | deposit: مودال واریز — با deposit_support_message_text */
|
||||
type SupportPickerIntent = 'plain' | 'deposit'
|
||||
|
||||
const CHAT_PICKER_ENTRY: ResolvedSupportMessengerEntry = {
|
||||
messenger: 'chat',
|
||||
id: 'support-chat',
|
||||
label: 'چت پشتیبانی',
|
||||
icon: 'vuesax-linear:messages-2',
|
||||
accent: '#16a34a',
|
||||
url: '',
|
||||
}
|
||||
|
||||
export function useSupportMessenger() {
|
||||
const settingsStore = useSettingsStore()
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
const supportPickerOpen = supportMessengerPickerOpen
|
||||
const supportPickerIntent = ref<SupportPickerIntent>('plain')
|
||||
|
||||
/** چت فقط بعد از لاگین — روی صفحه ورود در picker نیاید */
|
||||
const isChatEnabled = computed(() => {
|
||||
void route.name
|
||||
return isUserSupportChatEnabled()
|
||||
})
|
||||
|
||||
const legacySupportLink = computed(() => '')
|
||||
|
||||
const depositSupportMessage = computed(() => resolveDepositSupportMessage())
|
||||
|
||||
const supportMessengerEntries = computed(() =>
|
||||
resolveSupportMessengerEntries(supportMessengerSettings.value),
|
||||
)
|
||||
|
||||
const pickerEntries = computed(() => {
|
||||
const list = [...supportMessengerEntries.value]
|
||||
if (isChatEnabled.value) {
|
||||
list.unshift(CHAT_PICKER_ENTRY)
|
||||
}
|
||||
return list
|
||||
})
|
||||
|
||||
const primaryMessengerEntry = computed(() => supportMessengerEntries.value[0] ?? null)
|
||||
|
||||
const messengerType = computed(
|
||||
() => (primaryMessengerEntry.value?.messenger ?? supportMessengerSettings.value.messenger ?? '').trim().toLowerCase(),
|
||||
)
|
||||
|
||||
const messengerMeta = computed(() => {
|
||||
if (isChatEnabled.value && supportMessengerEntries.value.length === 0) {
|
||||
return {
|
||||
label: CHAT_PICKER_ENTRY.label,
|
||||
icon: CHAT_PICKER_ENTRY.icon,
|
||||
accent: CHAT_PICKER_ENTRY.accent,
|
||||
}
|
||||
}
|
||||
return primaryMessengerEntry.value
|
||||
? {
|
||||
label: primaryMessengerEntry.value.label,
|
||||
icon: primaryMessengerEntry.value.icon,
|
||||
accent: primaryMessengerEntry.value.accent,
|
||||
}
|
||||
: resolveSupportMessengerMeta(messengerType.value)
|
||||
})
|
||||
|
||||
const messengerLink = computed(() =>
|
||||
primaryMessengerEntry.value?.url
|
||||
|| resolveSupportMessengerLink(
|
||||
supportMessengerSettings.value.messenger,
|
||||
supportMessengerSettings.value.messengerId,
|
||||
legacySupportLink.value,
|
||||
),
|
||||
)
|
||||
|
||||
function goToSupportChat() {
|
||||
void router.push({ name: 'support' })
|
||||
return true
|
||||
}
|
||||
|
||||
async function openMessengerEntry(entry: ResolvedSupportMessengerEntry, text?: string) {
|
||||
if (entry.messenger === 'chat') {
|
||||
return goToSupportChat()
|
||||
}
|
||||
|
||||
const messageText =
|
||||
text !== undefined
|
||||
? text.trim()
|
||||
: supportPickerIntent.value === 'deposit'
|
||||
? depositSupportMessage.value.trim()
|
||||
: ''
|
||||
const opened = await openSupportMessengerEntry(entry, messageText, legacySupportLink.value)
|
||||
if (!opened) return false
|
||||
|
||||
if (messageText && messengerNeedsClipboardCopy(entry.messenger)) {
|
||||
message.success('متن پیام کپی شد — در پیامرسان paste کنید')
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
let supportPickerOpenedAt = 0
|
||||
|
||||
async function openSupportPicker(
|
||||
intent: SupportPickerIntent,
|
||||
anchorEl?: HTMLElement | null,
|
||||
) {
|
||||
supportPickerIntent.value = intent
|
||||
if (anchorEl !== undefined) {
|
||||
supportMessengerPickerAnchor.value = anchorEl
|
||||
}
|
||||
|
||||
const draft =
|
||||
intent === 'deposit' ? depositSupportMessage.value.trim() : ''
|
||||
const messengerEntries = supportMessengerEntries.value
|
||||
const entries = pickerEntries.value
|
||||
|
||||
// لیست خالی + چت خاموش → هیچکار
|
||||
if (entries.length === 0) {
|
||||
return false
|
||||
}
|
||||
|
||||
// فقط چت (لیست پیامرسان خالی) → مستقیم چت
|
||||
if (isChatEnabled.value && messengerEntries.length === 0) {
|
||||
return goToSupportChat()
|
||||
}
|
||||
|
||||
// فقط یک گزینه (چت یا یک پیامرسان) → مستقیم همان
|
||||
if (entries.length === 1) {
|
||||
return openMessengerEntry(entries[0], draft)
|
||||
}
|
||||
|
||||
// چند گزینه (چت + لینکها یا چند پیامرسان) → منوی انتخاب
|
||||
const now = Date.now()
|
||||
if (supportPickerOpen.value) {
|
||||
if (now - supportPickerOpenedAt < 450) return true
|
||||
supportPickerOpen.value = false
|
||||
return true
|
||||
}
|
||||
|
||||
supportPickerOpen.value = true
|
||||
supportPickerOpenedAt = now
|
||||
return true
|
||||
}
|
||||
|
||||
async function openSupportMessenger(anchorEl?: HTMLElement | null) {
|
||||
return openSupportPicker('plain', anchorEl)
|
||||
}
|
||||
|
||||
async function openDepositSupportMessenger(anchorEl?: HTMLElement | null) {
|
||||
return openSupportPicker('deposit', anchorEl)
|
||||
}
|
||||
|
||||
function handleSupportMessengerClick(event?: Event) {
|
||||
const target = event?.currentTarget
|
||||
const anchor = target instanceof HTMLElement ? target : null
|
||||
void openSupportMessenger(anchor)
|
||||
}
|
||||
|
||||
const depositSmsLink = computed(() =>
|
||||
buildDepositSmsUrl(
|
||||
supportMessengerSettings.value.depositSmsSupportNumber,
|
||||
depositSupportMessage.value,
|
||||
),
|
||||
)
|
||||
|
||||
const supportPhoneLink = computed(() => {
|
||||
const fromSettings = buildSupportPhoneUrl(
|
||||
supportMessengerSettings.value.depositSmsSupportNumber,
|
||||
)
|
||||
if (fromSettings) return fromSettings
|
||||
|
||||
const legacy = legacySupportLink.value
|
||||
if (legacy.startsWith('tel:') && legacy.length > 4) return legacy
|
||||
|
||||
return ''
|
||||
})
|
||||
|
||||
const supportMessengerText = computed(() => resolveDepositGuideText())
|
||||
|
||||
const depositCardNumberRaw = computed(() => {
|
||||
void settingsStore.settings
|
||||
const fromMessenger = supportMessengerSettings.value.depositCardNumber?.trim()
|
||||
if (fromMessenger) return fromMessenger
|
||||
return String(getDepositGuideVarsFromSettings().cardNumber ?? '').trim()
|
||||
})
|
||||
|
||||
const depositShebaRaw = computed(() => {
|
||||
void settingsStore.settings
|
||||
const fromMessenger = supportMessengerSettings.value.depositSheba?.trim()
|
||||
if (fromMessenger) return fromMessenger
|
||||
return String(getDepositGuideVarsFromSettings().sheba ?? '').trim()
|
||||
})
|
||||
|
||||
const depositCardNumber = computed(() => displayDepositCardNumber(depositCardNumberRaw.value))
|
||||
const depositSheba = computed(() => displayDepositSheba(depositShebaRaw.value))
|
||||
|
||||
const depositCardLabel = computed(() => {
|
||||
void settingsStore.settings
|
||||
return getDepositSettingLabel('deposit_card_number', 'شماره کارت واریز')
|
||||
})
|
||||
|
||||
const depositShebaLabel = computed(() => {
|
||||
void settingsStore.settings
|
||||
return getDepositSettingLabel('deposit_sheba', 'شبا واریز')
|
||||
})
|
||||
|
||||
const hasDepositCardValue = computed(() => hasDepositFieldValue(depositCardNumberRaw.value))
|
||||
const hasDepositShebaValue = computed(() => hasDepositFieldValue(depositShebaRaw.value))
|
||||
|
||||
async function copyDepositCardNumber() {
|
||||
await copyDepositFieldValue(
|
||||
depositCardNumberRaw.value,
|
||||
'card',
|
||||
'شماره کارت ثبت نشده است',
|
||||
)
|
||||
}
|
||||
|
||||
async function copyDepositShebaNumber() {
|
||||
await copyDepositFieldValue(
|
||||
depositShebaRaw.value,
|
||||
'sheba',
|
||||
'شماره شبا ثبت نشده است',
|
||||
)
|
||||
}
|
||||
|
||||
const hasMessengerLink = computed(
|
||||
() => isChatEnabled.value || supportMessengerEntries.value.length > 0,
|
||||
)
|
||||
const hasMultipleMessengers = computed(() => pickerEntries.value.length > 1)
|
||||
const hasSupportPhoneLink = computed(() => !!supportPhoneLink.value)
|
||||
const hasSupportActions = computed(() => hasSupportPhoneLink.value || hasMessengerLink.value)
|
||||
const opensInNewTab = computed(() => /^https?:\/\//i.test(messengerLink.value))
|
||||
|
||||
return {
|
||||
supportPickerOpen,
|
||||
supportPickerAnchor: supportMessengerPickerAnchor,
|
||||
supportMessengerEntries: pickerEntries,
|
||||
isChatEnabled,
|
||||
messengerType,
|
||||
messengerMeta,
|
||||
messengerLink,
|
||||
supportPhoneLink,
|
||||
depositSmsLink,
|
||||
supportMessengerText,
|
||||
depositSupportMessage,
|
||||
depositCardNumber,
|
||||
depositSheba,
|
||||
depositCardNumberRaw,
|
||||
depositShebaRaw,
|
||||
depositCardLabel,
|
||||
depositShebaLabel,
|
||||
hasDepositCardValue,
|
||||
hasDepositShebaValue,
|
||||
copyDepositCardNumber,
|
||||
copyDepositShebaNumber,
|
||||
openSupportMessenger,
|
||||
openDepositSupportMessenger,
|
||||
openMessengerEntry,
|
||||
handleSupportMessengerClick,
|
||||
goToSupportChat,
|
||||
hasMessengerLink,
|
||||
hasMultipleMessengers,
|
||||
hasSupportPhoneLink,
|
||||
hasSupportActions,
|
||||
opensInNewTab,
|
||||
loadSupportMessengerFromSettings,
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { fetchTrackingSettings, isTrackingSystemsEnabled } from '@/utils/trackingSystemsSettings'
|
||||
|
||||
export function useTrackingSystemsFeature() {
|
||||
const trackingSystemsEnabled = ref(false)
|
||||
const trackingSystemsReady = ref(false)
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
const settings = await fetchTrackingSettings()
|
||||
trackingSystemsEnabled.value = isTrackingSystemsEnabled(settings)
|
||||
} finally {
|
||||
trackingSystemsReady.value = true
|
||||
}
|
||||
})
|
||||
|
||||
return {
|
||||
trackingSystemsEnabled,
|
||||
trackingSystemsReady,
|
||||
}
|
||||
}
|
||||
@@ -4,56 +4,10 @@ type RawAppConfig = AppConfig & {
|
||||
user?: Record<string, any>
|
||||
}
|
||||
|
||||
const EMPTY_STRING_CONFIG_KEYS = new Set([
|
||||
'color',
|
||||
'secondary_color',
|
||||
'background_color',
|
||||
'theme_config',
|
||||
])
|
||||
|
||||
function emptyStringToNull(value: unknown) {
|
||||
if (typeof value === 'string' && value.trim() === '') {
|
||||
return null
|
||||
}
|
||||
|
||||
return value
|
||||
}
|
||||
|
||||
function normalizeUserConfig(user?: Record<string, any>) {
|
||||
if (!user || typeof user !== 'object') {
|
||||
return user
|
||||
}
|
||||
|
||||
const normalized: Record<string, any> = { ...user }
|
||||
|
||||
for (const key of EMPTY_STRING_CONFIG_KEYS) {
|
||||
if (key in normalized) {
|
||||
normalized[key] = emptyStringToNull(normalized[key])
|
||||
}
|
||||
}
|
||||
|
||||
return normalized
|
||||
}
|
||||
|
||||
export function normalizeAppConfig(config: RawAppConfig): RawAppConfig {
|
||||
if (!config || typeof config !== 'object') {
|
||||
return {}
|
||||
}
|
||||
|
||||
if (!config.user || typeof config.user !== 'object') {
|
||||
return config
|
||||
}
|
||||
|
||||
return {
|
||||
...config,
|
||||
user: normalizeUserConfig(config.user),
|
||||
}
|
||||
}
|
||||
|
||||
let appConfig: RawAppConfig | null = null
|
||||
|
||||
export function setAppConfig(config: RawAppConfig) {
|
||||
appConfig = normalizeAppConfig(config || {})
|
||||
appConfig = config || {}
|
||||
window.__APP_CONFIG__ = appConfig
|
||||
}
|
||||
|
||||
@@ -61,14 +15,33 @@ export function getRawAppConfig() {
|
||||
return appConfig ?? window.__APP_CONFIG__ ?? null
|
||||
}
|
||||
|
||||
function isPlainObject(value: unknown): value is Record<string, any> {
|
||||
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
||||
}
|
||||
|
||||
export function getTenantConfig() {
|
||||
const rawConfig = getRawAppConfig()
|
||||
if (!rawConfig) return {}
|
||||
|
||||
if (rawConfig?.user && typeof rawConfig.user === 'object') {
|
||||
return rawConfig.user
|
||||
const user = rawConfig.user
|
||||
|
||||
if (isPlainObject(user)) {
|
||||
return {
|
||||
...user,
|
||||
name: rawConfig.name ?? user.name,
|
||||
name_fa: rawConfig.name_fa ?? user.name_fa,
|
||||
}
|
||||
}
|
||||
|
||||
if (rawConfig && Object.keys(rawConfig).length > 0) {
|
||||
if (Array.isArray(user) && isPlainObject(user[0])) {
|
||||
return {
|
||||
...user[0],
|
||||
name: rawConfig.name ?? user[0].name,
|
||||
name_fa: rawConfig.name_fa ?? user[0].name_fa,
|
||||
}
|
||||
}
|
||||
|
||||
if (Object.keys(rawConfig).length > 0) {
|
||||
return rawConfig
|
||||
}
|
||||
|
||||
@@ -77,7 +50,7 @@ export function getTenantConfig() {
|
||||
|
||||
export function getConfig<T = any>(key: string, fallback?: T): T {
|
||||
const config = getTenantConfig()
|
||||
const value = emptyStringToNull(config?.[key])
|
||||
const value = config?.[key]
|
||||
|
||||
return (value ?? fallback ?? null) as T
|
||||
}
|
||||
|
||||
@@ -1,14 +1,37 @@
|
||||
import { getConfig } from '@/config/app-config'
|
||||
import { isPwaManifestReady } from '@/modules/pwa/manifest'
|
||||
import { getProjectBranding } from '@/utils/project'
|
||||
|
||||
export function applyAppConfig() {
|
||||
if (isPwaManifestReady()) return
|
||||
applyProjectTheme()
|
||||
|
||||
if (isPwaManifestReady()) {
|
||||
setTitle()
|
||||
return
|
||||
}
|
||||
|
||||
setTitle()
|
||||
setFavicon()
|
||||
setAppleTouchIconFallback()
|
||||
}
|
||||
|
||||
function applyProjectTheme() {
|
||||
const branding = getProjectBranding()
|
||||
const root = document.documentElement
|
||||
const primary = branding.accentColor
|
||||
|
||||
root.style.setProperty('--project-accent', primary)
|
||||
root.style.setProperty('--project-hero-gradient', branding.heroGradient)
|
||||
root.style.setProperty('--app-primary-color', primary)
|
||||
root.style.setProperty('--primary-color', primary)
|
||||
root.dataset.project = branding.id
|
||||
|
||||
const secondaryColor = getConfig<string>('secondary_color')
|
||||
if (secondaryColor) {
|
||||
root.style.setProperty('--secondary-color', secondaryColor)
|
||||
}
|
||||
}
|
||||
|
||||
function setTitle() {
|
||||
document.title = getConfig('name_fa', 'در حال بارگذاری...')
|
||||
}
|
||||
@@ -76,8 +99,8 @@ function resolveRemoteLogo(path: string) {
|
||||
|
||||
const lastSuccess = localStorage.getItem('CONFIG_Success_URL')
|
||||
const base = lastSuccess
|
||||
? lastSuccess.replace(/[?#].*$/, '').replace(/\/get_user\/?$/i, '').replace(/\/+$/, '')
|
||||
: 'https://adm.montzar.ir'
|
||||
? lastSuccess.replace(/\/get_user\/?$/i, '').replace(/\/+$/, '')
|
||||
: 'https://nerkh.gold'
|
||||
|
||||
return `${base}/${path.replace(/^\/+/, '')}`
|
||||
}
|
||||
|
||||
@@ -1,17 +1,8 @@
|
||||
import type { AppConfig } from '@/config/types'
|
||||
import { normalizeAppConfig } from '@/config/app-config'
|
||||
import { readCachedAppConfig, writeCachedAppConfig } from '@/config/config-cache'
|
||||
import {
|
||||
allowSuperAdminFallback,
|
||||
getSuperAdminBase,
|
||||
getSuperAdminBases,
|
||||
isSuperAdminUrl,
|
||||
resolveTenantDomain,
|
||||
SA_RETRY_ROUNDS,
|
||||
} from '@/config/superadmin'
|
||||
|
||||
const CONFIG_SUCCESS_URL_KEY = 'CONFIG_Success_URL'
|
||||
export const CONFIG_RETRY_ROUNDS = SA_RETRY_ROUNDS
|
||||
export const CONFIG_RETRY_ROUNDS = 5
|
||||
|
||||
function getProtocol() {
|
||||
return window.location.protocol === 'https:' ? 'https:' : 'http:'
|
||||
@@ -19,34 +10,24 @@ function getProtocol() {
|
||||
|
||||
export function getConfigUrls() {
|
||||
const protocol = getProtocol()
|
||||
const domain = encodeURIComponent(resolveTenantDomain())
|
||||
const urls = getSuperAdminBases().map((base) => `${base}/get_user?domain=${domain}`)
|
||||
|
||||
if (allowSuperAdminFallback()) {
|
||||
urls.push(
|
||||
`${protocol}//tablo.talasevin.ir/get_user`,
|
||||
`${protocol}//abshode-service.montgit.ir/server/get_user`,
|
||||
`${protocol}//212.23.201.173:8381/get_user`,
|
||||
`${protocol}//91.212.174.137:4040/server/get_user`,
|
||||
)
|
||||
}
|
||||
|
||||
return urls
|
||||
return [
|
||||
`${protocol}//nerkh.gold/get_user`,
|
||||
`${protocol}//tablo.talasevin.ir/get_user`,
|
||||
`${protocol}//abshode-service.montgit.ir/server/get_user`,
|
||||
`${protocol}//212.23.201.173:8381/get_user`,
|
||||
`${protocol}//91.212.174.137:4040/server/get_user`
|
||||
]
|
||||
}
|
||||
|
||||
export function sortConfigUrls(urls: string[]) {
|
||||
const lastSuccessUrl = localStorage.getItem(CONFIG_SUCCESS_URL_KEY)
|
||||
if (
|
||||
!lastSuccessUrl ||
|
||||
!urls.includes(lastSuccessUrl) ||
|
||||
!isSuperAdminUrl(lastSuccessUrl)
|
||||
) {
|
||||
if (lastSuccessUrl && !isSuperAdminUrl(lastSuccessUrl)) {
|
||||
localStorage.removeItem(CONFIG_SUCCESS_URL_KEY)
|
||||
}
|
||||
return [...urls]
|
||||
}
|
||||
return [lastSuccessUrl, ...urls.filter((url) => url !== lastSuccessUrl)]
|
||||
|
||||
return [...urls].sort((a, b) => {
|
||||
if (a === lastSuccessUrl) return -1
|
||||
if (b === lastSuccessUrl) return 1
|
||||
return 0
|
||||
})
|
||||
}
|
||||
|
||||
function clearStaleConfigSuccessUrl(url: string) {
|
||||
@@ -63,10 +44,10 @@ async function fetchConfig(url: string, timeout = 3000): Promise<AppConfig> {
|
||||
const response = await fetch(url, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
Accept: 'application/json'
|
||||
},
|
||||
cache: 'no-store',
|
||||
signal: controller.signal,
|
||||
signal: controller.signal
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
@@ -79,7 +60,7 @@ async function fetchConfig(url: string, timeout = 3000): Promise<AppConfig> {
|
||||
throw new Error('Config response is not JSON')
|
||||
}
|
||||
|
||||
return normalizeAppConfig(await response.json())
|
||||
return await response.json()
|
||||
} finally {
|
||||
clearTimeout(timeoutId)
|
||||
}
|
||||
@@ -96,11 +77,7 @@ export async function fetchFreshAppConfig(rounds = CONFIG_RETRY_ROUNDS): Promise
|
||||
const timeout = index === urls.length - 1 ? 7000 : 4000
|
||||
const config = await fetchConfig(url, timeout)
|
||||
|
||||
if (isSuperAdminUrl(url)) {
|
||||
localStorage.setItem(CONFIG_SUCCESS_URL_KEY, url)
|
||||
} else {
|
||||
clearStaleConfigSuccessUrl(url)
|
||||
}
|
||||
localStorage.setItem(CONFIG_SUCCESS_URL_KEY, url)
|
||||
writeCachedAppConfig(config)
|
||||
|
||||
return config
|
||||
@@ -111,19 +88,20 @@ export async function fetchFreshAppConfig(rounds = CONFIG_RETRY_ROUNDS): Promise
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error(
|
||||
getSuperAdminBase()
|
||||
? `Cannot load from SuperAdmin (${getSuperAdminBase()}).`
|
||||
: 'Cannot load app config from any server',
|
||||
)
|
||||
throw new Error('Cannot load app config from any server')
|
||||
}
|
||||
|
||||
export async function loadAppConfig(): Promise<AppConfig> {
|
||||
const cachedConfig = readCachedAppConfig()
|
||||
try {
|
||||
return await fetchFreshAppConfig()
|
||||
} catch (error) {
|
||||
const cachedConfig = readCachedAppConfig()
|
||||
|
||||
if (cachedConfig) {
|
||||
return normalizeAppConfig(cachedConfig)
|
||||
if (cachedConfig) {
|
||||
console.warn('Using cached app config because fresh fetch failed', error)
|
||||
return cachedConfig
|
||||
}
|
||||
|
||||
throw error
|
||||
}
|
||||
|
||||
return await fetchFreshAppConfig()
|
||||
}
|
||||
|
||||
@@ -1,11 +1,3 @@
|
||||
import {
|
||||
allowSuperAdminFallback,
|
||||
getSuperAdminBases,
|
||||
isSuperAdminUrl,
|
||||
resolveTenantDomain,
|
||||
SA_RETRY_ROUNDS,
|
||||
} from '@/config/superadmin'
|
||||
|
||||
type VersionResponse =
|
||||
| string
|
||||
| number
|
||||
@@ -17,9 +9,10 @@ type VersionResponse =
|
||||
}
|
||||
|
||||
const VERSION_SUCCESS_URL_KEY = 'VERSION_Success_URL'
|
||||
export const VERSION_RETRY_ROUNDS = SA_RETRY_ROUNDS
|
||||
export const VERSION_RETRY_ROUNDS = 5
|
||||
|
||||
let versionFetchPromise: Promise<string | null> | null = null
|
||||
let cachedVersionResult: string | null | undefined
|
||||
|
||||
function getProtocol() {
|
||||
return window.location.protocol === 'https:' ? 'https:' : 'http:'
|
||||
@@ -27,34 +20,25 @@ function getProtocol() {
|
||||
|
||||
function getVersionUrls() {
|
||||
const protocol = getProtocol()
|
||||
const domain = encodeURIComponent(resolveTenantDomain())
|
||||
const urls = getSuperAdminBases().map((base) => `${base}/get_version?domain=${domain}`)
|
||||
|
||||
if (allowSuperAdminFallback()) {
|
||||
urls.push(
|
||||
'https://tablo.talasevin.ir/get_version',
|
||||
'https://abshode-service.montgit.ir/server/get_version',
|
||||
`${protocol}//212.23.201.173:8381/get_version`,
|
||||
`${protocol}//91.212.174.137:4040/server/get_version`,
|
||||
)
|
||||
}
|
||||
|
||||
return urls
|
||||
return [
|
||||
'https://nerkh.gold/get_version',
|
||||
'https://tablo.talasevin.ir/get_version',
|
||||
'https://abshode-service.montgit.ir/server/get_version',
|
||||
`${protocol}//212.23.201.173:8381/get_version`,
|
||||
`${protocol}//91.212.174.137:4040/server/get_version`
|
||||
]
|
||||
}
|
||||
|
||||
function sortVersionUrls(urls: string[]) {
|
||||
const lastSuccessUrl = localStorage.getItem(VERSION_SUCCESS_URL_KEY)
|
||||
if (
|
||||
!lastSuccessUrl ||
|
||||
!urls.includes(lastSuccessUrl) ||
|
||||
!isSuperAdminUrl(lastSuccessUrl)
|
||||
) {
|
||||
if (lastSuccessUrl && !isSuperAdminUrl(lastSuccessUrl)) {
|
||||
localStorage.removeItem(VERSION_SUCCESS_URL_KEY)
|
||||
}
|
||||
return [...urls]
|
||||
|
||||
if (!lastSuccessUrl) {
|
||||
return urls
|
||||
}
|
||||
return [lastSuccessUrl, ...urls.filter((url) => url !== lastSuccessUrl)]
|
||||
|
||||
const others = urls.filter((url) => url !== lastSuccessUrl)
|
||||
return [lastSuccessUrl, ...others]
|
||||
}
|
||||
|
||||
function clearStaleVersionSuccessUrl(url: string) {
|
||||
@@ -105,10 +89,10 @@ async function fetchVersion(url: string, timeout = 3500): Promise<string | null>
|
||||
const response = await fetch(url, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
Accept: 'application/json'
|
||||
},
|
||||
cache: 'no-store',
|
||||
signal: controller.signal,
|
||||
signal: controller.signal
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
@@ -116,22 +100,18 @@ async function fetchVersion(url: string, timeout = 3500): Promise<string | null>
|
||||
}
|
||||
|
||||
const contentType = response.headers.get('content-type') ?? ''
|
||||
if (!contentType.includes('application/json')) {
|
||||
throw new Error('Version response is not JSON')
|
||||
}
|
||||
|
||||
const data = (await response.json()) as VersionResponse
|
||||
const data = contentType.includes('application/json')
|
||||
? ((await response.json()) as VersionResponse)
|
||||
: ((await response.text()) as VersionResponse)
|
||||
|
||||
const version = normalizeVersionResponse(data)
|
||||
|
||||
if (!version) {
|
||||
throw new Error('Version response is empty')
|
||||
}
|
||||
|
||||
if (isSuperAdminUrl(url)) {
|
||||
localStorage.setItem(VERSION_SUCCESS_URL_KEY, url)
|
||||
} else {
|
||||
clearStaleVersionSuccessUrl(url)
|
||||
}
|
||||
localStorage.setItem(VERSION_SUCCESS_URL_KEY, url)
|
||||
|
||||
return version
|
||||
} finally {
|
||||
@@ -163,6 +143,7 @@ async function fetchVersionWithRetry(rounds = VERSION_RETRY_ROUNDS): Promise<str
|
||||
}
|
||||
|
||||
export function resetVersionCheckCache() {
|
||||
cachedVersionResult = undefined
|
||||
versionFetchPromise = null
|
||||
}
|
||||
|
||||
@@ -177,13 +158,22 @@ export async function loadRemoteAppVersion(options?: {
|
||||
resetVersionCheckCache()
|
||||
}
|
||||
|
||||
if (cachedVersionResult !== undefined) {
|
||||
return cachedVersionResult
|
||||
}
|
||||
|
||||
if (versionFetchPromise) {
|
||||
return versionFetchPromise
|
||||
}
|
||||
|
||||
versionFetchPromise = fetchVersionWithRetry(rounds).finally(() => {
|
||||
versionFetchPromise = null
|
||||
})
|
||||
versionFetchPromise = fetchVersionWithRetry(rounds)
|
||||
.then((version) => {
|
||||
cachedVersionResult = version
|
||||
return version
|
||||
})
|
||||
.finally(() => {
|
||||
versionFetchPromise = null
|
||||
})
|
||||
|
||||
return versionFetchPromise
|
||||
}
|
||||
|
||||
@@ -1,83 +0,0 @@
|
||||
/** سوپرادمین — مستر، بعد دو اسلیو */
|
||||
export const SUPERADMIN_BASES = [
|
||||
'https://adm.montzar.ir',
|
||||
'https://adm.montech.ir',
|
||||
'https://adm.montest.ir',
|
||||
] as const
|
||||
|
||||
/** هر API: سه دامنه × سه دور */
|
||||
export const SA_RETRY_ROUNDS = 3
|
||||
|
||||
/** تنظیمات پیشرفته نسخه — همان دادهٔ /get_settings بدون نیاز به nginx جدا */
|
||||
export const SA_PROGRAM_SETTINGS_PATH = '/api/public/program-settings'
|
||||
|
||||
function normalizeBase(url: string) {
|
||||
return String(url || '').trim().replace(/\/$/, '')
|
||||
}
|
||||
|
||||
export function getSuperAdminBases(): string[] {
|
||||
const fromEnv = normalizeBase(String(import.meta.env.VITE_SUPERADMIN_URL || ''))
|
||||
const bases = [...SUPERADMIN_BASES]
|
||||
if (fromEnv) {
|
||||
return [fromEnv, ...bases.filter((base) => base !== fromEnv)]
|
||||
}
|
||||
return bases
|
||||
}
|
||||
|
||||
export function getSuperAdminBase(): string {
|
||||
return getSuperAdminBases()[0] || ''
|
||||
}
|
||||
|
||||
export function resolveTenantDomain(): string {
|
||||
const override = String(import.meta.env.VITE_TENANT_DOMAIN || '').trim()
|
||||
if (override) return override
|
||||
|
||||
const host = String(window.location.hostname || '').trim()
|
||||
if (!host || host === 'localhost' || host === '127.0.0.1') {
|
||||
return 'k.montzar.ir'
|
||||
}
|
||||
return host
|
||||
}
|
||||
|
||||
export function isSuperAdminUrl(url: string): boolean {
|
||||
return getSuperAdminBases().some((base) => url.startsWith(base))
|
||||
}
|
||||
|
||||
export function allowSuperAdminFallback(): boolean {
|
||||
return Boolean(import.meta.env.DEV)
|
||||
}
|
||||
|
||||
export async function fetchSuperAdminJson<T>(
|
||||
buildUrl: (base: string) => string,
|
||||
timeout = 5000,
|
||||
): Promise<T> {
|
||||
let lastError: unknown
|
||||
const bases = getSuperAdminBases()
|
||||
for (let round = 1; round <= SA_RETRY_ROUNDS; round++) {
|
||||
for (const base of bases) {
|
||||
const controller = new AbortController()
|
||||
const timer = window.setTimeout(() => controller.abort(), timeout)
|
||||
try {
|
||||
const res = await fetch(buildUrl(base), {
|
||||
method: 'GET',
|
||||
cache: 'no-store',
|
||||
signal: controller.signal,
|
||||
headers: { Accept: 'application/json' },
|
||||
})
|
||||
if (!res.ok) {
|
||||
throw new Error(`HTTP ${res.status}`)
|
||||
}
|
||||
const contentType = res.headers.get('content-type') || ''
|
||||
if (!contentType.includes('application/json')) {
|
||||
throw new Error('SuperAdmin response is not JSON')
|
||||
}
|
||||
return (await res.json()) as T
|
||||
} catch (error) {
|
||||
lastError = error
|
||||
} finally {
|
||||
window.clearTimeout(timer)
|
||||
}
|
||||
}
|
||||
}
|
||||
throw lastError instanceof Error ? lastError : new Error('SuperAdmin unreachable')
|
||||
}
|
||||
@@ -8,10 +8,6 @@ export function useAppNavigation() {
|
||||
const popVisible = ref(false)
|
||||
const currentRoute = computed(() => route.name)
|
||||
const hideMenu = computed(() => !!route.meta.hideMenu)
|
||||
/** فقط ناو پایین موبایل — سایدبار دسکتاپ را مخفی نمیکند */
|
||||
const hideBottomNav = computed(
|
||||
() => !!route.meta.hideBottomNav || !!route.meta.hideMenu,
|
||||
)
|
||||
|
||||
function isNavActive(routeName: string) {
|
||||
return currentRoute.value === routeName
|
||||
@@ -38,7 +34,6 @@ export function useAppNavigation() {
|
||||
popVisible,
|
||||
currentRoute,
|
||||
hideMenu,
|
||||
hideBottomNav,
|
||||
isNavActive,
|
||||
navItemClass,
|
||||
navigateTo,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { AppNavItem } from '../types'
|
||||
import { getProjectBranding, isGhatreProject } from '@/utils/project'
|
||||
|
||||
/** تبهای پایین موبایل — کاربر لاگینشده */
|
||||
/** تبهای پایین موبایل — کاربر لاگینشده (کشکول) */
|
||||
export const AUTH_PRIMARY_NAV: AppNavItem[] = [
|
||||
{ id: 'home', routeName: 'home', label: 'صفحه اصلی', icon: 'vuesax-linear:home' },
|
||||
{ id: 'transactions', routeName: 'transactions', label: 'گزارش', icon: 'vuesax-linear:receipt-item' },
|
||||
@@ -8,6 +9,14 @@ export const AUTH_PRIMARY_NAV: AppNavItem[] = [
|
||||
{ id: 'cart', routeName: 'cart', label: 'سبد خرید', icon: 'vuesax-linear:shopping-cart' },
|
||||
]
|
||||
|
||||
/** تبهای پایین موبایل — کاربر لاگینشده (قطره) */
|
||||
export const GHATRE_AUTH_PRIMARY_NAV: AppNavItem[] = [
|
||||
{ id: 'buyProduct', routeName: 'buyProduct', label: 'فروشگاه', icon: 'vuesax-linear:coin' },
|
||||
{ id: 'transactions', routeName: 'transactions', label: 'گزارش', icon: 'vuesax-linear:receipt-item' },
|
||||
{ id: 'wallet', routeName: 'wallet', label: 'کیف پول', icon: 'vuesax-linear:wallet-1' },
|
||||
{ id: 'cart', routeName: 'cart', label: 'سبد خرید', icon: 'vuesax-linear:shopping-cart' },
|
||||
]
|
||||
|
||||
/** تبهای پایین موبایل — مهمان */
|
||||
export const GUEST_PRIMARY_NAV: AppNavItem[] = [
|
||||
{ id: 'buyProduct', routeName: 'buyProduct', label: 'فروشگاه', icon: 'vuesax-linear:coin' },
|
||||
@@ -16,13 +25,6 @@ export const GUEST_PRIMARY_NAV: AppNavItem[] = [
|
||||
{ id: 'login', routeName: 'login', label: 'ورود', icon: 'vuesax-linear:login' },
|
||||
]
|
||||
|
||||
export const RECOVERY_SITES_NAV_ITEM: AppNavItem = {
|
||||
id: 'recoverySites',
|
||||
routeName: 'recoverySites',
|
||||
label: 'سایتهای ریگیری',
|
||||
icon: 'vuesax-linear:global',
|
||||
}
|
||||
|
||||
/** منوی FAB موبایل + بخش فرعی سایدبار دسکتاپ — کاربر لاگینشده */
|
||||
export const AUTH_SECONDARY_NAV: AppNavItem[] = [
|
||||
{ id: 'notifyTrigger', routeName: 'notifyTrigger', label: 'هشدار قیمت', icon: 'vuesax-linear:bill' },
|
||||
@@ -38,16 +40,16 @@ export const AUTH_SECONDARY_NAV: AppNavItem[] = [
|
||||
]
|
||||
|
||||
export function getPrimaryNavItems(isAuthenticated: boolean): AppNavItem[] {
|
||||
return isAuthenticated ? AUTH_PRIMARY_NAV : GUEST_PRIMARY_NAV
|
||||
if (!isAuthenticated) return GUEST_PRIMARY_NAV
|
||||
return isGhatreProject() ? GHATRE_AUTH_PRIMARY_NAV : AUTH_PRIMARY_NAV
|
||||
}
|
||||
|
||||
export function getSecondaryNavItems(
|
||||
isAuthenticated: boolean,
|
||||
options?: { includeRecoverySites?: boolean },
|
||||
): AppNavItem[] {
|
||||
export function getSecondaryNavItems(isAuthenticated: boolean): AppNavItem[] {
|
||||
if (!isAuthenticated) return []
|
||||
if (options?.includeRecoverySites) {
|
||||
return [...AUTH_SECONDARY_NAV, RECOVERY_SITES_NAV_ITEM]
|
||||
}
|
||||
return AUTH_SECONDARY_NAV
|
||||
|
||||
const fundLabel = getProjectBranding().fundLabel
|
||||
|
||||
return AUTH_SECONDARY_NAV.map((item) =>
|
||||
item.id === 'fund' ? { ...item, label: fundLabel } : item
|
||||
)
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ defineEmits<{
|
||||
height: 18px;
|
||||
padding: 0 4px;
|
||||
border-radius: 999px;
|
||||
background: #a72b77;
|
||||
background: var(--app-primary-color, #a72b77);
|
||||
color: #fff;
|
||||
font-size: 10px;
|
||||
font-weight: 700;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<aside class="desktop-sidebar">
|
||||
<div class="desktop-sidebar__brand">
|
||||
<img :src="navLogo" alt="کشکول گلد" class="desktop-sidebar__logo" />
|
||||
<img :src="navLogo" :alt="projectNameFa" class="desktop-sidebar__logo" />
|
||||
</div>
|
||||
|
||||
<nav class="desktop-sidebar__section" aria-label="منوی اصلی">
|
||||
@@ -42,34 +42,17 @@ import { computed } from 'vue'
|
||||
import logoFull from '@/assets/img/logo_full_.png'
|
||||
import { isToken } from '@/utils'
|
||||
import { useCartStore } from '@/store/cartStore'
|
||||
import { useTrackingSystemsFeature } from '@/composables/useTrackingSystemsFeature'
|
||||
import { useSettingsStore } from '@/store/settingsStore'
|
||||
import { getPrimaryNavItems, getSecondaryNavItems } from '../config/navigation'
|
||||
import { useAppNavigation } from '../composables/useAppNavigation'
|
||||
import DesktopNavItem from './DesktopNavItem.vue'
|
||||
import { useProject } from '@/composables/useProject'
|
||||
|
||||
const { projectNameFa } = useProject()
|
||||
const cartStore = useCartStore()
|
||||
const authenticated = computed(() => isToken())
|
||||
const navLogo = logoFull
|
||||
const { trackingSystemsEnabled } = useTrackingSystemsFeature()
|
||||
const settingsStore = useSettingsStore()
|
||||
const primaryItems = computed(() => getPrimaryNavItems(authenticated.value))
|
||||
/** «لیست دریافتیها» فقط در موبایل نمایش داده میشود */
|
||||
const DESKTOP_HIDDEN_NAV_IDS = ['list']
|
||||
const secondaryItems = computed(() =>
|
||||
getSecondaryNavItems(authenticated.value, {
|
||||
includeRecoverySites: trackingSystemsEnabled.value,
|
||||
}).filter((item) => {
|
||||
if (DESKTOP_HIDDEN_NAV_IDS.includes(item.id)) return false
|
||||
if (item.id === 'notifyTrigger') {
|
||||
return settingsStore.isSettingTruthy('has_page_price_trigger')
|
||||
}
|
||||
if (item.id === 'giftCard') {
|
||||
return settingsStore.isSettingTruthy('has_page_gift_card')
|
||||
}
|
||||
return true
|
||||
}),
|
||||
)
|
||||
const secondaryItems = computed(() => getSecondaryNavItems(authenticated.value))
|
||||
const cartCount = computed(() => cartStore.itemCount || 0)
|
||||
|
||||
const { isNavActive, navigateTo } = useAppNavigation()
|
||||
|
||||
@@ -110,15 +110,15 @@
|
||||
|
||||
&:hover {
|
||||
background: rgba(167, 43, 119, 0.06);
|
||||
color: @primary-color;
|
||||
color: @theme-primary;
|
||||
}
|
||||
|
||||
&--active {
|
||||
background: rgba(167, 43, 119, 0.1);
|
||||
color: @primary-color;
|
||||
color: @theme-primary;
|
||||
|
||||
.desktop-nav-item__icon {
|
||||
color: @primary-color;
|
||||
color: @theme-primary;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@
|
||||
&__price {
|
||||
font-size: 15px;
|
||||
font-weight: 700;
|
||||
color: @App-primary-color;
|
||||
color: @theme-primary;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@
|
||||
&__total {
|
||||
font-size: 20px;
|
||||
font-weight: 700;
|
||||
color: @App-primary-color;
|
||||
color: @theme-primary;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@
|
||||
.dproduct-info__price {
|
||||
font-size: 22px;
|
||||
font-weight: 700;
|
||||
color: @App-primary-color;
|
||||
color: @theme-primary;
|
||||
}
|
||||
|
||||
.dproduct-info__desc {
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
@navigate="navigateTo"
|
||||
/>
|
||||
|
||||
<div :class="['main-with-bottom-chrome', { 'main-with-bottom-chrome--no-nav': hideBottomNav }]">
|
||||
<div :class="['main-with-bottom-chrome', { 'main-with-bottom-chrome--no-nav': hideMenu }]">
|
||||
<router-view v-slot="{ Component, route: activeRoute }">
|
||||
<transition :name="activeRoute.meta.transition || 'fade'">
|
||||
<component :is="Component" :key="activeRoute.fullPath" class="main-with-bottom-chrome-inner" />
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
<Teleport to="body">
|
||||
<MobileBottomNav
|
||||
v-if="!hideBottomNav"
|
||||
v-if="!hideMenu"
|
||||
:nav-item-class="navItemClass"
|
||||
@navigate="navigateTo"
|
||||
@toggle-overflow="toggleOverflowMenu"
|
||||
@@ -37,7 +37,7 @@ const route = useRoute()
|
||||
|
||||
const {
|
||||
popVisible,
|
||||
hideBottomNav,
|
||||
hideMenu,
|
||||
navItemClass,
|
||||
navigateTo,
|
||||
toggleOverflowMenu,
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
</div>
|
||||
</BasicButton>
|
||||
<BasicButton
|
||||
v-if="authenticated && priceTriggerEnabled"
|
||||
v-if="authenticated"
|
||||
icon-size="16"
|
||||
class="!font-bold w-15rem"
|
||||
@click="go('notifyTrigger')"
|
||||
@@ -71,7 +71,7 @@
|
||||
<!-- </div>-->
|
||||
<!-- </BasicButton>-->
|
||||
<BasicButton
|
||||
v-if="authenticated && giftCardEnabled"
|
||||
v-if="authenticated"
|
||||
icon-size="16"
|
||||
class="!font-bold w-15rem"
|
||||
@click="go('giftCard')"
|
||||
@@ -87,17 +87,6 @@
|
||||
<div>درباره ما</div>
|
||||
</div>
|
||||
</BasicButton>
|
||||
<BasicButton
|
||||
v-if="authenticated && trackingSystemsEnabled"
|
||||
icon-size="16"
|
||||
class="!font-bold w-15rem"
|
||||
@click="go('recoverySites')"
|
||||
>
|
||||
<div class="flex gap-2 items-center">
|
||||
<BasicIcon icon="vuesax-linear:global" size="16" class="absolute right-2" />
|
||||
<div>سایتهای ریگیری</div>
|
||||
</div>
|
||||
</BasicButton>
|
||||
<BasicButton
|
||||
v-if="authenticated"
|
||||
icon-size="16"
|
||||
@@ -119,8 +108,6 @@
|
||||
import { computed } from 'vue'
|
||||
import BasicButton from '@/components/BasicPacks/BasicButton.vue'
|
||||
import BasicIcon from '@/components/BasicPacks/BasicIcon.vue'
|
||||
import { useTrackingSystemsFeature } from '@/composables/useTrackingSystemsFeature'
|
||||
import { useSettingsStore } from '@/store/settingsStore'
|
||||
import { isToken } from '@/utils'
|
||||
|
||||
defineProps<{
|
||||
@@ -133,14 +120,6 @@ const emit = defineEmits<{
|
||||
}>()
|
||||
|
||||
const authenticated = computed(() => isToken())
|
||||
const { trackingSystemsEnabled } = useTrackingSystemsFeature()
|
||||
const settingsStore = useSettingsStore()
|
||||
const priceTriggerEnabled = computed(() =>
|
||||
settingsStore.isSettingTruthy('has_page_price_trigger'),
|
||||
)
|
||||
const giftCardEnabled = computed(() =>
|
||||
settingsStore.isSettingTruthy('has_page_gift_card'),
|
||||
)
|
||||
|
||||
function go(routeName: string) {
|
||||
emit('navigate', routeName)
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
|
||||
&.text-primary .tab__icon,
|
||||
&.text-primary .tab__icon .ant-badge {
|
||||
color: @primary-color;
|
||||
color: @theme-primary;
|
||||
}
|
||||
|
||||
&.text-gray-400 .tab__icon,
|
||||
@@ -68,11 +68,11 @@
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
background-color: #a72b77;
|
||||
background-color: @theme-primary;
|
||||
|
||||
.circle_into {
|
||||
overflow: hidden;
|
||||
background-color: @primary-color;
|
||||
background-color: @theme-primary;
|
||||
border-radius: 50%;
|
||||
width: 56px;
|
||||
height: 56px;
|
||||
|
||||
@@ -172,10 +172,3 @@ html.app-layout--desktop .app-splash-screen {
|
||||
left: 0 !important;
|
||||
width: 100vw !important;
|
||||
}
|
||||
|
||||
html.app-layout--desktop .login-page-root {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
min-height: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
padding: 0.75rem;
|
||||
padding-top: calc(0.75rem + var(--app-safe-top, env(safe-area-inset-top, 0px)));
|
||||
background: #fff;
|
||||
color: @primary-color;
|
||||
color: @theme-primary;
|
||||
font-size: 1rem;
|
||||
font-weight: 700;
|
||||
line-height: 1.5;
|
||||
@@ -67,7 +67,7 @@
|
||||
z-index: 1999;
|
||||
padding: 0.75rem;
|
||||
background: #fff;
|
||||
color: @primary-color;
|
||||
color: @theme-primary;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,19 +1,16 @@
|
||||
import type {Wallet} from '@/models/wallet';
|
||||
import type {Product} from '@/models/products';
|
||||
|
||||
export interface Fund {
|
||||
id?: number,
|
||||
title?: string,
|
||||
file_id?: number,
|
||||
customer_id?: number,
|
||||
product_id?: number,
|
||||
created_at?: string,
|
||||
updated_at?: string,
|
||||
deleted_at?: string,
|
||||
wallet?: Wallet[] | Wallet,
|
||||
product?: Product,
|
||||
wallet?: Wallet[] | Wallet
|
||||
}
|
||||
export interface FundTransaction {
|
||||
fund_id?: number
|
||||
value?: number
|
||||
}
|
||||
}
|
||||
@@ -48,9 +48,6 @@ export interface User {
|
||||
virtual_card_number: string
|
||||
finger_print: boolean
|
||||
gold: number;
|
||||
chat_room_id?: string | null
|
||||
chat_user_id?: string | null
|
||||
settings?: Array<{ key?: string; value?: string | number }>
|
||||
}
|
||||
|
||||
export interface Login {
|
||||
|
||||
@@ -10,8 +10,6 @@ export interface Product {
|
||||
unit: string
|
||||
active: boolean
|
||||
show: boolean
|
||||
show_in_assets?: boolean
|
||||
show_on_tv?: boolean
|
||||
open_sell: boolean
|
||||
open_buy: boolean
|
||||
group_type:string
|
||||
@@ -19,30 +17,16 @@ export interface Product {
|
||||
percent_fee_sell: number | undefined
|
||||
cash_fee_buy: number | undefined
|
||||
cash_fee_sell: number | undefined
|
||||
cash_fee_buy_is_percent?: boolean | null
|
||||
cash_fee_sell_is_percent?: boolean | null
|
||||
order_limit_enabled?: boolean
|
||||
min_order_cash?: number | null
|
||||
max_order_cash?: number | null
|
||||
has_physical_delivery?: boolean
|
||||
min_physical_delivery_quantity?: number | null
|
||||
reading_method: any
|
||||
created_at: any
|
||||
updated_at: any
|
||||
deleted_at: any
|
||||
price?:number | undefined
|
||||
price_profit?: number | null
|
||||
price_offset_percent?: number | null
|
||||
sellPrice?:number | undefined
|
||||
description: string
|
||||
wallet: Wallet
|
||||
similar?:Product[]
|
||||
inventory:number
|
||||
app_price?: boolean | number | null
|
||||
direct_price?: number | null
|
||||
trade_by_quantity?: boolean | number | null
|
||||
use_last_price_if_zero?: boolean | null
|
||||
reference_provider_active?: boolean | null
|
||||
}
|
||||
|
||||
export interface PInventory {
|
||||
|
||||
@@ -1,77 +0,0 @@
|
||||
export type ChatAttachmentType = 'image' | 'audio'
|
||||
|
||||
export type ChatMessageSender = 'user' | 'support' | 'admin'
|
||||
|
||||
export type ChatMessageStatus = 'sending' | 'sent' | 'seen' | 'failed'
|
||||
|
||||
export type ChatAttachment = {
|
||||
id: string
|
||||
type: 'image' | 'audio'
|
||||
url: string
|
||||
name?: string
|
||||
size?: number
|
||||
mimeType?: string
|
||||
durationMs?: number
|
||||
file?: File
|
||||
uploading?: boolean
|
||||
uploadProgress?: number
|
||||
}
|
||||
|
||||
export type ChatReplyPreview = {
|
||||
id: string
|
||||
sender: string
|
||||
text?: string
|
||||
attachment?: {
|
||||
type: 'image' | 'audio'
|
||||
url: string
|
||||
name?: string
|
||||
} | null
|
||||
}
|
||||
|
||||
export interface ChatMessage {
|
||||
id: string
|
||||
text?: string
|
||||
sender: 'user' | 'support'
|
||||
createdAt: string
|
||||
createdAtRaw?: string | number | Date | null
|
||||
status?: 'sending' | 'sent' | 'seen'
|
||||
attachments?: ChatAttachment[]
|
||||
|
||||
// reply
|
||||
reply?: string | null
|
||||
replyTo?: ChatReplyPreview | null
|
||||
}
|
||||
|
||||
export type ComposerSendPayload = {
|
||||
text: string
|
||||
attachments: ChatAttachment[]
|
||||
reply?: string | null
|
||||
replyTo?: ChatReplyPreview | null
|
||||
}
|
||||
|
||||
|
||||
export interface SupportMessage {
|
||||
id: string
|
||||
sender: 'user' | 'admin'
|
||||
text?: string
|
||||
createdAt: string
|
||||
createdAtRaw?: string | number | Date | null
|
||||
status?: ChatMessageStatus
|
||||
attachments?: ChatAttachment[]
|
||||
|
||||
// reply
|
||||
reply?: string | null
|
||||
replyTo?: ChatReplyPreview | null
|
||||
}
|
||||
|
||||
export interface SupportConversation {
|
||||
id: string
|
||||
userName: string
|
||||
avatar: string
|
||||
online: boolean
|
||||
unreadCount: number
|
||||
lastSeenText: string
|
||||
lastMessagePreview: string
|
||||
updatedAtText: string
|
||||
messages: SupportMessage[]
|
||||
}
|
||||
@@ -1,129 +0,0 @@
|
||||
import { PWA_MANIFEST_READY_EVENT } from '@/modules/pwa/manifest'
|
||||
import { isTWA } from '@/utils/config'
|
||||
|
||||
export const PWA_INSTALL_BANNER_DISMISSED_KEY = 'pwa-install-banner-dismissed'
|
||||
|
||||
type BeforeInstallPromptEvent = Event & {
|
||||
prompt: () => Promise<void>
|
||||
userChoice: Promise<{ outcome: 'accepted' | 'dismissed' }>
|
||||
}
|
||||
|
||||
let deferredInstallPrompt: BeforeInstallPromptEvent | null = null
|
||||
let installListenerInitialized = false
|
||||
|
||||
export function isStandalonePwa() {
|
||||
if (typeof window === 'undefined') return false
|
||||
|
||||
const nav = window.navigator as Navigator & { standalone?: boolean }
|
||||
if (nav.standalone) return true
|
||||
|
||||
// installed / launched as app (not a normal browser tab)
|
||||
const modes = ['standalone', 'fullscreen', 'minimal-ui', 'window-controls-overlay'] as const
|
||||
return modes.some((mode) => window.matchMedia(`(display-mode: ${mode})`).matches)
|
||||
}
|
||||
|
||||
/** دکمه/منوی نصب فقط وقتی هنوز داخل مرورگر عادی هستیم. */
|
||||
export function shouldOfferPwaInstall() {
|
||||
if (typeof window === 'undefined') return false
|
||||
if (isStandalonePwa() || isTWA()) return false
|
||||
return true
|
||||
}
|
||||
|
||||
export function isAppleMobileDevice() {
|
||||
if (typeof navigator === 'undefined') return false
|
||||
|
||||
const ua = navigator.userAgent || ''
|
||||
|
||||
if (/iPhone|iPod/i.test(ua)) return true
|
||||
if (/iPad/i.test(ua)) return true
|
||||
|
||||
const isTouchMac = navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1
|
||||
if (!isTouchMac) return false
|
||||
|
||||
if (/CriOS|FxiOS|EdgiOS/i.test(ua)) return true
|
||||
if (/Chrome|Edg|Firefox|OPR/i.test(ua) && !/Mobile/i.test(ua)) return false
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
export function isAndroidDevice() {
|
||||
if (typeof navigator === 'undefined') return false
|
||||
return /Android/i.test(navigator.userAgent || '')
|
||||
}
|
||||
|
||||
export function isMobileBrowser() {
|
||||
if (typeof window === 'undefined') return false
|
||||
|
||||
const coarsePointer = window.matchMedia('(pointer: coarse)').matches
|
||||
const narrowViewport = window.matchMedia('(max-width: 767.98px)').matches
|
||||
|
||||
return coarsePointer || narrowViewport || isAppleMobileDevice() || isAndroidDevice()
|
||||
}
|
||||
|
||||
export function getDefaultPwaPlatform(): 'android' | 'ios' {
|
||||
if (isAppleMobileDevice()) return 'ios'
|
||||
return 'android'
|
||||
}
|
||||
|
||||
export function hasNativeInstallPrompt() {
|
||||
return Boolean(deferredInstallPrompt)
|
||||
}
|
||||
|
||||
export function isPwaInstallBannerDismissed() {
|
||||
if (typeof localStorage === 'undefined') return false
|
||||
return localStorage.getItem(PWA_INSTALL_BANNER_DISMISSED_KEY) === '1'
|
||||
}
|
||||
|
||||
export function dismissPwaInstallBanner() {
|
||||
localStorage.setItem(PWA_INSTALL_BANNER_DISMISSED_KEY, '1')
|
||||
}
|
||||
|
||||
/** بعد از اولین نمایش بنر / راهنما دیگر نشان داده نشود. */
|
||||
export function markPwaInstallBannerAsShown() {
|
||||
dismissPwaInstallBanner()
|
||||
}
|
||||
|
||||
export function shouldShowPwaInstallPrompt() {
|
||||
if (typeof window === 'undefined') return false
|
||||
if (!window.isSecureContext) return false
|
||||
if (!shouldOfferPwaInstall()) return false
|
||||
if (isPwaInstallBannerDismissed()) return false
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
export function initPwaInstallPromptListener() {
|
||||
if (installListenerInitialized || typeof window === 'undefined') return
|
||||
installListenerInitialized = true
|
||||
|
||||
window.addEventListener(PWA_MANIFEST_READY_EVENT, (event) => {
|
||||
const installEvent = (event as CustomEvent<{ installEvent?: Event | null }>).detail?.installEvent
|
||||
|
||||
if (installEvent) {
|
||||
deferredInstallPrompt = installEvent as BeforeInstallPromptEvent
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export async function triggerNativePwaInstall() {
|
||||
const promptEvent = deferredInstallPrompt
|
||||
|
||||
if (!promptEvent) {
|
||||
return false
|
||||
}
|
||||
|
||||
try {
|
||||
await promptEvent.prompt()
|
||||
const choice = await promptEvent.userChoice
|
||||
|
||||
if (choice.outcome === 'accepted') {
|
||||
deferredInstallPrompt = null
|
||||
dismissPwaInstallBanner()
|
||||
return true
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('Native PWA install prompt failed', error)
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
export type PwaPlatform = 'android' | 'ios'
|
||||
|
||||
export type PwaGuideIllustration =
|
||||
| 'android-chrome'
|
||||
| 'android-menu'
|
||||
| 'android-install'
|
||||
| 'android-confirm'
|
||||
| 'ios-safari'
|
||||
| 'ios-share'
|
||||
| 'ios-add-home'
|
||||
| 'ios-confirm'
|
||||
|
||||
export type PwaGuideStep = {
|
||||
illustration: PwaGuideIllustration
|
||||
text: string
|
||||
hint?: string
|
||||
}
|
||||
|
||||
export type PwaGuidePlatformConfig = {
|
||||
title: string
|
||||
steps: PwaGuideStep[]
|
||||
}
|
||||
|
||||
export const PWA_INSTALL_GUIDE: Record<PwaPlatform, PwaGuidePlatformConfig> = {
|
||||
android: {
|
||||
title: 'نصب روی Android',
|
||||
steps: [
|
||||
{
|
||||
illustration: 'android-chrome',
|
||||
text: 'سایت را در مرورگر Chrome باز کنید.',
|
||||
},
|
||||
{
|
||||
illustration: 'android-menu',
|
||||
text: 'روی منوی سهنقطه ⋮ در گوشه بالا بزنید.',
|
||||
},
|
||||
{
|
||||
illustration: 'android-install',
|
||||
text: 'گزینه «Install app» یا «Add to Home screen» / «افزودن به صفحه اصلی» را انتخاب کنید.',
|
||||
},
|
||||
{
|
||||
illustration: 'android-confirm',
|
||||
text: 'نصب را تأیید کنید تا میانبر روی صفحه اصلی ساخته شود.',
|
||||
hint: 'اگر دکمه نصب را نمیبینید، یکبار صفحه را رفرش کنید و دوباره منو را باز کنید.',
|
||||
},
|
||||
],
|
||||
},
|
||||
ios: {
|
||||
title: 'نصب روی iPhone / iPad',
|
||||
steps: [
|
||||
{
|
||||
illustration: 'ios-safari',
|
||||
text: 'سایت را در مرورگر Safari باز کنید (از Chrome روی iOS نصب نمیشود).',
|
||||
},
|
||||
{
|
||||
illustration: 'ios-share',
|
||||
text: 'روی دکمه Share در پایین صفحه بزنید (مربع با فلش رو به بالا).',
|
||||
},
|
||||
{
|
||||
illustration: 'ios-add-home',
|
||||
text: 'به پایین اسکرول کنید و «Add to Home Screen» یا «افزودن به صفحه اصلی» را انتخاب کنید.',
|
||||
},
|
||||
{
|
||||
illustration: 'ios-confirm',
|
||||
text: 'نام را تأیید کنید و روی Add / افزودن بزنید.',
|
||||
hint: 'بعد از نصب، آیکون اپ مثل بقیه برنامهها روی صفحه اصلی ظاهر میشود.',
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
export const PWA_GUIDE_STEP_LABELS = ['۱', '۲', '۳', '۴'] as const
|
||||
@@ -1,5 +1,5 @@
|
||||
import {createRouter, createWebHistory} from 'vue-router'
|
||||
import {isToken} from "@/utils";
|
||||
import { getProjectDefaultRoute } from '@/utils/project'
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(import.meta.env.BASE_URL),
|
||||
@@ -9,16 +9,10 @@ const router = createRouter({
|
||||
name: 'login',
|
||||
component: () => import('../views/login/index.vue')
|
||||
},
|
||||
/* {
|
||||
path: '/',
|
||||
name: 'null',
|
||||
redirect: {name: 'home'},
|
||||
// component: () => import('../views/login/index.vue')
|
||||
},*/
|
||||
{
|
||||
path: `/`,
|
||||
name: 'main',
|
||||
redirect: {name: isToken()?'home':'buyProduct'},
|
||||
redirect: () => ({ name: getProjectDefaultRoute() }),
|
||||
component: () => import('../views/base/index.vue'),
|
||||
children: [
|
||||
{
|
||||
@@ -71,22 +65,11 @@ const router = createRouter({
|
||||
name: 'about',
|
||||
component: () => import('@/views/base/about/index.vue')
|
||||
},
|
||||
{
|
||||
path: 'support',
|
||||
name: 'support',
|
||||
meta: { hideBottomNav: true },
|
||||
component: () => import('@/views/support/index.vue')
|
||||
},
|
||||
{
|
||||
path: 'notifyTrigger',
|
||||
name: 'notifyTrigger',
|
||||
component: () => import('@/views/base/priceTrigger/index.vue')
|
||||
},
|
||||
{
|
||||
path: 'appNotifications',
|
||||
name: 'appNotifications',
|
||||
component: () => import('@/views/base/appNotifications/index.vue')
|
||||
},
|
||||
{
|
||||
path: 'transfer',
|
||||
name: 'transfer',
|
||||
@@ -120,11 +103,6 @@ const router = createRouter({
|
||||
name: 'rules',
|
||||
component: () => import('@/views/base/rules/index.vue')
|
||||
},
|
||||
{
|
||||
path: 'recoverySites',
|
||||
name: 'recoverySites',
|
||||
component: () => import('@/views/base/recoverySites/index.vue')
|
||||
},
|
||||
{
|
||||
path: 'permissions',
|
||||
name: 'permissions',
|
||||
@@ -151,29 +129,8 @@ const router = createRouter({
|
||||
name: 'fund_add',
|
||||
component: () => import('@/views/base/fund/newFund/index.vue')
|
||||
},
|
||||
{
|
||||
path: 'piggy',
|
||||
name: 'piggy',
|
||||
component: () => import('@/views/base/piggy/index.vue')
|
||||
},
|
||||
{
|
||||
path: 'piggy/add',
|
||||
name: 'piggy_add',
|
||||
component: () => import('@/views/base/piggy/new.vue')
|
||||
},
|
||||
{
|
||||
path: 'piggy/:id',
|
||||
name: 'piggy_info',
|
||||
component: () => import('@/views/base/piggy/info.vue')
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
path: '/tv',
|
||||
name: 'tv',
|
||||
meta: { hideMenu: true },
|
||||
component: () => import('@/views/base/tv/index.vue')
|
||||
},
|
||||
{
|
||||
path: '/:pathMatch(.*)*',
|
||||
name: 'notFound',
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
import { ref } from 'vue'
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
export const useConfigStore = defineStore('config', () => {
|
||||
const config = ref(window.__APP_CONFIG__?.user)
|
||||
|
||||
async function getConfigData() {
|
||||
config.value = window.__APP_CONFIG__?.user
|
||||
}
|
||||
|
||||
return {
|
||||
config,
|
||||
getConfigData,
|
||||
}
|
||||
})
|
||||
@@ -1,33 +1,39 @@
|
||||
import { ref } from 'vue'
|
||||
import { defineStore } from 'pinia'
|
||||
import { getFundTable } from '@/api/fund'
|
||||
import type { Fund } from '@/models/fund'
|
||||
import type { TableOutput } from '@/models/table'
|
||||
import { type ComputedRef, ref } from 'vue'
|
||||
// import { get } from 'lodash'
|
||||
import {defineStore} from "pinia";
|
||||
import {getMe} from "@/api/me";
|
||||
import {getFundTable} from "@/api/fund";
|
||||
import type {Fund} from "@/models/fund";
|
||||
import type {TableOutput} from "@/models/table";
|
||||
import { getProductInventory } from '@/api/products'
|
||||
|
||||
export const useFundUserStore = defineStore('fund', () => {
|
||||
/** داراییها / موجودی محصول (صفحهٔ /fund فعلی) */
|
||||
const myFunds = ref<TableOutput<Fund> | undefined>(undefined)
|
||||
/** قلکهای واقعی (مدل Fund) */
|
||||
const myPiggyFunds = ref<TableOutput<Fund> | undefined>(undefined)
|
||||
|
||||
async function getMyFund() {
|
||||
try {
|
||||
myFunds.value = await getProductInventory()
|
||||
// console.log('fff')
|
||||
myFunds.value = await getFundTable()
|
||||
return myFunds.value
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
}
|
||||
}
|
||||
|
||||
async function getMyPiggyFunds() {
|
||||
try {
|
||||
myPiggyFunds.value = await getFundTable()
|
||||
return myPiggyFunds.value
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
}
|
||||
}
|
||||
/* const permissions: ComputedRef<string[]> = computed(() => {
|
||||
const permissions: string[] = get(userInfo.value, 'permission', [])
|
||||
const excludes: string[] = get(userInfo.value, 'exclude', [])
|
||||
return permissions.filter((item) => !excludes.includes(item))
|
||||
})*/
|
||||
|
||||
return { getMyFund, getMyPiggyFunds, myFunds, myPiggyFunds }
|
||||
/*
|
||||
function canAccess(permissionKey: string) {
|
||||
if (isAdmin.value) return true
|
||||
return permissions.value.includes(permissionKey)
|
||||
}
|
||||
*/
|
||||
/*
|
||||
const isAdmin = computed(() => {
|
||||
return userInfo.value?.is_admin
|
||||
})*/
|
||||
|
||||
return { getMyFund, myFunds/* permissions, canAccess, isAdmin*/ }
|
||||
})
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
import { computed, ref } from 'vue'
|
||||
import { ref } from 'vue'
|
||||
import { defineStore } from 'pinia'
|
||||
import { getSettings } from '@/api/configuration'
|
||||
import { fetchSuperAdminProgramSettings, isLockedCanEdit } from '@/api/superadminSettings'
|
||||
import { resolveMeltedGoldLabel, resolveMetalTypeLabel } from '@/utils/metalLabels'
|
||||
import { resolveTradeWeightUnit } from '@/utils/weightUnit'
|
||||
|
||||
export interface AppSetting {
|
||||
id?: number
|
||||
@@ -13,7 +10,6 @@ export interface AppSetting {
|
||||
description?: string
|
||||
is_active?: boolean
|
||||
type?: string
|
||||
can_edit?: number | boolean | string
|
||||
}
|
||||
|
||||
export const useSettingsStore = defineStore('settings', () => {
|
||||
@@ -26,40 +22,6 @@ export const useSettingsStore = defineStore('settings', () => {
|
||||
return item?.value ?? null
|
||||
}
|
||||
|
||||
function isSettingTruthy(key: string) {
|
||||
const value = getSettingByKey(key)
|
||||
if (value == null) {
|
||||
return false
|
||||
}
|
||||
if (value === true) {
|
||||
return true
|
||||
}
|
||||
const normalized = String(value).trim().toLowerCase()
|
||||
return normalized === 'true' || normalized === '1' || normalized === 'yes'
|
||||
}
|
||||
|
||||
function mergeSettings(items?: AppSetting[] | null) {
|
||||
if (!items?.length) {
|
||||
return
|
||||
}
|
||||
|
||||
const merged = [...settings.value]
|
||||
items.forEach((item) => {
|
||||
if (!item?.key) {
|
||||
return
|
||||
}
|
||||
|
||||
const index = merged.findIndex((setting) => setting.key === item.key)
|
||||
if (index >= 0) {
|
||||
merged[index] = { ...merged[index], ...item }
|
||||
} else {
|
||||
merged.push(item)
|
||||
}
|
||||
})
|
||||
|
||||
settings.value = merged
|
||||
}
|
||||
|
||||
async function fetchSettings(force = false) {
|
||||
if (!force && fetchPromise) {
|
||||
return fetchPromise
|
||||
@@ -67,39 +29,26 @@ export const useSettingsStore = defineStore('settings', () => {
|
||||
|
||||
fetchPromise = (async () => {
|
||||
try {
|
||||
const localRaw = await getSettings().catch(() => [])
|
||||
const remote = await fetchSuperAdminProgramSettings()
|
||||
const local = Array.isArray(localRaw) ? localRaw : []
|
||||
const editable = local.filter((row) => !isLockedCanEdit(row?.can_edit))
|
||||
settings.value = []
|
||||
mergeSettings(remote as AppSetting[])
|
||||
mergeSettings(editable)
|
||||
loaded.value = true
|
||||
return settings.value
|
||||
const data = await getSettings()
|
||||
if (Array.isArray(data)) {
|
||||
settings.value = data
|
||||
}
|
||||
} catch (error) {
|
||||
fetchPromise = null
|
||||
throw error
|
||||
console.log(error)
|
||||
} finally {
|
||||
loaded.value = true
|
||||
}
|
||||
|
||||
return settings.value
|
||||
})()
|
||||
|
||||
return fetchPromise
|
||||
}
|
||||
|
||||
const metalTypeSettingValue = computed(() => getSettingByKey('metal_type'))
|
||||
const metalTypeLabel = computed(() => resolveMetalTypeLabel(metalTypeSettingValue.value))
|
||||
const meltedGoldLabel = computed(() => resolveMeltedGoldLabel(metalTypeSettingValue.value))
|
||||
const tradeWeightUnit = computed(() => resolveTradeWeightUnit(getSettingByKey('unit')))
|
||||
|
||||
return {
|
||||
settings,
|
||||
loaded,
|
||||
fetchSettings,
|
||||
mergeSettings,
|
||||
getSettingByKey,
|
||||
isSettingTruthy,
|
||||
metalTypeSettingValue,
|
||||
metalTypeLabel,
|
||||
meltedGoldLabel,
|
||||
tradeWeightUnit,
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1,165 +0,0 @@
|
||||
/** نوتیف مرورگر بدون Firebase — ترجیحاً با gesture کاربر؛ بعد از لاگین هم تلاش میشود. */
|
||||
|
||||
export type BrowserNotifState =
|
||||
| 'unsupported'
|
||||
| 'needs-pwa'
|
||||
| 'default'
|
||||
| 'granted'
|
||||
| 'denied'
|
||||
|
||||
function isStandalonePwa() {
|
||||
if (typeof window === 'undefined') return false
|
||||
return (
|
||||
window.matchMedia('(display-mode: standalone)').matches ||
|
||||
Boolean((window.navigator as Navigator & { standalone?: boolean }).standalone)
|
||||
)
|
||||
}
|
||||
|
||||
/** فقط دستگاههای واقعی اپل موبایل — نه مک با ترکپد */
|
||||
function isAppleMobileDevice() {
|
||||
if (typeof navigator === 'undefined') return false
|
||||
const ua = navigator.userAgent || ''
|
||||
|
||||
if (/iPhone|iPod/i.test(ua)) return true
|
||||
if (/iPad/i.test(ua)) return true
|
||||
|
||||
const isTouchMac = navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1
|
||||
if (!isTouchMac) return false
|
||||
|
||||
if (/CriOS|FxiOS|EdgiOS/i.test(ua)) return true
|
||||
if (/Chrome|Edg|Firefox|OPR/i.test(ua) && !/Mobile/i.test(ua)) return false
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
export function getBrowserNotificationState(): BrowserNotifState {
|
||||
if (typeof window === 'undefined') return 'unsupported'
|
||||
if (typeof window.isSecureContext === 'boolean' && !window.isSecureContext) {
|
||||
return 'unsupported'
|
||||
}
|
||||
|
||||
const hasApi = 'Notification' in window
|
||||
|
||||
if (isAppleMobileDevice() && !isStandalonePwa() && !hasApi) {
|
||||
return 'needs-pwa'
|
||||
}
|
||||
|
||||
if (!hasApi) {
|
||||
return 'unsupported'
|
||||
}
|
||||
|
||||
const permission = Notification.permission
|
||||
if (permission === 'granted') return 'granted'
|
||||
if (permission === 'denied') return 'denied'
|
||||
return 'default'
|
||||
}
|
||||
|
||||
export function canRequestBrowserNotification() {
|
||||
return getBrowserNotificationState() === 'default'
|
||||
}
|
||||
|
||||
export async function requestBrowserNotificationPermission(): Promise<BrowserNotifState> {
|
||||
const before = getBrowserNotificationState()
|
||||
if (before === 'granted' || before === 'denied' || before === 'unsupported' || before === 'needs-pwa') {
|
||||
return before
|
||||
}
|
||||
if (!('Notification' in window)) {
|
||||
return getBrowserNotificationState()
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await Notification.requestPermission()
|
||||
if (result === 'granted') return 'granted'
|
||||
if (result === 'denied') return 'denied'
|
||||
return 'default'
|
||||
} catch {
|
||||
return getBrowserNotificationState()
|
||||
}
|
||||
}
|
||||
|
||||
/** لوگوی برند از کانفیگ؛ fallback به آیکونهای PWA */
|
||||
function resolveNotifIcon() {
|
||||
try {
|
||||
const avatar = String(
|
||||
(window as Window & { __APP_CONFIG__?: { user?: { avatar?: string } } }).__APP_CONFIG__?.user
|
||||
?.avatar ?? '',
|
||||
).trim()
|
||||
if (avatar) {
|
||||
return avatar
|
||||
}
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
|
||||
try {
|
||||
return new URL('/192.png', window.location.origin).href
|
||||
} catch {
|
||||
try {
|
||||
return new URL('/favicon.png', window.location.origin).href
|
||||
} catch {
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export type ShowBrowserNotificationOptions = {
|
||||
title: string
|
||||
body?: string
|
||||
tag?: string
|
||||
url?: string
|
||||
}
|
||||
|
||||
/** نمایش نوتیف سیستم؛ ترجیح با Service Worker (معتبرتر روی Chrome/Android). */
|
||||
export async function showBrowserNotification(options: ShowBrowserNotificationOptions): Promise<boolean> {
|
||||
if (getBrowserNotificationState() !== 'granted') {
|
||||
return false
|
||||
}
|
||||
|
||||
const title = options.title || 'اعلان جدید'
|
||||
const body = options.body || ''
|
||||
const tag = options.tag || `app-notification-${Date.now()}`
|
||||
const url = options.url || '/appNotifications'
|
||||
const icon = resolveNotifIcon()
|
||||
|
||||
try {
|
||||
if ('serviceWorker' in navigator) {
|
||||
const reg = await navigator.serviceWorker.ready
|
||||
if (reg?.showNotification) {
|
||||
await reg.showNotification(title, {
|
||||
body,
|
||||
tag,
|
||||
icon,
|
||||
badge: icon,
|
||||
data: { url },
|
||||
renotify: true,
|
||||
})
|
||||
return true
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('SW showNotification failed, falling back', error)
|
||||
}
|
||||
|
||||
try {
|
||||
const n = new Notification(title, {
|
||||
body,
|
||||
tag,
|
||||
icon,
|
||||
dir: 'rtl',
|
||||
lang: 'fa',
|
||||
})
|
||||
n.onclick = () => {
|
||||
window.focus()
|
||||
n.close()
|
||||
if (url) {
|
||||
void import('@/router').then((mod) => {
|
||||
mod.default.push(url).catch(() => undefined)
|
||||
})
|
||||
}
|
||||
}
|
||||
return true
|
||||
} catch (error) {
|
||||
console.warn('Notification constructor failed', error)
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,19 @@
|
||||
import { getTenantConfig } from '@/config/app-config'
|
||||
|
||||
export function getConfigApp(key: string) {
|
||||
const config = window.__APP_CONFIG__ ? window.__APP_CONFIG__.user : {}
|
||||
const config = getTenantConfig()
|
||||
const value = config?.[key]
|
||||
|
||||
if (config) {
|
||||
return config[key]
|
||||
}
|
||||
return null
|
||||
return value ?? null
|
||||
}
|
||||
|
||||
export function isBoursecuProject() {
|
||||
const name = String(getConfigApp('name') || '').toLowerCase()
|
||||
return name === 'boursecu' || name === 'boursemes'
|
||||
}
|
||||
export {
|
||||
getProjectId,
|
||||
getProjectBranding,
|
||||
getProjectDefaultRoute,
|
||||
isGhatreProject,
|
||||
isKashkoolProject,
|
||||
isBoursecuProject,
|
||||
} from '@/utils/project'
|
||||
|
||||
export function isTWA() {
|
||||
if (typeof sessionStorage === 'undefined') return false
|
||||
if (sessionStorage.getItem('appMode') === 'twa') return true
|
||||
if (typeof document !== 'undefined' && document.referrer.startsWith('android-app://')) {
|
||||
sessionStorage.setItem('appMode', 'twa')
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
export type { ProjectId, ProjectBranding } from '@/utils/project'
|
||||
|
||||
@@ -1,202 +0,0 @@
|
||||
import { message } from 'ant-design-vue'
|
||||
import { useSettingsStore } from '@/store/settingsStore'
|
||||
import { useUserStore } from '@/store/userStore'
|
||||
|
||||
export interface DepositGuideVars {
|
||||
accountHolder?: string | null
|
||||
cardNumber?: string | null
|
||||
sheba?: string | null
|
||||
/** نام مشتری واردشده — برای پیام پشتیبانی واریز */
|
||||
customerName?: string | null
|
||||
}
|
||||
|
||||
export const DEFAULT_DEPOSIT_GUIDE_TEXT =
|
||||
'جهت شارژ حساب کاربری خود، کلمه «شماره حساب» را برای پشتیبانی ارسال نمایید.'
|
||||
|
||||
export const DEFAULT_DEPOSIT_SUPPORT_MESSAGE_TEXT =
|
||||
'باسلام، %نام هستم. کدپیگیری و مبلغ واریزی من:'
|
||||
|
||||
/** الگوی متغیر نام — ٪نام / %نام / % نام / %نام% */
|
||||
const NAME_PLACEHOLDER_RE = /[%٪]\s*نام(?:\s*[%٪])?/gu
|
||||
const CARD_PLACEHOLDER_RE = /[%٪]\s*کارت(?:\s*[%٪])?/gu
|
||||
const SHEBA_PLACEHOLDER_RE = /[%٪]\s*شبا(?:\s*[%٪])?/gu
|
||||
|
||||
export function getCustomerNameFromUser(): string {
|
||||
try {
|
||||
const user = useUserStore().userInfo
|
||||
const fullName = [user?.fname, user?.lname].filter(Boolean).join(' ').trim()
|
||||
return fullName
|
||||
} catch {
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
/** نام نمایشی در پیام پشتیبانی: اول مشتری، بعد نام صاحب حساب تنظیمات */
|
||||
function resolveSupportMessageName(vars: DepositGuideVars): string {
|
||||
const customerName = String(vars.customerName ?? '').trim()
|
||||
if (customerName) return customerName
|
||||
return String(vars.accountHolder ?? '').trim()
|
||||
}
|
||||
|
||||
/** فقط %نام — برای پیام SMS/پیامرسان پشتیبانی (نه کارت/شبا) */
|
||||
export function renderDepositSupportMessageText(
|
||||
template: string,
|
||||
vars: DepositGuideVars,
|
||||
): string {
|
||||
const name = resolveSupportMessageName(vars)
|
||||
return template.replace(NAME_PLACEHOLDER_RE, name)
|
||||
}
|
||||
|
||||
/** جایگزینی متغیرها در متن راهنمای واریز — ٪نام / %نام، ٪کارت / %کارت، ٪شبا / %شبا */
|
||||
export function renderDepositGuideText(
|
||||
template: string,
|
||||
vars: DepositGuideVars,
|
||||
): string {
|
||||
const accountHolder = String(vars.accountHolder ?? '').trim()
|
||||
const cardNumber = String(vars.cardNumber ?? '').trim()
|
||||
const sheba = String(vars.sheba ?? '').trim()
|
||||
|
||||
return template
|
||||
.replace(SHEBA_PLACEHOLDER_RE, sheba)
|
||||
.replace(CARD_PLACEHOLDER_RE, cardNumber)
|
||||
.replace(NAME_PLACEHOLDER_RE, accountHolder)
|
||||
}
|
||||
|
||||
export function getDepositGuideVarsFromSettings(): DepositGuideVars {
|
||||
const customerName = getCustomerNameFromUser()
|
||||
try {
|
||||
const store = useSettingsStore()
|
||||
return {
|
||||
accountHolder: store.getSettingByKey('deposit_account_holder') as string | null,
|
||||
cardNumber: store.getSettingByKey('deposit_card_number') as string | null,
|
||||
sheba: store.getSettingByKey('deposit_sheba') as string | null,
|
||||
customerName,
|
||||
}
|
||||
} catch {
|
||||
return { customerName }
|
||||
}
|
||||
}
|
||||
|
||||
export function getDepositGuideTemplate(): string {
|
||||
try {
|
||||
const fromSettings = String(useSettingsStore().getSettingByKey('support_messenger_text') ?? '').trim()
|
||||
if (fromSettings) return fromSettings
|
||||
} catch {
|
||||
// settings store may not be ready yet
|
||||
}
|
||||
return DEFAULT_DEPOSIT_GUIDE_TEXT
|
||||
}
|
||||
|
||||
export function getDepositSupportMessageTemplate(): string {
|
||||
try {
|
||||
const fromSettings = String(
|
||||
useSettingsStore().getSettingByKey('deposit_support_message_text') ?? '',
|
||||
).trim()
|
||||
if (fromSettings) return fromSettings
|
||||
} catch {
|
||||
// settings store may not be ready yet
|
||||
}
|
||||
return DEFAULT_DEPOSIT_SUPPORT_MESSAGE_TEXT
|
||||
}
|
||||
|
||||
export function getRenderedDepositGuideText(vars?: DepositGuideVars): string {
|
||||
return renderDepositGuideText(getDepositGuideTemplate(), vars ?? getDepositGuideVarsFromSettings())
|
||||
}
|
||||
|
||||
export function getRenderedDepositSupportMessage(vars?: DepositGuideVars): string {
|
||||
return renderDepositSupportMessageText(
|
||||
getDepositSupportMessageTemplate(),
|
||||
vars ?? getDepositGuideVarsFromSettings(),
|
||||
)
|
||||
}
|
||||
|
||||
export function formatDepositCardNumber(value?: string | null) {
|
||||
const digits = String(value ?? '').replace(/\D/g, '')
|
||||
if (!digits) return ''
|
||||
|
||||
return digits.replace(/(\d{4})(?=\d)/g, '$1 ').trim()
|
||||
}
|
||||
|
||||
export function formatDepositSheba(value?: string | null) {
|
||||
const normalized = String(value ?? '').replace(/\s/g, '').toUpperCase()
|
||||
if (!normalized) return ''
|
||||
|
||||
const digits = normalized.replace(/^IR/i, '').replace(/\D/g, '')
|
||||
if (!digits) return normalized
|
||||
|
||||
const full = `IR${digits}`
|
||||
return full.replace(/(.{4})/g, '$1 ').trim()
|
||||
}
|
||||
|
||||
export function hasDepositFieldValue(value?: string | null) {
|
||||
return Boolean(String(value ?? '').trim())
|
||||
}
|
||||
|
||||
export function displayDepositCardNumber(value?: string | null) {
|
||||
return formatDepositCardNumber(value) || '**** **** **** ****'
|
||||
}
|
||||
|
||||
export function displayDepositSheba(value?: string | null) {
|
||||
return formatDepositSheba(value) || 'IR** **** **** **** **** **** **'
|
||||
}
|
||||
|
||||
export function getDepositSettingLabel(key: string, fallback: string) {
|
||||
try {
|
||||
const item = useSettingsStore().settings.find(
|
||||
(setting) => String(setting?.key ?? '') === key,
|
||||
)
|
||||
return item?.title_fa?.trim() || fallback
|
||||
} catch {
|
||||
return fallback
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeDepositCopyValue(value: string, kind: 'card' | 'sheba') {
|
||||
const normalized = value.replace(/\s/g, '')
|
||||
if (!normalized) return ''
|
||||
|
||||
if (kind === 'sheba') {
|
||||
const upper = normalized.toUpperCase()
|
||||
if (upper.startsWith('IR')) return upper
|
||||
const digits = upper.replace(/\D/g, '')
|
||||
return digits ? `IR${digits}` : upper
|
||||
}
|
||||
|
||||
return normalized.replace(/\D/g, '')
|
||||
}
|
||||
|
||||
export async function copyDepositFieldValue(
|
||||
value: string | null | undefined,
|
||||
kind: 'card' | 'sheba',
|
||||
emptyMessage: string,
|
||||
) {
|
||||
const raw = String(value ?? '').trim()
|
||||
const normalized = normalizeDepositCopyValue(raw, kind)
|
||||
|
||||
if (!normalized) {
|
||||
message.warning(emptyMessage)
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
if (typeof navigator !== 'undefined' && navigator.clipboard?.writeText) {
|
||||
await navigator.clipboard.writeText(normalized)
|
||||
} else if (typeof document !== 'undefined') {
|
||||
const textarea = document.createElement('textarea')
|
||||
textarea.value = normalized
|
||||
textarea.setAttribute('readonly', 'true')
|
||||
textarea.style.position = 'fixed'
|
||||
textarea.style.left = '-9999px'
|
||||
document.body.appendChild(textarea)
|
||||
textarea.select()
|
||||
document.execCommand('copy')
|
||||
document.body.removeChild(textarea)
|
||||
} else {
|
||||
throw new Error('clipboard unavailable')
|
||||
}
|
||||
|
||||
message.info('کپی شد')
|
||||
} catch {
|
||||
message.error('کپی انجام نشد')
|
||||
}
|
||||
}
|
||||
@@ -113,27 +113,6 @@ function isToken() {
|
||||
return !!token
|
||||
}
|
||||
|
||||
function createUuid() {
|
||||
if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {
|
||||
return crypto.randomUUID()
|
||||
}
|
||||
if (typeof crypto !== 'undefined' && typeof crypto.getRandomValues === 'function') {
|
||||
const bytes = new Uint8Array(16)
|
||||
crypto.getRandomValues(bytes)
|
||||
bytes[6] = (bytes[6] & 0x0f) | 0x40
|
||||
bytes[8] = (bytes[8] & 0x3f) | 0x80
|
||||
const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, '0')).join('')
|
||||
return [
|
||||
hex.slice(0, 8),
|
||||
hex.slice(8, 12),
|
||||
hex.slice(12, 16),
|
||||
hex.slice(16, 20),
|
||||
hex.slice(20),
|
||||
].join('-')
|
||||
}
|
||||
return `${Date.now()}-${Math.floor(Math.random() * 1e9)}`
|
||||
}
|
||||
|
||||
export {
|
||||
getToken,
|
||||
setToken,
|
||||
@@ -144,6 +123,5 @@ export {
|
||||
removeFingerPrint,
|
||||
getIsActiveFingerprint,
|
||||
setFingerPrint,
|
||||
isToken,
|
||||
createUuid
|
||||
isToken
|
||||
}
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
export function resolveMetalTypeLabel(settingValue?: string | number | null): string {
|
||||
const value = settingValue?.toString().trim()
|
||||
return value ? value : 'طلا'
|
||||
}
|
||||
|
||||
export function resolveMeltedGoldLabel(settingValue?: string | number | null): string {
|
||||
const value = settingValue?.toString().trim()
|
||||
return value ? value : 'آبشده'
|
||||
}
|
||||
@@ -13,49 +13,6 @@ export function persianToEnglishDigits(value: string | number | null | undefined
|
||||
.replace(/٫/g, '.')
|
||||
}
|
||||
|
||||
/**
|
||||
* اعداد فارسی/عربی + جداکنندههای اعشار رایج ماشینحساب فارسی.
|
||||
* - `commaAsThousand` true (مبلغ): `,` / `،` حذف میشوند
|
||||
* - `commaAsThousand` false (وزن/اعشار): `,` / `،` هم → `.`
|
||||
*/
|
||||
export function normalizeDecimalInput(
|
||||
val: string | number | null | undefined,
|
||||
options?: { commaAsThousand?: boolean }
|
||||
): string {
|
||||
if (val == null || val === '') return ''
|
||||
|
||||
const commaAsThousand = options?.commaAsThousand ?? true
|
||||
let normalized = persianToEnglishDigits(String(val))
|
||||
|
||||
if (commaAsThousand) {
|
||||
normalized = normalized.replace(/[,،]/g, '')
|
||||
} else {
|
||||
normalized = normalized.replace(/[,،]/g, '.')
|
||||
}
|
||||
|
||||
normalized = normalized
|
||||
.replace(/\//g, '.')
|
||||
.replace(/[^\d.]/g, '')
|
||||
|
||||
const firstDot = normalized.indexOf('.')
|
||||
if (firstDot !== -1) {
|
||||
normalized =
|
||||
normalized.slice(0, firstDot + 1) +
|
||||
normalized.slice(firstDot + 1).replace(/\./g, '')
|
||||
}
|
||||
|
||||
return normalized
|
||||
}
|
||||
|
||||
export function parseDecimalInput(
|
||||
val: string | number | null | undefined,
|
||||
options?: { commaAsThousand?: boolean }
|
||||
): number {
|
||||
const normalized = normalizeDecimalInput(val, options)
|
||||
if (!normalized) return NaN
|
||||
return Number(normalized)
|
||||
}
|
||||
|
||||
export function shouldNormalizeInputDigits(options: {
|
||||
isPassword?: boolean
|
||||
type?: string
|
||||
@@ -70,16 +27,3 @@ export function shouldNormalizeInputDigits(options: {
|
||||
const mode = String(options.inputmode ?? '').trim().toLowerCase()
|
||||
return mode === 'numeric' || mode === 'decimal' || mode === 'number'
|
||||
}
|
||||
|
||||
/** فیلدهای وزن/مبلغ/عدد اعشاری که باید `/` را ممیز بگیرند */
|
||||
export function shouldNormalizeDecimalSeparators(options: {
|
||||
isPassword?: boolean
|
||||
type?: string
|
||||
inputmode?: string
|
||||
}): boolean {
|
||||
if (options.isPassword) return false
|
||||
const type = String(options.type ?? '').trim().toLowerCase()
|
||||
if (type === 'price' || type === 'number') return true
|
||||
const mode = String(options.inputmode ?? '').trim().toLowerCase()
|
||||
return mode === 'numeric' || mode === 'decimal' || mode === 'number'
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import {
|
||||
priceWssEnabled,
|
||||
shouldUsePricePolling,
|
||||
} from '@/utils/priceSocketState'
|
||||
import { applyBoardSpecialToLastPayload } from '@/utils/specialPricing'
|
||||
|
||||
const LAST_INTERVAL_MS = 10000
|
||||
|
||||
@@ -16,7 +15,7 @@ let lastSubscribers = 0
|
||||
|
||||
export const price = ref<Price>()
|
||||
export const lastPrice = ref<Price>()
|
||||
export const olderPrice = ref<number | null>(null)
|
||||
export const olderPrice = ref<number | undefined>(0)
|
||||
|
||||
let lastPriceSourceAt = 0
|
||||
let consecutivePriceFetchFailures = 0
|
||||
@@ -162,18 +161,14 @@ export async function getLastPrices(): Promise<boolean> {
|
||||
}
|
||||
|
||||
export function applyLastPricePayload(dataLast: Price) {
|
||||
const normalized = normalizePriceResponse(applyBoardSpecialToLastPayload(dataLast as any) as Price)
|
||||
const nextBuy = getTradeBuyPrice(normalized)
|
||||
const prevBuy = getTradeBuyPrice(lastPrice.value)
|
||||
|
||||
if (prevBuy > 0 && nextBuy > 0 && prevBuy !== nextBuy) {
|
||||
olderPrice.value = prevBuy
|
||||
const normalized = normalizePriceResponse(dataLast)
|
||||
if (lastPrice.value?.price_last != normalized.price_last) {
|
||||
olderPrice.value = lastPrice.value?.price_last
|
||||
}
|
||||
|
||||
lastPrice.value = normalized
|
||||
price.value = {
|
||||
...normalized,
|
||||
buy: nextBuy,
|
||||
buy: getTradeBuyPrice(normalized),
|
||||
sell: getTradeSellPrice(normalized),
|
||||
}
|
||||
|
||||
@@ -182,13 +177,9 @@ export function applyLastPricePayload(dataLast: Price) {
|
||||
}
|
||||
}
|
||||
|
||||
/** تغییر درصدی نسبت به قیمت خرید قبلی (آخرین بهروزرسانی) */
|
||||
export function percentPriceChanged() {
|
||||
const currentBuy = getTradeBuyPrice(lastPrice.value)
|
||||
const prevBuy = olderPrice.value
|
||||
if (!currentBuy || prevBuy == null || prevBuy <= 0 || prevBuy === currentBuy) {
|
||||
if (!olderPrice.value) {
|
||||
return 0
|
||||
}
|
||||
|
||||
return ((currentBuy - prevBuy) * 100) / prevBuy
|
||||
return ((lastPrice.value?.price_last! - olderPrice.value) * 100) / olderPrice.value
|
||||
}
|
||||
|
||||
@@ -9,10 +9,6 @@ import {
|
||||
priceStreamLifecycle,
|
||||
priceWssEnabled,
|
||||
} from '@/utils/priceSocketState'
|
||||
import {
|
||||
applyBoardSpecialToLastPayload,
|
||||
setSpecialPricingPayload,
|
||||
} from '@/utils/specialPricing'
|
||||
|
||||
export {
|
||||
priceSocketConnected,
|
||||
@@ -330,7 +326,7 @@ function handleLastPayload(payload: unknown) {
|
||||
return
|
||||
}
|
||||
|
||||
const last = applyBoardSpecialToLastPayload(payload as Price)
|
||||
const last = payload as Price
|
||||
if (last.price_last == null && last.price == null && last.buy == null) {
|
||||
return
|
||||
}
|
||||
@@ -348,42 +344,6 @@ function handleListPayload(payload: unknown) {
|
||||
applyProductsListFromStream(payload as Product[])
|
||||
}
|
||||
|
||||
function handleAppNotificationPayload(payload: unknown) {
|
||||
if (!payload || typeof payload !== 'object') {
|
||||
return
|
||||
}
|
||||
|
||||
touchStreamActivity()
|
||||
void applyAppNotificationFromStream(payload as Record<string, unknown>)
|
||||
}
|
||||
|
||||
function handleUnreadCountPayload(payload: unknown) {
|
||||
if (!payload || typeof payload !== 'object') {
|
||||
return
|
||||
}
|
||||
|
||||
touchStreamActivity()
|
||||
void applyUnreadCountFromStreamPayload(payload as Record<string, unknown>)
|
||||
}
|
||||
|
||||
async function applyAppNotificationFromStream(payload: Record<string, unknown>) {
|
||||
try {
|
||||
const { bumpUnreadFromStream } = await import('@/composables/useAppNotificationBadge')
|
||||
bumpUnreadFromStream(payload)
|
||||
} catch (error) {
|
||||
console.warn('App notification SSE apply failed', error)
|
||||
}
|
||||
}
|
||||
|
||||
async function applyUnreadCountFromStreamPayload(payload: Record<string, unknown>) {
|
||||
try {
|
||||
const { applyUnreadCountFromStream } = await import('@/composables/useAppNotificationBadge')
|
||||
applyUnreadCountFromStream(payload)
|
||||
} catch (error) {
|
||||
console.warn('Unread-count SSE apply failed', error)
|
||||
}
|
||||
}
|
||||
|
||||
function bindStreamEvents(source: EventSource) {
|
||||
source.addEventListener('last', (event) => {
|
||||
try {
|
||||
@@ -401,30 +361,6 @@ function bindStreamEvents(source: EventSource) {
|
||||
}
|
||||
})
|
||||
|
||||
source.addEventListener('app_notification', (event) => {
|
||||
try {
|
||||
handleAppNotificationPayload(JSON.parse(event.data))
|
||||
} catch (error) {
|
||||
console.warn('App notification SSE parse failed', error)
|
||||
}
|
||||
})
|
||||
|
||||
source.addEventListener('unread-count', (event) => {
|
||||
try {
|
||||
handleUnreadCountPayload(JSON.parse(event.data))
|
||||
} catch (error) {
|
||||
console.warn('Unread-count SSE parse failed', error)
|
||||
}
|
||||
})
|
||||
|
||||
source.addEventListener('special-pricing', (event) => {
|
||||
try {
|
||||
setSpecialPricingPayload(JSON.parse(event.data))
|
||||
} catch (error) {
|
||||
console.warn('Special-pricing SSE parse failed', error)
|
||||
}
|
||||
})
|
||||
|
||||
source.addEventListener('ping', () => {
|
||||
touchStreamActivity()
|
||||
})
|
||||
|
||||
@@ -39,7 +39,7 @@ export function getProductDisplayImage(product?: {
|
||||
return resolveProductImageSrc(product)
|
||||
}
|
||||
|
||||
import { formatGoldAmount, usePriceWithoutType } from '@/utils/usePrice'
|
||||
import { formatGoldAmount } from '@/utils/usePrice'
|
||||
|
||||
export function formatMetalTotal(
|
||||
metal: WalletMetalTotal,
|
||||
@@ -71,44 +71,3 @@ export function resolveAssetsRialValue(
|
||||
?.metal_totals?.[0]?.total_weight
|
||||
return cash + Number(metalWeight ?? 0) * liveGoldPrice
|
||||
}
|
||||
|
||||
export function getProductInventoryQuantity(
|
||||
cards: WalletInventoryCard[],
|
||||
productId?: number | null,
|
||||
mainWalletGold?: number | null,
|
||||
): number {
|
||||
const card = cards.find((item) => Number(item.product_id) === Number(productId))
|
||||
return card ? Number(card.quantity ?? 0) : Number(mainWalletGold ?? 0)
|
||||
}
|
||||
|
||||
export function formatProductWalletBalanceText(
|
||||
product:
|
||||
| { id?: number; title?: string | null; unit?: string | null; group_type?: string | null }
|
||||
| null,
|
||||
cards: WalletInventoryCard[] = [],
|
||||
mainWalletGold?: number | null,
|
||||
): string {
|
||||
const card = cards.find((item) => Number(item.product_id) === Number(product?.id))
|
||||
const quantity = card ? Number(card.quantity ?? 0) : Number(mainWalletGold ?? 0)
|
||||
const unit = card?.unit ?? product?.unit?.trim() ?? 'گرم'
|
||||
const title = product?.title?.trim() || 'محصول'
|
||||
const formatted = unit === 'عدد'
|
||||
? usePriceWithoutType(quantity, false)
|
||||
: formatGoldAmount(quantity)
|
||||
|
||||
return `موجودی کیف ${title}: ${formatted} ${unit}`
|
||||
}
|
||||
|
||||
export function getCashWalletBalance(
|
||||
walletInfo?: Record<string, unknown> | null,
|
||||
wallets?: unknown,
|
||||
): number {
|
||||
const direct = Number(walletInfo?.cash ?? walletInfo?.count_cash_wallets ?? 0)
|
||||
if (direct) return direct
|
||||
|
||||
if (Array.isArray(wallets)) {
|
||||
return wallets.reduce((sum, wallet) => sum + Number(wallet?.cash ?? 0), 0)
|
||||
}
|
||||
|
||||
return Number((wallets as { cash?: number } | null)?.cash ?? 0)
|
||||
}
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
export type ProductCashFeeSource = {
|
||||
cash_fee_buy?: number | null
|
||||
cash_fee_sell?: number | null
|
||||
cash_fee_buy_is_percent?: boolean | null
|
||||
cash_fee_sell_is_percent?: boolean | null
|
||||
}
|
||||
|
||||
/** 0.5 => 0.5% ، 5 => 5% — همیشه عدد درصد */
|
||||
export function resolveCashFeePercentRatio(percentValue?: number | null) {
|
||||
const offset = Number(percentValue ?? 0)
|
||||
if (!offset || !Number.isFinite(offset)) {
|
||||
return 0
|
||||
}
|
||||
|
||||
return offset / 100
|
||||
}
|
||||
|
||||
/** @deprecated از resolveCashFeePercentRatio استفاده کنید */
|
||||
export function resolveFeePercentRatio(percentValue?: number | null) {
|
||||
return resolveCashFeePercentRatio(percentValue)
|
||||
}
|
||||
|
||||
export function resolveProductCashFeeRial(
|
||||
feeValue: number | null | undefined,
|
||||
isPercent: boolean | null | undefined,
|
||||
basePriceRial: number,
|
||||
) {
|
||||
const raw = Number(feeValue ?? 0)
|
||||
if (!raw || !Number.isFinite(raw)) {
|
||||
return 0
|
||||
}
|
||||
|
||||
if (!isPercent) {
|
||||
return Math.round(raw)
|
||||
}
|
||||
|
||||
const base = Number(basePriceRial)
|
||||
if (!base || base <= 0) {
|
||||
return 0
|
||||
}
|
||||
|
||||
return Math.round(Math.abs(base * resolveCashFeePercentRatio(raw)))
|
||||
}
|
||||
|
||||
export function resolveProductCashFeeBuyRial(product: ProductCashFeeSource, basePriceRial: number) {
|
||||
const baseFee = resolveProductCashFeeRial(
|
||||
product.cash_fee_buy,
|
||||
product.cash_fee_buy_is_percent,
|
||||
basePriceRial,
|
||||
)
|
||||
const special = Number((product as any).special_profit_buy ?? 0)
|
||||
return baseFee + (Number.isFinite(special) ? Math.round(special) : 0)
|
||||
}
|
||||
|
||||
export function resolveProductCashFeeSellRial(product: ProductCashFeeSource, basePriceRial: number) {
|
||||
const baseFee = resolveProductCashFeeRial(
|
||||
product.cash_fee_sell,
|
||||
product.cash_fee_sell_is_percent,
|
||||
basePriceRial,
|
||||
)
|
||||
const special = Number((product as any).special_profit_sell ?? 0)
|
||||
return baseFee + (Number.isFinite(special) ? Math.round(special) : 0)
|
||||
}
|
||||
|
||||
export function formatProductCashFeeLabel(
|
||||
feeValue: number | null | undefined,
|
||||
isPercent?: boolean | null,
|
||||
) {
|
||||
const raw = Number(feeValue ?? 0)
|
||||
if (!raw) {
|
||||
return '۰'
|
||||
}
|
||||
|
||||
if (isPercent) {
|
||||
const text = Number.isInteger(raw) ? String(raw) : String(parseFloat(raw.toFixed(4)))
|
||||
return `${text}%`
|
||||
}
|
||||
|
||||
return `${raw} ریال`
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
/** دستهبندی یکسان محصول — همتراز با khaneghi_user */
|
||||
export const PRODUCT_CATEGORY_ABSHODE = 'آبشده'
|
||||
|
||||
export const LEGACY_GROUP_KATOD = 'کاتد مس'
|
||||
|
||||
export const LEGACY_MELTED_GROUP_TYPES = [LEGACY_GROUP_KATOD] as const
|
||||
|
||||
export function normalizeProductGroupType(groupType?: string | null) {
|
||||
return (groupType ?? '').trim()
|
||||
}
|
||||
|
||||
/** محصول آبشدهای — قیمت از مظنه اپ (مگر قیمت ثابت / مرجع) */
|
||||
export function isMeltedTradeGroup(groupType?: string | null) {
|
||||
const group = normalizeProductGroupType(groupType)
|
||||
return group === PRODUCT_CATEGORY_ABSHODE
|
||||
|| LEGACY_MELTED_GROUP_TYPES.includes(group as typeof LEGACY_MELTED_GROUP_TYPES[number])
|
||||
}
|
||||
|
||||
export interface QuantityTradeProductSource {
|
||||
group_type?: string | null
|
||||
trade_by_quantity?: boolean | number | null
|
||||
}
|
||||
|
||||
export function usesQuantityTrade(product?: QuantityTradeProductSource | null) {
|
||||
if (!product) {
|
||||
return false
|
||||
}
|
||||
|
||||
return product.trade_by_quantity === true || Number(product.trade_by_quantity) === 1
|
||||
}
|
||||
|
||||
export function isMetalCommodityGroup(groupType?: string | null) {
|
||||
const group = normalizeProductGroupType(groupType)
|
||||
return group === 'مس' || group === 'نقره'
|
||||
}
|
||||
|
||||
export type MeltedPriceSource = 'app' | 'fixed' | 'reference'
|
||||
|
||||
export function resolveMeltedPriceSource(product?: {
|
||||
reading_method?: string | null
|
||||
direct_price?: number | null
|
||||
} | null): MeltedPriceSource {
|
||||
if (product?.reading_method) {
|
||||
return 'reference'
|
||||
}
|
||||
if (Number(product?.direct_price) === 1) {
|
||||
return 'fixed'
|
||||
}
|
||||
return 'app'
|
||||
}
|
||||
|
||||
/** محصول با پرچم صریح «قیمت اپ» */
|
||||
export function isAppPriceProduct(product?: {
|
||||
app_price?: boolean | number | null
|
||||
reading_method?: string | null
|
||||
} | null) {
|
||||
if (!product || product.reading_method) {
|
||||
return false
|
||||
}
|
||||
return product.app_price === true || Number(product.app_price) === 1
|
||||
}
|
||||
|
||||
export function isMeltedProductUsingAppPrice(product?: {
|
||||
group_type?: string | null
|
||||
reading_method?: string | null
|
||||
direct_price?: number | null
|
||||
trade_by_quantity?: boolean | number | null
|
||||
price?: number | null
|
||||
} | null) {
|
||||
if (!product || resolveMeltedPriceSource(product) !== 'app') {
|
||||
return false
|
||||
}
|
||||
|
||||
if (isMeltedTradeGroup(product.group_type)) {
|
||||
return true
|
||||
}
|
||||
|
||||
if (!usesQuantityTrade(product)) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (Number(product.direct_price) === 1) {
|
||||
return false
|
||||
}
|
||||
|
||||
return Number(product.price ?? 0) <= 0
|
||||
}
|
||||
@@ -1,12 +1,25 @@
|
||||
import { useSettingsStore } from '@/store/settingsStore'
|
||||
|
||||
export function getWeightUnit() {
|
||||
return useSettingsStore().tradeWeightUnit
|
||||
function normalizeGroupType(value: unknown): string {
|
||||
return String(value ?? '').trim().toLowerCase()
|
||||
}
|
||||
|
||||
export function formatCashWalletBalanceText(
|
||||
cashFormatted: string | number,
|
||||
_groupType?: string | null,
|
||||
) {
|
||||
return `موجودی کیف پول: ${cashFormatted} ریال`
|
||||
export function isKatodMesGroup(groupType: unknown): boolean {
|
||||
const type = normalizeGroupType(groupType)
|
||||
return type.includes('کاتد') || type.includes('katod')
|
||||
}
|
||||
|
||||
export function isMaftolMesGroup(groupType: unknown): boolean {
|
||||
const type = normalizeGroupType(groupType)
|
||||
return type.includes('مفتول') || type.includes('maftol')
|
||||
}
|
||||
|
||||
export function isShamshMesGroup(groupType: unknown, title?: unknown): boolean {
|
||||
const type = normalizeGroupType(groupType)
|
||||
const name = normalizeGroupType(title)
|
||||
|
||||
return (
|
||||
type.includes('شمش') ||
|
||||
type.includes('shamsh') ||
|
||||
name.includes('شمش') ||
|
||||
name.includes('shamsh')
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,120 +0,0 @@
|
||||
import type { Product } from '@/models/products'
|
||||
import { usePriceWithoutType } from '@/utils/usePrice'
|
||||
import { persianToEnglishDigits } from '@/utils/persianDigits'
|
||||
|
||||
type LimitProduct = Pick<Product, 'order_limit_enabled' | 'min_order_cash' | 'max_order_cash'> | null | undefined
|
||||
|
||||
function parseOrderLimitCash(value: unknown): number | undefined {
|
||||
if (value === undefined || value === null || value === '') {
|
||||
return undefined
|
||||
}
|
||||
|
||||
const raw = persianToEnglishDigits(String(value).trim().replace(/[,\s٬]/g, ''))
|
||||
if (raw === '') {
|
||||
return undefined
|
||||
}
|
||||
|
||||
const num = Number(raw)
|
||||
if (!Number.isFinite(num) || num < 0) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
return Math.trunc(num)
|
||||
}
|
||||
|
||||
function isOrderLimitFlagEnabled(value: unknown): boolean {
|
||||
if (value === true || value === 1) {
|
||||
return true
|
||||
}
|
||||
|
||||
if (typeof value === 'string') {
|
||||
const normalized = value.trim().toLowerCase()
|
||||
return normalized === '1' || normalized === 'true'
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
export function productOrderLimitEnabled(product?: LimitProduct): boolean {
|
||||
if (!product) {
|
||||
return false
|
||||
}
|
||||
|
||||
const min = parseOrderLimitCash(product.min_order_cash)
|
||||
const max = parseOrderLimitCash(product.max_order_cash)
|
||||
if (min != null || max != null) {
|
||||
return true
|
||||
}
|
||||
|
||||
return isOrderLimitFlagEnabled(product.order_limit_enabled)
|
||||
}
|
||||
|
||||
export function productMinOrderCash(product?: LimitProduct, isBuy = true, defaultBuyMin = 500_000): number {
|
||||
const min = parseOrderLimitCash(product?.min_order_cash)
|
||||
if (productOrderLimitEnabled(product) && min != null) {
|
||||
return min
|
||||
}
|
||||
|
||||
return isBuy ? defaultBuyMin : 0
|
||||
}
|
||||
|
||||
export function productMaxOrderCash(product?: LimitProduct): number | undefined {
|
||||
const max = parseOrderLimitCash(product?.max_order_cash)
|
||||
if (productOrderLimitEnabled(product) && max != null) {
|
||||
return max
|
||||
}
|
||||
|
||||
return undefined
|
||||
}
|
||||
|
||||
export function productCashValidationMessage(
|
||||
product: LimitProduct,
|
||||
goldCash: number | string | undefined,
|
||||
isBuy: boolean,
|
||||
formatPrice: (value: number) => string = usePriceWithoutType
|
||||
): string {
|
||||
if (goldCash === '' || goldCash === undefined) {
|
||||
return ''
|
||||
}
|
||||
|
||||
const cash = parseOrderLimitCash(goldCash) ?? 0
|
||||
const min = productMinOrderCash(product, isBuy)
|
||||
const max = productMaxOrderCash(product)
|
||||
|
||||
if (max != null && cash > max) {
|
||||
return `حداکثر مبلغ این محصول ${formatPrice(max)} ریال است`
|
||||
}
|
||||
|
||||
if (min > 0 && cash < min) {
|
||||
if (productOrderLimitEnabled(product) && parseOrderLimitCash(product?.min_order_cash) != null) {
|
||||
return `حداقل مبلغ این محصول ${formatPrice(min)} ریال است`
|
||||
}
|
||||
|
||||
return `حداقل مبلغ طلا جهت ${isBuy ? 'خرید' : 'فروش'} ${formatPrice(min)} ریال می باشد.`
|
||||
}
|
||||
|
||||
return ''
|
||||
}
|
||||
|
||||
export function validateProductOrderLimitForm(form: {
|
||||
order_limit_enabled?: boolean
|
||||
min_order_cash?: number | string | null
|
||||
max_order_cash?: number | string | null
|
||||
}): string | null {
|
||||
if (!form.order_limit_enabled) return null
|
||||
|
||||
const min = form.min_order_cash
|
||||
const max = form.max_order_cash
|
||||
const hasMin = min != null && min !== ''
|
||||
const hasMax = max != null && max !== ''
|
||||
|
||||
if (!hasMin && !hasMax) {
|
||||
return 'با فعال بودن محدودیت مبلغ سفارش، حداقل یکی از حداقل یا حداکثر مبلغ باید وارد شود'
|
||||
}
|
||||
|
||||
if (hasMin && hasMax && Number(min) > Number(max)) {
|
||||
return 'حداقل مبلغ نمیتواند بیشتر از حداکثر باشد'
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
@@ -1,257 +1,93 @@
|
||||
import type { Product } from '@/models/products'
|
||||
import { getTradeBuyPrice, getTradeSellPrice, lastPrice } from '@/utils/price'
|
||||
import { resolveProductCashFeeBuyRial, resolveProductCashFeeSellRial } from '@/utils/productCashFee'
|
||||
import {
|
||||
isAppPriceProduct,
|
||||
isMeltedProductUsingAppPrice,
|
||||
isMeltedTradeGroup,
|
||||
isMetalCommodityGroup,
|
||||
usesQuantityTrade,
|
||||
} from '@/utils/productCategories'
|
||||
|
||||
/**
|
||||
* قیمتگیری محصول — همتراز با khaneghi_user:
|
||||
* آبشده / قیمتاپ از مظنه زنده؛ قیمت ثابت و مرجع از سرور.
|
||||
* قیمتگیری ماژولار محصول در حالت فروشگاهی (is_store=true).
|
||||
*
|
||||
* منبع حقیقت قیمت و وضعیت نمایش، سرور است: `/customer/product/list` و رویداد SSE
|
||||
* `list` هر دو قیمت هر محصول (`price`/`price_profit`) و `show` را محاسبهشده میفرستند.
|
||||
* این ماژول فقط همان قیمت سرور را میخواند و فقط برای آبشده وقتی قیمت سرور صفر است
|
||||
* به قیمت زندهٔ مرجع (`lastPrice`) fallback میکند — هیچجا قیمت سرور بازنویسی نمیشود.
|
||||
*/
|
||||
|
||||
function productUsesLastPriceIfZero(product: Product): boolean {
|
||||
return Boolean(product.use_last_price_if_zero)
|
||||
const MELTED_GROUP = 'آبشده'
|
||||
|
||||
export function isMeltedProduct(product?: Product | null): boolean {
|
||||
return product?.group_type === MELTED_GROUP
|
||||
}
|
||||
|
||||
function hasReferenceReadingMethod(product: Product): boolean {
|
||||
return Boolean(product.reading_method)
|
||||
}
|
||||
|
||||
function hasProductUnitWeight(product?: Product | null) {
|
||||
if (!product || isMeltedTradeGroup(product.group_type)) {
|
||||
return false
|
||||
}
|
||||
return Number(product.amount ?? 0) > 0
|
||||
}
|
||||
|
||||
function productPriceAmountFactor(product?: Product | null) {
|
||||
if (!product || product.reading_method) {
|
||||
return 1
|
||||
}
|
||||
if (isAppPriceProduct(product)) {
|
||||
const amount = Number(product.amount ?? 0)
|
||||
return amount > 0 ? amount : 1
|
||||
}
|
||||
if (hasProductUnitWeight(product) && Number(product.direct_price ?? 0) === 0) {
|
||||
const amount = Number(product.amount ?? 0)
|
||||
return amount > 0 ? amount : 1
|
||||
}
|
||||
return 1
|
||||
}
|
||||
|
||||
function getReferenceProductBaseBuyPrice(product: Product): number {
|
||||
const storedUnit = Number(product.price ?? 0)
|
||||
const useLast = productUsesLastPriceIfZero(product)
|
||||
|
||||
if (!useLast) {
|
||||
return storedUnit > 0 ? storedUnit : 0
|
||||
}
|
||||
|
||||
return storedUnit
|
||||
}
|
||||
|
||||
export function resolvePriceOffsetRatio(offsetPercent?: number | null) {
|
||||
const offset = Number(offsetPercent ?? 0)
|
||||
if (!offset) {
|
||||
return 0
|
||||
}
|
||||
|
||||
if (Math.abs(offset) > 0 && Math.abs(offset) < 1) {
|
||||
return offset
|
||||
}
|
||||
|
||||
return offset / 100
|
||||
}
|
||||
|
||||
export function applyPriceOffsetPercent(basePrice: number, offsetPercent?: number | null) {
|
||||
const ratio = resolvePriceOffsetRatio(offsetPercent)
|
||||
if (!ratio) {
|
||||
return basePrice
|
||||
}
|
||||
|
||||
return Math.round(basePrice * (1 + ratio))
|
||||
}
|
||||
|
||||
/** قیمت پایه بدون کارمزد */
|
||||
/** قیمت پایهٔ خرید (بدون کارمزد) — قیمت سرور، با fallback زندهٔ آبشده وقتی سرور صفر است */
|
||||
export function getProductBaseBuyPrice(product?: Product | null): number {
|
||||
if (!product) {
|
||||
return 0
|
||||
}
|
||||
|
||||
if (isMeltedProductUsingAppPrice(product) || isAppPriceProduct(product)) {
|
||||
const apiPrice = Number(product.price ?? 0)
|
||||
const useLast = productUsesLastPriceIfZero(product)
|
||||
|
||||
if (!useLast) {
|
||||
const liveBuy = getTradeBuyPrice(lastPrice.value)
|
||||
if (liveBuy > 0) {
|
||||
return applyPriceOffsetPercent(liveBuy, product.price_offset_percent)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
if (apiPrice > 0) {
|
||||
return apiPrice
|
||||
}
|
||||
const serverPrice = Number(product.price ?? 0)
|
||||
if (serverPrice > 0) {
|
||||
return serverPrice
|
||||
}
|
||||
|
||||
if (isMeltedProduct(product)) {
|
||||
const liveBuy = getTradeBuyPrice(lastPrice.value)
|
||||
if (liveBuy > 0) {
|
||||
return applyPriceOffsetPercent(liveBuy, product.price_offset_percent)
|
||||
const amount = Number(product.amount ?? 0)
|
||||
return amount > 0 ? liveBuy * amount : liveBuy
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
if (isMeltedTradeGroup(product.group_type)) {
|
||||
return Number(product.price ?? 0)
|
||||
}
|
||||
|
||||
if (isMetalCommodityGroup(product.group_type)) {
|
||||
return Number(product.price_profit ?? 0) + Number(product.price ?? 0)
|
||||
}
|
||||
|
||||
if (hasReferenceReadingMethod(product)) {
|
||||
return getReferenceProductBaseBuyPrice(product)
|
||||
}
|
||||
|
||||
return Number(product.price ?? 0)
|
||||
return 0
|
||||
}
|
||||
|
||||
/** قیمت خرید نمایشی */
|
||||
/** قیمت خرید نمایشی محصول (همان مقداری که در لیست و صفحهٔ محصول نشان داده میشود) */
|
||||
export function getProductBuyPrice(product?: Product | null): number {
|
||||
if (!product) {
|
||||
return 0
|
||||
}
|
||||
|
||||
const base = getProductBaseBuyPrice(product)
|
||||
if (base <= 0) {
|
||||
return 0
|
||||
}
|
||||
|
||||
const fee = resolveProductCashFeeBuyRial(product, base)
|
||||
const withFee = base + fee
|
||||
|
||||
if (isAppPriceProduct(product)) {
|
||||
return withFee * productPriceAmountFactor(product)
|
||||
}
|
||||
|
||||
if (
|
||||
isMeltedProductUsingAppPrice(product)
|
||||
|| isMeltedTradeGroup(product.group_type)
|
||||
|| isMetalCommodityGroup(product.group_type)
|
||||
) {
|
||||
return withFee
|
||||
}
|
||||
|
||||
if (usesQuantityTrade(product) && hasProductUnitWeight(product)) {
|
||||
return withFee * productPriceAmountFactor(product)
|
||||
}
|
||||
|
||||
if (usesQuantityTrade(product)) {
|
||||
return withFee
|
||||
}
|
||||
|
||||
return withFee * productPriceAmountFactor(product)
|
||||
return base + Number(product?.cash_fee_buy ?? 0)
|
||||
}
|
||||
|
||||
/** قیمت پایه فروش */
|
||||
/** قیمت پایهٔ فروش (بدون کارمزد) — قیمت فروش سرور، با fallback زندهٔ آبشده */
|
||||
export function getProductBaseSellPrice(product?: Product | null): number {
|
||||
if (!product) {
|
||||
return 0
|
||||
}
|
||||
|
||||
if (isMeltedProductUsingAppPrice(product) || isAppPriceProduct(product)) {
|
||||
const apiPrice = Number(product.price ?? 0)
|
||||
const useLast = productUsesLastPriceIfZero(product)
|
||||
|
||||
if (!useLast) {
|
||||
const liveSell = getTradeSellPrice(lastPrice.value)
|
||||
if (liveSell > 0) {
|
||||
return applyPriceOffsetPercent(liveSell, product.price_offset_percent)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
if (apiPrice > 0) {
|
||||
return apiPrice
|
||||
}
|
||||
|
||||
const liveSell = getTradeSellPrice(lastPrice.value)
|
||||
if (liveSell > 0) {
|
||||
return applyPriceOffsetPercent(liveSell, product.price_offset_percent)
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
if (isMeltedTradeGroup(product.group_type)) {
|
||||
return Number(product.sellPrice ?? product.price ?? 0)
|
||||
}
|
||||
|
||||
const serverSell = Number(product.sellPrice ?? 0)
|
||||
if (serverSell > 0) {
|
||||
return serverSell
|
||||
}
|
||||
|
||||
if (isMeltedProduct(product)) {
|
||||
const liveSell = getTradeSellPrice(lastPrice.value)
|
||||
if (liveSell > 0) {
|
||||
const amount = Number(product.amount ?? 0)
|
||||
return amount > 0 ? liveSell * amount : liveSell
|
||||
}
|
||||
}
|
||||
|
||||
return getProductBaseBuyPrice(product)
|
||||
}
|
||||
|
||||
/** قیمت فروش نمایشی */
|
||||
/** قیمت فروش نمایشی محصول */
|
||||
export function getProductSellPrice(product?: Product | null): number {
|
||||
if (!product) {
|
||||
return 0
|
||||
}
|
||||
|
||||
const base = getProductBaseSellPrice(product)
|
||||
if (base <= 0) {
|
||||
return 0
|
||||
}
|
||||
|
||||
if (isAppPriceProduct(product)) {
|
||||
const withFee = base - resolveProductCashFeeSellRial(product, base)
|
||||
return withFee * productPriceAmountFactor(product)
|
||||
}
|
||||
|
||||
if (isMeltedProductUsingAppPrice(product) || isMeltedTradeGroup(product.group_type)) {
|
||||
return base - resolveProductCashFeeSellRial(product, base)
|
||||
}
|
||||
|
||||
if (usesQuantityTrade(product) && hasProductUnitWeight(product)) {
|
||||
const withFee = base - resolveProductCashFeeSellRial(product, base)
|
||||
return withFee * productPriceAmountFactor(product)
|
||||
}
|
||||
|
||||
if (usesQuantityTrade(product)) {
|
||||
return base - resolveProductCashFeeSellRial(product, base)
|
||||
}
|
||||
|
||||
return base - resolveProductCashFeeSellRial(product, base)
|
||||
return base - Number(product?.cash_fee_sell ?? 0)
|
||||
}
|
||||
|
||||
/** محصول وقتی قیمت پایهٔ معتبری ندارد، غیرفعال (غیرقابل معامله) است */
|
||||
export function isProductPriceInactive(product?: Product | null): boolean {
|
||||
if (!product) {
|
||||
return true
|
||||
}
|
||||
|
||||
if (
|
||||
hasReferenceReadingMethod(product)
|
||||
&& !productUsesLastPriceIfZero(product)
|
||||
&& product.reference_provider_active === false
|
||||
) {
|
||||
return true
|
||||
}
|
||||
|
||||
return getProductBaseBuyPrice(product) <= 0
|
||||
}
|
||||
|
||||
/**
|
||||
* نمایش محصول در فروشگاه — اولویت با `show` سرور.
|
||||
* آبشدهٔ قیمتاپ با مظنه زنده حتی اگر show هنوز false باشد.
|
||||
* فقط برای آبشدهای که قیمت سرورش هنوز نرسیده، با قیمت زنده تکمیل میکنیم.
|
||||
*/
|
||||
export function isProductVisible(product?: Product | null): boolean {
|
||||
if (!product || product.active === false) {
|
||||
@@ -262,7 +98,6 @@ export function isProductVisible(product?: Product | null): boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
return isMeltedProductUsingAppPrice(product) && getProductBaseBuyPrice(product) > 0
|
||||
// سازگاری: آبشدهای که سرور هنوز قیمت نداده ولی قیمت زنده موجود است
|
||||
return isMeltedProduct(product) && getProductBaseBuyPrice(product) > 0
|
||||
}
|
||||
|
||||
export { isMeltedTradeGroup, isMeltedProductUsingAppPrice } from '@/utils/productCategories'
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
import type { Product } from '@/models/products'
|
||||
|
||||
type TradeOpenProduct = Pick<Product, 'open_buy' | 'open_sell'> | null | undefined
|
||||
|
||||
function asBool(value: boolean | number | null | undefined) {
|
||||
return value === true || Number(value) === 1
|
||||
}
|
||||
|
||||
export function isProductBuyOpen(product: TradeOpenProduct) {
|
||||
if (!product) return true
|
||||
return asBool(product?.open_buy)
|
||||
}
|
||||
|
||||
export function isProductSellOpen(product: TradeOpenProduct) {
|
||||
if (!product) return true
|
||||
return asBool(product?.open_sell)
|
||||
}
|
||||
|
||||
export function isAnyProductTradeOpen(product: TradeOpenProduct) {
|
||||
return isProductBuyOpen(product) || isProductSellOpen(product)
|
||||
}
|
||||
|
||||
export function isProductTradeOpen(product: TradeOpenProduct, isBuy: boolean) {
|
||||
return isBuy ? isProductBuyOpen(product) : isProductSellOpen(product)
|
||||
}
|
||||
|
||||
/** تب اولیه با توجه به query و وضعیت باز/بسته خرید و فروش */
|
||||
export function resolveProductTradeIsBuy(product: TradeOpenProduct, routeState?: string | null) {
|
||||
const wantSell = routeState === 'sell'
|
||||
const wantBuy = routeState === 'buy'
|
||||
const buyOpen = isProductBuyOpen(product)
|
||||
const sellOpen = isProductSellOpen(product)
|
||||
|
||||
if (wantSell && sellOpen) return false
|
||||
if (wantBuy && buyOpen) return true
|
||||
if (buyOpen) return true
|
||||
if (sellOpen) return false
|
||||
return true
|
||||
}
|
||||
|
||||
export function productTradeClosedMessage(isBuy: boolean) {
|
||||
return isBuy
|
||||
? 'خرید این محصول در این لحظه مقدور نمیباشد'
|
||||
: 'فروش این محصول در این لحظه مقدور نمیباشد'
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
import { getRawAppConfig } from '@/config/app-config'
|
||||
import type { AppConfig } from '@/config/types'
|
||||
|
||||
export type ProjectId = 'ghatre' | 'kashkool' | 'boursecu'
|
||||
|
||||
export interface ProjectBranding {
|
||||
id: ProjectId
|
||||
nameFa: string
|
||||
heroGradient: string
|
||||
accentColor: string
|
||||
borderAccent: string
|
||||
fundLabel: string
|
||||
fundHeroBg: string
|
||||
idCardLabel: string
|
||||
buyPriceLabel: string
|
||||
defaultRoute: string
|
||||
showHomeRoute: boolean
|
||||
referralDomain: string
|
||||
}
|
||||
|
||||
const PROJECT_BRANDING: Record<ProjectId, ProjectBranding> = {
|
||||
ghatre: {
|
||||
id: 'ghatre',
|
||||
nameFa: 'قطره',
|
||||
heroGradient: 'linear-gradient(145deg, #521620 0%, #7a2a1e 40%, #521620 100%)',
|
||||
accentColor: '#521620',
|
||||
borderAccent: '#521620',
|
||||
fundLabel: 'قلک',
|
||||
fundHeroBg: '#EFCED9',
|
||||
idCardLabel: 'شناسه شما در قطره',
|
||||
buyPriceLabel: 'قیمت خرید از قطره',
|
||||
defaultRoute: 'buyProduct',
|
||||
showHomeRoute: false,
|
||||
referralDomain: 'ghatre.gold',
|
||||
},
|
||||
kashkool: {
|
||||
id: 'kashkool',
|
||||
nameFa: 'کشکول',
|
||||
heroGradient: 'linear-gradient(145deg, #a72b77 0%, #711d4d 40%, #a72b77 100%)',
|
||||
accentColor: '#a72b77',
|
||||
borderAccent: '#a72b77',
|
||||
fundLabel: 'دارایی ها',
|
||||
fundHeroBg: '',
|
||||
idCardLabel: 'شناسه شما در کشکول',
|
||||
buyPriceLabel: 'قیمت خرید از کشکول',
|
||||
defaultRoute: 'home',
|
||||
showHomeRoute: true,
|
||||
referralDomain: 'kh.kashkolgold.ir',
|
||||
},
|
||||
boursecu: {
|
||||
id: 'boursecu',
|
||||
nameFa: 'بورسکو',
|
||||
heroGradient: 'linear-gradient(145deg, #1e2229 0%, #374151 40%, #1e2229 100%)',
|
||||
accentColor: '#1e2229',
|
||||
borderAccent: '#1e2229',
|
||||
fundLabel: 'دارایی ها',
|
||||
fundHeroBg: '',
|
||||
idCardLabel: 'شناسه شما',
|
||||
buyPriceLabel: 'قیمت خرید',
|
||||
defaultRoute: 'home',
|
||||
showHomeRoute: true,
|
||||
referralDomain: '',
|
||||
},
|
||||
}
|
||||
|
||||
function normalizeProjectName(value: unknown): string {
|
||||
return String(value ?? '')
|
||||
.trim()
|
||||
.toLowerCase()
|
||||
.replace(/\s+/g, '')
|
||||
}
|
||||
|
||||
export function resolveProjectNameFromConfig(raw: AppConfig | null | undefined): string {
|
||||
if (!raw) return ''
|
||||
|
||||
const candidates: unknown[] = [
|
||||
raw.name,
|
||||
typeof raw.user === 'object' && raw.user !== null && !Array.isArray(raw.user)
|
||||
? (raw.user as Record<string, unknown>).name
|
||||
: undefined,
|
||||
Array.isArray(raw.user) && raw.user[0] && typeof raw.user[0] === 'object'
|
||||
? (raw.user[0] as Record<string, unknown>).name
|
||||
: undefined,
|
||||
]
|
||||
|
||||
for (const value of candidates) {
|
||||
const normalized = normalizeProjectName(value)
|
||||
if (normalized) return normalized
|
||||
}
|
||||
|
||||
return ''
|
||||
}
|
||||
|
||||
function getProjectNameRaw(): string {
|
||||
return resolveProjectNameFromConfig(getRawAppConfig())
|
||||
}
|
||||
|
||||
function matchesProjectName(name: string, aliases: string[]): boolean {
|
||||
return aliases.some((alias) => name.includes(normalizeProjectName(alias)))
|
||||
}
|
||||
|
||||
export function getProjectId(): ProjectId {
|
||||
const name = getProjectNameRaw()
|
||||
|
||||
if (name === 'ghatreh') {
|
||||
return 'ghatre'
|
||||
}
|
||||
|
||||
if (name === 'kashkolgold') {
|
||||
return 'kashkool'
|
||||
}
|
||||
|
||||
if (matchesProjectName(name, ['boursecu', 'bourse', 'بورسکو', 'بورس'])) {
|
||||
return 'boursecu'
|
||||
}
|
||||
|
||||
if (matchesProjectName(name, ['ghatre', 'qatre', 'قطره'])) {
|
||||
return 'ghatre'
|
||||
}
|
||||
|
||||
if (matchesProjectName(name, ['kashkool', 'kashkol', 'کشکول'])) {
|
||||
return 'kashkool'
|
||||
}
|
||||
|
||||
return 'kashkool'
|
||||
}
|
||||
|
||||
export function isGhatreProject(): boolean {
|
||||
return getProjectId() === 'ghatre'
|
||||
}
|
||||
|
||||
export function isKashkoolProject(): boolean {
|
||||
return getProjectId() === 'kashkool'
|
||||
}
|
||||
|
||||
export function isBoursecuProject(): boolean {
|
||||
return getProjectId() === 'boursecu'
|
||||
}
|
||||
|
||||
export function getProjectBranding(): ProjectBranding {
|
||||
const id = getProjectId()
|
||||
const defaults = PROJECT_BRANDING[id]
|
||||
|
||||
return {
|
||||
...defaults,
|
||||
nameFa: defaults.nameFa,
|
||||
accentColor: defaults.accentColor,
|
||||
borderAccent: defaults.borderAccent,
|
||||
heroGradient: defaults.heroGradient,
|
||||
}
|
||||
}
|
||||
|
||||
export function getProjectDefaultRoute(): string {
|
||||
return getProjectBranding().defaultRoute
|
||||
}
|
||||
@@ -1,65 +1,30 @@
|
||||
import { ref } from 'vue'
|
||||
import { useSettingsStore } from '@/store/settingsStore'
|
||||
import { getSettings } from '@/api/configuration'
|
||||
|
||||
export const serviceFeePercentage = ref<number>(0.01)
|
||||
|
||||
/**
|
||||
* @deprecated منطق کارمزد دیگر به این کلید وابسته نیست.
|
||||
* قانون واحد: کاربر هر فیلدی را که پر کند دقیقاً همان معامله میشود و کارمزد از سمت دیگر کسر میشود:
|
||||
* • ریال قفل (کاربر مبلغ زده) → مبلغ دقیق، کارمزد از طلا.
|
||||
* • گرم قفل (کاربر وزن زده) → وزن دقیق، کارمزد از ریال.
|
||||
*/
|
||||
/** true = مبالغ رند: فروش → ریال دقیق (کارمزد از طلا)؛ خرید → وزن دقیق (کارمزد از ریال) */
|
||||
export const feeDeductFromGold = ref(false)
|
||||
|
||||
/** آخرین فیلدی که کاربر مستقیم ویرایش کرده — مبنای بهروزرسانی هنگام تغییر قیمت */
|
||||
export type TradeInputLock = 'gram' | 'rial' | null
|
||||
|
||||
/** ریال قفل است؟ (کاربر مبلغ ریالی را مستقیم وارد کرده) → کارمزد از طلا */
|
||||
export function isRialLocked(inputLock?: TradeInputLock): boolean {
|
||||
return inputLock === 'rial'
|
||||
}
|
||||
|
||||
/** حداکثر اعشار ذخیره/ارسال به سرور (مطابق orders.amount) */
|
||||
export const TRADE_GRAM_STORAGE_DECIMALS = 10
|
||||
|
||||
/** حداکثر اعشار نمایش به کاربر در اپ */
|
||||
export const TRADE_GRAM_DISPLAY_DECIMALS = 8
|
||||
|
||||
/** زیر این مقدار (گرم)، معادل گرم در فیلد ورودی نشان داده نمیشود */
|
||||
export const TRADE_GRAM_MIN_DISPLAY_GRAMS = 0.0001
|
||||
|
||||
function trimTrailingDecimalZeros(fixed: string): string {
|
||||
if (!fixed.includes('.')) {
|
||||
return fixed
|
||||
}
|
||||
|
||||
const trimmed = fixed.replace(/\.?0+$/, '')
|
||||
return trimmed === '' ? '0' : trimmed
|
||||
}
|
||||
|
||||
function formatTradeGramFixedText(grams: number): string {
|
||||
return trimTrailingDecimalZeros(grams.toFixed(TRADE_GRAM_DISPLAY_DECIMALS))
|
||||
}
|
||||
|
||||
export function normalizeOrderGoldAmount(grams?: number | null): number {
|
||||
const value = Number(grams ?? 0)
|
||||
if (!Number.isFinite(value) || value === 0) return 0
|
||||
return parseFloat(value.toFixed(TRADE_GRAM_STORAGE_DECIMALS))
|
||||
}
|
||||
|
||||
/** نمایش گرم در UI — همیشه اعشاری، بدون نماد e */
|
||||
export function formatTradeGramDisplay(grams?: number | null): string {
|
||||
export function formatTradeGramDisplay(grams?: number | null): number {
|
||||
const value = Number(grams ?? 0)
|
||||
if (!Number.isFinite(value) || value === 0) return '0'
|
||||
return formatTradeGramFixedText(value)
|
||||
}
|
||||
|
||||
/** مقدار فیلد گرم هنگام تبدیل از ریال — مقادیر خیلی ریز خالی میمانند */
|
||||
export function formatTradeGramInputValue(grams?: number | null): string | undefined {
|
||||
const value = Number(grams ?? 0)
|
||||
if (!Number.isFinite(value) || value <= 0) return undefined
|
||||
if (value < TRADE_GRAM_MIN_DISPLAY_GRAMS) return undefined
|
||||
return formatTradeGramFixedText(value)
|
||||
if (!Number.isFinite(value)) return 0
|
||||
return parseFloat(value.toFixed(TRADE_GRAM_DISPLAY_DECIMALS))
|
||||
}
|
||||
|
||||
function feeRate() {
|
||||
@@ -68,12 +33,8 @@ function feeRate() {
|
||||
|
||||
export async function loadServiceFeeFromSettings() {
|
||||
try {
|
||||
const settingsStore = useSettingsStore()
|
||||
if (!settingsStore.loaded) {
|
||||
await settingsStore.fetchSettings()
|
||||
}
|
||||
const settings = settingsStore.settings
|
||||
if (settings?.length) {
|
||||
const settings = await getSettings()
|
||||
if (settings && Array.isArray(settings)) {
|
||||
const feeSetting = settings.find(
|
||||
(s) => s?.key === 'fee_service_charge_percentage' && s?.is_active === true
|
||||
)
|
||||
@@ -106,36 +67,44 @@ export function calcGoldAmountFromTargetRial(rialAmount: number, unitPriceRial:
|
||||
return normalizeOrderGoldAmount(rialAmount / unitPriceRial)
|
||||
}
|
||||
|
||||
/**
|
||||
* کاربر گرم را قفل کرده → وزن دقیق است و کارمزد از ریال کسر میشود.
|
||||
* خرید: مبلغ پرداختی = وزن × مظنه × (۱ + کارمزد).
|
||||
* فروش: مبلغ دریافتی = وزن × مظنه × (۱ − کارمزد).
|
||||
*/
|
||||
/** وقتی کاربر گرم را قفل کرده — ریال نمایشی/قابل پرداخت از همان گرم */
|
||||
export function calcRialFromLockedGram(displayGram: number, unitPriceRial: number, isBuy: boolean) {
|
||||
const grams = Number(displayGram)
|
||||
const unit = Number(unitPriceRial)
|
||||
if (!grams || !unit) return 0
|
||||
const fee = feeRate()
|
||||
|
||||
return isBuy
|
||||
? Math.round(grams * unit * (1 + fee))
|
||||
: Math.round(grams * unit * (1 - fee))
|
||||
if (isBuy) {
|
||||
if (feeDeductFromGold.value) {
|
||||
return Math.round(grams * unit * (1 + fee))
|
||||
}
|
||||
return Math.round(grams * unit)
|
||||
}
|
||||
|
||||
if (feeDeductFromGold.value) {
|
||||
return Math.round(grams * unit)
|
||||
}
|
||||
return Math.round(grams * unit * (1 - fee))
|
||||
}
|
||||
|
||||
/**
|
||||
* کاربر ریال را قفل کرده → مبلغ دقیق است و کارمزد از طلا کسر میشود.
|
||||
* خرید: طلای دریافتی = (مبلغ ÷ مظنه) × (۱ − کارمزد) (خالص واریزی به کیف).
|
||||
* فروش: طلای کسرشونده از کیف = (مبلغ ÷ مظنه) × (۱ + کارمزد) (شامل کارمزد).
|
||||
*/
|
||||
/** وقتی کاربر ریال را قفل کرده — گرم نمایشی از همان مبلغ */
|
||||
export function calcGramFromLockedRial(rialAmount: number, unitPriceRial: number, isBuy: boolean) {
|
||||
const rial = Number(rialAmount)
|
||||
const unit = Number(unitPriceRial)
|
||||
if (!rial || !unit) return 0
|
||||
const fee = feeRate()
|
||||
|
||||
return isBuy
|
||||
? (rial / unit) * (1 - fee)
|
||||
: (rial / unit) * (1 + fee)
|
||||
if (isBuy) {
|
||||
if (feeDeductFromGold.value) {
|
||||
return rial / (unit * (1 + fee))
|
||||
}
|
||||
return (rial / unit) * (1 - fee)
|
||||
}
|
||||
|
||||
if (feeDeductFromGold.value) {
|
||||
return rial / unit
|
||||
}
|
||||
return rial / (unit * (1 - fee))
|
||||
}
|
||||
|
||||
/** مبلغ ریالی قفلشده توسط کاربر — برای ارسال به سرور */
|
||||
@@ -149,11 +118,7 @@ export function calcTradeTargetCash(
|
||||
return Math.round(cash)
|
||||
}
|
||||
|
||||
/**
|
||||
* مبلغ نهایی قابل پرداخت (خرید) یا دریافت (فروش) به ریال.
|
||||
* • ریال قفل (targetRialCash موجود) → دقیقاً همان مبلغ (کارمزد از طلاست، روی ریال اثر ندارد).
|
||||
* • گرم قفل → کارمزد از ریال: خرید = ارزش + کارمزد، فروش = ارزش − کارمزد.
|
||||
*/
|
||||
/** مبلغ نهایی قابل پرداخت (خرید) یا دریافت (فروش) به ریال */
|
||||
export function calcPayablePriceRial(
|
||||
finalPriceRial: number,
|
||||
feeInRial: number,
|
||||
@@ -161,21 +126,17 @@ export function calcPayablePriceRial(
|
||||
targetRialCash?: number | null
|
||||
) {
|
||||
if (targetRialCash != null && Number(targetRialCash) > 0) {
|
||||
return Math.round(Number(targetRialCash))
|
||||
return Number(targetRialCash)
|
||||
}
|
||||
|
||||
return isBuy
|
||||
? Math.round(finalPriceRial + feeInRial)
|
||||
: Math.max(0, Math.round(finalPriceRial - feeInRial))
|
||||
if (feeDeductFromGold.value) {
|
||||
if (isBuy) return finalPriceRial + feeInRial
|
||||
return finalPriceRial
|
||||
}
|
||||
return isBuy ? finalPriceRial : Math.max(0, finalPriceRial - feeInRial)
|
||||
}
|
||||
|
||||
/**
|
||||
* وزن مبنای معامله که به سرور ارسال میشود.
|
||||
* • گرم قفل → همان وزن واردشده (دقیق).
|
||||
* • ریال قفل خرید → طلای خالص دریافتی = (مبلغ ÷ مظنه) × (۱ − کارمزد).
|
||||
* • ریال قفل فروش → وزن معادلِ مبلغ = مبلغ ÷ مظنه (کارمزد جدا از این وزن کسر میشود).
|
||||
* در حالت ریالقفل، سرور مقدار را از target_cash بازمحاسبه میکند؛ این مقدار صرفاً نمایشی/پشتیبان است.
|
||||
*/
|
||||
/** وزن ارسالی به سرور */
|
||||
export function calcOrderGoldAmount(
|
||||
goldValue?: number | null,
|
||||
goldCash?: number | null,
|
||||
@@ -186,267 +147,60 @@ export function calcOrderGoldAmount(
|
||||
const gold = Number(goldValue ?? 0)
|
||||
const cash = Number(goldCash ?? 0)
|
||||
const unit = Number(unitPriceRial ?? 0)
|
||||
const fee = feeRate()
|
||||
|
||||
if (inputLock === 'rial' && cash > 0 && unit > 0) {
|
||||
if (isBuy) {
|
||||
return normalizeOrderGoldAmount((cash / unit) * (1 - fee))
|
||||
if (isBuy && inputLock === 'rial' && cash > 0 && unit > 0) {
|
||||
if (feeDeductFromGold.value) {
|
||||
const fee = feeRate()
|
||||
return normalizeOrderGoldAmount(cash / (unit * (1 + fee)))
|
||||
}
|
||||
return normalizeOrderGoldAmount(cash / unit)
|
||||
}
|
||||
|
||||
if (!isBuy && feeDeductFromGold.value) {
|
||||
if (inputLock === 'rial' && cash > 0 && unit > 0) {
|
||||
return calcGoldAmountFromTargetRial(cash, unit)
|
||||
}
|
||||
if (inputLock !== 'rial') {
|
||||
return normalizeOrderGoldAmount(gold)
|
||||
}
|
||||
const targetCash = calcSellTargetCash(goldCash, goldValue, unitPriceRial, inputLock)
|
||||
if (targetCash != null && unit > 0) {
|
||||
return calcGoldAmountFromTargetRial(targetCash, unit)
|
||||
}
|
||||
}
|
||||
|
||||
return normalizeOrderGoldAmount(gold)
|
||||
}
|
||||
|
||||
/** مبلغ ریالی دقیق (فروش یا خرید) وقتی کاربر ریال را قفل کرده — همان چیزی که به سرور بهعنوان target_cash میرود */
|
||||
/** مبلغ ریالی دقیق دریافتی در فروش (فقط وقتی کاربر با ریال وارد کرده) */
|
||||
export function calcSellTargetCash(
|
||||
goldCash?: number | null,
|
||||
goldValue?: number | null,
|
||||
unitPriceRial?: number,
|
||||
inputLock?: TradeInputLock
|
||||
) {
|
||||
if (inputLock !== 'rial') return undefined
|
||||
if (!feeDeductFromGold.value) return undefined
|
||||
if (inputLock === 'gram') return undefined
|
||||
|
||||
const cash = Number(goldCash ?? 0)
|
||||
if (cash <= 0) return undefined
|
||||
if (inputLock === 'rial') return Math.round(cash)
|
||||
|
||||
const gold = Number(goldValue ?? 0)
|
||||
const unit = Number(unitPriceRial ?? 0)
|
||||
if (gold > 0 && unit > 0) {
|
||||
const derived = Math.round(gold * unit)
|
||||
if (Math.abs(derived - Math.round(cash)) <= 1) return undefined
|
||||
}
|
||||
return Math.round(cash)
|
||||
}
|
||||
|
||||
/**
|
||||
* کل طلای کسرشونده از کیف در فروش.
|
||||
* • ریال قفل → وزن معادل + کارمزد (کارمزد از طلا).
|
||||
* • گرم قفل → فقط همان وزن (کارمزد از ریال کسر میشود، نه از طلا).
|
||||
*/
|
||||
export function calcSellGoldDebit(
|
||||
goldValue?: number | null,
|
||||
feeInGrams?: number | null,
|
||||
inputLock?: TradeInputLock
|
||||
) {
|
||||
/** کل طلای کسرشونده از کیف در فروش (شامل کارمزد وقتی fee_deduct_from_gold روشن است) */
|
||||
export function calcSellGoldDebit(goldValue?: number | null, feeInGrams?: number | null) {
|
||||
const gold = Number(goldValue ?? 0)
|
||||
const fee = Number(feeInGrams ?? 0)
|
||||
if (isRialLocked(inputLock)) {
|
||||
if (feeDeductFromGold.value) {
|
||||
return parseFloat((gold + fee).toFixed(4))
|
||||
}
|
||||
return gold
|
||||
}
|
||||
|
||||
export type FeeDeductionAsset = 'gold' | 'rial'
|
||||
|
||||
/** کارمزد از کدام دارایی کسر میشود — فقط تابع قفل ورودی است (نه خرید/فروش، نه کلید تنظیمات) */
|
||||
export function feeDeductedFrom(inputLock?: TradeInputLock): FeeDeductionAsset {
|
||||
return isRialLocked(inputLock) ? 'gold' : 'rial'
|
||||
}
|
||||
|
||||
/** طلای خالص واریزی به کیف پس از کسر کارمزد (فقط خرید) */
|
||||
export function calcNetGoldCredited(
|
||||
orderGoldAmount: number,
|
||||
feeInGrams: number,
|
||||
isBuy: boolean,
|
||||
inputLock?: TradeInputLock
|
||||
): number {
|
||||
if (!isBuy) return orderGoldAmount
|
||||
// ریال قفل: orderGoldAmount از قبل خالص است. گرم قفل: کارمزد از ریال است، پس همان وزن دریافت میشود.
|
||||
return normalizeOrderGoldAmount(orderGoldAmount)
|
||||
}
|
||||
|
||||
/** مبلغ پایه معامله قبل از اعمال کارمزد ریالی (خرید با افزودن کارمزد به ریال) */
|
||||
export function calcTradeBasePriceRial(orderGoldAmount: number, unitPriceRial: number) {
|
||||
return Math.round(Number(orderGoldAmount) * Number(unitPriceRial))
|
||||
}
|
||||
|
||||
export interface TradeConfirmRow {
|
||||
label: string
|
||||
gram?: number | null
|
||||
rial?: number | null
|
||||
bold?: boolean
|
||||
minus?: boolean
|
||||
plus?: boolean
|
||||
dividerBefore?: boolean
|
||||
}
|
||||
|
||||
export interface TradeConfirmSection {
|
||||
heading: string
|
||||
rows: TradeConfirmRow[]
|
||||
footnote?: string
|
||||
}
|
||||
|
||||
export interface TradeConfirmBreakdown {
|
||||
sections: TradeConfirmSection[]
|
||||
formHint: string
|
||||
}
|
||||
|
||||
function hasTradeFee(feeInGrams: number, feeInRial: number) {
|
||||
return feeInGrams > 0 || feeInRial > 0
|
||||
}
|
||||
|
||||
function grossGoldFromRial(rial: number, unitPriceRial: number) {
|
||||
if (!rial || !unitPriceRial) return 0
|
||||
return normalizeOrderGoldAmount(rial / unitPriceRial)
|
||||
}
|
||||
|
||||
/**
|
||||
* جزئیات مدال تأیید — دو بخش «کسر از کیف» و «واریز به کیف».
|
||||
* فقط بر پایهٔ قفل ورودی تصمیم میگیرد:
|
||||
* • ریال قفل → مبلغ دقیق، کارمزد از طلا.
|
||||
* • گرم قفل → وزن دقیق، کارمزد از ریال.
|
||||
*/
|
||||
export function buildTradeConfirmBreakdown(params: {
|
||||
isBuy: boolean
|
||||
inputLock: TradeInputLock
|
||||
orderGoldAmount: number
|
||||
feeInGrams: number
|
||||
feeInRial: number
|
||||
payablePrice: number
|
||||
unitPriceRial: number
|
||||
sellGoldDebit?: number
|
||||
}): TradeConfirmBreakdown {
|
||||
const {
|
||||
isBuy,
|
||||
inputLock,
|
||||
orderGoldAmount,
|
||||
feeInGrams,
|
||||
feeInRial,
|
||||
payablePrice,
|
||||
unitPriceRial,
|
||||
sellGoldDebit,
|
||||
} = params
|
||||
const hasFee = hasTradeFee(feeInGrams, feeInRial)
|
||||
const rialLocked = isRialLocked(inputLock)
|
||||
const weight = orderGoldAmount
|
||||
|
||||
if (!isBuy) {
|
||||
// ————— فروش —————
|
||||
if (rialLocked) {
|
||||
// مبلغ دقیق دریافتی، کارمزد از طلا
|
||||
const debit = sellGoldDebit ?? parseFloat((weight + feeInGrams).toFixed(4))
|
||||
const goldRows: TradeConfirmRow[] = hasFee
|
||||
? [
|
||||
{ label: 'وزن معادل مبلغ', gram: weight },
|
||||
{ label: 'کارمزد', gram: feeInGrams, minus: true },
|
||||
{ label: 'جمع کسر از کیف طلا', gram: debit, bold: true, dividerBefore: true },
|
||||
]
|
||||
: [{ label: 'وزن فروش', gram: weight, bold: true }]
|
||||
|
||||
return {
|
||||
sections: [
|
||||
{ heading: 'از کیف طلا کسر میشود', rows: goldRows },
|
||||
{
|
||||
heading: 'به کیف پول واریز میشود',
|
||||
rows: [{ label: 'مبلغ دریافتی', rial: payablePrice, bold: true }],
|
||||
footnote: hasFee
|
||||
? 'دقیقاً همان مبلغی که وارد کردید واریز میشود؛ کارمزد فقط از طلای کیف کسر میشود.'
|
||||
: undefined,
|
||||
},
|
||||
],
|
||||
formHint: hasFee
|
||||
? `${payablePrice.toLocaleString('fa-IR')} ریال دریافت — ${formatTradeGramDisplay(debit)} گرم از کیف کسر میشود (شامل ${formatTradeGramDisplay(feeInGrams)} گرم کارمزد)`
|
||||
: `${payablePrice.toLocaleString('fa-IR')} ریال دریافت`,
|
||||
}
|
||||
}
|
||||
|
||||
// گرم قفل: وزن دقیق، کارمزد از ریال
|
||||
const grossSellRial = Math.round(weight * unitPriceRial)
|
||||
const cashRows: TradeConfirmRow[] = hasFee
|
||||
? [
|
||||
{ label: 'ارزش فروش', rial: grossSellRial },
|
||||
{ label: 'کارمزد', rial: feeInRial, minus: true },
|
||||
{ label: 'خالص دریافتی', rial: payablePrice, bold: true, dividerBefore: true },
|
||||
]
|
||||
: [{ label: 'مبلغ دریافتی', rial: payablePrice, bold: true }]
|
||||
|
||||
return {
|
||||
sections: [
|
||||
{ heading: 'از کیف طلا کسر میشود', rows: [{ label: 'وزن فروش', gram: weight, bold: true }] },
|
||||
{
|
||||
heading: 'به کیف پول واریز میشود',
|
||||
rows: cashRows,
|
||||
footnote: hasFee ? 'کارمزد از مبلغ ریالی دریافتی کم شده است.' : undefined,
|
||||
},
|
||||
],
|
||||
formHint: hasFee
|
||||
? `${formatTradeGramDisplay(weight)} گرم فروش — ${feeInRial.toLocaleString('fa-IR')} ریال کارمزد از مبلغ دریافتی کسر میشود`
|
||||
: `${formatTradeGramDisplay(weight)} گرم فروش — ${payablePrice.toLocaleString('fa-IR')} ریال به کیف پول`,
|
||||
}
|
||||
}
|
||||
|
||||
// ————— خرید —————
|
||||
if (rialLocked) {
|
||||
// مبلغ دقیق پرداختی، کارمزد از طلا
|
||||
const grossGram = grossGoldFromRial(payablePrice, unitPriceRial)
|
||||
const feeGram = parseFloat(Math.max(0, grossGram - weight).toFixed(4))
|
||||
const goldRows: TradeConfirmRow[] = hasFee
|
||||
? [
|
||||
{ label: 'معادل طلای خام', gram: grossGram },
|
||||
{ label: 'کارمزد', gram: feeGram, minus: true },
|
||||
{ label: 'خالص واریزی به کیف طلا', gram: weight, bold: true, dividerBefore: true },
|
||||
]
|
||||
: [{ label: 'واریزی به کیف طلا', gram: weight, bold: true }]
|
||||
|
||||
return {
|
||||
sections: [
|
||||
{
|
||||
heading: 'از کیف پول کسر میشود',
|
||||
rows: [{ label: 'مبلغ پرداختی', rial: payablePrice, bold: true }],
|
||||
footnote: 'دقیقاً همان مبلغی که وارد کردید؛ کارمزد جداگانه اضافه نمیشود.',
|
||||
},
|
||||
{
|
||||
heading: 'به کیف طلا واریز میشود',
|
||||
rows: goldRows,
|
||||
footnote: hasFee ? 'کارمزد از وزن طلای دریافتی کسر شده است.' : undefined,
|
||||
},
|
||||
],
|
||||
formHint: hasFee
|
||||
? `${payablePrice.toLocaleString('fa-IR')} ریال پرداخت — ${formatTradeGramDisplay(weight)} گرم واریز (کارمزد از طلا کسر شد)`
|
||||
: `${payablePrice.toLocaleString('fa-IR')} ریال پرداخت`,
|
||||
}
|
||||
}
|
||||
|
||||
// گرم قفل خرید: وزن دقیق، کارمزد از ریال
|
||||
const basePriceRial = calcTradeBasePriceRial(weight, unitPriceRial)
|
||||
const cashRows: TradeConfirmRow[] = hasFee
|
||||
? [
|
||||
{ label: `ارزش ${formatTradeGramDisplay(weight)} گرم`, rial: basePriceRial },
|
||||
{ label: 'کارمزد', rial: feeInRial, plus: true },
|
||||
{ label: 'جمع پرداختی', rial: payablePrice, bold: true, dividerBefore: true },
|
||||
]
|
||||
: [{ label: 'مبلغ پرداختی', rial: payablePrice, bold: true }]
|
||||
|
||||
return {
|
||||
sections: [
|
||||
{
|
||||
heading: 'از کیف پول کسر میشود',
|
||||
rows: cashRows,
|
||||
footnote: hasFee ? 'کارمزد به مبلغ پرداختی اضافه شده است.' : undefined,
|
||||
},
|
||||
{
|
||||
heading: 'به کیف طلا واریز میشود',
|
||||
rows: [{ label: 'دقیقاً', gram: weight, bold: true }],
|
||||
},
|
||||
],
|
||||
formHint: hasFee
|
||||
? `${payablePrice.toLocaleString('fa-IR')} ریال (شامل ${feeInRial.toLocaleString('fa-IR')} ریال کارمزد) — ${formatTradeGramDisplay(weight)} گرم واریز`
|
||||
: `${payablePrice.toLocaleString('fa-IR')} ریال پرداخت`,
|
||||
}
|
||||
}
|
||||
|
||||
/** @deprecated از buildTradeConfirmBreakdown استفاده کنید */
|
||||
export function buildTradeFeeConfirmCopy(params: {
|
||||
isBuy: boolean
|
||||
inputLock: TradeInputLock
|
||||
orderGoldAmount: number
|
||||
feeInGrams: number
|
||||
feeInRial: number
|
||||
payablePrice: number
|
||||
unitPriceRial: number
|
||||
sellGoldDebit?: number
|
||||
}) {
|
||||
const breakdown = buildTradeConfirmBreakdown(params)
|
||||
return {
|
||||
feeDeductFrom: feeDeductedFrom(params.inputLock),
|
||||
feeDeductionLabel: '',
|
||||
feeDeductionHint: breakdown.formHint,
|
||||
payableNote: breakdown.sections.at(-1)?.footnote ?? '',
|
||||
showNetGoldRow: false,
|
||||
showSellDebitRow: false,
|
||||
showBasePriceRow: false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
import { ref } from 'vue'
|
||||
|
||||
export type SpecialPricingRule = {
|
||||
product_id?: number
|
||||
package_id: number
|
||||
title: string
|
||||
profit_buy: number
|
||||
profit_sell: number
|
||||
show_product: boolean
|
||||
}
|
||||
|
||||
export type SpecialPricingPayload = {
|
||||
enabled?: boolean
|
||||
products?: SpecialPricingRule[]
|
||||
board?: SpecialPricingRule | null
|
||||
}
|
||||
|
||||
const state = ref<{
|
||||
enabled: boolean
|
||||
byProduct: Record<number, SpecialPricingRule>
|
||||
board: SpecialPricingRule | null
|
||||
}>({
|
||||
enabled: false,
|
||||
byProduct: {},
|
||||
board: null,
|
||||
})
|
||||
|
||||
export function setSpecialPricingPayload(payload?: SpecialPricingPayload | null) {
|
||||
if (!payload || !payload.enabled) {
|
||||
state.value = { enabled: false, byProduct: {}, board: null }
|
||||
return
|
||||
}
|
||||
|
||||
const byProduct: Record<number, SpecialPricingRule> = {}
|
||||
for (const row of payload.products ?? []) {
|
||||
const pid = Number(row.product_id ?? 0)
|
||||
if (pid > 0) byProduct[pid] = row
|
||||
}
|
||||
|
||||
state.value = {
|
||||
enabled: true,
|
||||
byProduct,
|
||||
board: payload.board ?? null,
|
||||
}
|
||||
}
|
||||
|
||||
export function getSpecialPricingState() {
|
||||
return state
|
||||
}
|
||||
|
||||
/** اگر سرور قبلاً special_pricing نزده، اختلاف تابلو را روی last اعمال کن */
|
||||
export function applyBoardSpecialToLastPayload<T extends Record<string, any>>(payload: T): T {
|
||||
if (!payload || typeof payload !== 'object') return payload
|
||||
if (payload.special_pricing) return payload
|
||||
|
||||
const board = state.value.board
|
||||
if (!state.value.enabled || !board) return payload
|
||||
|
||||
const buyExtra = Number(board.profit_buy ?? 0)
|
||||
const sellExtra = Number(board.profit_sell ?? 0)
|
||||
if (buyExtra <= 0 && sellExtra <= 0) return payload
|
||||
|
||||
const next = { ...payload } as T & Record<string, any>
|
||||
if (Number(next.buy ?? 0) > 0 && buyExtra > 0) {
|
||||
next.buy = Number(next.buy) + buyExtra
|
||||
}
|
||||
if (Number(next.sell ?? 0) > 0 && sellExtra > 0) {
|
||||
next.sell = Math.max(0, Number(next.sell) - sellExtra)
|
||||
}
|
||||
if (Number(next.price_last ?? 0) > 0 && buyExtra > 0) {
|
||||
next.price_last = Number(next.price_last) + buyExtra
|
||||
}
|
||||
next.special_pricing = {
|
||||
package_id: board.package_id,
|
||||
title: board.title,
|
||||
profit_buy: buyExtra,
|
||||
profit_sell: sellExtra,
|
||||
}
|
||||
return next
|
||||
}
|
||||
@@ -1,16 +1,5 @@
|
||||
import { ref } from 'vue'
|
||||
import type { DepositGuideVars } from '@/utils/depositGuideText'
|
||||
import {
|
||||
DEFAULT_DEPOSIT_GUIDE_TEXT,
|
||||
getCustomerNameFromUser,
|
||||
getDepositGuideVarsFromSettings,
|
||||
getDepositSupportMessageTemplate,
|
||||
getRenderedDepositGuideText,
|
||||
getRenderedDepositSupportMessage,
|
||||
renderDepositGuideText,
|
||||
renderDepositSupportMessageText,
|
||||
} from '@/utils/depositGuideText'
|
||||
import { useSettingsStore } from '@/store/settingsStore'
|
||||
import { getSettings } from '@/api/configuration'
|
||||
|
||||
export type SupportMessengerType =
|
||||
| 'bale'
|
||||
@@ -19,271 +8,14 @@ export type SupportMessengerType =
|
||||
| 'rubika'
|
||||
| 'eitaa'
|
||||
| 'soroush'
|
||||
| 'call'
|
||||
| 'sms'
|
||||
|
||||
export interface SupportMessengerSettings {
|
||||
messengers?: SupportMessengerEntry[]
|
||||
messenger?: SupportMessengerType | string
|
||||
messengerId?: string
|
||||
messengerText?: string
|
||||
depositSupportMessageText?: string
|
||||
depositAccountHolder?: string
|
||||
depositCardNumber?: string
|
||||
depositSheba?: string
|
||||
depositSmsSupportNumber?: string
|
||||
}
|
||||
|
||||
export interface SupportMessengerEntry {
|
||||
messenger: string
|
||||
id: string
|
||||
}
|
||||
|
||||
export interface ResolvedSupportMessengerEntry extends SupportMessengerEntry {
|
||||
label: string
|
||||
icon: string
|
||||
accent: string
|
||||
url: string
|
||||
}
|
||||
|
||||
const VALID_SUPPORT_MESSENGERS = new Set([
|
||||
'bale',
|
||||
'telegram',
|
||||
'whatsapp',
|
||||
'rubika',
|
||||
'eitaa',
|
||||
'soroush',
|
||||
'call',
|
||||
'sms',
|
||||
])
|
||||
|
||||
const PHONE_NATIVE_MESSENGERS = new Set(['call', 'sms'])
|
||||
|
||||
export const supportMessengerSettings = ref<SupportMessengerSettings>({})
|
||||
export const supportMessengerPickerOpen = ref(false)
|
||||
/** لنگر منوی انتخاب پیامرسان — FAB یا دکمه داخل مودال شارژ */
|
||||
export const supportMessengerPickerAnchor = ref<HTMLElement | null>(null)
|
||||
|
||||
export function parseSupportMessengersJson(raw?: string | null): SupportMessengerEntry[] {
|
||||
const value = (raw ?? '').trim()
|
||||
if (!value) return []
|
||||
|
||||
try {
|
||||
const decoded = JSON.parse(value)
|
||||
if (!Array.isArray(decoded)) return []
|
||||
|
||||
return decoded
|
||||
.map((row) => ({
|
||||
messenger: String(row?.messenger ?? '').trim().toLowerCase(),
|
||||
id: String(row?.id ?? '').trim(),
|
||||
}))
|
||||
.filter((row) => VALID_SUPPORT_MESSENGERS.has(row.messenger) && row.id !== '')
|
||||
} catch {
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
export function resolveSupportMessengersFromSettings(
|
||||
settings: Array<{ key?: string; value?: unknown }>,
|
||||
): SupportMessengerEntry[] {
|
||||
// اگر کلید جدید در تنظیمات هست (حتی خالی/null)، فقط همان لیست معتبر است — legacy بله را برنگردان
|
||||
const hasMessengersKey = settings.some((row) => row?.key === 'support_messengers')
|
||||
if (hasMessengersKey) {
|
||||
return parseSupportMessengersJson(getSupportSettingValue(settings, 'support_messengers'))
|
||||
}
|
||||
|
||||
const legacyMessenger = getSupportSettingValue(settings, 'support_messenger').toLowerCase()
|
||||
const legacyId = getSupportSettingValue(settings, 'support_messenger_id')
|
||||
if (!legacyId) return []
|
||||
|
||||
const messenger = legacyMessenger || 'bale'
|
||||
if (!VALID_SUPPORT_MESSENGERS.has(messenger)) return []
|
||||
|
||||
return [{ messenger, id: legacyId }]
|
||||
}
|
||||
|
||||
/** فقط موارد موجود در `support_messengers` — تماس/پیامک خودکار اضافه نمیشوند */
|
||||
export function resolveSupportMessengerEntries(
|
||||
settings?: SupportMessengerSettings,
|
||||
messageText?: string,
|
||||
): ResolvedSupportMessengerEntry[] {
|
||||
const resolved = settings ?? supportMessengerSettings.value
|
||||
const text = (messageText ?? '').trim()
|
||||
// فقط لیست resolveشده؛ قبل از load خالی است تا legacy دوباره دکمه نسازد
|
||||
const source = Array.isArray(resolved.messengers) ? resolved.messengers : []
|
||||
|
||||
return source
|
||||
.map((entry) => {
|
||||
const meta = resolveSupportMessengerMeta(entry.messenger)
|
||||
const url = buildSupportMessengerUrl(entry.messenger, entry.id, text)
|
||||
if (!url) return null
|
||||
return {
|
||||
...entry,
|
||||
...meta,
|
||||
url,
|
||||
}
|
||||
})
|
||||
.filter((entry): entry is ResolvedSupportMessengerEntry => entry !== null)
|
||||
}
|
||||
|
||||
/** @deprecated از depositGuideText استفاده کنید */
|
||||
export const DEFAULT_SUPPORT_MESSENGER_TEXT = DEFAULT_DEPOSIT_GUIDE_TEXT
|
||||
|
||||
export interface SupportMessengerMeta {
|
||||
label: string
|
||||
icon: string
|
||||
accent: string
|
||||
}
|
||||
|
||||
export const SUPPORT_MESSENGER_META: Record<string, SupportMessengerMeta> = {
|
||||
bale: { label: 'بله', icon: 'vuesax-linear:messages-2', accent: '#16a34a' },
|
||||
telegram: { label: 'تلگرام', icon: 'vuesax-linear:send-2', accent: '#0ea5e9' },
|
||||
whatsapp: { label: 'واتساپ', icon: 'vuesax-linear:whatsapp', accent: '#22c55e' },
|
||||
rubika: { label: 'روبیکا', icon: 'vuesax-linear:messages-2', accent: '#7c3aed' },
|
||||
eitaa: { label: 'ایتا', icon: 'vuesax-linear:messages-2', accent: '#f59e0b' },
|
||||
soroush: { label: 'سروش', icon: 'vuesax-linear:messages-2', accent: '#2563eb' },
|
||||
call: { label: 'تماس', icon: 'vuesax-linear:call-calling', accent: '#10b981' },
|
||||
sms: { label: 'پیامک', icon: 'vuesax-linear:sms', accent: '#3b82f6' },
|
||||
}
|
||||
|
||||
export const DEFAULT_SUPPORT_MESSENGER_META: SupportMessengerMeta = {
|
||||
label: 'پشتیبانی',
|
||||
icon: 'vuesax-linear:headphone',
|
||||
accent: '#334155',
|
||||
}
|
||||
|
||||
export function resolveSupportMessengerMeta(messenger?: string): SupportMessengerMeta {
|
||||
const type = (messenger ?? '').trim().toLowerCase()
|
||||
return SUPPORT_MESSENGER_META[type] ?? DEFAULT_SUPPORT_MESSENGER_META
|
||||
}
|
||||
|
||||
export function resolveSupportMessengerLink(
|
||||
messenger?: string,
|
||||
messengerId?: string,
|
||||
fallbackLink = '',
|
||||
messageText?: string,
|
||||
) {
|
||||
const fromSettings = buildSupportMessengerUrl(messenger, messengerId, messageText)
|
||||
return fromSettings || fallbackLink
|
||||
}
|
||||
|
||||
export function getDepositGuideVarsFromSupportSettings(
|
||||
settings: SupportMessengerSettings,
|
||||
): DepositGuideVars {
|
||||
return {
|
||||
accountHolder: settings.depositAccountHolder,
|
||||
cardNumber: settings.depositCardNumber,
|
||||
sheba: settings.depositSheba,
|
||||
customerName: getCustomerNameFromUser(),
|
||||
}
|
||||
}
|
||||
|
||||
export function resolveDepositGuideText(settings?: SupportMessengerSettings): string {
|
||||
try {
|
||||
const fromStore = getRenderedDepositGuideText()
|
||||
if (fromStore.trim()) return fromStore
|
||||
} catch {
|
||||
// settings store may not be ready
|
||||
}
|
||||
|
||||
const resolved = settings ?? supportMessengerSettings.value
|
||||
const template = resolved.messengerText?.trim() || DEFAULT_DEPOSIT_GUIDE_TEXT
|
||||
const vars = resolved.depositAccountHolder
|
||||
? getDepositGuideVarsFromSupportSettings(resolved)
|
||||
: getDepositGuideVarsFromSettings()
|
||||
|
||||
return renderDepositGuideText(template, vars)
|
||||
}
|
||||
|
||||
export function resolveDepositSupportMessage(settings?: SupportMessengerSettings): string {
|
||||
try {
|
||||
const fromStore = getRenderedDepositSupportMessage()
|
||||
if (fromStore.trim()) return fromStore
|
||||
} catch {
|
||||
// settings store may not be ready
|
||||
}
|
||||
|
||||
const resolved = settings ?? supportMessengerSettings.value
|
||||
const rawTemplate = resolved.depositSupportMessageText?.trim() || ''
|
||||
const template = rawTemplate || getDepositSupportMessageTemplate()
|
||||
const vars = resolved.depositAccountHolder
|
||||
? getDepositGuideVarsFromSupportSettings(resolved)
|
||||
: getDepositGuideVarsFromSettings()
|
||||
|
||||
return renderDepositSupportMessageText(template, vars)
|
||||
}
|
||||
|
||||
/** پیامرسانهایی که پارامتر text در URL دارند */
|
||||
export function messengerSupportsUrlText(messenger?: string): boolean {
|
||||
const type = (messenger ?? '').trim().toLowerCase()
|
||||
return type === 'telegram' || type === 'whatsapp' || type === 'sms'
|
||||
}
|
||||
|
||||
/** تماس/پیام بومی — نیازی به کپی متن در کلیپبورد نیست */
|
||||
export function isPhoneNativeSupportMessenger(messenger?: string): boolean {
|
||||
const type = (messenger ?? '').trim().toLowerCase()
|
||||
return PHONE_NATIVE_MESSENGERS.has(type)
|
||||
}
|
||||
|
||||
export function messengerNeedsClipboardCopy(messenger?: string): boolean {
|
||||
if (isPhoneNativeSupportMessenger(messenger) || messengerSupportsUrlText(messenger)) {
|
||||
return false
|
||||
}
|
||||
return Boolean((messenger ?? '').trim())
|
||||
}
|
||||
|
||||
export async function openSupportMessengerWithMessage(
|
||||
messenger?: string,
|
||||
messengerId?: string,
|
||||
messageText?: string,
|
||||
fallbackLink = '',
|
||||
): Promise<boolean> {
|
||||
const text = (messageText ?? '').trim()
|
||||
const url =
|
||||
buildSupportMessengerUrl(messenger, messengerId, text) ||
|
||||
(fallbackLink.trim() || '')
|
||||
|
||||
return openSupportMessengerUrl(url, messenger, text)
|
||||
}
|
||||
|
||||
export async function openSupportMessengerEntry(
|
||||
entry: SupportMessengerEntry | ResolvedSupportMessengerEntry,
|
||||
messageText?: string,
|
||||
fallbackLink = '',
|
||||
): Promise<boolean> {
|
||||
const text = (messageText ?? '').trim()
|
||||
// همیشه URL را با متن فعلی بساز — url کششدهٔ entry ممکن است text قدیمی داشته باشد
|
||||
const url =
|
||||
buildSupportMessengerUrl(entry.messenger, entry.id, text) ||
|
||||
('url' in entry && !text ? entry.url : '') ||
|
||||
fallbackLink.trim()
|
||||
|
||||
return openSupportMessengerUrl(url, entry.messenger, text)
|
||||
}
|
||||
|
||||
async function openSupportMessengerUrl(
|
||||
url: string,
|
||||
messenger?: string,
|
||||
messageText?: string,
|
||||
): Promise<boolean> {
|
||||
if (!url) return false
|
||||
|
||||
if (messageText && messengerNeedsClipboardCopy(messenger) && navigator.clipboard?.writeText) {
|
||||
try {
|
||||
await navigator.clipboard.writeText(messageText)
|
||||
} catch {
|
||||
// clipboard optional
|
||||
}
|
||||
}
|
||||
|
||||
if (url.startsWith('tel:') || url.startsWith('sms:')) {
|
||||
window.location.href = url
|
||||
return true
|
||||
}
|
||||
|
||||
window.open(url, '_blank', 'noopener,noreferrer')
|
||||
return true
|
||||
}
|
||||
|
||||
function getSupportSettingValue(
|
||||
settings: Array<{ key?: string; is_active?: boolean | number; value?: unknown }>,
|
||||
@@ -298,11 +30,7 @@ function getSupportSettingValue(
|
||||
return String(value).trim()
|
||||
}
|
||||
|
||||
export function buildSupportMessengerUrl(
|
||||
messenger?: string,
|
||||
messengerId?: string,
|
||||
messageText?: string,
|
||||
) {
|
||||
export function buildSupportMessengerUrl(messenger?: string, messengerId?: string) {
|
||||
const id = (messengerId ?? '').trim()
|
||||
if (!id) return ''
|
||||
|
||||
@@ -310,8 +38,6 @@ export function buildSupportMessengerUrl(
|
||||
|
||||
const type = (messenger ?? '').trim().toLowerCase()
|
||||
const username = id.replace(/^@/, '')
|
||||
const text = (messageText ?? '').trim()
|
||||
const textQuery = text ? `?text=${encodeURIComponent(text)}` : ''
|
||||
|
||||
if (!type) return ''
|
||||
|
||||
@@ -322,62 +48,29 @@ export function buildSupportMessengerUrl(
|
||||
}
|
||||
return `https://ble.ir/${username}`
|
||||
case 'telegram':
|
||||
return `https://t.me/${username}${textQuery}`
|
||||
return `https://t.me/${username}`
|
||||
case 'whatsapp':
|
||||
return `https://wa.me/${username.replace(/\D/g, '')}${textQuery}`
|
||||
return `https://wa.me/${username.replace(/\D/g, '')}`
|
||||
case 'rubika':
|
||||
return `https://rubika.ir/${username}`
|
||||
case 'eitaa':
|
||||
return `https://eitaa.com/${username}`
|
||||
case 'soroush':
|
||||
return `https://splus.ir/splus/${username}`
|
||||
case 'call':
|
||||
return buildSupportPhoneUrl(id)
|
||||
case 'sms':
|
||||
return buildDepositSmsUrl(id, text)
|
||||
default:
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
export function buildDepositSmsUrl(phoneNumber?: string, messageText?: string) {
|
||||
const digits = (phoneNumber ?? '').replace(/\D/g, '')
|
||||
if (!digits) return ''
|
||||
|
||||
const body = (messageText ?? '').trim()
|
||||
// بدون پیشنویس مگر صریحاً متن داده شود (مودال واریز)
|
||||
if (!body) return `sms:${digits}`
|
||||
return `sms:${digits}?body=${encodeURIComponent(body)}`
|
||||
}
|
||||
|
||||
export function buildSupportPhoneUrl(phoneNumber?: string) {
|
||||
const digits = (phoneNumber ?? '').replace(/\D/g, '')
|
||||
if (!digits) return ''
|
||||
return `tel:${digits}`
|
||||
}
|
||||
|
||||
export async function loadSupportMessengerFromSettings(forceSettingsRefresh = false) {
|
||||
export async function loadSupportMessengerFromSettings() {
|
||||
try {
|
||||
const settingsStore = useSettingsStore()
|
||||
if (forceSettingsRefresh) {
|
||||
await settingsStore.fetchSettings(true)
|
||||
} else if (!settingsStore.loaded) {
|
||||
await settingsStore.fetchSettings()
|
||||
}
|
||||
|
||||
const settings = settingsStore.settings
|
||||
if (!settings?.length) return
|
||||
const settings = await getSettings()
|
||||
if (!settings || !Array.isArray(settings)) return
|
||||
|
||||
supportMessengerSettings.value = {
|
||||
messengers: resolveSupportMessengersFromSettings(settings),
|
||||
messenger: getSupportSettingValue(settings, 'support_messenger'),
|
||||
messengerId: getSupportSettingValue(settings, 'support_messenger_id'),
|
||||
messengerText: getSupportSettingValue(settings, 'support_messenger_text'),
|
||||
depositSupportMessageText: getSupportSettingValue(settings, 'deposit_support_message_text'),
|
||||
depositAccountHolder: getSupportSettingValue(settings, 'deposit_account_holder'),
|
||||
depositCardNumber: getSupportSettingValue(settings, 'deposit_card_number'),
|
||||
depositSheba: getSupportSettingValue(settings, 'deposit_sheba'),
|
||||
depositSmsSupportNumber: getSupportSettingValue(settings, 'deposit_sms_support_number'),
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
|
||||
@@ -1,110 +0,0 @@
|
||||
import type { AppSetting } from '@/store/settingsStore'
|
||||
import { useSettingsStore } from '@/store/settingsStore'
|
||||
|
||||
export const TRACKING_SYSTEMS_KEY = 'tracking_systems'
|
||||
export const TRACKING_SYSTEMS_ENABLED_KEY = 'tracking_systems_enabled'
|
||||
|
||||
export interface TrackingSystemSite {
|
||||
id: string
|
||||
name: string
|
||||
url: string
|
||||
}
|
||||
|
||||
let trackingSettingsCache: AppSetting[] | null = null
|
||||
let trackingSettingsPromise: Promise<AppSetting[]> | null = null
|
||||
|
||||
export function normalizeSettingsResponse(data: unknown): AppSetting[] {
|
||||
if (Array.isArray(data)) return data as AppSetting[]
|
||||
|
||||
if (data && typeof data === 'object') {
|
||||
const record = data as Record<string, unknown>
|
||||
const nested = record.data ?? record.settings ?? record.rows
|
||||
if (Array.isArray(nested)) return nested as AppSetting[]
|
||||
}
|
||||
|
||||
return []
|
||||
}
|
||||
|
||||
export function findSettingValue(settings: AppSetting[], key: string): unknown {
|
||||
const setting = settings.find((item) => String(item?.key ?? '').trim() === key)
|
||||
return setting?.value ?? null
|
||||
}
|
||||
|
||||
export function isSettingTruthy(value: unknown): boolean {
|
||||
if (value === true) return true
|
||||
const normalized = String(value ?? '').trim().toLowerCase()
|
||||
return normalized === 'true' || normalized === '1' || normalized === 'yes'
|
||||
}
|
||||
|
||||
export function parseTrackingSystems(raw: unknown): TrackingSystemSite[] {
|
||||
let value: unknown = raw
|
||||
|
||||
for (let depth = 0; depth < 2; depth += 1) {
|
||||
if (typeof value !== 'string') break
|
||||
const trimmed = value.trim()
|
||||
if (!trimmed) return []
|
||||
|
||||
try {
|
||||
value = JSON.parse(trimmed)
|
||||
} catch {
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
if (!Array.isArray(value)) return []
|
||||
|
||||
return value
|
||||
.map((item) => {
|
||||
if (!item || typeof item !== 'object') return null
|
||||
|
||||
const record = item as Record<string, unknown>
|
||||
const id = String(record.id ?? '').trim()
|
||||
const name = String(record.name ?? record.title ?? '').trim()
|
||||
const url = String(record.url ?? record.link ?? '').trim()
|
||||
|
||||
if (!name || !url) return null
|
||||
return { id: id || `${name}-${url}`, name, url }
|
||||
})
|
||||
.filter((item): item is TrackingSystemSite => item != null)
|
||||
}
|
||||
|
||||
export function resolveTrackingSystems(settings: AppSetting[]): TrackingSystemSite[] {
|
||||
return parseTrackingSystems(findSettingValue(settings, TRACKING_SYSTEMS_KEY))
|
||||
}
|
||||
|
||||
export function isTrackingSystemsEnabled(settings: AppSetting[]): boolean {
|
||||
return isSettingTruthy(findSettingValue(settings, TRACKING_SYSTEMS_ENABLED_KEY))
|
||||
}
|
||||
|
||||
export async function fetchTrackingSettings(force = false): Promise<AppSetting[]> {
|
||||
if (!force && trackingSettingsCache) return trackingSettingsCache
|
||||
if (!force && trackingSettingsPromise) return trackingSettingsPromise
|
||||
|
||||
trackingSettingsPromise = (async () => {
|
||||
const settingsStore = useSettingsStore()
|
||||
|
||||
try {
|
||||
await settingsStore.fetchSettings(force)
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
}
|
||||
|
||||
trackingSettingsCache = [...settingsStore.settings]
|
||||
return trackingSettingsCache
|
||||
})()
|
||||
.catch((error) => {
|
||||
console.log(error)
|
||||
trackingSettingsCache = []
|
||||
return []
|
||||
})
|
||||
.finally(() => {
|
||||
trackingSettingsPromise = null
|
||||
})
|
||||
|
||||
return trackingSettingsPromise
|
||||
}
|
||||
|
||||
export function resetTrackingSettingsCache() {
|
||||
trackingSettingsCache = null
|
||||
trackingSettingsPromise = null
|
||||
}
|
||||
@@ -71,46 +71,29 @@ _axios.interceptors.response.use(
|
||||
}
|
||||
|
||||
const apiMessage = extractApiErrorMessage(response?.data)
|
||||
const status = Number(response?.status ?? 0)
|
||||
|
||||
if (response?.status === 403) {
|
||||
showApiError(
|
||||
withHttpStatus(apiMessage || 'شما دسترسی لازم برای انجام این عملیات را ندارید', 403),
|
||||
config,
|
||||
)
|
||||
showApiError(apiMessage || 'شما دسترسی لازم برای انجام این عملیات را ندارید', config)
|
||||
return Promise.reject(error)
|
||||
}
|
||||
|
||||
if (response?.status === 422) {
|
||||
if (apiMessage) {
|
||||
showApiError(withHttpStatus(apiMessage, 422), config)
|
||||
} else {
|
||||
showApiError(withHttpStatus('خطا در اعتبارسنجی', 422), config)
|
||||
showApiError(apiMessage, config)
|
||||
}
|
||||
return Promise.reject(error)
|
||||
}
|
||||
|
||||
if (response) {
|
||||
if (status >= 500) {
|
||||
showApiError(withHttpStatus(SERVER_ERROR, status), config)
|
||||
} else {
|
||||
showApiError(withHttpStatus(apiMessage || DEFAULT_LOAD_ERROR, status), config)
|
||||
}
|
||||
showApiError(apiMessage || DEFAULT_LOAD_ERROR, config)
|
||||
return Promise.reject(error)
|
||||
}
|
||||
|
||||
// بدون status (نه 4xx نه 5xx): قطع شبکه، timeout، DNS، …
|
||||
showApiError(NETWORK_ERROR, config)
|
||||
showApiError(DEFAULT_LOAD_ERROR, config)
|
||||
return Promise.reject(error)
|
||||
})
|
||||
|
||||
const DEFAULT_LOAD_ERROR = 'خطا در بارگذاری اطلاعات'
|
||||
const SERVER_ERROR = 'خطا در برقراری ارتباط با سرور'
|
||||
const NETWORK_ERROR = 'لطفا اینترنت خود را بررسی کنید و مجددا تلاش کنید'
|
||||
|
||||
function withHttpStatus(message: string, status: number): string {
|
||||
return `${message} (${status})`
|
||||
}
|
||||
|
||||
function extractApiErrorMessage(data: unknown): string {
|
||||
if (!data || typeof data !== 'object') {
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
import { usePriceWithoutType } from '@/utils/usePrice'
|
||||
|
||||
/** پیشفرض تاریخی UI وقتی تنظیم خالی است (۱۰۰ هزار تومان = ۱٬۰۰۰٬۰۰۰ ریال) */
|
||||
export const DEFAULT_WALLET_MIN_RIAL = 1_000_000
|
||||
|
||||
export function parseWalletMinRial(
|
||||
raw: string | number | null | undefined,
|
||||
fallback = DEFAULT_WALLET_MIN_RIAL,
|
||||
): number {
|
||||
if (raw == null || String(raw).trim() === '') {
|
||||
return fallback
|
||||
}
|
||||
const n = Number(String(raw).replace(/,/g, '').trim())
|
||||
if (!Number.isFinite(n) || n < 0) {
|
||||
return fallback
|
||||
}
|
||||
return Math.floor(n)
|
||||
}
|
||||
|
||||
export function formatWalletMinHint(
|
||||
kind: 'withdraw' | 'deposit',
|
||||
amountRial: number,
|
||||
formatPrice: (value: number) => string = usePriceWithoutType,
|
||||
): string {
|
||||
const label = kind === 'withdraw' ? 'برداشتی' : 'واریزی'
|
||||
return `حداقل مبلغ ${label} ${formatPrice(amountRial)} ریال می باشد.`
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
export const TRADE_WEIGHT_UNIT_GRAM = 'گرم'
|
||||
export const TRADE_WEIGHT_UNIT_KILOGRAM = 'کیلوگرم'
|
||||
|
||||
export function isKilogramUnit(unit?: string | null) {
|
||||
const value = (unit ?? '').trim()
|
||||
return value === TRADE_WEIGHT_UNIT_KILOGRAM || value === 'kilogram' || value === 'kg'
|
||||
}
|
||||
|
||||
/** واحد نمایش از ستینگ — خالی یا نامعتبر = گرم */
|
||||
export function resolveTradeWeightUnit(settingValue?: string | number | null) {
|
||||
return isKilogramUnit(settingValue?.toString()) ? TRADE_WEIGHT_UNIT_KILOGRAM : TRADE_WEIGHT_UNIT_GRAM
|
||||
}
|
||||
|
||||
export function weightToGrams(value: number, fromUnit?: string | null) {
|
||||
return isKilogramUnit(fromUnit) ? value * 1000 : value
|
||||
}
|
||||
|
||||
export function gramsToTradeUnit(grams: number, displayUnit?: string | null) {
|
||||
return isKilogramUnit(displayUnit ?? resolveTradeWeightUnit(null)) ? grams / 1000 : grams
|
||||
}
|
||||
|
||||
export function convertWeightToDisplayUnit(
|
||||
value: number,
|
||||
fromUnit?: string | null,
|
||||
displayUnit?: string | null
|
||||
) {
|
||||
return gramsToTradeUnit(weightToGrams(value, fromUnit), displayUnit)
|
||||
}
|
||||
|
||||
export function formatTradeWeight(value: number, displayUnit?: string | null) {
|
||||
const unit = resolveTradeWeightUnit(displayUnit)
|
||||
return `${value} ${unit}`
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
/** toast اعلان درونبرنامه — بالای هدر و ناوبری */
|
||||
export const APP_Z_TOAST = 5050
|
||||
|
||||
/** Overlay dialogs (loading / blocking) */
|
||||
export const APP_Z_OVERLAY = 5600
|
||||
@@ -1,205 +1,11 @@
|
||||
<script lang="ts" setup>
|
||||
import { computed } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { getConfigApp } from '@/utils/config'
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
const brandName = computed(
|
||||
() => String(getConfigApp('name_fa') || getConfigApp('name') || 'خانه')
|
||||
)
|
||||
const logo = computed(() => String(getConfigApp('avatar') || ''))
|
||||
|
||||
function goHome() {
|
||||
router.push({ name: 'home' })
|
||||
}
|
||||
|
||||
function goBack() {
|
||||
if (window.history.length > 1) {
|
||||
router.back()
|
||||
return
|
||||
}
|
||||
goHome()
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="not-found" dir="rtl">
|
||||
<div class="not-found__glow not-found__glow--a" aria-hidden="true" />
|
||||
<div class="not-found__glow not-found__glow--b" aria-hidden="true" />
|
||||
<div class="not-found__grid" aria-hidden="true" />
|
||||
|
||||
<div class="not-found__panel">
|
||||
<div v-if="logo" class="not-found__brand">
|
||||
<img :src="logo" :alt="brandName" class="not-found__logo">
|
||||
<span class="not-found__brand-name">{{ brandName }}</span>
|
||||
</div>
|
||||
<p v-else class="not-found__brand-name not-found__brand-name--solo">
|
||||
{{ brandName }}
|
||||
</p>
|
||||
|
||||
<p class="not-found__code" aria-hidden="true">۴۰۴</p>
|
||||
|
||||
<h1 class="not-found__title">
|
||||
صفحه مورد نظر یافت نشد
|
||||
</h1>
|
||||
<p class="not-found__subtitle">
|
||||
این مسیر وجود ندارد یا جابهجا شده است. میتوانید به صفحه اصلی برگردید
|
||||
و از آنجا ادامه دهید.
|
||||
</p>
|
||||
|
||||
<div class="not-found__actions">
|
||||
<a-button type="primary" size="large" class="not-found__cta" @click="goHome">
|
||||
بازگشت به صفحه اصلی
|
||||
</a-button>
|
||||
<a-button size="large" class="not-found__secondary" @click="goBack">
|
||||
صفحه قبل
|
||||
</a-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-center">صفحه مورد نظر یافت نشد</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.not-found {
|
||||
@apply relative min-h-screen w-full overflow-hidden flex items-center justify-center px-4 py-10;
|
||||
background:
|
||||
radial-gradient(120% 80% at 50% -10%, color-mix(in srgb, var(--App-primary, #7f1d1d) 18%, transparent), transparent 55%),
|
||||
linear-gradient(165deg, #f7f4f0 0%, #efe8e0 45%, #f8f6f3 100%);
|
||||
color: #1c1917;
|
||||
}
|
||||
|
||||
.not-found__glow {
|
||||
@apply pointer-events-none absolute rounded-full;
|
||||
filter: blur(48px);
|
||||
opacity: 0.45;
|
||||
animation: not-found-float 9s ease-in-out infinite;
|
||||
}
|
||||
|
||||
.not-found__glow--a {
|
||||
width: min(48vw, 22rem);
|
||||
height: min(48vw, 22rem);
|
||||
top: 8%;
|
||||
left: 6%;
|
||||
background: color-mix(in srgb, var(--App-primary, #7f1d1d) 35%, #c4a574);
|
||||
}
|
||||
|
||||
.not-found__glow--b {
|
||||
width: min(42vw, 18rem);
|
||||
height: min(42vw, 18rem);
|
||||
right: 4%;
|
||||
bottom: 12%;
|
||||
background: color-mix(in srgb, var(--App-primary, #7f1d1d) 22%, #d6c3a3);
|
||||
animation-delay: -3.5s;
|
||||
}
|
||||
|
||||
.not-found__grid {
|
||||
@apply pointer-events-none absolute inset-0 opacity-40;
|
||||
background-image:
|
||||
linear-gradient(rgba(28, 25, 23, 0.04) 1px, transparent 1px),
|
||||
linear-gradient(90deg, rgba(28, 25, 23, 0.04) 1px, transparent 1px);
|
||||
background-size: 48px 48px;
|
||||
mask-image: radial-gradient(ellipse at center, black 20%, transparent 75%);
|
||||
}
|
||||
|
||||
.not-found__panel {
|
||||
@apply relative z-1 w-full max-w-lg flex flex-col items-center text-center;
|
||||
animation: not-found-rise 0.7s ease-out both;
|
||||
}
|
||||
|
||||
.not-found__brand {
|
||||
@apply flex items-center justify-center gap-2.5 mb-6;
|
||||
}
|
||||
|
||||
.not-found__logo {
|
||||
@apply w-11 h-11 rounded-full object-cover;
|
||||
box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.9), 0 8px 24px rgba(28, 25, 23, 0.12);
|
||||
}
|
||||
|
||||
.not-found__brand-name {
|
||||
@apply text-base font-bold tracking-wide text-primary m-0;
|
||||
}
|
||||
|
||||
.not-found__brand-name--solo {
|
||||
@apply mb-6;
|
||||
}
|
||||
|
||||
.not-found__code {
|
||||
@apply m-0 font-black leading-none select-none;
|
||||
font-size: clamp(5.5rem, 22vw, 9rem);
|
||||
letter-spacing: -0.06em;
|
||||
background: linear-gradient(
|
||||
135deg,
|
||||
var(--App-primary, #7f1d1d) 0%,
|
||||
#b45309 48%,
|
||||
var(--App-primary, #7f1d1d) 100%
|
||||
);
|
||||
-webkit-background-clip: text;
|
||||
background-clip: text;
|
||||
color: transparent;
|
||||
filter: drop-shadow(0 12px 28px rgba(127, 29, 29, 0.18));
|
||||
animation: not-found-pulse 5.5s ease-in-out infinite;
|
||||
}
|
||||
|
||||
.not-found__title {
|
||||
@apply m-0 mt-2 text-xl md:text-2xl font-bold text-stone-900;
|
||||
}
|
||||
|
||||
.not-found__subtitle {
|
||||
@apply m-0 mt-3 text-sm md:text-base leading-7 text-stone-500 max-w-md;
|
||||
}
|
||||
|
||||
.not-found__actions {
|
||||
@apply mt-8 flex flex-wrap items-center justify-center gap-3 w-full;
|
||||
}
|
||||
|
||||
.not-found__cta {
|
||||
@apply min-w-44 font-bold;
|
||||
box-shadow: 0 10px 28px color-mix(in srgb, var(--App-primary, #7f1d1d) 28%, transparent);
|
||||
}
|
||||
|
||||
.not-found__secondary {
|
||||
@apply min-w-28;
|
||||
}
|
||||
|
||||
@keyframes not-found-rise {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(18px);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes not-found-float {
|
||||
0%,
|
||||
100% {
|
||||
transform: translate3d(0, 0, 0) scale(1);
|
||||
}
|
||||
50% {
|
||||
transform: translate3d(12px, -16px, 0) scale(1.05);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes not-found-pulse {
|
||||
0%,
|
||||
100% {
|
||||
transform: translateY(0);
|
||||
filter: drop-shadow(0 12px 28px rgba(127, 29, 29, 0.18));
|
||||
}
|
||||
50% {
|
||||
transform: translateY(-6px);
|
||||
filter: drop-shadow(0 18px 36px rgba(127, 29, 29, 0.26));
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.not-found__glow,
|
||||
.not-found__code,
|
||||
.not-found__panel {
|
||||
animation: none;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
@@ -2,12 +2,8 @@ export interface AboutSection {
|
||||
title?: string
|
||||
paragraphs?: string[]
|
||||
items?: string[]
|
||||
/** متن HTML از Setting — در صورت وجود، اولویت با این است */
|
||||
html?: string
|
||||
}
|
||||
|
||||
const ABOUT_SETTING_KEYS = ['text_about'] as const
|
||||
|
||||
export function getAboutSections(projectName: string): AboutSection[] {
|
||||
return [
|
||||
{
|
||||
@@ -15,59 +11,3 @@ export function getAboutSections(projectName: string): AboutSection[] {
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
function looksLikeHtml(value: string) {
|
||||
return /<\/?[a-z][\s\S]*>/i.test(value)
|
||||
}
|
||||
|
||||
function parseAboutSettingValue(raw: string): AboutSection[] | null {
|
||||
const value = raw.trim()
|
||||
if (!value) return null
|
||||
|
||||
try {
|
||||
const decoded = JSON.parse(value)
|
||||
if (Array.isArray(decoded) && decoded.length > 0) {
|
||||
return decoded as AboutSection[]
|
||||
}
|
||||
if (decoded && typeof decoded === 'object' && typeof decoded.html === 'string') {
|
||||
const html = decoded.html.trim()
|
||||
if (html) return [{ html }]
|
||||
}
|
||||
if (decoded && typeof decoded === 'object' && typeof decoded.text === 'string') {
|
||||
return parseAboutSettingValue(decoded.text)
|
||||
}
|
||||
} catch {
|
||||
// plain text / html
|
||||
}
|
||||
|
||||
if (looksLikeHtml(value)) {
|
||||
return [{ html: value }]
|
||||
}
|
||||
|
||||
const paragraphs = value
|
||||
.split(/\r?\n+/)
|
||||
.map((line) => line.trim())
|
||||
.filter(Boolean)
|
||||
|
||||
return [{ paragraphs: paragraphs.length > 0 ? paragraphs : [value] }]
|
||||
}
|
||||
|
||||
export function getAboutSettingText(
|
||||
getSettingByKey: (key: string) => unknown,
|
||||
): string {
|
||||
for (const key of ABOUT_SETTING_KEYS) {
|
||||
const value = String(getSettingByKey(key) ?? '').trim()
|
||||
if (value) return value
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
/** اولویت با Setting؛ در صورت خالی بودن، متن پیشفرض */
|
||||
export function resolveAboutSections(
|
||||
projectName: string,
|
||||
settingsText?: string | null,
|
||||
): AboutSection[] {
|
||||
const fromSettings = parseAboutSettingValue(String(settingsText ?? ''))
|
||||
if (fromSettings?.length) return fromSettings
|
||||
return getAboutSections(projectName)
|
||||
}
|
||||
|
||||
@@ -8,41 +8,13 @@
|
||||
v-if="sectionIndex > 0"
|
||||
:class="variant === 'desktop' ? 'dabout-content__divider' : 'w-full h-1px my-3 bg-tertiary'"
|
||||
/>
|
||||
|
||||
<div
|
||||
v-if="section.html"
|
||||
class="about-sections-html"
|
||||
:class="variant === 'desktop' ? 'dabout-content__paragraph' : ''"
|
||||
v-html="section.html"
|
||||
/>
|
||||
|
||||
<template v-else>
|
||||
<div
|
||||
v-if="section.title"
|
||||
:class="variant === 'desktop' ? 'dabout-content__title' : 'font-bold text-sm mb-2'"
|
||||
>
|
||||
{{ section.title }}
|
||||
</div>
|
||||
<div
|
||||
v-for="(paragraph, paragraphIndex) in section.paragraphs ?? []"
|
||||
:key="`p-${sectionIndex}-${paragraphIndex}`"
|
||||
:class="[variant === 'desktop' ? 'dabout-content__paragraph' : '', paragraphIndex > 0 ? 'mt-3' : '']"
|
||||
>
|
||||
{{ paragraph }}
|
||||
</div>
|
||||
<ul
|
||||
v-if="section.items?.length"
|
||||
:class="variant === 'desktop' ? 'dabout-content__list' : 'mt-2 pr-4 list-disc'"
|
||||
>
|
||||
<li
|
||||
v-for="(item, itemIndex) in section.items"
|
||||
:key="`i-${sectionIndex}-${itemIndex}`"
|
||||
:class="variant === 'desktop' ? 'dabout-content__list-item' : 'mt-2'"
|
||||
>
|
||||
{{ item }}
|
||||
</li>
|
||||
</ul>
|
||||
</template>
|
||||
v-for="(paragraph, paragraphIndex) in section.paragraphs ?? []"
|
||||
:key="`p-${sectionIndex}-${paragraphIndex}`"
|
||||
:class="[variant === 'desktop' ? 'dabout-content__paragraph' : '', paragraphIndex > 0 ? 'mt-3' : '']"
|
||||
>
|
||||
{{ paragraph }}
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
@@ -54,21 +26,3 @@ withDefaults(defineProps<{ variant?: 'mobile' | 'desktop' }>(), { variant: 'mobi
|
||||
|
||||
const { aboutSections } = useAboutPageContext()
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
.about-sections-html {
|
||||
:deep(p + p) {
|
||||
margin-top: 0.75rem;
|
||||
}
|
||||
|
||||
:deep(ul) {
|
||||
margin: 0.5rem 0 0;
|
||||
padding-right: 1.1rem;
|
||||
list-style: disc;
|
||||
}
|
||||
|
||||
:deep(li + li) {
|
||||
margin-top: 0.35rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,18 +1,23 @@
|
||||
<template>
|
||||
<SupportContactBar
|
||||
:variant="variant"
|
||||
mobile-root-class="wrap-fix mobile-info-page__support flex gap-2"
|
||||
desktop-root-class="dabout-support"
|
||||
/>
|
||||
<div :class="variant === 'desktop' ? 'dabout-support' : 'wrap-fix bottom-0 px-10 py-6 flex gap-2 bg-white items-center'">
|
||||
<a class="w-full" :href="supportHref" target="_blank" rel="noopener noreferrer">
|
||||
<BasicButton class="w-full" type="primary">تماس با پشتیبانی</BasicButton>
|
||||
</a>
|
||||
<a :href="supportHref" target="_blank" rel="noopener noreferrer">
|
||||
<img
|
||||
src="@/assets/img/rubika.webp"
|
||||
alt=""
|
||||
:class="variant === 'desktop' ? 'dabout-support__bale' : 'w-12'"
|
||||
/>
|
||||
</a>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import SupportContactBar from '@/components/SupportContactBar.vue'
|
||||
import BasicButton from '@/components/BasicPacks/BasicButton.vue'
|
||||
import { useAboutPageContext } from '../composables/useAboutPage'
|
||||
|
||||
withDefaults(
|
||||
defineProps<{
|
||||
variant?: 'mobile' | 'desktop'
|
||||
}>(),
|
||||
{ variant: 'mobile' },
|
||||
)
|
||||
withDefaults(defineProps<{ variant?: 'mobile' | 'desktop' }>(), { variant: 'mobile' })
|
||||
|
||||
const { supportHref } = useAboutPageContext()
|
||||
</script>
|
||||
|
||||
@@ -1,34 +1,23 @@
|
||||
import { computed, inject, onMounted, provide, type InjectionKey, type ComputedRef } from 'vue'
|
||||
import { computed, inject, provide, type InjectionKey, type ComputedRef } from 'vue'
|
||||
import { getConfig } from '@/config/app-config'
|
||||
import { useSettingsStore } from '@/store/settingsStore'
|
||||
import {
|
||||
getAboutSettingText,
|
||||
resolveAboutSections,
|
||||
type AboutSection,
|
||||
} from '../aboutContent'
|
||||
import { getAboutSections, type AboutSection } from '../aboutContent'
|
||||
|
||||
export interface AboutPageContext {
|
||||
projectName: ComputedRef<string>
|
||||
aboutSections: ComputedRef<AboutSection[]>
|
||||
supportHref: ComputedRef<string>
|
||||
}
|
||||
|
||||
export const ABOUT_PAGE_CONTEXT_KEY: InjectionKey<AboutPageContext> = Symbol('aboutPageContext')
|
||||
|
||||
const SUPPORT_LINK = 'https://web.rubika.ir/#c=u0I8F1U0a939b0df5ba9f73618d33d7c'
|
||||
|
||||
export function useAboutPage() {
|
||||
const settingsStore = useSettingsStore()
|
||||
const projectName = computed(() => getConfig('name_fa', 'کشکول گلد'))
|
||||
const aboutSections = computed(() => getAboutSections(projectName.value))
|
||||
const supportHref = computed(() => SUPPORT_LINK)
|
||||
|
||||
const aboutSections = computed(() => {
|
||||
void settingsStore.settings
|
||||
const fromSettings = getAboutSettingText((key) => settingsStore.getSettingByKey(key))
|
||||
return resolveAboutSections(projectName.value, fromSettings)
|
||||
})
|
||||
|
||||
onMounted(() => {
|
||||
void settingsStore.fetchSettings()
|
||||
})
|
||||
|
||||
const context: AboutPageContext = { projectName, aboutSections }
|
||||
const context: AboutPageContext = { projectName, aboutSections, supportHref }
|
||||
provide(ABOUT_PAGE_CONTEXT_KEY, context)
|
||||
return context
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@
|
||||
height: 56px;
|
||||
border-radius: 14px;
|
||||
background: rgba(9, 61, 81, 0.08);
|
||||
color: @App-primary-color;
|
||||
color: @theme-primary;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@
|
||||
border: 1px solid rgba(9, 61, 81, 0.15);
|
||||
border-radius: 12px;
|
||||
background: rgba(9, 61, 81, 0.03);
|
||||
color: @App-primary-color;
|
||||
color: @theme-primary;
|
||||
}
|
||||
|
||||
&__divider {
|
||||
@@ -205,7 +205,22 @@
|
||||
}
|
||||
|
||||
.dabout-support {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
|
||||
> a:first-child {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
&__bale {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
object-fit: contain;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 1023.98px) {
|
||||
|
||||
@@ -1,94 +0,0 @@
|
||||
import { computed, inject, onMounted, provide, ref, type InjectionKey } from 'vue'
|
||||
import {
|
||||
getAppNotifications,
|
||||
markAllAppNotificationsRead,
|
||||
markAppNotificationRead,
|
||||
type CustomerAppNotification,
|
||||
} from '@/api/appNotifications'
|
||||
import { useSettingsStore } from '@/store/settingsStore'
|
||||
|
||||
export interface AppNotificationsPageContext {
|
||||
loading: ReturnType<typeof ref<boolean>>
|
||||
items: ReturnType<typeof ref<CustomerAppNotification[]>>
|
||||
enabled: ReturnType<typeof computed<boolean>>
|
||||
refresh: () => Promise<void>
|
||||
markRead: (id: number) => Promise<void>
|
||||
markAllRead: () => Promise<void>
|
||||
}
|
||||
|
||||
export const APP_NOTIFICATIONS_PAGE_KEY: InjectionKey<AppNotificationsPageContext> =
|
||||
Symbol('appNotificationsPage')
|
||||
|
||||
export function useAppNotificationsPage() {
|
||||
const settingsStore = useSettingsStore()
|
||||
const loading = ref(false)
|
||||
const items = ref<CustomerAppNotification[]>([])
|
||||
|
||||
const enabled = computed(() => settingsStore.isSettingTruthy('has_page_notification'))
|
||||
|
||||
async function refresh() {
|
||||
if (!enabled.value) {
|
||||
items.value = []
|
||||
return
|
||||
}
|
||||
loading.value = true
|
||||
try {
|
||||
const data = await getAppNotifications()
|
||||
items.value = Array.isArray(data) ? data : []
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
items.value = []
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function markRead(id: number) {
|
||||
try {
|
||||
await markAppNotificationRead(id)
|
||||
const row = items.value.find((item) => item.id === id)
|
||||
if (row) row.is_read = true
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
}
|
||||
|
||||
async function markAllRead() {
|
||||
try {
|
||||
await markAllAppNotificationsRead()
|
||||
items.value = items.value.map((item) => ({ ...item, is_read: true }))
|
||||
const { clearUnreadLocally } = await import('@/composables/useAppNotificationBadge')
|
||||
clearUnreadLocally()
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
void refresh().then(() => {
|
||||
const hasUnread = items.value.some((item) => !item.is_read)
|
||||
if (hasUnread) {
|
||||
void markAllRead()
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
const ctx: AppNotificationsPageContext = {
|
||||
loading,
|
||||
items,
|
||||
enabled,
|
||||
refresh,
|
||||
markRead,
|
||||
markAllRead,
|
||||
}
|
||||
provide(APP_NOTIFICATIONS_PAGE_KEY, ctx)
|
||||
return ctx
|
||||
}
|
||||
|
||||
export function useAppNotificationsPageContext() {
|
||||
const ctx = inject(APP_NOTIFICATIONS_PAGE_KEY)
|
||||
if (!ctx) {
|
||||
throw new Error('useAppNotificationsPageContext must be used within useAppNotificationsPage')
|
||||
}
|
||||
return ctx
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
<template>
|
||||
<div class="dapp-notif">
|
||||
<header class="dapp-notif__top">
|
||||
<div>
|
||||
<p class="dapp-notif__eyebrow">اعلانها</p>
|
||||
<h1 class="dapp-notif__title">پیامهای مدیریت</h1>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<a-spin :spinning="loading">
|
||||
<div v-if="!items.length" class="dapp-notif__empty">
|
||||
<BasicIcon icon="vuesax-linear:notification-bing" size="36" />
|
||||
<p>اعلانی برای نمایش نیست.</p>
|
||||
</div>
|
||||
<div v-else class="dapp-notif__list">
|
||||
<article
|
||||
v-for="item in items"
|
||||
:key="item.id"
|
||||
class="dapp-notif__card"
|
||||
:class="`dapp-notif__card--${item.severity}`"
|
||||
@click="markRead(item.id)"
|
||||
>
|
||||
<div class="flex items-start justify-between gap-3">
|
||||
<h3 class="m-0 text-base font-bold">{{ item.title }}</h3>
|
||||
<span class="dapp-notif__tag">{{ severityLabel(item.severity) }}</span>
|
||||
</div>
|
||||
<p class="m-0 mt-2 text-sm text-gray-600 whitespace-pre-wrap">{{ item.body }}</p>
|
||||
</article>
|
||||
</div>
|
||||
</a-spin>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import BasicIcon from '@/components/BasicPacks/BasicIcon.vue'
|
||||
import { useAppNotificationsPageContext } from '../composables/useAppNotificationsPage'
|
||||
|
||||
const { loading, items, markRead } = useAppNotificationsPageContext()
|
||||
|
||||
function severityLabel(severity: string) {
|
||||
switch (severity) {
|
||||
case 'success':
|
||||
return 'موفق'
|
||||
case 'warning':
|
||||
return 'هشدار'
|
||||
case 'danger':
|
||||
return 'مهم'
|
||||
default:
|
||||
return 'اطلاعات'
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.dapp-notif {
|
||||
@apply p-6 min-h-full;
|
||||
}
|
||||
.dapp-notif__eyebrow {
|
||||
@apply m-0 text-xs text-gray-500;
|
||||
}
|
||||
.dapp-notif__title {
|
||||
@apply m-0 mt-1 text-xl font-bold;
|
||||
}
|
||||
.dapp-notif__empty {
|
||||
@apply mt-10 flex flex-col items-center gap-2 text-gray-500;
|
||||
}
|
||||
.dapp-notif__list {
|
||||
@apply mt-6 flex flex-col gap-3 max-w-3xl;
|
||||
}
|
||||
.dapp-notif__card {
|
||||
@apply rounded-xl bg-white border border-gray-100 p-4 cursor-pointer;
|
||||
}
|
||||
.dapp-notif__tag {
|
||||
@apply shrink-0 rounded-md px-2 py-0.5 text-xs font-bold bg-gray-50 text-gray-700;
|
||||
}
|
||||
.dapp-notif__card--info .dapp-notif__tag {
|
||||
@apply bg-blue-50 text-blue-700;
|
||||
}
|
||||
.dapp-notif__card--success .dapp-notif__tag {
|
||||
@apply bg-green-50 text-green-700;
|
||||
}
|
||||
.dapp-notif__card--warning .dapp-notif__tag {
|
||||
@apply bg-orange-50 text-orange-700;
|
||||
}
|
||||
.dapp-notif__card--danger .dapp-notif__tag {
|
||||
@apply bg-red-50 text-red-700;
|
||||
}
|
||||
</style>
|
||||
@@ -1,23 +0,0 @@
|
||||
<template>
|
||||
<div class="app-notifications-page-root">
|
||||
<DesktopAppNotificationsView v-show="isDesktop" />
|
||||
<MobileAppNotificationsView v-show="!isDesktop" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { useDesktopBreakpoint } from '@/layouts/composables/useAppLayout'
|
||||
import { useAppNotificationsPage } from './composables/useAppNotificationsPage'
|
||||
import DesktopAppNotificationsView from './desktop/DesktopAppNotificationsView.vue'
|
||||
import MobileAppNotificationsView from './mobile/MobileAppNotificationsView.vue'
|
||||
|
||||
const isDesktop = useDesktopBreakpoint()
|
||||
useAppNotificationsPage()
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.app-notifications-page-root {
|
||||
min-height: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
</style>
|
||||