Merge remote-tracking branch 'origin/modular' into modular

This commit is contained in:
2026-07-05 11:26:04 +02:00
28 changed files with 1314 additions and 446 deletions
@@ -48,7 +48,6 @@ import BasicSelect from '@/components/BasicPacks/BasicSelect.vue'
import BasicButton from '@/components/BasicPacks/BasicButton.vue'
import BasicInput from '@/components/BasicPacks/BasicInput.vue'
import BasicTextArea from '@/components/BasicPacks/BasicTextArea.vue'
import { loading } from '@/utils'
import { createAddress, getCity, updateAddress } from '@/api/address'
import { FormInstance, message } from 'ant-design-vue'
import { Address } from '@/models/address'
@@ -130,14 +129,11 @@ const changeProvince = async (obj: any) => {
return
}
try {
loading.value = true
cityList.value = undefined
address.value.city = undefined
cityList.value = await getCity(obj.id)
} catch (e) {
message.error('خطا در دریافت شهرها')
} finally {
loading.value = false
}
}
@@ -98,14 +98,11 @@ export function useAddressPage() {
const changeProvince = async (obj: { id: number }) => {
try {
loading.value = true
cityList.value = undefined
address.value.city = undefined
cityList.value = await getCity(obj.id)
} catch (e) {
message.error('خطا در دریافت شهرها')
} finally {
loading.value = false
}
}
+35 -14
View File
@@ -232,9 +232,11 @@ import type { Product } from '@/models/products'
import { useFundUserStore } from '@/store/fundStore'
import {useConfigStore} from "@/store/configStore";
import { calcFeeInGrams, calcPayablePriceRial, calcSellGoldDebit, feeDeductFromGold, loadServiceFeeFromSettings } from '@/utils/serviceFee'
import { resolveProductCashFeeBuyRial, resolveProductCashFeeSellRial } from '@/utils/productCashFee'
import { formatCashWalletBalanceText, formatGoldWalletBalanceText } from '@/utils/productDealMethod'
import { getCashWalletBalance } from '@/utils/productAssets'
import { isStoreClosed, getStoreClosedMessage } from '@/utils/storeHours'
import { resetTransactionsPageData } from '@/views/base/transactions/composables/useTransactionsPageData'
const infoVisible = ref(false)
const walletStore = useWalletStore()
@@ -282,13 +284,12 @@ const basePriceValue = computed(() => {
const product = props?.ProductItem
if (!product) return undefined
const { price_profit = 0, price = 0, cash_fee_buy = 0, cash_fee_sell = 0 } = product
const { price_profit = 0, price = 0 } = product
const base = price_profit + price
const buyFee = resolveProductCashFeeBuyRial(product, base)
const sellFee = resolveProductCashFeeSellRial(product, base)
const rawPrice = isBuy.value
? base + cash_fee_buy
: base - cash_fee_sell
return rawPrice
return isBuy.value ? base + buyFee : base - sellFee
})
const finalPrice = computed(() => {
@@ -298,15 +299,17 @@ const finalPrice = computed(() => {
const product = props?.ProductItem
if (!product) return 0
const { price_profit = 0, price = 0, cash_fee_buy = 0, cash_fee_sell = 0 } = product
const { price_profit = 0, price = 0 } = product
const base = price_profit + price
const buyFee = resolveProductCashFeeBuyRial(product, base)
const sellFee = resolveProductCashFeeSellRial(product, base)
if (isBuy.value) {
return gold * (base + cash_fee_buy)
} else {
return gold * (base - cash_fee_sell)
return gold * (base + buyFee)
}
return gold * (base - sellFee)
})
const payablePrice = computed(() =>
@@ -532,20 +535,30 @@ watch(
}
)
function productFeeBase(product?: Product) {
return (product?.price_profit ?? 0) + (product?.price ?? 0)
}
function calculateCash(val: number) {
priceErrorVisible.value = false
if (!lastPrice.value) return
const product = props?.ProductItem
if (!product) return
const base = productFeeBase(product)
const buyFee = resolveProductCashFeeBuyRial(product, base)
const sellFee = resolveProductCashFeeSellRial(product, base)
const tradeBuy = getTradeBuyPrice(lastPrice.value)
form.value.goldVazn = parseFloat((val * ((props?.ProductItem?.price) + (props?.ProductItem?.cash_fee_buy))) / tradeBuy).toFixed(1)
form.value.goldVazn = parseFloat(String((val * (base + buyFee)) / tradeBuy)).toFixed(1)
if (isBuy.value) {
form.value.goldCash = val
? parseFloat(String(val * ((props?.ProductItem?.price) + (props?.ProductItem?.cash_fee_buy))))
? parseFloat(String(val * (base + buyFee)))
: 0
if (!val) form.value.goldVazn = 0
} else {
form.value.goldCash = val
? parseFloat(String((val * props?.ProductItem?.price) - (props?.ProductItem?.cash_fee_sell)))
? parseFloat(String(val * base - sellFee))
: 0
if (!val) form.value.goldVazn = 0
}
@@ -553,9 +566,16 @@ function calculateCash(val: number) {
function calculateGold(val: number) {
if (price.value) {
const product = props?.ProductItem
if (!product) return
const base = productFeeBase(product)
const buyFee = resolveProductCashFeeBuyRial(product, base)
const sellFee = resolveProductCashFeeSellRial(product, base)
if (isBuy.value) {
if (val) {
form.value.goldValue = toFixedDownThreeChar(parseFloat(val / (((props?.ProductItem?.price_profit) + (props?.ProductItem?.price)) + (props?.ProductItem?.cash_fee_buy))))
form.value.goldValue = toFixedDownThreeChar(parseFloat(String(val / (base + buyFee))))
if (parseInt(finalPrice.value) > 0) priceErrorVisible.value = true
if (parseInt(finalPrice.value) === 0) priceErrorVisible.value = false
}
@@ -570,7 +590,7 @@ function calculateGold(val: number) {
}
else {
if (val) {
form.value.goldValue = toFixedDownThreeChar(parseFloat(val / (((props?.ProductItem?.price_profit) + (props?.ProductItem?.price)) + (props?.ProductItem?.cash_fee_sell))))
form.value.goldValue = toFixedDownThreeChar(parseFloat(String(val / (base - sellFee))))
if (parseInt(finalPrice.value) > 0) priceErrorVisible.value = true
if (parseInt(finalPrice.value) === 0) priceErrorVisible.value = false
} else if (val.toString() === '') {
@@ -658,6 +678,7 @@ async function ok() {
})
confirmAction.value = false
await walletStore.getMyWallet()
resetTransactionsPageData()
await router.push({ name: 'transactions' })
form.value = {
goldValue: undefined,
+84 -60
View File
@@ -102,20 +102,6 @@
@change="percentChange" />
</a-form-item>
</Transition>
<!-- <Transition mode="out-in" name="fade">
<div v-if="priceErrorVisible" class="flex gap-1 items-center text-xs mt-[-15px] text-orange-600">
<BasicIcon icon="vuesax-linear:danger" />
ارزش کل وارد شده بر حسب گرم طلا محاسبه خواهد شد و قیمت وارد شده معادل {{ usePrice(finalPrice) }} می
باشد!
</div>
</Transition>-->
<Transition mode="out-in" name="fade">
<div v-if="priceErrorVisible" class="flex gap-1 items-center text-xs mt-[-15px] text-blue-600">
<BasicIcon icon="vuesax-linear:info-circle" />
ارزش کل وارد شده بر حسب گرم طلا محاسبه خواهد شد و قیمت وارد شده معادل {{ usePrice(parseInt(finalPrice.toFixed(0))) }} می
باشد!
</div>
</Transition>
</div>
</div>
<GoldLoading v-model:show="infoVisible" />
@@ -173,7 +159,7 @@
<div class="flex justify-between ">
<div>وزن:</div>
<div class="flex items-center">
<div class="font-bold">{{ form.goldValue }}</div>
<div class="font-bold">{{ displayTradeGoldAmount }}</div>
<div class="text-xs mr-1">{{ weightUnit }}</div>
</div>
</div>
@@ -195,7 +181,7 @@
<div v-if="isBuy && feeDeductFromGold" class="flex justify-between mt-3">
<div>طلا دریافتی:</div>
<div class="flex items-center">
<div class="font-bold">{{ form.goldValue }}</div>
<div class="font-bold">{{ displayTradeGoldAmount }}</div>
<div class="text-xs mr-1">{{ weightUnit }} (دقیق — کارمزد از ریال)</div>
</div>
</div>
@@ -214,7 +200,14 @@
</div>
</div>
</div>
<BasicButton class="mb-20 mt-5 w-full" type="primary" @click="ok(); confirmAction= false">ثبت نهایی</BasicButton>
<BasicButton
class="mb-20 mt-5 w-full"
type="primary"
:disabled="loading"
@click="ok"
>
ثبت نهایی
</BasicButton>
</BasicActionSheet>
<BasicModal
v-else
@@ -228,7 +221,7 @@
<div class="flex justify-between ">
<div>وزن:</div>
<div class="flex items-center">
<div class="font-bold">{{ form.goldValue }}</div>
<div class="font-bold">{{ displayTradeGoldAmount }}</div>
<div class="text-xs mr-1">{{ weightUnit }}</div>
</div>
</div>
@@ -250,7 +243,7 @@
<div v-if="isBuy && feeDeductFromGold" class="flex justify-between mt-3">
<div>طلا دریافتی:</div>
<div class="flex items-center">
<div class="font-bold">{{ form.goldValue }}</div>
<div class="font-bold">{{ displayTradeGoldAmount }}</div>
<div class="text-xs mr-1">{{ weightUnit }} (دقیق — کارمزد از ریال)</div>
</div>
</div>
@@ -269,7 +262,7 @@
</div>
</div>
</div>
<BasicButton class="mt-5 w-full" type="primary" @click="ok(); confirmAction = false">
<BasicButton class="mt-5 w-full" type="primary" :disabled="loading" @click="ok">
ثبت نهایی
</BasicButton>
<template #footer>
@@ -299,7 +292,7 @@ import img1 from '@/assets/img/home_ly2.svg'
import { usePrice, usePriceWithoutType } from '@/utils/usePrice'
import BasicInput from '@/components/BasicPacks/BasicInput.vue'
import type { Gold } from '@/models/gold'
import { isIphone, loading, loadingMore, toFixedDownThreeChar } from '@/utils'
import { isIphone, loading, loadingMore } from '@/utils'
import BasicButton from '@/components/BasicPacks/BasicButton.vue'
import router from '@/router'
import { useWalletStore } from '@/store/walletStore'
@@ -330,8 +323,24 @@ import { getLastPrices, getTradeBuyPrice, getTradeSellPrice, lastPrice } from '@
import type { Product } from '@/models/products'
import { useFundUserStore } from '@/store/fundStore'
import {useConfigStore} from "@/store/configStore";
import { calcFeeInGrams, calcOrderGoldAmount, calcPayablePriceRial, calcSellGoldDebit, calcSellTargetCash, feeDeductFromGold, loadServiceFeeFromSettings } from '@/utils/serviceFee'
import {
calcFeeInGrams,
calcGramFromLockedRial,
calcOrderGoldAmount,
calcPayablePriceRial,
calcRialFromLockedGram,
calcSellGoldDebit,
calcSellTargetCash,
calcTradeTargetCash,
feeDeductFromGold,
formatTradeGramDisplay,
loadServiceFeeFromSettings,
normalizeOrderGoldAmount,
serviceFeePercentage,
type TradeInputLock,
} from '@/utils/serviceFee'
import { isStoreClosed, getStoreClosedMessage } from '@/utils/storeHours'
import { resetTransactionsPageData } from '@/views/base/transactions/composables/useTransactionsPageData'
import { formatCashWalletBalanceText, getWeightUnit } from '@/utils/productDealMethod'
import { formatProductWalletBalanceText, getCashWalletBalance, getProductInventoryQuantity } from '@/utils/productAssets'
import { useWalletAssets } from '@/composables/useWalletAssets'
@@ -359,7 +368,6 @@ const confirmAction = ref<boolean>(false)
const noCompleteVisible = ref<boolean>(false)
const buyItems = ref<Transaction[]>([])
const sellItems = ref<Transaction[]>([])
const priceErrorVisible = ref<boolean>(false)
const buyTableOutput = ref<TableOutput<Transaction> | null>(null)
const sellTableOutput = ref<TableOutput<Transaction> | null>(null)
const el = ref()
@@ -386,6 +394,7 @@ const contentClass = computed(() => {
return 'mt-5 px-3 pb-4'
})
const isBuy = ref<boolean>(true)
const inputLock = ref<TradeInputLock>(null)
const tradeProductLabel = computed(() => {
const title = props.ProductItem?.title?.trim()
@@ -436,7 +445,13 @@ const unitPrice = computed(() => {
return isBuy.value ? getTradeBuyPrice(lastPrice.value) : getTradeSellPrice(lastPrice.value)
})
const orderGoldAmount = computed(() =>
calcOrderGoldAmount(form.value?.goldValue, form.value?.goldCash, unitPrice.value, isBuy.value)
calcOrderGoldAmount(
form.value?.goldValue,
form.value?.goldCash,
unitPrice.value,
isBuy.value,
inputLock.value
)
)
const feeInGrams = computed(() => calcFeeInGrams(orderGoldAmount.value))
const finalPrice = computed(() => orderGoldAmount.value * unitPrice.value)
@@ -447,11 +462,15 @@ const payablePrice = computed(() =>
finalPrice.value,
feeInRial.value,
isBuy.value,
!isBuy.value ? form.value?.goldCash : undefined
inputLock.value === 'rial' ? form.value?.goldCash : undefined
)
)
const sellGoldDebit = computed(() => calcSellGoldDebit(orderGoldAmount.value, feeInGrams.value))
const displayTradeGoldAmount = computed(() =>
formatTradeGramDisplay(orderGoldAmount.value)
)
const minOrderCash = computed(() => productMinOrderCash(props.ProductItem, isBuy.value))
const maxOrderCash = computed(() => productMaxOrderCash(props.ProductItem))
const cashValidationMessage = computed(() =>
@@ -620,20 +639,18 @@ onMounted(() => {
})
function percentChange(val: number) {
if (val !== 0)
if (val !== 0) {
if (isBuy.value) {
form.value.goldCash = unitCashCalculator.value * val
calculateGold(form.value.goldCash)
calculateCash(form.value.goldValue)
} else {
// console.log((unitGoldCalculator.value * val).toFixed(2))
// form.value.goldValue = parseFloat((unitGoldCalculator.value * val).toFixed(2))
form.value.goldValue = toFixedDownThreeChar(parseFloat(unitGoldCalculator.value * val))
form.value.goldValue = formatTradeGramDisplay(parseFloat(String(unitGoldCalculator.value * val)))
calculateCash(form.value.goldValue)
}
else {
} else {
form.value.goldValue = undefined
form.value.goldCash = undefined
inputLock.value = null
}
}
@@ -645,11 +662,13 @@ const unitCashCalculator = computed(() => {
function syncFormWithLatestPrice() {
const unit = unitPrice.value
if (!unit || Number.isNaN(unit)) return
if (!unit || Number.isNaN(unit) || !inputLock.value) return
const goldValue = form.value.goldValue
if (goldValue !== undefined && goldValue !== null && goldValue !== '' && !isNaN(Number(goldValue))) {
calculateCash(Number(goldValue))
if (inputLock.value === 'gram') {
const goldValue = form.value.goldValue
if (goldValue !== undefined && goldValue !== null && goldValue !== '' && !isNaN(Number(goldValue))) {
calculateCash(Number(goldValue))
}
return
}
@@ -666,42 +685,36 @@ watch(
}
)
watch([feeDeductFromGold, () => serviceFeePercentage.value], () => {
syncFormWithLatestPrice()
})
function calculateCash(val: number) {
priceErrorVisible.value = false
inputLock.value = 'gram'
const unit = unitPrice.value
if (!unit || Number.isNaN(unit)) return
form.value.goldCash = val ? parseFloat((val * unit).toFixed(0)) : undefined
if (val === undefined || val === null || Number.isNaN(val)) {
form.value.goldCash = undefined
inputLock.value = null
return
}
form.value.goldCash = calcRialFromLockedGram(val, unit, isBuy.value)
}
function calculateGold(val: number) {
inputLock.value = 'rial'
const unit = unitPrice.value
if (!unit || Number.isNaN(unit)) return
if (isBuy.value) {
if (val) {
form.value.goldValue = toFixedDownThreeChar(parseFloat(String(val / unit)))
priceErrorVisible.value = parseInt(String(finalPrice.value)) > 0
} else if (val.toString() === '') {
form.value.goldValue = undefined
priceErrorVisible.value = false
} else {
form.value.goldValue = 0
priceErrorVisible.value = false
}
} else if (val) {
if (!isBuy.value && feeDeductFromGold.value) {
form.value.goldValue = parseFloat((val / unit).toFixed(6))
} else {
form.value.goldValue = toFixedDownThreeChar(parseFloat(String(val / unit)))
}
priceErrorVisible.value = parseInt(String(finalPrice.value)) > 0
if (val) {
form.value.goldValue = formatTradeGramDisplay(calcGramFromLockedRial(val, unit, isBuy.value))
} else if (val.toString() === '') {
form.value.goldValue = undefined
priceErrorVisible.value = false
inputLock.value = null
} else {
form.value.goldValue = 0
priceErrorVisible.value = false
}
}
@@ -724,7 +737,7 @@ function setIsBuy(val: boolean) {
form.value.goldValue = undefined
form.value.goldCash = undefined
form.value.percentWallet = 0
priceErrorVisible.value = false
inputLock.value = null
// console.log(bganim.value.classList)
// bganim?.value?.classList.add(val?'right':'left')
// bganim?.value?.style.transform = `translateX(${val ? '0' : '-100'});`
@@ -767,6 +780,9 @@ function okConfirm() {
}
async function ok() {
if (loading.value) {
return
}
if (isStoreClosed()) {
message.warning(getStoreClosedMessage())
return
@@ -777,19 +793,27 @@ async function ok() {
await createOrder({
direction: isBuy.value ? 1 : 2,
price: Math.round(unitPrice.value),
amount: orderGoldAmount.value,
target_cash: calcSellTargetCash(form.value.goldCash, form.value.goldValue, unitPrice.value),
amount: normalizeOrderGoldAmount(orderGoldAmount.value),
target_cash: calcTradeTargetCash(form.value.goldCash, inputLock.value)
?? calcSellTargetCash(
form.value.goldCash,
form.value.goldValue,
unitPrice.value,
inputLock.value
),
abshode_id: props.ProductItem?.id,
})
confirmAction.value = false
await walletStore.getMyWallet()
await loadWalletAssets(true)
resetTransactionsPageData()
await router.push({ name: 'transactions' })
form.value = {
goldValue: undefined,
goldCash: undefined,
percentWallet: undefined
}
inputLock.value = null
message.success('سفارش شما با موفقیت انجام شد')
await fundStore.getMyFund()
} catch (e) {
@@ -9,15 +9,13 @@
<div class="text-l mr-2 font-bold">{{ usePriceWithoutType(countBasedInventory, false) }} عدد</div>
</div>
<PortfolioOverview v-if="!boursecuLayout" variant="mobile" />
<BoursecuAssetsSummary
v-else-if="boursecuLayout"
v-if="boursecuLayout"
variant="mobile"
icon-color="primary"
/>
<template v-else-if="showLegacyRows && meta?.single_metal && primaryMetalTotal">
<template v-else-if="meta?.single_metal && primaryMetalTotal">
<div :class="[rowClass, meta?.has_count_based_products ? 'mt-2' : '']" class="flex justify-center w-full z-20">
{{ primaryMetalTotal.label }}:
<div class="text-l mr-2 font-bold">{{ formatMetalTotal(primaryMetalTotal) }}</div>
@@ -29,6 +27,8 @@
/>
</div>
<PortfolioProfitInsight variant="mobile" />
<div :class="[rowClass, 'mt-2']" class="flex justify-center w-full z-20">
دارایی ریالی:
<div class="text-l mr-2 font-bold">{{ usePriceWithoutType(cashWallet) }} ریال</div>
@@ -41,7 +41,7 @@
</div>
</template>
<template v-else-if="showLegacyRows && !boursecuLayout">
<template v-else-if="!boursecuLayout">
<div
v-for="(metal, index) in metalTotals"
:key="metal.metal_id"
@@ -59,6 +59,8 @@
/>
</div>
<PortfolioProfitInsight variant="mobile" />
<div :class="[rowClass, 'mt-2']" class="flex justify-center w-full z-20">
دارایی ریالی:
<div class="text-l mr-2 font-bold">{{ usePriceWithoutType(cashWallet) }} ریال</div>
@@ -77,7 +79,7 @@
import { computed } from 'vue'
import BasicIcon from '@/components/BasicPacks/BasicIcon.vue'
import BoursecuAssetsSummary from './BoursecuAssetsSummary.vue'
import PortfolioOverview from './PortfolioOverview.vue'
import PortfolioProfitInsight from './PortfolioProfitInsight.vue'
import { formatWeightAmount, usePriceWithoutType } from '@/utils/usePrice'
import { useWalletAssets } from '@/composables/useWalletAssets'
import type { WalletMetalTotal } from '@/models/walletAssets'
@@ -119,8 +121,6 @@ const inventoryCards = computed(() => assetsSummary.value?.inventory_cards ?? []
const countBasedInventory = computed(() =>
(assetsSummary.value?.count_products ?? []).reduce((sum, item) => sum + Number(item.quantity ?? 0), 0)
)
const showLegacyRows = computed(() => !assetsSummary.value?.portfolio)
function formatMetalTotal(metal: WalletMetalTotal) {
return `${formatWeightAmount(resolveSummaryMetalWeight(metal, inventoryCards.value))}${metal.unit}`
}
@@ -16,9 +16,21 @@
'portfolio-overview__profit--down': profitTone === 'loss',
}"
>
<span class="portfolio-overview__profit-amount">{{ profitText }}</span>
<span v-if="profitPercent" class="portfolio-overview__profit-percent">{{ profitPercent }}</span>
<span class="portfolio-overview__profit-hint">سود/زیان تحقق‌نیافته طلا</span>
<div class="portfolio-overview__profit-main">
<span class="portfolio-overview__profit-amount">{{ profitText }}</span>
<span v-if="profitPercent" class="portfolio-overview__profit-percent">{{ profitPercent }}</span>
</div>
<div class="portfolio-overview__profit-label">
<span class="portfolio-overview__profit-hint">سود/زیان تحقق‌نیافته طلا</span>
<button
type="button"
class="portfolio-overview__profit-info"
aria-label="اطلاعات بیشتر"
@click="openProfitInfo"
>
<BasicIcon icon="vuesax-linear:info-circle" size="14" color="tertiary" />
</button>
</div>
</div>
<div class="portfolio-overview__grid">
@@ -36,17 +48,16 @@
</article>
</div>
<p v-if="hasProfitInsight && averageBuyPrice" class="portfolio-overview__footnote">
بر اساس میانگین خرید {{ usePriceWithoutType(averageBuyPrice) }} ریال و قیمت فعلی
{{ usePriceWithoutType(liveGoldPrice) }} ریال
</p>
</section>
</template>
<script setup lang="ts">
import { computed } from 'vue'
import { computed, h } from 'vue'
import { Modal } from 'ant-design-vue'
import BasicIcon from '@/components/BasicPacks/BasicIcon.vue'
import { useWalletAssets } from '@/composables/useWalletAssets'
import {
formatPortfolioProfitInfoText,
formatPortfolioProfitLabel,
formatPortfolioProfitPercent,
formatPortfolioProfitText,
@@ -79,8 +90,6 @@ const metalRial = computed(() => {
return resolveAssetsRialValue(assetsSummary.value, getTradeBuyPrice(lastPrice.value))
})
const goldWeight = computed(() => Number(portfolio.value?.gold_weight ?? 0))
const averageBuyPrice = computed(() => portfolio.value?.average_buy_price ?? null)
const liveGoldPrice = computed(() => Number(portfolio.value?.live_gold_price ?? 0))
const hasProfitInsight = computed(() => portfolio.value?.unrealized_profit_rial != null)
const profitTone = computed(() => formatPortfolioProfitLabel(portfolio.value?.unrealized_profit_rial))
@@ -89,6 +98,33 @@ const profitPercent = computed(() =>
formatPortfolioProfitPercent(portfolio.value?.unrealized_profit_percent)
)
function renderModalLines(text: string) {
return h(
'div',
{ style: { lineHeight: '1.9' } },
text.split('\n').map((line, index) =>
h(
'div',
{ key: index, style: index > 0 ? { marginTop: '6px' } : undefined },
line
)
)
)
}
function openProfitInfo() {
const p = portfolio.value
if (!p) return
Modal.confirm({
title: 'سود/زیان تحقق‌نیافته طلا',
content: renderModalLines(formatPortfolioProfitInfoText(p, weightUnit.value)),
okText: 'متوجه شدم',
centered: true,
cancelButtonProps: { style: { display: 'none' } },
})
}
const rootClass = computed(() => [
'portfolio-overview',
`portfolio-overview--${props.variant}`,
@@ -146,17 +182,46 @@ const rootClass = computed(() => [
.portfolio-overview__profit {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px;
padding: 8px 10px;
border-radius: 10px;
flex-direction: column;
gap: 6px;
padding: 10px 12px;
border-radius: 12px;
margin-bottom: 12px;
background: rgba(255, 255, 255, 0.12);
font-size: 13px;
font-weight: 700;
}
.portfolio-overview__profit-main {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px;
}
.portfolio-overview__profit-label {
display: inline-flex;
align-items: center;
gap: 4px;
}
.portfolio-overview__profit-info {
display: inline-flex;
align-items: center;
justify-content: center;
padding: 0;
margin: 0;
border: none;
background: transparent;
cursor: pointer;
line-height: 0;
opacity: 0.85;
&:hover {
opacity: 1;
}
}
.portfolio-overview--desktop .portfolio-overview__profit {
background: #f9fafb;
}
@@ -244,16 +309,4 @@ const rootClass = computed(() => [
color: #9ca3af;
opacity: 1;
}
.portfolio-overview__footnote {
margin: 10px 0 0;
font-size: 11px;
line-height: 1.6;
opacity: 0.8;
}
.portfolio-overview--desktop .portfolio-overview__footnote {
color: #6b7280;
opacity: 1;
}
</style>
@@ -0,0 +1,207 @@
<template>
<div
v-if="hasProfitInsight"
class="portfolio-profit"
:class="[
`portfolio-profit--${variant}`,
{
'portfolio-profit--up': profitTone === 'profit',
'portfolio-profit--down': profitTone === 'loss',
},
]"
>
<div class="portfolio-profit__main">
<span class="portfolio-profit__amount">{{ profitText }}</span>
<span v-if="profitPercent" class="portfolio-profit__percent">{{ profitPercent }}</span>
</div>
<div class="portfolio-profit__label-row">
<span class="portfolio-profit__hint">سود/زیان تحقق‌نیافته طلا</span>
<button
type="button"
class="portfolio-profit__info"
aria-label="اطلاعات بیشتر"
@click="openInfoModal"
>
<BasicIcon
icon="vuesax-linear:info-circle"
:size="variant === 'desktop' ? 14 : 16"
:color="infoIconColor"
/>
</button>
</div>
</div>
</template>
<script setup lang="ts">
import { computed, h } from 'vue'
import { Modal } from 'ant-design-vue'
import BasicIcon from '@/components/BasicPacks/BasicIcon.vue'
import { useWalletAssets } from '@/composables/useWalletAssets'
import {
formatPortfolioProfitInfoText,
formatPortfolioProfitLabel,
formatPortfolioProfitPercent,
formatPortfolioProfitText,
} from '@/utils/productAssets'
const props = withDefaults(
defineProps<{
variant?: 'mobile' | 'desktop'
}>(),
{ variant: 'mobile' }
)
const { assetsSummary } = useWalletAssets()
const portfolio = computed(() => assetsSummary.value?.portfolio)
const weightUnit = computed(() => assetsSummary.value?.meta?.weight_unit || 'گرم')
const hasProfitInsight = computed(() => portfolio.value?.unrealized_profit_rial != null)
const profitTone = computed(() => formatPortfolioProfitLabel(portfolio.value?.unrealized_profit_rial))
const profitText = computed(() => formatPortfolioProfitText(portfolio.value?.unrealized_profit_rial))
const profitPercent = computed(() =>
formatPortfolioProfitPercent(portfolio.value?.unrealized_profit_percent)
)
const infoIconColor = computed(() => (props.variant === 'desktop' ? 'tertiary' : 'tertiary'))
function renderModalLines(text: string) {
return h(
'div',
{ style: { lineHeight: '1.9' } },
text.split('\n').map((line, index) =>
h(
'div',
{ key: index, style: index > 0 ? { marginTop: '6px' } : undefined },
line
)
)
)
}
function openInfoModal() {
const p = portfolio.value
if (!p) return
Modal.confirm({
title: 'سود/زیان تحقق‌نیافته طلا',
content: renderModalLines(formatPortfolioProfitInfoText(p, weightUnit.value)),
okText: 'متوجه شدم',
centered: true,
cancelButtonProps: { style: { display: 'none' } },
})
}
</script>
<style scoped lang="less">
.portfolio-profit {
display: flex;
flex-direction: column;
align-items: center;
gap: 6px;
padding: 10px 14px;
border-radius: 12px;
margin-top: 10px;
background: linear-gradient(145deg, rgba(255, 255, 255, 0.18), rgba(255, 255, 255, 0.06));
border: 1px solid rgba(255, 255, 255, 0.22);
box-shadow: 0 4px 14px rgba(0, 0, 0, 0.1);
backdrop-filter: blur(6px);
}
.portfolio-profit--desktop {
align-items: flex-start;
margin-top: 0;
margin-bottom: 12px;
background: linear-gradient(145deg, #f9fafb, #f3f4f6);
border: 1px solid rgba(15, 23, 42, 0.06);
box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04);
backdrop-filter: none;
}
.portfolio-profit__main {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: center;
gap: 6px 10px;
font-size: 14px;
font-weight: 800;
letter-spacing: -0.01em;
}
.portfolio-profit--desktop .portfolio-profit__main {
justify-content: flex-start;
font-size: 15px;
}
.portfolio-profit--up {
color: #bbf7d0;
border-color: rgba(187, 247, 208, 0.35);
}
.portfolio-profit--desktop.portfolio-profit--up {
color: #027a48;
background: linear-gradient(145deg, #ecfdf3, #d1fae5);
border-color: rgba(2, 122, 72, 0.12);
}
.portfolio-profit--down {
color: #fecaca;
border-color: rgba(254, 202, 202, 0.35);
}
.portfolio-profit--desktop.portfolio-profit--down {
color: #b42318;
background: linear-gradient(145deg, #fef3f2, #fee4e2);
border-color: rgba(180, 35, 24, 0.12);
}
.portfolio-profit__percent {
direction: ltr;
unicode-bidi: isolate;
font-variant-numeric: tabular-nums;
font-size: 0.92em;
opacity: 0.95;
}
.portfolio-profit__label-row {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 4px;
}
.portfolio-profit--desktop .portfolio-profit__label-row {
justify-content: flex-start;
}
.portfolio-profit__hint {
font-size: 11px;
font-weight: 500;
opacity: 0.88;
white-space: nowrap;
}
.portfolio-profit--desktop .portfolio-profit__hint {
color: #6b7280;
opacity: 1;
}
.portfolio-profit__info {
display: inline-flex;
align-items: center;
justify-content: center;
padding: 0;
margin: 0;
border: none;
background: transparent;
cursor: pointer;
opacity: 0.85;
line-height: 0;
transition: opacity 0.15s ease;
&:hover {
opacity: 1;
}
}
</style>
@@ -2,7 +2,7 @@
import { computed } from 'vue'
import BasicIcon from '@/components/BasicPacks/BasicIcon.vue'
import BoursecuAssetsSummary from '../../components/BoursecuAssetsSummary.vue'
import PortfolioOverview from '../../components/PortfolioOverview.vue'
import PortfolioProfitInsight from '../../components/PortfolioProfitInsight.vue'
import { formatWeightAmount, usePriceWithoutType } from '@/utils/usePrice'
import { useWalletAssets } from '@/composables/useWalletAssets'
import type { WalletMetalTotal } from '@/models/walletAssets'
@@ -25,7 +25,6 @@ const cashWallet = computed(() => assetsSummary.value?.cash_wallet ?? 0)
const countBasedInventory = computed(() =>
(assetsSummary.value?.count_products ?? []).reduce((sum, item) => sum + Number(item.quantity ?? 0), 0),
)
const showLegacyMetrics = computed(() => !assetsSummary.value?.portfolio)
type MetricItem = {
id: string
@@ -104,9 +103,9 @@ function handleInfo(metric: MetricItem) {
/>
<template v-else>
<PortfolioOverview variant="desktop" />
<PortfolioProfitInsight variant="desktop" />
<div v-if="showLegacyMetrics" class="dhome-metrics">
<div class="dhome-metrics">
<article v-for="metric in metrics" :key="metric.id" class="dhome-metric-tile">
<div class="dhome-metric-tile__head">
<span class="dhome-metric-tile__label">{{ metric.label }}</span>
@@ -37,13 +37,7 @@ const showSkeleton = computed(() => Boolean(getToken()) && !userInfo.value)
<HomeSkeleton v-if="showSkeleton" />
<template v-if="showContent">
<DesktopAssetsMetrics
v-if="!ctx.isGaroosi.value"
@open-gold-modal="ctx.openGoldModal"
@open-rial-modal="ctx.openRialModal"
/>
<section class="dhome-hero-row">
<section v-if="ctx.isGaroosi.value" class="dhome-hero-row">
<DesktopLivePrice />
<DesktopPriceRange />
</section>
@@ -74,6 +68,17 @@ const showSkeleton = computed(() => Boolean(getToken()) && !userInfo.value)
<template v-else>
<DesktopDefaultActions />
<DesktopAssetsMetrics
@open-gold-modal="ctx.openGoldModal"
@open-rial-modal="ctx.openRialModal"
/>
<section class="dhome-hero-row">
<DesktopLivePrice />
<DesktopPriceRange />
</section>
<section
v-if="ctx.bannerEnabled.value && ctx.banners.value?.length"
class="dhome-surface dhome-chart-banner-combined"
@@ -24,6 +24,10 @@ const innerSections = computed(() =>
layoutConfig.value.sections.filter((section) => section.visible !== false)
)
const tailSections = computed(() =>
(layoutConfig.value.tailSections ?? []).filter((section) => section.visible !== false)
)
/** محتوا با userInfo — داده‌های API در پس‌زمینه لود می‌شوند */
const showContent = computed(() => Boolean(userInfo.value))
const showSkeleton = computed(() => Boolean(getToken()) && !userInfo.value)
@@ -56,6 +60,12 @@ function resolveSectionComponent(sectionId: HomeSectionId) {
:key="section.id"
/>
</template>
<component
:is="resolveSectionComponent(section.id)"
v-for="section in tailSections"
:key="`tail-${section.id}`"
/>
</div>
<HomeSkeleton v-else-if="showSkeleton" class="w-full" />
@@ -3,12 +3,14 @@ import type { HomeLayoutConfig } from '../types'
/** چیدمان پیش‌فرض — همه پروژه‌ها به‌جز boursecu */
export const defaultHomeLayoutConfig: HomeLayoutConfig = {
id: 'default',
wrapperClass: 'p-1 from-primary rounded-lg p-px to-transparent mt-5',
wrapperClass: 'p-1 shadow-lg from-primary rounded-lg p-px to-transparent mt-5',
sections: [
{ id: 'garoosiAssets' },
{ id: 'assets' },
{ id: 'mainActions' },
{ id: 'referral' },
{ id: 'assets' },
],
tailSections: [
{ id: 'marketClosed' },
{ id: 'currentPrice' },
{ id: 'banners' },
+2
View File
@@ -31,6 +31,8 @@ export interface HomeLayoutConfig {
wrapperClass?: string
outerSections?: HomeLayoutSectionConfig[]
sections: HomeLayoutSectionConfig[]
/** بعد از wrapper — مثل قیمت و نمودار در UI قدیمی */
tailSections?: HomeLayoutSectionConfig[]
}
export interface HomeActionItem {
@@ -281,11 +281,13 @@ import type { TableEngineInput, TableOutput } from '@/models/table'
import { getTransactionTable } from '@/api/transaction'
import { getLastPrices, getTradeBuyPrice, getTradeSellPrice, lastPrice, setIntervalGetAllPrice, stopPriceInterval } from '@/utils/price'
import { getProductBuyPrice, getProductSellPrice, isProductPriceInactive } from '@/utils/productPrice'
import { resolveProductCashFeeBuyRial, resolveProductCashFeeSellRial } from '@/utils/productCashFee'
import { Product } from '@/models/products'
import BasicSelect from '@/components/BasicPacks/BasicSelect.vue'
import Bg_main from '@/components/bg_main.vue'
import { useFundUserStore } from '@/store/fundStore'
import { getProductsCatalogRef } from '@/composables/useProductsCatalog'
import { resetTransactionsPageData } from '@/views/base/transactions/composables/useTransactionsPageData'
import {
getDefaultProductDealMethod,
getProductDealMethodOptions,
@@ -401,22 +403,9 @@ interface Prop {
const props = withDefaults(defineProps<Prop>(), {})
const emit = defineEmits<{ ordered: [] }>()
const isBuy = ref<boolean>(true)
const buyTotalPrice = computed(() => {
const item = props?.ProductItem
if (!item) return 0
const basePrice = (item.price ?? 0) + (item.cash_fee_buy ?? 0)
const buyTotalPrice = computed(() => resolveProductTradeBuyUnitPrice(props?.ProductItem))
return basePrice * productPriceAmountFactor(item)
})
const sellTotalPrice = computed(() => {
const item = props?.ProductItem
if (!item) return 0
const basePrice = (item.price ?? 0) - (item.cash_fee_sell ?? 0)
return basePrice * productPriceAmountFactor(item)
})
const sellTotalPrice = computed(() => resolveProductTradeSellUnitPrice(props?.ProductItem))
const buyFee = computed(() => ((props?.ProductItem?.amount * (props?.ProductItem?.percent_fee_buy ?? 0) * (props?.ProductItem?.price ?? 0)).toFixed(0)))
const sellFee = computed(() => ((props?.ProductItem?.amount * (props?.ProductItem?.percent_fee_sell ?? 0) * (props?.ProductItem?.sellPrice ?? 0)).toFixed(0)))
@@ -737,7 +726,8 @@ function calculateCash(val: number) {
// form.value.goldVazn = parseFloat((val * (( props?.ProductItem?.price) + (props?.ProductItem?.cash_fee_buy)))/lastPrice.value?.buy).toFixed(2)
if (isBuy.value) {
if (val){
const unitPrice = (props?.ProductItem?.price ?? 0) + (props?.ProductItem?.cash_fee_buy ?? 0)
const base = props?.ProductItem?.price ?? 0
const unitPrice = base + resolveProductCashFeeBuyRial(props?.ProductItem, base)
form.value.goldCash = parseFloat(String(val * unitPrice * productPriceAmountFactor(props?.ProductItem))).toFixed(0)
}
else {
@@ -747,7 +737,8 @@ function calculateCash(val: number) {
}
else {
if (val){
const unitPrice = (props?.ProductItem?.price ?? 0) - (props?.ProductItem?.cash_fee_sell ?? 0)
const base = props?.ProductItem?.price ?? 0
const unitPrice = base - resolveProductCashFeeSellRial(props?.ProductItem, base)
form.value.goldCash = parseFloat(String(val * unitPrice * productPriceAmountFactor(props?.ProductItem))).toFixed(0)
}
else{
@@ -838,8 +829,11 @@ async function initPrice() {
await getLastPrices()
// await setIntervalGetPrice()
loading.value = true
props.ProductItem.price = lastPrice?.value?.price? (lastPrice?.value?.price + props.ProductItem?.cash_fee_buy) * props.ProductItem?.amount: 0
props.ProductItem.sellPrice = lastPrice?.value?.price? (lastPrice?.value?.price - props.ProductItem?.percent_fee_sell) * props.ProductItem?.amount:0
const livePrice = lastPrice?.value?.price ?? 0
const buyFee = resolveProductCashFeeBuyRial(props.ProductItem, livePrice)
const sellFee = resolveProductCashFeeSellRial(props.ProductItem, livePrice)
props.ProductItem.price = livePrice ? (livePrice + buyFee) * props.ProductItem.amount : 0
props.ProductItem.sellPrice = livePrice ? (livePrice - sellFee) * props.ProductItem.amount : 0
} catch (e) {
console.log(e)
} finally {
@@ -898,6 +892,7 @@ async function ok() {
await loadWalletAssets(true)
await fundStore.getMyFund()
message.success('سفارش شما با موفقیت انجام شد')
resetTransactionsPageData()
await router.push({ name: 'transactions' })
form.value = {
goldValue: undefined,
@@ -4,7 +4,7 @@
? 'drules-content'
: 'rules-panel border-solid border-2 border-primary text-primary rounded-[12px] p-4 mobile-content-box'"
>
<div :class="variant !== 'desktop' ? 'mobile-content-box__scroll' : undefined">
<div :class="variant === 'desktop' ? 'drules-content__scroll' : 'mobile-content-box__scroll'">
<div :class="variant === 'desktop' ? 'drules-content__title' : 'font-bold text-sm text-primary'">
{{ rulesTitle }}
</div>
@@ -77,6 +77,10 @@
.drules-main {
padding: 28px;
display: flex;
flex-direction: column;
min-height: 0;
max-height: calc(100vh - 180px);
&__intro {
display: flex;
@@ -85,6 +89,7 @@
margin-bottom: 24px;
padding-bottom: 20px;
border-bottom: 1px solid #eef0f3;
flex-shrink: 0;
}
&__logo {
@@ -114,12 +119,27 @@
}
.drules-content {
display: flex;
flex-direction: column;
flex: 1;
min-height: 0;
overflow: hidden;
padding: 20px;
border: 1px solid rgba(9, 61, 81, 0.12);
border-radius: 12px;
background: rgba(9, 61, 81, 0.02);
color: @App-primary-color;
&__scroll {
flex: 1;
min-height: 0;
overflow-y: auto;
overflow-x: hidden;
overscroll-behavior-y: contain;
padding-left: 4px;
margin-left: -4px;
}
&__title {
font-size: 16px;
font-weight: 700;
@@ -206,6 +226,10 @@
grid-template-columns: 1fr;
}
.drules-main {
max-height: none;
}
.drules-side {
position: static;
}
@@ -16,7 +16,7 @@
<div class="dtxn-row__meta">
<span>{{ toJalaliOutOfUTC(props.item.expire_at) }}</span>
<span :class="goldAmount >= 0 ? 'text-green-600' : 'text-red-600'">
{{ formatGoldAmount(goldAmount) }} {{ props.item.unit }}
{{ formatTransactionGoldAmount(props.item, goldAmount) }} {{ props.item.unit }}
</span>
<span v-if="isGold">
قیمت معامله:
@@ -32,8 +32,8 @@
{{ usePriceWithoutType(props.item.cash ?? 0) }} ریال
</div>
<div class="dtxn-row__status">
<ATag color="blue" class="!py-1 !px-4 !ml-0 !text-xs">
{{ props.item.order?.sts_str ?? props.item.withdraw?.sts_str }}
<ATag v-if="statusLabel" color="blue" class="!py-1 !px-4 !ml-0 !text-xs">
{{ statusLabel }}
</ATag>
</div>
</button>
@@ -59,7 +59,7 @@
:class="goldAmount >= 0 ? 'text-green-600' : 'text-red-600'"
class="text-gray-500 text-xs number-ltr"
>
{{ formatGoldAmount(goldAmount) }}
{{ formatTransactionGoldAmount(props.item, goldAmount) }}
<div>{{ props.item.unit }}</div>
</div>
<div class="text-gray-500 flex gap-1 text-xs items-center number-ltr">
@@ -83,8 +83,8 @@
<div class="flex w-full justify-between mt-2">
<div class="text-gray-500">وضعیت :</div>
<div class="text-gray-500 flex gap-1 text-xs items-center">
<ATag class="!py-1 !px-6 !ml-0" color="blue">
{{ props.item.order?.sts_str ?? props.item.withdraw?.sts_str }}
<ATag v-if="statusLabel" class="!py-1 !px-6 !ml-0" color="blue">
{{ statusLabel }}
</ATag>
</div>
</div>
@@ -115,11 +115,12 @@
<script lang="ts" setup>
import Icon from '@/components/BasicPacks/BasicIcon.vue'
import {
formatGoldAmount,
getTransactionGoldAmount,
getTransactionTradePrice,
resolveTransactionStatusLabel,
usePriceWithoutType,
} from '@/utils/usePrice'
import { formatTransactionGoldAmount } from '@/utils/productDealMethod'
import BasicActionSheet from '@/components/BasicPacks/BasicActionSheet.vue'
import BasicModal from '@/components/BasicPacks/BasicModal.vue'
import { computed, ref } from 'vue'
@@ -140,6 +141,7 @@ const props = withDefaults(
const goldAmount = computed(() => getTransactionGoldAmount(props.item))
const tradePrice = computed(() => getTransactionTradePrice(props.item))
const statusLabel = computed(() => resolveTransactionStatusLabel(props.item))
const isUp = computed(
() =>
@@ -47,7 +47,7 @@
]"
>
<div class="flex items-center gap-1">
<div class="text-base">{{ formatGoldAmount(item.gold) }}</div>
<div class="text-base">{{ formatTransactionGoldAmount(item, item.gold) }}</div>
{{ item.unit }}
</div>
<div
@@ -82,7 +82,7 @@
</div>
<div class="flex flex-col items-end text-xs text-yellow-700">
<div class="flex items-center">
<div class="text-base ml-1">{{ formatGoldAmount(item.balance_gold) }}</div>
<div class="text-base ml-1">{{ formatTransactionGoldAmount(item, item.balance_gold) }}</div>
{{ metalWalletBalanceUnit }}
</div>
<div v-if="getProductUnitWeightLabel(metalWalletProduct)" class="text-gray-500">
@@ -93,8 +93,8 @@
<div :class="variant === 'desktop' ? 'dtxn-detail__row' : 'flex justify-between mb-3'">
<div :class="variant === 'desktop' ? 'dtxn-detail__label' : 'text-primary'">وضعیت:</div>
<div class="flex text-xs items-center">
<ATag color="blue" class="!py-1 !px-6 !ml-0">
{{ item.order?.sts_str ?? item.withdraw?.sts_str }}
<ATag v-if="statusLabel" color="blue" class="!py-1 !px-6 !ml-0">
{{ statusLabel }}
</ATag>
</div>
</div>
@@ -115,9 +115,10 @@
<script lang="ts" setup>
import { computed } from 'vue'
import { formatGoldAmount, usePriceWithoutType } from '@/utils/usePrice'
import { resolveTransactionStatusLabel, usePriceWithoutType } from '@/utils/usePrice'
import type { Transaction } from '@/models/transaction'
import {
formatTransactionGoldAmount,
getCashWalletLabel,
getProductTotalWeightLabel,
getProductUnitWeightLabel,
@@ -139,6 +140,7 @@ const props = withDefaults(
)
const tradeProduct = computed(() => resolveTransactionTradeProduct(props.item))
const statusLabel = computed(() => resolveTransactionStatusLabel(props.item))
const tradeProductLabel = computed(
() => (tradeProduct.value?.title ?? '').trim() || getMeltedGoldTradeLabel(),
)
@@ -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'
@@ -166,7 +166,7 @@ export function useTransactionsPageProvider(options?: { boursecu?: boolean }) {
useIntersectionObserver(
activeObserverEl,
async ([entry]) => {
if (entry?.isIntersecting) {
if (entry?.isIntersecting && !loading.value && !loadingMore.value) {
await loadMoreTransactions()
}
},
@@ -184,6 +184,10 @@ export function useTransactionsPageProvider(options?: { boursecu?: boolean }) {
await initTransactionsPageData(isBoursecu)
})
onActivated(async () => {
await reloadTransactionsTable()
})
const context: TransactionsPageContext = {
pagination: transactionPagination,
items: transactionItems,
@@ -11,9 +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
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 })
@@ -27,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) ??
@@ -65,46 +60,67 @@ export function resetTransactionsPagination() {
}
}
async function fetchTransactionsPage(append: boolean) {
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 resolveTransactionFetcher()(transactionPagination.value)
if (fetchId !== activeFetchId) {
return false
}
transactionTableOutput.value = await fetcher(transactionPagination.value)
const rows = transactionTableOutput.value.rows ?? []
transactionTableOutput.value = output
const rows = output.rows ?? []
if (isFirstPage) {
transactionItems.value = [...rows]
} else {
transactionItems.value.push(...rows)
}
return true
} catch (error) {
console.error('Error fetching transactions:', error)
if (fetchId === activeFetchId) {
console.error('Error fetching transactions:', error)
}
return false
} finally {
loading.value = false
loadingMore.value = false
if (fetchId === activeFetchId) {
loading.value = false
loadingMore.value = false
}
}
}
/** همیشه از سرور — بدون کش لیست */
export async function reloadTransactionsTable() {
transactionPagination.value.page = 0
transactionItems.value = []
transactionTableOutput.value = null
resetTransactionsPagination()
await fetchTransactionsPage(false)
}
export async function loadMoreTransactions() {
if (loading.value || loadingMore.value) {
return
}
if (
!transactionTableOutput.value
|| (transactionPagination.value.page + 1) * transactionPagination.value.limit
@@ -117,40 +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() {
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 = []