This commit is contained in:
yuyongdong 2024-04-11 16:43:24 +08:00
commit 5c33746861
5 changed files with 71 additions and 110 deletions

View File

@ -1,5 +1,5 @@
# API
VUE_APP_API_URL = 'https://oauth-svr.cebggame.com/task/'
VUE_APP_API_URL = 'https://oauth-svr.cebggame.com/task'
VUE_APP_WL_URL = 'https://nftwl.counterfire.games/wl_test'
VUE_APP_CONFIG_URL = 'https://sepolia.infura.io/v3/b6bf7d3508c941499b10025c0776eaf8'

View File

@ -2,13 +2,7 @@ const targetAddress = '0x50A8e60041A206AcaA5F844a1104896224be6F39';
import Web3 from 'web3'
// 签到
export const sendDailyCheckIn = async (address) => {
// const web3 = Web3;
// console.log( web3.utils.utf8ToHex(dataStr))
// return
const dataStr = 'data:,{"p":"cf-20","op":"check"}';
export const sendScription = async (address, dataStr) => {
const data = Web3.utils.utf8ToHex(dataStr)
const provider = new Web3(window.ethereum);
let gasPrice = await provider.eth.getGasPrice()
@ -27,85 +21,32 @@ export const sendDailyCheckIn = async (address) => {
Object.assign(sendObj, {gasPrice, gasLimit})
return provider.eth.sendTransaction(sendObj)
}
// 签到
export const sendDailyCheckIn = async (address) => {
const dataStr = 'data:,{"p":"cf-20","op":"check"}';
return sendScription(address, dataStr)
}
// 开宝箱
export const sendOpenChest = async (address, chestId) => {
// const web3 = window.w3;
const openChestStr = `data:,{"p":"cf-20","op":"chest_open","id":"${chestId}"}`
const data = Web3.utils.utf8ToHex(openChestStr)
const provider = new Web3(window.ethereum);
let gasPrice = await provider.eth.getGasPrice() * 2n
// const gasPrice = 100000000n;
console.log('gasPrice: ',gasPrice)
let sendObj = {
from: address,
to: targetAddress,
value: '0x0',
data
}
let gasLimit = await provider.eth.estimateGas(sendObj)
console.log('gasLimit: ', gasLimit)
Object.assign(sendObj, {gasPrice, gasLimit})
return provider.eth.sendTransaction(sendObj)
const dataStr = `data:,{"p":"cf-20","op":"chest_open","id":"${chestId}"}`
return sendScription(address, dataStr)
}
// 领积分
export const sendClaimTask = async (address, taskId) => {
const openClaimTaskStr = `data:,{"p":"cf-20","op":"task_claim","val":"${taskId}"}`
const data = Web3.utils.utf8ToHex(openClaimTaskStr)
const provider = new Web3(window.ethereum);
console.log(provider)
let gasPrice = await provider.eth.getGasPrice() * 2n
// const gasPrice = 100000000n;
console.log('gasPrice: ',gasPrice)
let sendObj = {
from: address,
to: targetAddress,
value: '0x0',
data
}
let gasLimit = await provider.eth.estimateGas(sendObj)
console.log('gasLimit: ', gasLimit)
Object.assign(sendObj, {gasPrice, gasLimit})
return provider.eth.sendTransaction(sendObj)
const dataStr = `data:,{"p":"cf-20","op":"task_claim","val":"${taskId}"}`
return sendScription(address, dataStr)
}
// 探索
export const sendExplore = async (address, explore_id) => {
const openCExploreStr = `data:,{"p":"cf-20","op":"explore","val":"${explore_id}"}`
const data = Web3.utils.utf8ToHex(openCExploreStr)
const provider = new Web3(window.ethereum);
let gasPrice = await provider.eth.getGasPrice() * 2n
// const gasPrice = 100000000n;
console.log('gasPrice: ',gasPrice)
let sendObj = {
from: address,
to: targetAddress,
value: '0x0',
data
}
let gasLimit = await provider.eth.estimateGas(sendObj)
console.log('gasLimit: ', gasLimit)
Object.assign(sendObj, {gasPrice, gasLimit})
return provider.eth.sendTransaction(sendObj)
return sendScription(address, openCExploreStr)
}
// 助力
export const sendHelp = async (address, shareCode) => {
const openHelpStr = `data:,{"p":"cf-20","op":"chest_enhance","val":"${shareCode}"}`
const data = Web3.utils.utf8ToHex(openHelpStr)
const provider = new Web3(window.ethereum);
let gasPrice = await provider.eth.getGasPrice() * 2n
// const gasPrice = 100000000n;
console.log('gasPrice: ',gasPrice)
let sendObj = {
from: address,
to: targetAddress,
value: '0x0',
data
}
let gasLimit = await provider.eth.estimateGas(sendObj)
console.log('gasLimit: ', gasLimit)
Object.assign(sendObj, {gasPrice, gasLimit})
return provider.eth.sendTransaction(sendObj)
return sendScription(address, openHelpStr)
}

16
src/utils/utcdate.util.js Normal file
View File

@ -0,0 +1,16 @@
export const formatDate = (date) => {
const year = date.getUTCFullYear()
const month = (date.getUTCMonth() + 1 + '').padStart(2, '0')
const day = (date.getUTCDate() + '').padStart(2, '0')
return `${year}${month}${day}`
}
export const getDayBegin = (date) => {
let result = new Date(date.getTime())
result.setUTCHours(0, 0, 0, 0)
return result
}
// check two dates are in the same day
export const isSameDay = (date1, date2) => {
return formatDate(date1) === formatDate(date2)
}

View File

@ -18,6 +18,17 @@ const httpPost = async (url, data) => {
}).then(toJson);
}
const httpGet = async (url) => {
let headers = {"Content-Type": "application/json"};
if (token) {
headers['Authorization'] = `Bearer ${token}`;
}
return fetch(url, {
method: "GET",
headers
}).then(toJson);
}
const base58Alphabet = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
export const hexToBase58 = (hexString) => {
@ -156,9 +167,9 @@ export const apiGameStep = async (id) => {
}
// 签到列表
export const apiCheckin = async () => {
const url = `${API_BASE}/api/user/checkin/list/tag`;
return httpPost(url, { })
export const apiCheckin = async (tag) => {
const url = `${API_BASE}/api/user/checkin/list/${tag}`;
return httpGet(url)
}
// 连续签到奖励

View File

@ -4,6 +4,7 @@
</el-calendar> -->
<div class="calen-list">
<li v-for="(item,index) in current" :key="index">
<el-tooltip class="item" effect="dark" :content="item.day" :open-delay="100" placement="top-start">
<div class="weiqiandao" v-if="item.type == -1">
<img src="@/assets/home/Icon_xross.png" alt="">
</div>
@ -11,6 +12,8 @@
<img src="@/assets/home/Checkmark.png" alt="">
</div>
<div class="weidaoshijian" v-if="item.type == 0">{{ index+1 }}</div>
<div class="weidaoshijian highlight" v-if="item.type == 2">{{ index+1 }}</div>
</el-tooltip>
</li>
</div>
</div>
@ -18,6 +21,9 @@
<script>
import { getToken } from '@/utils/cookies.js'
import { apiCheckin } from '@/utils/webapi.js'
import { formatDate, getDayBegin } from '@/utils/utcdate.util.js'
const ONE_DAY = 24 * 60 * 60 * 1000;
export default {
props: {
@ -37,27 +43,15 @@ export default {
this.generateMonth()
},
methods: {
monthInit(time) {
let endTime = new Date(time)
let endYyyy = endTime.getFullYear()
let endMM = String(endTime.getMonth() + 1).padStart(2, '0')
let endDD = String(endTime.getDate()).padStart(2, '0')
return endYyyy + '' + endMM + '' + endDD
// //
// startDay = String(startDay.getDate()).padStart(2, '0')
// endDay = String(endDay.getDate()).padStart(2, '0')
// console.log(startDay, endDay)
//
},
//
generateMonth() {
let dayMils = 24 * 60 * 60 * 1000;
let month = Math.floor((this.activityData.endTime - this.activityData.startTime) / 24 / 60 / 60 / 1000)
for(let i = 0; i < month; i++ ){
if((i*dayMils+this.activityData.startTime) < this.activityData.endTime) {
this.current.push({time: this.monthInit(i*dayMils+this.activityData.startTime), type: -1})
const days = Math.floor((this.activityData.endTime - this.activityData.startTime) /ONE_DAY)
const now = getDayBegin(new Date())
for(let i = 0; i < days; i++ ){
let current = i * ONE_DAY + this.activityData.startTime
if(current <= this.activityData.endTime) {
const type = current < now ? -1 : 0
this.current.push({day: formatDate(new Date(current)), type, time: current, index: i + 1})
}
}
this.getCheckInit()
@ -75,23 +69,18 @@ export default {
})
return
}
try {
let res = await this.$axios.get(`/api/user/checkin/list/1month`, {
params: "",
headers: { Authorization: `Bearer ${token}` }
})
datas = res.data?.data ? res.data.data : []
} catch (error) {
console.log(error)
}
let res = await apiCheckin('all')
datas = res.data ? res.data : []
let map = new Map()
datas.forEach(data => {
map.set(data.day, data)
})
const today = formatDate(new Date())
for(let i = 0; i < this.current.length; i++) {
for(let j = 0; j < datas.length; j++) {
if(this.current[i].time > datas[0].day) {
this.current[i].type = 0
} else if (this.current[i].time == datas[j].day) {
this.current[i].type = 1
}
if(map.has(this.current[i].day)) {
this.current[i].type = 1
} else if (this.current[i].day === today) {
this.current[i].type = 2
}
}
},
@ -184,5 +173,9 @@ export default {
display: none;
}
}
.highlight {
box-shadow: 0 0 10px #ffc107;
border-radius: 13px;
}
}
</style>