完成备忘的更新

This commit is contained in:
HelloWorld 2020-04-08 11:10:32 +08:00
parent 6c4dc01f36
commit b66e8d8a83
8 changed files with 88 additions and 72 deletions

View File

@ -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() });
}

View File

@ -3,7 +3,7 @@
<!-- 百度统计 -->
<script>
var _hmt = _hmt || [];
(function() {
(function () {
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?01351b0343ccf42968923cff21a4a851";
var s = document.getElementsByTagName("script")[0];
@ -26,34 +26,45 @@
<link href="css/externe/ngDialog-theme-default.css" rel="stylesheet" />
<link href="css/externe/ngDialog-theme-plain.css" rel="stylesheet" />
<script type="text/javascript">
window.onload = function() {
window.onload = function () {
var clipboard = new ClipboardJS(document.getElementById("clipboard"));
clipboard.on("success", function(e) {
clipboard.on("success", function (e) {
var text = e.text.length >= 180 ? e.text.substr(0, 180) + "..." : e.text;
toastr.success(text + "<br/>已复制到您的剪切板", "提示");
e.clearSelection();
});
clipboard.on("error", function(e) {
clipboard.on("error", function (e) {
var text = e.text.length >= 180 ? e.text.substr(0, 180) + "..." : e.text;
toastr.error(text + "<br/>复制失败", "提示");
});
};
let resizeContainer = () => {
let count = 1;
let id = setInterval(() => {
if (count++ >= 100) {
clearInterval(id);
}
$("#js-container").css("left", ($(window).width() - $("#js-container").width()) / 2);
}, 10);
};
window.onresize = resizeContainer;
resizeContainer();
</script>
</head>
<body ng-app="bookmarkApp">
<div class="ui container">
<div class="ui container" id="js-container" style="position: absolute;left: 86;">
<!-- directive菜单 -->
<menus></menus>
<div class="ui container" style="width:100%;height:2px"></div>
<div class="ui container" style="width: 100%; height: 2px;"></div>
<div class="ui container">
<div ui-view></div>
</div>
<div class="ui container" style="width:100%;height:10px"></div>
<div class="foot" style="margin-bottom:10px;">
<div class="ui container" style="width: 100%; height: 10px;"></div>
<div class="foot" style="margin-bottom: 10px;">
<div class="ui segment container">我爱佳佳与这个世界&nbsp;&nbsp;|&nbsp;&nbsp;Copyleft ©All Rights Reserved LCQ&nbsp;&nbsp;|&nbsp;&nbsp;<a href="http://m.mybookmark.cn/">移动设备访问</a>&nbsp;&nbsp;|&nbsp;&nbsp;联系我(QQ:530485521)&nbsp;&nbsp;|&nbsp;&nbsp;<a href="https://github.com/luchenqun/my-bookmark" target="_blank">网站源码</a>&nbsp;&nbsp;|&nbsp;&nbsp;V1.5.0&nbsp;&nbsp;|&nbsp;&nbsp;<span>加载失败请按F5(●'◡'●)</span><br /></div>
<!-- 主要用来配合clipboard.min.js复制文本的 -->
<div id="clipboard" data-clipboard-text="i love this world and jiajia!" style="opacity:0;cursor:default">
<div id="clipboard" data-clipboard-text="i love this world and jiajia!" style="opacity: 0; cursor: default;">
<span>Copy</span>
</div>
</div>

View File

@ -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;
}

View File

@ -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) => {

View File

@ -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) {

View File

@ -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 || '{}'));

View File

@ -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);

View File

@ -1,12 +1,12 @@
<div class="ui segment js-note-card" style="padding:14px 0px 0px 0px;">
<div class="ui segment js-note-card" style="padding:14px 0px 0px 0px;" ng-show="!loading || tags.length > 0">
<div class="ui container" style="padding-left:14px">
<div class="ui label" style="margin:3px 15px 8px 0px;cursor:default;" ng-class="{green:tag.clicked}" ng-repeat="tag in tags" ng-click="clickTag(tag.id)" ng-show="tag.noteCount || add">{{ tag.name }} ({{ tag.noteCount || 0 }})</div>
<div class="ui label" style="margin:3px 15px 8px 0px;cursor:default;" ng-click="showAddNote()" data-tooltip="点击添加备忘。你也可以在任意界面按快捷键A(不区分大小写)增加备忘录。">
<i class="plus icon" style="margin-right:0px;"></i>
</div>
</div>
<div class="ui container" style="padding-left:14px;padding-bottom:14px">
<div class="ui form" ng-show="add">
<div class="ui container" style="padding-left:14px;padding-bottom:14px" ng-show="add">
<div class="ui form" >
<div class="required field">
<label>内容</label>
<textarea rows="12" placeholder="" ng-model="content" id="noteedit"></textarea>
@ -31,7 +31,7 @@
</ul>
</div>
</div>
<div class="ui vertical segment" ng-repeat="note in notes" ng-click="noteClick(note)" ng-mouseover="setHoverNote(note)" ng-mouseleave="setHoverNote(null)" id="{{note.id}}" style="margin:0px;padding-top:10px;padding-bottom: 10px;">
<div class="ui vertical segment" ng-repeat="note in notes" ng-click="noteClick(note)" ng-mouseover="setHoverNote(note)" ng-mouseleave="setHoverNote(null)" id="{{note.id}}" style="margin:0px;padding:10px 0px;">
<pre class="note-content" title="单击查看详情C复制D删除E编辑" style="margin:0px;padding-left:14px;padding-right:14px" ng-if="!note.detail">{{ note.brief }}</pre>
<pre class="note-content" title="双击复制" ng-dblclick="copy(note.content)" style="margin:0px; font-size:16px;padding:60px 14px;" ng-if="note.detail">{{ note.content }}</pre>
<div class="ui right aligned grid" ng-show="note.detail">
@ -63,6 +63,6 @@
</div>
</div>
</div>
<div class="ui massive text centered inline loader js-hot-loader" ng-class="{active:loadBusy, disabled:!loadBusy}">
<div class="ui massive text centered inline loader js-hot-loader" style="margin-top: 10px;" ng-class="{active:loading, disabled:!loading}">
正在加载中...
</div>