From b66e8d8a838947d53cae8968cd4276e95ecbfb2b Mon Sep 17 00:00:00 2001 From: HelloWorld Date: Wed, 8 Apr 2020 11:10:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=A4=87=E5=BF=98=E7=9A=84?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controller/api.js | 11 +- view/index_index.html | 29 +++-- www/css/style.css | 2 +- www/scripts/controllers/edit-controller.js | 2 +- www/scripts/controllers/note-controller.js | 100 +++++++++--------- .../controllers/settings-controller.js | 2 +- www/scripts/controllers/tags-controller.js | 4 +- www/views/note.html | 10 +- 8 files changed, 88 insertions(+), 72 deletions(-) diff --git a/src/controller/api.js b/src/controller/api.js index 7f14143..5c8ebff 100644 --- a/src/controller/api.js +++ b/src/controller/api.js @@ -568,14 +568,17 @@ module.exports = class extends Base { } async notesAction() { + let params = this.get(); let where = {}; try { - let keyword = this.get('keyword'); - if (keyword) { - where.content = ['like', `%${keyword}%`] + if (params.keyword) { + where.content = ['like', `%${params.keyword}%`] + } + if (params.tagId) { + where.tagId = params.tagId; } let data = await this.model('notes').where(where).order("createdAt DESC").page(this.get('page'), this.get('pageSize')).countSelect(); - this.json({ code: 0, data }); + this.json({ code: 0, data }) } catch (error) { this.json({ code: 1, msg: error.toString() }); } diff --git a/view/index_index.html b/view/index_index.html index 51a79cb..7ef9a3e 100644 --- a/view/index_index.html +++ b/view/index_index.html @@ -3,7 +3,7 @@ -
+
-
+
-
-
+
+
我爱佳佳与这个世界  |  Copyleft ©All Rights Reserved LCQ  |  移动设备访问  |  联系我(QQ:530485521)  |  网站源码  |  V1.5.0  |  加载失败,请按F5!(●'◡'●)
-
+
Copy
diff --git a/www/css/style.css b/www/css/style.css index 361b18b..eccb232 100644 --- a/www/css/style.css +++ b/www/css/style.css @@ -3,7 +3,7 @@ body { background-repeat: repeat; background-position: top left; background-attachment: scroll; - padding: 50px; + padding-top: 50px; font: 14px "Lucida Grande", Helvetica, Arial, sans-serif; } diff --git a/www/scripts/controllers/edit-controller.js b/www/scripts/controllers/edit-controller.js index abd5e0b..9adddde 100644 --- a/www/scripts/controllers/edit-controller.js +++ b/www/scripts/controllers/edit-controller.js @@ -235,7 +235,7 @@ app.controller('editCtr', ['$scope', '$state', '$timeout', '$document', 'ngDialo async function getTags() { let tags = await get('tags'); tags.sort((a, b) => { - if (a.last_use > b.last_use) return -1; + if (a.lastUse > b.lastUse) return -1; return 1; }) tags.forEach((tag) => { diff --git a/www/scripts/controllers/note-controller.js b/www/scripts/controllers/note-controller.js index 0231aea..0b5d133 100644 --- a/www/scripts/controllers/note-controller.js +++ b/www/scripts/controllers/note-controller.js @@ -5,10 +5,9 @@ app.controller('noteCtr', ['$scope', '$state', '$stateParams', '$filter', '$wind return; } - const perPageItems = 35; var dialog = null; $scope.hoverNote = null; - $scope.loadBusy = false; + $scope.loading = false; $scope.add = false; $scope.edit = false; $scope.preContent = ''; @@ -26,15 +25,13 @@ app.controller('noteCtr', ['$scope', '$state', '$stateParams', '$filter', '$wind var timeagoInstance = timeago(); - get('user').then(user => { - pubSubService.publish('Common.menuActive', { - login: true, - index: dataService.LoginIndexNote - }); - getTags(); - getNotes(); + pubSubService.publish('Common.menuActive', { + login: true, + index: dataService.LoginIndexNote }); + getTags(); + $scope.changeCurrentPage = function (currentPage) { currentPage = parseInt(currentPage) || 0; if (currentPage <= $scope.totalPages && currentPage >= 1) { @@ -236,9 +233,7 @@ app.controller('noteCtr', ['$scope', '$state', '$stateParams', '$filter', '$wind $scope.totalItems = 0; updateSelectTag(id); - if ($scope.add || $scope.edit) { - - } else { + if (!($scope.add || $scope.edit)) { $scope.currentPage = 1; getNotes($scope.currentTagId); } @@ -287,7 +282,6 @@ app.controller('noteCtr', ['$scope', '$state', '$stateParams', '$filter', '$wind tag.clicked = false; if (tag.id == tagId) { tag.clicked = true; - t = tag; } }) } @@ -310,73 +304,81 @@ app.controller('noteCtr', ['$scope', '$state', '$stateParams', '$filter', '$wind }) }); + let count = 1; async function getNotes(tagId) { $scope.notes = []; - $scope.loadBusy = true; + $scope.loading = true; var params = { page: $scope.currentPage, - pageSize: perPageItems, + pageSize: 35, keyword: $scope.keyword, tagId: tagId || $scope.currentTagId }; + // if (count++ % 2) return; - try { - let reply = await get("notes", params); - $scope.notes = reply.data; - $scope.notes.forEach((note) => { + let reply = await get("notes", params); + $timeout(function () { + let notes = reply.data; + notes.forEach((note) => { note.brief = note.content || ""; while (note.brief.indexOf("\n") > 0) { note.brief = note.brief.replace(/\n/g, ""); } note.brief = " " + note.brief.substring(0, 200) + (note.content.length > 200 ? " ......" : ""); }) + + $scope.notes = notes; $scope.totalPages = reply.totalPages; $scope.totalItems = reply.count; - $timeout(function () { - timeagoInstance.cancel(); - timeagoInstance.render(document.querySelectorAll('.need_to_be_rendered'), 'zh_CN'); - // 如果需要增加书签 - if ($scope.key == 'A') { - $scope.key = null; - $scope.showAddNote(); - } - }, 100) - $scope.loadBusy = false; + + timeagoInstance.cancel(); + timeagoInstance.render(document.querySelectorAll('.need_to_be_rendered'), 'zh_CN'); + // 如果需要增加书签 + if ($scope.key == 'A') { + $scope.key = null; + $scope.showAddNote(); + } + $scope.loading = false; if ($scope.totalItems == 0) { $(".js-note").removeClass("hidden"); } - transition(); - } catch (error) { - $scope.notes = []; - $scope.loadBusy = false; - } + }) } - async function getTags() { - $scope.loadBusy = true; - $scope.tags = [] + async function updateTags(_tags) { + let tags = JSON.parse(JSON.stringify(_tags)); + $scope.loading = true; + $scope.tags = []; - let tags = await get('tags', { noteCount: true }); let find = false; tags.forEach((tag) => { - $scope.tags.push(tag); if (tag.id == $scope.currentTagId) { find = true; // 如果是删了分类返回来,那么要重新默认选中第一个分类 } }) if (!find) $scope.currentTagId = null; - $scope.loadBusy = false; + + $timeout(() => { + $scope.loading = false; + $scope.tags = tags; + getNotes(); + }) } - $('.js-note-card').transition('hide'); - - function transition() { - var className = 'js-note-card'; - $('.' + className).transition('hide'); - $('.' + className).transition({ - animation: dataService.animation(), - duration: 500, - }); + async function getTags() { + // 通过缓存tags,如果回来的tags跟缓存的一致,那么这个时间差就省下来了 + let tags = JSON.parse(localStorage.getItem("tags") || "[]"); + if (tags.length > 0) { + get('tags').then((_tags) => { + if (JSON.stringify(tags) != JSON.stringify(_tags)) { + localStorage.setItem("tags", JSON.stringify(tags)); + } + }); + } else { + tags = await get('tags'); + localStorage.setItem("tags", JSON.stringify(tags)); + } + updateTags(tags); } function toPos(id) { diff --git a/www/scripts/controllers/settings-controller.js b/www/scripts/controllers/settings-controller.js index 436a275..c2e89d2 100644 --- a/www/scripts/controllers/settings-controller.js +++ b/www/scripts/controllers/settings-controller.js @@ -24,7 +24,7 @@ app.controller('settingsCtr', ['$scope', '$stateParams', '$filter', '$state', '$ $scope.form[index] = true; if (index == 0 || index == 1 || index == 4) { let user = await get('user', { full: true }); - let tags = await get('tags', { bookmarkCount: true, noteCount: true }); + let tags = await get('tags'); $timeout(() => { $scope.user = user $scope.quickUrl = objKeySort(JSON.parse($scope.user.quickUrl || '{}')); diff --git a/www/scripts/controllers/tags-controller.js b/www/scripts/controllers/tags-controller.js index 3d36b1d..b811124 100644 --- a/www/scripts/controllers/tags-controller.js +++ b/www/scripts/controllers/tags-controller.js @@ -387,14 +387,14 @@ app.controller('tagsCtr', ['$scope', '$filter', '$state', '$window', '$statePara // 通过缓存tags,如果回来的tags跟缓存的一致,那么这个时间差就省下来了 let tags = JSON.parse(localStorage.getItem("tags") || "[]"); if (tags.length > 0) { - get('tags', { bookmarkCount: true }).then((_tags) => { + get('tags').then((_tags) => { if (JSON.stringify(tags) != JSON.stringify(_tags)) { localStorage.setItem("tags", JSON.stringify(tags)); updateTags(tags); } }); } else { - tags = await get('tags', { bookmarkCount: true }); + tags = await get('tags'); localStorage.setItem("tags", JSON.stringify(tags)); } updateTags(tags); diff --git a/www/views/note.html b/www/views/note.html index fc332c7..9a15d10 100644 --- a/www/views/note.html +++ b/www/views/note.html @@ -1,12 +1,12 @@ -
+
{{ tag.name }} ({{ tag.noteCount || 0 }})
-
-
+
+
@@ -31,7 +31,7 @@
-
+
{{ note.brief }}
{{ note.content }}
@@ -63,6 +63,6 @@
-
+
正在加载中...