diff --git a/src/api/product.ts b/src/api/product.ts index 17511f8..ca6afb2 100644 --- a/src/api/product.ts +++ b/src/api/product.ts @@ -8,6 +8,8 @@ export const createProduct = async (obj: Customer) => await useAxios.post(`/admin/product`, obj) export const deleteCustomer = async (id: number) => await useAxios.delete(`/admin/product/${id}`) + +export const archiveProduct = async (id: number) => await useAxios.delete(`/admin/product/${id}`) export const updateCustomer = async (id: number, obj: Customer) => await useAxios.put(`/admin/product/${id}`, obj) diff --git a/src/components/BasicActionSheet.vue b/src/components/BasicActionSheet.vue index 63fdf40..72d12fc 100644 --- a/src/components/BasicActionSheet.vue +++ b/src/components/BasicActionSheet.vue @@ -19,7 +19,7 @@ > { @@ -15,14 +11,11 @@ configReject = reject; }); - const VERSION_URL = 'https://abshode-service.montgit.ir/server/get_version'; - const CONFIG_URLS = [ - 'https://nerkh.gold/get_user', - 'https://abshode-service.montgit.ir/server/get_user' - ]; + const VERSION_SUCCESS_URL_KEY = 'VERSION_Success_URL'; const CONFIG_SUCCESS_URL_KEY = 'CONFIG_Success_URL'; + const VERSION_RETRY_ROUNDS = 5; + const CONFIG_RETRY_ROUNDS = 5; - // Timeout to ensure main.ts loads even if config fails const CONFIG_TIMEOUT = 12000; let configTimeoutId; let mainScriptLoaded = false; @@ -31,6 +24,40 @@ return window.location.protocol === 'https:' ? 'https:' : 'http:'; } + function getVersionUrls() { + const protocol = getProtocol(); + + 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 getConfigUrls() { + const protocol = getProtocol(); + + return [ + protocol + '//nerkh.gold/get_user', + protocol + '//tablo.talasevin.ir/get_user', + protocol + '//abshode-service.montgit.ir/server/get_user', + protocol + '//212.23.201.173:8381/get_user', + protocol + '//91.212.174.137:4040/server/get_user' + ]; + } + + function sortVersionUrls(urls) { + const lastSuccessUrl = localStorage.getItem(VERSION_SUCCESS_URL_KEY); + + if (!lastSuccessUrl) { + return urls.slice(); + } + + return [lastSuccessUrl].concat(urls.filter((url) => url !== lastSuccessUrl)); + } + function sortConfigUrls(urls) { const lastSuccessUrl = localStorage.getItem(CONFIG_SUCCESS_URL_KEY); @@ -41,6 +68,12 @@ }); } + function clearStaleSuccessUrl(key, url) { + if (localStorage.getItem(key) === url) { + localStorage.removeItem(key); + } + } + async function fetchJson(url, timeout = 3500) { const controller = new AbortController(); const timeoutId = window.setTimeout(() => controller.abort(), timeout); @@ -72,36 +105,50 @@ } } - async function loadVersion() { - try { - await fetchJson(VERSION_URL, 3500); - console.log('Version loaded from:', VERSION_URL); - } catch (error) { - console.warn('Version check failed from', VERSION_URL, error); + async function loadVersion(rounds = VERSION_RETRY_ROUNDS) { + const urls = sortVersionUrls(getVersionUrls()); + + for (let round = 1; round <= rounds; round++) { + for (let index = 0; index < urls.length; index++) { + const url = urls[index]; + const timeout = index === urls.length - 1 ? 6000 : 3500; + + try { + await fetchJson(url, timeout); + localStorage.setItem(VERSION_SUCCESS_URL_KEY, url); + console.log('Version loaded from:', url); + return; + } catch (error) { + clearStaleSuccessUrl(VERSION_SUCCESS_URL_KEY, url); + console.warn('Version failed from', url, 'round:', round, error); + } + } } + + console.warn('Version check failed from all endpoints'); } - async function fetchConfig() { - const protocol = getProtocol(); - const urls = sortConfigUrls( - CONFIG_URLS.map((url) => url.replace(/^https?:/, protocol)) - ); + async function fetchConfig(rounds = CONFIG_RETRY_ROUNDS) { + const urls = sortConfigUrls(getConfigUrls()); - for (let index = 0; index < urls.length; index++) { - const url = urls[index]; - const timeout = index === urls.length - 1 ? 5000 : 3500; + for (let round = 1; round <= rounds; round++) { + for (let index = 0; index < urls.length; index++) { + const url = urls[index]; + const timeout = index === urls.length - 1 ? 7000 : 4000; - try { - const config = await fetchJson(url, timeout); + try { + const config = await fetchJson(url, timeout); - if (!config || typeof config !== 'object') { - throw new Error('Config response is invalid'); + if (!config || typeof config !== 'object') { + throw new Error('Config response is invalid'); + } + + localStorage.setItem(CONFIG_SUCCESS_URL_KEY, url); + return { config, url }; + } catch (error) { + clearStaleSuccessUrl(CONFIG_SUCCESS_URL_KEY, url); + console.warn('Config failed from', url, 'round:', round, error); } - - localStorage.setItem(CONFIG_SUCCESS_URL_KEY, url); - return { config, url }; - } catch (error) { - console.warn('Config failed from', url, error); } } @@ -148,7 +195,6 @@ loadMainScript(); } - // Fetch config from server async function loadConfig() { try { await loadVersion(); @@ -169,57 +215,24 @@ } } - // Function to dynamically load main.ts script function loadMainScript() { - //const config= window.__APP_CONFIG__ - // Check if main.ts is already loaded if (mainScriptLoaded || document.querySelector('script[src="/src/main.ts"]')) { return; } mainScriptLoaded = true; - /*const manifestLink = document.createElement("link") - manifestLink.rel = "manifest" - manifestLink.id= "manifestsdfsdfsdfsdfsdfsdf" - manifestLink.href = `https://nerkh.gold/get_user/${config.user.id}/monifist.json` - - document.head.appendChild(manifestLink)*/ - - import('/src/main.ts').then(() => { console.log('Main script loaded and executed'); }); - - /*const script = document.createElement('script'); - script.type = 'module'; - script.src = '/src/main.ts'; - script.async = true;*/ - - // Handle script load errors - /*script.onerror = function() { - console.error('Failed to load main.ts script'); - mainScriptLoaded = false; - }; - - script.onload = function() { - console.log('Main script loaded successfully'); - }; - - document.body.appendChild(script);*/ - - //console.log('Main script loading started...'); } - // Set timeout to ensure main.ts loads even if config fails configTimeoutId = setTimeout(function() { if (!mainScriptLoaded) { console.warn('Config loader: Timeout reached. Loading main.ts with empty config.'); - // Set default empty config window.__APP_CONFIG__ = window.__APP_CONFIG__ || {}; window.__CONFIG_READY__ = true; - // Resolve promise with empty config if (configResolve) { configResolve({}); } @@ -228,7 +241,5 @@ } }, CONFIG_TIMEOUT); - // Start loading config immediately loadConfig(); })(); - diff --git a/src/constants/overlayZIndex.ts b/src/constants/overlayZIndex.ts index 71bb2a7..b53d869 100644 --- a/src/constants/overlayZIndex.ts +++ b/src/constants/overlayZIndex.ts @@ -6,3 +6,6 @@ export const MODAL_ABOVE_ACTION_SHEET_Z_INDEX = 1100 /** z-index برای dropdown سلکت‌ها داخل مودال (باید بالاتر از مودال باشد) */ export const SELECT_DROPDOWN_Z_INDEX = MODAL_ABOVE_ACTION_SHEET_Z_INDEX + 100 + +/** z-index برای tooltip راهنما داخل مودال (باید از override جدول‌ها و خود مودال بالاتر باشد) */ +export const TOOLTIP_ABOVE_MODAL_Z_INDEX = SELECT_DROPDOWN_Z_INDEX + 50 diff --git a/src/model/dashboard.ts b/src/model/dashboard.ts index 61d8a1f..741e085 100644 --- a/src/model/dashboard.ts +++ b/src/model/dashboard.ts @@ -37,6 +37,8 @@ export interface DashboardFinance { fullPriceSood?: number fullPriceKarmozd?: number fullPriceKaermozd?: number + /** سود اسپرد + کارمزد */ + totalTradingProfit?: number orderCount?: number Gifts?: string GiftsPrise?: number diff --git a/src/model/wallet.ts b/src/model/wallet.ts index aa7b9b2..95209f0 100644 --- a/src/model/wallet.ts +++ b/src/model/wallet.ts @@ -1,5 +1,7 @@ import type { User } from '@/model/user' +export type WalletKind = 'main' | 'product' | 'fund' + export interface WalletMetalBalance { metal_id: number label: string @@ -8,6 +10,20 @@ export interface WalletMetalBalance { display_unit?: string } +export interface WalletProductSummary { + id?: number + title?: string + group_type?: string + unit?: string + amount?: number | string + metal_id?: number +} + +export interface WalletFundSummary { + id?: number + title?: string +} + export interface Wallet { owner: number id: number @@ -17,6 +33,22 @@ export interface Wallet { product_id?: number | null metal_gold?: Record customer: User + product?: WalletProductSummary | null + fund?: WalletFundSummary | null + wallet_kind?: WalletKind + wallet_kind_label?: string + wallet_subject?: string + product_title?: string | null + product_group_type?: string | null + product_unit?: string | null + product_amount?: number | string | null + fund_title?: string | null + wallet_metal_id?: number + wallet_metal_label?: string + gold_to_cash?: number + gold_grams?: number + total_rial_value?: number + created_at?: string } export interface WalletTableSums { @@ -43,6 +75,8 @@ export interface Withdraw { tracked_number?: string date_at?: string sts?: number + type?: number + bank_account_id?: number | null created_at?: string updated_at?: string sts_str?: string diff --git a/src/pages/dashboard/components/DashboardHelpTip.vue b/src/pages/dashboard/components/DashboardHelpTip.vue index 9a1db4d..70fe96c 100644 --- a/src/pages/dashboard/components/DashboardHelpTip.vue +++ b/src/pages/dashboard/components/DashboardHelpTip.vue @@ -1,18 +1,17 @@