wangzhibo
4 天以前 ae6f40460dcd56af6c5f60ba52c883854c3bac55
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="utf-8"/>
  <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1"/>
  <title>打卡</title>
  <link rel="stylesheet" href="css.css"/>
</head>
<body>
<div class="wrap">
  <div class="page-head">
    <h1>扫码打卡</h1>
    <a class="back-link" href="home.html">返回工作台</a>
  </div>
  <div class="card">
    <div id="msg" class="muted">点击开始后持续扫码,扫到回收码即打卡。扫码页可点「停止 / 返回」结束。</div>
    <div id="result"></div>
    <button class="btn" id="btn" onclick="toggle()">开始扫码</button>
  </div>
</div>
<script src="app.js"></script>
<script>
var running = false, timer = null;
function toggle() {
  running = !running;
  $("btn").textContent = running ? "停止扫码" : "开始扫码";
  if (running) loop();
  else if (timer) { clearTimeout(timer); timer = null; }
}
function loop() {
  if (!running) return;
  scan().then(function (code) {
    if (!running) return;
    if (!code) { running = false; $("btn").textContent = "开始扫码"; return; }
    return api("/app/shop/sorter/checkUser", { unionid: code }).then(function (user) {
      return api("/app/shop/sorter/checkIn", { unionid: user.unionid }).then(function (r) {
        $("result").innerHTML = "<div class='ok'>打卡成功 · " + (user.nickName || "") + " +" + r.score + "分</div>";
        toast("打卡成功");
        timer = setTimeout(function () { $("result").innerHTML = ""; loop(); }, 3000);
      });
    });
  }).catch(function (e) {
    $("result").innerHTML = "<div class='err'>" + (e.message || "打卡失败") + "</div>";
    toast(e.message || "打卡失败");
    timer = setTimeout(function () { if (running) loop(); }, 1800);
  });
}
</script>
</body>
</html>