From 2c7d6bc3c4b5c1e32189bf57dfe434c6455e5e01 Mon Sep 17 00:00:00 2001 From: "cn.yimian.xyz" Date: Sun, 23 Aug 2020 16:16:39 +0800 Subject: [PATCH] f --- api/joinTable.php | 55 ++++++++++++++++++++++++++++++++------------ index.html | 46 +++++++++++++++++++++++++------------ records.html | 27 ++++++++++++++++------ setTable.html | 58 +++++++++++++++++++++++++++++++++++++++++------ 4 files changed, 143 insertions(+), 43 deletions(-) diff --git a/api/joinTable.php b/api/joinTable.php index a920b7c..0676a3e 100644 --- a/api/joinTable.php +++ b/api/joinTable.php @@ -1,24 +1,49 @@ $hash, - "table" => $tableId, - "state" => '1', - "created_at" => date("Y-m-d H:i:s", time()) -), array( - "user" => $hash, - "table" => $tableId -)); - -echo ''; \ No newline at end of file +$data = getFinalData($cnn, $tableId); + +if(!db__rowNum($cnn, "user", "user", $hash, "table", $tableId)){ + $itemId = hash('sha256', time().$hash.$tableId.rand(222,999)); + + db__pushData($cnn, "account", array( + "id" => $itemId, + "table" => $tableId, + "user" => $hash, + "type" => 'placeholde', + "state" => '0', + "value" => $data['average'], + "created_at" => date("Y-m-d H:i:s", time()) + )); + db__pushData($cnn, "user", array( + "user" => $hash, + "table" => $tableId, + "state" => '1', + "created_at" => date("Y-m-d H:i:s", time()) + )); +}else{ + db__pushData($cnn, "user", array( + "user" => $hash, + "table" => $tableId, + "state" => '1', + "created_at" => date("Y-m-d H:i:s", time()) + ), array( + "user" => $hash, + "table" => $tableId + )); + +} + +setcookie("tableId", $tableId, time()+3600*12*60*365, "/"); + + +echo ''; diff --git a/index.html b/index.html index a1230be..3d34a57 100644 --- a/index.html +++ b/index.html @@ -31,7 +31,7 @@ - + @@ -283,18 +283,17 @@ if(cookie.get('cache')){ function load(){ session.onload(function(){ $('#usr').html('Hi~ '+session.get('nickname')); - if(page.params.hasOwnProperty('type') && page.params.type == 'join'){ + if(!session.get('email')) return; + if(page.params.hasOwnProperty('tableId')){ window.location.href="./api/joinTable.php?hash="+session.get('hash')+'&tableId='+page.params.tableId; return; } - $.get('./api/getData.php?hash='+session.get('hash'), function(data){ - if(!data.length){ - alert('请先创建一个公共账户!'); - window.location.href="./setTable.html"; - return; - } + + function localLoad(data){ + if(!session.get('hash')) return; + if(!data.length) return; var buttons = []; @@ -401,13 +400,15 @@ function load(){ name: data.name, total: data.total, lastWeekTotal: Number(lastWeekTotal/(7*data.users.length)).toFixed(2), - userTotal: Number(data['actualTotals'][session.get('hash')]) + userTotal: Number(data['actualTotals'][session.get('hash')]), + threshold: data.threshold }; - cookie.set('cache', btoa(JSON.stringify(briefData))); - + try{ + cookie.set('cache', btoa(JSON.stringify(briefData))); + }catch(e){} var show = []; for(var i = data['items'].length - 1; i > data['items'].length-10 && i >= 0; i --){ - if(data['items'][i]['value'] > 0 && data['items'][i]['type'] != 'innerT') + if(data['items'][i]['value'] > 0 && (data['items'][i]['type'] == 'innerF' || data['items'][i]['type'] == 'external')) show.push(data['items'][i]); } var s = ''; @@ -460,7 +461,7 @@ function load(){ var userNotice = []; data['itemsByUser'][session.get('hash')].forEach((item)=>{ - if(!(item.state == '1')){ + if(!(item.state == '1') && item.type != 'placeholde'){ userNotice.push(item); } }); @@ -560,7 +561,7 @@ function load(){ var arr = []; data['items'].forEach((item)=>{ - if(item.type != 'external' && item.created_at == created_at){ + if((item.type == 'innerF' || item.type == 'innerT') && item.created_at == created_at){ arr.push(item.id); } }); @@ -682,9 +683,26 @@ console.log(daily_avg, daily_avg_week) ); + }; + if(window.localStorage[session.get('hash')]){ + try{ + data = JSON.parse(window.localStorage[session.get('hash')]); + localLoad(data); + }catch(e){ + } + } + + $.get('./api/getData.php?hash='+session.get('hash'), function(data){ + window.localStorage[session.get('hash')] = JSON.stringify(data); + if(!data.length){ + alert('请先创建一个公共账户!'); + window.location.href="./setTable.html"; + return; + } + localLoad(data); }); }); diff --git a/records.html b/records.html index 0240cad..b6a7a77 100644 --- a/records.html +++ b/records.html @@ -30,6 +30,7 @@ + @@ -138,13 +139,9 @@