Files
BlockChainH5/pages/index/index.vue
2021-11-15 17:17:18 +08:00

703 lines
16 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<view class="content">
<!-- ios安全区 -->
<view class="ios-top"></view>
<!-- header -->
<view class="header-total ios-top">
<view class="total">
<view class="item nowrap" @click="navAccount('walletProperty')">
<image src="@/static/icons/gemstone-icon.png" />{{isAuth ? '通证' + account.coin : '查看通证'}}
</view>
<view class="item nowrap" @click="navAccount('Fragment')">
<image src="@/static/icons/crystal-icon.png" />{{isAuth ? '贡献值' + account.crystal : '查看贡献值'}}
</view>
</view>
</view>
<!-- 矿机 -->
<view class="ore">
<image class="ore-back" src="@/static/background/chain-back-00.png" mode="widthFix"></image>
<view class="ball">
<view class="shadow"></view>
</view>
<block v-if="isAuth">
<view class="ore-lists">
<view class="oct-float ore-item" v-for="(item, index) in crystalArr" :key="index" :style="{left: item.left + '%', top: item.top + '%'}" @click="ledCrystal(index)">
<block v-if="item.amount !== null">
<view class="oct-icon">
<image src="@/static/icons/crystal-icon.png" mode="widthFix" class="icon" />
</view>
<view class="text">{{ item.amount || '-'}}</view>
</block>
</view>
<view class="oct-float ore-item-nav" @click="issueGoosd">
<view class="oct-icon">
<image src="@/static/icons/gemstone-ore-icon.png" mode="widthFix" class="icon" />
</view>
<view class="text">发权证<uni-icons type="arrowright" color="#FFFFFF" size="12"></uni-icons>
</view>
</view>
</view>
</block>
<block v-else>
<view class="ore-lists">
<view class="oct-float oct-login" @click="$Router.push({name: 'Login'})">
<view class="oct-icon">
<image src="@/static/icons/crystal-icon.png" mode="widthFix" class="icon" />
</view>
<view class="text">登录后领取</view>
</view>
</view>
</block>
</view>
<!-- 任务推荐 -->
<scroll-view class="task-block" scroll-x="true">
<view class="item" v-for="(item, index) in categoryArr" :key="index" @click="JumpUrl(item.url, item.title)">
<view class="text nowrap">{{item.sub_title}}</view>
<view class="icon">
<image :src="item.cover" />
</view>
<view class="title nowrap">{{item.title}}</view>
<view class="submit-title nowrap">贡献值{{item.tips}}</view>
</view>
</scroll-view>
<!-- 平台概况 -->
<view class="situation">
<view class="header">
<view class="header-item">
<view class="title">平台通证余量
<uni-icons class="help-icon" @click="showHelp('balance')" type="help-filled" size="15"
color="rgba(255,255,255,.3)" />
</view>
<view class="number nowrap">{{chains.balance}}</view>
</view>
<view class="header-item">
<view class="title">上期发放通证
<uni-icons class="help-icon" @click="showHelp('stone')" type="help-filled" size="15"
color="rgba(255,255,255,.3)" />
</view>
<view class="number nowrap">{{chains.stone}}</view>
</view>
<view class="header-item">
<view class="title">当前通证价值
<uni-icons class="help-icon" @click="showHelp('up')" type="help-filled" size="15"
color="rgba(255,255,255,.3)" />
</view>
<view class="number nowrap">{{chains.up}}</view>
</view>
<view class="header-item">
<view class="title">昨日瓜分贡献值
<uni-icons class="help-icon" @click="showHelp('score')" type="help-filled" size="15"
color="rgba(255,255,255,.3)" />
</view>
<view class="number nowrap">{{chains.score}}</view>
</view>
<view class="header-item">
<view class="title">区块链高度
<uni-icons class="help-icon" @click="showHelp('height')" type="help-filled" size="15"
color="rgba(255,255,255,.3)" />
</view>
<view class="number nowrap">{{chains.height}}</view>
</view>
<view class="header-item">
<view class="title">已开通节点数
<uni-icons class="help-icon" @click="showHelp('number')" type="help-filled" size="15"
color="rgba(255,255,255,.3)" />
</view>
<view class="number nowrap">{{chains.number}}</view>
</view>
</view>
<!-- 平台累计盈利通证 -->
<view class="chart">
<view class="title">累计盈利和通证价值走势图</view>
<view class="chart-f2">
<l-f2 ref="chartChange"></l-f2>
</view>
</view>
<!-- 提示信息 -->
<u-toast ref="uToast" />
</view>
</view>
</template>
<script>
import { chain, crystals, thawlog } from '@/apis/interfaces/chain'
import F2 from '@/uni_modules/lime-f2/components/lime-f2/f2.min.js'
import lF2 from '@/uni_modules/lime-f2/components/lime-f2/'
export default {
components: { lF2 },
data() {
return {
isAuth: false,
chains: { // 区块链统计
balance: 0,
height: 0,
number: 0,
score: 0,
up: 0,
stone: 0
},
account: { // 账户
coin: 0,
crystal: 0
},
crystalArr: [], // 待领取
allIds: [], // 可领取ids
categoryArr: [], // 推荐列表
help: {}, // 帮助信息
userAuth: { // 用户认证状态
certification: false,
company: false,
vip: false
},
// 领取贡献值队列
queueData : [],
queueState : false
};
},
onShow() {
this.isAuth = this.$store.state.token != ''
this.getIndex()
},
methods: {
// 求助信息
showHelp(key) {
uni.showModal({
title: '提示',
content: this.help[key],
showCancel: false,
confirmColor: '#8b64fd'
})
},
// 查看钱包账户
navAccount(pathName) {
if (!this.isAuth) {
this.$Router.push({
name: 'Login'
})
return
}
this.$Router.push({
name: pathName
})
},
// 发权证
issueGoosd() {
let typeAuth = '',
pathName = ''
if (this.userAuth.company && this.userAuth.vip) {
this.$Router.push({
name: 'goodsManagement'
})
return
} else if (!this.userAuth.vip) {
typeAuth = '暂未开通平台VIP会员节点无法发布商品权证'
pathName = 'vipIndex'
} else if (!this.userAuth.company) {
typeAuth = '企业未认证或企业认证审核中,无法发布商品权证'
pathName = 'setting'
}
uni.showModal({
title: '提示',
content: typeAuth,
cancelColor: '#555',
cancelText: '稍后',
confirmText: pathName === 'vipIndex' ? '去开通' : '去认证',
confirmColor: '#8b64fd',
success: res => {
if (res.confirm) {
if (pathName === 'vipIndex') {
this.$Router.push({
name: 'vipIndex',
params: {
identity_id: this.userAuth.identity
}
})
return
}
this.$Router.push({
name: pathName
})
}
}
})
},
// 领取贡献值
ledCrystal(index) {
// 播放音频
const innerAudioContext = uni.createInnerAudioContext();
innerAudioContext.autoplay = true;
innerAudioContext.src = require('@/static/mp3/crystal.mp3');
// 请求接口
thawlog({
thaw_id: this.crystalArr[index].log_id,
all_ids: this.allIds
}).then(res => {
uni.showToast({
image: require('@/static/icons/crystal-icon.png'),
title: '+' + this.crystalArr[index].amount,
duration: 2000
})
this.$set(this.account, 'crystal', res.crystal)
this.ids = res.all_ids
if (JSON.stringify(res.last) === '[]') {
this.$set(this.crystalArr, index, {
amount: null
})
return
}
this.$set(this.crystalArr, index, res.last)
}).catch(err => {
uni.showToast({
icon: 'none',
title: err
})
})
},
// occ信息
getIndex() {
Promise.all([crystals(), chain()]).then(res => {
let crystalsData = res[0],
occData = res[1]
if (!crystalsData.needLogin) {
this.account = {
coin: crystalsData.coin,
crystal: crystalsData.crystal
}
this.userAuth = {
certification: crystalsData.is_certification,
company: crystalsData.is_company,
vip: crystalsData.is_vip,
identity: crystalsData.identity
}
this.crystalArr = crystalsData.crystal_array
this.allIds = crystalsData.all_ids
}
this.chains = occData.data
this.categoryArr = occData.tasks
this.help = occData.help
this.showCartc(occData.movement)
}).catch(err => {
uni.showToast({
title: err.message,
icon: 'none'
})
})
},
// 绘制图表
showCartc(data) {
// 图表信息
this.$refs.chartChange.init(config => {
config.appendPadding = [10, 30, 10, 15]
const chart = new F2.Chart(config);
chart.source(data, {
date: {
range: [0, 1],
type: 'timeCat',
mask: 'MM-DD'
},
value: {
tickCount: 0
}
});
chart.legend({
position: 'bottom',
offsetY: 0,
offsetX: 30
});
chart.area()
.position('date*value')
.color('name', ['#5881d3', '#ca66e0'])
.shape('smooth')
chart.line()
.position('date*value')
.color('name', ['#5881d3', '#ca66e0'])
.shape('smooth', name => {
if (name === '预期收益率') {
return 'line';
}
if (name === '实际收益率') {
return 'line';
}
});
chart.render();
return chart;
})
},
// 能量跳转
JumpUrl(open, title) {
var type = open.openType;
switch (type) {
case 'switchTab':
this.$Router.pushTab({
name: open.path
})
break;
case 'web':
window.location.href = open.path
break;
case 'navigateTo':
this.$Router.push({
name: open.path
})
break;
}
}
}
}
</script>
<style scoped>
/* 星球旋转 */
.ball {
position: absolute;
height: 480rpx;
width: 480rpx;
top: 50%;
left: 50%;
margin-top: -240rpx;
margin-left: -240rpx;
border-radius: 50%;
-webkit-transform-style: preserve-3d;
background: url(/static/background/chain-back-02.png) repeat-x;
/* background-size: auto 100%; */
background-size: 1616rpx;
-webkit-animation: move-map 60s infinite linear;
-moz-animation: move-map 60s infinite linear;
-o-animation: move-map 60s infinite linear;
-ms-animation: move-map 60s infinite linear;
animation: move-map 60s infinite linear;
box-shadow: 0 0 50rpx 50rpx rgba(31, 25, 34, .2);
}
.shadow {
position: absolute;
top: 1%;
left: 5%;
width: 90%;
height: 90%;
border-radius: 50%;
filter: blur(5px);
z-index: 3;
background: radial-gradient(circle at 50% 0, rgba(255, 255, 255, .6), rgba(255, 255, 255, .0) 58%);
}
.ball:before,
.ball::after {
position: absolute;
top: 0;
left: 0;
content: "";
width: 100%;
height: 100%;
border-radius: 50%;
filter: blur(5px);
z-index: 2;
}
.ball:before {
background: radial-gradient(circle at 100% 50%, #5881d3, rgba(255, 255, 255, .0) 45%);
}
.ball::after {
background: radial-gradient(circle at 0 50%, #ca66e0, rgba(255, 255, 255, .0) 45%);
}
@-webkit-keyframes move-map {
0% {
background-position: -1616rpx 0;
}
100% {
background-position: 0 0;
}
}
@-ms-keyframes move-map {
0% {
background-position: -1616rpx 0;
}
100% {
background-position: 0 0;
}
}
@keyframes move-map {
0% {
background-position: -1616rpx 0;
}
100% {
background-position: 0 0;
}
}
/* 水晶漂浮动画 */
.oct-float {
animation: 4s octfloat infinite;
}
@keyframes octfloat {
0% {
margin-top: 0;
}
50% {
margin-top: 10rpx;
}
100% {
margin-top: 0;
}
}
</style>
<style lang="scss" scoped>
.content {
min-height: calc(100vh - 60px);
background: #1f1922;
overflow: hidden;
}
// 平台概况
.situation {
margin: 0 $margin;
background-image: linear-gradient(to bottom, $block-color, #1f1922);
border-radius: $radius;
padding: $padding $padding/2 $padding*2;
// 平台统计
.header {
display: flex;
flex-wrap: wrap;
padding-bottom: $padding;
.number {
color: white;
font-size: $title-size;
font-weight: bold;
line-height: 70rpx;
}
.title {
color: rgba($color: white, $alpha: .4);
font-size: $title-size-sm;
line-height: 40rpx;
}
.header-item {
width: 50%;
padding: $padding / 2;
padding-bottom: $padding;
box-sizing: border-box;
// &:first-child{
// width: 100%;
// .number{
// font-size: $title-size;
// }
// }
}
}
// 图表
.chart {
background: rgba($color: $block-color, $alpha: .8);
padding: $padding/2;
border-radius: $radius/2;
.title {
text-align: center;
line-height: 80rpx;
color: rgba($color: #FFFFFF, $alpha: .4);
font-size: $title-size-sm;
}
.chart-f2 {
height: 200px;
}
}
}
// 数据统计
.header-total {
position: fixed;
top: 0;
left: 0;
right: 0;
z-index: 99;
background: #1f1922;
.total {
position: relative;
margin: $margin/2 $margin;
background: #2b2449;
padding: 0;
display: flex;
border-radius: $radius;
.item {
width: 50%;
padding: 0 $padding;
text-align: center;
color: white;
font-size: $title-size-sm;
line-height: 76rpx;
image {
width: 38rpx;
height: 38rpx;
vertical-align: top;
margin-top: calc((76rpx - 38rpx) / 2);
margin-right: $margin / 2;
}
}
&::before {
position: absolute;
top: 0;
bottom: 0;
content: "";
width: 2rpx;
left: 50%;
background: linear-gradient(to bottom, transparent, rgba(255, 255, 255, .7), transparent);
}
}
}
// 求助icon
.help-icon {
margin-left: $margin/3;
opacity: .7;
}
// 矿石
.ore {
margin-top: 76rpx;
position: relative;
padding-top: 120%;
&>image {
width: 100%;
position: absolute;
top: 0;
left: 0;
}
.ore-lists {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
z-index: 1;
.oct-float-item {
position: absolute;
text-align: center;
.text {
color: white;
font-size: $title-size-sm - 4;
line-height: 40rpx;
text-shadow: 0 3rpx 3rpx rgba($color: #000000, $alpha: .2);
}
.oct-icon {
display: inline-block;
width: 58rpx;
height: 58rpx;
line-height: 58rpx;
background: radial-gradient(circle at 50% 50%, rgba(202, 102, 224, .0) 40%, #ca66e0);
border-radius: 50%;
box-shadow: 0 0 5rpx 5rpx rgba($color: #ca66e0, $alpha: .5);
.icon {
margin-top: 10rpx;
height: 38rpx;
width: 38rpx;
}
}
}
.ore-item-nav {
@extend .oct-float-item;
right: $margin;
top: 12%;
}
.ore-item {
@extend .oct-float-item;
}
.oct-login {
@extend .oct-float-item;
left: 42%;
top: 45%;
}
}
}
// 任务
.task-block {
white-space: nowrap;
margin-bottom: $margin;
.item {
background: $block-color;
display: inline-block;
margin-left: $margin;
width: 260rpx;
border-radius: $radius;
text-align: center;
padding: ($padding - 10) $padding/2;
&:first-child {
margin-left: $margin;
}
&:last-child {
margin-right: $margin;
}
.icon {
display: inline-block;
margin: ($margin/2) 0;
width: 98rpx;
height: 98rpx;
line-height: 98rpx;
background: #1f183d;
border-radius: 50%;
text-align: center;
image {
width: 56rpx;
height: 56rpx;
vertical-align: middle;
}
}
.text {
font-size: $title-size-sm;
color: rgba($color: white, $alpha: .4);
line-height: 40rpx;
}
.title {
font-size: $title-size-lg;
color: white;
font-weight: bold;
line-height: 50rpx;
}
.submit-title {
font-size: $title-size-sm - 4;
color: rgba($color: white, $alpha: .4);
line-height: 40rpx;
}
}
}
</style>