Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
SunWuyuan committed Mar 23, 2024
1 parent 63c3104 commit 8d185e1
Show file tree
Hide file tree
Showing 15 changed files with 154 additions and 190 deletions.
23 changes: 20 additions & 3 deletions server/router_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,10 @@ router.get('/usertx', function (req, res) {
router.post("/getuserinfo", function (req, res) {
//获取已分享的作品总数:1:普通作品,2:推荐的优秀作品

SQL = `SELECT id,nickname, motto FROM user WHERE id = ${req.query.id || req.body.id};`;

DB.query(SQL, function (err, USER) {
SQL = `SELECT id,nickname, motto,images,regTime FROM user WHERE id=?;`;
id = [req.query.id || req.body.id]

DB.qww(SQL,id, function (err, USER) {
if (err || USER.length == 0) {
res.locals.tip = { opt: "flash", msg: "用户不存在" };
res.render("404.ejs");
Expand All @@ -147,6 +148,22 @@ router.post("/getuserinfo", function (req, res) {
});
});

router.get("/getuserinfo", function (req, res) {
//获取已分享的作品总数:1:普通作品,2:推荐的优秀作品

SQL = `SELECT id,nickname, motto,images,regTime,tag FROM user WHERE id=?;`;
id = [req.query.id || req.body.id]

DB.qww(SQL,id, function (err, USER) {
if (err || USER.length == 0) {
res.locals.tip = { opt: "flash", msg: "用户不存在" };
res.render("404.ejs");
return;
}
res.status(200).send({status: 'ok',info:USER[0]});

});
});
//平台概况
router.get('/info', function (req, res) {
var SQL = `SELECT `+
Expand Down
118 changes: 2 additions & 116 deletions server/router_python.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ router.post("/view/getPythonProjects", function (req, res) {
type = "time";
}

var SQL = `SELECT python.id, python.title, python.state,python.authorid, python.description,user.nickname,user.motto FROM python JOIN user ON python.authorid = user.id WHERE python.state > 0 ORDER BY python.${type} DESC LIMIT ${
var SQL = `SELECT python.id, python.title, python.state,python.authorid, python.description,python.view_count,user.nickname,user.motto FROM python JOIN user ON python.authorid = user.id WHERE python.state > 0 ORDER BY python.${type} DESC LIMIT ${
(curr - 1) * limit
}, ${limit}`;
DB.query(SQL, function (err, data) {
Expand All @@ -61,7 +61,7 @@ router.post("/view/seachPythonProjects", function (req, res) {
searchinfo = "src";
}
//var SQL = `SELECT id, title FROM ${tabelName} WHERE state>0 AND (${searchinfo} LIKE ?) LIMIT 12`;
var SQL = `SELECT ${tabelName}.id, ${tabelName}.title, ${tabelName}.state,${tabelName}.authorid,${tabelName}.description, user.nickname,user.motto FROM ${tabelName} JOIN user ON ${tabelName}.authorid = user.id WHERE ${tabelName}.state>0 AND (${searchinfo} LIKE ?)`;
var SQL = `SELECT ${tabelName}.id, ${tabelName}.title, ${tabelName}.state,${tabelName}.authorid,${tabelName}.description,${tabelName}.view_count, user.nickname,user.motto FROM ${tabelName} JOIN user ON ${tabelName}.authorid = user.id WHERE ${tabelName}.state>0 AND (${searchinfo} LIKE ?)`;
var WHERE = [`%${req.body.txt}%`];
DB.qww(SQL, WHERE, function (err, data) {
if (err) {
Expand All @@ -78,120 +78,6 @@ router.get('/play', function (req, res) {
res.render('python/python_play.ejs');
});

//项目点赞
router.post('/play/like', function (req, res) {
if (!res.locals.login){
res.status(200).send( {'status': 'failed','msg': '请先登录'});
return;
}

var pid = req.body['pid'];
var SQL = `SELECT id FROM python_like WHERE userid=${res.locals.userid} AND projectid=${pid} LIMIT 1`;
DB.query(SQL, function(err, LIKE){
if (err){
res.status(200).send( {'status': 'failed','msg': '数据错误,请再试一次'});
return;
}

if (LIKE.length==0){
//插入一条点赞记录、python表like_count+1
var UPDATE = `UPDATE python SET like_count=like_count+1 WHERE id=${pid} LIMIT 1`;
DB.query(UPDATE, function(err, PYTHON){
if (err|| PYTHON.changedRows==0){
res.status(200).send( {'status': 'failed','msg': '数据错误,请再试一次'});
return;
}

var INSERT =`INSERT INTO python_like (userid, projectid) VALUES (${res.locals.userid}, ${pid})`;
DB.query(INSERT, function(err, LIKE){
if (err || LIKE.affectedRows == 0){
res.status(200).send( {'status': 'failed','msg': '数据错误,请再试一次'});
return;
}

res.status(200).send( {'status': '1','opt':1,'msg': '感谢点赞!'});
});
});
} else {
//删除一条点赞记录、python表like_count-1
var UPDATE = `UPDATE python SET like_count=like_count-1 WHERE id=${pid} LIMIT 1`;
DB.query(UPDATE, function(err, PYTHON){
if (err|| PYTHON.changedRows==0){
res.status(200).send( {'status': 'failed','msg': '数据错误,请再试一次'});
return;
}

var INSERT =`DELETE FROM python_like WHERE id=${LIKE[0].id} LIMIT 1`;
DB.query(INSERT, function(err, LIKE){
if (err || LIKE.affectedRows == 0){
res.status(200).send( {'status': 'failed','msg': '数据错误,请再试一次'});
return;
}

res.status(200).send( {'status': '1','opt':-1,'msg': '操作成功'});
});
});
}
});
});
//项目收藏
router.post('/play/favo', function (req, res) {
if (!res.locals.login){
res.status(200).send( {'status': 'failed','msg': '请先登录'});
return;
}

var pid = req.body['pid'];
var SQL = `SELECT id FROM python_favo WHERE userid=${res.locals.userid} AND projectid=${pid} LIMIT 1`;
DB.query(SQL, function(err, FAVO){
if (err){
res.status(200).send( {'status': 'failed','msg': '数据错误,请再试一次'});
return;
}

if (FAVO.length==0){
//插入一条收藏记录、python表favo_count+1
var UPDATE = `UPDATE python SET favo_count=favo_count+1 WHERE id=${pid} LIMIT 1`;
DB.query(UPDATE, function(err, PYTHON){
if (err|| PYTHON.changedRows==0){
res.status(200).send( {'status': 'failed','msg': '数据错误,请再试一次'});
return;
}

var INSERT =`INSERT INTO python_favo (userid, projectid) VALUES (${res.locals.userid}, ${pid})`;
DB.query(INSERT, function(err, FAVO){
if (err || FAVO.affectedRows == 0){
res.status(200).send( {'status': 'failed','msg': '数据错误,请再试一次'});
return;
}

res.status(200).send( {'status': '1','opt':1,'msg': '感谢收藏!'});
});
});
} else {
//删除一条收藏记录、python表favo_count-1
var UPDATE = `UPDATE python SET favo_count=favo_count-1 WHERE id=${pid} LIMIT 1`;
DB.query(UPDATE, function(err, PYTHON){
if (err|| PYTHON.changedRows==0){
res.status(200).send( {'status': 'failed','msg': '数据错误,请再试一次'});
return;
}

var INSERT =`DELETE FROM python_favo WHERE id=${FAVO[0].id} LIMIT 1`;
DB.query(INSERT, function(err, FAVO){
if (err || FAVO.affectedRows == 0){
res.status(200).send( {'status': 'failed','msg': '数据错误,请再试一次'});
return;
}

res.status(200).send( {'status': '1','opt':-1,'msg': '操作成功'});
});
});
}
});
});



//python项目编辑界面:获取项目源代码
router.get('/edit', function (req, res) {
Expand Down
4 changes: 2 additions & 2 deletions server/router_scratch.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ router.post("/view/getScratchProjects", function (req, res) {
type = "time";
}

var SQL = `SELECT scratch.id, scratch.title, scratch.state,scratch.authorid, user.nickname,user.motto FROM scratch JOIN user ON scratch.authorid = user.id WHERE scratch.state > 0 ORDER BY scratch.${type} DESC LIMIT ${
var SQL = `SELECT scratch.id, scratch.title, scratch.state,scratch.authorid,scratch.view_count, user.nickname,user.motto FROM scratch JOIN user ON scratch.authorid = user.id WHERE scratch.state > 0 ORDER BY scratch.${type} DESC LIMIT ${
(curr - 1) * limit
}, ${limit}`;
DB.query(SQL, function (err, data) {
Expand All @@ -61,7 +61,7 @@ router.post("/view/seachScratchProjects", function (req, res) {
searchinfo = "src";
}
//var SQL = `SELECT id, title FROM ${tabelName} WHERE state>0 AND (${searchinfo} LIKE ?) LIMIT 12`;
var SQL = `SELECT ${tabelName}.id, ${tabelName}.title, ${tabelName}.state,${tabelName}.authorid,${tabelName}.description, user.nickname,user.motto FROM ${tabelName} JOIN user ON ${tabelName}.authorid = user.id WHERE ${tabelName}.state>0 AND (${searchinfo} LIKE ?)`;
var SQL = `SELECT ${tabelName}.id, ${tabelName}.title, ${tabelName}.state,${tabelName}.authorid,${tabelName}.description,${tabelName}.view_count, user.nickname,user.motto FROM ${tabelName} JOIN user ON ${tabelName}.authorid = user.id WHERE ${tabelName}.state>0 AND (${searchinfo} LIKE ?)`;
var WHERE = [`%${req.body.txt}%`];
DB.qww(SQL, WHERE, function (err, data) {
if (err) {
Expand Down
7 changes: 5 additions & 2 deletions views/html-footer.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<script type="text/javascript" src="<%= process.env.staticurl %>/layui/layui.all.js"></script>
<script src="<%= process.env.staticurl %>/mdui2/mdui.global.js"></script>
<script type="text/javascript" src="<%= process.env.staticurl %>/js/main.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/dompurify/3.0.11/purify.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/marked/12.0.1/marked.min.js"></script>

<script>
function automsg(msg) {
Expand All @@ -22,14 +24,15 @@
<mdui-button-icon icon="close" onclick="webdialog.open = false"></mdui-button-icon>
<mdui-top-app-bar-title ></mdui-top-app-bar-title>
<div style="flex-grow: 1"></div>
<mdui-button-icon icon="fullscreen" onclick="webdialog.fullscreen = !webdialog.fullscreen" id="webdialogfull"></mdui-button-icon>
<mdui-button-icon icon="fullscreen" onclick="webdialog.fullscreen = !webdialog.fullscreen " id="webdialogfull"></mdui-button-icon>
<mdui-button-icon icon="open_in_new" onclick="window.open(`${webdialogiframe.src}`)" id="webdialogfull"></mdui-button-icon>

</mdui-top-app-bar>
<iframe
frameborder="0"
id="webdialogiframe"
style="height: 90vh;width: 95vw;border-radius: 15px;"
style="min-height: calc(100vh - 208px);min-width: 497px;width: 100%;border-radius: 15px;"

>
<p>
<a href="https://developer.mozilla.org/zh-CN/docs/Glossary">
Expand Down
13 changes: 8 additions & 5 deletions views/html-head.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@
<meta name="description" content="<%= process.env.SiteSlogan %>">
<meta name="keyword" content="<%= process.env.SiteSlogan %>">


<script src="https://npm.elemecdn.com/[email protected]/dist/js/mdui.min.js"></script>

<link rel="stylesheet" href="https://npm.elemecdn.com/[email protected]/dist/css/mdui.min.css" />
<link rel="stylesheet" href="<%= process.env.staticurl %>/mdui2/mdui.css">
<link rel="stylesheet" href="<%= process.env.staticurl %>/layui/css/layui.css">
<link rel="stylesheet" href="<%= process.env.staticurl %>/css/projectspage.css">
<link rel="stylesheet" href="<%= process.env.staticurl %>/css/main.css">
<link rel="stylesheet" href="<%= process.env.staticurl %>/css/waline.css" />



<meta name="view-transition" content="same-origin">
<link id="layui_theme_css" rel="stylesheet">

Expand All @@ -30,7 +33,7 @@
</style>
<body class="mdui-theme-light mdui-theme-accent-blue mdui-loaded " >
<mdui-layout style='height: 100vh;'>


<mdui-navigation-drawer class="user-drawer" close-on-esc close-on-overlay-click>
<mdui-list>
Expand All @@ -57,7 +60,7 @@
<mdui-list>
<mdui-list-item rounded id="open-feedback-dialog" icon="send" description="发送反馈">反馈</mdui-list-item>
<mdui-list-item rounded href="/tools/asdm" icon="content_copy" description="公益Scratch下载镜像">Scratch下载镜像</mdui-list-item>
<mdui-list-item rounded href="/tools/comparer" icon="build" description="对比项目差异">项目比较器</mdui-list-item>
<mdui-list-item rounded onclick="openWebdialog('https:\/\/b2.190823.xyz/ourworld/comparer.html')" icon="build" description="对比项目差异">项目比较器</mdui-list-item>
<mdui-list-item rounded icon="brightness_4" id="switch-theme" description="切换light/dark">切换主题</mdui-list-item>

<mdui-list-item rounded>当前CDN节点<span id="cdn" slot="description">[未知]</span></mdui-list-item>
Expand All @@ -81,8 +84,8 @@
<mdui-navigation-drawer class="types-drawer" close-on-esc close-on-overlay-click>

<mdui-list>
<mdui-list-item rounded href="/scratch" icon="code">Scratch分区</mdui-list-item>
<mdui-list-item rounded href="/python" icon="code">Python分区</mdui-list-item>
<mdui-list-item rounded href="/scratch" icon="code">Scratch</mdui-list-item>
<mdui-list-item rounded href="/python" icon="code">Python</mdui-list-item>
<mdui-list-item rounded class="close-types" icon="arrow_left">关闭</mdui-list-item>
</mdui-list>

Expand Down
4 changes: 2 additions & 2 deletions views/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
/>
</mdui-card>
<div style="padding: 16px">
<div style="font-size: 24px">Scratch分区</div>
<div style="font-size: 24px">Scratch</div>
<div style="font-size: 14px; opacity: 0.54">图形化编程</div>
</div>
</mdui-card>
Expand All @@ -80,7 +80,7 @@
/>
</mdui-card>
<div style="padding: 16px">
<div style="font-size: 24px">Python分区</div>
<div style="font-size: 24px">Python</div>
<div style="font-size: 14px; opacity: 0.54">适合新手的代码编程语言</div>
</div>
</mdui-card>
Expand Down
64 changes: 42 additions & 22 deletions views/my_info.ejs
Original file line number Diff line number Diff line change
@@ -1,47 +1,67 @@
<%- include('./html-head.ejs', {pageTitle: '个人中心'}); %>

<div class="mdui-typo-display-2">
<%= nickname %>
个人信息
</div>
<div class="mdui-typo-headline-opacity">
<%= motto %>
您可以随时修改个人信息,可能要重新登录后本地生效
</div><br />






<div class="mdui-row">
<div class="mdui-textfield mdui-textfield-floating-label mdui-col-xs-2">
<mdui-tabs value="tab-1">
<mdui-tab value="tab-1">用户信息</mdui-tab>
<mdui-tab value="tab-2">头像</mdui-tab>
<mdui-tab value="tab-3">安全</mdui-tab>

<mdui-tab-panel slot="panel" value="tab-1">
<br/>

<div>
<div class=" mdui-col-xs-2" style=" margin-bottom: 10px;
">
<mdui-text-field variant="outlined" id="my_nickname" maxlength="10" value="<%= nickname %>"
label="昵称"></mdui-text-field>

</div>
<div class="mdui-textfield mdui-textfield-floating-label mdui-col-xs-10">
<mdui-text-field variant="outlined" id="my_aboutme" maxlength="255" value="<%= motto %>"
label="简介"></mdui-text-field>
<br/>
<div class="mdui-col-xs-12" style=" margin-bottom: 10px;
">
<mdui-text-field variant="outlined" id="my_aboutme" maxlength="1000" value="<%= motto %>"
label="简介" autosize min-rows="2"></mdui-text-field>
</div>
<br/>
<mdui-select variant="outlined" id="sex-chick" label="性别" class="mdui-col-xs-3" <% if (sex==1) { %>value="1" <% } %>
<% if (sex==0) { %>value="0" <% } %> >
<mdui-menu-item value="1">男</mdui-menu-item>
<mdui-menu-item value="0">女</mdui-menu-item>
</mdui-select>
</div>
<mdui-select variant="outlined" id="sex-chick" label="性别" <% if (sex==1) { %>value="1" <% } %>
<% if (sex==0) { %>value="0" <% } %> style="width: 120px;">
<mdui-menu-item value="1">男</mdui-menu-item>
<mdui-menu-item value="0">女</mdui-menu-item>
</mdui-select>
<div style="float: right;">
<mdui-button href="/my/info">取消</mdui-button>
<mdui-button onclick="updataInfo()">确认</mdui-button>
</div>
</mdui-tab-panel>
<mdui-tab-panel slot="panel" value="tab-2"><br/>
<img class="mdui-img-circle mdui-m-l-2" src="/api/usertx?id=<%= userid %>"
style="height: 100px;width: auto;border-radius: 15px;" />
<br/> <br/>
<mdui-button class="avatarUpload " lay-data="{exts:'png|jpg', size:1024}">修改头像</mdui-button>
</mdui-tab-panel><br/>
<mdui-tab-panel slot="panel" value="tab-3"> <br/> <mdui-text-field variant="outlined" id='old_password' type="password"
label="原密码" autocomplete="off"></mdui-text-field><br/><br/>
<mdui-text-field variant="outlined" id='new_password' type="password"
label="新密码" autocomplete="off"></mdui-text-field><br/>
<div style="float: right;">
<mdui-button onclick="updatePassword()">确认</mdui-button>
</div>
</mdui-tab-panel>
</mdui-tabs>





<br /><br />
<img class="mdui-img-circle mdui-m-l-2" src="/api/usertx?id=<%= userid %>"
style="height: 100px;width: auto;border-radius: 15px;" />
<br/> <br/>
<mdui-button class="avatarUpload " lay-data="{exts:'png|jpg', size:1024}">修改头像</mdui-button>

<mdui-button class="open-password-dialog">修改密码</mdui-button>
<mdui-dialog class="password-dialog"
headline="修改密码"
description="请确保密码足够安全"
Expand Down
Loading

0 comments on commit 8d185e1

Please sign in to comment.