price calulator changed 7
This commit is contained in:
@@ -50,6 +50,7 @@ export function useFormat(num: string | number, unit = '') {
|
||||
type TransactionPriceSource = {
|
||||
cash?: number | null
|
||||
gold?: number | null
|
||||
type?: number | null
|
||||
order?: {
|
||||
price?: number | null
|
||||
total_price?: number | null
|
||||
@@ -118,6 +119,10 @@ export function resolveTransactionStatusLabel(item?: TransactionPriceSource | nu
|
||||
return 'موفق'
|
||||
}
|
||||
|
||||
if (item.order_id && (item.type === 1 || item.type === 2 || item.type === 10)) {
|
||||
return 'موفق'
|
||||
}
|
||||
|
||||
return ''
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { computed, inject, onMounted, provide, ref, type ComponentPublicInstance, type InjectionKey } from 'vue'
|
||||
import { computed, inject, onActivated, onMounted, provide, ref, type ComponentPublicInstance, type InjectionKey } from 'vue'
|
||||
import { useIntersectionObserver } from '@vueuse/core'
|
||||
import { useDesktopBreakpoint } from '@/layouts/composables/useAppLayout'
|
||||
import { getProductsCatalog, getProductsCatalogRef } from '@/composables/useProductsCatalog'
|
||||
@@ -181,13 +181,10 @@ export function useTransactionsPageProvider(options?: { boursecu?: boolean }) {
|
||||
if (isBoursecu) {
|
||||
await getProductsCatalog()
|
||||
}
|
||||
await initTransactionsPageData(isBoursecu)
|
||||
})
|
||||
|
||||
const modeMatches = transactionsBoursecuMode.value === isBoursecu
|
||||
if (!initialized.value || !modeMatches) {
|
||||
await initTransactionsPageData(isBoursecu, !modeMatches)
|
||||
return
|
||||
}
|
||||
|
||||
onActivated(async () => {
|
||||
await reloadTransactionsTable()
|
||||
})
|
||||
|
||||
|
||||
@@ -11,10 +11,8 @@ import {
|
||||
type BoursecuTransactionTabId,
|
||||
} from '../config/boursecuTabs'
|
||||
|
||||
/** Shared transactions datasets — mobile/desktop views read this module state only. */
|
||||
let initPromise: Promise<void> | null = null
|
||||
let fetchSeq = 0
|
||||
const initialized = ref(false)
|
||||
/** Shared transactions page state — refetched on every page visit (no list cache). */
|
||||
let activeFetchId = 0
|
||||
|
||||
export const transactionsBoursecuMode = ref(false)
|
||||
export const transactionPagination = ref<TableEngineInput>({ filters: [], limit: 7, page: 0 })
|
||||
@@ -28,10 +26,6 @@ export const transactionProductFilter = ref<number>()
|
||||
export const transactionActiveTabId = ref<BoursecuTransactionTabId>('trades')
|
||||
export const transactionTradeSide = ref<BoursecuTradeSide>('buy')
|
||||
|
||||
export function isTransactionsPageDataInitialized() {
|
||||
return initialized.value
|
||||
}
|
||||
|
||||
export function getActiveBoursecuTab(): BoursecuTransactionTab {
|
||||
return (
|
||||
BOURSECU_TRANSACTION_TABS.find((tab) => tab.id === transactionActiveTabId.value) ??
|
||||
@@ -66,26 +60,28 @@ export function resetTransactionsPagination() {
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchTransactionsPage(append: boolean) {
|
||||
const seq = ++fetchSeq
|
||||
function resolveTransactionFetcher() {
|
||||
const activeTab = getActiveBoursecuTab()
|
||||
return transactionsBoursecuMode.value && activeTab.fetchMode === 'deposit'
|
||||
? getTransactionTable2
|
||||
: getTransactionTable
|
||||
}
|
||||
|
||||
async function fetchTransactionsPage(append: boolean): Promise<boolean> {
|
||||
const fetchId = ++activeFetchId
|
||||
const isFirstPage = transactionPagination.value.page === 0 && !append
|
||||
|
||||
if (isFirstPage) {
|
||||
loading.value = true
|
||||
loadingMore.value = false
|
||||
} else {
|
||||
loadingMore.value = true
|
||||
}
|
||||
|
||||
try {
|
||||
const activeTab = getActiveBoursecuTab()
|
||||
const fetcher =
|
||||
transactionsBoursecuMode.value && activeTab.fetchMode === 'deposit'
|
||||
? getTransactionTable2
|
||||
: getTransactionTable
|
||||
|
||||
const output = await fetcher(transactionPagination.value)
|
||||
if (seq !== fetchSeq) {
|
||||
return
|
||||
const output = await resolveTransactionFetcher()(transactionPagination.value)
|
||||
if (fetchId !== activeFetchId) {
|
||||
return false
|
||||
}
|
||||
|
||||
transactionTableOutput.value = output
|
||||
@@ -96,20 +92,23 @@ async function fetchTransactionsPage(append: boolean) {
|
||||
} else {
|
||||
transactionItems.value.push(...rows)
|
||||
}
|
||||
|
||||
return true
|
||||
} catch (error) {
|
||||
if (seq === fetchSeq) {
|
||||
if (fetchId === activeFetchId) {
|
||||
console.error('Error fetching transactions:', error)
|
||||
}
|
||||
return false
|
||||
} finally {
|
||||
if (seq === fetchSeq) {
|
||||
if (fetchId === activeFetchId) {
|
||||
loading.value = false
|
||||
loadingMore.value = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** همیشه از سرور — بدون کش لیست */
|
||||
export async function reloadTransactionsTable() {
|
||||
fetchSeq += 1
|
||||
transactionPagination.value.page = 0
|
||||
transactionItems.value = []
|
||||
transactionTableOutput.value = null
|
||||
@@ -134,41 +133,16 @@ export async function loadMoreTransactions() {
|
||||
await fetchTransactionsPage(true)
|
||||
}
|
||||
|
||||
export async function initTransactionsPageData(boursecu: boolean, force = false) {
|
||||
if (!force && initialized.value && transactionsBoursecuMode.value === boursecu) {
|
||||
return
|
||||
}
|
||||
|
||||
if (!force && initPromise) {
|
||||
return initPromise
|
||||
}
|
||||
|
||||
initPromise = (async () => {
|
||||
try {
|
||||
if (force) {
|
||||
resetTransactionsPageData()
|
||||
}
|
||||
|
||||
transactionsBoursecuMode.value = boursecu
|
||||
transactionPagination.value.page = 0
|
||||
transactionItems.value = []
|
||||
resetTransactionsPagination()
|
||||
await fetchTransactionsPage(false)
|
||||
initialized.value = true
|
||||
} catch (error) {
|
||||
console.error('Transactions page initialization error:', error)
|
||||
} finally {
|
||||
initPromise = null
|
||||
}
|
||||
})()
|
||||
|
||||
return initPromise
|
||||
/** هر بار ورود به صفحه تراکنشها */
|
||||
export async function initTransactionsPageData(boursecu: boolean) {
|
||||
transactionsBoursecuMode.value = boursecu
|
||||
await reloadTransactionsTable()
|
||||
}
|
||||
|
||||
export function resetTransactionsPageData() {
|
||||
fetchSeq += 1
|
||||
initialized.value = false
|
||||
initPromise = null
|
||||
activeFetchId += 1
|
||||
loading.value = false
|
||||
loadingMore.value = false
|
||||
transactionsBoursecuMode.value = false
|
||||
transactionPagination.value = { filters: [], limit: 7, page: 0 }
|
||||
transactionItems.value = []
|
||||
|
||||
Reference in New Issue
Block a user