Browse Source

修改价格小数点

master
liaoxinyu 2 years ago
parent
commit
14a388960d
  1. BIN
      assets/img/home/illustration_1.png
  2. 13
      pages/exchange/exchange-transaction.vue
  3. 86
      pages/exchange/open-position.vue
  4. 9
      pages/exchange/sell-and-buy.vue
  5. 8
      utils/class/math.js

BIN
assets/img/home/illustration_1.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 49 KiB

After

Width:  |  Height:  |  Size: 97 KiB

13
pages/exchange/exchange-transaction.vue

@ -194,11 +194,12 @@
<!-- 深度列表 --> <!-- 深度列表 -->
<view class="w-6/12 p-l-md d-flex flex-col dep-list"> <view class="w-6/12 p-l-md d-flex flex-col dep-list">
<sell-and-buy :buyList="buyList" :max="symbol=='GITP/USDT'?11:8" :sellList="sellList" :symbol="symbol" v-on:price="getPrice($event)" :contract="0"> <sell-and-buy :buyList="buyList" :max="symbol=='GITP/USDT'?11:8" :sellList="sellList" :symbol="symbol" v-on:price="getPrice($event)" :contract="0">
<view <view
class="fn-lg row fn-bold" class="fn-lg row fn-bold"
:class="newPrice.increase < 0 ? 'color-sell' : 'color-buy'" :class="newPrice.increase < 0 ? 'color-sell' : 'color-buy'"
> >
{{ newPrice.price }} <!-- {{ newPrice.price }} -->
{{ Price }}
</view> </view>
<!-- <view class="fn-xs" v-if="newPrice.price"> <!-- <view class="fn-xs" v-if="newPrice.price">
{{ omitTo(newPrice.price * price_cny, 2) }} {{ omitTo(newPrice.price * price_cny, 2) }}
@ -505,6 +506,14 @@ export default {
return this.currentCoin; return this.currentCoin;
} }
}, },
Price(){
if (this.newPrice.price) {
let price = this.newPrice.price.toString();
let parts = price.split(".");
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
return parts.join(",");
}
}
}, },
watch: { watch: {
symbol(n, o) { symbol(n, o) {

86
pages/exchange/open-position.vue

@ -53,9 +53,8 @@
{{ $t("contract.d6") }} {{ $t("contract.d6") }}
<van-icon @click="popshow=true" class="color-theme-1 m-l-xs" name="info-o"/> <van-icon @click="popshow=true" class="color-theme-1 m-l-xs" name="info-o"/>
</view> </view>
<view class="num color-light fn-right" style="margin-top:8px;">{{ <!-- <view class="num color-light fn-right" style="margin-top:8px;">{{accountInfo.riskRate || "0%"}} -->
accountInfo.riskRate || "0%" <view class="num color-light fn-right" style="margin-top:8px;">{{riskRate || "0%"}}
}}
</view> </view>
</view> </view>
</view> </view>
@ -311,7 +310,8 @@
:max="6" :max="6"
:contract="1" :contract="1"
> >
<view class="fn-lg color-buy">{{ newPrice.price }}</view> <view class="fn-lg color-buy">{{ modifiedPrice }}</view>
<!-- <view class="fn-lg color-buy">{{ newPrice.price }}</view> -->
</sell-and-buy> </sell-and-buy>
</view> </view>
</view> </view>
@ -437,17 +437,19 @@
<view class="row d-flex m-y-xs justify-between fn-14 p-t-xs"> <view class="row d-flex m-y-xs justify-between fn-14 p-t-xs">
<view class="w-33 fn-left"> <view class="w-33 fn-left">
<view class="label">{{ $t("contract.g6") }}</view> <view class="label">{{ $t("contract.g6") }}</view>
<view class="color-light">{{item.avg_price}}</view> <!-- <view class="color-light">{{item.avg_price}}</view> -->
<view class="color-light">{{avg_price1(item.avg_price)}}</view>
</view> </view>
<view class="w-33 fn-center"> <view class="w-33 fn-center">
<view class="label">{{ $t("first.c5") }}</view> <view class="label">{{ $t("first.c5") }}</view>
<view class="color-light"> <view class="color-light">
<template>{{item.realtimePrice}}</template> <!-- <template>{{item.realtimePrice}}</template> -->
<template>{{realtimePrice1(item.realtimePrice)}}</template>
</view> </view>
</view> </view>
<view class="w-33 fn-right"> <view class="w-33 fn-right">
<view class="label">{{ $t("contract.b1") }}</view> <view class="label">{{ $t("contract.b1") }}</view>
<view class="color-light">{{item.position_margin}}</view> <view class="color-light">{{avg_price1(item.position_margin)}}</view>
</view> </view>
</view> </view>
<view class="row d-flex m-y-xs justify-between fn-14 p-t-xs"> <view class="row d-flex m-y-xs justify-between fn-14 p-t-xs">
@ -464,7 +466,7 @@
<view class="w-33 fn-right"> <view class="w-33 fn-right">
<view class="label">{{ $t("contract.a1") }}({{ $t("contract.d8") }})</view> <view class="label">{{ $t("contract.a1") }}({{ $t("contract.d8") }})</view>
<view class="color-light"> <view class="color-light">
{{item.avail_position}} {{avg_price1(item.avail_position)}}
</view> </view>
</view> </view>
</view> </view>
@ -473,7 +475,9 @@
<view class="label">{{ $t("option.b6") }}</view> <view class="label">{{ $t("option.b6") }}</view>
<view class="color-light" <view class="color-light"
:class="item.unRealProfit>0?'increace':item.unRealProfit<0?'decreace':''"> :class="item.unRealProfit>0?'increace':item.unRealProfit<0?'decreace':''">
{{item.unRealProfit}} <!-- {{ item.unRealProfit}} -->
{{avg_price1(item.unRealProfit)}}
</view> </view>
</view> </view>
<!-- <view class="w-50 fn-center"> <!-- <view class="w-50 fn-center">
@ -483,7 +487,8 @@
<view class="w-50 fn-right"> <view class="w-50 fn-right">
<view class="label">{{ $t("contract.h0") }}</view> <view class="label">{{ $t("contract.h0") }}</view>
<view class="color-light" :class="item.unRealProfit>0?'color-buy':'color-sell'"> <view class="color-light" :class="item.unRealProfit>0?'color-buy':'color-sell'">
{{item.profitRate}} <!-- {{item.profitRate}} -->
{{avg_price1(item.profitRate)}}
</view> </view>
</view> </view>
</view> </view>
@ -921,7 +926,23 @@ export default {
// #ifdef APP-PLUS // #ifdef APP-PLUS
return plus.os.name return plus.os.name
// #endif // #endif
} },
modifiedPrice(){
if (this.newPrice.price) {
let price = this.newPrice.price;
let parts = price.split(".");
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
return parts.join(",");
}
},
riskRate(){
if (this.accountInfo.riskRate) {
let price = this.accountInfo.riskRate;
let parts = price.split(".");
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
return parts.join(",");
}
}
}, },
watch: { watch: {
maxNum(n) { maxNum(n) {
@ -1003,6 +1024,22 @@ export default {
} }
}, },
methods: { methods: {
avg_price1(item){
if (item) {
let price = item.toString();
let parts = price.split(".");
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
return parts.join(",");
}
},
realtimePrice1(item){
if (item) {
let price = item;
let parts = price.split(".");
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
return parts.join(",");
}
},
onRefresh() { onRefresh() {
if (this.refreshing) return; if (this.refreshing) return;
this.refreshing = true; this.refreshing = true;
@ -1311,9 +1348,23 @@ export default {
}; };
Contract.contractAccount(data, {loading: !boo, toast: false}).then((res) => { Contract.contractAccount(data, {loading: !boo, toast: false}).then((res) => {
// console.info(res) // console.info(res)
res.data.account_equity = (parseInt(res.data.account_equity)).toFixed(2) // res.data.account_equity = (parseInt(res.data.account_equity)).toFixed(2)
res.data.usable_balance = (res.data.usable_balance).toFixed(2) // res.data.usable_balance = (res.data.usable_balance).toFixed(2)
res.data.account_equity = (parseInt(res.data.account_equity)).toFixed(2)
var parts1 = res.data.account_equity.split(".");
parts1[0] = parts1[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
res.data.account_equity = parts1.join(",");
res.data.usable_balance = res.data.usable_balance.toFixed(2).toString();
var parts = res.data.usable_balance.split(".");
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
res.data.usable_balance = parts.join(",");
this.accountInfo = res.data; this.accountInfo = res.data;
console.log(res.data,'12345612');
if (!boo) { if (!boo) {
// this.form.lever_rate = res.data.lever_rate; // this.form.lever_rate = res.data.lever_rate;
if (this.form.lever_rate) { if (this.form.lever_rate) {
@ -1470,6 +1521,15 @@ export default {
socketMessage() { socketMessage() {
// //
let buyFun = lodash.throttle((data) => { let buyFun = lodash.throttle((data) => {
// data.forEach((item) => {
// let price = item.price.toString();
// let parts = price.split(".");
// parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
// item.price = parts.join(",");
// });
// data.forEach((item) => {
// item.price = (parseFloat(item.price)).toString().replace("." , ",");
// });
this.buyList = data; this.buyList = data;
}, 500); }, 500);
let sellFun = lodash.throttle((data) => { let sellFun = lodash.throttle((data) => {

9
pages/exchange/sell-and-buy.vue

@ -14,6 +14,7 @@
@click="$emit('price',item.price)" @click="$emit('price',item.price)"
> >
<span class="color-sell" v-if="item.price>100">{{omitTo(item.price,2)}}</span> <span class="color-sell" v-if="item.price>100">{{omitTo(item.price,2)}}</span>
<!-- <span class="color-sell" v-if="item.price>100">{{omitTo(price1(item.price),2)}}</span> -->
<span class="color-sell" v-if="item.price>1&&item.price<100">{{omitTo(item.price,4)}}</span> <span class="color-sell" v-if="item.price>1&&item.price<100">{{omitTo(item.price,4)}}</span>
<span class="color-sell" v-if="item.price<1">{{omitTo(item.price,6)}}</span> <span class="color-sell" v-if="item.price<1">{{omitTo(item.price,6)}}</span>
<span class="p-r-xs">{{omitTo(item.amount,2)}}</span> <span class="p-r-xs">{{omitTo(item.amount,2)}}</span>
@ -105,6 +106,14 @@ export default {
let max = Math.max(...arr); let max = Math.max(...arr);
return math.division(amount, max, 2) * 100; return math.division(amount, max, 2) * 100;
}, },
price1(item){
if (item) {
let price = item.toString();
let parts = price.split(".");
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
return parts.join(",");
}
}
}, },
}; };
</script> </script>

8
utils/class/math.js

@ -90,6 +90,7 @@ function omitTo(val, scale) {
// 提取实体集和精度值 // 提取实体集和精度值
let [entity, precisionVal] = val.toString().split("."); let [entity, precisionVal] = val.toString().split(".");
entity = entity.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
if (precisionVal.length > scale) { if (precisionVal.length > scale) {
// trunc() 方法会将数字的小数部分去掉,只保留整数部分。 // trunc() 方法会将数字的小数部分去掉,只保留整数部分。
let tmp = scientific2No(Math.trunc(val * Math.pow(10, scale))); let tmp = scientific2No(Math.trunc(val * Math.pow(10, scale)));
@ -118,11 +119,14 @@ function omitTo(val, scale) {
} else { } else {
// 补全小数点 // 补全小数点
ret = entity + '.' + precisionVal.padEnd(scale, '0'); ret = entity + ',' + precisionVal.padEnd(scale, '0');
} }
// 检测整型值 // 检测整型值
} else ret = val + '.' + '0'.repeat(scale); } else {
val = val.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
ret = val + ',' + '0'.repeat(scale);
}
// 去除末尾可能产生的多余的. // 去除末尾可能产生的多余的.
if (ret.toString().endsWith('.')) ret = ret.slice(0, -1); if (ret.toString().endsWith('.')) ret = ret.slice(0, -1);

Loading…
Cancel
Save