li.shaoyi 2 yıl önce
ebeveyn
işleme
e4869c86f2

+ 19 - 9
src/filters/index.ts

@@ -155,6 +155,16 @@ export function parsePercent(value = 0, decimal = 2) {
 }
 
 /**
+ * 四舍五入,处理计算精度问题
+ * @param value 
+ * @param precision 
+ * @returns 
+ */
+export function round(value: number, precision = 2) {
+    return Math.round(+(value + 'e' + precision)) / Math.pow(10, precision)
+}
+
+/**
  * 强制保留小数位,不足位数自动补零
  * @param value 
  * @param decimal 保留小数位
@@ -323,18 +333,18 @@ export function sortBy<T extends object, K extends keyof T>(arr: Array<T>, sortV
 }
 
 // 身份证号 获取对应的证件年龄
-export function getIdCardAge(cardnum: string) { 
+export function getIdCardAge(cardnum: string) {
     // 根据身份证号提取出年 月 日 
-    const idYear = Number(cardnum.substring(6, 10) )
-    const idMonth = Number(cardnum.substring(10, 12)) 
+    const idYear = Number(cardnum.substring(6, 10))
+    const idMonth = Number(cardnum.substring(10, 12))
     const idDay = Number(cardnum.substring(12, 14))
     // 获取当前日期的年 月 日 
-    const year = (new Date()).getFullYear() 
-    const month = (new Date()).getMonth() +1 
-    const day = (new Date()).getDate() 
+    const year = (new Date()).getFullYear()
+    const month = (new Date()).getMonth() + 1
+    const day = (new Date()).getDate()
     // 计算年龄 
-    let age = year - idYear 
+    let age = year - idYear
     // 需要根据月份和具体日子判断下 
-    if((idMonth > month) || idMonth == month && idDay > day ){ age-- } 
-    return age 
+    if ((idMonth > month) || idMonth == month && idDay > day) { age-- }
+    return age
 }

+ 1 - 2
src/packages/sbyj/views/home/index.vue

@@ -72,6 +72,7 @@ const onTabClick = (index: number) => {
         currentTab.value = index
         routerTo(name, true)
       }).catch(() => {
+        cssTransition.value = true
         routerTo('user-login')
       }).finally(() => {
         hideLoading()
@@ -88,8 +89,6 @@ watch(() => route.name, () => {
   const params = getGlobalUrlParams()
   if (params.tabIndex > -1) {
     onTabClick(params.tabIndex)
-  } else if (tabIndex.value > -1) {
-    onTabClick(tabIndex.value)
   } else {
     // 如果参数不是 tabIndex ,需要保留到下一个路由
     setGlobalUrlParams(params)

+ 7 - 5
src/stores/modules/position.ts

@@ -1,5 +1,5 @@
 import { reactive, computed, toRefs } from 'vue'
-import { handlePriceColor } from '@/filters'
+import { handlePriceColor, round } from '@/filters'
 import { BuyOrSell } from '@/constants/order'
 import { queryTradePosition } from '@/services/api/order'
 import { useFuturesStore } from './futures'
@@ -48,16 +48,18 @@ export const usePositionStore = defineStore(() => {
 
             // 计算市值 = 现价 * 数量 * 合约单位
             const marketValue = price ? price * item.curpositionqty * item.agreeunit : 0
+            const roundedMarketValue = round(marketValue, quote.value?.decimalplace)
             // 计算浮动盈亏
-            const closepl = price ? (marketValue - item.curholderamount) * (item.buyorsell === BuyOrSell.Buy ? 1 : -1) : 0
+            const closepl = price ? (roundedMarketValue - item.curholderamount) * (item.buyorsell === BuyOrSell.Buy ? 1 : -1) : 0
+            const roundedClosepl = round(closepl, quote.value?.decimalplace)
 
             result.push({
                 ...item,
                 lastprice: price,
                 lastColor: handlePriceColor(price, presettle),
-                closepl,
-                closeplColor: handlePriceColor(closepl, 0),
-                marketValue,
+                closepl: roundedClosepl,
+                closeplColor: handlePriceColor(roundedClosepl, 0),
+                marketValue: roundedMarketValue,
             })
         })