![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/b98deded3c6ba74aa7f1a66cb73136e6.png)
<template>
<div>
<div class="top">
<i @click="back" class="cubeic-back"></i>
<span>{{classname}} {{coursename}}</span>
<cube-button :primary='true' :outline='true' :inline='true' @click="qiandao">签到</cube-button>
</div>
<div class="data">
<div v-for="(item,index) in list" :key="item.kqid" class="item">
<div class="left">
<span style='margin-right:5px;'>{{item.ymd}}</span>
<span>{{item.weekday}}</span>
<div style="color:#999;margin-top:5px;">{{item.his}}</div>
</div>
<div class="right">
<span class="state">{{item.state}}</span>
</div>
</div>
</div>
</div>
</template>
<script>
import {
timestampToHis1,
timestampToWeekday1,
timestampToYmd1
} from '../../common.js'
export default{
data:function(){
return{
list:[],
classname:sessionStorage.getItem('classname'),
coursename:sessionStorage.getItem('coursename')
}
},
mounted(){
this.$request({
url: '/student.index/jilu',
method: 'post',
data: {
token: sessionStorage.getItem('token'),
ccid: sessionStorage.getItem('ccid')
}
}).then(res => {
res.forEach(row => {
row['ymd'] = timestampToYmd1(row['updatetime'])
row['his'] = timestampToHis1(row['updatetime'])
row['weekday'] = timestampToWeekday1(row['updatetime'])
})
this.list = res
console.log(this.list)
}).catch(res => {
})
},
methods:{
qiandao:function(){
this.$createDialog({
type: 'prompt',
title: '签到',
prompt: {
value: '',
placeholder: '请输入签到码'
},
onConfirm: (e, promptValue) => {
let data = {
token: sessionStorage.getItem('token'),
yzm: promptValue,
ccid:sessionStorage.getItem('ccid')
}
this.$request({
method: 'post',
url: '/student.qiandao/qiandao',
data: data
}).then(res => {
this.$createToast({
type: 'correct',
time: 2000,
txt: res.message,
}).show()
this.list.push(res)
})
},
}).show()
},
back:function(){
this.$router.back()
},
}
}
</script>
<style scoped>
.page {
font-size: 18px;
}
.top {
display: flex;
justify-content: space-between;
height: 50px;
padding: 10px 10px;
align-items: center;
background-color:
}
.data {
margin-top: 24px;
}
.state{
padding-right: 11px;
}
.item {
height: 52px;
display: flex;
justify-content: space-between;
}
.left {
padding-left: 10px;
}
</style>
<?php
namespace app\api\controller\student;
use think\Cache;
use think\Db;
use think\cache\driver\Redis;
class Qiandao extends Base
{
private $ccid;
public function _initialize()
{
parent::_initialize();
$ccid = input('post.ccid');
$this->ccid = $ccid;
}
public function index()
{
$number = $this->stu['number'];
$data = Db::name('kaoqin_details')
->alias('kd')
->join('__STATEBASE__ s', 's.id=kd.stateid')
->where('number', $number)
->where('ccid', $this->ccid)
->field('kd.number,kd.name,kd.stateid,kd.value,s.state,kd.updatetime')
->order('updatetime desc')
->select();
return success($data);
}
public function qiandao()
{
$yzm = input('post.yzm');
$redis = Cache::store('redis')->handler();
$ret = $redis->hget($this->ccid,'yzm');
if (empty($ret)) {
return error('未在签到时间内');
}
if ($yzm != $ret) {
return error('验证码不正确');
}
$number = $this->stu['number'];
if ($redis->hexists($this->ccid, $number)) {
return error('您已经签到,不要重复签到');
}
$time = time();
$redis->hset($this->ccid, $number, $time);
return success(['message' => '签到成功', 'time' => $time]);
}
}