合约调用

This commit is contained in:
yuyongdong 2024-06-24 13:26:47 +08:00
parent a474382f31
commit 9fa16f02fb
16 changed files with 453 additions and 65 deletions

1
components.d.ts vendored
View File

@ -55,6 +55,7 @@ declare module 'vue' {
Roadmap: typeof import('./src/components/about/Roadmap.vue')['default']
RouterLink: typeof import('vue-router')['RouterLink']
RouterView: typeof import('vue-router')['RouterView']
SellDialog: typeof import('./src/components/Dialogs/sellDialog.vue')['default']
Sort: typeof import('./src/components/common/searchView/Sort.vue')['default']
StarTimer: typeof import('./src/components/common/starTimer.vue')['default']
Status: typeof import('./src/components/common/searchView/status.vue')['default']

View File

@ -89,10 +89,13 @@ const handleCancel = (e) => {
}
</script>
<style lang="scss">
<style lang="scss" scoped>
// .ant-modal-wrap{
.buyDia {
:deep(.ant-modal-wrap) {
width: 200px;
background: #B966FF;
}
.ant-modal {
width: 1140px !important;
color: #fff;
.ant-modal-content {

View File

@ -0,0 +1,253 @@
<template>
<a-modal :class="'buyDia'" v-model:open="props.sellDialogVisible" :closable="false" :footer="null" :maskClosable="false" @ok="handleOk">
<!-- <template #footer>
<a-button key="back" @click="handleCancel">Return</a-button>
<a-button key="submit" type="primary" :loading="loading" @click="handleOk">Submit</a-button>
</template> -->
<div class="top-close" @click="handleCancel">
<img src="@/assets/img/marketplace/Close counter.png" alt="">
</div>
<div class="content">
<div class="content-title">On the shelves NFT</div>
<div class="content-table">
<div>NFT</div>
<div>On the shelves Price</div>
<div>Royalties</div>
<div>Period</div>
<div>Expected profits</div>
</div>
<div class="content-nfts">
<li>
<div class="nft">
<div class="nft-img">
<img :src="sellDataArr.image" alt="tupian">
</div>
</div>
<div class="id">2516</div>
<div>2%</div>
<div>Expected profits</div>
<div class="price">
<!-- <div>{{ priceCalculated(sellDataArr[0].event.data.buy[0].amount) }}</div> -->
<div>0.08</div>
<div class="price-img"><img src="@/assets/img/marketplace/ETHicon.png" alt=""></div>
</div>
</li>
</div>
</div>
<div class="btm">
<div class="btm-left">
<li>Total&nbsp;:&nbsp;</li>
<li>
<div>
<!-- <span>{{ priceCalculated(sellDataArr[0].event.data.buy[0].amount) }}</span> -->
<span>0.08</span>
<img src="@/assets/img/marketplace/ETHicon.png" alt="">
</div>
<div class="money">$ 400</div>
</li>
</div>
<div class="btm-right" @click="sellConfirm">Confirm</div>
</div>
</a-modal>
</template>
<script setup>
import { ref, toRaw, defineEmits } from "vue";
import {priceCalculated} from "@/configs/priceCalculate.js"
import {PassportWallet} from "@/wallet/passPort.js"
// const passProd = ref(new PassportWallet())
const props = defineProps({
sellDialogVisible: {
type: Boolean,
required: true,
},
sellDataArr: {
type: Object,
required: true,
},
});
const emit = defineEmits(['handleClose'])
const handleOk = (e) => {
emit('handleClose')
};
const buyConfirm = async () => {
const pass = new PassportWallet()
let ids = []
ids.push(toRaw(props.sellDataArr)[0].nft.token_id)
// console.log(ids)
// return
let res = await pass.beginBuy(toRaw(props.sellDataArr)[0].nft.token_id)
console.log('购买', res)
}
// const priceAmount = () => {
// return priceCalculated(price)
// }
const handleCancel = (e) => {
emit('handleClose')
}
</script>
<style lang="scss" scoped>
// .ant-modal-wrap{
.buyDia {
width: 1362px !important;
color: #fff;
.ant-modal-content {
padding: 0px;
background: #1a1821;
border: 1px solid #B966FF;
box-shadow: 0px 15px 28px 3px rgba(22,22,22,0.13);
border-radius: 100px;
.top-close {
position: absolute;
top: -53px;
right: -53px;
width: 106px;
height: 106px;
cursor: pointer;
img {
width: 100%;
height: 100%;
}
}
.ant-modal-body {
padding: 30px 50px;
padding-bottom: 10px;
.content {
.content-title {
font-family: 'Anton';
font-weight: 400;
font-size: 48px;
margin-left: 50px;
}
.content-table {
width: 1017px;
height: 48px;
line-height: 48px;
margin: 0 auto;
background: #2d2738;
border-radius: 20px;
display: flex;
justify-content: space-between;
align-items: center;
color: #A8A5AC;
font-size: 14px;
div {
width: 240px;
text-align: center;
&:nth-child(1) {
width: 540px;
text-align: left;
padding-left: 100px;
box-sizing: border-box;
}
}
}
.content-nfts {
width: 1017px;
margin: 0 auto;
li {
display: flex;
justify-content: space-between;
align-items: center;
margin: 20px 0;
>div {
width: 240px;
font-family: 'Poppins';
font-weight: 500;
font-size: 30px;
text-align: center;
}
.nft {
display: flex;
align-items: center;
width: 540px;
.nft-img {
width: 110px;
height: 164px;
border: 1px solid #fff;
margin-left: 50px;
}
}
.id {
}
.price {
display: flex;
justify-content: center;
align-items: center;
.price-img {
width: 28px;
height: 28px;
margin-left: 10px;
img {
width: 100%;
height: 100%;
}
}
}
}
}
}
.btm {
display: flex;
justify-content: space-between;
align-items: center;
margin-left: 60px;
padding-top: 20px;
border-top: 2px solid #3A3B57;
box-sizing: border-box;
.btm-left {
display: flex;
margin-left: 20px;
li {
font-family: 'Anton';
font-weight: 400;
font-size: 42px;
color: #BB7FFF;
div {
display: flex;
align-items: center;
img {
width: 39px;
height: 39px;
margin-left: 20px;
}
}
.money {
font-family: 'Poppins';
font-weight: 400;
font-size: 24px;
}
}
}
.btm-right {
width: 240px;
height: 40px;
display: flex;
align-items: center;
justify-content: center;
line-height: 40px;
margin-right: 20px;
background: #fec25d;
color: #2D2738;
font-family: 'Poppins';
font-weight: 500;
font-size: 14px;
text-align: center;
border-radius: 20px;
box-shadow: 0 0 5px 0px #fec25d;
cursor: pointer;
}
}
}
}
}
// }
</style>

View File

@ -1,6 +1,7 @@
<template>
<div class="cards">
<div class="card-top" v-if="nftData" @click="toDetail">
<div class="card-top" v-if="nftData">
<!-- @click="toDetail" -->
<div class="card-img">
<img :src="nftData.image" alt="图片">
</div>
@ -11,7 +12,7 @@
<div class="card-price">
<div>
<span>
0.085
0.085 {{ nftData.item_id }}
</span>
<img src="@/assets/img/marketplace/ETHicon.png" alt="图片">
</div>
@ -24,13 +25,13 @@
<img src="@/assets/img/marketplace/Add shopping cart02.png" alt="">
</div>
</div>
<!-- <BuyDialog :buyDialogVisible="buyDialogVisible" :buyDataArr="buyDataArr" @handleClose="buyHandleClose" /> -->
<SellDialog :sellDialogVisible="sellDialogVisible" :sellDataArr="sellDataArr" @handleClose="sellHandleClose" />
</div>
</template>
<script setup>
import { ref, toRaw, onMounted, getCurrentInstance } from "vue"
// import BuyDialog from "@/components/Dialogs/buyDialog.vue"
import SellDialog from "@/components/Dialogs/sellDialog.vue"
import {PassportWallet} from "@/wallet/passPort.js"
import { useDetailStore } from "@/store/detail"
import {
@ -47,11 +48,15 @@ const props = defineProps({
},
});
const buyDialogVisible = ref(false)
const buyDataArr = ref([])
const sellDialogVisible = ref(false)
const sellDataArr = ref([])
// NFT
const sellNft = async (val) => {
console.log(val)
sellDialogVisible.value = true
sellDataArr.value = val
return
const data = {
// import.meta.env.VUE_APP_PASSPORT_MARKET_ADDRESS
contractAddress: val.contract_address,
@ -59,7 +64,7 @@ const sellNft = async (val) => {
currencyAddress: val.owner_address,
currencyAmount: '1000000000000000000'
}
// buyDataArr.value.push(val)
// sellDataArr.value.push(val)
// buyDialogVisible.value = true
const pass = new PassportWallet()
let res = await pass.beginSellERC721(data)
@ -78,7 +83,7 @@ const toDetail = () => {
//
const addCart = async (val) => {
console.log('-',val.nft)
console.log('-',val)
const data = {
net_id: import.meta.env.VUE_APP_NET_ID,
tokens: [
@ -100,9 +105,9 @@ const addCart = async (val) => {
}
//
const buyHandleClose = () => {
buyDialogVisible.value = false
buyDataArr.value = []
const sellHandleClose = () => {
sellDialogVisible.value = false
sellDataArr.value = []
}
onMounted(() => {

View File

@ -81,6 +81,7 @@ const getHistoryList = async () => {
search_name: ''
}
let res = await apiHangingState(myAddress, data)
console.log('getHistoryList', res)
}
onMounted(() => {

View File

@ -76,7 +76,12 @@ const clearAll = () => {
const getHistoryList = async () => {
const myAddress = localStorage.getItem('assessAddress')
let res = await apiHistoryState(myAddress)
const data = {
type: '0',
page_size: '20',
cursor: '',
}
let res = await apiHistoryState(myAddress,data)
}
onMounted(() => {

View File

@ -31,6 +31,7 @@
import { ref, defineEmits, onMounted } from "vue"
import { useRouter, useRoute } from "vue-router";
import { useImmutableStore } from "@/store/immutable"
import { useMarketplaceStore } from "@/store/marketplace"
import {
apiGetCartList,
apiClearCartList,
@ -61,15 +62,16 @@ const clearCart = async () => {
}
const getCartList = async () => {
let token = localStorage.getItem('assessToken')
if(token) {
try {
let res = await apiGetCartList()
console.log(res,'----')
} catch (e) {
console.log(e)
}
}
console.log(await useMarketplaceStore().getCartList(),'-------------------------------------------------------')
// let token = localStorage.getItem('assessToken')
// if(token) {
// try {
// let res = await apiGetCartList()
// console.log(res,'----')
// } catch (e) {
// console.log(e)
// }
// }
}
onMounted(()=> {

View File

@ -0,0 +1,124 @@
<template>
<div class="rank-check">
<h2>Heroic rank</h2>
<!-- <a-collapse :expand-icon-position="expandIconPosition">
<a-collapse-panel header="Hero"> -->
<a-checkbox v-for="item in heroList" :key="item.value" @change="onChangeValue(item.value)">
<span>{{ item.label }}</span>
<!-- <span>{{ heroList.length }}</span> -->
</a-checkbox>
<!-- </a-collapse-panel>
</a-collapse> -->
</div>
</template>
<script setup>
import { ref, reactive } from "vue";
import { SettingOutlined } from "@ant-design/icons-vue";
import { useMarketplaceStore } from "@/store/marketplace"
const marketplaceList = useMarketplaceStore()
const heroList = [
{ label: "Hill", value: "Hill" },
{ label: "Aoi", value: "Aoi" },
{ label: "Yamada", value: "Yamada" },
{ label: "Astral", value: "Astral" },
];
const checkArr = ref([])
const expandIconPosition = ref("end");
const handleClick = (event) => {
// If you don't want click extra trigger collapse, you can prevent this:
event.stopPropagation();
};
const onChangeValue = (e) => {
// ToDo:
console.log(JSON.parse(JSON.stringify(marketplaceList.rank)),'-0---')
if(JSON.parse(JSON.stringify(marketplaceList.rank)) == undefined || JSON.parse(JSON.stringify(marketplaceList.rank)).length <= 0) {
console.log(e)
JSON.parse(JSON.stringify(marketplaceList.rank)).push(e)
for(let i = 0; i < JSON.parse(JSON.stringify(marketplaceList.rank)).length; i++) {
console.log('进来')
if(JSON.parse(JSON.stringify(marketplaceList.rank))[i] == e) {
console.log('这里')
JSON.parse(JSON.stringify(marketplaceList.rank)).splice(i,1)
}
}
}
console.log(JSON.parse(JSON.stringify(marketplaceList.rank)),JSON.parse(JSON.stringify(checkArr.value)))
};
const noRepeat1 = function (arr) {
arr = [...new Set(arr)];
return arr
}
const setArr = ref([])
const noRepeat2 = (arr,e) => {
console.log(arr)
// arr = arr.filter(item => item != e)
for(var i = 0; i < arr.length; i++){
if(arr[i] != e) {
console.log(e,'不')
setArr.value.push(e)
} else {
console.log(arr[i],'等')
}
}
console.log(setArr.value,arr,'-------')
}
</script>
<style lang="scss" scoped>
.rank-check {
border-bottom: 2px solid #fff;
margin: 20px 0;
padding-bottom: 20px;
h2 {
font-family: 'Poppins';
font-weight: bold;
font-size: 20px;
color: #BB7FFF;
margin-bottom: 10px;
}
// :deep(.ant-collapse) {
// color: #fff;
// border: 0px;
// .ant-collapse-item {
// border: 0px;
// .ant-collapse-header {
// color: #BB7FFF;
// padding: 0;
// }
// .ant-collapse-content {
// background: none;
// border: none;
.ant-checkbox-wrapper {
display: flex !important;
color: #BB7FFF;
}
.ant-collapse-content-box {
padding: 20px 0;
.ant-checkbox-wrapper {
display: flex !important;
span {
color: #BB7FFF;
}
}
.ant-checkbox-group {
display: block;
.ant-checkbox-wrapper {
display: flex !important;
}
.ant-checkbox-group-item {
display: flex !important;
background: #fff;
span {
color: #BB7FFF !important;
}
}
}
// }
// }
// }
}
}
</style>

View File

@ -22,7 +22,7 @@ export const useCollectiblesStore = defineStore('collectibles', () => {
status, updateStatusStatus,
}
},
{
{
persist: true,
}
}
)

View File

@ -17,7 +17,7 @@ export const useDetailStore = defineStore('detail', () => {
nftData, updateDetailStatus,
}
},
{
{
persist: true,
}
}
)

View File

@ -22,7 +22,7 @@ export const useHangingStore = defineStore('hanging', () => {
status, updateStatusStatus,
}
},
{
{
persist: true,
}
}
)

View File

@ -16,7 +16,7 @@ export const useImmutableStore = defineStore('immutable', () => {
access, updateAccessStatus,
}
},
{
{
persist: true,
}
}
)

View File

@ -1,6 +1,6 @@
import { defineStore } from 'pinia';
import { ref } from 'vue';
// import { apiMarketplaceState } from "@/utils/marketplace"
import { apiGetCartList } from "@/utils/marketplace"
export const useMarketplaceStore = defineStore('marketplace', () => {
const overview = ref('')
@ -47,8 +47,11 @@ export const useMarketplaceStore = defineStore('marketplace', () => {
// return '可以'
// }
// }
const getCartList = async () => {
cartList.value = '可以'
async function getCartList() {
// cartList.value = '可以'
let res = await apiGetCartList()
console.log(res)
return res
}
return {

View File

@ -22,7 +22,7 @@ export const useTradingStore = defineStore('trading', () => {
status, updateStatusStatus,
}
},
{
{
persist: true,
}
}
)

View File

@ -43,25 +43,25 @@ export const apiMarketplaceState = async (data) => {
// 获取我拥有得资产
export const apiAssetsState = async (account_address, data) => {
const url = `/api/asset/${net_id}/${account_address}`
return httpGet(url, {data})
const url = `${API_BASE}/api/asset/${net_id}/${account_address}?type=${data.type}?ge_size=${data.page_size}?cursor=${data.cursor}?search_name=${data.search_name}`
return httpGet(url, {})
}
// 获取上架出售得NFTS
export const apiHangingState = async (account_address, data) => {
const url = `/api/asset/${net_id}/${account_address}`
const url = `${API_BASE}/api/asset/${net_id}/${account_address}`
return httpGet(url, {data})
}
// 账号交易历史
export const apiHistoryState = async (account_address) => {
const url = `/api/market/transaction/history/${net_id}/${account_address}`
export const apiHistoryState = async (account_address,data) => {
const url = `${API_BASE}/api/market/transaction/history/${net_id}/${account_address}?type=${data.type}?ge_size=${data.page_size}?cursor=${data.cursor}`
return httpGet(url, {})
}
// 详情
export const apiDetail = async (account_address) => {
const url = `/api/market/transaction/history/${net_id}/${account_address}`
const url = `${API_BASE}/api/market/transaction/history/${net_id}/${account_address}`
return httpGet(url, {})
}
@ -73,16 +73,16 @@ export const apiGetCartList = async () => {
// 添加购物车
export const apiAddCartList = async (data) => {
const url = `/api/shopcart/add`
const url = `${API_BASE}/api/shopcart/add`
return httpPost(url, {data})
}
// 删除购物车
export const apiDelCartList = async () => {
const url = `/api/shopcart/del`
const url = `${API_BASE}/api/shopcart/del`
}
// 清空购物车
export const apiClearCartList = async () => {
const url = `/api/shopcart/clear`
const url = `${API_BASE}/api/shopcart/clear`
}

View File

@ -141,7 +141,9 @@
import { ref, toRaw, onMounted } from "vue"
import StarTimer from "@/components/common/starTimer.vue"
import { apiDetail } from "@/utils/marketplace"
import {priceCalculated} from "@/configs/priceCalculate.js"
import { useDetailStore } from "@/store/detail"
const detailData = useDetailStore()
console.log(toRaw(detailData.nftData))
import { PassportWallet } from "@/wallet/passPort"
@ -198,29 +200,18 @@ const sliceAddress = (address) => {
//
const priceWei = (price) => {
let toPrice = parseInt(BigInt(price))/1e18
return priceFixed(toPrice)
}
const priceFixed = (num) => {
if(isNaN(num)){return num};
//
var str = ''+num;
if(!/e/i.test(str)){return num;};
//
var fixed = (''+num).match(/\d+$/)[0];
//
return new Number(num).toFixed(fixed);
return priceCalculated(price)
}
const getDetail = async () => {
let address = localStorage.getItem('address')
let address = localStorage.getItem('assessAddress')
let res = await apiDetail(address)
console.log('getDetail',toRaw(res))
nftData.value = res.rows
}
onMounted(() => {
// getDetail()
getDetail()
})
</script>