完成备忘录的添加

This commit is contained in:
HelloWorld 2020-03-26 15:13:54 +08:00
parent 1d3b72ed2f
commit 8f8643deec
13 changed files with 1608 additions and 1576 deletions

View File

@ -12,6 +12,7 @@
"dependencies": { "dependencies": {
"cheerio": "^1.0.0-rc.3", "cheerio": "^1.0.0-rc.3",
"fs-extra": "^9.0.0", "fs-extra": "^9.0.0",
"node-readability": "^3.0.0",
"think-cache": "^1.0.0", "think-cache": "^1.0.0",
"think-cache-file": "^1.0.8", "think-cache-file": "^1.0.8",
"think-logger3": "^1.0.0", "think-logger3": "^1.0.0",

View File

@ -30,7 +30,7 @@ exports.cache = {
exports.model = { exports.model = {
type: 'mysql', type: 'mysql',
common: { common: {
logConnect: isDev, logConnect: false,
logSql: isDev, logSql: isDev,
logger: msg => think.logger.info(msg) logger: msg => think.logger.info(msg)
}, },

View File

@ -1,6 +1,7 @@
const Base = require('./base.js'); const Base = require('./base.js');
const crypto = require('crypto'); const crypto = require('crypto');
const fs = require('fs-extra'); const fs = require('fs-extra');
const read = require('node-readability');
function md5(str) { function md5(str) {
return crypto.createHash('md5').update(str).digest('hex'); return crypto.createHash('md5').update(str).digest('hex');
@ -84,8 +85,8 @@ module.exports = class extends Base {
if (param.bookmarkCount) { if (param.bookmarkCount) {
tag.bookmarkCount = await this.model('bookmarks').where({ tagId: tag.id }).count(); tag.bookmarkCount = await this.model('bookmarks').where({ tagId: tag.id }).count();
} }
if (param.notes) { if (param.noteCount) {
tag.bookmarkCount = await this.model('notes').where({ tagId: tag.id }).count(); tag.noteCount = await this.model('notes').where({ tagId: tag.id }).count();
} }
} }
this.json({ code: 0, data: tags, msg: '' }); this.json({ code: 0, data: tags, msg: '' });
@ -104,6 +105,19 @@ module.exports = class extends Base {
} }
} }
// 获取书签
// @todo 如果是自己的任意获取,如果是别人的必须公开才能获取
async bookmarkAction() {
let id = this.get("id");
try {
let data = await this.model('bookmarks').where({ id }).find();
this.json({ code: 0, data });
} catch (error) {
this.json({ code: 1, msg: error.toString() });
}
}
// 添加书签
async addBookmarkAction() { async addBookmarkAction() {
let bookmark = this.post(); let bookmark = this.post();
bookmark.userId = this.ctx.state.user.id; bookmark.userId = this.ctx.state.user.id;
@ -140,6 +154,69 @@ module.exports = class extends Base {
} }
} }
// 点击书签
async clickBookmarkAction() {
let id = this.post("id");
try {
let data = await this.model('bookmarks').where({
userId: this.ctx.state.user.id,
id
}).update({
clickCount: ['exp', 'clickCount+1'],
lastClick: ['exp', 'NOW()']
});
this.json({ code: 0, data });
} catch (error) {
this.json({ code: 1, msg: error.toString() });
}
}
// 更新书签
async updateBookmarkAction() {
let bookmark = this.post();
try {
let data = await this.model('bookmarks').where({
userId: this.ctx.state.user.id,
id: bookmark.id
}).update(bookmark);
this.json({ code: 0, data });
} catch (error) {
this.json({ code: 1, msg: error.toString() });
}
}
// 获取文章
async getArticleAction() {
let url = this.get("url");
async function readArticle(url) {
return new Promise(function (resolve, reject) {
read(url, (err, article, meta) => {
if (err) {
reject(err)
} else {
resolve({
title: article.title
});
article.close();
}
});
})
}
try {
let article = await readArticle(url);
this.json({
code: 0,
data: {
title: article.title
}
});
} catch (error) {
this.json({
code: 1,
msg: error.toString()
});
}
}
// 新增留言 // 新增留言
async addAdviceAction() { async addAdviceAction() {
let advice = this.post(); let advice = this.post();
@ -161,4 +238,53 @@ module.exports = class extends Base {
this.json({ code: 1, data: '', msg: error.toString() }); this.json({ code: 1, data: '', msg: error.toString() });
} }
} }
// 新增
async addNoteAction() {
let note = this.post();
note.userId = this.ctx.state.user.id;
try {
let data = await this.model("notes").add(note);
this.json({ code: 0, data, msg: `备忘添加成功` });
} catch (error) {
this.json({ code: 1, msg: error.toString() });
}
}
// 更新备忘
async updateNoteAction() {
let note = this.post();
note.userId = this.ctx.state.user.id;
try {
let data = await this.model('bookmarks').where({
userId: this.ctx.state.user.id,
id: note.id
}).update(note);
this.json({ code: 0, data, msg: `备忘更新成功` });
} catch (error) {
this.json({ code: 1, msg: error.toString() });
}
}
// 更新
async delNoteAction() {
let note = this.post();
note.userId = this.ctx.state.user.id;
try {
let data = await this.model("notes").where(note).delete();
this.json({ code: 0, data, msg: `备忘删除成功` });
} catch (error) {
this.json({ code: 1, msg: error.toString() });
}
}
async notesAction() {
let where = {};
try {
let data = await this.model('notes').where(where).order("createdAt DESC").page(this.get('page'), this.get('pageSize')).countSelect();
this.json({ code: 0, data });
} catch (error) {
this.json({ code: 1, msg: error.toString() });
}
}
}; };

View File

@ -4,38 +4,31 @@ app.controller('bookmarkInfoCtr', ['$scope', '$state', '$timeout', '$sce', '$win
$scope.content = ''; $scope.content = '';
$scope.loading = false; $scope.loading = false;
pubSubService.subscribe('TagCtr.showBookmarkInfo', $scope, function (event, bookmark) { pubSubService.subscribe('TagCtr.showBookmarkInfo', $scope, async function (event, bookmark) {
console.log('subscribe TagCtr.showBookmarkInfo', bookmark); console.log('subscribe TagCtr.showBookmarkInfo', bookmark);
$('.ui.modal.js-bookmark-info').modal({ $('.ui.modal.js-bookmark-info').modal({
closable: false, closable: false,
}).modal('setting', 'transition', dataService.animation()).modal('show'); }).modal('setting', 'transition', dataService.animation()).modal('show');
bookmark.favicon_url = 'http://favicon.luchenqun.com/?url=' + bookmark.url; bookmark.favicon_url = 'http://favicon.luchenqun.com/?url=' + bookmark.url;
bookmark.snap_url = bookmark.snap_url || ('./images/snap/' + bookmark.id + '.png');
$scope.bookmark = bookmark; $scope.bookmark = bookmark;
$scope.bookmark.description = $sce.trustAsHtml(bookmark.description); $scope.bookmark.description = $sce.trustAsHtml(bookmark.description);
$scope.content = $sce.trustAsHtml(bookmark.content) || ''; $scope.content = $sce.trustAsHtml(bookmark.content) || '';
var params = {
url: bookmark.url,
requestId: 1
}
if (!$scope.content) { if (!$scope.content) {
$timeout(function () { $timeout(function () {
$('.ui.modal.js-bookmark-info').modal("refresh"); $('.ui.modal.js-bookmark-info').modal("refresh");
$("p").css("word-wrap", "break-word"); $("p").css("word-wrap", "break-word");
}, 500); }, 500);
$scope.loading = true $scope.loading = true;
bookmarkService.getArticle(params) try {
.then((data) => { let data = get("getArticle", { url: bookmark.url });
$scope.content = data.content ? $sce.trustAsHtml(data.content) : $sce.trustAsHtml('<p>数据获取失败可能是服务器不允许获取或者是https网站</p>'); $scope.content = data.content ? $sce.trustAsHtml(data.content) : $sce.trustAsHtml('<p>数据获取失败可能是服务器不允许获取或者是https网站</p>');
setTimeout(function () { setTimeout(function () {
$('.ui.modal.js-bookmark-info').modal && $('.ui.modal.js-bookmark-info').modal("refresh"); $('.ui.modal.js-bookmark-info').modal && $('.ui.modal.js-bookmark-info').modal("refresh");
}, 100); }, 100);
$scope.loading = false; } catch (error) {
})
.catch((err) => { }
$scope.content = $sce.trustAsHtml('<p>数据获取失败:' + JSON.stringify(err) + '</p>'); $scope.loading = false;
$scope.loading = false;
})
} else { } else {
setTimeout(function () { setTimeout(function () {
$('.ui.modal.js-bookmark-info').modal && $('.ui.modal.js-bookmark-info').modal("refresh"); $('.ui.modal.js-bookmark-info').modal && $('.ui.modal.js-bookmark-info').modal("refresh");
@ -46,14 +39,12 @@ app.controller('bookmarkInfoCtr', ['$scope', '$state', '$timeout', '$sce', '$win
} }
}); });
$scope.jumpToUrl = function (url, id) { $scope.jumpToUrl = async function (url, id) {
$window.open(url, '_blank'); $window.open(url, '_blank');
if ($scope.bookmark.own) { if ($scope.bookmark.own) {
bookmarkService.clickBookmark({ await post('clickBookmark', { id });
id: id $scope.bookmark.clickCount += 1;
}); $scope.bookmark.lastClick = $filter("date")(new Date(), "yyyy-MM-dd HH:mm:ss");
$scope.bookmark.click_count += 1;
$scope.bookmark.last_click = $filter("date")(new Date(), "yyyy-MM-dd HH:mm:ss");
} }
} }

View File

@ -52,11 +52,10 @@ app.controller('bookmarksCtr', ['$scope', '$state', '$stateParams', '$filter', '
} }
} }
$scope.jumpToUrl = function (url, id) { $scope.jumpToUrl = async function (url, id) {
$window.open(url, '_blank'); $window.open(url, '_blank');
bookmarkService.clickBookmark({ await post("clickBookmark", { id });
id: id
});
if ($scope.showStyle != 'navigate') { if ($scope.showStyle != 'navigate') {
var bookmarks = $scope.showStyle == 'table' ? $scope.bookmarkData.bookmarks : $scope.bookmarkData; var bookmarks = $scope.showStyle == 'table' ? $scope.bookmarkData.bookmarks : $scope.bookmarkData;
@ -107,13 +106,11 @@ app.controller('bookmarksCtr', ['$scope', '$state', '$stateParams', '$filter', '
}); });
} }
$scope.editBookmark = function (bookmarkId) { $scope.editBookmark = function (id) {
pubSubService.publish('bookmarksCtr.editBookmark', { pubSubService.publish('bookmarksCtr.editBookmark', { id });
'bookmarkId': bookmarkId
});
} }
$scope.detailBookmark = function (b) { $scope.detailBookmark = async function (b) {
var bookmark = $.extend(true, {}, b); // 利用jQuery执行深度拷贝 var bookmark = $.extend(true, {}, b); // 利用jQuery执行深度拷贝
bookmark.own = true; bookmark.own = true;
if ($scope.showStyle == 'navigate') { if ($scope.showStyle == 'navigate') {
@ -123,9 +120,7 @@ app.controller('bookmarksCtr', ['$scope', '$state', '$stateParams', '$filter', '
}]; }];
} }
pubSubService.publish('TagCtr.showBookmarkInfo', bookmark); pubSubService.publish('TagCtr.showBookmarkInfo', bookmark);
bookmarkService.clickBookmark({ await post("clickBookmark", { id: bookmark.id });
id: bookmark.id
});
} }
$scope.copy = function (url) { $scope.copy = function (url) {

View File

@ -5,7 +5,7 @@ app.controller('editCtr', ['$scope', '$state', '$timeout', '$document', 'ngDialo
var cancelDefault = false; var cancelDefault = false;
init(); init();
$scope.$watch('url', function (newUrl, oldUrl, scope) { $scope.$watch('url', async function (newUrl, oldUrl, scope) {
$timeout(function () { $timeout(function () {
$scope.urlError = $scope.url == '' && $('.ui.modal.js-add-bookmark').modal('is active'); $scope.urlError = $scope.url == '' && $('.ui.modal.js-add-bookmark').modal('is active');
}); });
@ -17,23 +17,21 @@ app.controller('editCtr', ['$scope', '$state', '$timeout', '$document', 'ngDialo
requestId: 0, requestId: 0,
} }
$scope.loadTitle = true; $scope.loadTitle = true;
bookmarkService.getArticle(params) try {
.then((data) => { let data = await get('getArticle', { url: newUrl });
$scope.loadTitle = false; $scope.loadTitle = false;
$scope.originTitle = data.title; $scope.originTitle = data.title;
$scope.title = data.title; $scope.title = data.title;
if (!$scope.title) { if (!$scope.title) {
toastr.error('获取书签标题失败,请手动填入', "提示"); toastr.error('获取书签标题失败,请手动填入', "提示");
} else { } else {
$scope.title = data.title.split('-')[0].trim(); $scope.title = data.title.split('-')[0].trim();
} }
}) } catch (error) {
.catch((err) => { toastr.error('获取书签标题失败:' + JSON.stringify(err) + ',请手动填入', "提示");
console.log('getTitle err', err); $scope.loadTitle = false;
toastr.error('获取书签标题失败:' + JSON.stringify(err) + ',请手动填入', "提示"); }
$scope.loadTitle = false;
})
} }
} }
}); });
@ -84,7 +82,7 @@ app.controller('editCtr', ['$scope', '$state', '$timeout', '$document', 'ngDialo
return; return;
} }
if ($scope.tagsError) { if ($scope.tagsError) {
toastr.error('您至少要选择一个分类!最多选择三个分类!如果暂时没想到放到哪个分类,可以先选择未分类', "错误"); toastr.error('您至少要选择一个分类!如果暂时没想到放到哪个分类,可以先选择未分类', "错误");
return; return;
} }
if ($scope.titleError) { if ($scope.titleError) {
@ -98,16 +96,10 @@ app.controller('editCtr', ['$scope', '$state', '$timeout', '$document', 'ngDialo
$('.ui.modal.js-add-bookmark').modal('hide'); $('.ui.modal.js-add-bookmark').modal('hide');
pubSubService.publish('EditCtr.inserBookmarsSuccess', params); pubSubService.publish('EditCtr.inserBookmarsSuccess', params);
} else { } else {
bookmarkService.updateBookmark(params) await post('updateBookmark', params);
.then((data) => { $('.ui.modal.js-add-bookmark').modal('hide');
$('.ui.modal.js-add-bookmark').modal('hide'); pubSubService.publish('EditCtr.inserBookmarsSuccess', data);
pubSubService.publish('EditCtr.inserBookmarsSuccess', data); toastr.success('[ ' + params.title + ' ] 更新成功,将自动重新更新书签!', "提示");
toastr.success('[ ' + params.title + ' ] 更新成功,将自动重新更新书签!', "提示");
})
.catch((err) => {
console.log('updateBookmark err', err);
toastr.error('[ ' + params.title + ' ] 更新失败' + JSON.stringify(err), "提示");
});
} }
} }
@ -168,7 +160,7 @@ app.controller('editCtr', ['$scope', '$state', '$timeout', '$document', 'ngDialo
getTags(); getTags();
}); });
pubSubService.subscribe('bookmarksCtr.editBookmark', $scope, function (event, params) { pubSubService.subscribe('bookmarksCtr.editBookmark', $scope, async function (event, params) {
console.log('subscribe bookmarksCtr.editBookmark', params); console.log('subscribe bookmarksCtr.editBookmark', params);
$('.ui.modal.js-add-bookmark').modal({ $('.ui.modal.js-add-bookmark').modal({
closable: false, closable: false,
@ -178,36 +170,24 @@ app.controller('editCtr', ['$scope', '$state', '$timeout', '$document', 'ngDialo
}, 500); }, 500);
$scope.add = false; $scope.add = false;
$scope.loadTags = true; $scope.loadTags = true;
$scope.autoGettitle = false;
cancelDefault = false; cancelDefault = false;
bookmarkService.getBookmark(params)
.then((data) => {
console.log('getBookmark ', data);
var bookmark = data.bookmark; let bookmark = await get("bookmark", params);
$scope.autoGettitle = false; let tags = await get("tags");
$scope.id = (bookmark && bookmark.id) || '';
$scope.url = (bookmark && bookmark.url) || '';
$scope.title = (bookmark && bookmark.title) || '';
$scope.description = (bookmark && bookmark.description) || '';
$scope.tags = data.tags.map((tag) => {
tag.clicked = false;
return tag;
});
$scope.public = (bookmark && bookmark.id) || '1';
$('.ui.checkbox.js-public').checkbox((bookmark && bookmark.public && bookmark.public == '1') ? 'set checked' : 'set unchecked')
$timeout(function () { $scope.id = (bookmark && bookmark.id) || '';
data.bookmarkTags.forEach((tagId) => { $scope.url = (bookmark && bookmark.url) || '';
$scope.tags.forEach((tag) => { $scope.title = (bookmark && bookmark.title) || '';
if (tag.id == tagId) { $scope.description = (bookmark && bookmark.description) || '';
tag.clicked = true; $scope.tags = tags.map((tag) => {
} tag.clicked = bookmark.tagId == tag.id;
}) return tag;
}); });
}); $scope.public = (bookmark && bookmark.id) || '1';
$scope.loadTags = false; $('.ui.checkbox.js-public').checkbox((bookmark && bookmark.public && bookmark.public == '1') ? 'set checked' : 'set unchecked')
}) $scope.loadTags = false;
.catch((err) => console.log('updateBookmark err', err));
}); });
pubSubService.subscribe('TagCtr.storeBookmark', $scope, function (event, bookmark) { pubSubService.subscribe('TagCtr.storeBookmark', $scope, function (event, bookmark) {

View File

@ -26,12 +26,12 @@ app.controller('menuCtr', ['$scope', '$stateParams', '$state', '$window', '$time
$scope.loginMenus = dataService.loginMenus; // 登陆之后显示的菜单数据。uiSerf内部跳转链接。 $scope.loginMenus = dataService.loginMenus; // 登陆之后显示的菜单数据。uiSerf内部跳转链接。
$scope.notLoginMenus = dataService.notLoginMenus; // 未登陆显示的菜单数据 $scope.notLoginMenus = dataService.notLoginMenus; // 未登陆显示的菜单数据
(async () => { get('own').then(user => {
$scope.user = await get('own'); $scope.user = user;
if (data.username === 'lcq') { if ($scope.user.username === 'lcq') {
$scope.loginMenus[dataService.LoginIndexHot].show = false; $scope.loginMenus[dataService.LoginIndexHot].show = false;
} }
})(); });
$scope.toggleReady = function (ready) { $scope.toggleReady = function (ready) {
if (ready) { if (ready) {

View File

@ -26,20 +26,14 @@ app.controller('noteCtr', ['$scope', '$state', '$stateParams', '$filter', '$wind
var timeagoInstance = timeago(); var timeagoInstance = timeago();
bookmarkService.autoLogin() get('own').then(user => {
.then((data) => { pubSubService.publish('Common.menuActive', {
var login = data.logined; login: true,
var index = login ? dataService.LoginIndexNote : dataService.NotLoginIndexLogin; index: dataService.LoginIndexNote
pubSubService.publish('Common.menuActive', {
login: login,
index: index
});
getTags();
getNotes();
})
.catch((err) => {
dataService.netErrorHandle(err, $state)
}); });
getTags();
getNotes();
});
$scope.changeCurrentPage = function (currentPage) { $scope.changeCurrentPage = function (currentPage) {
currentPage = parseInt(currentPage) || 0; currentPage = parseInt(currentPage) || 0;
@ -85,7 +79,7 @@ app.controller('noteCtr', ['$scope', '$state', '$stateParams', '$filter', '$wind
} }
} }
$scope.addNote = function (close) { $scope.addNote = async function (close) {
if ($scope.content == '') { if ($scope.content == '') {
toastr.error('不允许备忘录内容为空!', "提示"); toastr.error('不允许备忘录内容为空!', "提示");
return; return;
@ -100,7 +94,7 @@ app.controller('noteCtr', ['$scope', '$state', '$stateParams', '$filter', '$wind
$scope.tags.forEach((tag) => { $scope.tags.forEach((tag) => {
if ($scope.currentTagId === tag.id) { if ($scope.currentTagId === tag.id) {
tagName = tag.name; tagName = tag.name;
tag.ncnt += 1; tag.noteCount += 1;
} }
if (!$scope.currentTagId) { if (!$scope.currentTagId) {
if (tag.name == '未分类') { if (tag.name == '未分类') {
@ -111,27 +105,22 @@ app.controller('noteCtr', ['$scope', '$state', '$stateParams', '$filter', '$wind
}) })
var note = { var note = {
tag_id: $scope.currentTagId, tagId: $scope.currentTagId,
content: $scope.content, content: $scope.content,
} }
bookmarkService.addNote(note) await post("addNote", note);
.then((data) => {
// 增加成功,重新获取一次备忘录 // 增加成功,重新获取一次备忘录
$scope.tags.forEach((tag) => { $scope.tags.forEach((tag) => {
tag.clicked = false; tag.clicked = false;
}) })
$scope.preContent = $scope.content; $scope.preContent = $scope.content;
$scope.content = ''; $scope.content = '';
$scope.currentTagId = null; $scope.currentTagId = null;
$scope.currentPage = 1; $scope.currentPage = 1;
$scope.searchWord = ''; $scope.searchWord = '';
getNotes(); getNotes();
})
.catch((err) => {
console.log('addNote err', err);
$scope.currentTagId = null;
});
} }
$scope.copy = function (content, $event) { $scope.copy = function (content, $event) {
@ -151,31 +140,21 @@ app.controller('noteCtr', ['$scope', '$state', '$stateParams', '$filter', '$wind
}); });
} }
$scope.confirmDelNote = function () { $scope.confirmDelNote = async function () {
if ($scope.currentNoteId) { if ($scope.currentNoteId) {
var params = { var params = {
id: $scope.currentNoteId id: $scope.currentNoteId
} }
ngDialog.close(dialog); ngDialog.close(dialog);
bookmarkService.delNote(params) await post('delNote', params)
.then((data) => { $("#" + $scope.currentNoteId).transition({
if (data.result == 1) { animation: dataService.animation(),
$("#" + $scope.currentNoteId).transition({ duration: 500,
animation: dataService.animation(), onComplete: function () {
duration: 500, $("#" + $scope.currentNoteId).remove();
onComplete: function () { }
$("#" + $scope.currentNoteId).remove(); });
} $scope.totalItems -= 1;
});
toastr.success('备忘删除成功!', "提示");
$scope.totalItems -= 1;
} else {
toastr.error('没有找到对应的备忘录,删除失败!请刷新页面再尝试', "提示");
}
})
.catch((err) => {
toastr.error('备忘删除失败!错误提示:' + JSON.stringify(err), "提示");
});
} else { } else {
toastr.error('删除失败!请刷新页面再尝试', "提示"); toastr.error('删除失败!请刷新页面再尝试', "提示");
} }
@ -190,7 +169,7 @@ app.controller('noteCtr', ['$scope', '$state', '$stateParams', '$filter', '$wind
updateSelectTag(tagId); updateSelectTag(tagId);
} }
$scope.updateNote = function () { $scope.updateNote = async function () {
if (!$scope.content) { if (!$scope.content) {
toastr.error('更新失败,更新内容不能为空', "提示"); toastr.error('更新失败,更新内容不能为空', "提示");
return; return;
@ -211,30 +190,20 @@ app.controller('noteCtr', ['$scope', '$state', '$stateParams', '$filter', '$wind
var params = { var params = {
id: $scope.currentNoteId, id: $scope.currentNoteId,
content: $scope.content, content: $scope.content,
tag_id: $scope.currentTagId, tagId: $scope.currentTagId,
} }
bookmarkService.updateNote(params) await post("updateNote", params);
.then((data) => { $scope.notes.forEach((note) => {
if (data.result == 1) { if (note.id == $scope.currentNoteId) {
toastr.success('备忘更新成功!', "提示"); note.content = $scope.content;
$scope.notes.forEach((note) => { note.tagName = tagName;
if (note.id == $scope.currentNoteId) { note.tag_id = $scope.currentTagId;
note.content = $scope.content; toPos(note.id);
note.tagName = tagName; }
note.tag_id = $scope.currentTagId; })
toPos(note.id); $scope.add = false;
} $scope.edit = false;
})
$scope.add = false;
$scope.edit = false;
} else {
toastr.error('备忘更新失败!请刷新页面再尝试', "提示");
}
})
.catch((err) => {
toastr.error('备忘更新失败!错误提示:' + JSON.stringify(err), "提示");
});
} }
$scope.detailNote = function (content) { $scope.detailNote = function (content) {
@ -301,28 +270,16 @@ app.controller('noteCtr', ['$scope', '$state', '$stateParams', '$filter', '$wind
dataService.clipboard(`https://mybookmark.cn/api/notes/?shareNote=${note.id}`); dataService.clipboard(`https://mybookmark.cn/api/notes/?shareNote=${note.id}`);
toastr.info(`将地址 https://mybookmark.cn/api/notes/?shareNote=${note.id} 发给别人粘贴到浏览器地址栏就可以访问到你分享的备忘啦!`, "提示"); toastr.info(`将地址 https://mybookmark.cn/api/notes/?shareNote=${note.id} 发给别人粘贴到浏览器地址栏就可以访问到你分享的备忘啦!`, "提示");
}, time) }, time)
} }
$scope.updatePublic = function (note, public) { $scope.updatePublic = async function (note, public) {
var params = { var params = {
id: note.id, id: note.id,
public: public, public: public,
} }
bookmarkService.updateNotePublic(params) await post("updateNode", params);
.then((data) => { note.public = public;
if (data.result == 1) {
public == 1 && toastr.success('备忘已由私密状态转为公开状态', "提示");
public == 0 && toastr.success('备忘已由公开状态转为私密状态', "提示");
note.public = public;
} else {
toastr.error('备忘状态更新失败', "提示");
}
})
.catch((err) => {
toastr.error('备忘更新失败!错误提示:' + JSON.stringify(err), "提示");
});
} }
function updateSelectTag(tagId) { function updateSelectTag(tagId) {
@ -353,73 +310,62 @@ app.controller('noteCtr', ['$scope', '$state', '$stateParams', '$filter', '$wind
}) })
}); });
function getNotes(tagId) { async function getNotes(tagId) {
$scope.notes = []; $scope.notes = [];
$scope.loadBusy = true; $scope.loadBusy = true;
var params = { var params = {
currentPage: $scope.currentPage, page: $scope.currentPage,
perPageItems: perPageItems, pageSize: perPageItems,
searchWord: $scope.searchWord, searchWord: $scope.searchWord,
tagId: tagId || $scope.currentTagId
}; };
if (tagId || $scope.currentTagId) {
params.tagId = tagId || $scope.currentTagId; try {
} let reply = await get("notes", params);
bookmarkService.getNotes(params) $scope.notes = reply.data;
.then((data) => { $scope.notes.forEach((note) => {
$scope.notes = data.notes; note.brief = note.content || "";
$scope.notes.forEach((note) => { while (note.brief.indexOf("\n") > 0) {
note.brief = note.content || ""; note.brief = note.brief.replace(/\n/g, "");
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.totalPages = Math.ceil(data.totalItems / perPageItems);
$scope.totalItems = data.totalItems;
$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;
if ($scope.totalItems == 0) {
$(".js-note").removeClass("hidden");
} }
transition(); note.brief = " " + note.brief.substring(0, 200) + (note.content.length > 200 ? " ......" : "");
}) })
.catch((err) => { $scope.totalPages = reply.totalPages;
$scope.notes = []; $scope.totalItems = reply.count;
$scope.loadBusy = false; $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;
if ($scope.totalItems == 0) {
$(".js-note").removeClass("hidden");
}
transition();
} catch (error) {
$scope.notes = [];
$scope.loadBusy = false;
}
} }
function getTags(params) { async function getTags() {
$scope.loadBusy = true; $scope.loadBusy = true;
bookmarkService.getTags(params) $scope.tags = []
.then((data) => {
$scope.tags = []
var find = false;
data.forEach((tag) => {
$scope.tags.push(tag);
if (tag.id == $scope.currentTagId) {
find = true; // 如果是删了分类返回来,那么要重新默认选中第一个分类
}
})
if (!find) $scope.currentTagId = null;
if ($scope.currentTagId) { let tags = await get('tags', { noteCount: true });
getTags($scope.currentTagId); let find = false;
} tags.forEach((tag) => {
$scope.loadBusy = false; $scope.tags.push(tag);
}) if (tag.id == $scope.currentTagId) {
.catch((err) => { find = true; // 如果是删了分类返回来,那么要重新默认选中第一个分类
console.log('getTags err', err); }
$scope.loadBusy = false; })
}); if (!find) $scope.currentTagId = null;
$scope.loadBusy = false;
} }
$('.js-note-card').transition('hide'); $('.js-note-card').transition('hide');

View File

@ -62,12 +62,11 @@ app.controller('searchCtr', ['$scope', '$state', '$stateParams', '$filter', '$wi
toastr.warning("请输入搜索关键字再进行查询!", "提示"); toastr.warning("请输入搜索关键字再进行查询!", "提示");
} }
$scope.jumpToUrl = function (url, id) { $scope.jumpToUrl = async function (url, id) {
if (!$scope.edit) { if (!$scope.edit) {
$window.open(url); $window.open(url);
bookmarkService.clickBookmark({ await post("clickBookmark", { id });
id: id
});
$scope.searchBookmarks.forEach(function (bookmark) { $scope.searchBookmarks.forEach(function (bookmark) {
if (bookmark.id == id && bookmark.own) { if (bookmark.id == id && bookmark.own) {
bookmark.click_count += 1; bookmark.click_count += 1;
@ -111,10 +110,8 @@ app.controller('searchCtr', ['$scope', '$state', '$stateParams', '$filter', '$wi
}); });
} }
$scope.editBookmark = function (bookmarkId) { $scope.editBookmark = function (id) {
pubSubService.publish('bookmarksCtr.editBookmark', { pubSubService.publish('bookmarksCtr.editBookmark', { id });
'bookmarkId': bookmarkId
});
} }
$scope.detailBookmark = function (bookmark) { $scope.detailBookmark = function (bookmark) {

View File

@ -91,12 +91,11 @@ app.controller('tagsCtr', ['$scope', '$filter', '$state', '$window', '$statePara
} }
} }
$scope.jumpToUrl = function (url, id) { $scope.jumpToUrl = async function (url, id) {
if (!$scope.editMode) { if (!$scope.editMode) {
$window.open(url, '_blank'); $window.open(url, '_blank');
bookmarkService.clickBookmark({ await post("clickBookmark", { id });
id: id
});
$scope.bookmarks.forEach(function (bookmark, index) { $scope.bookmarks.forEach(function (bookmark, index) {
if (bookmark.id == id) { if (bookmark.id == id) {
bookmark.click_count += 1; bookmark.click_count += 1;
@ -149,18 +148,15 @@ app.controller('tagsCtr', ['$scope', '$filter', '$state', '$window', '$statePara
}); });
} }
$scope.editBookmark = function (bookmarkId) { $scope.editBookmark = function (id) {
pubSubService.publish('bookmarksCtr.editBookmark', { console.log('publish bookmarksCtr.editBookmark', { id });
'bookmarkId': bookmarkId pubSubService.publish('bookmarksCtr.editBookmark', { id });
});
} }
$scope.detailBookmark = function (bookmark) { $scope.detailBookmark = async function (bookmark) {
bookmark.own = true; bookmark.own = true;
pubSubService.publish('TagCtr.showBookmarkInfo', bookmark); pubSubService.publish('TagCtr.showBookmarkInfo', bookmark);
bookmarkService.clickBookmark({ await post("clickBookmark", { id: bookmark.id });
id: bookmark.id
});
} }
$scope.copy = function (url) { $scope.copy = function (url) {

View File

@ -22,12 +22,12 @@
</div> </div>
<div class="column"> <div class="column">
<i class="calendar icon"></i>最后点击: <i class="calendar icon"></i>最后点击:
<span>{{bookmark.last_click}}</span> <span>{{bookmark.lastClick}}</span>
</div> </div>
</div> </div>
<div class="two column row"> <div class="two column row">
<div class="column" ng-if="bookmark.click_count"> <div class="column" ng-if="bookmark.clickCount">
<i class="hand pointer icon"></i>点击次数:{{bookmark.click_count}} <i class="hand pointer icon"></i>点击次数:{{bookmark.clickCount}}
</div> </div>
<div class="column" ng-if="bookmark.fav_count"> <div class="column" ng-if="bookmark.fav_count">
<i class="heart icon"></i>收藏人数:{{bookmark.fav_count}} <i class="heart icon"></i>收藏人数:{{bookmark.fav_count}}

View File

@ -1,6 +1,6 @@
<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;">
<div class="ui container" style="padding-left:14px"> <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.ncnt || add">{{ tag.name }} ({{ tag.ncnt || 0 }})</div> <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(不区分大小写)增加备忘录。"> <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> <i class="plus icon" style="margin-right:0px;"></i>
</div> </div>