时间窗的简单使用

时间窗的简单使用

一.根据自己需求在页面加载前或点击按钮触发时

views例如:

class WorkingView(APIView):
    def put(self, request):
        cid = request.GET.get('cid')
        thetime = int(time.time())
        Coach.objects.filter(id=cid).update(working=F('working') + 1)
        return Response({'msg': '教练开始工作','time':thetime})

return我们的在这里拿到的时间传给前端

Vue中例如:

work(id){
            axios.put('http://127.0.0.1:8000/app01/work/?cid='+id).then(res=>{
                sessionStorage.setItem('time',res.data.time)
                alert(res.data.msg)
            })

        }

在对应接口下做一个保持状态

close_work(price){
            // this.time2 = new Date()
            // this.time3 = parseInt(this.time2-this.time1)
            // this.time3 = Math.ceil(this.time3/1000)
            // console.log(this.time3)
            // console.log(this.money)
axios.post('http://127.0.0.1:8000/app01/order/',{'uid':sessionStorage.getItem('uid'),
'cid':this.id,'money':price,
'time':sessionStorage.getItem('time')}).then(res=>{
                alert(res.data.msg)
            })
        }

在另一个进行结算或者结束计时时将时间返回给后端

Views中

class OrderView(APIView):
    def post(self, request):
        uid = request.data.get('uid')
        cid = request.data.get('cid')
        money = request.data.get('money')
        start_time = request.data.get('time')
        thetime = int(time.time())
        timelong = thetime-int(start_time)

在获取当前时间 注意一定要进行将数据类型转换
然后用第二次获取到的时间去减去第一次获取到的时间
拿到时长然后根据时长去进行所需的计算

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值