直播签到

This commit is contained in:
zhangyc
2022-12-25 18:30:25 +08:00
parent d48ebe59db
commit 765aa3d5a6
2 changed files with 61 additions and 8 deletions

View File

@@ -50,7 +50,9 @@
background: `${new Date(data.liveStartTime).getTime() > new Date().getTime() ? '#999' : 'rgb(59, 191, 252)'}`,
}" @click="showClick">观看
</botton>
<botton class="btn" :style="{
<botton v-if="!isAllowSign" class="btn" style="margin-right: 20px; background: #999" @click="signClick">签到
</botton>
<botton v-else class="btn" :style="{
background: `${new Date(data.liveStartTime).getTime() > new Date().getTime() ? '#999' : data.signFlag ? '#999' : 'rgb(57, 146, 249)'}`,
}" @click="signClick">{{ data.signFlag ? "已签到" : "签到" }}
</botton>

View File

@@ -45,13 +45,9 @@
<div style="margin-left: 8px">{{ data?.activityAddress }}</div>
</div>
</div>
<botton
class="btn"
:style="{
background: `${data.signFlag ? '#999' : 'rgb(57, 146, 249)'}`,
}"
@click="signClick"
>{{ data.signFlag ? "已签到" : "签到" }}
<botton v-if="!isAllowSign" class="btn" style="margin-right: 20px; background: #999" @click="signClick">签到
</botton>
<botton class="btn" :style="{background: `${data.signFlag ? '#999' : 'rgb(57, 146, 249)'}`, }" @click="signClick" >{{ data.signFlag ? "已签到" : "签到" }}
</botton>
</div>
<!-- 基本信息 -->
@@ -147,6 +143,7 @@ import { request, useRequest } from "@/api/request";
import { useRouter } from "vue-router";
import { useRoute } from "vue-router/dist/vue-router";
import { ElMessage } from "element-plus";
import { reactive, onUnmounted } from "vue";
const router = useRouter();
const returnclick = () => {
router.back();
@@ -154,7 +151,10 @@ const returnclick = () => {
const {
query: { courseId: activityId, id: taskId, type, pName, sName },
} = useRoute();
const state = reactive({
isAllowSign: false,
});
const { data } = useRequest(ACTIVITY, { activityId });
const signClick = (tab, event) => {
if (data.value.signFlag) {
@@ -168,6 +168,57 @@ const signClick = (tab, event) => {
type,
});
};
let timer = null;
//判断能否签到
function isSignClick() {
timer = setInterval(() => {
let beginTime = new Date(data.activityStartTime).getTime();
let endTime = !data.afterSignIn
? new Date(data.activityEndTime).getTime()
: new Date(data.activityStartTime).getTime();
let nowTime = new Date().getTime();
if (data.beforeSignIn && data.afterSignIn) {
//有开始前有开始后
beginTime = beginTime - data.beforeSignIn * 60 * 1000;
endTime = endTime + data.afterSignIn * 60 * 1000;
console.log("1111");
} else if (
data.beforeSignIn &&
!data.afterSignIn
) {
//只有开始前无开始后
beginTime = beginTime - data.beforeSignIn * 60 * 1000;
console.log("11112222");
} else if (
!data.beforeSignIn &&
data.afterSignIn
) {
//无开始前有开始后
endTime = endTime + data.afterSignIn * 60 * 1000;
console.log("1111333");
}
if (nowTime < endTime && nowTime > beginTime) {
state.isAllowSign = true;
} else {
state.isAllowSign = false;
}
// console.log(
// "isAllowSign",
// state.isAllowSign,
// nowTime,
// endTime,
// beginTime,
// nowTime < endTime,
// nowTime > beginTime
// );
}, 1000);
}
isSignClick();
onUnmounted(() => {
if (timer) {
clearInterval(timer);
}
});
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->