diff --git a/db/comments.py b/db/comments.py new file mode 100644 index 0000000..1cfcf57 --- /dev/null +++ b/db/comments.py @@ -0,0 +1,76 @@ +import time +import db.util as util + + +# 查找评论 +def listByBookid(id: str): + "通过bookid查找所有评论" + conn = util.getConn() + c = conn.cursor() + cursor = c.execute("SELECT * FROM Comments WHERE bookid = ? ORDER BY time desc", (id,)) + out = [] + for row in cursor: + out.append(row) + conn.close() + return out + + +# 获取综合评分 +def getScore(bookid: str): + "获取综合评分 返回一个字典 字典有两个key like和dislike分别记录不同评论的个数" + conn = util.getConn() + c = conn.cursor() + cursor = c.execute("SELECT * FROM Comments WHERE bookid = ? ", (bookid,)) + num={'like':0,'dislike':0} + for row in cursor: + if row[4] == "like": + num["like"]+=1 + elif row[4] == "dislike": + num["dislike"]+=1 + conn.close() + return num + + +# 查找评论 +def searchByUid(uid: str): + "通过用户查找所有评论" + conn = util.getConn() + c = conn.cursor() + cursor = c.execute("SELECT * FROM Comments WHERE from_uid = ? ORDER BY time desc", (uid,)) + out = [] + for row in cursor: + out.append(row) + conn.close() + return out + + +# 查找评论 +def searchByAll(uid: str,bookid:str): + "通过用户和BookID查找所有评论" + conn = util.getConn() + c = conn.cursor() + cursor = c.execute("SELECT * FROM Comments WHERE from_uid = ? AND bookid= ? ORDER BY time desc", (uid,bookid)) + out = [] + for row in cursor: + out.append(row) + conn.close() + return out + + +# 在数据库中添加一个新的文件记录 +def new(bookid: str, from_uid: int, score: str, content=""): + "添加一条新评论 score字段可选值为[like,none,dislike] content字段非必填" + conn = util.getConn() + c = conn.cursor() + c.execute( + """ + INSERT INTO Comments + (time, bookid, from_uid, score, content) + VALUES + (?, ?, ?, ?,?); + """, + (int(time.time()), bookid, from_uid, score, content), + ) + conn.commit() + conn.close() + return diff --git a/db/user.py b/db/user.py index 7c14bae..5ede852 100644 --- a/db/user.py +++ b/db/user.py @@ -32,4 +32,24 @@ def check(username: str, password: int): cursor = c.execute("SELECT * FROM User WHERE username = ? AND password = ?", (username, password)) if cursor.fetchone() is None: return False - return True \ No newline at end of file + return True + +def getUid(username: str): + "判断用户名是否存在 并获取用户uid 用户不存在则返回None" + conn = util.getConn() + c = conn.cursor() + cursor = c.execute("SELECT * FROM User WHERE username = ?", (username,)) + out = cursor.fetchone() + if out is not None: + return out[0] + return None + +def getUsername(uid:str): + "判断Uid是否存在 并获取用户名 用户不存在则返回None" + conn = util.getConn() + c = conn.cursor() + cursor = c.execute("SELECT * FROM User WHERE uid = ?", (uid,)) + out = cursor.fetchone() + if out is not None: + return out[1] + return None \ No newline at end of file diff --git a/db/util.py b/db/util.py index faf4765..2d21c90 100644 --- a/db/util.py +++ b/db/util.py @@ -31,5 +31,29 @@ def init(): ); """ ) + c.execute( + """ + CREATE TABLE IF NOT EXISTS Comments ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + time INT NOT NULL, + bookid TEXT NOT NULL, + from_uid INTEGAR NOT NULL, + score INT NOT NULL, + content TEXT + ); + """ + ) + c.execute( + """ + INSERT INTO User (username, password) + SELECT ?, ? + WHERE NOT EXISTS (SELECT 1 FROM User WHERE username = ?); + """, + ( + conf.get("user", "username"), + conf.get("user", "password"), + conf.get("user", "username"), + ), + ) conn.commit() conn.close() diff --git a/main.py b/main.py index 2c6fed3..2490ead 100644 --- a/main.py +++ b/main.py @@ -6,6 +6,7 @@ from flask import * from web.api_Img import api_Img_bp from web.page import page_bp from web.admin_page import admin_page_bp +from web.api_comment import comment_api_bp app = Flask(__name__) @@ -20,6 +21,7 @@ def appinit(): app.register_blueprint(api_Img_bp) app.register_blueprint(page_bp) app.register_blueprint(admin_page_bp) +app.register_blueprint(comment_api_bp) if __name__ == "__main__": appinit() diff --git a/static/js/popper.min.js b/static/js/popper.min.js deleted file mode 100644 index 8a17212..0000000 --- a/static/js/popper.min.js +++ /dev/null @@ -1,5 +0,0 @@ -/* - Copyright (C) Federico Zivolo 2019 - Distributed under the MIT License (license terms are at http://opensource.org/licenses/MIT). - */(function(e,t){'object'==typeof exports&&'undefined'!=typeof module?module.exports=t():'function'==typeof define&&define.amd?define(t):e.Popper=t()})(this,function(){'use strict';function e(e){return e&&'[object Function]'==={}.toString.call(e)}function t(e,t){if(1!==e.nodeType)return[];var o=e.ownerDocument.defaultView,n=o.getComputedStyle(e,null);return t?n[t]:n}function o(e){return'HTML'===e.nodeName?e:e.parentNode||e.host}function n(e){if(!e)return document.body;switch(e.nodeName){case'HTML':case'BODY':return e.ownerDocument.body;case'#document':return e.body;}var i=t(e),r=i.overflow,p=i.overflowX,s=i.overflowY;return /(auto|scroll|overlay)/.test(r+s+p)?e:n(o(e))}function i(e){return e&&e.referenceNode?e.referenceNode:e}function r(e){return 11===e?re:10===e?pe:re||pe}function p(e){if(!e)return document.documentElement;for(var o=r(10)?document.body:null,n=e.offsetParent||null;n===o&&e.nextElementSibling;)n=(e=e.nextElementSibling).offsetParent;var i=n&&n.nodeName;return i&&'BODY'!==i&&'HTML'!==i?-1!==['TH','TD','TABLE'].indexOf(n.nodeName)&&'static'===t(n,'position')?p(n):n:e?e.ownerDocument.documentElement:document.documentElement}function s(e){var t=e.nodeName;return'BODY'!==t&&('HTML'===t||p(e.firstElementChild)===e)}function d(e){return null===e.parentNode?e:d(e.parentNode)}function a(e,t){if(!e||!e.nodeType||!t||!t.nodeType)return document.documentElement;var o=e.compareDocumentPosition(t)&Node.DOCUMENT_POSITION_FOLLOWING,n=o?e:t,i=o?t:e,r=document.createRange();r.setStart(n,0),r.setEnd(i,0);var l=r.commonAncestorContainer;if(e!==l&&t!==l||n.contains(i))return s(l)?l:p(l);var f=d(e);return f.host?a(f.host,t):a(e,d(t).host)}function l(e){var t=1=o.clientWidth&&n>=o.clientHeight}),l=0a[e]&&!t.escapeWithReference&&(n=Q(f[o],a[e]-('right'===e?f.width:f.height))),ae({},o,n)}};return l.forEach(function(e){var t=-1===['left','top'].indexOf(e)?'secondary':'primary';f=le({},f,m[t](e))}),e.offsets.popper=f,e},priority:['left','right','top','bottom'],padding:5,boundariesElement:'scrollParent'},keepTogether:{order:400,enabled:!0,fn:function(e){var t=e.offsets,o=t.popper,n=t.reference,i=e.placement.split('-')[0],r=Z,p=-1!==['top','bottom'].indexOf(i),s=p?'right':'bottom',d=p?'left':'top',a=p?'width':'height';return o[s]r(n[s])&&(e.offsets.popper[d]=r(n[s])),e}},arrow:{order:500,enabled:!0,fn:function(e,o){var n;if(!K(e.instance.modifiers,'arrow','keepTogether'))return e;var i=o.element;if('string'==typeof i){if(i=e.instance.popper.querySelector(i),!i)return e;}else if(!e.instance.popper.contains(i))return console.warn('WARNING: `arrow.element` must be child of its popper element!'),e;var r=e.placement.split('-')[0],p=e.offsets,s=p.popper,d=p.reference,a=-1!==['left','right'].indexOf(r),l=a?'height':'width',f=a?'Top':'Left',m=f.toLowerCase(),h=a?'left':'top',c=a?'bottom':'right',u=S(i)[l];d[c]-us[c]&&(e.offsets.popper[m]+=d[m]+u-s[c]),e.offsets.popper=g(e.offsets.popper);var b=d[m]+d[l]/2-u/2,w=t(e.instance.popper),y=parseFloat(w['margin'+f],10),E=parseFloat(w['border'+f+'Width'],10),v=b-e.offsets.popper[m]-y-E;return v=ee(Q(s[l]-u,v),0),e.arrowElement=i,e.offsets.arrow=(n={},ae(n,m,$(v)),ae(n,h,''),n),e},element:'[x-arrow]'},flip:{order:600,enabled:!0,fn:function(e,t){if(W(e.instance.modifiers,'inner'))return e;if(e.flipped&&e.placement===e.originalPlacement)return e;var o=v(e.instance.popper,e.instance.reference,t.padding,t.boundariesElement,e.positionFixed),n=e.placement.split('-')[0],i=T(n),r=e.placement.split('-')[1]||'',p=[];switch(t.behavior){case ce.FLIP:p=[n,i];break;case ce.CLOCKWISE:p=G(n);break;case ce.COUNTERCLOCKWISE:p=G(n,!0);break;default:p=t.behavior;}return p.forEach(function(s,d){if(n!==s||p.length===d+1)return e;n=e.placement.split('-')[0],i=T(n);var a=e.offsets.popper,l=e.offsets.reference,f=Z,m='left'===n&&f(a.right)>f(l.left)||'right'===n&&f(a.left)f(l.top)||'bottom'===n&&f(a.top)f(o.right),g=f(a.top)f(o.bottom),b='left'===n&&h||'right'===n&&c||'top'===n&&g||'bottom'===n&&u,w=-1!==['top','bottom'].indexOf(n),y=!!t.flipVariations&&(w&&'start'===r&&h||w&&'end'===r&&c||!w&&'start'===r&&g||!w&&'end'===r&&u),E=!!t.flipVariationsByContent&&(w&&'start'===r&&c||w&&'end'===r&&h||!w&&'start'===r&&u||!w&&'end'===r&&g),v=y||E;(m||b||v)&&(e.flipped=!0,(m||b)&&(n=p[d+1]),v&&(r=z(r)),e.placement=n+(r?'-'+r:''),e.offsets.popper=le({},e.offsets.popper,C(e.instance.popper,e.offsets.reference,e.placement)),e=P(e.instance.modifiers,e,'flip'))}),e},behavior:'flip',padding:5,boundariesElement:'viewport',flipVariations:!1,flipVariationsByContent:!1},inner:{order:700,enabled:!1,fn:function(e){var t=e.placement,o=t.split('-')[0],n=e.offsets,i=n.popper,r=n.reference,p=-1!==['left','right'].indexOf(o),s=-1===['top','left'].indexOf(o);return i[p?'left':'top']=r[o]-(s?i[p?'width':'height']:0),e.placement=T(t),e.offsets.popper=g(i),e}},hide:{order:800,enabled:!0,fn:function(e){if(!K(e.instance.modifiers,'hide','preventOverflow'))return e;var t=e.offsets.reference,o=D(e.instance.modifiers,function(e){return'preventOverflow'===e.name}).boundaries;if(t.bottomo.right||t.top>o.bottom||t.rightwindow.devicePixelRatio||!fe),c='bottom'===o?'top':'bottom',g='right'===n?'left':'right',b=B('transform');if(d='bottom'==c?'HTML'===l.nodeName?-l.clientHeight+h.bottom:-f.height+h.bottom:h.top,s='right'==g?'HTML'===l.nodeName?-l.clientWidth+h.right:-f.width+h.right:h.left,a&&b)m[b]='translate3d('+s+'px, '+d+'px, 0)',m[c]=0,m[g]=0,m.willChange='transform';else{var w='bottom'==c?-1:1,y='right'==g?-1:1;m[c]=d*w,m[g]=s*y,m.willChange=c+', '+g}var E={"x-placement":e.placement};return e.attributes=le({},E,e.attributes),e.styles=le({},m,e.styles),e.arrowStyles=le({},e.offsets.arrow,e.arrowStyles),e},gpuAcceleration:!0,x:'bottom',y:'right'},applyStyle:{order:900,enabled:!0,fn:function(e){return V(e.instance.popper,e.styles),j(e.instance.popper,e.attributes),e.arrowElement&&Object.keys(e.arrowStyles).length&&V(e.arrowElement,e.arrowStyles),e},onLoad:function(e,t,o,n,i){var r=L(i,t,e,o.positionFixed),p=O(o.placement,r,t,e,o.modifiers.flip.boundariesElement,o.modifiers.flip.padding);return t.setAttribute('x-placement',p),V(t,{position:o.positionFixed?'fixed':'absolute'}),o},gpuAcceleration:void 0}}},ge}); -//# sourceMappingURL=popper.min.js.map diff --git a/templates/book.html b/templates/book.html index f500658..1a84bd5 100644 --- a/templates/book.html +++ b/templates/book.html @@ -72,6 +72,36 @@ + + +
@@ -81,24 +111,51 @@

{{ data[0][2] }}

-

时间: {{time}}

-

暂无评价

+

更新时间: {{time}}

+

👍{{socre["like"]}} 👎{{socre["dislike"]}}

+ +
+
+
+

评论区

+ {% if not comments%} +

暂无评论

+ {%endif%} + {% for item in comments %}
-

用户A:Lorem ipsum dolor sit amet consectetur adipisicing elit. Nobis, quam!

-
-
-

用户B:Lorem, ipsum dolor sit amet consectetur adipisicing elit. Aut sunt tempore architecto minus, cum - mollitia voluptatibus repellendus aliquid id reprehenderit.

+

{{item["from"]}}: + {%if item["socre"] == "like"%} + 觉得很赞👍 + {%endif%} + {%if item["socre"] == "dislike"%} + 点了个踩👎 + {%endif%} +

+

{{item["text"]}}

+ id:{{item["id"]}} {{item["time"]}}
+ {% endfor %}
+ + + + + + + \ No newline at end of file diff --git a/templates/overview.html b/templates/overview.html index 5b120ec..1bfbece 100644 --- a/templates/overview.html +++ b/templates/overview.html @@ -50,7 +50,7 @@ -webkit-backdrop-filter: blur(10px); /* 模糊度可以根据需要调整 */ transition: display; - z-index: 1; + z-index: 10; /* 保证遮罩在页面上方 */ pointer-events: none; /* 确保遮罩不影响下方元素的交互 */ @@ -61,10 +61,20 @@ -
- - +
+
+ + +
+