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 # 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_WL_URL = 'https://nftwl.counterfire.games/wl_test'
VUE_APP_CONFIG_URL = 'https://sepolia.infura.io/v3/b6bf7d3508c941499b10025c0776eaf8' VUE_APP_CONFIG_URL = 'https://sepolia.infura.io/v3/b6bf7d3508c941499b10025c0776eaf8'

View File

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

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); }).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'; const base58Alphabet = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
export const hexToBase58 = (hexString) => { export const hexToBase58 = (hexString) => {
@ -156,9 +167,9 @@ export const apiGameStep = async (id) => {
} }
// 签到列表 // 签到列表
export const apiCheckin = async () => { export const apiCheckin = async (tag) => {
const url = `${API_BASE}/api/user/checkin/list/tag`; const url = `${API_BASE}/api/user/checkin/list/${tag}`;
return httpPost(url, { }) return httpGet(url)
} }
// 连续签到奖励 // 连续签到奖励

View File

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