253 lines
6.3 KiB
Vue
253 lines
6.3 KiB
Vue
<template>
|
|
<div class="naber">
|
|
<div class="content">
|
|
<div class="logo">
|
|
<router-link to="/">
|
|
<a><img src="@/assets/img/task/logo.png" alt="" /></a>
|
|
</router-link>
|
|
</div>
|
|
<div class="header-right">
|
|
<div class="twitter">
|
|
<a href="https://twitter.com/CEBG_GAME" rel="noopener noreferrer">
|
|
<img src="@/assets/img/task/TW.png" alt=""
|
|
/></a>
|
|
</div>
|
|
<div class="discode">
|
|
<a
|
|
href="https://discord.com/invite/fNSn2NHUvf"
|
|
rel="noopener noreferrer"
|
|
><img src="@/assets/img/task/DC.png" alt=""
|
|
/></a>
|
|
</div>
|
|
<div v-if="!chain.logined" class="login-btn" @click="login">
|
|
Connect Wallet
|
|
</div>
|
|
<div v-else class="login-btn-active" @click="showMenu = !showMenu">
|
|
{{ formatAddress }}
|
|
<div class="menu" v-show="showMenu">
|
|
<div class="menu-item" @click="logout">Disconnect</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup>
|
|
import { ref, reactive, onMounted, computed, watchEffect } from "vue";
|
|
import { useChainStore } from "@/store/chain";
|
|
import { useAppStore } from "@/store/app";
|
|
import { useRouter, useRoute } from "vue-router";
|
|
import { UserStatus } from "@/api/User";
|
|
import ChainModel from "@/components/home/ChainModel.vue";
|
|
import { hasMetamask } from "@/utils/chain.util";
|
|
import { useCopyToClipboard } from "./../../hooks/useCopyToClipboard";
|
|
|
|
const AppModule = useAppStore();
|
|
const router = useRouter();
|
|
const route = useRoute();
|
|
const showMenu = ref(false);
|
|
const chain = useChainStore();
|
|
const app = useAppStore();
|
|
const { copied, error, reset, copyToClipboard } = useCopyToClipboard();
|
|
const emit = defineEmits(["login-success"]);
|
|
const formatAddress = computed(() => {
|
|
const accountId = AppModule.accountId;
|
|
if (!accountId) return "-";
|
|
if (accountId.length >= 10) {
|
|
return `${accountId.substring(0, 6)}......${accountId.slice(-4)}`;
|
|
}
|
|
return accountId;
|
|
});
|
|
const isMobile = () => {
|
|
const userAgent = navigator.userAgent;
|
|
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
|
|
userAgent
|
|
);
|
|
};
|
|
async function login(event) {
|
|
var next = window.location.href;
|
|
|
|
if (isMobile() && !hasMetamask()) {
|
|
///debugger
|
|
var url = `https://metamask.app.link/dapp/${next}`;
|
|
location.href = url;
|
|
console.log("-============", hasMetamask(), next);
|
|
//document.getElementById("href").setAttribute("href", url);
|
|
} else {
|
|
if (!chain.logined) {
|
|
//没有登录情况下执行登录
|
|
|
|
await chain.chainManager.login();
|
|
// console.log("logined:", chain.chainManager.isLogined);
|
|
chain.logined = chain.chainManager.isLogined;
|
|
const resq = await UserStatus({
|
|
account: AppModule.accountId,
|
|
invite_code: route.query.code,
|
|
});
|
|
if (chain.logined) {
|
|
emit("login-success");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
const logout = async () => {
|
|
await chain.chainManager.logout();
|
|
window.location.reload();
|
|
// console.log("logined:", chain.chainManager.isLogined);
|
|
chain.logined = chain.chainManager.isLogined;
|
|
window.location.reload();
|
|
};
|
|
|
|
const handleCopy = () => {
|
|
const accountId = AppModule.accountId;
|
|
reset();
|
|
copyToClipboard(accountId).then(() => {
|
|
// if (copied.value) {
|
|
// message.success("Copy successful!");
|
|
// }
|
|
});
|
|
};
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
|
.naber {
|
|
// position: fixed;
|
|
// z-index: 20;
|
|
// top: 0;
|
|
// left: 0;
|
|
// background-color: rgb(15, 15, 15);
|
|
width: 100%;
|
|
height: 75px;
|
|
padding-top: 26px;
|
|
display: flex;
|
|
padding-left: 40px;
|
|
padding-right: 40px;
|
|
justify-content: center;
|
|
align-items: center;
|
|
.logo {
|
|
width: 166px;
|
|
height: 80px;
|
|
img {
|
|
width: 100%;
|
|
height: 100%;
|
|
}
|
|
}
|
|
.content {
|
|
width: 100%;
|
|
display: flex;
|
|
justify-content: space-between;
|
|
}
|
|
.login-btn {
|
|
width: 211px;
|
|
height: 61px;
|
|
color: #fff;
|
|
font-size: 22px;
|
|
cursor: pointer;
|
|
text-align: center;
|
|
line-height: 61px;
|
|
font-family: "Arial";
|
|
//border: 1px solid #ffffff;
|
|
background: url("@/assets/img/task/login-btn.png") no-repeat;
|
|
background-size: 100% 100%;
|
|
}
|
|
.login-btn:hover {
|
|
background: url("@/assets/img/task/login-btn-active.png") no-repeat;
|
|
background-size: 100% 100%;
|
|
color: #000000;
|
|
}
|
|
.login-btn-active {
|
|
width: 211px;
|
|
height: 61px;
|
|
cursor: pointer;
|
|
font-family: "Arial";
|
|
font-size: 22px;
|
|
color: #fff;
|
|
text-align: center;
|
|
line-height: 61px;
|
|
// border: 1px solid #ffffff;
|
|
background: url("@/assets/img/task/login-btn.png") no-repeat;
|
|
background-size: 100% 100%;
|
|
position: relative;
|
|
.menu {
|
|
position: absolute;
|
|
top: 100%;
|
|
right: 0; //update this line to right: 0;
|
|
width: 100%;
|
|
z-index: 1;
|
|
// padding: 10px 0;
|
|
// background-color: #bdb8b8;
|
|
border-radius: 5px;
|
|
box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
|
|
list-style: none;
|
|
transition: all 0.3s ease-out;
|
|
}
|
|
li {
|
|
margin: 5px 0;
|
|
}
|
|
.menu-item-top {
|
|
padding: 10px 15px;
|
|
color: #f5f5f5;
|
|
display: flex;
|
|
align-items: center;
|
|
position: relative;
|
|
padding-bottom: 15px;
|
|
.title {
|
|
margin-right: 20px;
|
|
}
|
|
}
|
|
.menu-item-top:before {
|
|
position: absolute;
|
|
top: 100%;
|
|
left: 15px;
|
|
content: "";
|
|
width: 140px;
|
|
height: 1px;
|
|
background: #676767;
|
|
}
|
|
.menu-item {
|
|
// padding: 5px 15px;
|
|
color: #f5f5f5;
|
|
display: flex;
|
|
font-family: "Arial";
|
|
//border: 1px solid #ccc;
|
|
background-color: #161515;
|
|
justify-content: center;
|
|
text-align: center;
|
|
// padding-top: 10px;
|
|
align-items: center;
|
|
.title {
|
|
margin-right: 10px;
|
|
}
|
|
}
|
|
}
|
|
.login-btn-active:hover {
|
|
background: url("@/assets/img/task/login-btn-active.png") no-repeat;
|
|
background-size: 100% 100%;
|
|
color: #000000;
|
|
}
|
|
.header-right {
|
|
// width: 228px;
|
|
|
|
display: flex;
|
|
align-items: center;
|
|
.discode {
|
|
width: 38px;
|
|
height: 29px;
|
|
img {
|
|
width: 100%;
|
|
height: 100%;
|
|
}
|
|
margin-left: 40px;
|
|
margin-right: 40px;
|
|
// padding-left: 40px;
|
|
// padding-right: 40px;
|
|
}
|
|
.twitter {
|
|
width: 33px;
|
|
height: 27px;
|
|
}
|
|
}
|
|
}
|
|
</style>
|