Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9356a2ab5e | ||
|
|
e9012e26fb | ||
|
|
b1cf0639f5 | ||
|
|
42aef88064 | ||
|
|
be896fe247 | ||
|
|
e6dea15752 | ||
|
|
4fd12277e7 | ||
|
|
21345318ba | ||
|
|
149f82edd4 | ||
|
|
da66e6fef5 |
@@ -0,0 +1,15 @@
|
|||||||
|
# کپی به `.env.production` / `.env.development`
|
||||||
|
|
||||||
|
# لوکال (پیشنهادی): پروکسی Vite → بدون CORS
|
||||||
|
# VITE_SUPERADMIN_URL=/__sa
|
||||||
|
# VITE_TENANT_DOMAIN=k.montzar.ir
|
||||||
|
|
||||||
|
# لوکال با API سوپرادمین روی سیستم خودت:
|
||||||
|
# VITE_SUPERADMIN_URL=http://localhost:3001
|
||||||
|
|
||||||
|
# پروداکشن:
|
||||||
|
# VITE_SUPERADMIN_URL=https://adm.montzar.ir
|
||||||
|
# failover: adm.montzar.ir → adm.montech.ir → adm.montest.ir
|
||||||
|
|
||||||
|
# URL لندینگ داخل اپ
|
||||||
|
VITE_LANDING_APP_URL=/landing/
|
||||||
@@ -14,6 +14,11 @@ dist-ssr
|
|||||||
coverage
|
coverage
|
||||||
*.local
|
*.local
|
||||||
|
|
||||||
|
# Local env
|
||||||
|
.env
|
||||||
|
.env.*
|
||||||
|
!.env.example
|
||||||
|
|
||||||
/cypress/videos/
|
/cypress/videos/
|
||||||
/cypress/screenshots/
|
/cypress/screenshots/
|
||||||
|
|
||||||
|
|||||||
@@ -7,10 +7,12 @@ export {}
|
|||||||
|
|
||||||
declare module 'vue' {
|
declare module 'vue' {
|
||||||
export interface GlobalComponents {
|
export interface GlobalComponents {
|
||||||
|
ABadge: typeof import('ant-design-vue/es')['Badge']
|
||||||
AButton: typeof import('ant-design-vue/es')['Button']
|
AButton: typeof import('ant-design-vue/es')['Button']
|
||||||
ADivider: typeof import('ant-design-vue/es')['Divider']
|
ADivider: typeof import('ant-design-vue/es')['Divider']
|
||||||
AForm: typeof import('ant-design-vue/es')['Form']
|
AForm: typeof import('ant-design-vue/es')['Form']
|
||||||
AFormItem: typeof import('ant-design-vue/es')['FormItem']
|
AFormItem: typeof import('ant-design-vue/es')['FormItem']
|
||||||
|
AImage: typeof import('ant-design-vue/es')['Image']
|
||||||
AInput: typeof import('ant-design-vue/es')['Input']
|
AInput: typeof import('ant-design-vue/es')['Input']
|
||||||
AInputPassword: typeof import('ant-design-vue/es')['InputPassword']
|
AInputPassword: typeof import('ant-design-vue/es')['InputPassword']
|
||||||
AModal: typeof import('ant-design-vue/es')['Modal']
|
AModal: typeof import('ant-design-vue/es')['Modal']
|
||||||
@@ -49,13 +51,20 @@ declare module 'vue' {
|
|||||||
Disabled: typeof import('./src/components/BasicPacks/BaseDatePicker/src/datePick/demo/disabled.vue')['default']
|
Disabled: typeof import('./src/components/BasicPacks/BaseDatePicker/src/datePick/demo/disabled.vue')['default']
|
||||||
DisabledDate: typeof import('./src/components/BasicPacks/BaseDatePicker/src/datePick/demo/disabled-date.vue')['default']
|
DisabledDate: typeof import('./src/components/BasicPacks/BaseDatePicker/src/datePick/demo/disabled-date.vue')['default']
|
||||||
Empty: typeof import('./src/components/empty.vue')['default']
|
Empty: typeof import('./src/components/empty.vue')['default']
|
||||||
|
EnamadBadge: typeof import('./src/components/EnamadBadge.vue')['default']
|
||||||
ExtraFooter: typeof import('./src/components/BasicPacks/BaseDatePicker/src/datePick/demo/extra-footer.vue')['default']
|
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']
|
Format: typeof import('./src/components/BasicPacks/BaseDatePicker/src/datePick/demo/format.vue')['default']
|
||||||
|
GoldDayCalculatorModal: typeof import('./src/components/GoldDayCalculatorModal.vue')['default']
|
||||||
GoldLoading: typeof import('./src/components/GoldLoading.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']
|
ListAnim: typeof import('./src/components/ListAnim.vue')['default']
|
||||||
Mode: typeof import('./src/components/BasicPacks/BaseDatePicker/src/datePick/demo/mode.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']
|
PresettedRanges: typeof import('./src/components/BasicPacks/BaseDatePicker/src/datePick/demo/presetted-ranges.vue')['default']
|
||||||
|
ProductImage: typeof import('./src/components/ProductImage.vue')['default']
|
||||||
ProfileAvatarUpload: typeof import('./src/components/ProfileAvatarUpload.vue')['default']
|
ProfileAvatarUpload: typeof import('./src/components/ProfileAvatarUpload.vue')['default']
|
||||||
|
PwaInstallBanner: typeof import('./src/components/pwa/PwaInstallBanner.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']
|
RangePicker: typeof import('./src/components/BasicPacks/BaseDatePicker/src/datePick/demo/range-picker.vue')['default']
|
||||||
RouterLink: typeof import('vue-router')['RouterLink']
|
RouterLink: typeof import('vue-router')['RouterLink']
|
||||||
RouterView: typeof import('vue-router')['RouterView']
|
RouterView: typeof import('vue-router')['RouterView']
|
||||||
@@ -65,9 +74,12 @@ declare module 'vue' {
|
|||||||
StartEnd: typeof import('./src/components/BasicPacks/BaseDatePicker/src/datePick/demo/start-end.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']
|
Suffix: typeof import('./src/components/BasicPacks/BaseDatePicker/src/datePick/demo/suffix.vue')['default']
|
||||||
SupportContactBar: typeof import('./src/components/SupportContactBar.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']
|
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']
|
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']
|
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']
|
TransactionSkeleton: typeof import('./src/components/TransactionSkeleton.vue')['default']
|
||||||
VanActionSheet: typeof import('vant/es')['ActionSheet']
|
VanActionSheet: typeof import('vant/es')['ActionSheet']
|
||||||
VanDialog: typeof import('vant/es')['Dialog']
|
VanDialog: typeof import('vant/es')['Dialog']
|
||||||
|
|||||||
@@ -2,6 +2,65 @@
|
|||||||
<html lang="fa" dir="rtl">
|
<html lang="fa" dir="rtl">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
|
<script>
|
||||||
|
(function () {
|
||||||
|
try {
|
||||||
|
var icon = ''
|
||||||
|
try {
|
||||||
|
icon = localStorage.getItem('PWA_INSTALL_ICON_URL') || ''
|
||||||
|
} catch (e) {}
|
||||||
|
var title = ''
|
||||||
|
try {
|
||||||
|
var raw = localStorage.getItem('PWA_MANIFEST_CACHE_V5')
|
||||||
|
if (raw) {
|
||||||
|
var payload = JSON.parse(raw)
|
||||||
|
var manifest = payload && payload.manifest
|
||||||
|
if (manifest) {
|
||||||
|
title = manifest.short_name || manifest.name || ''
|
||||||
|
if (!icon && manifest.icons && manifest.icons.length) {
|
||||||
|
var icons = manifest.icons
|
||||||
|
var pick = function (size) {
|
||||||
|
var target = size + 'x' + size
|
||||||
|
for (var i = 0; i < icons.length; i++) {
|
||||||
|
if (String(icons[i].sizes || '').indexOf(target) !== -1 && icons[i].src) {
|
||||||
|
return icons[i].src
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
icon = pick(180) || pick(192) || pick(512) || (icons[0] && icons[0].src) || ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
if (title) {
|
||||||
|
document.title = title
|
||||||
|
var appleTitle = document.createElement('meta')
|
||||||
|
appleTitle.name = 'apple-mobile-web-app-title'
|
||||||
|
appleTitle.content = title
|
||||||
|
document.head.appendChild(appleTitle)
|
||||||
|
}
|
||||||
|
if (icon) {
|
||||||
|
var sized = document.createElement('link')
|
||||||
|
sized.rel = 'apple-touch-icon'
|
||||||
|
sized.setAttribute('data-dynamic-pwa', 'true')
|
||||||
|
sized.setAttribute('data-pwa-icon-src', icon)
|
||||||
|
sized.setAttribute('sizes', '180x180')
|
||||||
|
sized.href = icon
|
||||||
|
document.head.appendChild(sized)
|
||||||
|
var primary = document.createElement('link')
|
||||||
|
primary.rel = 'apple-touch-icon'
|
||||||
|
primary.setAttribute('data-dynamic-pwa', 'true')
|
||||||
|
primary.setAttribute('data-pwa-icon-src', icon)
|
||||||
|
primary.href = icon
|
||||||
|
document.head.appendChild(primary)
|
||||||
|
var img = new Image()
|
||||||
|
img.decoding = 'async'
|
||||||
|
img.src = icon
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
})()
|
||||||
|
</script>
|
||||||
<meta name="enamad" content="44889195" />
|
<meta name="enamad" content="44889195" />
|
||||||
|
|
||||||
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
|
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
|
||||||
@@ -12,6 +71,8 @@
|
|||||||
name="viewport"
|
name="viewport"
|
||||||
content="width=device-width, initial-scale=1.0, viewport-fit=cover, interactive-widget=resizes-content"
|
content="width=device-width, initial-scale=1.0, viewport-fit=cover, interactive-widget=resizes-content"
|
||||||
/>
|
/>
|
||||||
|
<meta name="apple-mobile-web-app-capable" content="yes" />
|
||||||
|
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
|
||||||
|
|
||||||
<title>در حال بارگذاری...</title>
|
<title>در حال بارگذاری...</title>
|
||||||
<!---->
|
<!---->
|
||||||
@@ -33,15 +94,19 @@
|
|||||||
body {
|
body {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
min-height: 100%;
|
min-height: 100%;
|
||||||
|
width: 100%;
|
||||||
background: var(--boot-bg);
|
background: var(--boot-bg);
|
||||||
}
|
}
|
||||||
|
|
||||||
#app {
|
#app {
|
||||||
min-height: 100vh;
|
min-height: 100vh;
|
||||||
|
width: 100%;
|
||||||
|
max-width: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.boot-loader {
|
.boot-loader {
|
||||||
min-height: 100vh;
|
min-height: 100vh;
|
||||||
|
width: 100%;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
@@ -85,13 +150,22 @@
|
|||||||
display: block !important;
|
display: block !important;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#app,
|
||||||
|
.boot-loader {
|
||||||
|
width: 100% !important;
|
||||||
|
max-width: none !important;
|
||||||
|
}
|
||||||
.app-splash-screen {
|
.app-splash-screen {
|
||||||
position: fixed;
|
position: fixed !important;
|
||||||
inset: 0;
|
inset: 0 !important;
|
||||||
width: 100vw;
|
width: 100vw !important;
|
||||||
min-height: 100vh;
|
min-width: 100vw !important;
|
||||||
|
max-width: none !important;
|
||||||
|
min-height: 100vh !important;
|
||||||
left: 0 !important;
|
left: 0 !important;
|
||||||
right: 0 !important;
|
right: 0 !important;
|
||||||
|
margin: 0 !important;
|
||||||
|
transform: none !important;
|
||||||
z-index: 2147483646;
|
z-index: 2147483646;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
@@ -328,30 +402,49 @@
|
|||||||
return window.location.protocol === 'https:' ? 'https:' : 'http:'
|
return window.location.protocol === 'https:' ? 'https:' : 'http:'
|
||||||
}
|
}
|
||||||
|
|
||||||
function getVersionUrls() {
|
function resolveTenantDomain() {
|
||||||
var protocol = getProtocol()
|
var host = String(window.location.hostname || '').trim()
|
||||||
|
if (!host || host === 'localhost' || host === '127.0.0.1') {
|
||||||
|
return 'k.montzar.ir'
|
||||||
|
}
|
||||||
|
return host
|
||||||
|
}
|
||||||
|
|
||||||
|
function getSuperAdminBases() {
|
||||||
return [
|
return [
|
||||||
'https://nerkh.gold/get_version',
|
'https://adm.montzar.ir',
|
||||||
'https://tablo.talasevin.ir/get_version',
|
'https://adm.montech.ir',
|
||||||
'https://abshode-service.montgit.ir/server/get_version',
|
'https://adm.montest.ir'
|
||||||
protocol + '//212.23.201.173:8381/get_version',
|
|
||||||
protocol + '//91.212.174.137:4040/server/get_version'
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getVersionUrls() {
|
||||||
|
var domain = encodeURIComponent(resolveTenantDomain())
|
||||||
|
return getSuperAdminBases().map(function (base) {
|
||||||
|
return base + '/get_version?domain=' + domain
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function getConfigUrls() {
|
function getConfigUrls() {
|
||||||
var protocol = getProtocol()
|
var domain = encodeURIComponent(resolveTenantDomain())
|
||||||
|
return getSuperAdminBases().map(function (base) {
|
||||||
return [
|
return base + '/get_user?domain=' + domain
|
||||||
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'
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// پاککردن URL موفقیت قدیمی رجیستری (مثل nerkh.gold)
|
||||||
|
;(function clearLegacyConfigSuccess() {
|
||||||
|
var last = localStorage.getItem(CONFIG_SUCCESS_URL_KEY)
|
||||||
|
if (!last) return
|
||||||
|
var ok = getSuperAdminBases().some(function (base) {
|
||||||
|
return last.indexOf(base) === 0
|
||||||
|
})
|
||||||
|
if (!ok) {
|
||||||
|
localStorage.removeItem(CONFIG_SUCCESS_URL_KEY)
|
||||||
|
document.cookie = CONFIG_COOKIE_NAME + '=; Path=/; Max-Age=0; SameSite=Lax'
|
||||||
|
}
|
||||||
|
})()
|
||||||
|
|
||||||
function sortVersionUrls(urls) {
|
function sortVersionUrls(urls) {
|
||||||
var lastSuccessUrl = localStorage.getItem(VERSION_SUCCESS_URL_KEY)
|
var lastSuccessUrl = localStorage.getItem(VERSION_SUCCESS_URL_KEY)
|
||||||
|
|
||||||
@@ -367,6 +460,11 @@
|
|||||||
function sortByLastSuccess(urls) {
|
function sortByLastSuccess(urls) {
|
||||||
var lastSuccessUrl = localStorage.getItem(CONFIG_SUCCESS_URL_KEY)
|
var lastSuccessUrl = localStorage.getItem(CONFIG_SUCCESS_URL_KEY)
|
||||||
|
|
||||||
|
if (lastSuccessUrl && urls.indexOf(lastSuccessUrl) === -1) {
|
||||||
|
localStorage.removeItem(CONFIG_SUCCESS_URL_KEY)
|
||||||
|
lastSuccessUrl = null
|
||||||
|
}
|
||||||
|
|
||||||
return urls.slice().sort(function (a, b) {
|
return urls.slice().sort(function (a, b) {
|
||||||
if (a === lastSuccessUrl) return -1
|
if (a === lastSuccessUrl) return -1
|
||||||
if (b === lastSuccessUrl) return 1
|
if (b === lastSuccessUrl) return 1
|
||||||
@@ -650,10 +748,10 @@
|
|||||||
'<div style="font-size: 42px; margin-bottom: 12px;">⚠️</div>' +
|
'<div style="font-size: 42px; margin-bottom: 12px;">⚠️</div>' +
|
||||||
'<h2 style="margin: 0 0 12px; font-size: 20px;">خطا در بارگذاری برنامه</h2>' +
|
'<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 style="margin: 0 0 20px; color: var(--boot-muted); line-height: 2; font-size: 14px;">' +
|
||||||
'ارتباط با سرور برقرار نشد یا فایلهای برنامه بهدرستی دریافت نشدند.' +
|
'برقراری ارتباط با سرور امکانپذیر نیست. لطفاً اتصال اینترنت خود را بررسی کرده و صفحه را تازهسازی نمایید.' +
|
||||||
'</p>' +
|
'</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 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>' +
|
||||||
'<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;">' +
|
'<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;">' +
|
||||||
'پاکسازی و تلاش مجدد' +
|
'پاکسازی و تلاش مجدد' +
|
||||||
@@ -665,8 +763,8 @@
|
|||||||
async function cleanFetchAndReload() {
|
async function cleanFetchAndReload() {
|
||||||
renderRecovering('در حال دریافت تنظیمات جدید برنامه...')
|
renderRecovering('در حال دریافت تنظیمات جدید برنامه...')
|
||||||
|
|
||||||
var version = await loadRemoteVersion(5)
|
var version = await loadRemoteVersion(3)
|
||||||
var freshConfigResult = await fetchFreshConfig(5)
|
var freshConfigResult = await fetchFreshConfig(3)
|
||||||
|
|
||||||
clearReadableCookies()
|
clearReadableCookies()
|
||||||
// clearLocalStorageExceptToken()
|
// clearLocalStorageExceptToken()
|
||||||
|
|||||||
@@ -35,7 +35,8 @@
|
|||||||
"vue3-apexcharts": "^1.4.4",
|
"vue3-apexcharts": "^1.4.4",
|
||||||
"vue3-lazyload": "^0.3.8",
|
"vue3-lazyload": "^0.3.8",
|
||||||
"vue3-odometer": "^0.1.3",
|
"vue3-odometer": "^0.1.3",
|
||||||
"vue3-otp-input": "^0.4.1"
|
"vue3-otp-input": "^0.4.1",
|
||||||
|
"wavesurfer.js": "^7.12.11"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@rushstack/eslint-patch": "^1.3.2",
|
"@rushstack/eslint-patch": "^1.3.2",
|
||||||
@@ -9121,6 +9122,12 @@
|
|||||||
"loose-envify": "^1.0.0"
|
"loose-envify": "^1.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/wavesurfer.js": {
|
||||||
|
"version": "7.12.11",
|
||||||
|
"resolved": "https://registry.npmjs.org/wavesurfer.js/-/wavesurfer.js-7.12.11.tgz",
|
||||||
|
"integrity": "sha512-Sx0yZIz7jRJ9J9p7UL+pl9y0UQBB6UN/XNo+R7Gy4tCR5xZI9jMyA0dnt1R8TMVSQ4LZ10SeB2HJYQ+dV2dPSA==",
|
||||||
|
"license": "BSD-3-Clause"
|
||||||
|
},
|
||||||
"node_modules/webidl-conversions": {
|
"node_modules/webidl-conversions": {
|
||||||
"version": "4.0.2",
|
"version": "4.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-4.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-4.0.2.tgz",
|
||||||
|
|||||||
@@ -39,7 +39,8 @@
|
|||||||
"vue3-apexcharts": "^1.4.4",
|
"vue3-apexcharts": "^1.4.4",
|
||||||
"vue3-lazyload": "^0.3.8",
|
"vue3-lazyload": "^0.3.8",
|
||||||
"vue3-odometer": "^0.1.3",
|
"vue3-odometer": "^0.1.3",
|
||||||
"vue3-otp-input": "^0.4.1"
|
"vue3-otp-input": "^0.4.1",
|
||||||
|
"wavesurfer.js": "^7.12.11"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@rushstack/eslint-patch": "^1.3.2",
|
"@rushstack/eslint-patch": "^1.3.2",
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
{"nm":"Pre-comp 1","ddd":0,"h":1200,"w":1200,"meta":{"g":"LottieFiles AE 0.1.21"},"layers":[{"ty":4,"nm":"arrow down Outlines","sr":1,"st":0,"op":1020,"ip":0,"hd":false,"ddd":0,"bm":0,"hasMask":false,"ao":0,"ks":{"a":{"a":0,"k":[256,256,0],"ix":1},"s":{"a":0,"k":[46.875,46.875,100],"ix":6},"sk":{"a":0,"k":0},"p":{"a":1,"k":[{"o":{"x":0.333,"y":0},"i":{"x":0.667,"y":1},"s":[600,528,0],"t":0,"ti":[0,0,0],"to":[0,-15.333,0]},{"o":{"x":0.333,"y":0},"i":{"x":0.667,"y":1},"s":[600,436,0],"t":13,"ti":[0,-15.333,0],"to":[0,0,0]},{"s":[600,528,0],"t":27}],"ix":2,"x":"var $bm_rt;\n$bm_rt = loopOut('cycle');"},"r":{"a":0,"k":0,"ix":10},"sa":{"a":0,"k":0},"o":{"a":0,"k":100,"ix":11}},"ef":[],"shapes":[{"ty":"gr","bm":0,"hd":false,"mn":"ADBE Vector Group","nm":"Group 1","ix":1,"cix":2,"np":4,"it":[{"ty":"sh","bm":0,"hd":false,"mn":"ADBE Vector Shape - Group","nm":"Path 1","ix":1,"d":1,"ks":{"a":0,"k":{"c":true,"i":[[7.831,7.793],[7.792,-7.828],[0,0],[0,0],[11.045,0],[0,-11.046],[0,0],[0,0],[7.829,-7.792],[-7.791,-7.829],[0,0],[-0.005,-0.006],[-7.819,7.833],[-0.005,0.006],[0,0]],"o":[[-7.829,-7.792],[0,0],[0,0],[0,-11.046],[-11.046,0],[0,0],[0,0],[-7.792,-7.828],[-7.83,7.793],[0,0],[0.006,0.007],[7.792,7.809],[0.006,-0.007],[0,0],[7.79,-7.828]],"v":[[118.109,117.328],[89.825,117.394],[20.001,187.557],[20.001,-236],[0.001,-256],[-19.999,-236],[-19.999,187.557],[-89.824,117.393],[-118.107,117.327],[-118.175,145.612],[-14.175,250.116],[-14.157,250.134],[14.158,250.135],[14.176,250.117],[118.176,145.613]]},"ix":2}},{"ty":"fl","bm":0,"hd":false,"mn":"ADBE Vector Graphic - Fill","nm":"Fill 1","c":{"a":0,"k":[0.1608,0.1608,0.3843],"ix":4},"r":1,"o":{"a":0,"k":100,"ix":5}},{"ty":"tr","a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"sk":{"a":0,"k":0,"ix":4},"p":{"a":0,"k":[255.999,256],"ix":2},"r":{"a":0,"k":0,"ix":6},"sa":{"a":0,"k":0,"ix":5},"o":{"a":0,"k":100,"ix":7}}]}],"ind":1},{"ty":4,"nm":"Shape Layer 1","sr":1,"st":0,"op":1020,"ip":0,"hd":false,"ddd":0,"bm":0,"hasMask":false,"ao":0,"ks":{"a":{"a":0,"k":[0,0,0],"ix":1},"s":{"a":0,"k":[141,141,100],"ix":6},"sk":{"a":0,"k":0},"p":{"a":1,"k":[{"o":{"x":0.333,"y":0},"i":{"x":0.667,"y":1},"s":[622.56,380.04,0],"t":0,"ti":[0,0,0],"to":[0,-15.333,0]},{"o":{"x":0.333,"y":0},"i":{"x":0.667,"y":1},"s":[622.56,288.04,0],"t":13,"ti":[0,-15.333,0],"to":[0,0,0]},{"s":[622.56,380.04,0],"t":27}],"ix":2,"x":"var $bm_rt;\n$bm_rt = loopOut('cycle');"},"r":{"a":0,"k":0,"ix":10},"sa":{"a":0,"k":0},"o":{"a":0,"k":100,"ix":11}},"ef":[],"shapes":[{"ty":"gr","bm":0,"hd":false,"mn":"ADBE Vector Group","nm":"Ellipse 1","ix":1,"cix":2,"np":3,"it":[{"ty":"el","bm":0,"hd":false,"mn":"ADBE Vector Shape - Ellipse","nm":"Ellipse Path 1","d":1,"p":{"a":0,"k":[0,0],"ix":3},"s":{"a":0,"k":[144,144],"ix":2}},{"ty":"fl","bm":0,"hd":false,"mn":"ADBE Vector Graphic - Fill","nm":"Fill 1","c":{"a":0,"k":[1,1,1],"ix":4},"r":1,"o":{"a":0,"k":100,"ix":5}},{"ty":"tr","a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"sk":{"a":0,"k":0,"ix":4},"p":{"a":0,"k":[-16,156],"ix":2},"r":{"a":0,"k":0,"ix":6},"sa":{"a":0,"k":0,"ix":5},"o":{"a":0,"k":100,"ix":7}}]}],"ind":2}],"v":"5.5.7","fr":30,"op":1020,"ip":0,"assets":[]}
|
||||||
@@ -1,4 +1,19 @@
|
|||||||
<template>
|
<template>
|
||||||
|
<!-- Splash outside .desktopConfig so the 426px mobile frame cannot clip it -->
|
||||||
|
<div
|
||||||
|
v-if="showSplash"
|
||||||
|
class="app-splash-screen flex justify-center"
|
||||||
|
:style="{ backgroundColor: getProjectSplashBackground() }"
|
||||||
|
>
|
||||||
|
<div class="self-center splash_appear_fade_in">
|
||||||
|
<img
|
||||||
|
:src="getProjectSplashLogo(config?.config?.avatar)"
|
||||||
|
class="w-[min(72vw,280px)] h-auto object-contain"
|
||||||
|
alt=""
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="desktopConfig w-full right-0 left-0">
|
<div class="desktopConfig w-full right-0 left-0">
|
||||||
<div v-if="popVisible" class="top-0 bottom-0 wrap-fix bg-primary z-100 opacity-60">
|
<div v-if="popVisible" class="top-0 bottom-0 wrap-fix bg-primary z-100 opacity-60">
|
||||||
<div class="absolute right-0 left-0 bottom-10vh flex flex-col items-center">
|
<div class="absolute right-0 left-0 bottom-10vh flex flex-col items-center">
|
||||||
@@ -10,27 +25,21 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<AConfigProvider :theme="antTheme ?? undefined" direction="rtl">
|
<AConfigProvider :theme="antTheme ?? undefined" direction="rtl">
|
||||||
<div v-if="showSplash" class="app-splash-screen flex justify-center" :style="{ backgroundColor: getProjectSplashBackground() }">
|
<div v-if="!showSplash" class="app-main">
|
||||||
<div class="self-center splash_appear_fade_in">
|
|
||||||
<img
|
|
||||||
:src="getProjectSplashLogo(config?.config?.avatar)"
|
|
||||||
class="w-[min(72vw,280px)] h-auto object-contain"
|
|
||||||
alt=""
|
|
||||||
>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div v-else class="app-main">
|
|
||||||
<router-view v-slot="{ Component, route }">
|
<router-view v-slot="{ Component, route }">
|
||||||
<component :is="Component" :key="route.fullPath" />
|
<component :is="Component" :key="route.fullPath" />
|
||||||
</router-view>
|
</router-view>
|
||||||
</div>
|
</div>
|
||||||
</AConfigProvider>
|
</AConfigProvider>
|
||||||
<div
|
<div
|
||||||
v-if="showSupportButton && !showSplash"
|
v-if="showSupportButton && !showSplash && route.name !== 'support' && !isTvBoardRoute"
|
||||||
id="support-button"
|
id="support-button"
|
||||||
class="draggable-support-button"
|
ref="supportButtonEl"
|
||||||
:class="{ 'is-dragging': supportDragging }"
|
class="fixed z-[5100] cursor-grab select-none rounded-full"
|
||||||
|
:class="{
|
||||||
|
'cursor-grabbing': supportDragging,
|
||||||
|
'z-[var(--app-z-support-fab-open,5615)]': supportPickerOpen,
|
||||||
|
}"
|
||||||
:style="supportButtonStyle"
|
:style="supportButtonStyle"
|
||||||
title="پشتیبانی"
|
title="پشتیبانی"
|
||||||
@pointerdown="onSupportPointerDown"
|
@pointerdown="onSupportPointerDown"
|
||||||
@@ -38,26 +47,69 @@
|
|||||||
@pointerup="handleSupportPointerUp"
|
@pointerup="handleSupportPointerUp"
|
||||||
@pointercancel="onSupportPointerCancel"
|
@pointercancel="onSupportPointerCancel"
|
||||||
>
|
>
|
||||||
<div class="support-button-inner" :style="{ '--support-accent': supportAccentColor }">
|
<div
|
||||||
<BasicIcon :icon="supportIcon" size="18" class="support-button-icon" />
|
class="relative inline-flex items-center gap-2 rounded-full bg-white border border-solid border-gray-200 shadow-[0_6px_20px_rgba(15,23,42,0.14)] px-3.5 py-[9px] text-slate-800 text-[13px] font-600 leading-none transition-all duration-200"
|
||||||
<span class="support-button-label">پشتیبانی</span>
|
:class="{
|
||||||
|
'shadow-[0_10px_28px_rgba(15,23,42,0.22)]': supportDragging,
|
||||||
|
'scale-[0.94] shadow-[0_4px_14px_rgba(15,23,42,0.12)]': supportPickerOpen && !supportDragging,
|
||||||
|
}"
|
||||||
|
>
|
||||||
|
<BasicIcon
|
||||||
|
:icon="supportIcon"
|
||||||
|
size="18"
|
||||||
|
:color="supportAccentColor"
|
||||||
|
class="shrink-0"
|
||||||
|
/>
|
||||||
|
<span class="whitespace-nowrap">پشتیبانی</span>
|
||||||
|
<span
|
||||||
|
v-if="supportChatUnreadCount > 0"
|
||||||
|
class="support-fab-badge"
|
||||||
|
>
|
||||||
|
{{ supportChatUnreadCount > 99 ? '99+' : supportChatUnreadCount }}
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
v-if="!showSplash && !isDesktop"
|
v-if="!showSplash && !isDesktop && !isTvBoardRoute"
|
||||||
class="app-credit-footer app-credit-footer--mobile"
|
class="app-credit-footer app-credit-footer--mobile"
|
||||||
|
:class="{ 'app-credit-footer--login': isLoginRoute }"
|
||||||
>
|
>
|
||||||
|
<EnamadBadge v-if="isLoginRoute" size="sm" />
|
||||||
<AppCreditLink variant="mobile" />
|
<AppCreditLink variant="mobile" />
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
v-if="!showSplash && showDesktopFloatingCredit"
|
v-if="!showSplash && showDesktopFloatingCredit && !isTvBoardRoute"
|
||||||
class="app-credit-footer app-credit-footer--desktop-float"
|
class="app-credit-footer app-credit-footer--desktop-float"
|
||||||
|
:class="{ 'app-credit-footer--login': isLoginRoute }"
|
||||||
>
|
>
|
||||||
|
<EnamadBadge v-if="isLoginRoute" size="sm" />
|
||||||
<AppCreditLink variant="float" />
|
<AppCreditLink variant="float" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<SupportMessengerPicker
|
||||||
|
v-model:open="supportPickerOpen"
|
||||||
|
:entries="supportMessengerEntries"
|
||||||
|
:anchor-el="pickerAnchorEl"
|
||||||
|
@select="openMessengerEntry"
|
||||||
|
/>
|
||||||
|
|
||||||
<VersionUpdateModal />
|
<VersionUpdateModal />
|
||||||
|
|
||||||
|
<PwaInstallBanner
|
||||||
|
v-if="!showSplash && !isTvBoardRoute"
|
||||||
|
:visible="bannerVisible && !guideOpen"
|
||||||
|
@install="openGuide()"
|
||||||
|
@dismiss="dismissBanner()"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<PwaInstallGuideModal
|
||||||
|
v-model:open="guideOpen"
|
||||||
|
:platform="platform"
|
||||||
|
@complete="completeGuide()"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<GoldDayCalculatorModal />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
@@ -68,15 +120,30 @@ import {getProjectFontFamily, getProjectSplashBackground, getProjectSplashLogo,
|
|||||||
import {ConfigProvider as AConfigProvider} from 'ant-design-vue'
|
import {ConfigProvider as AConfigProvider} from 'ant-design-vue'
|
||||||
import BasicIcon from "@/components/BasicPacks/BasicIcon.vue";
|
import BasicIcon from "@/components/BasicPacks/BasicIcon.vue";
|
||||||
import { useApplyDesktopLayoutClass, useDesktopBreakpoint } from '@/layouts/composables/useAppLayout'
|
import { useApplyDesktopLayoutClass, useDesktopBreakpoint } from '@/layouts/composables/useAppLayout'
|
||||||
import {
|
import { useSupportMessenger } from '@/composables/useSupportMessenger'
|
||||||
buildSupportMessengerUrl,
|
import { loadSupportMessengerFromSettings } from '@/utils/supportMessenger'
|
||||||
loadSupportMessengerFromSettings,
|
|
||||||
supportMessengerSettings,
|
|
||||||
} from '@/utils/supportMessenger'
|
|
||||||
import { useDraggableFloatingButton } from '@/utils/useDraggableFloatingButton'
|
import { useDraggableFloatingButton } from '@/utils/useDraggableFloatingButton'
|
||||||
import AppCreditLink from '@/components/AppCreditLink.vue'
|
import AppCreditLink from '@/components/AppCreditLink.vue'
|
||||||
|
import EnamadBadge from '@/components/EnamadBadge.vue'
|
||||||
|
import SupportMessengerPicker from '@/components/SupportMessengerPicker.vue'
|
||||||
import { useRoute } from 'vue-router'
|
import { useRoute } from 'vue-router'
|
||||||
import { recoverMobileViewportAfterAuth } from '@/layouts/composables/useMobileScrollReset'
|
import { recoverMobileViewportAfterAuth } from '@/layouts/composables/useMobileScrollReset'
|
||||||
|
import { usePwaInstall } from '@/composables/usePwaInstall'
|
||||||
|
import PwaInstallBanner from '@/components/pwa/PwaInstallBanner.vue'
|
||||||
|
import PwaInstallGuideModal from '@/components/pwa/PwaInstallGuideModal.vue'
|
||||||
|
import GoldDayCalculatorModal from '@/components/GoldDayCalculatorModal.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 { message } from 'ant-design-vue'
|
||||||
|
import { showBrowserNotification } from '@/utils/browserNotification'
|
||||||
|
|
||||||
const VersionUpdateModal = defineAsyncComponent(
|
const VersionUpdateModal = defineAsyncComponent(
|
||||||
() => import('@/modules/version/VersionUpdateModal.vue')
|
() => import('@/modules/version/VersionUpdateModal.vue')
|
||||||
@@ -90,52 +157,55 @@ const showDesktopFloatingCredit = computed(() => {
|
|||||||
if (!isDesktop.value) return false
|
if (!isDesktop.value) return false
|
||||||
return route.name === 'login' || !!route.meta.hideMenu
|
return route.name === 'login' || !!route.meta.hideMenu
|
||||||
})
|
})
|
||||||
|
const isLoginRoute = computed(() => route.name === 'login')
|
||||||
|
|
||||||
const config = useConfigStore()
|
const config = useConfigStore()
|
||||||
const showSplash = ref(true)
|
|
||||||
|
function isTvBoardPath() {
|
||||||
|
const path = window.location.pathname.replace(/\/+$/, '')
|
||||||
|
return path.endsWith('/tv') || path.endsWith('/monitor')
|
||||||
|
}
|
||||||
|
|
||||||
|
const showSplash = ref(!isTvBoardPath())
|
||||||
|
const isTvBoardRoute = computed(
|
||||||
|
() => route.name === 'tvMonitor' || route.meta.hideChrome === true || isTvBoardPath(),
|
||||||
|
)
|
||||||
const popVisible = ref(false)
|
const popVisible = ref(false)
|
||||||
|
|
||||||
const supportLink = computed(() => {
|
const {
|
||||||
return buildSupportMessengerUrl(
|
guideOpen,
|
||||||
supportMessengerSettings.value.messenger,
|
bannerVisible,
|
||||||
supportMessengerSettings.value.messengerId
|
platform,
|
||||||
)
|
openGuide,
|
||||||
})
|
dismissBanner,
|
||||||
|
completeGuide,
|
||||||
|
showBanner,
|
||||||
|
} = usePwaInstall()
|
||||||
|
|
||||||
const showSupportButton = computed(() => !!supportLink.value)
|
const {
|
||||||
|
supportPickerOpen,
|
||||||
|
supportPickerAnchor,
|
||||||
|
supportMessengerEntries,
|
||||||
|
messengerMeta,
|
||||||
|
isChatEnabled,
|
||||||
|
hasMessengerLink: showSupportButton,
|
||||||
|
openMessengerEntry,
|
||||||
|
openSupportMessenger,
|
||||||
|
} = useSupportMessenger()
|
||||||
|
|
||||||
const supportIcon = computed(() => {
|
const supportButtonEl = ref<HTMLElement | null>(null)
|
||||||
const messenger = (supportMessengerSettings.value.messenger ?? '').toLowerCase()
|
const pickerAnchorEl = computed(() => supportPickerAnchor.value ?? supportButtonEl.value)
|
||||||
switch (messenger) {
|
|
||||||
case 'whatsapp':
|
const supportChatUnreadCount = computed(() =>
|
||||||
return 'vuesax-linear:whatsapp'
|
isChatEnabled.value ? Number(unreadSupportCount.value) || 0 : 0,
|
||||||
case 'telegram':
|
)
|
||||||
return 'vuesax-linear:send-2'
|
|
||||||
case 'bale':
|
const supportIcon = computed(() => messengerMeta.value.icon)
|
||||||
return 'vuesax-linear:messages-2'
|
|
||||||
default:
|
|
||||||
return 'vuesax-linear:messages-2'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
const supportAccentColor = computed(() => {
|
const supportAccentColor = computed(() => {
|
||||||
const messenger = (supportMessengerSettings.value.messenger ?? '').toLowerCase()
|
const accent = messengerMeta.value.accent
|
||||||
switch (messenger) {
|
if (accent !== '#334155') return accent
|
||||||
case 'whatsapp':
|
return config.config?.color || accent
|
||||||
return '#22c55e'
|
|
||||||
case 'telegram':
|
|
||||||
return '#0ea5e9'
|
|
||||||
case 'bale':
|
|
||||||
return '#16a34a'
|
|
||||||
case 'rubika':
|
|
||||||
return '#7c3aed'
|
|
||||||
case 'eitaa':
|
|
||||||
return '#f59e0b'
|
|
||||||
case 'soroush':
|
|
||||||
return '#2563eb'
|
|
||||||
default:
|
|
||||||
return config.config?.color || '#334155'
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const {
|
const {
|
||||||
@@ -153,14 +223,14 @@ const {
|
|||||||
})
|
})
|
||||||
|
|
||||||
function openSupportLink() {
|
function openSupportLink() {
|
||||||
if (!supportLink.value) return
|
void openSupportMessenger(supportButtonEl.value)
|
||||||
window.open(supportLink.value, '_blank', 'noopener,noreferrer')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleSupportPointerUp(event: PointerEvent) {
|
function handleSupportPointerUp(event: PointerEvent) {
|
||||||
if (supportPointerUp(event)) {
|
const clicked = supportPointerUp(event)
|
||||||
openSupportLink()
|
if (!clicked) return
|
||||||
}
|
event.stopPropagation()
|
||||||
|
openSupportLink()
|
||||||
}
|
}
|
||||||
|
|
||||||
const antTheme = computed(() => {
|
const antTheme = computed(() => {
|
||||||
@@ -196,11 +266,23 @@ onMounted(async () => {
|
|||||||
}, 2000)
|
}, 2000)
|
||||||
})
|
})
|
||||||
|
|
||||||
watch(showSplash, (visible) => {
|
watch(
|
||||||
if (!visible) {
|
showSplash,
|
||||||
|
(visible) => {
|
||||||
|
if (visible) {
|
||||||
|
const splashBg = getProjectSplashBackground()
|
||||||
|
document.documentElement.style.backgroundColor = splashBg
|
||||||
|
document.body.style.backgroundColor = splashBg
|
||||||
|
return
|
||||||
|
}
|
||||||
resetAppSurfaceBackground()
|
resetAppSurfaceBackground()
|
||||||
}
|
void import('@/utils/safeAreaInsets').then(({ syncSafeAreaInsets }) => {
|
||||||
})
|
syncSafeAreaInsets()
|
||||||
|
})
|
||||||
|
showBanner()
|
||||||
|
},
|
||||||
|
{ immediate: true },
|
||||||
|
)
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => route.name,
|
() => route.name,
|
||||||
@@ -213,13 +295,76 @@ watch(
|
|||||||
{ flush: 'post' },
|
{ flush: 'post' },
|
||||||
)
|
)
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
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>
|
</script>
|
||||||
|
|
||||||
<style lang="less">
|
<style lang="less">
|
||||||
/* ارتفاع نوار اعتبار + safe-area؛ منوی پایین با bottom: var(--app-credit-footer-offset) بالاتر از این نوار مینشیند */
|
/* ارتفاع نوار اعتبار + safe-area؛ منوی پایین با bottom: var(--app-credit-footer-offset) بالاتر از این نوار مینشیند */
|
||||||
:root {
|
:root {
|
||||||
--app-credit-bar-inner: 28px;
|
--app-credit-bar-inner: 28px;
|
||||||
|
/* constant برای iOS قدیمی؛ env باید مستقیم هم در مصرفکنندهها تکرار شود */
|
||||||
|
--app-safe-top: 0px;
|
||||||
|
--app-safe-top: constant(safe-area-inset-top);
|
||||||
--app-safe-top: env(safe-area-inset-top, 0px);
|
--app-safe-top: env(safe-area-inset-top, 0px);
|
||||||
|
--app-safe-bottom: 0px;
|
||||||
|
--app-safe-bottom: constant(safe-area-inset-bottom);
|
||||||
--app-safe-bottom: env(safe-area-inset-bottom, 0px);
|
--app-safe-bottom: env(safe-area-inset-bottom, 0px);
|
||||||
--app-home-header-offset: calc(4.25rem + var(--app-safe-top));
|
--app-home-header-offset: calc(4.25rem + var(--app-safe-top));
|
||||||
--app-credit-footer-offset: calc(var(--app-credit-bar-inner) + var(--app-safe-bottom));
|
--app-credit-footer-offset: calc(var(--app-credit-bar-inner) + var(--app-safe-bottom));
|
||||||
@@ -230,12 +375,20 @@ watch(
|
|||||||
/* بخشی از کارت کیفپول زیر نوار «افزودن کارت جدید» دیده میشود */
|
/* بخشی از کارت کیفپول زیر نوار «افزودن کارت جدید» دیده میشود */
|
||||||
--wallet-card-dock-overlap: 52px;
|
--wallet-card-dock-overlap: 52px;
|
||||||
--app-z-nav: 5000;
|
--app-z-nav: 5000;
|
||||||
|
--app-z-toast: 5050;
|
||||||
--app-z-wallet-dock: 4490;
|
--app-z-wallet-dock: 4490;
|
||||||
--app-z-wallet-add-bar: 4510;
|
--app-z-wallet-add-bar: 4510;
|
||||||
--app-z-action-sheet: 5200;
|
--app-z-action-sheet: 5200;
|
||||||
--app-z-dialog: 5300;
|
--app-z-dialog: 5300;
|
||||||
/* زیر لایه دراپداون اینت (99999) تا تقویم/سلکت داخل مدال روی آن باز شود */
|
/* زیر لایه دراپداون اینت (99999) تا تقویم/سلکت داخل مدال روی آن باز شود */
|
||||||
--app-z-modal: 5500;
|
--app-z-modal: 5500;
|
||||||
|
--app-z-support-picker: 5600;
|
||||||
|
--app-z-support-fab-open: 5615;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* نوار اعلان Ant — پیشفرض z-index:1010 زیر هدر fixed میرود */
|
||||||
|
.ant-notification {
|
||||||
|
z-index: var(--app-z-toast, 5050) !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.app-main {
|
.app-main {
|
||||||
@@ -257,25 +410,46 @@ watch(
|
|||||||
box-sizing: content-box;
|
box-sizing: content-box;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* toast اعلانهای اپ باید بالای نوار اعتبار باشد */
|
||||||
|
.ant-notification .app-notif-toast,
|
||||||
|
.app-notif-toast {
|
||||||
|
z-index: 1000001 !important;
|
||||||
|
}
|
||||||
|
|
||||||
.app-credit-footer--mobile {
|
.app-credit-footer--mobile {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
max-width: 426px;
|
max-width: 426px;
|
||||||
margin-left: auto;
|
margin-left: auto;
|
||||||
margin-right: auto;
|
margin-right: auto;
|
||||||
min-height: var(--app-credit-bar-inner);
|
min-height: var(--app-credit-bar-inner);
|
||||||
padding-bottom: var(--app-safe-bottom);
|
padding: 4px 0 var(--app-safe-bottom);
|
||||||
background: #fff;
|
background: #fff;
|
||||||
box-shadow: 0 -2px 4px -2px #0000001a;
|
box-shadow: 0 -2px 4px -2px #0000001a;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
gap: 4px;
|
||||||
font-size: 9px;
|
font-size: 9px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.app-credit-footer--login.app-credit-footer--mobile {
|
||||||
|
min-height: 72px;
|
||||||
|
}
|
||||||
|
|
||||||
|
:root:has(.app-credit-footer--login) {
|
||||||
|
--app-credit-bar-inner: 72px;
|
||||||
|
}
|
||||||
|
|
||||||
.app-credit-footer--desktop-float {
|
.app-credit-footer--desktop-float {
|
||||||
left: auto;
|
left: auto;
|
||||||
right: 20px;
|
right: 20px;
|
||||||
bottom: 16px;
|
bottom: 16px;
|
||||||
width: auto;
|
width: auto;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.app-credit-link {
|
.app-credit-link {
|
||||||
@@ -310,15 +484,30 @@ watch(
|
|||||||
}
|
}
|
||||||
|
|
||||||
&--sidebar {
|
&--sidebar {
|
||||||
flex-direction: column;
|
flex-direction: row;
|
||||||
gap: 6px;
|
flex-wrap: nowrap;
|
||||||
padding: 4px;
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
width: 100%;
|
||||||
|
max-width: 100%;
|
||||||
|
padding: 4px 4px;
|
||||||
color: #9ca3af;
|
color: #9ca3af;
|
||||||
font-size: 10px;
|
font-size: 11px;
|
||||||
|
line-height: 1.35;
|
||||||
|
text-align: center;
|
||||||
|
box-sizing: border-box;
|
||||||
|
|
||||||
|
.app-credit-link__text {
|
||||||
|
white-space: nowrap;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
.app-credit-link__logo {
|
.app-credit-link__logo {
|
||||||
height: 15px;
|
height: 15px;
|
||||||
opacity: 0.85;
|
max-width: 68px;
|
||||||
|
flex-shrink: 0;
|
||||||
|
opacity: 0.9;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -340,11 +529,15 @@ watch(
|
|||||||
|
|
||||||
html.project-boursecu {
|
html.project-boursecu {
|
||||||
.app-credit-link--sidebar {
|
.app-credit-link--sidebar {
|
||||||
color: rgba(255, 255, 255, 0.5);
|
color: rgba(255, 255, 255, 0.55);
|
||||||
|
|
||||||
.app-credit-link__logo {
|
.app-credit-link__logo {
|
||||||
filter: brightness(1.15);
|
filter: brightness(1.2);
|
||||||
opacity: 0.75;
|
opacity: 0.85;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
color: rgba(255, 255, 255, 0.85);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -362,50 +555,25 @@ html.project-boursecu {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#support-button {
|
#support-button {
|
||||||
position: fixed;
|
/* جای draggable از fabStyle میآید */
|
||||||
z-index: 5100;
|
|
||||||
cursor: grab;
|
|
||||||
user-select: none;
|
|
||||||
border-radius: 9999px;
|
|
||||||
|
|
||||||
&.is-dragging {
|
|
||||||
cursor: grabbing;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.support-button-inner {
|
.support-fab-badge {
|
||||||
display: inline-flex;
|
position: absolute;
|
||||||
align-items: center;
|
top: -6px;
|
||||||
gap: 8px;
|
left: -4px;
|
||||||
padding: 9px 14px 9px 12px;
|
z-index: 2;
|
||||||
background: #ffffff;
|
min-width: 18px;
|
||||||
border: 1px solid rgba(15, 23, 42, 0.08);
|
height: 18px;
|
||||||
border-radius: 9999px;
|
padding: 0 5px;
|
||||||
box-shadow: 0 6px 20px rgba(15, 23, 42, 0.14);
|
border-radius: 999px;
|
||||||
color: #1e293b;
|
background: #dc2626;
|
||||||
font-size: 13px;
|
color: #fff;
|
||||||
font-weight: 600;
|
font-size: 10px;
|
||||||
line-height: 1;
|
font-weight: 700;
|
||||||
direction: rtl;
|
line-height: 18px;
|
||||||
transition: box-shadow 0.2s ease, transform 0.2s ease;
|
text-align: center;
|
||||||
|
box-shadow: 0 0 0 2px #fff;
|
||||||
.support-button-icon {
|
|
||||||
color: var(--support-accent, #334155);
|
|
||||||
flex-shrink: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.support-button-label {
|
|
||||||
white-space: nowrap;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#support-button:not(.is-dragging):hover .support-button-inner {
|
|
||||||
transform: translateY(-1px);
|
|
||||||
box-shadow: 0 8px 24px rgba(15, 23, 42, 0.18);
|
|
||||||
}
|
|
||||||
|
|
||||||
#support-button.is-dragging .support-button-inner {
|
|
||||||
box-shadow: 0 10px 28px rgba(15, 23, 42, 0.22);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@media screen and (min-width: 426px) and (max-width: 767.98px) {
|
@media screen and (min-width: 426px) and (max-width: 767.98px) {
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
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`)
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
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`)
|
||||||
|
}
|
||||||
@@ -1,5 +1,8 @@
|
|||||||
import useAxios from "@/utils/useAxios";
|
import useAxios from '@/utils/useAxios'
|
||||||
|
import { getSuperAdminBase, resolveTenantDomain } from '@/config/superadmin'
|
||||||
|
|
||||||
export async function getConfig() {
|
export async function getConfig() {
|
||||||
return await useAxios.get(`https://nerkh.gold/get_user`)
|
const base = getSuperAdminBase() || 'https://adm.montzar.ir'
|
||||||
}
|
const domain = encodeURIComponent(resolveTenantDomain())
|
||||||
|
return await useAxios.get(`${base}/get_user?domain=${domain}`)
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,6 +6,10 @@ import type { PWallet, Wallet } from '@/models/wallet'
|
|||||||
export const getProducts = async (): Promise<any> => {
|
export const getProducts = async (): Promise<any> => {
|
||||||
return await useAxios.get<Product[]>(`/customer/product/list`)
|
return await useAxios.get<Product[]>(`/customer/product/list`)
|
||||||
}
|
}
|
||||||
|
export const getTvProducts = async (): Promise<Product[]> => {
|
||||||
|
const response = await useAxios.get<unknown>(`/customer/tv/products`)
|
||||||
|
return Array.isArray(response) ? (response as Product[]) : []
|
||||||
|
}
|
||||||
export const getProductInventory = async (): Promise<any> => {
|
export const getProductInventory = async (): Promise<any> => {
|
||||||
return await useAxios.post<PInventory[]>(`/customer/wallet/product/table`)
|
return await useAxios.post<PInventory[]>(`/customer/wallet/product/table`)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
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)
|
||||||
|
}
|
||||||
@@ -12,6 +12,8 @@ import { getToken } from '@/utils'
|
|||||||
import '@/utils/useDateTime'
|
import '@/utils/useDateTime'
|
||||||
import { initPriceRealtimeChannel } from '@/utils/priceSocket'
|
import { initPriceRealtimeChannel } from '@/utils/priceSocket'
|
||||||
import { initMobileScrollRestoration } from '@/layouts/composables/useMobileScrollReset'
|
import { initMobileScrollRestoration } from '@/layouts/composables/useMobileScrollReset'
|
||||||
|
import { initMobileInputKeyboardScroll } from '@/utils/mobileInputKeyboardScroll'
|
||||||
|
import { isServerUnavailableError } from '@/utils/serverUnavailable'
|
||||||
|
|
||||||
type BootWindow = Window & {
|
type BootWindow = Window & {
|
||||||
__BOOT_TIMEOUT__?: number
|
__BOOT_TIMEOUT__?: number
|
||||||
@@ -53,13 +55,13 @@ function showBootstrapError(error: unknown) {
|
|||||||
<div style="font-size: 42px; margin-bottom: 12px;">⚠️</div>
|
<div style="font-size: 42px; margin-bottom: 12px;">⚠️</div>
|
||||||
<h2 style="margin: 0 0 12px; font-size: 20px;">خطا در راهاندازی برنامه</h2>
|
<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 style="margin: 0 0 20px; color: var(--boot-muted, rgba(15,23,42,0.62)); line-height: 2; font-size: 14px;">
|
||||||
لطفاً اتصال اینترنت خود را بررسی کنید و دوباره تلاش کنید.
|
برقراری ارتباط با سرور امکانپذیر نیست. لطفاً اتصال اینترنت خود را بررسی کرده و صفحه را تازهسازی نمایید.
|
||||||
</p>
|
</p>
|
||||||
<button
|
<button
|
||||||
onclick="location.reload()"
|
onclick="location.reload()"
|
||||||
style="padding: 11px 22px; border: 0; border-radius: 12px; background: var(--boot-accent, #2563eb); color: white; cursor: pointer; font-weight: 700;"
|
style="padding: 11px 22px; border: 0; border-radius: 12px; background: var(--boot-accent, #2563eb); color: white; cursor: pointer; font-weight: 700;"
|
||||||
>
|
>
|
||||||
تلاش مجدد
|
تازهسازی صفحه
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -124,12 +126,13 @@ export async function bootstrapApp() {
|
|||||||
|
|
||||||
setupRouterGuards()
|
setupRouterGuards()
|
||||||
initMobileScrollRestoration()
|
initMobileScrollRestoration()
|
||||||
|
initMobileInputKeyboardScroll()
|
||||||
|
|
||||||
app.mount('#app')
|
app.mount('#app')
|
||||||
|
|
||||||
await router.isReady()
|
await router.isReady()
|
||||||
|
|
||||||
if (!getToken() && router.currentRoute.value.name !== 'login') {
|
if (!getToken() && router.currentRoute.value.name !== 'login' && router.currentRoute.value.name !== 'tvMonitor' && router.currentRoute.value.name !== 'aboutSoftware') {
|
||||||
await router.replace({ name: 'login' })
|
await router.replace({ name: 'login' })
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,6 +141,10 @@ export async function bootstrapApp() {
|
|||||||
sessionStorage.removeItem('__APP_BOOT_RECOVERY_DONE__')
|
sessionStorage.removeItem('__APP_BOOT_RECOVERY_DONE__')
|
||||||
sessionStorage.removeItem('__APP_BOOT_RETRY_CLICKED__')
|
sessionStorage.removeItem('__APP_BOOT_RETRY_CLICKED__')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
if (isServerUnavailableError(error)) {
|
||||||
|
clearBootTimeout()
|
||||||
|
return
|
||||||
|
}
|
||||||
showBootstrapError(error)
|
showBootstrapError(error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,8 +6,9 @@ import { useFundUserStore } from '@/store/fundStore'
|
|||||||
import type { NavigationGuardNext } from 'vue-router'
|
import type { NavigationGuardNext } from 'vue-router'
|
||||||
import { useAuthStore } from '@/store/useAuthStore'
|
import { useAuthStore } from '@/store/useAuthStore'
|
||||||
import { recoverMobileViewportAfterAuth } from '@/layouts/composables/useMobileScrollReset'
|
import { recoverMobileViewportAfterAuth } from '@/layouts/composables/useMobileScrollReset'
|
||||||
|
import { getFingerPosition, setFingerPosition } from '@/app/authBoot'
|
||||||
|
|
||||||
const PUBLIC_ROUTE_NAMES = ['login', '404', 'educate', 'aboutUs'] as const
|
const PUBLIC_ROUTE_NAMES = ['login', '404', 'educate', 'aboutUs', 'aboutSoftware', 'tvMonitor'] as const
|
||||||
|
|
||||||
function isPublicRoute(name: string | symbol | null | undefined) {
|
function isPublicRoute(name: string | symbol | null | undefined) {
|
||||||
return PUBLIC_ROUTE_NAMES.includes(name as (typeof PUBLIC_ROUTE_NAMES)[number])
|
return PUBLIC_ROUTE_NAMES.includes(name as (typeof PUBLIC_ROUTE_NAMES)[number])
|
||||||
@@ -76,6 +77,66 @@ export function setupRouterGuards() {
|
|||||||
return goToLogin(next)
|
return goToLogin(next)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (to.name === 'notifyTrigger') {
|
||||||
|
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 === 'giftCard') {
|
||||||
|
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 (to.name === 'appNotifications') {
|
||||||
|
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 === 'piggy' ||
|
||||||
|
to.name === 'fund' ||
|
||||||
|
to.name === 'fund_info' ||
|
||||||
|
to.name === 'fund_add'
|
||||||
|
) {
|
||||||
|
const { useSettingsStore } = await import('@/store/settingsStore')
|
||||||
|
const settingsStore = useSettingsStore()
|
||||||
|
if (!settingsStore.loaded) {
|
||||||
|
await settingsStore.fetchSettings()
|
||||||
|
}
|
||||||
|
if (!settingsStore.isSettingTruthy('enable_product_funds')) {
|
||||||
|
return next({ name: (from.name as string) || 'home' })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (to.name === 'earnMoney') {
|
||||||
|
const { useSettingsStore } = await import('@/store/settingsStore')
|
||||||
|
const settingsStore = useSettingsStore()
|
||||||
|
if (!settingsStore.loaded) {
|
||||||
|
await settingsStore.fetchSettings()
|
||||||
|
}
|
||||||
|
if (!settingsStore.isSettingTruthy('has_page_earn_money')) {
|
||||||
|
return next({ name: (from.name as string) || 'user' })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
hasFingerPrint = !!userStore.userInfo?.finger_print
|
hasFingerPrint = !!userStore.userInfo?.finger_print
|
||||||
|
|
||||||
if (isApple && userStore.userInfo?.finger_print) {
|
if (isApple && userStore.userInfo?.finger_print) {
|
||||||
@@ -86,7 +147,10 @@ export function setupRouterGuards() {
|
|||||||
if (!isApple && userStore.userInfo?.finger_print) {
|
if (!isApple && userStore.userInfo?.finger_print) {
|
||||||
if (!fingerprintChecked) {
|
if (!fingerprintChecked) {
|
||||||
fingerprintChecked = true
|
fingerprintChecked = true
|
||||||
setFingerPosition(await authenticateWithFingerprint())
|
// اگر همین الان با پسورد/OTP وارد شده (setTruth)، دوباره WebAuthn نخواه
|
||||||
|
if (!getFingerPosition()) {
|
||||||
|
setFingerPosition(await authenticateWithFingerprint())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!getFingerPosition()) {
|
if (!getFingerPosition()) {
|
||||||
|
|||||||
@@ -240,9 +240,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.ant-spin-dot-item {
|
.ant-spin-dot-item {
|
||||||
background-color: @App-primary-color !important;
|
background-color: var(--color-primary, var(--App-secondary-color)) !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.ant-spin-dot i {
|
.ant-spin-dot i {
|
||||||
background-color: @App-primary-color !important;
|
background-color: var(--color-primary, var(--App-secondary-color)) !important;
|
||||||
}
|
}
|
||||||
@@ -23,6 +23,7 @@
|
|||||||
@import (less) '../../views/base/physicalReceive/desktop/styles/desktop-physical-receive.less';
|
@import (less) '../../views/base/physicalReceive/desktop/styles/desktop-physical-receive.less';
|
||||||
@import (less) '../../views/base/fund/desktop/styles/desktop-fund.less';
|
@import (less) '../../views/base/fund/desktop/styles/desktop-fund.less';
|
||||||
@import (less) '../../views/base/gold/desktop/styles/desktop-gold.less';
|
@import (less) '../../views/base/gold/desktop/styles/desktop-gold.less';
|
||||||
|
@import (less) './mobile-keyboard-scroll.less';
|
||||||
|
|
||||||
html {
|
html {
|
||||||
scroll-behavior: smooth;
|
scroll-behavior: smooth;
|
||||||
@@ -465,4 +466,15 @@ body:has(.ant-modal-root .ant-modal-wrap:not([style*='display: none'])) {
|
|||||||
}
|
}
|
||||||
.ant-radio-group-solid .ant-radio-button-wrapper-checked:not(.ant-radio-button-wrapper-disabled):hover{
|
.ant-radio-group-solid .ant-radio-button-wrapper-checked:not(.ant-radio-button-wrapper-disabled):hover{
|
||||||
color: white !important;
|
color: white !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* لودینگ محتوای صفحه — وسط ناحیه محتوا (موبایل و دسکتاپ یکسان) */
|
||||||
|
.app-page-content-loading {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
box-sizing: border-box;
|
||||||
|
width: 100%;
|
||||||
|
min-height: min(52vh, 22rem);
|
||||||
|
padding: 2rem 1rem;
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
:root {
|
||||||
|
--app-keyboard-inset: 0px;
|
||||||
|
--app-visual-viewport-height: 100dvh;
|
||||||
|
--app-visual-viewport-offset-top: 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 767.98px) {
|
||||||
|
input,
|
||||||
|
textarea,
|
||||||
|
select,
|
||||||
|
.ant-input,
|
||||||
|
.ant-input-affix-wrapper,
|
||||||
|
.ant-select-selection-search-input {
|
||||||
|
scroll-margin-bottom: calc(var(--app-keyboard-inset) + 16px);
|
||||||
|
}
|
||||||
|
|
||||||
|
html[data-keyboard-open='true'] {
|
||||||
|
.main-with-bottom-chrome,
|
||||||
|
.login-vip-page__body,
|
||||||
|
.login-page,
|
||||||
|
.login-page-root,
|
||||||
|
.ant-modal-body,
|
||||||
|
.ant-drawer-body,
|
||||||
|
.van-action-sheet__content,
|
||||||
|
.basic-action-sheet__body {
|
||||||
|
scroll-padding-bottom: calc(var(--app-keyboard-inset) + 16px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.main-with-bottom-chrome,
|
||||||
|
.login-vip-page__body,
|
||||||
|
.login-page {
|
||||||
|
padding-bottom: var(--app-keyboard-inset);
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-mobile {
|
||||||
|
height: var(--app-visual-viewport-height, 100dvh);
|
||||||
|
max-height: var(--app-visual-viewport-height, 100dvh);
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-page.flex {
|
||||||
|
height: var(--app-visual-viewport-height, 92vh) !important;
|
||||||
|
max-height: var(--app-visual-viewport-height, 92vh) !important;
|
||||||
|
overflow-y: auto;
|
||||||
|
overscroll-behavior: contain;
|
||||||
|
-webkit-overflow-scrolling: touch;
|
||||||
|
align-items: flex-start !important;
|
||||||
|
justify-content: flex-start !important;
|
||||||
|
padding-top: 0.75rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
After Width: | Height: | Size: 40 KiB |
@@ -0,0 +1,10 @@
|
|||||||
|
<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>
|
||||||
|
After Width: | Height: | Size: 680 B |
|
After Width: | Height: | Size: 27 KiB |
|
After Width: | Height: | Size: 3.0 KiB |
@@ -0,0 +1,7 @@
|
|||||||
|
<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>
|
||||||
|
After Width: | Height: | Size: 337 B |
@@ -0,0 +1,7 @@
|
|||||||
|
<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>
|
||||||
|
After Width: | Height: | Size: 6.7 KiB |
@@ -0,0 +1 @@
|
|||||||
|
<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>
|
||||||
|
After Width: | Height: | Size: 1.1 KiB |
@@ -0,0 +1 @@
|
|||||||
|
<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>
|
||||||
|
After Width: | Height: | Size: 2.1 KiB |
@@ -14,7 +14,7 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
withDefaults(
|
withDefaults(
|
||||||
defineProps<{
|
defineProps<{
|
||||||
variant?: 'mobile' | 'sidebar' | 'float'
|
variant?: 'mobile' | 'sidebar' | 'float' | 'tv'
|
||||||
}>(),
|
}>(),
|
||||||
{ variant: 'mobile' },
|
{ variant: 'mobile' },
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -16,7 +16,14 @@
|
|||||||
|
|
||||||
</style>-->
|
</style>-->
|
||||||
<template>
|
<template>
|
||||||
<VanActionSheet v-model:show="show" teleport="body" :z-index="zIndex">
|
<VanActionSheet
|
||||||
|
v-model:show="show"
|
||||||
|
teleport="body"
|
||||||
|
overlay
|
||||||
|
lock-scroll
|
||||||
|
close-on-click-overlay
|
||||||
|
:z-index="zIndex"
|
||||||
|
>
|
||||||
<div class="justify-center cursor-pointer flex mt-1" @click="show = false">
|
<div class="justify-center cursor-pointer flex mt-1" @click="show = false">
|
||||||
<span class="rounded-sm w-12 border-t-2 border-t-solid border-t-gray-500 mt-2"></span>
|
<span class="rounded-sm w-12 border-t-2 border-t-solid border-t-gray-500 mt-2"></span>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -38,7 +38,11 @@
|
|||||||
import {usePrefix} from "@/utils/usePrefix";
|
import {usePrefix} from "@/utils/usePrefix";
|
||||||
import {computed} from "vue";
|
import {computed} from "vue";
|
||||||
import {usePrice} from "@/utils/usePrice";
|
import {usePrice} from "@/utils/usePrice";
|
||||||
import {persianToEnglishDigits, shouldNormalizeInputDigits} from '@/utils/persianDigits';
|
import {
|
||||||
|
normalizeDecimalInput,
|
||||||
|
persianToEnglishDigits,
|
||||||
|
shouldNormalizeDecimalSeparators,
|
||||||
|
} from '@/utils/persianDigits';
|
||||||
|
|
||||||
//Props
|
//Props
|
||||||
interface Prop {
|
interface Prop {
|
||||||
@@ -81,19 +85,23 @@ function normalizeValue(value: unknown) {
|
|||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
let normalized = String(value)
|
if (shouldNormalizeDecimalSeparators(props)) {
|
||||||
if (shouldNormalizeInputDigits(props)) {
|
const isPrice = String(props.type ?? '').trim().toLowerCase() === 'price'
|
||||||
normalized = persianToEnglishDigits(normalized)
|
return normalizeDecimalInput(value as string | number, {
|
||||||
|
commaAsThousand: isPrice,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
if (props.type === 'price') {
|
|
||||||
normalized = normalized.replaceAll(',', '')
|
return persianToEnglishDigits(String(value))
|
||||||
}
|
|
||||||
return normalized
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const handlerChange = (e: Event | string) => {
|
const handlerChange = (e: Event | string) => {
|
||||||
const raw = typeof e === 'string' ? e : (e.target as HTMLInputElement | null)?.value
|
const target = typeof e === 'string' ? null : (e.target as HTMLInputElement | null)
|
||||||
|
const raw = typeof e === 'string' ? e : target?.value
|
||||||
const normalized = normalizeValue(raw)
|
const normalized = normalizeValue(raw)
|
||||||
|
if (target && typeof normalized === 'string' && target.value !== normalized) {
|
||||||
|
target.value = normalized
|
||||||
|
}
|
||||||
emits('update:value', normalized)
|
emits('update:value', normalized)
|
||||||
emits('onchange', normalized)
|
emits('onchange', normalized)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
import {usePrice} from '@/utils/usePrice'
|
import {usePrice} from '@/utils/usePrice'
|
||||||
import {computed} from "vue";
|
import {computed} from "vue";
|
||||||
import BasicInput from "../../BasicInput.vue";
|
import BasicInput from "../../BasicInput.vue";
|
||||||
import {persianToEnglishDigits} from '@/utils/persianDigits'
|
import {normalizeDecimalInput} from '@/utils/persianDigits'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
value?: string | number
|
value?: string | number
|
||||||
@@ -24,7 +24,7 @@ const props = withDefaults(defineProps<Props>(), {})
|
|||||||
|
|
||||||
const _val = computed({
|
const _val = computed({
|
||||||
set(val: string) {
|
set(val: string) {
|
||||||
emit('update:value', persianToEnglishDigits(val).replaceAll(',', ''))
|
emit('update:value', normalizeDecimalInput(val))
|
||||||
},
|
},
|
||||||
get() {
|
get() {
|
||||||
return props.value ? usePrice(props.value as number, true, '').trim() : ''
|
return props.value ? usePrice(props.value as number, true, '').trim() : ''
|
||||||
|
|||||||
@@ -0,0 +1,70 @@
|
|||||||
|
<template>
|
||||||
|
<a
|
||||||
|
v-if="href && src"
|
||||||
|
referrerpolicy="origin"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
:href="href"
|
||||||
|
class="enamad-badge"
|
||||||
|
:class="`enamad-badge--${size}`"
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
referrerpolicy="origin"
|
||||||
|
:src="src"
|
||||||
|
alt="enamad"
|
||||||
|
class="enamad-badge__img"
|
||||||
|
:code="code || undefined"
|
||||||
|
/>
|
||||||
|
</a>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import { computed } from 'vue'
|
||||||
|
import { useSettingsStore } from '@/store/settingsStore'
|
||||||
|
|
||||||
|
withDefaults(
|
||||||
|
defineProps<{
|
||||||
|
size?: 'sm' | 'lg'
|
||||||
|
}>(),
|
||||||
|
{ size: 'sm' },
|
||||||
|
)
|
||||||
|
|
||||||
|
const settingsStore = useSettingsStore()
|
||||||
|
|
||||||
|
const href = computed(() =>
|
||||||
|
String(settingsStore.getSettingByKey('enamad_url') ?? '').trim(),
|
||||||
|
)
|
||||||
|
const src = computed(() =>
|
||||||
|
String(settingsStore.getSettingByKey('enamad_logo') ?? '').trim(),
|
||||||
|
)
|
||||||
|
const code = computed(() => {
|
||||||
|
try {
|
||||||
|
const u = new URL(href.value || src.value)
|
||||||
|
return u.searchParams.get('Code') || u.searchParams.get('code') || ''
|
||||||
|
} catch {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped lang="less">
|
||||||
|
.enamad-badge {
|
||||||
|
display: inline-flex;
|
||||||
|
line-height: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.enamad-badge__img {
|
||||||
|
width: auto;
|
||||||
|
cursor: pointer;
|
||||||
|
object-fit: contain;
|
||||||
|
}
|
||||||
|
|
||||||
|
.enamad-badge--sm .enamad-badge__img {
|
||||||
|
height: 40px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.enamad-badge--lg .enamad-badge__img {
|
||||||
|
height: 120px;
|
||||||
|
max-width: 100%;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,303 @@
|
|||||||
|
<template>
|
||||||
|
<BasicModal
|
||||||
|
v-model:visible="visible"
|
||||||
|
width="400px"
|
||||||
|
destroy-on-close
|
||||||
|
custom-footer
|
||||||
|
wrap-class-name="gold-day-calc-modal"
|
||||||
|
>
|
||||||
|
<template #title>
|
||||||
|
<div class="gold-day-calc-modal__title">
|
||||||
|
<BasicIcon icon="vuesax-linear:chart-2" size="20" class="gold-day-calc-modal__title-icon" />
|
||||||
|
<span>محاسبهگر طلای شما</span>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<div class="gold-day-calc" dir="rtl">
|
||||||
|
<BasicInput
|
||||||
|
v-model:value="weight"
|
||||||
|
title="وزن طلا (گرم)"
|
||||||
|
type="tel"
|
||||||
|
place-holder="مثلاً ۱۰.۵"
|
||||||
|
inputmode="decimal"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<BasicInput
|
||||||
|
:value="unitPriceInput"
|
||||||
|
title="قیمت روز طلا"
|
||||||
|
type="tel"
|
||||||
|
disabled
|
||||||
|
addon-before="ریال"
|
||||||
|
place-holder="قیمت صفحه اصلی"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<BasicInput
|
||||||
|
v-model:value="feePercent"
|
||||||
|
title="اجرت ساخت (%)"
|
||||||
|
type="tel"
|
||||||
|
place-holder="مثلاً ۷"
|
||||||
|
inputmode="decimal"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<BasicInput
|
||||||
|
v-model:value="taxPercent"
|
||||||
|
title="سود و مالیات (%)"
|
||||||
|
type="tel"
|
||||||
|
place-holder="مثلاً ۹"
|
||||||
|
inputmode="decimal"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div class="gold-day-calc__result rounded-xl border border-solid border-gray-200 bg-gray-50 p-3">
|
||||||
|
<div class="text-xs text-gray-500 mb-1">کل نهایی</div>
|
||||||
|
<div class="gold-day-calc__total text-lg font-bold text-primary">
|
||||||
|
<span class="gold-day-calc__num">{{ formattedTotal }}</span>
|
||||||
|
<span class="text-sm font-medium text-gray-600">ریال</span>
|
||||||
|
</div>
|
||||||
|
<div class="mt-2 flex flex-col gap-1 text-xs text-gray-600">
|
||||||
|
<div class="flex justify-between gap-2">
|
||||||
|
<span>هزینه طلا</span>
|
||||||
|
<span class="gold-day-calc__num">{{ formatRial(breakdown.goldCost) }}</span>
|
||||||
|
</div>
|
||||||
|
<div class="flex justify-between gap-2">
|
||||||
|
<span>اجرت</span>
|
||||||
|
<span class="gold-day-calc__num">{{ formatRial(breakdown.feeCost) }}</span>
|
||||||
|
</div>
|
||||||
|
<div class="flex justify-between gap-2">
|
||||||
|
<span>سود و مالیات</span>
|
||||||
|
<span class="gold-day-calc__num">{{ formatRial(breakdown.taxCost) }}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<template #footer>
|
||||||
|
<BasicButton type="primary" class="!w-full" size="middle" @click="recalculate">
|
||||||
|
محاسبه مجدد
|
||||||
|
</BasicButton>
|
||||||
|
</template>
|
||||||
|
</BasicModal>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { computed, ref, watch } from 'vue'
|
||||||
|
import BasicModal from '@/components/BasicPacks/BasicModal.vue'
|
||||||
|
import BasicInput from '@/components/BasicPacks/BasicInput.vue'
|
||||||
|
import BasicButton from '@/components/BasicPacks/BasicButton.vue'
|
||||||
|
import BasicIcon from '@/components/BasicPacks/BasicIcon.vue'
|
||||||
|
import { goldDayCalculatorVisible } from '@/composables/useGoldDayCalculator'
|
||||||
|
import {
|
||||||
|
getLastPrices,
|
||||||
|
getTradeBuyPrice,
|
||||||
|
lastPrice,
|
||||||
|
startLastPricePolling,
|
||||||
|
stopLastPricePolling,
|
||||||
|
} from '@/utils/price'
|
||||||
|
import { getPriceDisplayState, NO_QUOTE_MESSAGE } from '@/utils/storeHours'
|
||||||
|
import { usePriceWithoutType } from '@/utils/usePrice'
|
||||||
|
import { persianToEnglishDigits } from '@/utils/persianDigits'
|
||||||
|
|
||||||
|
const visible = goldDayCalculatorVisible
|
||||||
|
|
||||||
|
const weight = ref<string | number>('')
|
||||||
|
const feePercent = ref<string | number>('')
|
||||||
|
const taxPercent = ref<string | number>('')
|
||||||
|
const tick = ref(0)
|
||||||
|
|
||||||
|
function parseNum(raw: string | number | undefined): number {
|
||||||
|
const s = persianToEnglishDigits(String(raw ?? ''))
|
||||||
|
.replace(/,/g, '')
|
||||||
|
.replace(/[^\d.]/g, '')
|
||||||
|
const n = Number.parseFloat(s)
|
||||||
|
return Number.isFinite(n) ? n : 0
|
||||||
|
}
|
||||||
|
|
||||||
|
const liveUnitPrice = computed(() => {
|
||||||
|
void tick.value
|
||||||
|
if (getPriceDisplayState() !== 'open') return 0
|
||||||
|
return getTradeBuyPrice(lastPrice.value) || 0
|
||||||
|
})
|
||||||
|
|
||||||
|
const unitPriceInput = computed(() => {
|
||||||
|
void tick.value
|
||||||
|
const state = getPriceDisplayState()
|
||||||
|
if (state === 'closed') return 'فروشگاه بسته است'
|
||||||
|
if (state === 'no_quote') return NO_QUOTE_MESSAGE
|
||||||
|
const p = liveUnitPrice.value
|
||||||
|
return p > 0 ? usePriceWithoutType(p) : ''
|
||||||
|
})
|
||||||
|
|
||||||
|
const breakdown = computed(() => {
|
||||||
|
void tick.value
|
||||||
|
const w = parseNum(weight.value)
|
||||||
|
const fee = parseNum(feePercent.value)
|
||||||
|
const tax = parseNum(taxPercent.value)
|
||||||
|
const unit = liveUnitPrice.value
|
||||||
|
const goldCost = w * unit
|
||||||
|
const feeCost = goldCost * (fee / 100)
|
||||||
|
const taxCost = (goldCost + feeCost) * (tax / 100)
|
||||||
|
const total = goldCost + feeCost + taxCost
|
||||||
|
return { goldCost, feeCost, taxCost, total }
|
||||||
|
})
|
||||||
|
|
||||||
|
const formattedTotal = computed(() => formatRial(breakdown.value.total))
|
||||||
|
|
||||||
|
function formatRial(n: number) {
|
||||||
|
if (!Number.isFinite(n) || n <= 0) return '۰'
|
||||||
|
return usePriceWithoutType(Math.round(n))
|
||||||
|
}
|
||||||
|
|
||||||
|
function recalculate() {
|
||||||
|
tick.value += 1
|
||||||
|
void getLastPrices()
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(visible, async (open) => {
|
||||||
|
if (open) {
|
||||||
|
startLastPricePolling()
|
||||||
|
await getLastPrices()
|
||||||
|
tick.value += 1
|
||||||
|
} else {
|
||||||
|
stopLastPricePolling()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.gold-day-calc {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.75rem;
|
||||||
|
direction: rtl;
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
.gold-day-calc :deep(.ant-input-group) {
|
||||||
|
direction: ltr;
|
||||||
|
display: table;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.gold-day-calc :deep(.ant-input-group > .ant-input) {
|
||||||
|
direction: ltr;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.gold-day-calc :deep(.ant-input:not(.ant-input-group *)) {
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
.gold-day-calc__result {
|
||||||
|
direction: rtl;
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
.gold-day-calc__total {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
align-items: baseline;
|
||||||
|
justify-content: flex-start;
|
||||||
|
gap: 0.35rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.gold-day-calc__num {
|
||||||
|
direction: ltr;
|
||||||
|
unicode-bidi: isolate;
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<style lang="less">
|
||||||
|
.gold-day-calc-modal {
|
||||||
|
.ant-modal-content {
|
||||||
|
direction: rtl;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
max-height: min(88dvh, 640px);
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ant-modal-header {
|
||||||
|
flex-shrink: 0;
|
||||||
|
direction: rtl;
|
||||||
|
text-align: right;
|
||||||
|
padding-left: 2.75rem;
|
||||||
|
padding-right: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ant-modal-title {
|
||||||
|
text-align: right;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.gold-day-calc-modal__title {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: flex-start;
|
||||||
|
gap: 0.5rem;
|
||||||
|
direction: rtl;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.gold-day-calc-modal__title-icon {
|
||||||
|
flex-shrink: 0;
|
||||||
|
color: var(--App-secondary-color, #c9a062);
|
||||||
|
}
|
||||||
|
|
||||||
|
.ant-modal-close {
|
||||||
|
inset-inline-start: 0 !important;
|
||||||
|
inset-inline-end: auto !important;
|
||||||
|
right: auto !important;
|
||||||
|
left: 0 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ant-modal-body {
|
||||||
|
flex: 1 1 auto;
|
||||||
|
min-height: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
padding-bottom: 0.25rem;
|
||||||
|
max-height: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
#body {
|
||||||
|
max-height: min(48dvh, 360px) !important;
|
||||||
|
overflow-y: auto !important;
|
||||||
|
overscroll-behavior: contain;
|
||||||
|
-webkit-overflow-scrolling: touch;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ant-modal-footer {
|
||||||
|
flex-shrink: 0;
|
||||||
|
margin-top: 0;
|
||||||
|
padding-top: 0.75rem;
|
||||||
|
border-top: 1px solid rgba(148, 163, 184, 0.25);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 767.98px) {
|
||||||
|
.gold-day-calc-modal {
|
||||||
|
.ant-modal {
|
||||||
|
max-width: calc(100vw - 1.5rem);
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ant-modal-content {
|
||||||
|
max-height: min(86dvh, 100%);
|
||||||
|
}
|
||||||
|
|
||||||
|
#body {
|
||||||
|
max-height: min(42dvh, 280px) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ant-modal-body {
|
||||||
|
padding-top: 0.25rem;
|
||||||
|
padding-bottom: 0.25rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 400px) {
|
||||||
|
.gold-day-calc-modal #body {
|
||||||
|
max-height: min(38dvh, 240px) !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
<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>
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
<template>
|
||||||
|
<img
|
||||||
|
:src="currentSrc"
|
||||||
|
:class="[imgClass, dimmed && 'product-image--dimmed']"
|
||||||
|
:alt="alt"
|
||||||
|
@error="handleError"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref, watch } from 'vue'
|
||||||
|
import { getProductDisplayImage } from '@/utils/productAssets'
|
||||||
|
import type { Product } from '@/models/products'
|
||||||
|
import defaultImg from '@/assets/img/coin.png'
|
||||||
|
|
||||||
|
const props = withDefaults(
|
||||||
|
defineProps<{
|
||||||
|
product?: Product | null
|
||||||
|
imgClass?: string
|
||||||
|
alt?: string
|
||||||
|
dimmed?: boolean
|
||||||
|
}>(),
|
||||||
|
{
|
||||||
|
imgClass: 'max-h-full max-w-full object-contain',
|
||||||
|
alt: '',
|
||||||
|
dimmed: false,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
function productImageKey(product?: Product | null): string {
|
||||||
|
return [
|
||||||
|
product?.file_id ?? '',
|
||||||
|
product?.file?.id ?? '',
|
||||||
|
product?.file?.full_src ?? '',
|
||||||
|
product?.file?.src ?? '',
|
||||||
|
product?.file?.url ?? '',
|
||||||
|
product?.img ?? '',
|
||||||
|
].join('|')
|
||||||
|
}
|
||||||
|
|
||||||
|
const currentSrc = ref(getProductDisplayImage(props.product) || defaultImg)
|
||||||
|
const usingFallback = ref(false)
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => productImageKey(props.product),
|
||||||
|
() => {
|
||||||
|
usingFallback.value = false
|
||||||
|
currentSrc.value = getProductDisplayImage(props.product) || defaultImg
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
function handleError() {
|
||||||
|
if (usingFallback.value) return
|
||||||
|
usingFallback.value = true
|
||||||
|
currentSrc.value = defaultImg
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.product-image--dimmed {
|
||||||
|
opacity: 0.45;
|
||||||
|
filter: grayscale(1);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -1,32 +1,100 @@
|
|||||||
<template>
|
<template>
|
||||||
<div :class="variant === 'desktop' ? 'dpage-support' : 'wrap-fix bottom-0 px-10 pb-3rem flex gap-2 bg-white'">
|
<div :class="variant === 'desktop' ? desktopRootClass : mobileRootClass">
|
||||||
<a
|
<button
|
||||||
class="w-full"
|
ref="triggerEl"
|
||||||
:href="supportHref"
|
type="button"
|
||||||
:target="opensSupportInNewTab ? '_blank' : undefined"
|
class="support-contact-bar__btn"
|
||||||
:rel="opensSupportInNewTab ? 'noopener noreferrer' : undefined"
|
:disabled="!canContactSupport"
|
||||||
|
@click="onSupportClick"
|
||||||
>
|
>
|
||||||
<BasicButton class="w-full" type="primary">تماس با پشتیبانی</BasicButton>
|
<BasicIcon icon="vuesax-linear:messages-2" size="20" color="#fff" />
|
||||||
</a>
|
<span>ارتباط با پشتیبانی</span>
|
||||||
<a :href="baleHref" target="_blank" rel="noopener noreferrer">
|
</button>
|
||||||
<img src="@/assets/img/bale.png" alt="بله" :class="variant === 'desktop' ? 'dpage-support__bale' : 'h-10 w-10'" />
|
|
||||||
</a>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { computed } from 'vue'
|
import BasicIcon from '@/components/BasicPacks/BasicIcon.vue'
|
||||||
import BasicButton from '@/components/BasicPacks/BasicButton.vue'
|
import { useSupportMessenger } from '@/composables/useSupportMessenger'
|
||||||
import { getProjectBaleContactLink, getProjectSupportContactLink } from '@/utils/config'
|
import { computed, ref } from 'vue'
|
||||||
|
|
||||||
withDefaults(
|
withDefaults(
|
||||||
defineProps<{
|
defineProps<{
|
||||||
variant?: 'mobile' | 'desktop'
|
variant?: 'mobile' | 'desktop'
|
||||||
|
mobileRootClass?: string
|
||||||
|
desktopRootClass?: string
|
||||||
}>(),
|
}>(),
|
||||||
{ variant: 'mobile' },
|
{
|
||||||
|
variant: 'mobile',
|
||||||
|
mobileRootClass: 'wrap-fix bottom-0 px-10 pb-3rem flex bg-white',
|
||||||
|
desktopRootClass: 'dpage-support',
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
const supportHref = computed(() => getProjectSupportContactLink())
|
const {
|
||||||
const baleHref = computed(() => getProjectBaleContactLink())
|
supportPhoneLink,
|
||||||
const opensSupportInNewTab = computed(() => supportHref.value.startsWith('http'))
|
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>
|
</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, var(--ant-color-primary, #7f1d1d));
|
||||||
|
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>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
<template>
|
||||||
|
<span
|
||||||
|
class="block w-full h-full rounded-full overflow-hidden shrink-0 bg-slate-500"
|
||||||
|
:class="{ 'bg-[#e37600]': normalized === 'eitaa' }"
|
||||||
|
aria-hidden="true"
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
v-if="logoSrc"
|
||||||
|
:src="logoSrc"
|
||||||
|
:alt="normalized"
|
||||||
|
class="block w-full h-full object-cover object-center bg-white"
|
||||||
|
draggable="false"
|
||||||
|
/>
|
||||||
|
<span v-else class="block w-full h-full bg-slate-500" />
|
||||||
|
</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>
|
||||||
@@ -0,0 +1,266 @@
|
|||||||
|
<template>
|
||||||
|
<Teleport to="body">
|
||||||
|
<Transition name="support-picker-fade">
|
||||||
|
<div
|
||||||
|
v-if="open"
|
||||||
|
class="fixed inset-0 bg-slate-900/20"
|
||||||
|
:class="backdropActive ? 'pointer-events-auto' : 'pointer-events-none'"
|
||||||
|
:style="{ zIndex: pickerZIndex }"
|
||||||
|
@click="onBackdropClick"
|
||||||
|
/>
|
||||||
|
</Transition>
|
||||||
|
|
||||||
|
<div
|
||||||
|
v-show="open || closing"
|
||||||
|
class="fixed flex pointer-events-none"
|
||||||
|
:class="expandUp ? 'flex-col-reverse' : 'flex-col'"
|
||||||
|
:style="{ ...stackStyle, zIndex: stackZIndex }"
|
||||||
|
role="menu"
|
||||||
|
aria-label="انتخاب پیامرسان"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="support-picker-panel pointer-events-auto flex flex-col gap-2 rounded-2xl p-1 shadow-lg"
|
||||||
|
:class="{ 'is-open': panelOpen }"
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
v-for="(entry, index) in entries"
|
||||||
|
:key="`${entry.messenger}-${entry.id}`"
|
||||||
|
type="button"
|
||||||
|
class="support-picker-item m-0 border-0 bg-transparent p-0 cursor-pointer"
|
||||||
|
:style="{ '--i': index, '--total': entries.length }"
|
||||||
|
:title="entry.label"
|
||||||
|
:aria-label="entry.label"
|
||||||
|
@click.stop="select(entry)"
|
||||||
|
>
|
||||||
|
<span class="support-picker-item-inner inline-flex items-center gap-2 min-h-[38px] rounded-full bg-white shadow-md py-1 pl-3 pr-1 w-full">
|
||||||
|
<span class="block w-[30px] h-[30px] shrink-0 flex items-center justify-center">
|
||||||
|
<BasicIcon
|
||||||
|
v-if="entry.messenger === 'chat'"
|
||||||
|
:icon="entry.icon || 'vuesax-linear:messages-2'"
|
||||||
|
size="22"
|
||||||
|
:color="entry.accent || '#16a34a'"
|
||||||
|
/>
|
||||||
|
<SupportMessengerBrandIcon v-else :messenger="entry.messenger" />
|
||||||
|
</span>
|
||||||
|
<span class="text-sm font-600 text-slate-800 whitespace-nowrap leading-none">
|
||||||
|
{{ entry.label }}
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</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'
|
||||||
|
import { APP_Z_SUPPORT_PICKER } from '@/utils/zIndex'
|
||||||
|
|
||||||
|
const props = withDefaults(
|
||||||
|
defineProps<{
|
||||||
|
open: boolean
|
||||||
|
entries: ResolvedSupportMessengerEntry[]
|
||||||
|
anchorEl?: HTMLElement | null
|
||||||
|
}>(),
|
||||||
|
{
|
||||||
|
anchorEl: null,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
'update:open': [value: boolean]
|
||||||
|
select: [entry: ResolvedSupportMessengerEntry]
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const ITEM_H = 46
|
||||||
|
const GAP = 8
|
||||||
|
const PANEL_PAD = 24
|
||||||
|
const STACK_GAP = 10
|
||||||
|
const EDGE_PAD = 12
|
||||||
|
const CLOSE_MS = 220
|
||||||
|
const BACKDROP_GUARD_MS = 380
|
||||||
|
const pickerZIndex = APP_Z_SUPPORT_PICKER
|
||||||
|
const stackZIndex = APP_Z_SUPPORT_PICKER + 10
|
||||||
|
|
||||||
|
const stackStyle = ref<Record<string, string>>({})
|
||||||
|
const closing = ref(false)
|
||||||
|
const expandUp = ref(true)
|
||||||
|
const backdropActive = ref(false)
|
||||||
|
/** یک فریم بعد از open تا transition باز شدن دیده شود */
|
||||||
|
const panelOpen = ref(false)
|
||||||
|
let closeTimer: ReturnType<typeof setTimeout> | null = null
|
||||||
|
let backdropTimer: ReturnType<typeof setTimeout> | null = null
|
||||||
|
let openRaf = 0
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
if (openRaf) {
|
||||||
|
cancelAnimationFrame(openRaf)
|
||||||
|
openRaf = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
function schedulePanelOpen() {
|
||||||
|
panelOpen.value = false
|
||||||
|
openRaf = requestAnimationFrame(() => {
|
||||||
|
openRaf = requestAnimationFrame(() => {
|
||||||
|
panelOpen.value = true
|
||||||
|
openRaf = 0
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
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',
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const rect = anchor.getBoundingClientRect()
|
||||||
|
const stackHeight = count * ITEM_H + Math.max(0, count - 1) * GAP + PANEL_PAD
|
||||||
|
const right = Math.max(EDGE_PAD, window.innerWidth - rect.right)
|
||||||
|
const spaceAbove = rect.top
|
||||||
|
const spaceBelow = window.innerHeight - rect.bottom
|
||||||
|
expandUp.value = spaceAbove >= stackHeight + 24 || spaceAbove >= spaceBelow
|
||||||
|
|
||||||
|
if (expandUp.value) {
|
||||||
|
stackStyle.value = {
|
||||||
|
right: `${right}px`,
|
||||||
|
bottom: `${Math.max(EDGE_PAD, window.innerHeight - rect.top + STACK_GAP)}px`,
|
||||||
|
left: 'auto',
|
||||||
|
top: 'auto',
|
||||||
|
transform: 'none',
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
stackStyle.value = {
|
||||||
|
right: `${right}px`,
|
||||||
|
top: `${Math.max(EDGE_PAD, rect.bottom + STACK_GAP)}px`,
|
||||||
|
left: 'auto',
|
||||||
|
bottom: 'auto',
|
||||||
|
transform: 'none',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.open,
|
||||||
|
async (isOpen) => {
|
||||||
|
clearTimers()
|
||||||
|
if (isOpen) {
|
||||||
|
closing.value = false
|
||||||
|
panelOpen.value = false
|
||||||
|
armBackdropGuard()
|
||||||
|
await reposition()
|
||||||
|
await nextTick()
|
||||||
|
schedulePanelOpen()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
panelOpen.value = false
|
||||||
|
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>
|
||||||
|
/* انیمیشن باز/بسته — فقط جایی که utility کافی نیست */
|
||||||
|
.support-picker-item {
|
||||||
|
--i: 0;
|
||||||
|
opacity: 0;
|
||||||
|
transform: translateY(12px) scale(0.92);
|
||||||
|
transform-origin: right center;
|
||||||
|
transition:
|
||||||
|
transform 0.22s cubic-bezier(0.2, 1, 0.3, 1),
|
||||||
|
opacity 0.16s ease;
|
||||||
|
transition-delay: calc(var(--i) * 38ms);
|
||||||
|
}
|
||||||
|
|
||||||
|
.support-picker-panel.is-open .support-picker-item {
|
||||||
|
opacity: 1;
|
||||||
|
transform: translateY(0) scale(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.support-picker-fade-enter-active,
|
||||||
|
.support-picker-fade-leave-active {
|
||||||
|
transition: opacity 0.16s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.support-picker-fade-enter-from,
|
||||||
|
.support-picker-fade-leave-to {
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,227 @@
|
|||||||
|
<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>
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
defineProps<{
|
||||||
|
visible: boolean
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
install: []
|
||||||
|
dismiss: []
|
||||||
|
}>()
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Transition name="pwa-install-banner">
|
||||||
|
<button
|
||||||
|
v-if="visible"
|
||||||
|
type="button"
|
||||||
|
class="pwa-install-banner"
|
||||||
|
@click="emit('install')"
|
||||||
|
>
|
||||||
|
نصب وب اپلیکیشن
|
||||||
|
</button>
|
||||||
|
</Transition>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped lang="less">
|
||||||
|
.pwa-install-banner {
|
||||||
|
position: fixed;
|
||||||
|
left: 50%;
|
||||||
|
z-index: 5095;
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
width: fit-content;
|
||||||
|
max-width: calc(100% - 24px);
|
||||||
|
padding: 10px 18px;
|
||||||
|
border-radius: 999px;
|
||||||
|
background: #fff;
|
||||||
|
border: 1px solid rgba(15, 23, 42, 0.08);
|
||||||
|
box-shadow: 0 10px 28px rgba(15, 23, 42, 0.12);
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 700;
|
||||||
|
color: @App-primary-color;
|
||||||
|
white-space: nowrap;
|
||||||
|
cursor: pointer;
|
||||||
|
transform: translateX(-50%);
|
||||||
|
bottom: calc(var(--app-bottom-chrome-height, 108px) + 8px);
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (min-width: 768px) {
|
||||||
|
.pwa-install-banner {
|
||||||
|
/* بالاتر از متن نسخه در پنل برند لاگین */
|
||||||
|
bottom: 64px;
|
||||||
|
}
|
||||||
|
|
||||||
|
html.app-layout--desktop:not(.app-layout--desktop-no-sidebar) .pwa-install-banner {
|
||||||
|
left: calc(50% - var(--app-desktop-sidebar-width, 260px) / 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.pwa-install-banner-enter-active,
|
||||||
|
.pwa-install-banner-leave-active {
|
||||||
|
transition: opacity 0.2s ease, transform 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pwa-install-banner-enter-from,
|
||||||
|
.pwa-install-banner-leave-to {
|
||||||
|
opacity: 0;
|
||||||
|
transform: translate(-50%, 12px);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,376 @@
|
|||||||
|
<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;
|
||||||
|
/* بالاتر از نوار اعتبار (۱۰۰۰۰۰۰) و FAB پشتیبانی */
|
||||||
|
z-index: 1000002;
|
||||||
|
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>
|
||||||
@@ -0,0 +1,413 @@
|
|||||||
|
<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>
|
||||||
@@ -0,0 +1,220 @@
|
|||||||
|
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,12 @@
|
|||||||
|
import { ref } from 'vue'
|
||||||
|
|
||||||
|
/** باز/بسته بودن مدال محاسبهگر طلا — مشترک بین منوی کاربر و همبرگر */
|
||||||
|
export const goldDayCalculatorVisible = ref(false)
|
||||||
|
|
||||||
|
export function openGoldDayCalculator() {
|
||||||
|
goldDayCalculatorVisible.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
export function closeGoldDayCalculator() {
|
||||||
|
goldDayCalculatorVisible.value = false
|
||||||
|
}
|
||||||
@@ -0,0 +1,139 @@
|
|||||||
|
import { computed, onMounted, ref } from 'vue'
|
||||||
|
import type { PwaPlatform } from '@/modules/pwa/pwaInstallGuideSteps'
|
||||||
|
import {
|
||||||
|
getDefaultPwaPlatform,
|
||||||
|
initPwaInstallPromptListener,
|
||||||
|
isPwaInstallBannerDismissed,
|
||||||
|
isStandalonePwa,
|
||||||
|
markPwaInstallBannerAsShown,
|
||||||
|
shouldOfferPwaInstall,
|
||||||
|
shouldShowPwaInstallPrompt,
|
||||||
|
triggerNativePwaInstall,
|
||||||
|
} from '@/modules/pwa/pwaInstall'
|
||||||
|
import { isTWA } from '@/utils/config'
|
||||||
|
|
||||||
|
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) {
|
||||||
|
refreshOfferInstall()
|
||||||
|
// فقط وقتی واقعاً داخل PWA/TWA هستیم راهنما را نشان نده
|
||||||
|
if (isStandalonePwa() || isTWA()) 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) {
|
||||||
|
refreshOfferInstall()
|
||||||
|
if (isStandalonePwa() || isTWA()) 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,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,344 @@
|
|||||||
|
import { computed, ref } from 'vue'
|
||||||
|
import { message } from 'ant-design-vue'
|
||||||
|
import { useRouter, useRoute } from 'vue-router'
|
||||||
|
import { useConfigStore } from '@/store/configStore'
|
||||||
|
import {
|
||||||
|
getProjectBaleContactLink,
|
||||||
|
getProjectSupportContactLink,
|
||||||
|
getProjectSupportPhoneLink,
|
||||||
|
isBazretalaProject,
|
||||||
|
} from '@/utils/config'
|
||||||
|
import {
|
||||||
|
buildDepositSmsUrl,
|
||||||
|
buildSupportPhoneUrl,
|
||||||
|
loadSupportMessengerFromSettings,
|
||||||
|
messengerNeedsClipboardCopy,
|
||||||
|
openSupportMessengerEntry,
|
||||||
|
resolveDepositGuideText,
|
||||||
|
resolveDepositSupportMessage,
|
||||||
|
resolveSupportMessengerEntries,
|
||||||
|
resolveSupportMessengerLink,
|
||||||
|
resolveSupportMessengerMeta,
|
||||||
|
supportMessengerPickerAnchor,
|
||||||
|
supportMessengerPickerOpen,
|
||||||
|
supportMessengerSettings,
|
||||||
|
type ResolvedSupportMessengerEntry,
|
||||||
|
} from '@/utils/supportMessenger'
|
||||||
|
import {
|
||||||
|
copyDepositFieldValue,
|
||||||
|
displayDepositAccountNumber,
|
||||||
|
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 config = useConfigStore()
|
||||||
|
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(() => {
|
||||||
|
if (config.config?.name === 'garoosi' || isBazretalaProject()) {
|
||||||
|
return getProjectBaleContactLink()
|
||||||
|
}
|
||||||
|
return getProjectSupportContactLink()
|
||||||
|
})
|
||||||
|
|
||||||
|
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 legacyPhone = getProjectSupportPhoneLink()
|
||||||
|
if (legacyPhone && legacyPhone !== 'tel:') return legacyPhone
|
||||||
|
|
||||||
|
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 depositAccountNumberRaw = computed(() => {
|
||||||
|
void settingsStore.settings
|
||||||
|
const fromMessenger = supportMessengerSettings.value.depositAccountNumber?.trim()
|
||||||
|
if (fromMessenger) return fromMessenger
|
||||||
|
return String(getDepositGuideVarsFromSettings().accountNumber ?? '').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 depositAccountNumber = computed(() =>
|
||||||
|
displayDepositAccountNumber(depositAccountNumberRaw.value),
|
||||||
|
)
|
||||||
|
const depositSheba = computed(() => displayDepositSheba(depositShebaRaw.value))
|
||||||
|
|
||||||
|
const depositCardLabel = computed(() => {
|
||||||
|
void settingsStore.settings
|
||||||
|
return getDepositSettingLabel('deposit_card_number', 'شماره کارت واریز')
|
||||||
|
})
|
||||||
|
|
||||||
|
const depositAccountNumberLabel = computed(() => {
|
||||||
|
void settingsStore.settings
|
||||||
|
return getDepositSettingLabel('deposit_account_number', 'شماره حساب واریز')
|
||||||
|
})
|
||||||
|
|
||||||
|
const depositShebaLabel = computed(() => {
|
||||||
|
void settingsStore.settings
|
||||||
|
return getDepositSettingLabel('deposit_sheba', 'شبا واریز')
|
||||||
|
})
|
||||||
|
|
||||||
|
const hasDepositCardValue = computed(() => hasDepositFieldValue(depositCardNumberRaw.value))
|
||||||
|
const hasDepositAccountNumberValue = computed(() =>
|
||||||
|
hasDepositFieldValue(depositAccountNumberRaw.value),
|
||||||
|
)
|
||||||
|
const hasDepositShebaValue = computed(() => hasDepositFieldValue(depositShebaRaw.value))
|
||||||
|
|
||||||
|
async function copyDepositCardNumber() {
|
||||||
|
await copyDepositFieldValue(
|
||||||
|
depositCardNumberRaw.value,
|
||||||
|
'card',
|
||||||
|
'شماره کارت ثبت نشده است',
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function copyDepositAccountNumber() {
|
||||||
|
await copyDepositFieldValue(
|
||||||
|
depositAccountNumberRaw.value,
|
||||||
|
'account',
|
||||||
|
'شماره حساب ثبت نشده است',
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
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,
|
||||||
|
depositAccountNumber,
|
||||||
|
depositSheba,
|
||||||
|
depositCardNumberRaw,
|
||||||
|
depositAccountNumberRaw,
|
||||||
|
depositShebaRaw,
|
||||||
|
depositCardLabel,
|
||||||
|
depositAccountNumberLabel,
|
||||||
|
depositShebaLabel,
|
||||||
|
hasDepositCardValue,
|
||||||
|
hasDepositAccountNumberValue,
|
||||||
|
hasDepositShebaValue,
|
||||||
|
copyDepositCardNumber,
|
||||||
|
copyDepositAccountNumber,
|
||||||
|
copyDepositShebaNumber,
|
||||||
|
openSupportMessenger,
|
||||||
|
openDepositSupportMessenger,
|
||||||
|
openMessengerEntry,
|
||||||
|
handleSupportMessengerClick,
|
||||||
|
goToSupportChat,
|
||||||
|
hasMessengerLink,
|
||||||
|
hasMultipleMessengers,
|
||||||
|
hasSupportPhoneLink,
|
||||||
|
hasSupportActions,
|
||||||
|
opensInNewTab,
|
||||||
|
loadSupportMessengerFromSettings,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
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,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -71,13 +71,26 @@ function setAppleTouchIconFallback() {
|
|||||||
appleTitle.content = getConfig('name_fa', 'اپ مشتری')
|
appleTitle.content = getConfig('name_fa', 'اپ مشتری')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function resolveConfigBase(url: string) {
|
||||||
|
try {
|
||||||
|
const parsed = new URL(url)
|
||||||
|
parsed.search = ''
|
||||||
|
parsed.hash = ''
|
||||||
|
parsed.pathname = parsed.pathname.replace(/\/get_user\/?$/i, '')
|
||||||
|
if (!parsed.pathname || parsed.pathname === '/') {
|
||||||
|
return parsed.origin
|
||||||
|
}
|
||||||
|
return `${parsed.origin}${parsed.pathname.replace(/\/+$/, '')}`
|
||||||
|
} catch {
|
||||||
|
return url.replace(/[?#].*$/, '').replace(/\/get_user\/?$/i, '').replace(/\/+$/, '')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function resolveRemoteLogo(path: string) {
|
function resolveRemoteLogo(path: string) {
|
||||||
if (/^(https?:\/\/|data:|blob:)/i.test(path)) return path
|
if (/^(https?:\/\/|data:|blob:)/i.test(path)) return path
|
||||||
|
|
||||||
const lastSuccess = localStorage.getItem('CONFIG_Success_URL')
|
const lastSuccess = localStorage.getItem('CONFIG_Success_URL')
|
||||||
const base = lastSuccess
|
const base = lastSuccess ? resolveConfigBase(lastSuccess) : 'https://adm.montzar.ir'
|
||||||
? lastSuccess.replace(/\/get_user\/?$/i, '').replace(/\/+$/, '')
|
|
||||||
: 'https://nerkh.gold'
|
|
||||||
|
|
||||||
return `${base}/${path.replace(/^\/+/, '')}`
|
return `${base}/${path.replace(/^\/+/, '')}`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
import type { AppConfig } from '@/config/types'
|
import type { AppConfig } from '@/config/types'
|
||||||
import { resetVersionCheckCache } from '@/config/load-version'
|
import { resetVersionCheckCache } from '@/config/load-version'
|
||||||
import { clearCachedPwaManifest } from '@/modules/pwa/manifest-cache'
|
import { clearCachedPwaManifest } from '@/modules/pwa/manifest-cache'
|
||||||
|
import { resolveTenantDomain } from '@/config/superadmin'
|
||||||
import { collectAuthTokensForPreserve } from '@/utils/authToken'
|
import { collectAuthTokensForPreserve } from '@/utils/authToken'
|
||||||
|
|
||||||
const CONFIG_COOKIE_NAME = 'APP_CONFIG_CACHE'
|
const CONFIG_COOKIE_NAME = 'APP_CONFIG_CACHE'
|
||||||
|
const APP_CONFIG_LS_KEY = 'APP_CONFIG_LS_CACHE'
|
||||||
const CONFIG_SUCCESS_URL_KEY = 'CONFIG_Success_URL'
|
const CONFIG_SUCCESS_URL_KEY = 'CONFIG_Success_URL'
|
||||||
const VERSION_SUCCESS_URL_KEY = 'VERSION_Success_URL'
|
const VERSION_SUCCESS_URL_KEY = 'VERSION_Success_URL'
|
||||||
const CONFIG_COOKIE_MAX_AGE_SECONDS = 60 * 60 * 24 * 7
|
const CONFIG_COOKIE_MAX_AGE_SECONDS = 60 * 60 * 24 * 7
|
||||||
@@ -18,6 +20,13 @@ type CachedConfigPayload = {
|
|||||||
config: AppConfig
|
config: AppConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type VersionedAppConfigCache = {
|
||||||
|
version: string
|
||||||
|
domain: string
|
||||||
|
cached_at: number
|
||||||
|
config: AppConfig
|
||||||
|
}
|
||||||
|
|
||||||
type VersionUpdateLock = {
|
type VersionUpdateLock = {
|
||||||
version: string
|
version: string
|
||||||
started_at: number
|
started_at: number
|
||||||
@@ -62,6 +71,54 @@ export function readCachedAppConfig(): AppConfig | null {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** کش بزرگ get_user در localStorage — با version باطل میشود */
|
||||||
|
export function readVersionedAppConfigCache(domain?: string): VersionedAppConfigCache | null {
|
||||||
|
try {
|
||||||
|
const raw = localStorage.getItem(APP_CONFIG_LS_KEY)
|
||||||
|
if (!raw) return null
|
||||||
|
|
||||||
|
const payload = JSON.parse(raw) as VersionedAppConfigCache
|
||||||
|
if (!payload?.config || !payload.version) return null
|
||||||
|
|
||||||
|
if (domain && payload.domain && payload.domain !== domain) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
return payload
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('Failed to read versioned app config cache:', error)
|
||||||
|
clearVersionedAppConfigCache()
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function writeVersionedAppConfigCache(
|
||||||
|
config: AppConfig,
|
||||||
|
version: string,
|
||||||
|
domain: string,
|
||||||
|
) {
|
||||||
|
const normalizedVersion = String(version || '').trim()
|
||||||
|
if (!normalizedVersion) return
|
||||||
|
|
||||||
|
try {
|
||||||
|
const payload: VersionedAppConfigCache = {
|
||||||
|
version: normalizedVersion,
|
||||||
|
domain: String(domain || '').trim(),
|
||||||
|
cached_at: Date.now(),
|
||||||
|
config,
|
||||||
|
}
|
||||||
|
localStorage.setItem(APP_CONFIG_LS_KEY, JSON.stringify(payload))
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('Failed to write versioned app config cache:', error)
|
||||||
|
}
|
||||||
|
|
||||||
|
writeCachedAppConfig(config)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function clearVersionedAppConfigCache() {
|
||||||
|
localStorage.removeItem(APP_CONFIG_LS_KEY)
|
||||||
|
}
|
||||||
|
|
||||||
export function writeCachedAppConfig(config: AppConfig) {
|
export function writeCachedAppConfig(config: AppConfig) {
|
||||||
try {
|
try {
|
||||||
const payload: CachedConfigPayload = {
|
const payload: CachedConfigPayload = {
|
||||||
@@ -84,6 +141,7 @@ export function writeCachedAppConfig(config: AppConfig) {
|
|||||||
|
|
||||||
export function clearCachedAppConfig() {
|
export function clearCachedAppConfig() {
|
||||||
document.cookie = `${CONFIG_COOKIE_NAME}=; Path=/; Max-Age=0; SameSite=Lax`
|
document.cookie = `${CONFIG_COOKIE_NAME}=; Path=/; Max-Age=0; SameSite=Lax`
|
||||||
|
clearVersionedAppConfigCache()
|
||||||
clearCachedPwaManifest()
|
clearCachedPwaManifest()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -223,6 +281,7 @@ export function clearAppStorageExceptToken() {
|
|||||||
export function clearAllBootstrapFetchCaches() {
|
export function clearAllBootstrapFetchCaches() {
|
||||||
localStorage.removeItem(CONFIG_SUCCESS_URL_KEY)
|
localStorage.removeItem(CONFIG_SUCCESS_URL_KEY)
|
||||||
localStorage.removeItem(VERSION_SUCCESS_URL_KEY)
|
localStorage.removeItem(VERSION_SUCCESS_URL_KEY)
|
||||||
|
clearVersionedAppConfigCache()
|
||||||
clearCachedPwaManifest()
|
clearCachedPwaManifest()
|
||||||
resetVersionCheckCache()
|
resetVersionCheckCache()
|
||||||
window.__APP_CONFIG__ = undefined
|
window.__APP_CONFIG__ = undefined
|
||||||
@@ -253,6 +312,7 @@ export async function refreshConfigCacheForVersion(
|
|||||||
await clearBrowserRuntimeCaches()
|
await clearBrowserRuntimeCaches()
|
||||||
|
|
||||||
writeCachedAppConfig(freshConfig)
|
writeCachedAppConfig(freshConfig)
|
||||||
|
writeVersionedAppConfigCache(freshConfig, normalizedVersion, resolveTenantDomain())
|
||||||
finishVersionUpdateBeforeReload(normalizedVersion)
|
finishVersionUpdateBeforeReload(normalizedVersion)
|
||||||
|
|
||||||
return freshConfig
|
return freshConfig
|
||||||
@@ -275,6 +335,7 @@ export async function resetAppAndRefreshConfig(
|
|||||||
|
|
||||||
if (normalizedVersion) {
|
if (normalizedVersion) {
|
||||||
writeStoredAppVersion(normalizedVersion)
|
writeStoredAppVersion(normalizedVersion)
|
||||||
|
writeVersionedAppConfigCache(freshConfig, normalizedVersion, resolveTenantDomain())
|
||||||
}
|
}
|
||||||
|
|
||||||
return freshConfig
|
return freshConfig
|
||||||
|
|||||||
@@ -1,33 +1,54 @@
|
|||||||
import type { AppConfig } from '@/config/types'
|
import type { AppConfig } from '@/config/types'
|
||||||
import { readCachedAppConfig, writeCachedAppConfig } from '@/config/config-cache'
|
import {
|
||||||
|
clearCachedAppConfig,
|
||||||
|
getNormalizedVersion,
|
||||||
|
readCachedAppConfig,
|
||||||
|
readVersionedAppConfigCache,
|
||||||
|
writeCachedAppConfig,
|
||||||
|
writeStoredAppVersion,
|
||||||
|
writeVersionedAppConfigCache,
|
||||||
|
} from '@/config/config-cache'
|
||||||
|
import { loadRemoteAppVersion } from '@/config/load-version'
|
||||||
|
import {
|
||||||
|
assertServerReachableConfig,
|
||||||
|
hideServerUnavailableOverlay,
|
||||||
|
isServerUnreachableConfig,
|
||||||
|
} from '@/utils/serverUnavailable'
|
||||||
|
import {
|
||||||
|
allowSuperAdminFallback,
|
||||||
|
getSuperAdminBase,
|
||||||
|
getSuperAdminBases,
|
||||||
|
isSuperAdminUrl,
|
||||||
|
resolveTenantDomain,
|
||||||
|
SA_RETRY_ROUNDS,
|
||||||
|
} from '@/config/superadmin'
|
||||||
|
|
||||||
const CONFIG_SUCCESS_URL_KEY = 'CONFIG_Success_URL'
|
const CONFIG_SUCCESS_URL_KEY = 'CONFIG_Success_URL'
|
||||||
export const CONFIG_RETRY_ROUNDS = 5
|
const VERSION_SUCCESS_URL_KEY = 'VERSION_Success_URL'
|
||||||
|
export const CONFIG_RETRY_ROUNDS = SA_RETRY_ROUNDS
|
||||||
|
|
||||||
function getProtocol() {
|
export { getSuperAdminBase, resolveTenantDomain } from '@/config/superadmin'
|
||||||
return window.location.protocol === 'https:' ? 'https:' : 'http:'
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/** فقط SuperAdmin — بدون رجیستری قدیمی */
|
||||||
export function getConfigUrls() {
|
export function getConfigUrls() {
|
||||||
const protocol = getProtocol()
|
const domain = encodeURIComponent(resolveTenantDomain())
|
||||||
|
return getSuperAdminBases().map((base) => `${base}/get_user?domain=${domain}`)
|
||||||
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`
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** اولویت با last successful SuperAdmin؛ رجیستری قدیمی sticky نشود */
|
||||||
export function sortConfigUrls(urls: string[]) {
|
export function sortConfigUrls(urls: string[]) {
|
||||||
const lastSuccessUrl = localStorage.getItem(CONFIG_SUCCESS_URL_KEY)
|
const lastSuccessUrl = localStorage.getItem(CONFIG_SUCCESS_URL_KEY)
|
||||||
|
if (
|
||||||
return [...urls].sort((a, b) => {
|
!lastSuccessUrl ||
|
||||||
if (a === lastSuccessUrl) return -1
|
!urls.includes(lastSuccessUrl) ||
|
||||||
if (b === lastSuccessUrl) return 1
|
!isSuperAdminUrl(lastSuccessUrl)
|
||||||
return 0
|
) {
|
||||||
})
|
if (lastSuccessUrl && !isSuperAdminUrl(lastSuccessUrl)) {
|
||||||
|
localStorage.removeItem(CONFIG_SUCCESS_URL_KEY)
|
||||||
|
}
|
||||||
|
return [...urls]
|
||||||
|
}
|
||||||
|
return [lastSuccessUrl, ...urls.filter((url) => url !== lastSuccessUrl)]
|
||||||
}
|
}
|
||||||
|
|
||||||
function clearStaleConfigSuccessUrl(url: string) {
|
function clearStaleConfigSuccessUrl(url: string) {
|
||||||
@@ -36,6 +57,22 @@ function clearStaleConfigSuccessUrl(url: string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** پاککردن کامل کش کانفیگ قدیمی (کوکی + localStorage) */
|
||||||
|
function purgeLegacyConfigCache() {
|
||||||
|
clearCachedAppConfig()
|
||||||
|
localStorage.removeItem(CONFIG_SUCCESS_URL_KEY)
|
||||||
|
localStorage.removeItem(VERSION_SUCCESS_URL_KEY)
|
||||||
|
window.__APP_CONFIG__ = undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
function assertValidAppConfig(config: AppConfig, url: string): AppConfig {
|
||||||
|
const user = (config as { user?: unknown })?.user
|
||||||
|
if (!user || typeof user !== 'object') {
|
||||||
|
throw new Error(`SuperAdmin config invalid (no user) from ${url}`)
|
||||||
|
}
|
||||||
|
return config
|
||||||
|
}
|
||||||
|
|
||||||
async function fetchConfig(url: string, timeout = 3000): Promise<AppConfig> {
|
async function fetchConfig(url: string, timeout = 3000): Promise<AppConfig> {
|
||||||
const controller = new AbortController()
|
const controller = new AbortController()
|
||||||
const timeoutId = window.setTimeout(() => controller.abort(), timeout)
|
const timeoutId = window.setTimeout(() => controller.abort(), timeout)
|
||||||
@@ -44,10 +81,10 @@ async function fetchConfig(url: string, timeout = 3000): Promise<AppConfig> {
|
|||||||
const response = await fetch(url, {
|
const response = await fetch(url, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: {
|
headers: {
|
||||||
Accept: 'application/json'
|
Accept: 'application/json',
|
||||||
},
|
},
|
||||||
cache: 'no-store',
|
cache: 'no-store',
|
||||||
signal: controller.signal
|
signal: controller.signal,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
@@ -60,14 +97,17 @@ async function fetchConfig(url: string, timeout = 3000): Promise<AppConfig> {
|
|||||||
throw new Error('Config response is not JSON')
|
throw new Error('Config response is not JSON')
|
||||||
}
|
}
|
||||||
|
|
||||||
return await response.json()
|
return assertValidAppConfig(await response.json(), url)
|
||||||
} finally {
|
} finally {
|
||||||
clearTimeout(timeoutId)
|
clearTimeout(timeoutId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function fetchFreshAppConfig(rounds = CONFIG_RETRY_ROUNDS): Promise<AppConfig> {
|
async function tryFetchFromUrls(
|
||||||
const urls = sortConfigUrls(getConfigUrls())
|
urls: string[],
|
||||||
|
rounds: number,
|
||||||
|
): Promise<AppConfig | null> {
|
||||||
|
if (!urls.length) return null
|
||||||
|
|
||||||
for (let round = 1; round <= rounds; round++) {
|
for (let round = 1; round <= rounds; round++) {
|
||||||
for (let index = 0; index < urls.length; index++) {
|
for (let index = 0; index < urls.length; index++) {
|
||||||
@@ -77,9 +117,13 @@ export async function fetchFreshAppConfig(rounds = CONFIG_RETRY_ROUNDS): Promise
|
|||||||
const timeout = index === urls.length - 1 ? 7000 : 4000
|
const timeout = index === urls.length - 1 ? 7000 : 4000
|
||||||
const config = await fetchConfig(url, timeout)
|
const config = await fetchConfig(url, timeout)
|
||||||
|
|
||||||
localStorage.setItem(CONFIG_SUCCESS_URL_KEY, url)
|
if (isSuperAdminUrl(url)) {
|
||||||
|
localStorage.setItem(CONFIG_SUCCESS_URL_KEY, url)
|
||||||
|
} else {
|
||||||
|
clearStaleConfigSuccessUrl(url)
|
||||||
|
}
|
||||||
writeCachedAppConfig(config)
|
writeCachedAppConfig(config)
|
||||||
|
console.info('[config] loaded from SuperAdmin:', url, (config as { user?: { name?: string } })?.user?.name)
|
||||||
return config
|
return config
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
clearStaleConfigSuccessUrl(url)
|
clearStaleConfigSuccessUrl(url)
|
||||||
@@ -88,15 +132,157 @@ export async function fetchFreshAppConfig(rounds = CONFIG_RETRY_ROUNDS): Promise
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Error('Cannot load app config from any server')
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function loadAppConfig(): Promise<AppConfig> {
|
export async function fetchFreshAppConfig(
|
||||||
const cachedConfig = readCachedAppConfig()
|
rounds = CONFIG_RETRY_ROUNDS,
|
||||||
|
options?: { skipPurge?: boolean },
|
||||||
if (cachedConfig) {
|
): Promise<AppConfig> {
|
||||||
return cachedConfig
|
// cold load: کش قدیمی را دور بریز — poll/background نباید کش قطع را پاک کند
|
||||||
|
if (!options?.skipPurge) {
|
||||||
|
purgeLegacyConfigCache()
|
||||||
}
|
}
|
||||||
|
|
||||||
return await fetchFreshAppConfig()
|
const urls = sortConfigUrls(getConfigUrls())
|
||||||
|
const saUrls = urls.filter(isSuperAdminUrl)
|
||||||
|
const otherUrls = urls.filter((url) => !isSuperAdminUrl(url))
|
||||||
|
|
||||||
|
// اول SA؛ در DEV اگر allowSuperAdminFallback فعال باشد به رجیستری میرود (در boursecu غیرفعال)
|
||||||
|
const lists =
|
||||||
|
saUrls.length > 0
|
||||||
|
? allowSuperAdminFallback()
|
||||||
|
? [saUrls, otherUrls]
|
||||||
|
: [saUrls]
|
||||||
|
: [urls]
|
||||||
|
|
||||||
|
console.info('[config] SuperAdmin-only URLs:', saUrls.length ? saUrls : urls)
|
||||||
|
|
||||||
|
for (const list of lists) {
|
||||||
|
const config = await tryFetchFromUrls(list, rounds)
|
||||||
|
if (config) return config
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error(
|
||||||
|
`Cannot load from SuperAdmin (${getSuperAdminBase() || 'none'}). دامنه tenant در سوپرادمین ثبت نشده یا API/CORS مشکل دارد.`,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const UNBLOCK_POLL_MS = 5000
|
||||||
|
let unblockPollTimer: number | null = null
|
||||||
|
|
||||||
|
function stopUnblockPoll() {
|
||||||
|
if (unblockPollTimer != null) {
|
||||||
|
window.clearInterval(unblockPollTimer)
|
||||||
|
unblockPollTimer = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function persistFreshConfig(config: AppConfig, domain: string, remoteVersion = '') {
|
||||||
|
writeCachedAppConfig(config)
|
||||||
|
if (remoteVersion) {
|
||||||
|
writeVersionedAppConfigCache(config, remoteVersion, domain)
|
||||||
|
writeStoredAppVersion(remoteVersion)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** وقتی overlay قطع فعال است، وصل شدن از SA را بدون پاککردن کش چک کن */
|
||||||
|
function startUnblockPoll(domain: string) {
|
||||||
|
if (unblockPollTimer != null) return
|
||||||
|
|
||||||
|
unblockPollTimer = window.setInterval(() => {
|
||||||
|
void (async () => {
|
||||||
|
try {
|
||||||
|
const fresh = await fetchFreshAppConfig(2, { skipPurge: true })
|
||||||
|
if (isServerUnreachableConfig(fresh)) return
|
||||||
|
|
||||||
|
let remoteVersion = ''
|
||||||
|
try {
|
||||||
|
remoteVersion = getNormalizedVersion(await loadRemoteAppVersion({ rounds: 2 }))
|
||||||
|
} catch {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
|
||||||
|
stopUnblockPoll()
|
||||||
|
persistFreshConfig(fresh, domain, remoteVersion)
|
||||||
|
hideServerUnavailableOverlay()
|
||||||
|
window.location.reload()
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('Unblock poll get_user failed:', error)
|
||||||
|
}
|
||||||
|
})()
|
||||||
|
}, UNBLOCK_POLL_MS)
|
||||||
|
}
|
||||||
|
|
||||||
|
function lockForBlockedServer(config: AppConfig, domain: string, remoteVersion = ''): never {
|
||||||
|
persistFreshConfig(config, domain, remoteVersion)
|
||||||
|
startUnblockPoll(domain)
|
||||||
|
assertServerReachableConfig(config)
|
||||||
|
throw new Error('unreachable')
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* اول get_version (سبک) — فقط اگر ورژن عوض شده یا کش نبود get_user میزند.
|
||||||
|
* اگر کش «قطع» باشد همیشه get_user تازه میزنیم تا وصل مجدد گیر نکند.
|
||||||
|
*/
|
||||||
|
export async function loadAppConfig(): Promise<AppConfig> {
|
||||||
|
const domain = resolveTenantDomain()
|
||||||
|
|
||||||
|
let remoteVersion = ''
|
||||||
|
try {
|
||||||
|
remoteVersion = getNormalizedVersion(await loadRemoteAppVersion({ rounds: 3 }))
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('get_version failed during config load:', error)
|
||||||
|
}
|
||||||
|
|
||||||
|
const cached = readVersionedAppConfigCache(domain)
|
||||||
|
|
||||||
|
if (cached && remoteVersion && cached.version === remoteVersion) {
|
||||||
|
const config = cached.config
|
||||||
|
if (!isServerUnreachableConfig(config)) {
|
||||||
|
writeStoredAppVersion(remoteVersion)
|
||||||
|
// عمداً get_user در بکگراند نیست — فقط با عوض شدن ورژن
|
||||||
|
return config
|
||||||
|
}
|
||||||
|
// کش قطع است با ورژن یکسان → fall through به fetch تازه
|
||||||
|
}
|
||||||
|
|
||||||
|
// اگر get_version در دسترس نبود و کش سالم است، از کش استفاده کن
|
||||||
|
if (cached && !remoteVersion) {
|
||||||
|
console.warn('Using cached get_user because get_version is unavailable')
|
||||||
|
const config = cached.config
|
||||||
|
if (!isServerUnreachableConfig(config)) {
|
||||||
|
return config
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// سازگاری قدیمی بدون SA: کوکی کوچک
|
||||||
|
if (!getSuperAdminBase() && !cached) {
|
||||||
|
const cookieCached = readCachedAppConfig()
|
||||||
|
if (cookieCached && !remoteVersion && !isServerUnreachableConfig(cookieCached)) {
|
||||||
|
return cookieCached
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const config = await fetchFreshAppConfig()
|
||||||
|
if (isServerUnreachableConfig(config)) {
|
||||||
|
lockForBlockedServer(config, domain, remoteVersion)
|
||||||
|
}
|
||||||
|
|
||||||
|
stopUnblockPoll()
|
||||||
|
if (remoteVersion) {
|
||||||
|
writeVersionedAppConfigCache(config, remoteVersion, domain)
|
||||||
|
writeStoredAppVersion(remoteVersion)
|
||||||
|
} else {
|
||||||
|
writeCachedAppConfig(config)
|
||||||
|
}
|
||||||
|
|
||||||
|
return config
|
||||||
|
} catch (error) {
|
||||||
|
if (cached && isServerUnreachableConfig(cached.config)) {
|
||||||
|
lockForBlockedServer(cached.config, domain, remoteVersion)
|
||||||
|
}
|
||||||
|
throw error
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,11 @@
|
|||||||
|
import {
|
||||||
|
allowSuperAdminFallback,
|
||||||
|
getSuperAdminBases,
|
||||||
|
isSuperAdminUrl,
|
||||||
|
resolveTenantDomain,
|
||||||
|
SA_RETRY_ROUNDS,
|
||||||
|
} from '@/config/superadmin'
|
||||||
|
|
||||||
type VersionResponse =
|
type VersionResponse =
|
||||||
| string
|
| string
|
||||||
| number
|
| number
|
||||||
@@ -9,36 +17,25 @@ type VersionResponse =
|
|||||||
}
|
}
|
||||||
|
|
||||||
const VERSION_SUCCESS_URL_KEY = 'VERSION_Success_URL'
|
const VERSION_SUCCESS_URL_KEY = 'VERSION_Success_URL'
|
||||||
export const VERSION_RETRY_ROUNDS = 5
|
export const VERSION_RETRY_ROUNDS = SA_RETRY_ROUNDS
|
||||||
|
|
||||||
let versionFetchPromise: Promise<string | null> | null = null
|
let versionFetchPromise: Promise<string | null> | null = null
|
||||||
let cachedVersionResult: string | null | undefined
|
|
||||||
|
|
||||||
function getProtocol() {
|
|
||||||
return window.location.protocol === 'https:' ? 'https:' : 'http:'
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/** فقط SuperAdmin — بدون رجیستری قدیمی */
|
||||||
function getVersionUrls() {
|
function getVersionUrls() {
|
||||||
const protocol = getProtocol()
|
const domain = encodeURIComponent(resolveTenantDomain())
|
||||||
|
return getSuperAdminBases().map((base) => `${base}/get_version?domain=${domain}`)
|
||||||
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[]) {
|
function sortVersionUrls(urls: string[]) {
|
||||||
const lastSuccessUrl = localStorage.getItem(VERSION_SUCCESS_URL_KEY)
|
const lastSuccessUrl = localStorage.getItem(VERSION_SUCCESS_URL_KEY)
|
||||||
|
if (!lastSuccessUrl || !urls.includes(lastSuccessUrl) || !isSuperAdminUrl(lastSuccessUrl)) {
|
||||||
if (!lastSuccessUrl) {
|
if (lastSuccessUrl && !isSuperAdminUrl(lastSuccessUrl)) {
|
||||||
return urls
|
localStorage.removeItem(VERSION_SUCCESS_URL_KEY)
|
||||||
|
}
|
||||||
|
return [...urls]
|
||||||
}
|
}
|
||||||
|
return [lastSuccessUrl, ...urls.filter((url) => url !== lastSuccessUrl)]
|
||||||
const others = urls.filter((url) => url !== lastSuccessUrl)
|
|
||||||
return [lastSuccessUrl, ...others]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function clearStaleVersionSuccessUrl(url: string) {
|
function clearStaleVersionSuccessUrl(url: string) {
|
||||||
@@ -89,10 +86,10 @@ async function fetchVersion(url: string, timeout = 3500): Promise<string | null>
|
|||||||
const response = await fetch(url, {
|
const response = await fetch(url, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: {
|
headers: {
|
||||||
Accept: 'application/json'
|
Accept: 'application/json',
|
||||||
},
|
},
|
||||||
cache: 'no-store',
|
cache: 'no-store',
|
||||||
signal: controller.signal
|
signal: controller.signal,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
@@ -100,10 +97,11 @@ async function fetchVersion(url: string, timeout = 3500): Promise<string | null>
|
|||||||
}
|
}
|
||||||
|
|
||||||
const contentType = response.headers.get('content-type') ?? ''
|
const contentType = response.headers.get('content-type') ?? ''
|
||||||
|
if (!contentType.includes('application/json')) {
|
||||||
|
throw new Error('Version response is not JSON')
|
||||||
|
}
|
||||||
|
|
||||||
const data = contentType.includes('application/json')
|
const data = (await response.json()) as VersionResponse
|
||||||
? ((await response.json()) as VersionResponse)
|
|
||||||
: ((await response.text()) as VersionResponse)
|
|
||||||
|
|
||||||
const version = normalizeVersionResponse(data)
|
const version = normalizeVersionResponse(data)
|
||||||
|
|
||||||
@@ -112,15 +110,17 @@ async function fetchVersion(url: string, timeout = 3500): Promise<string | null>
|
|||||||
}
|
}
|
||||||
|
|
||||||
localStorage.setItem(VERSION_SUCCESS_URL_KEY, url)
|
localStorage.setItem(VERSION_SUCCESS_URL_KEY, url)
|
||||||
|
|
||||||
return version
|
return version
|
||||||
} finally {
|
} finally {
|
||||||
window.clearTimeout(timeoutId)
|
window.clearTimeout(timeoutId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchVersionWithRetry(rounds = VERSION_RETRY_ROUNDS): Promise<string | null> {
|
async function tryFetchVersionFromUrls(
|
||||||
const urls = sortVersionUrls(getVersionUrls())
|
urls: string[],
|
||||||
|
rounds: number,
|
||||||
|
): Promise<string | null> {
|
||||||
|
if (!urls.length) return null
|
||||||
|
|
||||||
for (let round = 1; round <= rounds; round++) {
|
for (let round = 1; round <= rounds; round++) {
|
||||||
for (let index = 0; index < urls.length; index++) {
|
for (let index = 0; index < urls.length; index++) {
|
||||||
@@ -142,8 +142,27 @@ async function fetchVersionWithRetry(rounds = VERSION_RETRY_ROUNDS): Promise<str
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function fetchVersionWithRetry(rounds = VERSION_RETRY_ROUNDS): Promise<string | null> {
|
||||||
|
const urls = sortVersionUrls(getVersionUrls())
|
||||||
|
const saUrls = urls.filter(isSuperAdminUrl)
|
||||||
|
const otherUrls = urls.filter((url) => !isSuperAdminUrl(url))
|
||||||
|
|
||||||
|
const lists =
|
||||||
|
saUrls.length > 0
|
||||||
|
? allowSuperAdminFallback()
|
||||||
|
? [saUrls, otherUrls]
|
||||||
|
: [saUrls]
|
||||||
|
: [urls]
|
||||||
|
|
||||||
|
for (const list of lists) {
|
||||||
|
const version = await tryFetchVersionFromUrls(list, rounds)
|
||||||
|
if (version) return version
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
export function resetVersionCheckCache() {
|
export function resetVersionCheckCache() {
|
||||||
cachedVersionResult = undefined
|
|
||||||
versionFetchPromise = null
|
versionFetchPromise = null
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,22 +177,13 @@ export async function loadRemoteAppVersion(options?: {
|
|||||||
resetVersionCheckCache()
|
resetVersionCheckCache()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cachedVersionResult !== undefined) {
|
|
||||||
return cachedVersionResult
|
|
||||||
}
|
|
||||||
|
|
||||||
if (versionFetchPromise) {
|
if (versionFetchPromise) {
|
||||||
return versionFetchPromise
|
return versionFetchPromise
|
||||||
}
|
}
|
||||||
|
|
||||||
versionFetchPromise = fetchVersionWithRetry(rounds)
|
versionFetchPromise = fetchVersionWithRetry(rounds).finally(() => {
|
||||||
.then((version) => {
|
versionFetchPromise = null
|
||||||
cachedVersionResult = version
|
})
|
||||||
return version
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
versionFetchPromise = null
|
|
||||||
})
|
|
||||||
|
|
||||||
return versionFetchPromise
|
return versionFetchPromise
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,130 @@
|
|||||||
|
/** سوپرادمین — مستر، بعد دو اسلیو */
|
||||||
|
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'
|
||||||
|
|
||||||
|
const PRODUCTION_SA = SUPERADMIN_BASES[0]
|
||||||
|
/** پروکسی Vite در توسعه — بدون مشکل CORS */
|
||||||
|
const DEV_SA_PROXY = '/__sa'
|
||||||
|
|
||||||
|
function isLoopbackBase(url: string) {
|
||||||
|
try {
|
||||||
|
const host = new URL(url, 'http://localhost').hostname
|
||||||
|
return host === 'localhost' || host === '127.0.0.1'
|
||||||
|
} catch {
|
||||||
|
return /localhost|127\.0\.0\.1/i.test(url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function isDevProxyBase(url: string) {
|
||||||
|
return url === DEV_SA_PROXY || url.startsWith(`${DEV_SA_PROXY}/`)
|
||||||
|
}
|
||||||
|
|
||||||
|
function normalizeBase(url: string) {
|
||||||
|
return String(url || '').trim().replace(/\/$/, '')
|
||||||
|
}
|
||||||
|
|
||||||
|
/** همه پایههای سوپرادمین به ترتیب اولویت (env اول، بعد لیست) */
|
||||||
|
export function getSuperAdminBases(): string[] {
|
||||||
|
const fromEnv = normalizeBase(String(import.meta.env.VITE_SUPERADMIN_URL || ''))
|
||||||
|
const bases = [...SUPERADMIN_BASES]
|
||||||
|
|
||||||
|
// در DEV همیشه اول پروکسی Vite — بدون CORS؛ بعد failover به دامنههای SA
|
||||||
|
if (import.meta.env.DEV && !fromEnv) {
|
||||||
|
return [DEV_SA_PROXY, ...bases]
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fromEnv) {
|
||||||
|
return [fromEnv, ...bases.filter((base) => base !== fromEnv)]
|
||||||
|
}
|
||||||
|
|
||||||
|
return bases
|
||||||
|
}
|
||||||
|
|
||||||
|
/** پایه سوپرادمین اول لیست — برای سازگاری با کد قبلی */
|
||||||
|
export function getSuperAdminBase(): string {
|
||||||
|
return getSuperAdminBases()[0] || ''
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* دامنه tenant برای get_user:
|
||||||
|
* - VITE_TENANT_DOMAIN اگر ست باشد
|
||||||
|
* - در DEV روی localhost → دمو خانگی
|
||||||
|
* - در DEV روی IP/hostname LAN → همان host (برای domains[] در سوپرادمین)
|
||||||
|
* - در prod → hostname
|
||||||
|
*/
|
||||||
|
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 (import.meta.env.DEV) {
|
||||||
|
if (!host || host === 'localhost' || host === '127.0.0.1') {
|
||||||
|
return 'k.montzar.ir'
|
||||||
|
}
|
||||||
|
return host
|
||||||
|
}
|
||||||
|
|
||||||
|
return host || 'k.montzar.ir'
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isSuperAdminUrl(url: string): boolean {
|
||||||
|
return getSuperAdminBases().some((base) => url.startsWith(base))
|
||||||
|
}
|
||||||
|
|
||||||
|
/** boursecu: فقط SuperAdmin — fallback به رجیستری غیرفعال (modular در DEV=true) */
|
||||||
|
export function allowSuperAdminFallback(): boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
/** آدرس SA جایگزین وقتی primary لوکال/پروکسی است */
|
||||||
|
export function getFallbackSuperAdminBase(): string {
|
||||||
|
const primary = getSuperAdminBase()
|
||||||
|
if (!primary) return PRODUCTION_SA
|
||||||
|
if (isLoopbackBase(primary) || isDevProxyBase(primary)) return PRODUCTION_SA
|
||||||
|
const next = SUPERADMIN_BASES.find((base) => base !== primary)
|
||||||
|
return next || ''
|
||||||
|
}
|
||||||
|
|
||||||
|
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,9 +8,28 @@ export function useAppNavigation() {
|
|||||||
const popVisible = ref(false)
|
const popVisible = ref(false)
|
||||||
const currentRoute = computed(() => route.name)
|
const currentRoute = computed(() => route.name)
|
||||||
const hideMenu = computed(() => !!route.meta.hideMenu)
|
const hideMenu = computed(() => !!route.meta.hideMenu)
|
||||||
|
/** فقط ناو پایین موبایل — سایدبار دسکتاپ را مخفی نمیکند */
|
||||||
|
const hideBottomNav = computed(
|
||||||
|
() => !!route.meta.hideBottomNav || !!route.meta.hideMenu,
|
||||||
|
)
|
||||||
|
|
||||||
function isNavActive(routeName: string) {
|
function isNavActive(routeName: string) {
|
||||||
return currentRoute.value === routeName
|
if (currentRoute.value === routeName) return true
|
||||||
|
|
||||||
|
// parent route (e.g. physicalReceive → list/new)
|
||||||
|
if (route.matched.some((record) => record.name === routeName)) return true
|
||||||
|
|
||||||
|
// fund detail/add are sibling routes of fund
|
||||||
|
if (routeName === 'fund') {
|
||||||
|
return currentRoute.value === 'fund_info' || currentRoute.value === 'fund_add'
|
||||||
|
}
|
||||||
|
|
||||||
|
// piggy detail/add are sibling routes of piggy
|
||||||
|
if (routeName === 'piggy') {
|
||||||
|
return currentRoute.value === 'piggy_info' || currentRoute.value === 'piggy_add'
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
function navItemClass(routeName: string) {
|
function navItemClass(routeName: string) {
|
||||||
@@ -34,6 +53,7 @@ export function useAppNavigation() {
|
|||||||
popVisible,
|
popVisible,
|
||||||
currentRoute,
|
currentRoute,
|
||||||
hideMenu,
|
hideMenu,
|
||||||
|
hideBottomNav,
|
||||||
isNavActive,
|
isNavActive,
|
||||||
navItemClass,
|
navItemClass,
|
||||||
navigateTo,
|
navigateTo,
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ const BOURSECU_PRIMARY_NAV: AppNavItem[] = [
|
|||||||
{
|
{
|
||||||
id: 'buyProduct',
|
id: 'buyProduct',
|
||||||
routeName: 'buyProduct',
|
routeName: 'buyProduct',
|
||||||
label: 'سفارشها',
|
label: 'خرید و فروش',
|
||||||
icon: 'vuesax-linear:box',
|
icon: 'vuesax-linear:box',
|
||||||
iconSrc: getBoursecuActionIconSrc('buySell'),
|
iconSrc: getBoursecuActionIconSrc('buySell'),
|
||||||
},
|
},
|
||||||
@@ -33,6 +33,20 @@ const BOURSECU_PRIMARY_NAV: AppNavItem[] = [
|
|||||||
icon: 'vuesax-linear:wallet-1',
|
icon: 'vuesax-linear:wallet-1',
|
||||||
iconSrc: getBoursecuActionIconSrc('wallet'),
|
iconSrc: getBoursecuActionIconSrc('wallet'),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
id: 'fund',
|
||||||
|
routeName: 'fund',
|
||||||
|
label: 'دارایی ها',
|
||||||
|
icon: 'vuesax-linear:cup',
|
||||||
|
iconSrc: getBoursecuActionIconSrc('assets'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'physicalReceive',
|
||||||
|
routeName: 'physicalReceive',
|
||||||
|
label: 'تحویل فیزیکی',
|
||||||
|
icon: 'vuesax-linear:direct-inbox',
|
||||||
|
iconSrc: getBoursecuActionIconSrc('physicalReceive'),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
id: 'user',
|
id: 'user',
|
||||||
routeName: 'user',
|
routeName: 'user',
|
||||||
|
|||||||
@@ -8,31 +8,33 @@
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<nav class="desktop-sidebar__section" aria-label="منوی اصلی">
|
<div class="desktop-sidebar__nav-scroll">
|
||||||
<DesktopNavItem
|
<nav class="desktop-sidebar__section" aria-label="منوی اصلی">
|
||||||
v-for="item in primaryItems"
|
<DesktopNavItem
|
||||||
:key="item.id"
|
v-for="item in primaryItems"
|
||||||
:icon="item.icon"
|
:key="item.id"
|
||||||
:icon-src="item.iconSrc"
|
:icon="item.icon"
|
||||||
:label="item.label"
|
:icon-src="item.iconSrc"
|
||||||
:active="isNavActive(item.routeName)"
|
:label="item.label"
|
||||||
@click="navigateTo(item.routeName)"
|
:active="isNavActive(item.routeName)"
|
||||||
/>
|
@click="navigateTo(item.routeName)"
|
||||||
</nav>
|
/>
|
||||||
|
</nav>
|
||||||
|
|
||||||
<div class="desktop-sidebar__divider" />
|
<div class="desktop-sidebar__divider" />
|
||||||
|
|
||||||
<nav class="desktop-sidebar__section desktop-sidebar__section--secondary" aria-label="منوی فرعی">
|
<nav class="desktop-sidebar__section desktop-sidebar__section--secondary" aria-label="منوی فرعی">
|
||||||
<DesktopNavItem
|
<DesktopNavItem
|
||||||
v-for="item in secondaryItems"
|
v-for="item in secondaryItems"
|
||||||
:key="item.id"
|
:key="item.id"
|
||||||
:icon="item.icon"
|
:icon="item.icon"
|
||||||
:icon-src="item.iconSrc"
|
:icon-src="item.iconSrc"
|
||||||
:label="item.label"
|
:label="item.label"
|
||||||
:active="isNavActive(item.routeName)"
|
:active="isNavActive(item.routeName)"
|
||||||
@click="navigateTo(item.routeName)"
|
@click="navigateTo(item.routeName)"
|
||||||
/>
|
/>
|
||||||
</nav>
|
</nav>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="desktop-sidebar__credit">
|
<div class="desktop-sidebar__credit">
|
||||||
<AppCreditLink variant="sidebar" />
|
<AppCreditLink variant="sidebar" />
|
||||||
@@ -43,16 +45,33 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { computed } from 'vue'
|
import { computed } from 'vue'
|
||||||
import { useConfigStore } from '@/store/configStore'
|
import { useConfigStore } from '@/store/configStore'
|
||||||
|
import { useSettingsStore } from '@/store/settingsStore'
|
||||||
import { getProjectSplashLogo } from '@/utils/config'
|
import { getProjectSplashLogo } from '@/utils/config'
|
||||||
|
import { featureSettingForRoute } from '@/utils/superAdminMenuGates'
|
||||||
import { getPrimaryNavItems, SECONDARY_NAV } from '../config/navigation'
|
import { getPrimaryNavItems, SECONDARY_NAV } from '../config/navigation'
|
||||||
import { useAppNavigation } from '../composables/useAppNavigation'
|
import { useAppNavigation } from '../composables/useAppNavigation'
|
||||||
import DesktopNavItem from './DesktopNavItem.vue'
|
import DesktopNavItem from './DesktopNavItem.vue'
|
||||||
import AppCreditLink from '@/components/AppCreditLink.vue'
|
import AppCreditLink from '@/components/AppCreditLink.vue'
|
||||||
|
|
||||||
const config = useConfigStore()
|
const config = useConfigStore()
|
||||||
|
const settingsStore = useSettingsStore()
|
||||||
const navLogo = computed(() => getProjectSplashLogo(config.config?.avatar))
|
const navLogo = computed(() => getProjectSplashLogo(config.config?.avatar))
|
||||||
const primaryItems = getPrimaryNavItems()
|
|
||||||
const secondaryItems = SECONDARY_NAV
|
const primaryItems = computed(() =>
|
||||||
|
getPrimaryNavItems().filter((item) => {
|
||||||
|
const featureKey = featureSettingForRoute(item.routeName)
|
||||||
|
if (featureKey) return settingsStore.isSettingTruthy(featureKey)
|
||||||
|
return true
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
|
||||||
|
const secondaryItems = computed(() =>
|
||||||
|
SECONDARY_NAV.filter((item) => {
|
||||||
|
const featureKey = featureSettingForRoute(item.routeName)
|
||||||
|
if (featureKey) return settingsStore.isSettingTruthy(featureKey)
|
||||||
|
return true
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
|
||||||
const { isNavActive, navigateTo } = useAppNavigation()
|
const { isNavActive, navigateTo } = useAppNavigation()
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -95,6 +95,7 @@
|
|||||||
justify-content: center;
|
justify-content: center;
|
||||||
padding: 8px 12px 20px;
|
padding: 8px 12px 20px;
|
||||||
margin-bottom: 4px;
|
margin-bottom: 4px;
|
||||||
|
flex-shrink: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.desktop-sidebar__logo {
|
.desktop-sidebar__logo {
|
||||||
@@ -105,27 +106,50 @@
|
|||||||
object-fit: contain;
|
object-fit: contain;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.desktop-sidebar__nav-scroll {
|
||||||
|
flex: 1 1 auto;
|
||||||
|
min-height: 0;
|
||||||
|
overflow-x: hidden;
|
||||||
|
overflow-y: auto;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0;
|
||||||
|
padding-bottom: 8px;
|
||||||
|
-webkit-overflow-scrolling: touch;
|
||||||
|
}
|
||||||
|
|
||||||
.desktop-sidebar__section {
|
.desktop-sidebar__section {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
gap: 4px;
|
gap: 4px;
|
||||||
|
flex-shrink: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.desktop-sidebar__section--secondary {
|
.desktop-sidebar__section--secondary {
|
||||||
margin-top: auto;
|
margin-top: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.desktop-sidebar__credit {
|
.desktop-sidebar__credit {
|
||||||
margin-top: 12px;
|
flex-shrink: 0;
|
||||||
padding: 12px 8px 4px;
|
margin-top: 8px;
|
||||||
|
padding: 14px 10px 6px;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
width: 100%;
|
||||||
|
box-sizing: border-box;
|
||||||
|
border-top: 1px solid rgba(15, 23, 42, 0.08);
|
||||||
|
}
|
||||||
|
|
||||||
|
.desktop-sidebar--boursecu .desktop-sidebar__credit {
|
||||||
|
border-top-color: rgba(255, 255, 255, 0.12);
|
||||||
}
|
}
|
||||||
|
|
||||||
.desktop-sidebar__divider {
|
.desktop-sidebar__divider {
|
||||||
height: 1px;
|
height: 1px;
|
||||||
background: rgba(0, 0, 0, 0.08);
|
background: rgba(0, 0, 0, 0.08);
|
||||||
margin: 12px 8px;
|
margin: 12px 8px;
|
||||||
|
flex-shrink: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.desktop-nav-item {
|
.desktop-nav-item {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="mobile-app-layout">
|
<div class="mobile-app-layout">
|
||||||
<div :class="['main-with-bottom-chrome', { 'main-with-bottom-chrome--no-nav': hideMenu }]">
|
<div :class="['main-with-bottom-chrome', { 'main-with-bottom-chrome--no-nav': hideBottomNav }]">
|
||||||
<router-view v-slot="{ Component, route: activeRoute }">
|
<router-view v-slot="{ Component, route: activeRoute }">
|
||||||
<transition :name="activeRoute.meta.transition || 'fade'">
|
<transition :name="activeRoute.meta.transition || 'fade'">
|
||||||
<component :is="Component" :key="activeRoute.fullPath" class="main-with-bottom-chrome-inner" />
|
<component :is="Component" :key="activeRoute.fullPath" class="main-with-bottom-chrome-inner" />
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<MobileBottomNav
|
<MobileBottomNav
|
||||||
v-if="!hideMenu"
|
v-if="!hideBottomNav"
|
||||||
:nav-item-class="navItemClass"
|
:nav-item-class="navItemClass"
|
||||||
@navigate="navigateTo"
|
@navigate="navigateTo"
|
||||||
/>
|
/>
|
||||||
@@ -26,7 +26,7 @@ import MobileBottomNav from './MobileBottomNav.vue'
|
|||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
|
|
||||||
const {
|
const {
|
||||||
hideMenu,
|
hideBottomNav,
|
||||||
navItemClass,
|
navItemClass,
|
||||||
navigateTo,
|
navigateTo,
|
||||||
} = useAppNavigation()
|
} = useAppNavigation()
|
||||||
|
|||||||
@@ -77,15 +77,19 @@ html.app-layout--desktop {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Splash — always full viewport; never sidebar-offset */
|
/* Splash — always full viewport; never sidebar-offset or 426px mobile frame */
|
||||||
.app-splash-screen {
|
.app-splash-screen {
|
||||||
position: fixed;
|
position: fixed !important;
|
||||||
inset: 0;
|
inset: 0 !important;
|
||||||
width: 100vw;
|
width: 100vw !important;
|
||||||
min-height: 100vh;
|
min-width: 100vw !important;
|
||||||
max-width: none;
|
max-width: none !important;
|
||||||
|
min-height: 100vh !important;
|
||||||
|
min-height: 100dvh !important;
|
||||||
left: 0 !important;
|
left: 0 !important;
|
||||||
right: 0 !important;
|
right: 0 !important;
|
||||||
|
margin: 0 !important;
|
||||||
|
transform: none !important;
|
||||||
z-index: 1000000000000;
|
z-index: 1000000000000;
|
||||||
|
|
||||||
&__gradient {
|
&__gradient {
|
||||||
|
|||||||
@@ -83,6 +83,15 @@ html:not(.app-layout--desktop) {
|
|||||||
justify-content: center;
|
justify-content: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Prevent flex shrink-to-content: otherwise #app collapses and white
|
||||||
|
gutters appear beside splash/boot during refresh. */
|
||||||
|
#app {
|
||||||
|
width: 100% !important;
|
||||||
|
max-width: 100% !important;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
.desktopConfig {
|
.desktopConfig {
|
||||||
width: 426px !important;
|
width: 426px !important;
|
||||||
max-width: 426px !important;
|
max-width: 426px !important;
|
||||||
|
|||||||
@@ -2,24 +2,25 @@
|
|||||||
|
|
||||||
:root {
|
:root {
|
||||||
--mpage-header-bar: 2.75rem;
|
--mpage-header-bar: 2.75rem;
|
||||||
--mpage-header-offset: calc(4rem + var(--app-safe-top, env(safe-area-inset-top, 0px)));
|
/* وابسته به --app-safe-top تا با sync JS روی iOS درست بماند */
|
||||||
--mpage-subheader-offset: calc(var(--mpage-header-bar) + var(--app-safe-top, env(safe-area-inset-top, 0px)));
|
--mpage-header-offset: calc(4rem + var(--app-safe-top, 0px));
|
||||||
--mpage-content-with-subheader: calc(6.5rem + var(--app-safe-top, env(safe-area-inset-top, 0px)));
|
--mpage-subheader-offset: calc(var(--mpage-header-bar) + var(--app-safe-top, 0px));
|
||||||
--mpage-scroll-max-height: calc(100dvh - 50px - var(--app-safe-top, env(safe-area-inset-top, 0px)));
|
--mpage-content-with-subheader: calc(6.5rem + var(--app-safe-top, 0px));
|
||||||
--mobile-info-support-block: calc(5rem + var(--app-safe-bottom, env(safe-area-inset-bottom, 0px)));
|
--mpage-scroll-max-height: calc(100dvh - 50px - var(--app-safe-top, 0px));
|
||||||
|
--mobile-info-support-block: calc(5rem + var(--app-safe-bottom, 0px));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Fixed top bar: background fills under status bar; content sits below safe area */
|
/* Fixed top bar: background fills under status bar; content sits below safe area */
|
||||||
.mobile-top-chrome {
|
.mobile-top-chrome {
|
||||||
top: 0;
|
top: 0;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
padding-top: calc(0.75rem + var(--app-safe-top, env(safe-area-inset-top, 0px)));
|
padding-top: calc(0.75rem + var(--app-safe-top, 0px));
|
||||||
}
|
}
|
||||||
|
|
||||||
.mobile-top-chrome.h-12,
|
.mobile-top-chrome.h-12,
|
||||||
.mobile-top-chrome.min-h-12 {
|
.mobile-top-chrome.min-h-12 {
|
||||||
height: auto;
|
height: auto;
|
||||||
min-height: calc(3rem + var(--app-safe-top, env(safe-area-inset-top, 0px)));
|
min-height: calc(3rem + var(--app-safe-top, 0px));
|
||||||
}
|
}
|
||||||
|
|
||||||
.mpage-header {
|
.mpage-header {
|
||||||
@@ -29,7 +30,8 @@
|
|||||||
top: 0;
|
top: 0;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
padding: 0.75rem;
|
padding: 0.75rem;
|
||||||
padding-top: calc(0.75rem + var(--app-safe-top, env(safe-area-inset-top, 0px)));
|
padding-top: calc(0.75rem + var(--app-safe-top, 0px));
|
||||||
|
min-height: calc(2.75rem + var(--app-safe-top, 0px));
|
||||||
background: #fff;
|
background: #fff;
|
||||||
color: @App-primary-color;
|
color: @App-primary-color;
|
||||||
font-size: 1rem;
|
font-size: 1rem;
|
||||||
@@ -85,15 +87,15 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.mobile-page-body--pt10 {
|
.mobile-page-body--pt10 {
|
||||||
padding-top: calc(2.5rem + var(--app-safe-top, env(safe-area-inset-top, 0px)));
|
padding-top: calc(2.5rem + var(--app-safe-top, 0px));
|
||||||
}
|
}
|
||||||
|
|
||||||
.mobile-page-body--pt15 {
|
.mobile-page-body--pt15 {
|
||||||
padding-top: calc(3.75rem + var(--app-safe-top, env(safe-area-inset-top, 0px)));
|
padding-top: calc(3.75rem + var(--app-safe-top, 0px));
|
||||||
}
|
}
|
||||||
|
|
||||||
.mobile-page-body--pt20 {
|
.mobile-page-body--pt20 {
|
||||||
padding-top: calc(5rem + var(--app-safe-top, env(safe-area-inset-top, 0px)));
|
padding-top: calc(5rem + var(--app-safe-top, 0px));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Info pages (about, educate): fixed shell, scroll inside content box only */
|
/* Info pages (about, educate): fixed shell, scroll inside content box only */
|
||||||
|
|||||||
@@ -3,7 +3,10 @@ import './assets/css/main.less'
|
|||||||
import 'virtual:uno.css'
|
import 'virtual:uno.css'
|
||||||
import '@unocss/reset/tailwind-compat.css'
|
import '@unocss/reset/tailwind-compat.css'
|
||||||
|
|
||||||
import { initPwaInstallCapture } from '@/modules/pwa/manifest'
|
import { applyCachedPwaChromeEarly, initPwaInstallCapture } from '@/modules/pwa/manifest'
|
||||||
|
import { initPwaInstallPromptListener } from '@/modules/pwa/pwaInstall'
|
||||||
|
import { initSafeAreaInsets } from '@/utils/safeAreaInsets'
|
||||||
|
import { preloadLottieAssets } from '@/utils/lottieAssets'
|
||||||
import { bootstrapApp } from '@/app/bootstrap'
|
import { bootstrapApp } from '@/app/bootstrap'
|
||||||
|
|
||||||
export {
|
export {
|
||||||
@@ -12,5 +15,9 @@ export {
|
|||||||
setFingerPosition,
|
setFingerPosition,
|
||||||
} from '@/app/authBoot'
|
} from '@/app/authBoot'
|
||||||
|
|
||||||
|
initSafeAreaInsets()
|
||||||
initPwaInstallCapture()
|
initPwaInstallCapture()
|
||||||
|
applyCachedPwaChromeEarly()
|
||||||
|
initPwaInstallPromptListener()
|
||||||
|
void preloadLottieAssets()
|
||||||
void bootstrapApp()
|
void bootstrapApp()
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
export interface PriceTrigger {
|
export interface PriceTrigger {
|
||||||
id?: number
|
id?: number
|
||||||
|
product_id?: number
|
||||||
|
product?: { id: number; title?: string }
|
||||||
target_price: string
|
target_price: string
|
||||||
price_condition: string
|
price_condition: string
|
||||||
action: string
|
action: string
|
||||||
|
|||||||
@@ -1,16 +1,19 @@
|
|||||||
import type {Wallet} from '@/models/wallet';
|
import type {Wallet} from '@/models/wallet';
|
||||||
|
import type {Product} from '@/models/products';
|
||||||
|
|
||||||
export interface Fund {
|
export interface Fund {
|
||||||
id?: number,
|
id?: number,
|
||||||
title?: string,
|
title?: string,
|
||||||
file_id?: number,
|
file_id?: number,
|
||||||
customer_id?: number,
|
customer_id?: number,
|
||||||
|
product_id?: number,
|
||||||
created_at?: string,
|
created_at?: string,
|
||||||
updated_at?: string,
|
updated_at?: string,
|
||||||
deleted_at?: string,
|
deleted_at?: string,
|
||||||
wallet?: Wallet[] | Wallet
|
wallet?: Wallet[] | Wallet,
|
||||||
|
product?: Product,
|
||||||
}
|
}
|
||||||
export interface FundTransaction {
|
export interface FundTransaction {
|
||||||
fund_id?: number
|
fund_id?: number
|
||||||
value?: number
|
value?: number
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,4 +31,8 @@ export interface Price {
|
|||||||
time?: string
|
time?: string
|
||||||
main_product?: number
|
main_product?: number
|
||||||
montzar?: number
|
montzar?: number
|
||||||
|
zaarbox?: number
|
||||||
|
/** montzar | zaarbox | main_product | store = مظنه زنده، database_last = آخرین قیمت ذخیرهشده */
|
||||||
|
price_source?: string | null
|
||||||
|
last_historical?: number
|
||||||
}
|
}
|
||||||
@@ -52,6 +52,9 @@ export interface User {
|
|||||||
|
|
||||||
finger_print: boolean
|
finger_print: boolean
|
||||||
gold: number;
|
gold: number;
|
||||||
|
chat_room_id?: string | null
|
||||||
|
chat_user_id?: string | null
|
||||||
|
settings?: Array<{ key?: string; value?: string | number }>
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Login {
|
export interface Login {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ export interface Product {
|
|||||||
active: boolean
|
active: boolean
|
||||||
show: boolean
|
show: boolean
|
||||||
show_in_assets?: boolean
|
show_in_assets?: boolean
|
||||||
|
show_on_tv?: boolean
|
||||||
open_sell: boolean
|
open_sell: boolean
|
||||||
open_buy: boolean
|
open_buy: boolean
|
||||||
group_type:string
|
group_type:string
|
||||||
@@ -28,6 +29,8 @@ export interface Product {
|
|||||||
has_physical_delivery?: boolean
|
has_physical_delivery?: boolean
|
||||||
min_physical_delivery_quantity?: number | null
|
min_physical_delivery_quantity?: number | null
|
||||||
direct_price: number | undefined
|
direct_price: number | undefined
|
||||||
|
price_formula_enabled?: boolean | number | null
|
||||||
|
price_formula?: string | null
|
||||||
price_offset_percent?: number | null
|
price_offset_percent?: number | null
|
||||||
use_last_price_if_zero?: boolean
|
use_last_price_if_zero?: boolean
|
||||||
reference_provider_active?: boolean
|
reference_provider_active?: boolean
|
||||||
|
|||||||
@@ -0,0 +1,77 @@
|
|||||||
|
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[]
|
||||||
|
}
|
||||||
@@ -14,7 +14,7 @@ export interface Transaction {
|
|||||||
unit: string
|
unit: string
|
||||||
hash?: string
|
hash?: string
|
||||||
id?: number
|
id?: number
|
||||||
note?: null
|
note?: string | null
|
||||||
title: string
|
title: string
|
||||||
order_id?: number
|
order_id?: number
|
||||||
transaction_type?: string
|
transaction_type?: string
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ export type PwaManifest = {
|
|||||||
|
|
||||||
const MANIFEST_CACHE_KEY = 'PWA_MANIFEST_CACHE_V5'
|
const MANIFEST_CACHE_KEY = 'PWA_MANIFEST_CACHE_V5'
|
||||||
const MANIFEST_CACHE_MAX_AGE_MS = 60 * 60 * 24 * 7
|
const MANIFEST_CACHE_MAX_AGE_MS = 60 * 60 * 24 * 7
|
||||||
|
/** با اسکریپت inline در index.html هماهنگ بماند */
|
||||||
|
export const PWA_INSTALL_ICON_URL_KEY = 'PWA_INSTALL_ICON_URL'
|
||||||
|
|
||||||
export type CachedPwaManifest = {
|
export type CachedPwaManifest = {
|
||||||
cached_at: number
|
cached_at: number
|
||||||
@@ -69,4 +71,39 @@ export function writeCachedPwaManifest(entry: CachedPwaManifest) {
|
|||||||
|
|
||||||
export function clearCachedPwaManifest() {
|
export function clearCachedPwaManifest() {
|
||||||
localStorage.removeItem(MANIFEST_CACHE_KEY)
|
localStorage.removeItem(MANIFEST_CACHE_KEY)
|
||||||
|
try {
|
||||||
|
localStorage.removeItem(PWA_INSTALL_ICON_URL_KEY)
|
||||||
|
} catch {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function writeCachedPwaInstallIconUrl(src: string) {
|
||||||
|
try {
|
||||||
|
const value = String(src || '').trim()
|
||||||
|
if (!value) return
|
||||||
|
localStorage.setItem(PWA_INSTALL_ICON_URL_KEY, value)
|
||||||
|
} catch {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** برای گرمکردن آیکون نصب، بدون نیاز به userId / configBase */
|
||||||
|
export function readAnyFreshCachedPwaManifest(): CachedPwaManifest | null {
|
||||||
|
try {
|
||||||
|
const raw = localStorage.getItem(MANIFEST_CACHE_KEY)
|
||||||
|
if (!raw) return null
|
||||||
|
|
||||||
|
const payload = JSON.parse(raw) as CachedPwaManifest
|
||||||
|
if (!payload?.manifest || !payload.manifest_url) return null
|
||||||
|
if (!Array.isArray(payload.manifest.icons) || payload.manifest.icons.length === 0) return null
|
||||||
|
|
||||||
|
if (Date.now() - Number(payload.cached_at || 0) > MANIFEST_CACHE_MAX_AGE_MS) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
return payload
|
||||||
|
} catch {
|
||||||
|
return null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,16 @@
|
|||||||
import type { AppConfig } from '@/config/types'
|
import type { AppConfig } from '@/config/types'
|
||||||
import { getConfig, getRawAppConfig } from '@/config/app-config'
|
import { getConfig, getRawAppConfig } from '@/config/app-config'
|
||||||
import { getConfigUrls, sortConfigUrls } from '@/config/load-config'
|
import { getConfigUrls, sortConfigUrls } from '@/config/load-config'
|
||||||
|
import {
|
||||||
|
getSuperAdminBase,
|
||||||
|
isSuperAdminUrl,
|
||||||
|
resolveTenantDomain,
|
||||||
|
} from '@/config/superadmin'
|
||||||
import {
|
import {
|
||||||
clearCachedPwaManifest,
|
clearCachedPwaManifest,
|
||||||
|
readAnyFreshCachedPwaManifest,
|
||||||
readCachedPwaManifest,
|
readCachedPwaManifest,
|
||||||
|
writeCachedPwaInstallIconUrl,
|
||||||
writeCachedPwaManifest,
|
writeCachedPwaManifest,
|
||||||
type PwaManifest
|
type PwaManifest
|
||||||
} from '@/modules/pwa/manifest-cache'
|
} from '@/modules/pwa/manifest-cache'
|
||||||
@@ -22,8 +29,26 @@ function sleep(ms: number) {
|
|||||||
return new Promise((resolve) => window.setTimeout(resolve, ms))
|
return new Promise((resolve) => window.setTimeout(resolve, ms))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** پایهٔ سرور از URLهای get_user یا manifest — query مثل ?domain= را حذف میکند */
|
||||||
function normalizeBaseUrl(url: string) {
|
function normalizeBaseUrl(url: string) {
|
||||||
return url.replace(/\/get_user\/?$/i, '').replace(/\/+$/, '')
|
try {
|
||||||
|
const parsed = new URL(url)
|
||||||
|
parsed.search = ''
|
||||||
|
parsed.hash = ''
|
||||||
|
parsed.pathname = parsed.pathname
|
||||||
|
.replace(/\/get_user\/?$/i, '')
|
||||||
|
.replace(/\/manifest\.json$/i, '')
|
||||||
|
if (!parsed.pathname || parsed.pathname === '/') {
|
||||||
|
return parsed.origin
|
||||||
|
}
|
||||||
|
return `${parsed.origin}${parsed.pathname.replace(/\/+$/, '')}`
|
||||||
|
} catch {
|
||||||
|
return url
|
||||||
|
.replace(/[?#].*$/, '')
|
||||||
|
.replace(/\/get_user\/?$/i, '')
|
||||||
|
.replace(/\/manifest\.json$/i, '')
|
||||||
|
.replace(/\/+$/, '')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** همان baseای که get_user از آن لود شده (کش شده در localStorage) */
|
/** همان baseای که get_user از آن لود شده (کش شده در localStorage) */
|
||||||
@@ -33,15 +58,31 @@ export function getConfigBaseFromStorage() {
|
|||||||
return normalizeBaseUrl(lastSuccess)
|
return normalizeBaseUrl(lastSuccess)
|
||||||
}
|
}
|
||||||
|
|
||||||
function configUrlToManifestUrl(configUrl: string) {
|
function getSuperAdminManifestUrl(): string | null {
|
||||||
return `${configUrl.replace(/\/+$/, '')}/manifest.json`
|
const saBase = getSuperAdminBase()
|
||||||
|
if (!saBase) return null
|
||||||
|
return `${saBase}/manifest.json?domain=${encodeURIComponent(resolveTenantDomain())}`
|
||||||
}
|
}
|
||||||
|
|
||||||
/** همان ۵ URL پایهٔ get_user — اولویت با CONFIG_Success_URL */
|
function configUrlToManifestUrl(configUrl: string) {
|
||||||
|
if (isSuperAdminUrl(configUrl)) {
|
||||||
|
return getSuperAdminManifestUrl() || `${normalizeBaseUrl(configUrl)}/manifest.json`
|
||||||
|
}
|
||||||
|
return `${normalizeBaseUrl(configUrl)}/manifest.json`
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* اولویت: manifest_url صریح → سوپرادمین (با domain) → رجیستریهای قدیمی
|
||||||
|
*/
|
||||||
export function resolveManifestUrls(config?: AppConfig | null): string[] {
|
export function resolveManifestUrls(config?: AppConfig | null): string[] {
|
||||||
const explicit = getConfig<string>('manifest_url')
|
const explicit = getConfig<string>('manifest_url')
|
||||||
if (explicit) return [explicit]
|
if (explicit) return [explicit]
|
||||||
|
|
||||||
|
const saManifest = getSuperAdminManifestUrl()
|
||||||
|
if (saManifest) {
|
||||||
|
return [saManifest]
|
||||||
|
}
|
||||||
|
|
||||||
return sortConfigUrls(getConfigUrls()).map(configUrlToManifestUrl)
|
return sortConfigUrls(getConfigUrls()).map(configUrlToManifestUrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,8 +263,12 @@ function mapManifestIcons(manifest: PwaManifest, base: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** فقط آیکونهای داخل monifist.json — بدون آواتار / pwa-icons / env */
|
/** فقط آیکونهای داخل monifist.json — بدون آواتار / pwa-icons / env */
|
||||||
function resolveInstallIcons(manifest: PwaManifest) {
|
function resolveInstallIcons(manifest: PwaManifest, manifestUrl?: string) {
|
||||||
const base = getConfigBaseFromStorage()
|
const lastSuccess = localStorage.getItem(CONFIG_SUCCESS_URL_KEY) || ''
|
||||||
|
const fromManifest = manifestUrl ? normalizeBaseUrl(manifestUrl) : ''
|
||||||
|
const fromConfig =
|
||||||
|
lastSuccess && !isSuperAdminUrl(lastSuccess) ? getConfigBaseFromStorage() : ''
|
||||||
|
const base = fromManifest || fromConfig
|
||||||
const mapped = mapManifestIcons(manifest, base)
|
const mapped = mapManifestIcons(manifest, base)
|
||||||
|
|
||||||
if (!mapped.length) {
|
if (!mapped.length) {
|
||||||
@@ -235,10 +280,10 @@ function resolveInstallIcons(manifest: PwaManifest) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
function prepareManifestForInstall(manifest: PwaManifest) {
|
function prepareManifestForInstall(manifest: PwaManifest, manifestUrl?: string) {
|
||||||
const scopeUrl = toSameOriginManifestUrl(manifest.scope ?? manifest.start_url, '/')
|
const scopeUrl = toSameOriginManifestUrl(manifest.scope ?? manifest.start_url, '/')
|
||||||
const startUrl = toSameOriginManifestUrl(manifest.start_url, '/')
|
const startUrl = toSameOriginManifestUrl(manifest.start_url, '/')
|
||||||
const icons = resolveInstallIcons(manifest)
|
const icons = resolveInstallIcons(manifest, manifestUrl)
|
||||||
const name = manifest.short_name || manifest.name
|
const name = manifest.short_name || manifest.name
|
||||||
|
|
||||||
if (!name) {
|
if (!name) {
|
||||||
@@ -288,6 +333,60 @@ function pickManifestIconUrl(manifest: PwaManifest, preferredSizes: number[]) {
|
|||||||
return sorted[0]?.src || ''
|
return sorted[0]?.src || ''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const PWA_ICON_CACHE_NAME = 'pwa-install-icons-v1'
|
||||||
|
|
||||||
|
function uniqueIconSrcs(manifest: PwaManifest): string[] {
|
||||||
|
const seen = new Set<string>()
|
||||||
|
const urls: string[] = []
|
||||||
|
for (const icon of manifest.icons || []) {
|
||||||
|
const src = String(icon?.src || '').trim()
|
||||||
|
if (!src || seen.has(src)) continue
|
||||||
|
seen.add(src)
|
||||||
|
urls.push(src)
|
||||||
|
}
|
||||||
|
return urls
|
||||||
|
}
|
||||||
|
|
||||||
|
/** کش HTTP مرورگر — همان مسیری که شیت نصب iOS آیکون را میگیرد (نه blob) */
|
||||||
|
function warmIconInHttpCache(src: string) {
|
||||||
|
const img = new Image()
|
||||||
|
img.decoding = 'async'
|
||||||
|
img.src = src
|
||||||
|
void img.decode().catch(() => undefined)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function persistIconInCacheApi(src: string) {
|
||||||
|
if (typeof caches === 'undefined') return
|
||||||
|
|
||||||
|
try {
|
||||||
|
const cache = await caches.open(PWA_ICON_CACHE_NAME)
|
||||||
|
if (await cache.match(src)) return
|
||||||
|
|
||||||
|
const fetched = await fetch(src, {
|
||||||
|
method: 'GET',
|
||||||
|
mode: 'cors',
|
||||||
|
credentials: 'omit',
|
||||||
|
cache: 'force-cache',
|
||||||
|
priority: 'high',
|
||||||
|
} as RequestInit)
|
||||||
|
|
||||||
|
if (!fetched.ok) return
|
||||||
|
await cache.put(src, fetched)
|
||||||
|
} catch {
|
||||||
|
// بدون CORS یا سهمیه — Image() همچنان کش HTTP را گرم میکند
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function warmPwaInstallIcons(manifest: PwaManifest) {
|
||||||
|
const urls = uniqueIconSrcs(manifest)
|
||||||
|
if (!urls.length) return
|
||||||
|
|
||||||
|
urls.forEach((src) => {
|
||||||
|
warmIconInHttpCache(src)
|
||||||
|
void persistIconInCacheApi(src)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function upsertLink(rel: string, attrs: Record<string, string>) {
|
function upsertLink(rel: string, attrs: Record<string, string>) {
|
||||||
const selectorParts = Object.entries(attrs)
|
const selectorParts = Object.entries(attrs)
|
||||||
.filter(([key]) => key !== 'href')
|
.filter(([key]) => key !== 'href')
|
||||||
@@ -351,6 +450,7 @@ function applyAppleTouchIconsFromManifest(manifest: PwaManifest) {
|
|||||||
|
|
||||||
upsertLink('apple-touch-icon', {
|
upsertLink('apple-touch-icon', {
|
||||||
'data-dynamic-pwa': 'true',
|
'data-dynamic-pwa': 'true',
|
||||||
|
'data-pwa-icon-src': href,
|
||||||
sizes: `${size}x${size}`,
|
sizes: `${size}x${size}`,
|
||||||
href
|
href
|
||||||
})
|
})
|
||||||
@@ -359,8 +459,10 @@ function applyAppleTouchIconsFromManifest(manifest: PwaManifest) {
|
|||||||
const primary = pickManifestIconUrl(manifest, [180, 192, 512, 384])
|
const primary = pickManifestIconUrl(manifest, [180, 192, 512, 384])
|
||||||
|
|
||||||
if (primary) {
|
if (primary) {
|
||||||
|
writeCachedPwaInstallIconUrl(primary)
|
||||||
upsertLink('apple-touch-icon', {
|
upsertLink('apple-touch-icon', {
|
||||||
'data-dynamic-pwa': 'true',
|
'data-dynamic-pwa': 'true',
|
||||||
|
'data-pwa-icon-src': primary,
|
||||||
href: primary
|
href: primary
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -401,6 +503,7 @@ export async function applyPreparedManifestToDocument(
|
|||||||
upsertMeta('apple-mobile-web-app-title', title)
|
upsertMeta('apple-mobile-web-app-title', title)
|
||||||
upsertMeta('mobile-web-app-capable', 'yes')
|
upsertMeta('mobile-web-app-capable', 'yes')
|
||||||
upsertMeta('apple-mobile-web-app-capable', 'yes')
|
upsertMeta('apple-mobile-web-app-capable', 'yes')
|
||||||
|
upsertMeta('apple-mobile-web-app-status-bar-style', 'black-translucent')
|
||||||
|
|
||||||
applyAppleTouchIconsFromManifest(normalized)
|
applyAppleTouchIconsFromManifest(normalized)
|
||||||
|
|
||||||
@@ -409,12 +512,14 @@ export async function applyPreparedManifestToDocument(
|
|||||||
console.info('PWA manifest applied:', manifestUrl, `icons: ${normalized.icons.length}`)
|
console.info('PWA manifest applied:', manifestUrl, `icons: ${normalized.icons.length}`)
|
||||||
|
|
||||||
if (favicon) {
|
if (favicon) {
|
||||||
upsertLink('icon', { type: 'image/png', href: favicon })
|
upsertLink('icon', { type: 'image/png', href: favicon, 'data-pwa-icon-src': favicon })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
warmPwaInstallIcons(normalized)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function applyManifestToDocument(manifest: PwaManifest, manifestUrl: string) {
|
export async function applyManifestToDocument(manifest: PwaManifest, manifestUrl: string) {
|
||||||
const prepared = prepareManifestForInstall(manifest)
|
const prepared = prepareManifestForInstall(manifest, manifestUrl)
|
||||||
await applyPreparedManifestToDocument(prepared, manifestUrl)
|
await applyPreparedManifestToDocument(prepared, manifestUrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -430,6 +535,25 @@ export function isPwaManifestReady() {
|
|||||||
return sessionStorage.getItem(PWA_MANIFEST_READY_KEY) === '1'
|
return sessionStorage.getItem(PWA_MANIFEST_READY_KEY) === '1'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** کش مانیفست قبلی را همان اول بوت روی apple-touch-icon مینشاند و تصویر را گرم میکند */
|
||||||
|
export function applyCachedPwaChromeEarly() {
|
||||||
|
if (typeof window === 'undefined' || typeof document === 'undefined') return
|
||||||
|
|
||||||
|
const cached = readAnyFreshCachedPwaManifest()
|
||||||
|
if (!cached?.manifest) return
|
||||||
|
|
||||||
|
const apply = (manifest: PwaManifest) =>
|
||||||
|
applyPreparedManifestToDocument(manifest, cached.manifest_url).catch((error) => {
|
||||||
|
console.warn('Early PWA icon apply failed:', error)
|
||||||
|
})
|
||||||
|
|
||||||
|
try {
|
||||||
|
void apply(prepareManifestForInstall(cached.manifest, cached.manifest_url))
|
||||||
|
} catch {
|
||||||
|
void apply(cached.manifest)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** هرچه زودتر در main.ts — قبل از bootstrap */
|
/** هرچه زودتر در main.ts — قبل از bootstrap */
|
||||||
export function initPwaInstallCapture() {
|
export function initPwaInstallCapture() {
|
||||||
if (installCaptureInitialized || typeof window === 'undefined') return
|
if (installCaptureInitialized || typeof window === 'undefined') return
|
||||||
@@ -475,7 +599,7 @@ async function applyCachedManifestEntry(
|
|||||||
if (!cached) return false
|
if (!cached) return false
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const prepared = prepareManifestForInstall(cached.manifest)
|
const prepared = prepareManifestForInstall(cached.manifest, cached.manifest_url)
|
||||||
await applyPreparedManifestToDocument(prepared, cached.manifest_url)
|
await applyPreparedManifestToDocument(prepared, cached.manifest_url)
|
||||||
setPwaManifestReady(true)
|
setPwaManifestReady(true)
|
||||||
return true
|
return true
|
||||||
@@ -513,7 +637,7 @@ export async function setupPwaManifest(config?: AppConfig | null): Promise<boole
|
|||||||
try {
|
try {
|
||||||
const { manifest, manifestUrl } = await fetchManifestTryingUrls(manifestUrls)
|
const { manifest, manifestUrl } = await fetchManifestTryingUrls(manifestUrls)
|
||||||
|
|
||||||
const prepared = prepareManifestForInstall(manifest)
|
const prepared = prepareManifestForInstall(manifest, manifestUrl)
|
||||||
|
|
||||||
await applyPreparedManifestToDocument(prepared, manifestUrl)
|
await applyPreparedManifestToDocument(prepared, manifestUrl)
|
||||||
setPwaManifestReady(true)
|
setPwaManifestReady(true)
|
||||||
|
|||||||
@@ -0,0 +1,129 @@
|
|||||||
|
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
|
||||||
|
}
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
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
|
||||||
@@ -36,6 +36,7 @@ import {
|
|||||||
cancelVersionUpdateLock,
|
cancelVersionUpdateLock,
|
||||||
hardReloadApp
|
hardReloadApp
|
||||||
} from '@/config/config-cache'
|
} from '@/config/config-cache'
|
||||||
|
import { assertServerReachableConfig, isServerUnreachableConfig, isServerUnavailableError } from '@/utils/serverUnavailable'
|
||||||
|
|
||||||
const isUpdating = ref(false)
|
const isUpdating = ref(false)
|
||||||
const hasError = ref(false)
|
const hasError = ref(false)
|
||||||
@@ -86,6 +87,11 @@ async function startUpdate(version: string) {
|
|||||||
|
|
||||||
const freshConfig = await refreshConfigCacheForVersion(version, fetchFreshAppConfig)
|
const freshConfig = await refreshConfigCacheForVersion(version, fetchFreshAppConfig)
|
||||||
|
|
||||||
|
if (isServerUnreachableConfig(freshConfig)) {
|
||||||
|
assertServerReachableConfig(freshConfig)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
setAppConfig(freshConfig)
|
setAppConfig(freshConfig)
|
||||||
|
|
||||||
await wait(500)
|
await wait(500)
|
||||||
@@ -97,6 +103,11 @@ async function startUpdate(version: string) {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Version update failed:', error)
|
console.error('Version update failed:', error)
|
||||||
|
|
||||||
|
if (isServerUnavailableError(error)) {
|
||||||
|
cancelVersionUpdateLock()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (configBackup) {
|
if (configBackup) {
|
||||||
window.__APP_CONFIG__ = configBackup
|
window.__APP_CONFIG__ = configBackup
|
||||||
setAppConfig(configBackup)
|
setAppConfig(configBackup)
|
||||||
|
|||||||
@@ -8,6 +8,17 @@ const router = createRouter({
|
|||||||
name: 'login',
|
name: 'login',
|
||||||
component: () => import('../views/login/index.vue')
|
component: () => import('../views/login/index.vue')
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: `/tv`,
|
||||||
|
name: 'tvMonitor',
|
||||||
|
alias: ['/monitor'],
|
||||||
|
meta: {
|
||||||
|
public: true,
|
||||||
|
hideChrome: true,
|
||||||
|
hideMenu: true,
|
||||||
|
},
|
||||||
|
component: () => import('../views/tv/index.vue')
|
||||||
|
},
|
||||||
/* {
|
/* {
|
||||||
path: '/',
|
path: '/',
|
||||||
name: 'null',
|
name: 'null',
|
||||||
@@ -56,11 +67,22 @@ const router = createRouter({
|
|||||||
meta: {hideMenu: true},
|
meta: {hideMenu: true},
|
||||||
component: () => import('@/views/base/about/index.vue')
|
component: () => import('@/views/base/about/index.vue')
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: 'support',
|
||||||
|
name: 'support',
|
||||||
|
meta: { hideBottomNav: true },
|
||||||
|
component: () => import('@/views/support/index.vue')
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: 'notifyTrigger',
|
path: 'notifyTrigger',
|
||||||
name: 'notifyTrigger',
|
name: 'notifyTrigger',
|
||||||
component: () => import('@/views/base/priceTrigger/index.vue')
|
component: () => import('@/views/base/priceTrigger/index.vue')
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: 'appNotifications',
|
||||||
|
name: 'appNotifications',
|
||||||
|
component: () => import('@/views/base/appNotifications/index.vue')
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: 'address',
|
path: 'address',
|
||||||
name: 'address',
|
name: 'address',
|
||||||
@@ -106,6 +128,11 @@ const router = createRouter({
|
|||||||
name: 'giftCard',
|
name: 'giftCard',
|
||||||
component: () => import('@/views/base/giftCard/index.vue')
|
component: () => import('@/views/base/giftCard/index.vue')
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: 'recoverySites',
|
||||||
|
name: 'recoverySites',
|
||||||
|
component: () => import('@/views/base/recoverySites/index.vue')
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: 'fund',
|
path: 'fund',
|
||||||
name: 'fund',
|
name: 'fund',
|
||||||
@@ -122,6 +149,21 @@ const router = createRouter({
|
|||||||
name: 'fund_add',
|
name: 'fund_add',
|
||||||
component: () => import('@/views/base/fund/newFund/index.vue')
|
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')
|
||||||
|
},
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -129,6 +171,11 @@ const router = createRouter({
|
|||||||
name: 'aboutUs',
|
name: 'aboutUs',
|
||||||
component: () => import('@/views/base/aboutUs/index.vue')
|
component: () => import('@/views/base/aboutUs/index.vue')
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: '/about-software',
|
||||||
|
name: 'aboutSoftware',
|
||||||
|
component: () => import('@/views/base/aboutSoftware/index.vue')
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: '/:pathMatch(.*)*',
|
path: '/:pathMatch(.*)*',
|
||||||
name: 'notFound',
|
name: 'notFound',
|
||||||
|
|||||||
@@ -1,16 +1,18 @@
|
|||||||
import { type ComputedRef, ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
// import { get } from 'lodash'
|
import { defineStore } from 'pinia'
|
||||||
import {defineStore} from "pinia";
|
import { getFundTable } from '@/api/fund'
|
||||||
import {getMe} from "@/api/me";
|
import type { Fund } from '@/models/fund'
|
||||||
import {getFundTable} from "@/api/fund";
|
import type { TableOutput } from '@/models/table'
|
||||||
import type {Fund} from "@/models/fund";
|
|
||||||
import type {TableOutput} from "@/models/table";
|
|
||||||
import { getProductInventory } from '@/api/products'
|
import { getProductInventory } from '@/api/products'
|
||||||
|
|
||||||
export const useFundUserStore = defineStore('fund', () => {
|
export const useFundUserStore = defineStore('fund', () => {
|
||||||
|
/** داراییها / موجودی محصول (صفحهٔ /fund فعلی) */
|
||||||
const myFunds = ref<TableOutput<Fund> | undefined>(undefined)
|
const myFunds = ref<TableOutput<Fund> | undefined>(undefined)
|
||||||
|
/** قلکهای واقعی (مدل Fund) */
|
||||||
|
const myPiggyFunds = ref<TableOutput<Fund> | undefined>(undefined)
|
||||||
|
|
||||||
async function getMyFund() {
|
async function getMyFund() {
|
||||||
try {
|
try {
|
||||||
console.log('fff')
|
|
||||||
myFunds.value = await getProductInventory()
|
myFunds.value = await getProductInventory()
|
||||||
return myFunds.value
|
return myFunds.value
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -18,22 +20,14 @@ export const useFundUserStore = defineStore('fund', () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* const permissions: ComputedRef<string[]> = computed(() => {
|
async function getMyPiggyFunds() {
|
||||||
const permissions: string[] = get(userInfo.value, 'permission', [])
|
try {
|
||||||
const excludes: string[] = get(userInfo.value, 'exclude', [])
|
myPiggyFunds.value = await getFundTable()
|
||||||
return permissions.filter((item) => !excludes.includes(item))
|
return myPiggyFunds.value
|
||||||
})*/
|
} catch (e) {
|
||||||
|
console.log(e)
|
||||||
/*
|
}
|
||||||
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*/ }
|
return { getMyFund, getMyPiggyFunds, myFunds, myPiggyFunds }
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { computed, ref } from 'vue'
|
import { computed, ref } from 'vue'
|
||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
import { getSettings } from '@/api/configuration'
|
import { getSettings } from '@/api/configuration'
|
||||||
|
import { fetchSuperAdminProgramSettings, isLockedCanEdit } from '@/api/superadminSettings'
|
||||||
import { resolveMeltedGoldLabel, resolveMetalTypeLabel } from '@/utils/metalLabels'
|
import { resolveMeltedGoldLabel, resolveMetalTypeLabel } from '@/utils/metalLabels'
|
||||||
import { resolveTradeWeightUnit } from '@/utils/weightUnit'
|
import { resolveTradeWeightUnit } from '@/utils/weightUnit'
|
||||||
import { runOnceAsync } from '@/composables/useOnceAsync'
|
import { runOnceAsync } from '@/composables/useOnceAsync'
|
||||||
@@ -13,11 +14,13 @@ export interface AppSetting {
|
|||||||
description?: string
|
description?: string
|
||||||
is_active?: boolean
|
is_active?: boolean
|
||||||
type?: string
|
type?: string
|
||||||
|
can_edit?: number | boolean | string
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useSettingsStore = defineStore('settings', () => {
|
export const useSettingsStore = defineStore('settings', () => {
|
||||||
const settings = ref<AppSetting[]>([])
|
const settings = ref<AppSetting[]>([])
|
||||||
const loaded = ref(false)
|
const loaded = ref(false)
|
||||||
|
const settingsRevision = ref(0)
|
||||||
|
|
||||||
function getSettingByKey(key: string) {
|
function getSettingByKey(key: string) {
|
||||||
const item = settings.value.find((setting) => setting?.key === key)
|
const item = settings.value.find((setting) => setting?.key === key)
|
||||||
@@ -42,6 +45,7 @@ export const useSettingsStore = defineStore('settings', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const merged = [...settings.value]
|
const merged = [...settings.value]
|
||||||
|
let changed = false
|
||||||
items.forEach((item) => {
|
items.forEach((item) => {
|
||||||
if (!item?.key) {
|
if (!item?.key) {
|
||||||
return
|
return
|
||||||
@@ -49,27 +53,37 @@ export const useSettingsStore = defineStore('settings', () => {
|
|||||||
|
|
||||||
const index = merged.findIndex((setting) => setting.key === item.key)
|
const index = merged.findIndex((setting) => setting.key === item.key)
|
||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
merged[index] = { ...merged[index], ...item }
|
const current = merged[index]
|
||||||
} else {
|
if (current.value === item.value && current.is_active === item.is_active) {
|
||||||
merged.push(item)
|
return
|
||||||
|
}
|
||||||
|
merged[index] = { ...current, ...item }
|
||||||
|
changed = true
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
merged.push(item)
|
||||||
|
changed = true
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (!changed) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
settings.value = merged
|
settings.value = merged
|
||||||
|
settingsRevision.value += 1
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchSettings(force = false) {
|
async function fetchSettings(force = false) {
|
||||||
return runOnceAsync('settings:all', async () => {
|
return runOnceAsync('settings:all', async () => {
|
||||||
try {
|
const localRaw = await getSettings().catch(() => [])
|
||||||
const data = await getSettings()
|
const remote = await fetchSuperAdminProgramSettings()
|
||||||
if (Array.isArray(data)) {
|
const local = Array.isArray(localRaw) ? localRaw : []
|
||||||
mergeSettings(data)
|
const editable = local.filter((row) => !isLockedCanEdit(row?.can_edit))
|
||||||
}
|
settings.value = []
|
||||||
} catch (e) {
|
mergeSettings(remote)
|
||||||
console.log(e)
|
mergeSettings(editable)
|
||||||
} finally {
|
loaded.value = true
|
||||||
loaded.value = true
|
|
||||||
}
|
|
||||||
return settings.value
|
return settings.value
|
||||||
}, force)
|
}, force)
|
||||||
}
|
}
|
||||||
@@ -78,7 +92,14 @@ export const useSettingsStore = defineStore('settings', () => {
|
|||||||
const metalTypeLabel = computed(() => resolveMetalTypeLabel(metalTypeSettingValue.value))
|
const metalTypeLabel = computed(() => resolveMetalTypeLabel(metalTypeSettingValue.value))
|
||||||
const meltedGoldLabel = computed(() => resolveMeltedGoldLabel(metalTypeSettingValue.value))
|
const meltedGoldLabel = computed(() => resolveMeltedGoldLabel(metalTypeSettingValue.value))
|
||||||
const tradeWeightUnit = computed(() => resolveTradeWeightUnit(getSettingByKey('unit')))
|
const tradeWeightUnit = computed(() => resolveTradeWeightUnit(getSettingByKey('unit')))
|
||||||
|
const isReferralFieldVisible = computed(() => {
|
||||||
|
// کلید نباشد → نمایش (رفتار قبلی)
|
||||||
|
if (!settings.value?.some((s) => s?.key === 'referral_show')) return true
|
||||||
|
return isSettingTruthy('referral_show')
|
||||||
|
})
|
||||||
|
|
||||||
const isReferralRequired = computed(() => {
|
const isReferralRequired = computed(() => {
|
||||||
|
if (!isReferralFieldVisible.value) return false
|
||||||
const value = getSettingByKey('referral_id')
|
const value = getSettingByKey('referral_id')
|
||||||
return String(value ?? '').trim().toLowerCase() === 'required'
|
return String(value ?? '').trim().toLowerCase() === 'required'
|
||||||
})
|
})
|
||||||
@@ -86,11 +107,13 @@ export const useSettingsStore = defineStore('settings', () => {
|
|||||||
return {
|
return {
|
||||||
settings,
|
settings,
|
||||||
loaded,
|
loaded,
|
||||||
|
settingsRevision,
|
||||||
fetchSettings,
|
fetchSettings,
|
||||||
mergeSettings,
|
mergeSettings,
|
||||||
getSettingByKey,
|
getSettingByKey,
|
||||||
isSettingTruthy,
|
isSettingTruthy,
|
||||||
isReferralRequired,
|
isReferralRequired,
|
||||||
|
isReferralFieldVisible,
|
||||||
metalTypeSettingValue,
|
metalTypeSettingValue,
|
||||||
metalTypeLabel,
|
metalTypeLabel,
|
||||||
meltedGoldLabel,
|
meltedGoldLabel,
|
||||||
|
|||||||
@@ -28,11 +28,11 @@ export const useUserStore = defineStore('user', () => {
|
|||||||
console.log(e)
|
console.log(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function getValueByKey(keyName) {
|
function getValueByKey(keyName: string) {
|
||||||
const item = userInfo.value.settings?.find(obj => obj.key === keyName);
|
const item = userInfo.value?.settings?.find(obj => obj.key === keyName)
|
||||||
|
|
||||||
// اگر آیتم پیدا شد، فیلد value را برگردان، در غیر این صورت null
|
// اگر آیتم پیدا شد، فیلد value را برگردان، در غیر این صورت null
|
||||||
return item ? item.value : null;
|
return item ? item.value : null
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeInformation() {
|
function removeInformation() {
|
||||||
|
|||||||
@@ -1,7 +1,37 @@
|
|||||||
import { precacheAndRoute } from 'workbox-precaching'
|
import { precacheAndRoute } from 'workbox-precaching'
|
||||||
|
|
||||||
declare let self: ServiceWorkerGlobalScope
|
declare let self: ServiceWorkerGlobalScope
|
||||||
|
|
||||||
self.addEventListener('message', (event) => {
|
self.addEventListener('message', (event) => {
|
||||||
if (event.data && event.data.type === 'SKIP_WAITING') self.skipWaiting()
|
if (event.data && event.data.type === 'SKIP_WAITING') self.skipWaiting()
|
||||||
})
|
})
|
||||||
// self.__WB_MANIFEST is default injection point
|
|
||||||
|
self.addEventListener('notificationclick', (event) => {
|
||||||
|
event.notification.close()
|
||||||
|
const targetUrl = String(event.notification.data?.url || '/appNotifications')
|
||||||
|
|
||||||
|
event.waitUntil(
|
||||||
|
(async () => {
|
||||||
|
const allClients = await self.clients.matchAll({
|
||||||
|
type: 'window',
|
||||||
|
includeUncontrolled: true,
|
||||||
|
})
|
||||||
|
for (const client of allClients) {
|
||||||
|
if ('focus' in client) {
|
||||||
|
await client.focus()
|
||||||
|
if ('navigate' in client) {
|
||||||
|
try {
|
||||||
|
await (client as WindowClient).navigate(targetUrl)
|
||||||
|
} catch {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await self.clients.openWindow(targetUrl)
|
||||||
|
})(),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
precacheAndRoute(self.__WB_MANIFEST)
|
precacheAndRoute(self.__WB_MANIFEST)
|
||||||
|
|||||||
@@ -0,0 +1,165 @@
|
|||||||
|
/** نوتیف مرورگر بدون 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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,6 +24,11 @@ export function isBoursecuProject() {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** فقط برای سازگاری با منطق پشتیبانی modular — در boursecu همیشه false */
|
||||||
|
export function isBazretalaProject() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
const WALLET_DEPOSIT_QUICK_AMOUNTS_RIAL = [10_000_000, 50_000_000, 100_000_000] as const
|
const WALLET_DEPOSIT_QUICK_AMOUNTS_RIAL = [10_000_000, 50_000_000, 100_000_000] as const
|
||||||
|
|
||||||
export function getWalletDepositQuickAmountsRial(): readonly number[] {
|
export function getWalletDepositQuickAmountsRial(): readonly number[] {
|
||||||
|
|||||||
@@ -0,0 +1,215 @@
|
|||||||
|
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
|
||||||
|
accountNumber?: 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 ACCOUNT_PLACEHOLDER_RE = /[%٪]\s*حساب(?:\s*[%٪])?/gu
|
||||||
|
const SHEBA_PLACEHOLDER_RE = /[%٪]\s*شبا(?:\s*[%٪])?/gu
|
||||||
|
|
||||||
|
export function getCustomerNameFromUser(): string {
|
||||||
|
try {
|
||||||
|
return String(useUserStore().userInfo?.name ?? '').trim()
|
||||||
|
} 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 accountNumber = String(vars.accountNumber ?? '').trim()
|
||||||
|
const sheba = String(vars.sheba ?? '').trim()
|
||||||
|
|
||||||
|
return template
|
||||||
|
.replace(SHEBA_PLACEHOLDER_RE, sheba)
|
||||||
|
.replace(ACCOUNT_PLACEHOLDER_RE, accountNumber)
|
||||||
|
.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'),
|
||||||
|
cardNumber: store.getSettingByKey('deposit_card_number'),
|
||||||
|
accountNumber: store.getSettingByKey('deposit_account_number'),
|
||||||
|
sheba: store.getSettingByKey('deposit_sheba'),
|
||||||
|
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 formatDepositAccountNumber(value?: string | null) {
|
||||||
|
const digits = String(value ?? '').replace(/\D/g, '')
|
||||||
|
if (!digits) return String(value ?? '').trim()
|
||||||
|
return digits
|
||||||
|
}
|
||||||
|
|
||||||
|
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 displayDepositAccountNumber(value?: string | null) {
|
||||||
|
return formatDepositAccountNumber(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' | 'account' | '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, '') || normalized
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function copyDepositFieldValue(
|
||||||
|
value: string | null | undefined,
|
||||||
|
kind: 'card' | 'account' | '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('کپی انجام نشد')
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,28 +8,83 @@ export interface ProductFile {
|
|||||||
full_src?: string
|
full_src?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function projectBase(): string {
|
||||||
|
return resolveProjectBase().replace(/\/$/, '')
|
||||||
|
}
|
||||||
|
|
||||||
|
function storageRelativePath(value: string): string | null {
|
||||||
|
const match = value.match(/(?:^|\/)(storage\/.+)$/i)
|
||||||
|
return match ? match[1].replace(/^\/+/, '') : null
|
||||||
|
}
|
||||||
|
|
||||||
|
function joinProjectUrl(relative: string): string {
|
||||||
|
const path = relative.replace(/^\//, '')
|
||||||
|
let base = projectBase()
|
||||||
|
if (!base && typeof window !== 'undefined') {
|
||||||
|
base = `${window.location.origin}/server`
|
||||||
|
}
|
||||||
|
if (!base) {
|
||||||
|
return `/server/${path}`
|
||||||
|
}
|
||||||
|
base = base.replace(/\/$/, '')
|
||||||
|
if (path.startsWith('storage/') && !/\/(server|api)(\/|$)/i.test(base)) {
|
||||||
|
base = `${base}/server`
|
||||||
|
}
|
||||||
|
let url = `${base}/${path}`
|
||||||
|
if (typeof window !== 'undefined' && window.location.protocol === 'https:') {
|
||||||
|
url = url.replace(/^http:\/\//i, 'https://')
|
||||||
|
}
|
||||||
|
return url
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* URL فایل روی API — مسیرهای `storage/` و آدرسهای localhost/http
|
||||||
|
* را به `node_server` میچسباند تا روی اندروید (PWA/TWA) لود شوند.
|
||||||
|
*/
|
||||||
|
export function normalizePublicFileUrl(raw?: string | null): string | null {
|
||||||
|
if (raw == null) return null
|
||||||
|
const trimmed = String(raw).trim()
|
||||||
|
if (!trimmed || trimmed.toLowerCase() === 'null' || trimmed.toLowerCase() === 'undefined') {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
if (/^(data:|blob:)/i.test(trimmed)) return trimmed
|
||||||
|
|
||||||
|
const storagePath = storageRelativePath(trimmed)
|
||||||
|
if (storagePath) {
|
||||||
|
return joinProjectUrl(storagePath)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (/^https?:\/\//i.test(trimmed)) {
|
||||||
|
if (typeof window !== 'undefined' && window.location.protocol === 'https:') {
|
||||||
|
return trimmed.replace(/^http:\/\//i, 'https://')
|
||||||
|
}
|
||||||
|
return trimmed
|
||||||
|
}
|
||||||
|
|
||||||
|
return joinProjectUrl(trimmed)
|
||||||
|
}
|
||||||
|
|
||||||
export function getFileUrl(file?: ProductFile | null): string | null {
|
export function getFileUrl(file?: ProductFile | null): string | null {
|
||||||
if (!file) return null
|
if (!file) return null
|
||||||
|
|
||||||
for (const value of [file.full_src, file.url, file.src]) {
|
for (const value of [file.full_src, file.url, file.src]) {
|
||||||
if (!value) continue
|
if (!value) continue
|
||||||
if (/^https?:\/\//i.test(value)) return value
|
const normalized = normalizePublicFileUrl(value)
|
||||||
|
if (normalized) return normalized
|
||||||
}
|
}
|
||||||
|
|
||||||
const relative = file.src || file.full_src
|
return null
|
||||||
if (!relative) return null
|
|
||||||
|
|
||||||
const base = resolveProjectBase().replace(/\/$/, '')
|
|
||||||
if (!base) return relative.startsWith('/') ? relative : `/${relative}`
|
|
||||||
const path = String(relative).replace(/^\//, '')
|
|
||||||
return `${base}/${path}`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Resolve profile avatar URL from GET /customer/me payload */
|
/** Resolve profile avatar URL from GET /customer/me payload */
|
||||||
export function getUserAvatarUrl(user?: User | null): string | null {
|
export function getUserAvatarUrl(user?: User | null): string | null {
|
||||||
if (!user) return null
|
if (!user) return null
|
||||||
if (typeof user.avatar_url === 'string' && user.avatar_url) return user.avatar_url
|
if (typeof user.avatar_url === 'string' && user.avatar_url) {
|
||||||
if (typeof user.full_src === 'string' && user.full_src) return user.full_src
|
return normalizePublicFileUrl(user.avatar_url)
|
||||||
|
}
|
||||||
|
if (typeof user.full_src === 'string' && user.full_src) {
|
||||||
|
return normalizePublicFileUrl(user.full_src)
|
||||||
|
}
|
||||||
const nested = user.avatar || user.file
|
const nested = user.avatar || user.file
|
||||||
return getFileUrl(nested as ProductFile | undefined)
|
return getFileUrl(nested as ProductFile | undefined)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -122,6 +122,27 @@ function isIphone() {
|
|||||||
return /iPhone/.test(userAgent)
|
return /iPhone/.test(userAgent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
export {
|
||||||
getToken,
|
getToken,
|
||||||
setToken,
|
setToken,
|
||||||
@@ -131,5 +152,6 @@ export {
|
|||||||
isIphone,
|
isIphone,
|
||||||
removeFingerPrint,
|
removeFingerPrint,
|
||||||
getIsActiveFingerprint,
|
getIsActiveFingerprint,
|
||||||
setFingerPrint
|
setFingerPrint,
|
||||||
|
createUuid
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
/** Lottieهای لوکال (`public/lottie`) — پیشدانلود تا مودال/لیست خالی نماند */
|
||||||
|
|
||||||
|
const LOTTIE_FILES = {
|
||||||
|
logoutConfirm: 'lottie/logoutConfirm.json',
|
||||||
|
emptyList: 'lottie/emptyList.json',
|
||||||
|
goldBars: 'lottie/goldBars.json',
|
||||||
|
} as const
|
||||||
|
|
||||||
|
export type LottieAssetKey = keyof typeof LOTTIE_FILES
|
||||||
|
|
||||||
|
const cache = new Map<LottieAssetKey, string>()
|
||||||
|
|
||||||
|
export function lottieSrc(key: LottieAssetKey): string {
|
||||||
|
const base = import.meta.env.BASE_URL || '/'
|
||||||
|
const path = `${base}${LOTTIE_FILES[key]}`
|
||||||
|
return path.replace(/([^:]\/)\/+/g, '$1')
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getLottieData(key: LottieAssetKey): string | undefined {
|
||||||
|
return cache.get(key)
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function preloadLottieAssets(): Promise<void> {
|
||||||
|
const keys = Object.keys(LOTTIE_FILES) as LottieAssetKey[]
|
||||||
|
await Promise.all(
|
||||||
|
keys.map(async (key) => {
|
||||||
|
if (cache.has(key)) return
|
||||||
|
try {
|
||||||
|
const res = await fetch(lottieSrc(key))
|
||||||
|
if (!res.ok) return
|
||||||
|
cache.set(key, await res.text())
|
||||||
|
} catch {
|
||||||
|
/* شبکه/آفلاین — بعداً از src لوکال میخواند */
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,176 @@
|
|||||||
|
const MOBILE_MEDIA = '(max-width: 767.98px)'
|
||||||
|
const KEYBOARD_GAP_PX = 16
|
||||||
|
const SCROLL_RETRY_MS = [0, 90, 220, 420, 640]
|
||||||
|
|
||||||
|
let started = false
|
||||||
|
let activeField: HTMLElement | null = null
|
||||||
|
let blurTimer = 0
|
||||||
|
|
||||||
|
function isMobileLayout(): boolean {
|
||||||
|
return window.matchMedia(MOBILE_MEDIA).matches
|
||||||
|
}
|
||||||
|
|
||||||
|
function getKeyboardInset(): number {
|
||||||
|
const vv = window.visualViewport
|
||||||
|
if (!vv) return 0
|
||||||
|
return Math.max(0, Math.round(window.innerHeight - vv.height - vv.offsetTop))
|
||||||
|
}
|
||||||
|
|
||||||
|
function getVisibleViewportBottom(): number {
|
||||||
|
const vv = window.visualViewport
|
||||||
|
return vv ? vv.offsetTop + vv.height : window.innerHeight
|
||||||
|
}
|
||||||
|
|
||||||
|
function syncViewportVars(hasFocusedField: boolean) {
|
||||||
|
const vv = window.visualViewport
|
||||||
|
const inset = getKeyboardInset()
|
||||||
|
|
||||||
|
document.documentElement.style.setProperty('--app-keyboard-inset', `${inset}px`)
|
||||||
|
|
||||||
|
if (vv) {
|
||||||
|
document.documentElement.style.setProperty('--app-visual-viewport-height', `${Math.round(vv.height)}px`)
|
||||||
|
document.documentElement.style.setProperty('--app-visual-viewport-offset-top', `${Math.round(vv.offsetTop)}px`)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasFocusedField && inset > 0) {
|
||||||
|
document.documentElement.dataset.keyboardOpen = 'true'
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!hasFocusedField) {
|
||||||
|
delete document.documentElement.dataset.keyboardOpen
|
||||||
|
document.documentElement.style.setProperty('--app-keyboard-inset', '0px')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function resolveEditableTarget(node: EventTarget | null): HTMLElement | null {
|
||||||
|
if (!(node instanceof HTMLElement)) return null
|
||||||
|
|
||||||
|
const field = node.closest('input, textarea, select, [contenteditable="true"]')
|
||||||
|
if (!(field instanceof HTMLElement)) return null
|
||||||
|
|
||||||
|
if (field instanceof HTMLInputElement) {
|
||||||
|
if (field.disabled || field.readOnly || field.type === 'hidden') return null
|
||||||
|
}
|
||||||
|
|
||||||
|
if (field instanceof HTMLTextAreaElement) {
|
||||||
|
if (field.disabled || field.readOnly) return null
|
||||||
|
}
|
||||||
|
|
||||||
|
if (field instanceof HTMLSelectElement && field.disabled) return null
|
||||||
|
|
||||||
|
return field
|
||||||
|
}
|
||||||
|
|
||||||
|
function findScrollableAncestor(el: HTMLElement): HTMLElement | null {
|
||||||
|
let node: HTMLElement | null = el.parentElement
|
||||||
|
|
||||||
|
while (node && node !== document.body && node !== document.documentElement) {
|
||||||
|
const style = window.getComputedStyle(node)
|
||||||
|
const overflowY = style.overflowY
|
||||||
|
const scrollable = overflowY === 'auto' || overflowY === 'scroll' || overflowY === 'overlay'
|
||||||
|
|
||||||
|
if (scrollable && node.scrollHeight > node.clientHeight + 1) {
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
node = node.parentElement
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
function ensureFieldVisible(field: HTMLElement) {
|
||||||
|
if (!isMobileLayout()) return
|
||||||
|
|
||||||
|
syncViewportVars(true)
|
||||||
|
|
||||||
|
const rect = field.getBoundingClientRect()
|
||||||
|
const visibleBottom = getVisibleViewportBottom() - KEYBOARD_GAP_PX
|
||||||
|
const scrollParent = findScrollableAncestor(field)
|
||||||
|
|
||||||
|
if (rect.bottom > visibleBottom) {
|
||||||
|
const delta = rect.bottom - visibleBottom
|
||||||
|
if (scrollParent) {
|
||||||
|
scrollParent.scrollTop += delta
|
||||||
|
} else {
|
||||||
|
window.scrollBy({ top: delta, left: 0, behavior: 'auto' })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rect.top < KEYBOARD_GAP_PX && scrollParent) {
|
||||||
|
scrollParent.scrollTop += rect.top - KEYBOARD_GAP_PX
|
||||||
|
}
|
||||||
|
|
||||||
|
field.scrollIntoView({ block: 'nearest', inline: 'nearest', behavior: 'auto' })
|
||||||
|
}
|
||||||
|
|
||||||
|
function scheduleEnsureVisible(field: HTMLElement) {
|
||||||
|
SCROLL_RETRY_MS.forEach((delay) => {
|
||||||
|
window.setTimeout(() => {
|
||||||
|
const active = resolveEditableTarget(document.activeElement)
|
||||||
|
if (!active || active !== field) return
|
||||||
|
ensureFieldVisible(field)
|
||||||
|
}, delay)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function onFocusIn(event: FocusEvent) {
|
||||||
|
if (!isMobileLayout()) return
|
||||||
|
|
||||||
|
const field = resolveEditableTarget(event.target)
|
||||||
|
if (!field) return
|
||||||
|
|
||||||
|
activeField = field
|
||||||
|
window.clearTimeout(blurTimer)
|
||||||
|
scheduleEnsureVisible(field)
|
||||||
|
}
|
||||||
|
|
||||||
|
function onFocusOut() {
|
||||||
|
window.clearTimeout(blurTimer)
|
||||||
|
blurTimer = window.setTimeout(() => {
|
||||||
|
const next = resolveEditableTarget(document.activeElement)
|
||||||
|
activeField = next
|
||||||
|
|
||||||
|
if (!next) {
|
||||||
|
syncViewportVars(false)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
syncViewportVars(true)
|
||||||
|
scheduleEnsureVisible(next)
|
||||||
|
}, 120)
|
||||||
|
}
|
||||||
|
|
||||||
|
function onViewportChange() {
|
||||||
|
if (!isMobileLayout()) return
|
||||||
|
|
||||||
|
syncViewportVars(Boolean(activeField))
|
||||||
|
|
||||||
|
const active = resolveEditableTarget(document.activeElement) ?? activeField
|
||||||
|
if (!active) return
|
||||||
|
|
||||||
|
activeField = active
|
||||||
|
ensureFieldVisible(active)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** موبایل: با باز شدن کیبورد، فیلد فوکوسشده بالای کیبورد دیده شود. */
|
||||||
|
export function initMobileInputKeyboardScroll() {
|
||||||
|
if (typeof window === 'undefined' || started) return
|
||||||
|
started = true
|
||||||
|
|
||||||
|
document.addEventListener('focusin', onFocusIn, true)
|
||||||
|
document.addEventListener('focusout', onFocusOut, true)
|
||||||
|
window.visualViewport?.addEventListener('resize', onViewportChange, { passive: true })
|
||||||
|
window.visualViewport?.addEventListener('scroll', onViewportChange, { passive: true })
|
||||||
|
|
||||||
|
if (import.meta.hot) {
|
||||||
|
import.meta.hot.dispose(() => {
|
||||||
|
started = false
|
||||||
|
document.removeEventListener('focusin', onFocusIn, true)
|
||||||
|
document.removeEventListener('focusout', onFocusOut, true)
|
||||||
|
window.visualViewport?.removeEventListener('resize', onViewportChange)
|
||||||
|
window.visualViewport?.removeEventListener('scroll', onViewportChange)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,18 +13,68 @@ export function persianToEnglishDigits(value: string | number | null | undefined
|
|||||||
.replace(/٫/g, '.')
|
.replace(/٫/g, '.')
|
||||||
}
|
}
|
||||||
|
|
||||||
export function shouldNormalizeInputDigits(options: {
|
/**
|
||||||
|
* اعداد فارسی/عربی + جداکنندههای اعشار رایج ماشینحساب فارسی.
|
||||||
|
* - `slashAsDecimal` پیشفرض true: `/` → `.`
|
||||||
|
* - `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
|
isPassword?: boolean
|
||||||
type?: string
|
type?: string
|
||||||
inputmode?: string
|
inputmode?: string
|
||||||
}): boolean {
|
}): boolean {
|
||||||
if (options.isPassword) {
|
// همیشه ارقام فارسی/عربی → انگلیسی (لاگین، گرم، تعداد، مظنه، …)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** فیلدهای وزن/مبلغ/عدد اعشاری که باید `/` را ممیز بگیرند */
|
||||||
|
export function shouldNormalizeDecimalSeparators(options: {
|
||||||
|
isPassword?: boolean
|
||||||
|
type?: string
|
||||||
|
inputmode?: string
|
||||||
|
}): boolean {
|
||||||
|
if (options.isPassword) return false
|
||||||
const type = String(options.type ?? '').trim().toLowerCase()
|
const type = String(options.type ?? '').trim().toLowerCase()
|
||||||
if (type === 'price' || type === 'number' || type === 'tel') {
|
if (type === 'price' || type === 'number') return true
|
||||||
return true
|
|
||||||
}
|
|
||||||
const mode = String(options.inputmode ?? '').trim().toLowerCase()
|
const mode = String(options.inputmode ?? '').trim().toLowerCase()
|
||||||
return mode === 'numeric' || mode === 'decimal' || mode === 'number'
|
return mode === 'numeric' || mode === 'decimal' || mode === 'number'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import {
|
|||||||
priceWssEnabled,
|
priceWssEnabled,
|
||||||
shouldUsePricePolling,
|
shouldUsePricePolling,
|
||||||
} from '@/utils/priceSocketState'
|
} from '@/utils/priceSocketState'
|
||||||
|
import { applyBoardSpecialToLastPayload } from '@/utils/specialPricing'
|
||||||
|
import { useSettingsStore, type AppSetting } from '@/store/settingsStore'
|
||||||
|
|
||||||
const LAST_INTERVAL_MS = 10000
|
const LAST_INTERVAL_MS = 10000
|
||||||
|
|
||||||
@@ -16,10 +18,21 @@ let lastSubscribers = 0
|
|||||||
/** @deprecated از lastPrice استفاده کنید — برای سازگاری با کد قدیمی sync میشود */
|
/** @deprecated از lastPrice استفاده کنید — برای سازگاری با کد قدیمی sync میشود */
|
||||||
export const price = ref<Price>()
|
export const price = ref<Price>()
|
||||||
export const lastPrice = ref<Price>()
|
export const lastPrice = ref<Price>()
|
||||||
|
/** حداقل یک بار تلاش برای گرفتن مظنه تمام شده (موفق یا ناموفق) */
|
||||||
|
export const lastPriceReady = ref(false)
|
||||||
|
/**
|
||||||
|
* بعد از اولین پاسخ خالی/no_quote، چند لحظه صبر میکنیم تا تیک SSE/زنده برسد
|
||||||
|
* و «مظنه در دسترس نیست» زودهنگام نشان داده نشود.
|
||||||
|
*/
|
||||||
|
export const lastPriceSettleGeneration = ref(0)
|
||||||
export const olderPrice = ref<number | undefined>(0)
|
export const olderPrice = ref<number | undefined>(0)
|
||||||
|
|
||||||
|
const QUOTE_ABSENCE_SETTLE_MS = 2500
|
||||||
|
|
||||||
let lastPriceSourceAt = 0
|
let lastPriceSourceAt = 0
|
||||||
let consecutivePriceFetchFailures = 0
|
let consecutivePriceFetchFailures = 0
|
||||||
|
let lastPriceReadyAt = 0
|
||||||
|
let quoteSettleTimer: ReturnType<typeof setTimeout> | undefined
|
||||||
|
|
||||||
function hasValidPricePayload(data?: Price | null): boolean {
|
function hasValidPricePayload(data?: Price | null): boolean {
|
||||||
if (!data) {
|
if (!data) {
|
||||||
@@ -33,13 +46,77 @@ function hasValidPricePayload(data?: Price | null): boolean {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function applyTradingHoursSettingsPatch(data: unknown) {
|
||||||
|
if (!data || typeof data !== 'object') {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const patch = (data as { settings_patch?: unknown }).settings_patch
|
||||||
|
if (!Array.isArray(patch) || patch.length === 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
useSettingsStore().mergeSettings(patch as AppSetting[])
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearQuoteSettleTimer() {
|
||||||
|
if (quoteSettleTimer) {
|
||||||
|
clearTimeout(quoteSettleTimer)
|
||||||
|
quoteSettleTimer = undefined
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function bumpQuoteSettle() {
|
||||||
|
lastPriceSettleGeneration.value += 1
|
||||||
|
}
|
||||||
|
|
||||||
|
function scheduleQuoteAbsenceSettle() {
|
||||||
|
clearQuoteSettleTimer()
|
||||||
|
if (hasValidPricePayload(lastPrice.value) || lastPrice.value?.status === 'closed') {
|
||||||
|
bumpQuoteSettle()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const elapsed = lastPriceReadyAt > 0 ? Date.now() - lastPriceReadyAt : 0
|
||||||
|
const wait = Math.max(0, QUOTE_ABSENCE_SETTLE_MS - elapsed)
|
||||||
|
quoteSettleTimer = setTimeout(() => {
|
||||||
|
quoteSettleTimer = undefined
|
||||||
|
bumpQuoteSettle()
|
||||||
|
}, wait)
|
||||||
|
}
|
||||||
|
|
||||||
|
function markLastPriceReady() {
|
||||||
|
if (!lastPriceReady.value) {
|
||||||
|
lastPriceReadyAt = Date.now()
|
||||||
|
}
|
||||||
|
lastPriceReady.value = true
|
||||||
|
scheduleQuoteAbsenceSettle()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** قیمت آمده، بسته قطعی است، یا پنجرهٔ انتظارِ مظنه خالی تمام شده */
|
||||||
|
export function isLastPriceAbsenceSettled(): boolean {
|
||||||
|
void lastPriceSettleGeneration.value
|
||||||
|
if (!lastPriceReady.value) return false
|
||||||
|
if (hasValidPricePayload(lastPrice.value)) return true
|
||||||
|
if (lastPrice.value?.status === 'closed') return true
|
||||||
|
if (lastPriceReadyAt <= 0) return false
|
||||||
|
return Date.now() - lastPriceReadyAt >= QUOTE_ABSENCE_SETTLE_MS
|
||||||
|
}
|
||||||
|
|
||||||
export function markPriceSourceReceived() {
|
export function markPriceSourceReceived() {
|
||||||
lastPriceSourceAt = Date.now()
|
lastPriceSourceAt = Date.now()
|
||||||
consecutivePriceFetchFailures = 0
|
consecutivePriceFetchFailures = 0
|
||||||
|
void import('@/utils/priceSocket').then(({ clearPriceNetworkAlert }) => {
|
||||||
|
clearPriceNetworkAlert()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export function markPriceSourceFetchFailed() {
|
export function markPriceSourceFetchFailed() {
|
||||||
consecutivePriceFetchFailures += 1
|
consecutivePriceFetchFailures += 1
|
||||||
|
if (consecutivePriceFetchFailures >= 2) {
|
||||||
|
void import('@/utils/priceSocket').then(({ notifyPriceLastFetchFailed }) => {
|
||||||
|
notifyPriceLastFetchFailed()
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function hasRecentPriceFromSource(maxAgeMs = 45000): boolean {
|
export function hasRecentPriceFromSource(maxAgeMs = 45000): boolean {
|
||||||
@@ -163,18 +240,38 @@ export async function getLastPrices(): Promise<boolean> {
|
|||||||
console.log(e)
|
console.log(e)
|
||||||
markPriceSourceFetchFailed()
|
markPriceSourceFetchFailed()
|
||||||
return false
|
return false
|
||||||
|
} finally {
|
||||||
|
markLastPriceReady()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function applyLastPricePayload(dataLast: Price) {
|
export function applyLastPricePayload(dataLast: Price) {
|
||||||
const normalized = normalizePriceResponse(dataLast)
|
applyTradingHoursSettingsPatch(dataLast)
|
||||||
if (lastPrice.value?.price_last != normalized.price_last) {
|
const normalized = normalizePriceResponse(
|
||||||
|
applyBoardSpecialToLastPayload(dataLast as Record<string, unknown>) as Price,
|
||||||
|
)
|
||||||
|
const nextBuy = getTradeBuyPrice(normalized)
|
||||||
|
const prevBuy = getTradeBuyPrice(lastPrice.value)
|
||||||
|
const nextValid = hasValidPricePayload(normalized)
|
||||||
|
const prevValid = hasValidPricePayload(lastPrice.value)
|
||||||
|
|
||||||
|
// قطع فید / no_quote خالی — قیمت فعلی را پاک نکن؛ فقط closed قطعی اجازهٔ صفر شدن دارد
|
||||||
|
if (!nextValid && prevValid && normalized.status !== 'closed') {
|
||||||
|
markLastPriceReady()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (prevBuy > 0 && nextBuy > 0 && prevBuy !== nextBuy) {
|
||||||
|
olderPrice.value = prevBuy
|
||||||
|
} else if (lastPrice.value?.price_last != normalized.price_last) {
|
||||||
olderPrice.value = lastPrice.value?.price_last
|
olderPrice.value = lastPrice.value?.price_last
|
||||||
}
|
}
|
||||||
|
|
||||||
lastPrice.value = normalized
|
lastPrice.value = normalized
|
||||||
|
markLastPriceReady()
|
||||||
price.value = {
|
price.value = {
|
||||||
...normalized,
|
...normalized,
|
||||||
buy: getTradeBuyPrice(normalized),
|
buy: nextBuy,
|
||||||
sell: getTradeSellPrice(normalized),
|
sell: getTradeSellPrice(normalized),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,10 @@ import {
|
|||||||
priceStreamLifecycle,
|
priceStreamLifecycle,
|
||||||
priceWssEnabled,
|
priceWssEnabled,
|
||||||
} from '@/utils/priceSocketState'
|
} from '@/utils/priceSocketState'
|
||||||
|
import {
|
||||||
|
applyBoardSpecialToLastPayload,
|
||||||
|
setSpecialPricingPayload,
|
||||||
|
} from '@/utils/specialPricing'
|
||||||
|
|
||||||
export {
|
export {
|
||||||
priceSocketConnected,
|
priceSocketConnected,
|
||||||
@@ -20,7 +24,8 @@ export {
|
|||||||
|
|
||||||
const RECONNECT_BASE_MS = 3000
|
const RECONNECT_BASE_MS = 3000
|
||||||
const RECONNECT_MAX_MS = 30000
|
const RECONNECT_MAX_MS = 30000
|
||||||
const FAILURES_BEFORE_ALERT = 4
|
/** چند بار خطای پشتسرهم /api/price/last قبل از نمایش مدال */
|
||||||
|
const LAST_FETCH_FAILURES_BEFORE_ALERT = 2
|
||||||
const ALERT_COOLDOWN_MS = 5 * 60 * 1000
|
const ALERT_COOLDOWN_MS = 5 * 60 * 1000
|
||||||
const FALLBACK_POLL_INTERVAL_MS = 10000
|
const FALLBACK_POLL_INTERVAL_MS = 10000
|
||||||
/** بدون قیمت معتبر از مرجع (SSE یا API) */
|
/** بدون قیمت معتبر از مرجع (SSE یا API) */
|
||||||
@@ -29,8 +34,95 @@ const PRICE_SOURCE_STALE_MS_DESKTOP = 35000
|
|||||||
/** بدون event قیمت؛ ping هر ۵ث از سرور activity را تازه میکند */
|
/** بدون event قیمت؛ ping هر ۵ث از سرور activity را تازه میکند */
|
||||||
const STALE_STREAM_MS = 120000
|
const STALE_STREAM_MS = 120000
|
||||||
const FALLBACK_POLL_DELAY_MS = 2500
|
const FALLBACK_POLL_DELAY_MS = 2500
|
||||||
|
const STREAM_CONNECTING = 0
|
||||||
|
const STREAM_OPEN = 1
|
||||||
|
const STREAM_CLOSED = 2
|
||||||
|
|
||||||
let eventSource: EventSource | null = null
|
/** EventSource نمیتواند Authorization بفرستد؛ استریم همچنان auth:customer میخواهد. */
|
||||||
|
class AuthPriceStream extends EventTarget {
|
||||||
|
readyState = STREAM_CONNECTING
|
||||||
|
onopen: (() => void) | null = null
|
||||||
|
onerror: (() => void) | null = null
|
||||||
|
onmessage: (() => void) | null = null
|
||||||
|
private abort = new AbortController()
|
||||||
|
|
||||||
|
constructor(url: string, token: string) {
|
||||||
|
super()
|
||||||
|
void this.start(url, token)
|
||||||
|
}
|
||||||
|
|
||||||
|
close() {
|
||||||
|
this.readyState = STREAM_CLOSED
|
||||||
|
this.abort.abort()
|
||||||
|
}
|
||||||
|
|
||||||
|
private async start(url: string, token: string) {
|
||||||
|
try {
|
||||||
|
const response = await fetch(url, {
|
||||||
|
headers: {
|
||||||
|
Accept: 'text/event-stream',
|
||||||
|
Authorization: `Bearer ${token}`,
|
||||||
|
},
|
||||||
|
cache: 'no-store',
|
||||||
|
signal: this.abort.signal,
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!response.ok || !response.body) {
|
||||||
|
this.readyState = STREAM_CLOSED
|
||||||
|
this.onerror?.()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.readyState = STREAM_OPEN
|
||||||
|
this.onopen?.()
|
||||||
|
|
||||||
|
const reader = response.body.getReader()
|
||||||
|
const decoder = new TextDecoder()
|
||||||
|
let buffer = ''
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
const { done, value } = await reader.read()
|
||||||
|
if (done) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
buffer += decoder.decode(value, { stream: true })
|
||||||
|
buffer = this.flushSse(buffer)
|
||||||
|
}
|
||||||
|
|
||||||
|
this.readyState = STREAM_CLOSED
|
||||||
|
this.onerror?.()
|
||||||
|
} catch {
|
||||||
|
if (this.abort.signal.aborted) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.readyState = STREAM_CLOSED
|
||||||
|
this.onerror?.()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private flushSse(buffer: string): string {
|
||||||
|
const blocks = buffer.split('\n\n')
|
||||||
|
const rest = blocks.pop() ?? ''
|
||||||
|
|
||||||
|
for (const block of blocks) {
|
||||||
|
let event = 'message'
|
||||||
|
const data: string[] = []
|
||||||
|
for (const line of block.split('\n')) {
|
||||||
|
if (line.startsWith('event:')) {
|
||||||
|
event = line.slice(6).trim()
|
||||||
|
} else if (line.startsWith('data:')) {
|
||||||
|
data.push(line.slice(5).trimStart())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.dispatchEvent(new MessageEvent(event, { data: data.join('\n') }))
|
||||||
|
this.onmessage?.()
|
||||||
|
}
|
||||||
|
|
||||||
|
return rest
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let eventSource: AuthPriceStream | null = null
|
||||||
let subscribers = 0
|
let subscribers = 0
|
||||||
let stopped = false
|
let stopped = false
|
||||||
let getSetting: ((key: string) => unknown) | null = null
|
let getSetting: ((key: string) => unknown) | null = null
|
||||||
@@ -99,16 +191,12 @@ function resolveStreamUrl(): string | null {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
const token = findStoredAuthToken()
|
if (!findStoredAuthToken()) {
|
||||||
if (!token) {
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
const base = String(getConfigApp('node_server') || window.location.origin).replace(/\/$/, '')
|
const base = String(getConfigApp('node_server') || window.location.origin).replace(/\/$/, '')
|
||||||
const url = new URL(`${base}${resolveStreamPath()}`)
|
return `${base}${resolveStreamPath()}`
|
||||||
url.searchParams.set('token', token)
|
|
||||||
|
|
||||||
return url.toString()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function clearReconnectTimer() {
|
function clearReconnectTimer() {
|
||||||
@@ -137,7 +225,7 @@ function startStaleCheck() {
|
|||||||
stopped
|
stopped
|
||||||
|| subscribers <= 0
|
|| subscribers <= 0
|
||||||
|| !eventSource
|
|| !eventSource
|
||||||
|| eventSource.readyState !== EventSource.OPEN
|
|| eventSource.readyState !== STREAM_OPEN
|
||||||
) {
|
) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -190,6 +278,16 @@ function scheduleFallbackPoll() {
|
|||||||
}, FALLBACK_POLL_DELAY_MS)
|
}, FALLBACK_POLL_DELAY_MS)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function clearPriceNetworkAlert() {
|
||||||
|
networkAlertOpen = false
|
||||||
|
pendingPriceAlert = false
|
||||||
|
}
|
||||||
|
|
||||||
|
/** وقتی /api/price/last خطا میدهد (از polling عادی یا fallback) */
|
||||||
|
export function notifyPriceLastFetchFailed() {
|
||||||
|
void maybeShowNetworkAlert()
|
||||||
|
}
|
||||||
|
|
||||||
async function runFallbackPoll() {
|
async function runFallbackPoll() {
|
||||||
if (!priceWssEnabled.value || priceSocketConnected.value) {
|
if (!priceWssEnabled.value || priceSocketConnected.value) {
|
||||||
return
|
return
|
||||||
@@ -213,8 +311,9 @@ async function runFallbackPoll() {
|
|||||||
&& priceResult.value === true
|
&& priceResult.value === true
|
||||||
&& hasRecentPriceFromSource(getPriceSourceStaleMs())
|
&& hasRecentPriceFromSource(getPriceSourceStaleMs())
|
||||||
|
|
||||||
if (!priceOk) {
|
if (priceOk) {
|
||||||
markPriceSourceFetchFailed()
|
clearPriceNetworkAlert()
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
void maybeShowNetworkAlert()
|
void maybeShowNetworkAlert()
|
||||||
@@ -243,25 +342,7 @@ async function isRealPriceOutage(): Promise<boolean> {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
const fetchFailures = consecutivePriceSourceFailures()
|
return consecutivePriceSourceFailures() >= LAST_FETCH_FAILURES_BEFORE_ALERT
|
||||||
|
|
||||||
if (fetchFailures >= 2) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!priceSocketConnected.value && fetchFailures >= 1 && reconnectAttempt >= 2) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isMobileDevice() && !navigator.onLine && fetchFailures >= 1) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isMobileDevice() && reconnectAttempt >= FAILURES_BEFORE_ALERT) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function showNetworkAlert() {
|
function showNetworkAlert() {
|
||||||
@@ -322,7 +403,6 @@ function scheduleReconnect() {
|
|||||||
reconnectTimer = setTimeout(() => {
|
reconnectTimer = setTimeout(() => {
|
||||||
reconnectAttempt += 1
|
reconnectAttempt += 1
|
||||||
connect()
|
connect()
|
||||||
maybeShowNetworkAlert()
|
|
||||||
}, delay)
|
}, delay)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -331,13 +411,61 @@ async function applyLastFromStream(last: Price) {
|
|||||||
applyLastPricePayload(last)
|
applyLastPricePayload(last)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function applySettingsFromStream(payload: unknown) {
|
||||||
|
const items = Array.isArray(payload)
|
||||||
|
? payload
|
||||||
|
: payload && typeof payload === 'object' && Array.isArray((payload as { items?: unknown }).items)
|
||||||
|
? (payload as { items: unknown[] }).items
|
||||||
|
: null
|
||||||
|
if (!items?.length) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const { useSettingsStore } = await import('@/store/settingsStore')
|
||||||
|
const { touchStoreHoursSettings } = await import('@/utils/storeHours')
|
||||||
|
useSettingsStore().mergeSettings(items as Array<{ key?: string; value?: unknown }>)
|
||||||
|
touchStoreHoursSettings()
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('Settings SSE apply failed', error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function handleLastPayload(payload: unknown) {
|
function handleLastPayload(payload: unknown) {
|
||||||
if (!payload || typeof payload !== 'object') {
|
if (!payload || typeof payload !== 'object') {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const last = payload as Price
|
const raw = payload as Price & { settings_patch?: unknown }
|
||||||
if (last.price_last == null && last.price == null && last.buy == null) {
|
const last = applyBoardSpecialToLastPayload(raw)
|
||||||
|
const hasDisplayable =
|
||||||
|
Number(last.buy ?? 0) > 0
|
||||||
|
|| Number(last.sell ?? 0) > 0
|
||||||
|
|| Number(last.price_last ?? 0) > 0
|
||||||
|
|| Number(last.price ?? 0) > 0
|
||||||
|
const hasStatus = last.status != null || typeof last.closed === 'boolean'
|
||||||
|
|
||||||
|
if (!hasDisplayable && !hasStatus) {
|
||||||
|
if (Array.isArray(raw.settings_patch) && raw.settings_patch.length) {
|
||||||
|
touchStreamActivity()
|
||||||
|
void applySettingsFromStream(raw.settings_patch)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// SSE گاهی last خالی/no_quote میفرستد؛ قیمت معتبر فعلی را پاک نکن
|
||||||
|
if (!hasDisplayable) {
|
||||||
|
if (Array.isArray(raw.settings_patch) && raw.settings_patch.length) {
|
||||||
|
touchStreamActivity()
|
||||||
|
void applySettingsFromStream(raw.settings_patch)
|
||||||
|
}
|
||||||
|
void import('@/utils/price').then(({ getTradeBuyPrice, lastPrice }) => {
|
||||||
|
const keepCurrent =
|
||||||
|
getTradeBuyPrice(lastPrice.value) > 0 && last.status !== 'closed'
|
||||||
|
touchStreamActivity()
|
||||||
|
if (keepCurrent) return
|
||||||
|
void applyLastFromStream(last)
|
||||||
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -345,6 +473,11 @@ function handleLastPayload(payload: unknown) {
|
|||||||
void applyLastFromStream(last)
|
void applyLastFromStream(last)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleSettingsPayload(payload: unknown) {
|
||||||
|
touchStreamActivity()
|
||||||
|
void applySettingsFromStream(payload)
|
||||||
|
}
|
||||||
|
|
||||||
async function applyListFromStream(products: Product[]) {
|
async function applyListFromStream(products: Product[]) {
|
||||||
const { applyProductsListFromSocket } = await import(
|
const { applyProductsListFromSocket } = await import(
|
||||||
'@/views/base/products/composables/useProductsPageData'
|
'@/views/base/products/composables/useProductsPageData'
|
||||||
@@ -375,7 +508,43 @@ function handleAssetsPayload(payload: unknown) {
|
|||||||
void applyAssetsFromStream(payload)
|
void applyAssetsFromStream(payload)
|
||||||
}
|
}
|
||||||
|
|
||||||
function bindStreamEvents(source: EventSource) {
|
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: AuthPriceStream) {
|
||||||
source.addEventListener('last', (event) => {
|
source.addEventListener('last', (event) => {
|
||||||
try {
|
try {
|
||||||
handleLastPayload(JSON.parse(event.data))
|
handleLastPayload(JSON.parse(event.data))
|
||||||
@@ -384,6 +553,14 @@ function bindStreamEvents(source: EventSource) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
source.addEventListener('settings', (event) => {
|
||||||
|
try {
|
||||||
|
handleSettingsPayload(JSON.parse(event.data))
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('Price SSE settings parse failed', error)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
source.addEventListener('list', (event) => {
|
source.addEventListener('list', (event) => {
|
||||||
try {
|
try {
|
||||||
handleListPayload(JSON.parse(event.data))
|
handleListPayload(JSON.parse(event.data))
|
||||||
@@ -400,6 +577,30 @@ 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', () => {
|
source.addEventListener('ping', () => {
|
||||||
touchStreamActivity()
|
touchStreamActivity()
|
||||||
})
|
})
|
||||||
@@ -441,7 +642,8 @@ function connect() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const url = resolveStreamUrl()
|
const url = resolveStreamUrl()
|
||||||
if (!url) {
|
const token = findStoredAuthToken()
|
||||||
|
if (!url || !token) {
|
||||||
priceSocketConnected.value = false
|
priceSocketConnected.value = false
|
||||||
priceStreamLifecycle.value = 'closed'
|
priceStreamLifecycle.value = 'closed'
|
||||||
clearConnectingLifecycle()
|
clearConnectingLifecycle()
|
||||||
@@ -450,7 +652,7 @@ function connect() {
|
|||||||
|
|
||||||
if (eventSource) {
|
if (eventSource) {
|
||||||
const state = eventSource.readyState
|
const state = eventSource.readyState
|
||||||
if (state === EventSource.OPEN || state === EventSource.CONNECTING) {
|
if (state === STREAM_OPEN || state === STREAM_CONNECTING) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
disconnectSourceOnly()
|
disconnectSourceOnly()
|
||||||
@@ -459,7 +661,7 @@ function connect() {
|
|||||||
markConnectingLifecycle()
|
markConnectingLifecycle()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
eventSource = new EventSource(url)
|
eventSource = new AuthPriceStream(url, token)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.warn('Price SSE connect failed', error)
|
console.warn('Price SSE connect failed', error)
|
||||||
handleStreamLost()
|
handleStreamLost()
|
||||||
@@ -482,7 +684,7 @@ function connect() {
|
|||||||
|
|
||||||
eventSource.onerror = () => {
|
eventSource.onerror = () => {
|
||||||
const state = eventSource?.readyState
|
const state = eventSource?.readyState
|
||||||
if (state === EventSource.OPEN || state === EventSource.CONNECTING) {
|
if (state === STREAM_OPEN || state === STREAM_CONNECTING) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -596,7 +798,7 @@ function onVisibilityChange() {
|
|||||||
void maybeShowNetworkAlert()
|
void maybeShowNetworkAlert()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!eventSource || eventSource.readyState !== EventSource.OPEN) {
|
if (!eventSource || eventSource.readyState !== STREAM_OPEN) {
|
||||||
forceReconnect()
|
forceReconnect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -606,7 +808,7 @@ function onPageShow(event: PageTransitionEvent) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.persisted || !eventSource || eventSource.readyState !== EventSource.OPEN) {
|
if (event.persisted || !eventSource || eventSource.readyState !== STREAM_OPEN) {
|
||||||
reconnectAttempt = 0
|
reconnectAttempt = 0
|
||||||
networkAlertOpen = false
|
networkAlertOpen = false
|
||||||
forceReconnect()
|
forceReconnect()
|
||||||
|
|||||||
@@ -648,19 +648,31 @@ export function enrichInventoryWithCatalog<T extends { id?: number }>(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function withProductImageCacheBust(
|
||||||
|
url: string,
|
||||||
|
product?: { file_id?: number | string | null; file?: ProductFile | null } | null,
|
||||||
|
): string {
|
||||||
|
if (!url || !/^https?:\/\//i.test(url)) return url
|
||||||
|
const version = product?.file_id ?? product?.file?.id
|
||||||
|
if (version == null || version === '' || Number(version) <= 0) return url
|
||||||
|
if (/[?&]v=/.test(url)) return url
|
||||||
|
return `${url}${url.includes('?') ? '&' : '?'}v=${encodeURIComponent(String(version))}`
|
||||||
|
}
|
||||||
|
|
||||||
export function getProductDisplayImage(product?: {
|
export function getProductDisplayImage(product?: {
|
||||||
group_type?: string | null
|
group_type?: string | null
|
||||||
title?: string | null
|
title?: string | null
|
||||||
file?: ProductFile | null
|
file?: ProductFile | null
|
||||||
|
file_id?: number | string | null
|
||||||
img?: string | null
|
img?: string | null
|
||||||
} | null): string {
|
} | null): string {
|
||||||
const fileUrl = getFileUrl(product?.file)
|
const fileUrl = getFileUrl(product?.file)
|
||||||
if (fileUrl) {
|
if (fileUrl) {
|
||||||
return fileUrl
|
return withProductImageCacheBust(fileUrl, product)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (product?.img && /^https?:\/\//i.test(product.img)) {
|
if (product?.img && /^https?:\/\//i.test(product.img)) {
|
||||||
return product.img
|
return withProductImageCacheBust(product.img, product)
|
||||||
}
|
}
|
||||||
|
|
||||||
const group = normalizeProductGroupType(product?.group_type)
|
const group = normalizeProductGroupType(product?.group_type)
|
||||||
|
|||||||
@@ -43,19 +43,23 @@ export function resolveProductCashFeeRial(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function resolveProductCashFeeBuyRial(product: ProductCashFeeSource, basePriceRial: number) {
|
export function resolveProductCashFeeBuyRial(product: ProductCashFeeSource, basePriceRial: number) {
|
||||||
return resolveProductCashFeeRial(
|
const baseFee = resolveProductCashFeeRial(
|
||||||
product.cash_fee_buy,
|
product.cash_fee_buy,
|
||||||
product.cash_fee_buy_is_percent,
|
product.cash_fee_buy_is_percent,
|
||||||
basePriceRial,
|
basePriceRial,
|
||||||
)
|
)
|
||||||
|
const special = Number((product as { special_profit_buy?: number }).special_profit_buy ?? 0)
|
||||||
|
return baseFee + (Number.isFinite(special) ? Math.round(special) : 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function resolveProductCashFeeSellRial(product: ProductCashFeeSource, basePriceRial: number) {
|
export function resolveProductCashFeeSellRial(product: ProductCashFeeSource, basePriceRial: number) {
|
||||||
return resolveProductCashFeeRial(
|
const baseFee = resolveProductCashFeeRial(
|
||||||
product.cash_fee_sell,
|
product.cash_fee_sell,
|
||||||
product.cash_fee_sell_is_percent,
|
product.cash_fee_sell_is_percent,
|
||||||
basePriceRial,
|
basePriceRial,
|
||||||
)
|
)
|
||||||
|
const special = Number((product as { special_profit_sell?: number }).special_profit_sell ?? 0)
|
||||||
|
return baseFee + (Number.isFinite(special) ? Math.round(special) : 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function formatProductCashFeeLabel(
|
export function formatProductCashFeeLabel(
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ export interface ProductUnitSource {
|
|||||||
group_type?: string | null
|
group_type?: string | null
|
||||||
amount?: number | null
|
amount?: number | null
|
||||||
trade_by_quantity?: boolean | number | null
|
trade_by_quantity?: boolean | number | null
|
||||||
|
price_formula_enabled?: boolean | number | null
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isWeightBasedProductUnit(unit?: string | null) {
|
export function isWeightBasedProductUnit(unit?: string | null) {
|
||||||
@@ -80,6 +81,11 @@ export function hasProductUnitWeight(product?: ProductUnitSource | null) {
|
|||||||
|
|
||||||
/** ضریب قیمت — فقط «متغیر» بدون مرجع اتوماتیک: قیمت هر گرم × وزن */
|
/** ضریب قیمت — فقط «متغیر» بدون مرجع اتوماتیک: قیمت هر گرم × وزن */
|
||||||
export function productPriceAmountFactor(product?: ProductUnitSource | null) {
|
export function productPriceAmountFactor(product?: ProductUnitSource | null) {
|
||||||
|
// قیمت فرمولی = قیمت واحد هر عدد (وزن داخل فرمول است)
|
||||||
|
if (product?.price_formula_enabled) {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
if (product?.reading_method) {
|
if (product?.reading_method) {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
@@ -439,7 +445,7 @@ export function formatMainMetalReceiveText(weight?: number | null) {
|
|||||||
|
|
||||||
export function calcSellReceivedMetalWeight(
|
export function calcSellReceivedMetalWeight(
|
||||||
count?: number | null,
|
count?: number | null,
|
||||||
product?: ProductUnitSource & { percent_fee_sell?: number | null } | null,
|
product?: ProductUnitSource | null,
|
||||||
) {
|
) {
|
||||||
const quantity = Number(count ?? 0)
|
const quantity = Number(count ?? 0)
|
||||||
const unitAmount = Number(product?.amount ?? 0)
|
const unitAmount = Number(product?.amount ?? 0)
|
||||||
@@ -447,9 +453,8 @@ export function calcSellReceivedMetalWeight(
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
const grossAmount = quantity * unitAmount
|
// کارمزد محصول تعدادی از ریال است — وزن دریافتی فلز کم نمیشود
|
||||||
const feeRate = Number(product?.percent_fee_sell ?? 0)
|
return quantity * unitAmount
|
||||||
return grossAmount - feeRate * grossAmount
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isCashLikeDealMethod(method?: string | null) {
|
export function isCashLikeDealMethod(method?: string | null) {
|
||||||
|
|||||||
@@ -0,0 +1,72 @@
|
|||||||
|
/** سقف inset بالا (Dynamic Island / notch) — فقط وقتی env صفر است و واقعاً iOS standalone */
|
||||||
|
const MAX_SAFE_TOP_PX = 59
|
||||||
|
/** فقط PWA نصبشدهٔ آیفون — سافاری این را نگیرد */
|
||||||
|
const IOS_INSTALLED_TOP_BUFFER_PX = 10
|
||||||
|
|
||||||
|
function isStandaloneDisplay() {
|
||||||
|
return (
|
||||||
|
window.matchMedia('(display-mode: standalone)').matches ||
|
||||||
|
Boolean((window.navigator as Navigator & { standalone?: boolean }).standalone)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** iPhone / iPad — شامل iPadOS که خود را Mac معرفی میکند */
|
||||||
|
function isAppleTouchDevice() {
|
||||||
|
const ua = window.navigator.userAgent || ''
|
||||||
|
if (/iP(hone|od|ad)/i.test(ua)) return true
|
||||||
|
return window.navigator.platform === 'MacIntel' && window.navigator.maxTouchPoints > 1
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* روی بعضی buildهای iOS PWA، env(safe-area-inset-*) داخل CSS var صفر میماند
|
||||||
|
* در حالی که محتوا واقعاً زیر نوار وضعیت رسم میشود. این تابع مقدار واقعی را
|
||||||
|
* با یک probe میخواند و روی :root مینشاند.
|
||||||
|
*/
|
||||||
|
export function syncSafeAreaInsets() {
|
||||||
|
if (typeof document === 'undefined' || typeof window === 'undefined') {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const probe = document.createElement('div')
|
||||||
|
probe.setAttribute('aria-hidden', 'true')
|
||||||
|
probe.style.cssText = [
|
||||||
|
'position:fixed',
|
||||||
|
'top:0',
|
||||||
|
'left:0',
|
||||||
|
'width:0',
|
||||||
|
'height:0',
|
||||||
|
'padding:env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px)',
|
||||||
|
'visibility:hidden',
|
||||||
|
'pointer-events:none',
|
||||||
|
'z-index:-1',
|
||||||
|
].join(';')
|
||||||
|
|
||||||
|
document.documentElement.appendChild(probe)
|
||||||
|
const style = getComputedStyle(probe)
|
||||||
|
const top = style.paddingTop || '0px'
|
||||||
|
const right = style.paddingRight || '0px'
|
||||||
|
const bottom = style.paddingBottom || '0px'
|
||||||
|
const left = style.paddingLeft || '0px'
|
||||||
|
probe.remove()
|
||||||
|
|
||||||
|
const root = document.documentElement
|
||||||
|
root.style.setProperty('--app-safe-top', top)
|
||||||
|
root.style.setProperty('--app-safe-bottom', bottom)
|
||||||
|
root.style.setProperty('--app-safe-right', right)
|
||||||
|
root.style.setProperty('--app-safe-left', left)
|
||||||
|
|
||||||
|
const topPx = Number.parseFloat(top) || 0
|
||||||
|
if (isStandaloneDisplay() && isAppleTouchDevice()) {
|
||||||
|
const next = (topPx < 1 ? MAX_SAFE_TOP_PX : topPx) + IOS_INSTALLED_TOP_BUFFER_PX
|
||||||
|
root.style.setProperty('--app-safe-top', `${next}px`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function initSafeAreaInsets() {
|
||||||
|
syncSafeAreaInsets()
|
||||||
|
|
||||||
|
window.addEventListener('orientationchange', () => {
|
||||||
|
window.setTimeout(syncSafeAreaInsets, 100)
|
||||||
|
})
|
||||||
|
window.visualViewport?.addEventListener('resize', syncSafeAreaInsets)
|
||||||
|
}
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
const OVERLAY_ID = 'sa-server-unavailable-overlay'
|
||||||
|
export const SERVER_UNAVAILABLE_MESSAGE = 'خطا در برقراری ارتباط با سرور'
|
||||||
|
const MESSAGE = SERVER_UNAVAILABLE_MESSAGE
|
||||||
|
|
||||||
|
/** Thrown after kill-switch overlay is shown — bootstrap must not replace it with internet error */
|
||||||
|
export class ServerUnavailableError extends Error {
|
||||||
|
readonly isServerUnavailable = true
|
||||||
|
|
||||||
|
constructor(message = MESSAGE) {
|
||||||
|
super(message)
|
||||||
|
this.name = 'ServerUnavailableError'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isServerUnavailableError(error: unknown): boolean {
|
||||||
|
if (!error || typeof error !== 'object') return false
|
||||||
|
if (error instanceof ServerUnavailableError) return true
|
||||||
|
const record = error as { isServerUnavailable?: unknown; message?: unknown }
|
||||||
|
return (
|
||||||
|
record.isServerUnavailable === true ||
|
||||||
|
record.message === SERVER_UNAVAILABLE_MESSAGE
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isServerUnreachableConfig(config: unknown): boolean {
|
||||||
|
if (!config || typeof config !== 'object') return false
|
||||||
|
const root = config as Record<string, unknown>
|
||||||
|
const user =
|
||||||
|
root.user && typeof root.user === 'object'
|
||||||
|
? (root.user as Record<string, unknown>)
|
||||||
|
: null
|
||||||
|
|
||||||
|
if (root.server_reachable === false) return true
|
||||||
|
if (user && user.server_reachable === false) return true
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
export function showServerUnavailableOverlay(message = MESSAGE) {
|
||||||
|
if (typeof document === 'undefined') return
|
||||||
|
let root = document.getElementById(OVERLAY_ID)
|
||||||
|
if (!root) {
|
||||||
|
root = document.createElement('div')
|
||||||
|
root.id = OVERLAY_ID
|
||||||
|
document.body.appendChild(root)
|
||||||
|
}
|
||||||
|
|
||||||
|
// z-index بالاتر از boot-error تا پیام قطع عمدی با «خطای اینترنت» عوض نشود
|
||||||
|
root.innerHTML = `
|
||||||
|
<div style="position:fixed;inset:0;z-index:2147483647;display:flex;align-items:center;justify-content:center;direction:rtl;font-family:sans-serif;padding:24px;background:#ffffff;color:#111827;">
|
||||||
|
<div style="width:min(420px,100%);text-align:center;background:#fff;border:1px solid rgba(15,23,42,0.08);border-radius:24px;padding:28px 22px;">
|
||||||
|
<div style="font-size:42px;margin-bottom:12px;">⚠️</div>
|
||||||
|
<h2 style="margin:0 0 20px;font-size:20px;">${message}</h2>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onclick="location.reload()"
|
||||||
|
style="padding:11px 22px;border:0;border-radius:12px;background:#2563eb;color:white;cursor:pointer;font-weight:700;"
|
||||||
|
>
|
||||||
|
تلاش مجدد
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`
|
||||||
|
}
|
||||||
|
|
||||||
|
export function hideServerUnavailableOverlay() {
|
||||||
|
if (typeof document === 'undefined') return
|
||||||
|
const root = document.getElementById(OVERLAY_ID)
|
||||||
|
if (root) root.remove()
|
||||||
|
}
|
||||||
|
|
||||||
|
export function assertServerReachableConfig(config: unknown) {
|
||||||
|
if (isServerUnreachableConfig(config)) {
|
||||||
|
showServerUnavailableOverlay()
|
||||||
|
throw new ServerUnavailableError()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
import { getSettings } from '@/api/configuration'
|
import { useSettingsStore } from '@/store/settingsStore'
|
||||||
|
|
||||||
export const serviceFeePercentage = ref<number>(0.01)
|
export const serviceFeePercentage = ref<number>(0)
|
||||||
|
|
||||||
/** true = مبالغ رند: فروش → ریال دقیق (کارمزد از طلا)؛ خرید → وزن دقیق (کارمزد از ریال) */
|
/** true = مبالغ رند: فروش → ریال دقیق (کارمزد از طلا)؛ خرید → وزن دقیق (کارمزد از ریال) */
|
||||||
export const feeDeductFromGold = ref(false)
|
export const feeDeductFromGold = ref(false)
|
||||||
@@ -9,6 +9,11 @@ export const feeDeductFromGold = ref(false)
|
|||||||
/** آخرین فیلدی که کاربر مستقیم ویرایش کرده — مبنای بهروزرسانی هنگام تغییر قیمت */
|
/** آخرین فیلدی که کاربر مستقیم ویرایش کرده — مبنای بهروزرسانی هنگام تغییر قیمت */
|
||||||
export type TradeInputLock = 'gram' | 'rial' | null
|
export type TradeInputLock = 'gram' | 'rial' | null
|
||||||
|
|
||||||
|
/** ریال قفل است؟ (کاربر مبلغ ریالی را مستقیم وارد کرده) → کارمزد از طلا */
|
||||||
|
export function isRialLocked(inputLock?: TradeInputLock): boolean {
|
||||||
|
return inputLock === 'rial'
|
||||||
|
}
|
||||||
|
|
||||||
/** حداکثر اعشار ذخیره/ارسال به سرور (مطابق orders.amount) */
|
/** حداکثر اعشار ذخیره/ارسال به سرور (مطابق orders.amount) */
|
||||||
export const TRADE_GRAM_STORAGE_DECIMALS = 10
|
export const TRADE_GRAM_STORAGE_DECIMALS = 10
|
||||||
|
|
||||||
@@ -28,18 +33,34 @@ export function formatTradeGramDisplay(grams?: number | null): number {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function feeRate() {
|
function feeRate() {
|
||||||
return Number(serviceFeePercentage.value)
|
return normalizeServiceFeeRatio(Number(serviceFeePercentage.value))
|
||||||
|
}
|
||||||
|
|
||||||
|
/** نسبت کارمزد (۰٫۰۱ = ۱٪). مقدار ≥۱ یعنی درصد انسانی اشتباه وارد شده. */
|
||||||
|
export function normalizeServiceFeeRatio(value: number): number {
|
||||||
|
if (!Number.isFinite(value) || value <= 0) {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
if (value >= 1) {
|
||||||
|
return value / 100
|
||||||
|
}
|
||||||
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function loadServiceFeeFromSettings() {
|
export async function loadServiceFeeFromSettings() {
|
||||||
try {
|
try {
|
||||||
const settings = await getSettings()
|
const settingsStore = useSettingsStore()
|
||||||
if (settings && Array.isArray(settings)) {
|
if (!settingsStore.loaded) {
|
||||||
|
await settingsStore.fetchSettings()
|
||||||
|
}
|
||||||
|
const settings = settingsStore.settings
|
||||||
|
if (settings?.length) {
|
||||||
const feeSetting = settings.find(
|
const feeSetting = settings.find(
|
||||||
(s) => s?.key === 'fee_service_charge_percentage' && s?.is_active === true
|
(s) => s?.key === 'fee_service_charge_percentage' && s?.is_active === true
|
||||||
)
|
)
|
||||||
if (feeSetting?.value !== undefined && feeSetting?.value !== null) {
|
if (feeSetting?.value !== undefined && feeSetting?.value !== null) {
|
||||||
serviceFeePercentage.value = Number(feeSetting.value)
|
const raw = String(feeSetting.value).trim()
|
||||||
|
serviceFeePercentage.value = raw === '' ? 0 : normalizeServiceFeeRatio(Number(raw))
|
||||||
}
|
}
|
||||||
|
|
||||||
const feeModeSetting = settings.find(
|
const feeModeSetting = settings.find(
|
||||||
@@ -58,7 +79,7 @@ export async function loadServiceFeeFromSettings() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function calcFeeInGrams(goldValue?: number | null) {
|
export function calcFeeInGrams(goldValue?: number | null) {
|
||||||
return parseFloat(((goldValue ?? 0) * Number(serviceFeePercentage.value)).toFixed(4))
|
return parseFloat(((goldValue ?? 0) * feeRate()).toFixed(4))
|
||||||
}
|
}
|
||||||
|
|
||||||
/** گرم معادل برای دریافت دقیق مبلغ ریالی در فروش */
|
/** گرم معادل برای دریافت دقیق مبلغ ریالی در فروش */
|
||||||
@@ -204,3 +225,177 @@ export function calcSellGoldDebit(goldValue?: number | null, feeInGrams?: number
|
|||||||
}
|
}
|
||||||
return gold
|
return gold
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** مبلغ پایه معامله قبل از اعمال کارمزد ریالی (خرید با افزودن کارمزد به ریال) */
|
||||||
|
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')} ریال پرداخت`,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,80 @@
|
|||||||
|
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 && !sellExtra) return payload
|
||||||
|
|
||||||
|
const next = { ...payload } as T & Record<string, any>
|
||||||
|
if (Number(next.buy ?? 0) > 0 && buyExtra) {
|
||||||
|
next.buy = Math.max(0, Number(next.buy) + buyExtra)
|
||||||
|
}
|
||||||
|
if (Number(next.sell ?? 0) > 0 && sellExtra) {
|
||||||
|
next.sell = Math.max(0, Number(next.sell) - sellExtra)
|
||||||
|
}
|
||||||
|
if (Number(next.price_last ?? 0) > 0 && buyExtra) {
|
||||||
|
next.price_last = Math.max(0, 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,6 +1,6 @@
|
|||||||
import { ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
import { useSettingsStore } from '@/store/settingsStore'
|
import { useSettingsStore } from '@/store/settingsStore'
|
||||||
import { getTradeBuyPrice, getTradeSellPrice, lastPrice } from '@/utils/price'
|
import { isLastPriceAbsenceSettled, lastPrice, lastPriceReady } from '@/utils/price'
|
||||||
|
|
||||||
export interface StoreTradingHours {
|
export interface StoreTradingHours {
|
||||||
start: string
|
start: string
|
||||||
@@ -12,8 +12,24 @@ export interface EffectiveTradingHours {
|
|||||||
start: string
|
start: string
|
||||||
end: string
|
end: string
|
||||||
enforced: boolean
|
enforced: boolean
|
||||||
|
dayEnabled: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type WeekdayKey = 'sat' | 'sun' | 'mon' | 'tue' | 'wed' | 'thu' | 'fri'
|
||||||
|
|
||||||
|
type DaySchedule = {
|
||||||
|
enabled: boolean
|
||||||
|
start: string
|
||||||
|
end: string
|
||||||
|
}
|
||||||
|
|
||||||
|
type WeeklySchedule = {
|
||||||
|
mode: 'uniform' | 'per_day'
|
||||||
|
days: Record<WeekdayKey, DaySchedule>
|
||||||
|
}
|
||||||
|
|
||||||
|
const WEEKDAY_BY_JS: WeekdayKey[] = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat']
|
||||||
|
|
||||||
const productTradingHours = ref<{ start: string; end: string } | null>(null)
|
const productTradingHours = ref<{ start: string; end: string } | null>(null)
|
||||||
const productTradingHoursVersion = ref(0)
|
const productTradingHoursVersion = ref(0)
|
||||||
|
|
||||||
@@ -54,6 +70,11 @@ function hasProductTradingWindow(start?: string | null, end?: string | null): bo
|
|||||||
return open !== close
|
return open !== close
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** بعد از merge زندهٔ تنظیمات ساعت کاری — computedهای صفحه اصلی دوباره حساب شوند */
|
||||||
|
export function touchStoreHoursSettings() {
|
||||||
|
productTradingHoursVersion.value += 1
|
||||||
|
}
|
||||||
|
|
||||||
export function setProductTradingHours(start?: string | null, end?: string | null) {
|
export function setProductTradingHours(start?: string | null, end?: string | null) {
|
||||||
if (!hasProductTradingWindow(start, end)) {
|
if (!hasProductTradingWindow(start, end)) {
|
||||||
productTradingHours.value = null
|
productTradingHours.value = null
|
||||||
@@ -81,29 +102,77 @@ export function syncProductTradingHoursFromProducts(
|
|||||||
setProductTradingHours(null, null)
|
setProductTradingHours(null, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getStoreTradingHours(): StoreTradingHours {
|
function weekdayKey(now: Date): WeekdayKey {
|
||||||
const settings = useSettingsStore()
|
return WEEKDAY_BY_JS[now.getDay()] ?? 'sat'
|
||||||
const closeRaw = settings.getSettingByKey('close_price')
|
}
|
||||||
const closePriceEnabled =
|
|
||||||
closeRaw === true ||
|
|
||||||
closeRaw === 1 ||
|
|
||||||
String(closeRaw ?? 'false').trim().toLowerCase() === 'true'
|
|
||||||
|
|
||||||
return {
|
function parseWeeklySchedule(raw: unknown): WeeklySchedule | null {
|
||||||
start: normalizeTradingTimeSetting(settings.getSettingByKey('startDay'), '00:00'),
|
const text = String(raw ?? '').trim()
|
||||||
end: normalizeTradingTimeSetting(settings.getSettingByKey('endDay'), '23:59'),
|
if (!text) return null
|
||||||
closePriceEnabled,
|
try {
|
||||||
|
const parsed = JSON.parse(text) as Partial<WeeklySchedule>
|
||||||
|
if (!parsed?.days || typeof parsed.days !== 'object') return null
|
||||||
|
const mode = parsed.mode === 'per_day' ? 'per_day' : 'uniform'
|
||||||
|
const defaults = getStoreTradingHours()
|
||||||
|
const keys: WeekdayKey[] = ['sat', 'sun', 'mon', 'tue', 'wed', 'thu', 'fri']
|
||||||
|
const days = {} as Record<WeekdayKey, DaySchedule>
|
||||||
|
for (const key of keys) {
|
||||||
|
const row = parsed.days[key]
|
||||||
|
days[key] = {
|
||||||
|
enabled: row?.enabled !== false,
|
||||||
|
start: normalizeTradingTimeSetting(row?.start, defaults.start),
|
||||||
|
end: normalizeTradingTimeSetting(row?.end, defaults.end),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return { mode, days }
|
||||||
|
} catch {
|
||||||
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getEffectiveTradingHours(): EffectiveTradingHours {
|
function isOutsideTimeWindow(now: Date, start: string, end: string): boolean {
|
||||||
|
const currentSeconds = now.getHours() * 3600 + now.getMinutes() * 60 + now.getSeconds()
|
||||||
|
const openSeconds = parseTimeToSeconds(start)
|
||||||
|
const closeSeconds = parseTimeToSeconds(end)
|
||||||
|
if (closeSeconds <= openSeconds) {
|
||||||
|
return currentSeconds < openSeconds && currentSeconds > closeSeconds
|
||||||
|
}
|
||||||
|
return currentSeconds < openSeconds || currentSeconds > closeSeconds
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getStoreTradingHours(): StoreTradingHours {
|
||||||
|
const settings = useSettingsStore()
|
||||||
|
void settings.settingsRevision
|
||||||
|
return {
|
||||||
|
start: normalizeTradingTimeSetting(settings.getSettingByKey('startDay'), '00:00'),
|
||||||
|
end: normalizeTradingTimeSetting(settings.getSettingByKey('endDay'), '23:59'),
|
||||||
|
closePriceEnabled: settings.isSettingTruthy('close_price'),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getEffectiveTradingHours(now = new Date()): EffectiveTradingHours {
|
||||||
void productTradingHoursVersion.value
|
void productTradingHoursVersion.value
|
||||||
const settings = getStoreTradingHours()
|
const settings = getStoreTradingHours()
|
||||||
|
const weekly = parseWeeklySchedule(useSettingsStore().getSettingByKey('trading_hours_by_day'))
|
||||||
|
|
||||||
|
if (settings.closePriceEnabled && weekly?.mode === 'per_day') {
|
||||||
|
const day = weekly.days[weekdayKey(now)]
|
||||||
|
if (day) {
|
||||||
|
return {
|
||||||
|
start: day.start,
|
||||||
|
end: day.end,
|
||||||
|
enforced: true,
|
||||||
|
dayEnabled: day.enabled,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (settings.closePriceEnabled) {
|
if (settings.closePriceEnabled) {
|
||||||
return {
|
return {
|
||||||
start: settings.start,
|
start: settings.start,
|
||||||
end: settings.end,
|
end: settings.end,
|
||||||
enforced: true,
|
enforced: true,
|
||||||
|
dayEnabled: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,6 +181,7 @@ export function getEffectiveTradingHours(): EffectiveTradingHours {
|
|||||||
start: productTradingHours.value.start,
|
start: productTradingHours.value.start,
|
||||||
end: productTradingHours.value.end,
|
end: productTradingHours.value.end,
|
||||||
enforced: true,
|
enforced: true,
|
||||||
|
dayEnabled: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,16 +189,40 @@ export function getEffectiveTradingHours(): EffectiveTradingHours {
|
|||||||
start: settings.start,
|
start: settings.start,
|
||||||
end: settings.end,
|
end: settings.end,
|
||||||
enforced: false,
|
enforced: false,
|
||||||
|
dayEnabled: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isStoreClosedBySchedule(now = new Date()): boolean {
|
/** خارج از ساعت کاری سراسری — فقط وقتی close_price روشن باشد (صفحه اصلی) */
|
||||||
const { start, end, enforced } = getEffectiveTradingHours()
|
export function isOutsideGlobalStoreHours(now = new Date()): boolean {
|
||||||
if (!enforced) {
|
const settings = getStoreTradingHours()
|
||||||
|
if (!settings.closePriceEnabled) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
return isOutsideStoreTradingHours(now, start, end)
|
const weekly = parseWeeklySchedule(useSettingsStore().getSettingByKey('trading_hours_by_day'))
|
||||||
|
if (weekly?.mode === 'per_day') {
|
||||||
|
const day = weekly.days[weekdayKey(now)]
|
||||||
|
if (day && !day.enabled) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if (day) {
|
||||||
|
return isOutsideTimeWindow(now, day.start, day.end)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return isOutsideTimeWindow(now, settings.start, settings.end)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isStoreClosedBySchedule(now = new Date()): boolean {
|
||||||
|
const { start, end, enforced, dayEnabled } = getEffectiveTradingHours(now)
|
||||||
|
if (!enforced) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if (!dayEnabled) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return isOutsideTimeWindow(now, start, end)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isOutsideStoreTradingHours(
|
export function isOutsideStoreTradingHours(
|
||||||
@@ -136,20 +230,14 @@ export function isOutsideStoreTradingHours(
|
|||||||
start?: string,
|
start?: string,
|
||||||
end?: string,
|
end?: string,
|
||||||
): boolean {
|
): boolean {
|
||||||
const hours = start != null && end != null
|
if (start != null && end != null) {
|
||||||
? { start, end }
|
return isOutsideTimeWindow(now, start, end)
|
||||||
: getEffectiveTradingHours()
|
}
|
||||||
|
return isStoreClosedBySchedule(now)
|
||||||
const currentSeconds = now.getHours() * 3600 + now.getMinutes() * 60 + now.getSeconds()
|
|
||||||
const openSeconds = parseTimeToSeconds(hours.start)
|
|
||||||
const closeSeconds = parseTimeToSeconds(hours.end)
|
|
||||||
|
|
||||||
return currentSeconds < openSeconds || currentSeconds > closeSeconds
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function hasLivePriceQuote(): boolean {
|
export function hasLivePriceQuote(): boolean {
|
||||||
const p = lastPrice.value
|
return hasShowableHomePrice(lastPrice.value)
|
||||||
return getTradeBuyPrice(p) > 0 || getTradeSellPrice(p) > 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isStoreClosed(): boolean {
|
export function isStoreClosed(): boolean {
|
||||||
@@ -197,28 +285,83 @@ export type PriceDisplayState = 'open' | 'closed' | 'no_quote'
|
|||||||
|
|
||||||
export const NO_QUOTE_MESSAGE = 'مظنه در دسترس نیست'
|
export const NO_QUOTE_MESSAGE = 'مظنه در دسترس نیست'
|
||||||
|
|
||||||
|
/** سوییچ: خارج از ساعت کاری هم قیمت صفحه اصلی نشان داده شود */
|
||||||
|
export function shouldShowHomePriceWhenClosed(): boolean {
|
||||||
|
return useSettingsStore().isSettingTruthy('show_home_price_when_closed')
|
||||||
|
}
|
||||||
|
|
||||||
|
export function shouldShowLastSavedPrice(): boolean {
|
||||||
|
return useSettingsStore().isSettingTruthy('show_last_price')
|
||||||
|
}
|
||||||
|
|
||||||
|
/** فقط این منابع «آخرین قیمت ذخیرهشده» هستند؛ باقی price_source مظنهٔ زنده است */
|
||||||
|
const STORED_PRICE_SOURCES = ['database_last']
|
||||||
|
|
||||||
|
function hasShowableHomePrice(p = lastPrice.value): boolean {
|
||||||
|
if (!p) return false
|
||||||
|
return Number(p.buy) > 0 || Number(p.sell) > 0 || Number(p.price_last) > 0 || Number(p.price) > 0
|
||||||
|
}
|
||||||
|
|
||||||
|
/** قیمت از مرجع زنده آمده یا از آخرین ردیف ذخیرهشده */
|
||||||
|
function hasLiveQuote(p = lastPrice.value): boolean {
|
||||||
|
if (!hasShowableHomePrice(p)) return false
|
||||||
|
|
||||||
|
const source = String(p?.price_source ?? '').trim().toLowerCase()
|
||||||
|
if (source) return !STORED_PRICE_SOURCES.includes(source)
|
||||||
|
|
||||||
|
return (
|
||||||
|
Number(p?.montzar ?? 0) > 0
|
||||||
|
|| Number(p?.zaarbox ?? 0) > 0
|
||||||
|
|| Number(p?.main_product ?? 0) > 0
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* وضعیت نمایش قیمت:
|
* وضعیت نمایش قیمت در صفحه اصلی — همان منطق بکاند:
|
||||||
* - closed → فروشگاه بسته است (ساعت کاری، سیگنال سرور، یا نبود مظنه)
|
* خارج از ساعت کاری (close_price روشن) → show_home_price_when_closed روشن: آخرین قیمت؛ خاموش: closed
|
||||||
* - open → نمایش عادی قیمت
|
* داخل ساعت کاری → مظنه زنده: open ؛ وگرنه فقط با show_last_price آخرین قیمت؛ وگرنه no_quote
|
||||||
*/
|
*/
|
||||||
export function getPriceDisplayState(): PriceDisplayState {
|
export function getPriceDisplayState(): PriceDisplayState {
|
||||||
void productTradingHoursVersion.value
|
void productTradingHoursVersion.value
|
||||||
|
void useSettingsStore().settingsRevision
|
||||||
const p = lastPrice.value
|
const p = lastPrice.value
|
||||||
|
|
||||||
if (p?.status === 'closed' || p?.closed === true) {
|
const serverStatus = p?.status
|
||||||
return 'closed'
|
// اگر عدد قیمت هست، no_quote لحظهای سرور را جدی نگیر (race با تیک بعدی)
|
||||||
|
if (serverStatus === 'no_quote' && hasShowableHomePrice(p)) {
|
||||||
|
// fall through به منطق کلاینت
|
||||||
|
} else if (serverStatus === 'open' || serverStatus === 'closed' || serverStatus === 'no_quote') {
|
||||||
|
return serverStatus
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isStoreClosed()) {
|
if (isOutsideGlobalStoreHours()) {
|
||||||
return 'closed'
|
if (!shouldShowHomePriceWhenClosed()) return 'closed'
|
||||||
|
return hasShowableHomePrice(p) ? 'open' : 'no_quote'
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!hasLivePriceQuote()) {
|
if (hasLiveQuote(p)) return 'open'
|
||||||
return 'closed'
|
if (shouldShowLastSavedPrice() && hasShowableHomePrice(p)) return 'open'
|
||||||
}
|
if (hasShowableHomePrice(p)) return 'open'
|
||||||
|
|
||||||
return 'open'
|
return 'no_quote'
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* اسکلتون تا وقتی قیمت قابلنمایش برسد، یا وضعیت بسته قطعی شود،
|
||||||
|
* یا بعد از اولین پاسخ خالی پنجرهٔ settle تمام شود (مظنه واقعاً نیست).
|
||||||
|
*/
|
||||||
|
export function isHomeQuotePending(): boolean {
|
||||||
|
const settings = useSettingsStore()
|
||||||
|
void lastPriceReady.value
|
||||||
|
void lastPrice.value
|
||||||
|
void isLastPriceAbsenceSettled()
|
||||||
|
void settings.loaded
|
||||||
|
void settings.settingsRevision
|
||||||
|
|
||||||
|
if (!settings.loaded || !lastPriceReady.value) return true
|
||||||
|
if (hasShowableHomePrice(lastPrice.value)) return false
|
||||||
|
if (lastPrice.value?.status === 'closed') return false
|
||||||
|
return !isLastPriceAbsenceSettled()
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getPriceDisplayMessage(state: PriceDisplayState = getPriceDisplayState()): string {
|
export function getPriceDisplayMessage(state: PriceDisplayState = getPriceDisplayState()): string {
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
/**
|
||||||
|
* نگاشت منو/مسیر اپ کاربر → کلید دسترسی سوپرادمین.
|
||||||
|
* مقدار false/غایب = مخفی (پیشفرض امن).
|
||||||
|
*/
|
||||||
|
export const ROUTE_FEATURE_SETTING: Record<string, string> = {
|
||||||
|
fund: 'enable_product_funds',
|
||||||
|
fund_info: 'enable_product_funds',
|
||||||
|
fund_add: 'enable_product_funds',
|
||||||
|
piggy: 'enable_product_funds',
|
||||||
|
earnMoney: 'has_page_earn_money',
|
||||||
|
giftCard: 'has_page_gift_card',
|
||||||
|
notifyTrigger: 'has_page_price_trigger',
|
||||||
|
appNotifications: 'has_page_notification',
|
||||||
|
conditionalOrder: 'enable_conditional_order',
|
||||||
|
permissions: 'permision__enabled',
|
||||||
|
}
|
||||||
|
|
||||||
|
export const MENU_ID_FEATURE_SETTING: Record<string, string> = {
|
||||||
|
fund: 'enable_product_funds',
|
||||||
|
piggy: 'enable_product_funds',
|
||||||
|
earnMoney: 'has_page_earn_money',
|
||||||
|
giftCard: 'has_page_gift_card',
|
||||||
|
notify: 'has_page_price_trigger',
|
||||||
|
notifyTrigger: 'has_page_price_trigger',
|
||||||
|
conditionalOrder: 'enable_conditional_order',
|
||||||
|
permissions: 'permision__enabled',
|
||||||
|
}
|
||||||
|
|
||||||
|
export function featureSettingForRoute(routeName: string | null | undefined): string | null {
|
||||||
|
if (!routeName) return null
|
||||||
|
return ROUTE_FEATURE_SETTING[String(routeName)] ?? null
|
||||||
|
}
|
||||||
|
|
||||||
|
export function featureSettingForMenuId(id: string | null | undefined): string | null {
|
||||||
|
if (!id) return null
|
||||||
|
return MENU_ID_FEATURE_SETTING[String(id)] ?? null
|
||||||
|
}
|
||||||