fix some bug

This commit is contained in:
2026-06-06 15:48:27 +03:30
parent f82a0c3873
commit 4c707849ef
5 changed files with 29 additions and 27 deletions
+5 -13
View File
@@ -9,26 +9,18 @@ export const price = ref<Price>()
export const lastPrice = ref<Price>() export const lastPrice = ref<Price>()
export const olderPrice = ref<number | undefined>(0) export const olderPrice = ref<number | undefined>(0)
/** buy/sell معامله: اول up (مثل endpoint قدیمی /price/up) سپس fallback */ /** buy/sell نمایش و معامله — همان buy/sell/price_last از /api/price/last */
export function getTradeBuyPrice(p?: Price | null) { export function getTradeBuyPrice(p?: Price | null) {
return p?.up?.buy ?? p?.buy ?? 0 return p?.buy ?? p?.price_last ?? p?.up?.buy ?? 0
} }
export function getTradeSellPrice(p?: Price | null) { export function getTradeSellPrice(p?: Price | null) {
return p?.up?.sell ?? p?.sell ?? 0 return p?.sell ?? p?.up?.sell ?? 0
} }
/** یکسان‌سازی پاسخ last با رفتار قدیمی price/up */ /** up جدا نگه داشته می‌شود؛ buy/sell/price_last از lastPrice سرور دست‌نخورده می‌ماند */
export function normalizePriceResponse(data: Price): Price { export function normalizePriceResponse(data: Price): Price {
if (!data?.up) { return data
return data
}
return {
...data,
buy: data.up.buy,
sell: data.up.sell,
}
} }
export async function setIntervalGetAllPrice() { export async function setIntervalGetAllPrice() {
+10 -2
View File
@@ -1,10 +1,10 @@
import type { Product } from '@/models/products' import type { Product } from '@/models/products'
import { getTradeBuyPrice, lastPrice } from '@/utils/price' import { getTradeBuyPrice, getTradeSellPrice, lastPrice } from '@/utils/price'
/** قیمت خرید نمایشی محصول (همان مقداری که در لیست و اکشن‌شیت نشان داده می‌شود) */ /** قیمت خرید نمایشی محصول (همان مقداری که در لیست و اکشن‌شیت نشان داده می‌شود) */
export function getProductBuyPrice(product: Product): number { export function getProductBuyPrice(product: Product): number {
if (product.group_type === 'آبشده') { if (product.group_type === 'آبشده') {
return getTradeBuyPrice(lastPrice.value) return getTradeBuyPrice(lastPrice.value) + (product.cash_fee_buy ?? 0)
} }
if (['مس', 'نقره'].includes(product.group_type)) { if (['مس', 'نقره'].includes(product.group_type)) {
@@ -18,6 +18,14 @@ export function getProductBuyPrice(product: Product): number {
: basePrice : basePrice
} }
/** قیمت فروش نمایشی آبشده — فقط cash_fee_sell محصول اختلاف ایجاد می‌کند */
export function getProductSellPrice(product: Product): number {
if (product.group_type === 'آبشده') {
return getTradeSellPrice(lastPrice.value) - (product.cash_fee_sell ?? 0)
}
return getTradeSellPrice(lastPrice.value)
}
export function isProductPriceInactive(product: Product): boolean { export function isProductPriceInactive(product: Product): boolean {
return getProductBuyPrice(product) <= 0 return getProductBuyPrice(product) <= 0
} }
+8 -3
View File
@@ -227,6 +227,7 @@ import type { Transaction } from '@/models/transaction'
import type { TableEngineInput, TableOutput } from '@/models/table' import type { TableEngineInput, TableOutput } from '@/models/table'
import { useInfiniteScroll } from '@vueuse/core' import { useInfiniteScroll } from '@vueuse/core'
import { getTransactionTable } from '@/api/transaction' import { getTransactionTable } from '@/api/transaction'
import { getProductBuyPrice, getProductSellPrice } from '@/utils/productPrice'
import { getLastPrices, getTradeBuyPrice, getTradeSellPrice, lastPrice, setIntervalGetAllPrice, stopPriceInterval } from '@/utils/price' import { getLastPrices, getTradeBuyPrice, getTradeSellPrice, lastPrice, setIntervalGetAllPrice, stopPriceInterval } from '@/utils/price'
import type { Product } from '@/models/products' import type { Product } from '@/models/products'
import { useFundUserStore } from '@/store/fundStore' import { useFundUserStore } from '@/store/fundStore'
@@ -277,9 +278,13 @@ const sellPagination = ref<TableEngineInput>({
}], limit: 6, page: 0 }], limit: 6, page: 0
}) })
const unitPrice = computed(() => const unitPrice = computed(() => {
isBuy.value ? getTradeBuyPrice(lastPrice.value) : getTradeSellPrice(lastPrice.value) const product = props.ProductItem
) if (product?.group_type === 'آبشده') {
return isBuy.value ? getProductBuyPrice(product) : getProductSellPrice(product)
}
return isBuy.value ? getTradeBuyPrice(lastPrice.value) : getTradeSellPrice(lastPrice.value)
})
const feeInGrams = computed(() => calcFeeInGrams(form.value?.goldValue)) const feeInGrams = computed(() => calcFeeInGrams(form.value?.goldValue))
const finalPrice = computed(() => (form.value?.goldValue ?? 0) * unitPrice.value) const finalPrice = computed(() => (form.value?.goldValue ?? 0) * unitPrice.value)
const feeInRial = computed(() => unitPrice.value * feeInGrams.value) const feeInRial = computed(() => unitPrice.value * feeInGrams.value)
@@ -31,7 +31,7 @@
<script setup lang="ts"> <script setup lang="ts">
import Icon from '@/components/BasicPacks/BasicIcon.vue' import Icon from '@/components/BasicPacks/BasicIcon.vue'
import { useConfigStore } from '@/store/configStore' import { useConfigStore } from '@/store/configStore'
import {lastPrice, percentPriceChanged, price} from '@/utils/price' import { getTradeBuyPrice, lastPrice, percentPriceChanged, price } from '@/utils/price'
import Vue3Odometer from 'vue3-odometer' import Vue3Odometer from 'vue3-odometer'
import 'odometer/themes/odometer-theme-default.css' import 'odometer/themes/odometer-theme-default.css'
import {useTowDecimal} from "../../../../utils/usePrice"; import {useTowDecimal} from "../../../../utils/usePrice";
@@ -42,19 +42,19 @@ const config = useConfigStore()
// محاسبه درصد تغییرات به صورت reactive // محاسبه درصد تغییرات به صورت reactive
const percentChange = computed(() => { const percentChange = computed(() => {
if (! lastPrice?.value?.price_last) return 0 if (!getTradeBuyPrice(lastPrice.value)) return 0
return percentPriceChanged() return percentPriceChanged()
}) })
// بررسی بسته بودن بازار // بررسی بسته بودن بازار
const isMarketClosed = computed(() => { const isMarketClosed = computed(() => {
return lastPrice?.value?.goldir === 0 && lastPrice?.value?.price_last === 0 return lastPrice?.value?.goldir === 0 && getTradeBuyPrice(lastPrice.value) === 0
}) })
// مقدار نمایشی برای ادومتر (با مدیریت خطا) // مقدار نمایشی برای ادومتر (با مدیریت خطا)
const displayGoldVal = computed(() => { const displayGoldVal = computed(() => {
if (isMarketClosed.value) return 0 if (isMarketClosed.value) return 0
return lastPrice?.value?.price_last|| 0 return getTradeBuyPrice(lastPrice.value)
}) })
// انیمیشن fade-in // انیمیشن fade-in
@@ -32,8 +32,7 @@ import type {Product} from "@/models/products";
import {usePrice} from '@/utils/usePrice'; import {usePrice} from '@/utils/usePrice';
import {getFileUrl} from '@/utils/file'; import {getFileUrl} from '@/utils/file';
import {computed, ref} from "vue"; import {computed, ref} from "vue";
import { getTradeBuyPrice, lastPrice } from '@/utils/price' import { getProductBuyPrice } from '@/utils/productPrice'
import type { Price } from '@/models/home'
interface Prop { interface Prop {
ProductItem: Product ProductItem: Product
@@ -88,9 +87,7 @@ const price = computed(()=>{
} }
}) })
const priceLast = computed((): Price => <Price>lastPrice.value ?? 0) const goldPriceValue = computed(() => getProductBuyPrice(props.ProductItem))
const goldPriceValue = computed(() => getTradeBuyPrice(priceLast.value))
</script> </script>