diff --git a/api/market.js b/api/market.js index b7ffe6e..e1abf0e 100644 --- a/api/market.js +++ b/api/market.js @@ -65,7 +65,10 @@ class Market { static getstockCoinInfo(data){ return Serve.get(`/stock/getCoinInfo`,data) } - + // 是否显示颜色 + static getstocktradingOpen(data){ + return Serve.get(`/stock/tradingOpen`,data) + } } export default Market; \ No newline at end of file diff --git a/layout/vButton.vue b/layout/vButton.vue index d782f64..3e5b38f 100644 --- a/layout/vButton.vue +++ b/layout/vButton.vue @@ -205,4 +205,13 @@ export default { border-radius:inherit; } } +.colorless { + ::v-deep uni-button { + background: #999999; + color: #fff; + border:none; + border-radius:inherit; + box-shadow: 0px 0px 15px 0px rgba(199, 199, 199, 0.7); + } +} \ No newline at end of file diff --git a/pages/base/stockexchange-operation.vue b/pages/base/stockexchange-operation.vue index 4c9d9f4..1d28dca 100644 --- a/pages/base/stockexchange-operation.vue +++ b/pages/base/stockexchange-operation.vue @@ -68,7 +68,7 @@ @@ -98,10 +98,6 @@ export default { type: String, required: false, }, - stocksymbol: { - default: '', - type: String - } }, components: { exchangeTransaction, @@ -126,15 +122,14 @@ export default { watch: { isShow(n) { if (n) { - this.query = { symbol: this.stocksymbol }; setTimeout(() => { - this.ws.send({ + this.ws2.send({ cmd: "sub", msg: this.msg, }); }, 200); } else { - this.ws.send({ + this.ws2.send({ cmd: "unsub", msg: this.msg, }); @@ -143,7 +138,7 @@ export default { }, computed: { ...mapState({ - ws: "ws", + ws2: "ws2", }), isLogin() { return Boolean(uni.getStorageSync("token")); @@ -199,11 +194,11 @@ export default { // 链接socket linkSocket() { let msg = this.msg; - this.ws.send({ + this.ws2.send({ cmd: "sub", msg, }); - this.ws.on("message", (res) => { + this.ws2.on("message", (res) => { let { data, sub } = res; if (sub == msg) { this.marketList = data; @@ -227,11 +222,6 @@ export default { return curParam; }, }, - mounted() { - if (this.stocksymbol) { - this.query = { symbol: this.stocksymbol }; - } - }, created() { this.query = this.getQuery(); if (this.query.symbol) { @@ -241,7 +231,7 @@ export default { this.getCollect(); }, destroyed() { - this.ws.send({ + this.ws2.send({ cmd: "unsub", msg: 'exchangeMarketList', }) diff --git a/pages/stockexchange/exchange-transaction.vue b/pages/stockexchange/exchange-transaction.vue index b5903b1..61ed1ab 100644 --- a/pages/stockexchange/exchange-transaction.vue +++ b/pages/stockexchange/exchange-transaction.vue @@ -4,14 +4,14 @@ - {{ symbol }} + {{ activeCoin.coin_name }} {{increase.increaseStr}} - + {{ - form.direction == "buy" - ? this.$t("exchange.c3") - : this.$t("exchange.c4") - }} + v-if="tradingOpenshow==true"> + {{form.direction == "buy" ? this.$t("exchange.c3") : this.$t("exchange.c4")}} {{ activeCoin.coin_name }} + + {{form.direction == "buy" ? this.$t("exchange.c3") : this.$t("exchange.c4")}} + {{ activeCoin.coin_name }} - {{$t("exchange.g8")}}:{{item.pair_name}} + {{$t("exchange.g9")}}:{{item.coin_name}} - {{$t("exchange.g9")}}:{{item.market}} + {{$t("exchange.g10")}}:{{item.market}} - {{$t("exchange.g10")}}:{{item.usable_balance}} + {{$t("exchange.g11")}}:{{item.usable_balance}} - {{$t("exchange.g11")}}:{{item.realtimePrice}} + {{$t("exchange.g12")}}:{{item.realtimePrice}} - {{$t("exchange.g12")}}:{{item.cost_price}} + {{$t("exchange.g13")}}:{{item.cost_price}} - {{$t("exchange.g13")}}:{{item.dayProfit}} + {{$t("exchange.g14")}}:{{item.dayProfit}} - {{$t("exchange.g14")}}:{{item.unRealProfit}} + {{$t("exchange.g15")}}:{{item.unRealProfit}} - {{$t("exchange.g15")}}:{{item.profitRate}} + {{$t("exchange.g16")}}:{{item.profitRate}} @@ -461,7 +469,10 @@ export default { refreshing:false, active:0, stockholdPositionlist:[], - holdPositiondtime: null + holdPositiondtime: null, + + tradingOpenshow:false, + timer: null, }; }, computed: { @@ -526,14 +537,27 @@ export default { // 计算交易额 totalMoney() { // todo - let totalMoney = 0; - if (this.form.type == 0) { - totalMoney = math.multiple(this.form.amount, this.form.entrust_price); - } else { - // totalMoney = this.form.amount; - totalMoney = math.multiple(this.form.amount, this.form.entrust_price); - } - return totalMoney; + // let totalMoney = 0; + // if (this.form.type == 0) { + // totalMoney = math.multiple(this.form.amount, this.form.entrust_price); + // } else { + // // totalMoney = this.form.amount; + // totalMoney = math.multiple(this.form.amount, this.form.entrust_price); + // } + // return totalMoney; + let totalMoney = 0; + // 确保拿到的 amount 和 price 是有效数字,如果是空字符串或 -Infinity 则当做 0 处理 + let amount = Number(this.form.amount) || 0; + let price = Number(this.form.entrust_price) || 0; + + if (this.form.type == 0) { + totalMoney = math.multiple(amount, price); + } else { + totalMoney = math.multiple(amount, price); + } + + // 防止计算库返回异常值 + return isNaN(totalMoney) ? 0 : totalMoney; }, // 显示百分比 activeStep() { @@ -554,18 +578,22 @@ export default { usable() { if (this.form.direction == "buy") { if (!this.targetBalance.usable_balance) return 0; - return this.omitTo( - // this.targetBalance.usable_balance, - // this.activeCoin.price_decimals - this.currentBalance.usable_balance, - this.activeCoin.qty_decimals - ); + // return this.omitTo( + // // this.targetBalance.usable_balance, + // // this.activeCoin.price_decimals + // this.currentBalance.usable_balance, + // this.activeCoin.qty_decimals + // ); + return this.currentBalance.usable_balance } else { + // console.log(this.currentBalance); if (!this.currentBalance.usable_balance) return 0; - return this.omitTo( - this.currentBalance.usable_balance, - this.activeCoin.qty_decimals - ); + // return this.omitTo( + // this.currentBalance.usable_balance, + // // this.targetBalance.usable_balance, + // this.activeCoin.qty_decimals + // ); + return this.currentBalance.usable_balance } }, usable1() { @@ -618,10 +646,13 @@ export default { },3000) this.getUserBalance(); this.linkSocket(this.activeCoin.symbol); + + this.startSchedule(); } else if(!n&&this.isLogin){ this.unLink(this.activeCoin.symbol); clearInterval(this.dtime); clearInterval(this.holdPositiondtime); + clearInterval(this.timer); } }, @@ -633,9 +664,11 @@ export default { this.holdPositiondtime = setInterval(()=>{ this.stockholdPosition(); },3000) + this.startSchedule(); }else if(e!='stockexchange-operation'&&this.isLogin){ clearInterval(this.dtime); clearInterval(this.holdPositiondtime); + clearInterval(this.timer); } }, list(e){ @@ -708,6 +741,7 @@ export default { // 计算滑动出来的金额 sliderChange(n,i) { // console.log(n, i, this.form.direction); + if(!n)return let num = n/100; this.sliderActive=i if (this.form.direction == "buy") { @@ -720,11 +754,16 @@ export default { ); } else if (this.form.type == 1) { // 市价 - this.form.amount = this.form.amount = math.multiple( - this.targetBalance.usable_balance, - num, - 4 - ); + // this.form.amount = this.form.amount = math.multiple( + // this.targetBalance.usable_balance, + // num, + // 4 + // ); + this.form.amount = math.multiple( + this.targetBalance.usable_balance / this.form.entrust_price, + num, + 6 + ); } } else if (this.form.direction == "sell") { if (!this.currentBalance.usable_balance) return; @@ -783,12 +822,14 @@ export default { if(ti===3){ clearInterval(timer); } - }, 1000) + }, 2000) } - console.log('123'); + // console.log('123'); this.dtime = setInterval(() => { this.getCurrentEntrust(true) }, 3000); + this.sliderChange(null,-1) + this.sliderActive = -1 // this.getCurrentEntrust() }) .catch(() => {}); @@ -808,24 +849,85 @@ export default { this.newPrice = this.tradeList[0]||{}; }); }, + + + tradingOpen(){ + Market.getstocktradingOpen().then(res => { + this.tradingOpenshow = res.data + }).catch(err => {}); + }, + startSchedule() { + this.timer = setInterval(() => { + const now = new Date(); + const minutes = now.getMinutes(); + const seconds = now.getSeconds(); + + let remainingSeconds = 0; + + // 1. 如果正好是 00分00秒 或 30分00秒,说明时间到了! + if (minutes % 30 === 0 && seconds === 0) { + remainingSeconds = 0; + console.log(`距离下次刷新还有 ${remainingSeconds} 秒,正在执行刷新...`); + + // 触发接口调用 + this.tradingOpen(); + } + // 2. 否则,计算距离下一次刷新的秒数 + else { + if (minutes < 30) { + // 如果当前是 0~29 分,目标是 30 分 + remainingSeconds = (30 - minutes) * 60 - seconds; + } else { + // 如果当前是 30~59 分,目标是 60 分 (下一个整点) + remainingSeconds = (60 - minutes) * 60 - seconds; + } + + // 一直打印倒计时提示 + // console.log(`距离下次刷新还有 ${remainingSeconds} 秒`); + } + }, 1000); + }, + + // 获取默认价格 getDefaultPrice() { - if (this.form.direction == "buy") { - this.form.entrust_price = Math.min( - ...this.tradeList.map((item) => item.price) - ); - } else { - this.form.entrust_price = Math.max( - ...this.buyList.map((item) => item.price) - ); - } + // if (this.form.direction == "buy") { + // this.form.entrust_price = Math.min( + // ...this.tradeList.map((item) => item.price) + // ); + // } else { + // this.form.entrust_price = Math.max( + // ...this.buyList.map((item) => item.price) + // ); + // } + if (this.form.direction == "buy") { + // 确保 tradeList 有数据 + if (this.tradeList && this.tradeList.length > 0) { + this.form.entrust_price = Math.min( + ...this.tradeList.map((item) => Number(item.price)) + ); + } else { + // 兜底方案:如果没有数据,使用最新价或0 + this.form.entrust_price = this.newPrice.price || 0; + } + } else { // 卖出 + // 确保 buyList 有数据 + if (this.buyList && this.buyList.length > 0) { + this.form.entrust_price = Math.max( + ...this.buyList.map((item) => Number(item.price)) + ); + } else { + // 兜底方案:如果没有买盘数据,使用最新价或0 + this.form.entrust_price = this.newPrice.price || 0; + } + } }, // 切换方向 changeDirection(type){ this.form.direction = type; this.getDefaultPrice(); let n = this.progress[this.sliderActive]; - // this.sliderChange(n, this.sliderActive); + this.sliderChange(n, this.sliderActive); }, // 计算深度 getValue(amount) { @@ -944,6 +1046,10 @@ export default { this.getBooks(); this.getUserBalance(); this.socketMessage(); + + this.tradingOpen() + this.startSchedule(); + if (this.query.direction) { this.form.direction = this.query.direction; } @@ -959,6 +1065,9 @@ export default { // this.unLink(this.unSymbol); clearInterval(this.dtime); clearInterval(this.holdPositiondtime); + if (this.timer) { + clearInterval(this.timer); + } }, }; @@ -1130,4 +1239,7 @@ export default { .bor5-active{ border-bottom: 4px solid $theme-2; } +/deep/uni-input{ + background-color: transparent; +} \ No newline at end of file diff --git a/pages/stockexchange/index.vue b/pages/stockexchange/index.vue index 28cd1b8..aea5be3 100644 --- a/pages/stockexchange/index.vue +++ b/pages/stockexchange/index.vue @@ -562,5 +562,6 @@ export default { .chart-tradingview { height: 370px; width: 100%; + border: 0px; } diff --git a/pages/stockexchange/symbol-list.vue b/pages/stockexchange/symbol-list.vue index 8198cb3..63c52c8 100644 --- a/pages/stockexchange/symbol-list.vue +++ b/pages/stockexchange/symbol-list.vue @@ -1,14 +1,14 @@ - {{ title||$t("exchange.f5") }} + {{ heyue==2?$t('exchange.g7'):title||$t("exchange.f5") }} - + + + + + + + + + {{ $t("exchange.f7") }} + {{ $t("exchange.f8") }} + {{ $t("exchange.f9") }} + + + + + + + {{ item.pair_name }} + + + {{ item.coin_name||item.symbol }} + + + + + {{ item.price }} + + + + {{ item.increaseStr }} + + + + + + + +