PortIO/resources/js/views/Sign.vue

122 lines
3.2 KiB
Vue
Raw Normal View History

2023-05-14 15:31:50 +00:00
<template>
<div>
2023-05-16 11:25:37 +00:00
<h3>流量补给</h3>
2023-05-14 15:31:50 +00:00
<div>
<p>当前流量: {{ traffic.traffic }}GB</p>
<div v-if="traffic.is_signed">今日已签到</div>
<div v-else>
2023-07-30 11:15:45 +00:00
<p>完成验证码以签到</p>
<vue-recaptcha
2023-07-30 14:01:13 +00:00
:sitekey="key"
2023-07-30 15:52:39 +00:00
:theme="theme"
2023-07-30 11:15:45 +00:00
loadRecaptchaScript
recaptchaHost="www.recaptcha.net"
@verify="sign"
/>
2023-05-14 15:31:50 +00:00
</div>
</div>
2023-09-16 11:04:02 +00:00
<button
type="button"
class="btn btn-primary"
style="display: none"
id="signinButton"
data-bs-toggle="modal"
data-bs-target="#signinModal">
</button>
<div class="modal fade" id="signinModal" tabindex="-1" aria-labelledby="signinModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="signinModalLabel">签到</h1>
</div>
<div class="modal-body">
签到成功{{ content }}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-bs-dismiss="modal">确定</button>
</div>
</div>
</div>
</div>
2023-05-14 15:31:50 +00:00
</div>
</template>
<script setup>
2023-07-30 15:52:39 +00:00
import {ref} from "vue";
import {VueRecaptcha} from 'vue-recaptcha';
2023-05-14 15:31:50 +00:00
import http from "../plugins/http";
2023-07-30 14:01:13 +00:00
const key = window.Base.ReCaptcha
2023-09-16 11:04:02 +00:00
const content = ref("")
2023-07-30 14:01:13 +00:00
2023-05-14 15:31:50 +00:00
const traffic = ref({
last_sign_at: null,
traffic: 0,
});
2023-07-30 15:52:39 +00:00
const theme = ref("")
if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
theme.value = "dark"
} else {
theme.value = "light"
}
2023-05-14 15:31:50 +00:00
http.get("user")
.then((res) => {
traffic.value.traffic = res.data.traffic;
})
2023-07-30 11:15:45 +00:00
function sign(captcha_token) {
http.post("traffic", {
"recaptcha": captcha_token
})
2023-05-14 15:31:50 +00:00
.then((res) => {
traffic.value = res.data;
2023-09-16 11:04:02 +00:00
content.value = `获得了 ${res.data.traffic} GB 流量!`;
2023-05-14 15:31:50 +00:00
if (res.data.traffic === 0) {
2023-09-16 11:04:02 +00:00
content.value = "没有获得流量~";
2023-05-14 15:31:50 +00:00
}
2023-09-16 11:04:02 +00:00
document.querySelector("#signinButton").click()
// alert(content);
2023-05-14 15:31:50 +00:00
})
.finally(() => {
http.get("user")
.then((res) => {
traffic.value.traffic = res.data.traffic;
})
.finally(() => {
// refreshSign()
});
});
}
// function refreshSign() {
// const date = new Date(traffic.value.last_sign_at)
//
//
// if (traffic.value.last_sign_at) {
// date.setDate(date.getDate() + 1)
// // nextSignAt.value = date.toLocaleString()
// // 算出差多少小时
// const diff = date.getTime() - new Date().getTime()
// const hours = Math.floor(diff / 1000 / 60 / 60)
// const minutes = Math.floor(diff / 1000 / 60 % 60)
// nextSignAt.value = `${hours} 小时 ${minutes} 分钟`
//
// } else {
// nextSignAt.value = null
// }
// }
</script>