From fd6a30d7a259852ea5cc10a890f2312e1d8b7089 Mon Sep 17 00:00:00 2001
From: lxf <1371462558@qq.com>
Date: Mon, 16 Jun 2025 14:54:39 +0800
Subject: [PATCH] 优化计算方式
---
src/components/constract/PerpetualContract/orderCom/amountSlider.vue | 105 +++++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 90 insertions(+), 15 deletions(-)
diff --git a/src/components/constract/PerpetualContract/orderCom/amountSlider.vue b/src/components/constract/PerpetualContract/orderCom/amountSlider.vue
index 29b0ca4..fed921b 100644
--- a/src/components/constract/PerpetualContract/orderCom/amountSlider.vue
+++ b/src/components/constract/PerpetualContract/orderCom/amountSlider.vue
@@ -23,14 +23,17 @@
v-model="sliderAmount"
:format-tooltip="(v) => `${v}%`"
:marks="marks"
+ :step="25"
>
</el-slider>
</div>
<!-- 订单 -->
<div v-if="existToken">
<div v-if="typeNum == 0" class="submit-info-item">
- <div>{{ $t("message.home.kekaizhangshu") }}</div>
- <div>{{ `${maxAmount} ${$t("message.home.zhang")}` }}</div>
+ <!-- <div>{{ $t("message.home.kekaizhangshu") }}</div>
+ <div>{{ `${maxAmount} ${$t("message.home.zhang")}` }}</div> -->
+ <div>{{ $t("message.jiaoyi.qianbaoyue") }}</div>
+ <div>{{ walletMoney }} USDT</div>
</div>
<div v-if="typeNum == 1" class="submit-info-item">
@@ -53,6 +56,9 @@
import { mapState, mapActions, mapStores } from "pinia";
import { useUserStore } from "@/store/user";
import { useCurrencyStore } from "@/store/currency";
+import Axios from "@/api/currency.js";
+import bus from "vue3-eventbus";
+
export default {
emits: ["getAmount"],
name: "amountSlider",
@@ -81,6 +87,10 @@
type: Number,
default: 0,
},
+ initOpen: {
+ type: Object,
+ default: {},
+ },
},
data() {
return {
@@ -90,15 +100,52 @@
0: "0",
25: "25%",
50: "50%",
- 75: "70%",
+ 75: "75%",
100: "100%",
},
+ allowedSteps: [0, 25, 50, 75, 100],
+
+ totalAsset: "0.000000", //总资产
+ walletMoney: "0.000000", //钱包余额
+ profitLoss: "0.000000", //未实现盈亏
+ marginRate: "0.000000", //保证金比率
+ maintenanceMargin: "0.000000", //维持保证金 = 钱包余额
};
+ },
+ mounted() {
+ if (this.existToken) {
+ this.timer = setInterval(() => {
+ this.getAssetTotal();
+ }, 2000);
+ }
+ },
+ unmounted() {
+ if (this.timer) {
+ clearInterval(this.timer);
+ this.timer = null;
+ }
},
computed: {
...mapState(useUserStore, ["existToken"]),
+ //保证金余额
+ marginBalance: function () {
+ // 钱包余额 + 未实现盈亏
+ return bigDecimal.add(this.walletMoney, this.profitLoss);
+ },
},
methods: {
+ //获取资产总余额
+ getAssetTotal() {
+ Axios.currencyPaypal().then((res) => {
+ const { total, money_wallet, money_contract, money_contract_profit } =
+ res.data;
+ this.totalAsset = total; //总资产
+ this.walletMoney = bigDecimal.round(money_wallet, 2); //钱包余额
+ this.profitLoss = bigDecimal.round(money_contract_profit, 2); //永续合约总未实现盈亏
+ // bus.emit("moneyContract", money_contract); //合约可用余额
+ bus.emit("moneyContract", money_wallet); //合约可用余额
+ });
+ },
//输入框事件
inputChange(val) {
this.$emit("getAmount", val);
@@ -111,23 +158,51 @@
sliderAmountChange(val) {
let data;
if (this.maxAmount) {
- if (val == 0) {
- this.amount = undefined;
- } else {
- const rate = val / 100; //如0.25
- data = this.maxAmount * rate;
- // if (this.lever_rate) {
- // data = math.format((this.maxAmount * rate), 2);
- // } else {
- // data = math.format((this.maxAmount * rate) / 1, 2);
- // }
- this.amount = parseInt(data);
+ // if (val == 0) {
+ // this.amount = undefined;
+ // } else {
+
+ const rate = val / 100; //如0.25
+ let sxf = 0;
+ switch (Number(this.lever_rate)) {
+ case 25:
+ sxf = 0.0375;
+ break;
+ case 50:
+ sxf = 0.075;
+ break;
+ case 100:
+ sxf = 0.15;
+ break;
+ case 200:
+ sxf = 0.3;
+ break;
+ default:
+ sxf = 0;
}
+ // const fl =
+ // this.walletMoney * sxf * this.initOpen.amount * this.lever_rate * rate;
+ // const maxAmount =
+ // this.walletMoney * this.initOpen.amount * this.lever_rate;
+ const maxAmount = (this.walletMoney / (1 + sxf)) * this.lever_rate;
+ const fl = maxAmount * sxf;
+ console.log(maxAmount * rate, fl);
+
+ // data = maxAmount * rate - fl;
+ data = maxAmount;
+
+ // if (this.lever_rate) {
+ // data = math.format((this.maxAmount * rate), 2);
+ // } else {
+ // data = math.format((this.maxAmount * rate) / 1, 2);
+ // }
+ this.amount = parseInt(data);
+ // }
this.$emit("getAmount", this.amount);
}
},
emptyValue() {
- this.sliderAmount = undefined;
+ this.sliderAmount = 0;
},
},
};
--
Gitblit v1.9.3