Commit 77d898da authored by xhx's avatar xhx

封闭期相关处理

parent 4c6690af
NODE_ENV="development" NODE_ENV="development"
VUE_APP_URL="http://172.16.100.59:8090" #VUE_APP_URL="http://172.16.100.59:8090"
#VUE_APP_CHAIN="http://172.16.100.59:8801" VUE_APP_URL="http://172.16.100.59:8092"
VUE_APP_CHAIN="https://mainnet.bityuan.com/api" VUE_APP_CHAIN="http://172.16.100.59:8801"
\ No newline at end of file #VUE_APP_CHAIN="https://mainnet.bityuan.com/api"
\ No newline at end of file
NODE_ENV='development' NODE_ENV='development'
VUE_APP_URL="http://172.16.100.59:8090" #VUE_APP_URL="http://172.16.100.59:8090"
VUE_APP_URL="http://172.16.100.59:8092"
VUE_APP_CHAIN="http://172.16.100.59:8801" VUE_APP_CHAIN="http://172.16.100.59:8801"
\ No newline at end of file
...@@ -16,6 +16,12 @@ export default Vue.extend({ ...@@ -16,6 +16,12 @@ export default Vue.extend({
methods: { methods: {
// 账号是否能进入挖矿 // 账号是否能进入挖矿
async hasPoolAddr(addr: string) { async hasPoolAddr(addr: string) {
Toast.loading({
duration: 0,
forbidClick: true,
className: 'toast_x'
})
try {
const response = await service.getTicketAddress(addr) const response = await service.getTicketAddress(addr)
const walletRes = await service.getWalletAddress(addr) const walletRes = await service.getWalletAddress(addr)
const _result = response.data.result?.data const _result = response.data.result?.data
...@@ -23,7 +29,8 @@ export default Vue.extend({ ...@@ -23,7 +29,8 @@ export default Vue.extend({
Toast({ Toast({
message: '该账户不具备进入条件,将于3秒后退出', message: '该账户不具备进入条件,将于3秒后退出',
forbidClick: true, forbidClick: true,
duration: 3000 duration: 3000,
className: 'toast_x'
}) })
setTimeout(() => { setTimeout(() => {
closeWebview() closeWebview()
...@@ -40,7 +47,8 @@ export default Vue.extend({ ...@@ -40,7 +47,8 @@ export default Vue.extend({
Toast({ Toast({
message: '该账户不具备进入条件,将于3秒后退出', message: '该账户不具备进入条件,将于3秒后退出',
forbidClick: true, forbidClick: true,
duration: 3000 duration: 3000,
className: 'toast_x'
}) })
setTimeout(() => { setTimeout(() => {
closeWebview() closeWebview()
...@@ -48,9 +56,20 @@ export default Vue.extend({ ...@@ -48,9 +56,20 @@ export default Vue.extend({
} }
}) })
} }
} catch (e) {
console.log(e)
Toast({
message: '请求超时,请稍后再试',
className: 'toast_x'
})
setTimeout(() => {
closeWebview()
}, 1000)
}
} }
}, },
created() { mounted() {
getCurrentBTYAddress('',(res: any) => { getCurrentBTYAddress('',(res: any) => {
console.log('res', res) console.log('res', res)
this.$store.commit('app/SET_ADDRESS', res) this.$store.commit('app/SET_ADDRESS', res)
...@@ -83,4 +102,7 @@ export default Vue.extend({ ...@@ -83,4 +102,7 @@ export default Vue.extend({
} }
} }
} }
.toast_x {
z-index: 9999 !important;
}
</style> </style>
<template> <template>
<div class="mining-card bg-card-color px-2 pt-10 pb-2 rounded-lg"> <div class="mining-card bg-card-color px-2 pt-10 pb-2 rounded-lg">
<div class="mining-name bg-gradient-3 text-white text-13px rounded-r-full">{{ info.name }}</div> <div class="mining-name bg-gradient-3 text-white text-13px rounded-r-full">{{ info.name }}</div>
<time-box :date="runDays" :prefix="prefix" />
<div> <div>
<div class="px-2 flex items-center justify-between"> <div class="px-2 flex items-center justify-between">
<span class="font-semibold text-white1">{{ info.friendlyName }}</span> <span class="font-semibold text-white1">{{ info.friendlyName }}</span>
...@@ -31,6 +32,7 @@ ...@@ -31,6 +32,7 @@
<script lang="ts"> <script lang="ts">
import Vue from 'vue' import Vue from 'vue'
import InfoBar from '@/components/InfoBar.vue' import InfoBar from '@/components/InfoBar.vue'
import TimeBox from './TimeBox.vue'
export default Vue.extend({ export default Vue.extend({
props: { props: {
info: { info: {
...@@ -38,12 +40,30 @@ export default Vue.extend({ ...@@ -38,12 +40,30 @@ export default Vue.extend({
} }
}, },
components: { components: {
InfoBar InfoBar,
TimeBox
},
data() {
return {
prefix: ''
}
}, },
methods: { methods: {
goMining() { goMining() {
this.$emit('goDetails', (this.info as any)) this.$emit('goDetails', (this.info as any))
} }
},
computed: {
runDays() {
const info = (this as any).info
const isSell = +info.sellDays
if (isSell) {
(this as any).prefix = '封闭期'
return isSell * 24 * 3600 + Number(info.startTime) + ''
} else {
return Number(info.startTime) + (+info.days * 3600 * 24) + ''
}
}
} }
}) })
</script> </script>
......
<template>
<div class="absolute top-4 right-4 text-xs text-white3">
{{ prefix }}截止时间:{{ time }}
</div>
</template>
<script lang="ts">
import Vue from 'vue'
import { getEndTime } from '@/utils/utils'
export default Vue.extend({
props: {
prefix: {
type: String,
default: ''
},
date: {
type: String
}
},
computed: {
time() {
const val = +(this.date + '000')
console.log(val)
return getEndTime(val)
},
// prefix() {
// if (+this.date > 0) {
// return '封闭期'
// } else {
// return null
// }
// }
},
})
</script>
\ No newline at end of file
const stateData = {
showModal: true,
}
export type AppType = typeof stateData
export const global = {
namespaced: true,
state: () => ({
...stateData
}),
mutations: {
SET_SHOWMODAL(state: AppType, s: boolean) {
state.showModal = s
},
},
actions: {
},
getters: {
}
};
import Vue from 'vue' import Vue from 'vue'
import Vuex from 'vuex' import Vuex from 'vuex'
import { appStore } from './app' import { appStore } from './app'
import { global } from './global'
Vue.use(Vuex) Vue.use(Vuex)
...@@ -12,6 +13,7 @@ export default new Vuex.Store({ ...@@ -12,6 +13,7 @@ export default new Vuex.Store({
actions: { actions: {
}, },
modules: { modules: {
app: appStore app: appStore,
global: global
} }
}) })
...@@ -8,7 +8,8 @@ ...@@ -8,7 +8,8 @@
// } // }
export const test = { export const test = {
// addr: '1Lm22ZxsCHYE3PNtEnGYZJduJs5KG95GUp', // addr: '1Lm22ZxsCHYE3PNtEnGYZJduJs5KG95GUp',
addr: '16GgdskdRFasxuMdtBaxNS4ZagyZgEUuMs', addr: '16vD58z9z2Uvpci8ssvj797ENahbYZ497W',
// addr: '16GgdskdRFasxuMdtBaxNS4ZagyZgEUuMs',
// addr: '1LGQLmGVHSNthZcLbGpVfJTDmcicMQprZs', // addr: '1LGQLmGVHSNthZcLbGpVfJTDmcicMQprZs',
privateKey: '0xa65b62735022cd47b11c5a88b0caac8d360810257aaf1e14bbc330dee63b35ff' privateKey: '0xa65b62735022cd47b11c5a88b0caac8d360810257aaf1e14bbc330dee63b35ff'
} }
......
...@@ -9,3 +9,11 @@ export const getUsedDays = (d: string) => { ...@@ -9,3 +9,11 @@ export const getUsedDays = (d: string) => {
const p = new Date(d).getTime() const p = new Date(d).getTime()
return Math.floor((n - p) / (1000 * 60 * 60 * 24)) return Math.floor((n - p) / (1000 * 60 * 60 * 24))
} }
export const getEndTime = (d: number) => {
const date = new Date(d)
const year = date.getFullYear()
const month = (date.getMonth() + 1 >= 10) ? date.getMonth() + 1 : '0' + (date.getMonth() + 1)
const day = date.getDate() >= 10 ? date.getDate() : '0' + date.getDate()
return year + '年' + month + '月' + day + '日'
}
\ No newline at end of file
<template>
<div class="details">
<nav-bar left-arrow @click-left="onClickLeft" fixed>
<template #title>
<div class="text-lg text-white">
矿机详情
</div>
</template>
</nav-bar>
<div class="bg-gradient-6 p-4 pt-20">
<div class="pb-4">
<div class="text-brown1 text-base font-semibold text-left">{{ info.friendlyName || 'xinghao' }}</div>
</div>
<div class="mb-6 flex items-center justify-between">
<div class="text-left flex-grow">
<p class="mb-2 text-xs text-brown">委托票数</p>
<p class="text-base text-red1 font-semibold">3000 BTY=1票</p>
</div>
<div class="text-left flex-grow">
<p class="mb-2 text-xs text-brown">收益发放</p>
<p class="text-base text-red1 font-semibold">已实际出矿收益为准</p>
</div>
</div>
<div class="bg-gradient-7 py-2 text-13px text-brown3 flex items-center justify-between rounded">
<div class="flex-grow border-r border-solid border-card2-color">
<div>挖矿门槛</div>
<div>最低{{ info.minTicket || 10 }}票</div>
</div>
<div class="flex-grow border-r border-solid border-card2-color">
<div>矿机周期</div>
<div>{{ info.days }}天</div>
</div>
<div class="flex-grow">
<div>技术服务费</div>
<div class="special">限时免费</div>
</div>
</div>
</div>
<div class="bg-theme-color pt-3">
<div class="bg-card2-color px-4">
<p class="details-title">购买说明</p>
<div class="py-2">
<p class="details-item">
<span>挖矿门槛</span>
<span>最低{{ info.minTicket || 10 }}票</span>
</p>
<p class="details-item">
<span>矿池周期</span>
<span>{{ info.days }}天</span>
</p>
<p class="details-item">
<span>技术服务费</span>
<span class="special">限时免费</span>
</p>
<p class="details-item">
<span>运行机制</span>
<span>到期本金自动取回</span>
</p>
</div>
</div>
<div class="bg-card2-color px-4 mt-3">
<p class="details-title">挖矿信息</p>
<div class="py-2">
<p class="details-item">
<span class="flex-shrink-0 mr-3">矿池地址</span>
<span class="flex-grow-0 hide">{{ info.minerAddr }}</span>
</p>
<p class="details-item">
<span class="flex-shrink-0 mr-3">发起人挖矿地址</span>
<span class="flex-grow-0 hide">{{ info.selfAddr }}</span>
</p>
<p class="details-item">
<span>发起人委托票数</span>
<span>{{ info.selfEntrustTicket || 0 }}票</span>
</p>
<p class="details-item">
<span>当前委托人数</span>
<span class="special">{{ info.entrustPerson || 0 }}人</span>
</p>
<p class="details-item">
<span>当前委托挖矿票数</span>
<span class="special">{{ info.entrustTicket || 0 }}票</span>
</p>
</div>
</div>
<div class="bg-card2-color px-4 pb-16 mt-3">
<p class="details-title">风险提示</p>
<div class="py-2 text-sm text-white3 text-left">
<p class="pb-2 leading-5">1.bty会发生价格波动的情况,且挖矿难度是逐渐递增的。币价的波动或者挖矿难度的提高
都可能导致挖矿收益变动。本矿池不作保证收益承诺。用户须仔细评估自己的风险承受能力,
在可接受的风控范围内投资数字货币挖矿。矿池发起方对本矿池条款保留所有解释权。</p><br />
<p>2.由于法律政策、战争、地震、火灾和电力故障等不可抗原因导致矿池暂停运营,矿池发起
人不承担赔偿责任。</p>
</div>
</div>
</div>
<div class="w-full h-16 px-4 bg-card-color fixed bottom-0 flex items-center justify-between">
<div class="flex items-center">
<div class="text-sm text-white mr-3">票数</div>
<van-stepper v-model="value" :min="1" :max="Math.floor(profit/ticketNum)" integer />
</div>
<button class="bg-gradient-4 w-24 h-9 text-brown2 text-15px rounded-full" @click="buy">购买</button>
</div>
</div>
</template>
<script lang="ts">
import Vue from 'vue'
import { NavBar, Stepper, Toast } from 'vant'
import { poolInfo, bindPool, checkBind } from '@/service/pool'
import { signTxGroup } from '@33cn/wallet-api'
import service from '@/service/chain33'
export default Vue.extend({
components: {
'nav-bar': NavBar,
'van-stepper': Stepper
},
data() {
return {
value: 10,
info: {} as any,
fee: 0,
profit: 0,
isBind: false, // 初次购买 true: 否 false: 是
ticketNum: 10000 // BTY 转票比例
}
},
methods: {
onClickLeft() {
this.$router.back()
},
getFee() {
service.getProperFee(0, 0).then(res => {
console.log(res)
this.fee = res.data.result.properFee
})
service.getBalance(this.$store.state.app.address, 'coins').then((res: any) => {
console.log(res)
this.profit = Math.floor((res.data.result as any)[0].balance / 1e8)
})
},
getInfo() {
poolInfo(this.$route.query.id as string).then((res: any) => {
this.info = res.data.data
})
},
checkBind() {
checkBind(this.$route.query.id as string).then(res => {
if (res.data.data.isSucc) {
this.isBind = true
}
}).catch(() => {
this.isBind = false
})
},
signGroup(txs:Array<string>){
return signTxGroup(txs.join(),'none',-1);
},
async buy() {
if (this.profit < +this.info.minTicket) {
Toast(`您的票数余额为${this.profit}票,不足${this.info.minTicket}票`)
return
}
const bindRes = await service.createBindMiner({
bindAddr: this.info.minerAddr,
originAddr: this.$store.state.app.address,
amount: this.ticketNum * +this.value * 1e8,
checkBalance: false
})
const transRes = await service.createTransaction({
fee: this.fee,
to: '16htvcBNSEA7fZhAdLJphDwQRQJaHpyHTp',
amount: this.ticketNum * Number(this.value) * 1e8,
note: 'coins->ticket',
execName: 'ticket'
})
const sign = await this.signGroup([bindRes.data.result.txHex, transRes.data.result]);
Toast.loading({
duration: 0,
message: '购买中',
forbidClick: true
})
console.log('sign', sign)
const send = await service.sendTransaction(sign)
if (send.data.result.error) {
Toast('购买失败')
return
}
let res = {} as any
const timer = setInterval(async() => {
res = await service.getTransaction(send.data.result)
if (!res.data.error) {
clearInterval(timer)
const next = res.data.result.tx.next
const transaction = await service.getTransaction(next)
if (transaction.data.result.receipt.ty === 1) {
Toast(res.data.result.receipt.tyName)
} else {
const isBind = this.isBind ? true : false
bindPool(this.info.id, this.value, isBind).then(async (r: any) => {
if (r.data.data.isSucc) {
this.$toast('购买成功')
}
}).catch(e => {
Toast(e.response.data.reason)
})
}
}
}, 1000)
}
},
created() {
window.scrollTo(0, 0)
this.getInfo()
this.getFee()
this.checkBind()
}
})
</script>
<style lang="scss" scoped>
.details-title {
line-height: 44px;
color: #EFB771;
text-align: left;
border-bottom: 1px solid #47474B;
}
.details-item {
line-height: 36px;
color: rgba(255, 255, 255, 0.75);
font-size: 14px;
display: flex;
align-items: center;
justify-content: space-between;
}
.hide {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.special {
color: #FA6400
}
/deep/ .van-nav-bar {
background: #323232;
color: #fff;
}
/deep/ .van-nav-bar .van-icon {
color: #fff;
}
/deep/ .van-nav-bar__content {
height: 56px;
}
/deep/ .van-hairline--bottom::after {
border-bottom: none;
}
/deep/ .van-stepper__minus,
/deep/ .van-stepper__plus,
/deep/ .van-stepper__input {
color: #EFB771;
background: #3A3A3C;
border-color: #7A7979;
}
/deep/ .van-stepper__minus--disabled,
/deep/ .van-stepper__plus--disabled {
color: #c8c9cc;
background-color: #3A3A3C;
cursor: not-allowed;
}
/deep/ .van-stepper__minus--disabled,
/deep/ .van-stepper__plus--disabled,
/deep/ .van-stepper__minus--disabled:active,
/deep/ .van-stepper__plus--disabled:active {
background-color: #3A3A3C;
}
</style>
\ No newline at end of file
<template>
<div class="w-full min-h-screen pb-4">
<div class="w-full h-16 mb-0 px-4 bg-theme-color flex justify-between items-center fixed top-0 z-50">
<div class="text-2xl text-white">社区矿池</div>
<div class="flex-shrink-0 text-sm text-white" @click="goMining">
我的矿机
<span class="inline-block w-4 h-4 rounded-full bg-gradient-1">
<van-icon name="arrow" color="#323232" size="12" />
</span>
</div>
</div>
<div class="px-4 pt-20">
<div class="flex flex-col py-4 px-5 mb-11 bg-card bg-cover rounded-lg">
<div class="text-sm text-left pb-3 tracking-normal hide">当前地址:{{ addr }}</div>
<div class="flex items-center justify-between">
<div>
<p class="text-xs text-brown">可领收益</p>
<p class="text-3xl text-red1">{{ profit }}</p>
</div>
<div>
<p class="text-xs text-brown">参与票数</p>
<p class="text-3xl text-red1">{{ ticketNum }}</p>
</div>
<button
class="bg-gradient-2 w-20 h-8 leading-8 rounded-full text-sm text-white"
:disabled="btnType"
@click="getIncome">{{ btnText }}</button>
</div>
</div>
<div class="card-list relative py-7 px-3">
<div class="home-title w-full absolute flex items-start justify-center">
<div class="dot-l"></div>
<img class="w-1/5" src="../assets/image/t-l.png" alt="">
<img class="w-1/4 mt-1.5 mx-1" src="../assets/image/title.png" alt="">
<img class="w-1/5" src="../assets/image/t-r.png" alt="">
<div class="dot-r"></div>
</div>
<div>
<template v-if="lists.length > 0">
<div class="no-content">
<van-pull-refresh
v-model="isLoading"
success-text="刷新成功"
@refresh="onRefresh">
<MiningCard v-for="(i, index) in lists" :key="index" :info="i" />
</van-pull-refresh>
</div>
</template>
<template v-else>
<div class="no-content text-white flex items-center justify-center">
暂无矿池
</div>
</template>
</div>
</div>
</div>
<van-popup v-model="show" :close-on-click-overlay="false">
<div class="p-3 flex flex-col bg-theme-color text-white1">
<div class="mb-5">请输入推荐人</div>
<input class="mb-2 bg-theme-color border-b border-solid border-white2" type="text" max="34" v-model="val">
<button class="bg-blue" @click="addInvite">确定</button>
</div>
</van-popup>
</div>
</template>
<script lang="ts">
import { Icon, PullRefresh, Toast, Popup } from 'vant'
import MiningCard from '@/components/MiningCard.vue'
import Vue from 'vue'
import service from '@/service/chain33'
import { invitePool, poolList, userMinedData } from '@/service/pool'
export default Vue.extend({
components: {
'van-icon': Icon,
'van-pull-refresh': PullRefresh,
'van-popup': Popup,
MiningCard
},
data() {
return {
addr: '',
btnText: '领取收益',
btnType: false,
lists: [] as any,
isLoading: false,
count: 0,
timer: 0,
waiter: 180000,
page: 1,
pageSize: 10,
ticketNum: 0,
profit: 0,
fee: 0,
show: false,
val: '',
refresh: false
}
},
methods: {
addInvite() {
if (!this.val) {
this.$toast('请先输入推荐人地址')
}
invitePool(this.val).then((res: any) => {
if (res.data.data.isSucc) {
this.$toast('添加成功')
this.show = false
this.getInfo()
this.getList()
this.getTicket()
} else {
this.$toast('请输入正确的推荐人地址')
}
}).catch(() => {
this.$toast('请输入正确的推荐人地址')
})
},
getFee() {
service.getProperFee(0, 0).then(res => {
this.fee = res.data.result.properFee
})
},
getTicket() {
userMinedData().then(res => {
this.ticketNum = res.data.data.tickets
})
},
getList() {
poolList({
page: this.page,
pageSize: this.pageSize
}).then((res: any) => {
if (this.refresh) {
this.refresh = false
this.lists = []
}
res.data.data?.list ? this.lists.push(...res.data.data?.list) : this.lists = []
this.count = +res.data.data.count
document.addEventListener('scroll', this.scrollEvent)
}).catch(e => {
const err = e.response
if (err.data?.code === 406 && err.data?.reason === 'USER_NOT_BIND') {
this.show = true
}
if (this.timer) {
clearInterval(this.timer)
}
})
this.isLoading = false
},
getInfo() {
service.getBalance(this.$store.state.app.address, 'ticket').then((res: any) => {
this.profit = Math.floor((res.data.result as any)[0].balance / 1e8)
})
},
async getIncome() {
if (!this.profit) {
this.$toast('当前无收益可领')
return
}
this.btnText = '领取中'
this.btnType = true
Toast.loading({
message: '领取中',
forbidClick: true,
duration: 0
})
const transaction = await service.createTransaction({
to: '16htvcBNSEA7fZhAdLJphDwQRQJaHpyHTp',
amount: this.profit * 1e8,
fee: this.fee,
note: 'ticket -> coins',
isWithdraw: true,
execName: 'ticket'
})
await service.signTransition((transaction as any).data.result, async (sign: any) => {
let s = {} as any
if (typeof sign === 'string') {
s = JSON.parse(sign)
} else {
s = sign
}
if (s.error) {
Toast.clear()
this.btnText = '领取收益'
this.btnType = false
return
}
const send = await service.sendTransaction(s.signHash)
if (send.data.error) {
Toast(send.data.error)
this.btnText = '领取收益'
this.btnType = false
return
}
let res = {} as any
const timer = setInterval(async() => {
res = await service.getTransaction(send.data.result)
if (!res.data.error) {
clearInterval(timer)
if (res.data.result.receipt.ty === 1) {
this.$toast({
message: '领取失败',
duration: 3000
})
this.btnText = '领取收益'
this.btnType = false
} else {
this.$toast({
message: '领取成功',
duration: 3000
})
this.btnText = '领取收益'
this.btnType = false
this.getInfo()
}
}
}, 1000)
})
},
goMining() {
this.$router.push({ path: '/mine', query: {}})
},
onRefresh() {
this.page = 1
this.refresh = true
this.getList()
},
scrollEvent() {
const e = document.querySelector('.mining-card')
const g = (e as HTMLElement)?.offsetHeight
const h = document.documentElement?.scrollTop || document.body.scrollTop
if (this.lists.length < this.count) {
if (h > (g * this.page * (this.pageSize - 3))) {
this.page++
this.getList()
}
}
},
setTimer() {
if (this.timer) clearInterval(this.timer)
this.timer = setInterval(() => {
this.onRefresh()
}, this.waiter)
}
},
mounted() {
this.addr = this.$store.state.app.address
this.getList()
this.getInfo()
this.getFee()
this.getTicket()
this.setTimer()
},
beforeDestroy() {
const that = this
document.removeEventListener('scroll', that.scrollEvent)
clearInterval(this.timer)
}
})
</script>
<style lang="scss" scoped>
.home-header {
width: 100%;
position: fixed;
// position: sticky;
top: 0;
z-index: 50;
background: #323232;
}
.card-list {
border: 1px solid #A67855;
border-top: none;
border-radius: 5px;
.home-title {
top: 0;
left: 50%;
transform: translate3d(-50%, -50%, 0);
&::before, &::after {
display: block;
content: '';
width: 15%;
height: 5px;
border-top: 1px solid #A67855;
position: absolute;
}
&::after {
border-top-right-radius: 5px;
top: 50%;
right: -1px;
}
&::before {
border-top-left-radius: 5px;
top: 50%;
left: -1px;
}
.dot-l, .dot-r {
width: 6px;
height: 6px;
border-radius: 50%;
background: #A67855;
box-shadow: 0 0 2px 1px #A67855;
position: absolute;
top: 50%;
transform: translate3d(0, -50%, 0);
}
.dot-l {
left: 14%;
}
.dot-r {
right: 14%;
}
}
}
.no-content {
min-height: calc(100vh - 320px)
}
.hide {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
/deep/ .van-pull-refresh {
overflow: inherit;
}
/deep/ .van-popup--center {
width: 90%;
border-radius: 12px;
}
</style>
...@@ -45,6 +45,7 @@ export default Vue.extend({ ...@@ -45,6 +45,7 @@ export default Vue.extend({
}, },
methods: { methods: {
waitToPool() { waitToPool() {
if (this.timer) clearInterval(this.timer)
this.timer = setInterval(() => { this.timer = setInterval(() => {
this.getInfo() this.getInfo()
}, 5000) }, 5000)
......
...@@ -61,7 +61,7 @@ export default Vue.extend({ ...@@ -61,7 +61,7 @@ export default Vue.extend({
computed: { computed: {
constant() { constant() {
return constant.HOME_IMAGE return constant.HOME_IMAGE
} },
}, },
methods: { methods: {
getList() { getList() {
...@@ -76,12 +76,14 @@ export default Vue.extend({ ...@@ -76,12 +76,14 @@ export default Vue.extend({
res.data.data?.list ? this.lists.push(...res.data.data?.list) : this.lists = [] res.data.data?.list ? this.lists.push(...res.data.data?.list) : this.lists = []
this.count = +res.data.data.count this.count = +res.data.data.count
document.addEventListener('scroll', this.scrollEvent) document.addEventListener('scroll', this.scrollEvent)
Toast.clear() // Toast.clear()
}).catch(e => { }).catch(e => {
const err = e.response const err = e.response
Toast.clear() // Toast.clear()
if (err.data?.code === 406 && err.data?.reason === 'USER_NOT_BIND') { if (err.data?.code === 406 && err.data?.reason === 'USER_NOT_BIND') {
this.show = true this.show = true
} else {
Toast('网络异常')
} }
if (this.timer) { if (this.timer) {
clearInterval(this.timer) clearInterval(this.timer)
...@@ -111,8 +113,10 @@ export default Vue.extend({ ...@@ -111,8 +113,10 @@ export default Vue.extend({
this.onRefresh() this.onRefresh()
}, this.waiter) }, this.waiter)
}, },
goDetails(val: { id: string, minerAddr: string }) { goDetails(val: { id: string, minerAddr: string, sellDays: string, startTime: string }) {
// clear 用于清除失败提示
service.getTicketAddress(this.$store.state.app.address).then(r => { service.getTicketAddress(this.$store.state.app.address).then(r => {
// 已经投过票,跳过封闭期
if (r.data.result?.data) { if (r.data.result?.data) {
checkBind(val.id).then(res => { checkBind(val.id).then(res => {
if (res.data.data.isSucc) { if (res.data.data.isSucc) {
...@@ -122,23 +126,29 @@ export default Vue.extend({ ...@@ -122,23 +126,29 @@ export default Vue.extend({
}).catch(() => { }).catch(() => {
Toast('该账号已绑定过矿池') Toast('该账号已绑定过矿池')
}) })
// this.$router.push({ path: '/details', query: { id: val.id || '1' }}) } else {
// 未投过,检测封闭期是否到期,到期停止进入
const _now = Date.now()
const endTime = (+val.startTime + (+val.sellDays * 24 * 3600)) * 1000
if (endTime < _now && val.sellDays !== '0') {
Toast('改矿池已过封闭期,您不能进入')
} else { } else {
Toast.clear() Toast.clear()
this.$router.push({ path: '/details', query: { id: val.id || '1' }}) this.$router.push({ path: '/details', query: { id: val.id || '1' }})
} }
}
}).catch(e => {
Toast('网络异常')
}) })
}, },
addInvite(val: string) { addInvite(val: string) {
// const regexp = /^(1|3)[a-zA-Z\d]{24,33}$/ // if (this.$store.state.global.showModal) {
// return
// }
if (!val) { if (!val) {
Toast('请先输入推荐人地址') Toast('请先输入推荐人地址')
return return
} }
// else if (!regexp.test(val)) {
// Toast('请输入正确的推荐人地址')
// return
// }
invitePool(val).then((res: any) => { invitePool(val).then((res: any) => {
if (res.data.data.isSucc) { if (res.data.data.isSucc) {
Toast('添加成功') Toast('添加成功')
...@@ -154,7 +164,9 @@ export default Vue.extend({ ...@@ -154,7 +164,9 @@ export default Vue.extend({
}, },
}, },
created() { created() {
Toast.loading() // Toast.loading({
// duration: 0
// })
this.getList() this.getList()
this.setTimer() this.setTimer()
}, },
......
<template>
<div class="mine">
<nav-bar left-arrow @click-left="onClickLeft" fixed>
<template #title>
<div class="tab-tool">
<div :class="{'active': active === 1}" @click="setTab(1)">进行中</div>
<div :class="{'active': active === 2}" @click="setTab(2)">已结束</div>
</div>
</template>
</nav-bar>
<div class=" min-h-screen pb-5 px-4 pt-16">
<keep-alive>
<template v-if="lists.length > 0">
<van-pull-refresh
v-model="isLoading"
success-text="刷新成功"
@refresh="onRefresh">
<mining-info v-for="i in lists" :key="i" :type="active" :info="i" />
</van-pull-refresh>
</template>
<template v-else>
<div class="no-content text-white flex items-center justify-center">暂无矿机</div>
</template>
</keep-alive>
</div>
</div>
</template>
<script lang="ts">
import Vue from 'vue'
import { NavBar, PullRefresh } from 'vant'
import MiningInfo from '@/components/MiningInfo.vue'
import { userMachineList } from '@/service/pool'
export default Vue.extend({
components: {
'nav-bar': NavBar,
'van-pull-refresh': PullRefresh,
MiningInfo
},
data() {
return {
active: 1,
isLoading: false,
lists: [],
page: 1,
pageSize: 10,
count: 0,
status: 2 // 2 在线 1 离线
}
},
methods: {
getNowList() {
userMachineList({
page: this.page,
pageSize: this.pageSize,
status: 2
}).then(res => {
this.count = +res.data.data.count
this.lists = res.data.data.list || []
document.addEventListener('scroll', this.scrollEvent)
})
this.isLoading = false
},
getEndList() {
userMachineList({
page: this.page,
pageSize: this.pageSize,
status: 1
}).then(res => {
this.count = +res.data.data.count
this.lists = res.data.data.list || []
document.addEventListener('scroll', this.scrollEvent)
})
this.isLoading = false
},
onClickLeft() {
this.$router.back()
},
scrollEvent() {
const e = document.querySelector('.mining-card')
const g = (e as HTMLElement)?.offsetHeight
const h = document.documentElement?.scrollTop || document.body.scrollTop
if (this.lists.length < this.count) {
if (h > (g * this.page * (this.pageSize - 3))) {
this.page++
if (this.active === 1) {
this.getNowList()
} else {
this.getEndList()
}
}
}
},
onRefresh() {
this.page = 1
this.pageSize = 10
if (this.active === 1) {
this.getNowList()
} else {
this.getEndList()
}
},
setTab(n: number) {
this.active = n
this.lists = []
if (this.active === 1) {
this.getNowList()
} else {
this.getEndList()
}
}
},
mounted() {
this.getNowList()
},
beforeDestroy() {
document.removeEventListener('scroll', this.scrollEvent)
}
})
</script>
<style lang="scss" scoped>
.tab-tool {
width: 140px;
height: 32px;
line-height: 32px;
color: #EFB771;
display: flex;
align-items: center;
border: 1px solid #EFB771;
border-radius: 6px;
overflow: hidden;
box-sizing: border-box;
div {
height: 100%;
flex: 1;
}
}
.active {
background: linear-gradient(to right, #FCE4C1, #EFB771);
color: #4F320D;
}
.no-content {
height: calc(100vh - 84px);
}
/deep/ .van-nav-bar {
background: #323232;
}
/deep/ .van-nav-bar .van-icon {
color: #fff;
}
/deep/ .van-nav-bar__content {
height: 56px;
}
/deep/ .van-hairline--bottom::after {
border-bottom: none;
}
/deep/ .van-pull-refresh {
overflow: inherit;
}
</style>
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment