完成分类页面部分书签逻辑
This commit is contained in:
parent
5bdfbd0da7
commit
86d5ff15ba
|
|
@ -10,6 +10,8 @@
|
|||
"lint-fix": "eslint --fix src/"
|
||||
},
|
||||
"dependencies": {
|
||||
"cheerio": "^1.0.0-rc.3",
|
||||
"fs-extra": "^9.0.0",
|
||||
"think-cache": "^1.0.0",
|
||||
"think-cache-file": "^1.0.8",
|
||||
"think-logger3": "^1.0.0",
|
||||
|
|
|
|||
67
schema.sql
67
schema.sql
|
|
@ -6,56 +6,57 @@ CREATE TABLE `users` (
|
|||
`password` varchar(255) NOT NULL, -- 密码
|
||||
`email` varchar(255) NOT NULL, -- 邮箱
|
||||
`created_at` datetime DEFAULT now(), -- 创建时间
|
||||
`last_login` datetime DEFAULT NULL, -- 最后一次登录时间
|
||||
`search_history` varchar(512) DEFAULT NULL, -- 历史搜索记录
|
||||
`lastLogin` datetime DEFAULT NULL, -- 最后一次登录时间
|
||||
`searchHistory` varchar(512) DEFAULT NULL, -- 历史搜索记录
|
||||
`avatar` varchar(512) DEFAULT NULL, -- 头像地址
|
||||
`quick_url` varchar(2048) DEFAULT '{\"B\":\"https://www.baidu.com/\",\"G\":\"https://www.google.com.hk/\",\"V\":\"https://www.v2ex.com/\",\"L\":\"http://luchenqun.com/\",\"H\":\"https://github.com/\",\"Q\":\"http://www.iqiyi.com/\",\"J\":\"https://www.jd.com/\"}', -- 全局快捷地址
|
||||
`quickUrl` varchar(2048) DEFAULT '{\"B\":\"https://www.baidu.com/\",\"G\":\"https://www.google.com.hk/\",\"V\":\"https://www.v2ex.com/\",\"L\":\"http://luchenqun.com/\",\"H\":\"https://github.com/\",\"Q\":\"http://www.iqiyi.com/\",\"J\":\"https://www.jd.com/\"}', -- 全局快捷地址
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `username` (`username`),
|
||||
UNIQUE KEY `email` (`email`)
|
||||
);
|
||||
INSERT INTO `mybookmarks`.`users` (`id`, `username`, `password`, `email`, `created_at`, `lastLogin`, `searchHistory`, `avatar`, `quickUrl`) VALUES ('1', 'lcq', 'e10adc3949ba59abbe56e057f20f883e', 'lcq@qq.com', '2020-03-25 21:19:16', NULL, NULL, NULL, '{\"B\":\"https://www.baidu.com/\",\"G\":\"https://www.google.com.hk/\",\"V\":\"https://www.v2ex.com/\",\"L\":\"http://luchenqun.com/\",\"H\":\"https://github.com/\",\"Q\":\"http://www.iqiyi.com/\",\"J\":\"https://www.jd.com/\"}');
|
||||
|
||||
-- 书签表
|
||||
drop table if exists bookmarks;
|
||||
CREATE TABLE `bookmarks` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT, -- id
|
||||
`user_id` int(11) NOT NULL, -- 用户id
|
||||
`tag_id` int(11) NOT NULL, -- 分类id (只允许一个书签对应一个分类)
|
||||
`title` varchar(255) NOT NULL, -- 标题
|
||||
`description` varchar(4096) DEFAULT NULL, -- 描述
|
||||
`url` varchar(1024) NOT NULL, -- 链接
|
||||
`public` tinyint(4) DEFAULT '0', -- 是否公开 1 公开,0 不公开
|
||||
`click_count` smallint DEFAULT 1, -- 总共点击次数
|
||||
`created_at` datetime DEFAULT now(), -- 创建时间
|
||||
`last_click` datetime DEFAULT now(), -- 最后一次点击时间
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT, -- id
|
||||
`userId` int(11) NOT NULL, -- 用户id
|
||||
`tagId` int(11) NOT NULL, -- 分类id (只允许一个书签对应一个分类)
|
||||
`title` varchar(255) NOT NULL, -- 标题
|
||||
`description` varchar(4096) DEFAULT NULL,-- 描述
|
||||
`url` varchar(1024) NOT NULL, -- 链接
|
||||
`public` tinyint(4) DEFAULT '0', -- 是否公开 1 公开,0 不公开
|
||||
`clickCount` smallint DEFAULT 1, -- 总共点击次数
|
||||
`createdAt` datetime DEFAULT now(), -- 创建时间
|
||||
`lastClick` datetime DEFAULT now(), -- 最后一次点击时间
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `userIdIdx` (`user_id`)
|
||||
KEY `userIdIdx` (`userId`)
|
||||
);
|
||||
|
||||
-- 书签分类表
|
||||
drop table if exists tags;
|
||||
CREATE TABLE `tags` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT, -- id
|
||||
`user_id` int(11) NOT NULL, -- 用户id
|
||||
`name` varchar(32) NOT NULL, -- 标签
|
||||
`last_use` datetime DEFAULT now(), -- 最后使用标签的时间
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT, -- id
|
||||
`userId` int(11) NOT NULL, -- 用户id
|
||||
`name` varchar(32) NOT NULL, -- 标签
|
||||
`lastUse` datetime DEFAULT now(), -- 最后使用标签的时间
|
||||
`sort` tinyint(8) DEFAULT 0, -- 书签排序
|
||||
`show` tinyint(8) DEFAULT 1, -- 书签是否显示
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `userIdIdx` (`user_id`),
|
||||
UNIQUE KEY `tag` (`user_id`,`name`)
|
||||
KEY `userIdIdx` (`userId`),
|
||||
UNIQUE KEY `tag` (`userId`,`name`)
|
||||
);
|
||||
|
||||
-- 建议留言
|
||||
drop table if exists advices;
|
||||
CREATE TABLE `advices` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT, -- id
|
||||
`user_id` int(11) NOT NULL, -- 用户id
|
||||
`comment` text NOT NULL, -- 评论
|
||||
`created_at` datetime DEFAULT now(), -- 创建时间
|
||||
`state` tinyint(4) DEFAULT '0', -- 处理结果
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT, -- id
|
||||
`userId` int(11) NOT NULL, -- 用户id
|
||||
`comment` text NOT NULL, -- 评论
|
||||
`createdAt` datetime DEFAULT now(), -- 创建时间
|
||||
`state` tinyint(4) DEFAULT '0', -- 处理结果
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `userIdIdx` (`user_id`)
|
||||
KEY `userIdIdx` (`userId`)
|
||||
);
|
||||
|
||||
-- 热门表
|
||||
|
|
@ -66,12 +67,12 @@ CREATE TABLE `hot_bookmarks` (
|
|||
`title` varchar(255) DEFAULT NULL, -- 标题(title)
|
||||
`description` varchar(4096) DEFAULT NULL, -- 描述(自己添加)
|
||||
`url` varchar(1024) DEFAULT NULL, -- 链接(url)
|
||||
`fav_count` smallint DEFAULT 1, -- 总共收藏人数(favCount)
|
||||
`favCount` smallint DEFAULT 1, -- 总共收藏人数(favCount)
|
||||
`created_by` varchar(64) DEFAULT NULL, -- 创建者(sourceName)
|
||||
`created_at` bigint DEFAULT 0, -- 创建时间(updatetime)
|
||||
`last_click` bigint DEFAULT 0, -- 最后一次点击时间(createtime)
|
||||
`snap_url` varchar(1024) DEFAULT NULL, -- 截图链接(imageList[0])
|
||||
`favicon_url` varchar(1024) DEFAULT NULL, -- icon链接(sourceLogo)
|
||||
`lastClick` bigint DEFAULT 0, -- 最后一次点击时间(createtime)
|
||||
`snapUrl` varchar(1024) DEFAULT NULL, -- 截图链接(imageList[0])
|
||||
`faviconUrl` varchar(1024) DEFAULT NULL, -- icon链接(sourceLogo)
|
||||
`status` tinyint(4) DEFAULT '0', -- 状态
|
||||
PRIMARY KEY (`id`)
|
||||
);
|
||||
|
|
@ -80,10 +81,10 @@ CREATE TABLE `hot_bookmarks` (
|
|||
drop table if exists notes;
|
||||
CREATE TABLE `notes` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT, -- id
|
||||
`user_id` int(11) NOT NULL, -- 用户id
|
||||
`userId` int(11) NOT NULL, -- 用户id
|
||||
`content` text NOT NULL, -- 备忘内容
|
||||
`tag_id` int(11) NOT NULL, -- 分类id
|
||||
`created_at` datetime DEFAULT now(), -- 创建时间
|
||||
`tagId` int(11) NOT NULL, -- 分类id
|
||||
`createdAt` datetime DEFAULT now(), -- 创建时间
|
||||
`public` tinyint(4) DEFAULT '0', -- 是否公开 1 公开,0 不公开
|
||||
PRIMARY KEY (`id`)
|
||||
);
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ exports.model = {
|
|||
port: '3306',
|
||||
user: 'test',
|
||||
password: '123456',
|
||||
pageSize: 50,
|
||||
dateStrings: true
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
const Base = require('./base.js');
|
||||
const crypto = require('crypto');
|
||||
const fs = require('fs-extra');
|
||||
|
||||
function md5(str) {
|
||||
return crypto.createHash('md5').update(str).digest('hex');
|
||||
|
|
@ -77,14 +78,14 @@ module.exports = class extends Base {
|
|||
// 获取分类信息
|
||||
async tagsAction() {
|
||||
let param = this.get();
|
||||
let tags = await this.model('tags').where({ user_id: this.ctx.state.user.id }).order('sort ASC, last_use DESC').select();
|
||||
let tags = await this.model('tags').where({ userId: this.ctx.state.user.id }).order('sort ASC, lastUse DESC').select();
|
||||
// 这个分类包含的书签与备忘录的个数
|
||||
for (let tag of tags) {
|
||||
if (param.bookmarkCount) {
|
||||
tag.bookmarkCount = await this.model('bookmarks').where({ tag_id: tag.id }).count();
|
||||
tag.bookmarkCount = await this.model('bookmarks').where({ tagId: tag.id }).count();
|
||||
}
|
||||
if (param.notes) {
|
||||
tag.bookmarkCount = await this.model('notes').where({ tag_id: tag.id }).count();
|
||||
tag.bookmarkCount = await this.model('notes').where({ tagId: tag.id }).count();
|
||||
}
|
||||
}
|
||||
this.json({ code: 0, data: tags, msg: '' });
|
||||
|
|
@ -94,7 +95,7 @@ module.exports = class extends Base {
|
|||
let name = this.post().name;
|
||||
try {
|
||||
let res = await this.model("tags").add({
|
||||
user_id: this.ctx.state.user.id,
|
||||
userId: this.ctx.state.user.id,
|
||||
name
|
||||
});
|
||||
this.json({ code: 0, data: res, msg: `分类 ${name} 添加成功` });
|
||||
|
|
@ -105,7 +106,7 @@ module.exports = class extends Base {
|
|||
|
||||
async addBookmarkAction() {
|
||||
let bookmark = this.post();
|
||||
bookmark.user_id = this.ctx.state.user.id;
|
||||
bookmark.userId = this.ctx.state.user.id;
|
||||
try {
|
||||
let res = await this.model("bookmarks").add(bookmark);
|
||||
this.json({ code: 0, data: res, msg: `书签 ${bookmark.title} 添加成功` });
|
||||
|
|
@ -114,4 +115,36 @@ module.exports = class extends Base {
|
|||
}
|
||||
}
|
||||
|
||||
// 根据书签id获取书签
|
||||
async getBookmarksByTagAction() {
|
||||
let tagId = this.get("tagId");
|
||||
// tagId = -1 个人定制 从自己里面取
|
||||
// tagId = -2 全局定制 从非个人里面取
|
||||
let where = {};
|
||||
let order = 'createdAt DESC';
|
||||
|
||||
if (tagId == -1) {
|
||||
where = { userId: this.ctx.state.user.id };
|
||||
} else if (tagId == -2) {
|
||||
where = { userId: ['!=', this.ctx.state.user.id] };
|
||||
} else {
|
||||
where = { tagId };
|
||||
}
|
||||
|
||||
if (this.get('createdAt')) {
|
||||
order = 'createdAt DESC';
|
||||
} else if (this.get('clickCount')) {
|
||||
order = 'clickCount DESC';
|
||||
} else if (this.get('lastClick')) {
|
||||
order = 'lastClick DESC';
|
||||
}
|
||||
|
||||
try {
|
||||
let data = await this.model('bookmarks').where(where).order(order).page(this.get('page'), this.get('pageSize')).countSelect();
|
||||
this.json({ code: 0, data });
|
||||
} catch (error) {
|
||||
this.json({ code: 1, msg: error.toString() });
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
|||
|
|
@ -60,22 +60,21 @@ app.controller('editCtr', ['$scope', '$state', '$timeout', '$document', 'ngDialo
|
|||
init();
|
||||
}
|
||||
$scope.ok = async function () {
|
||||
var tag_id = -1;
|
||||
var selectedTags = [];
|
||||
var tagId = -1;
|
||||
$scope.tags.forEach((tag) => {
|
||||
if (tag.clicked) {
|
||||
tag_id = tag.id;
|
||||
tagId = tag.id;
|
||||
}
|
||||
});
|
||||
// console.log('Hello ok clicked', $scope.url, $scope.title, $scope.description, $scope.public, selectedTags, $scope.tags);
|
||||
$scope.urlError = $scope.url == '';
|
||||
$scope.titleError = $scope.title == '';
|
||||
$scope.tagsError = tag_id == -1;
|
||||
$scope.tagsError = tagId == -1;
|
||||
|
||||
var params = {
|
||||
id: $scope.id,
|
||||
url: $scope.url,
|
||||
tag_id,
|
||||
tagId,
|
||||
title: $scope.title,
|
||||
description: $scope.description,
|
||||
public: $('.ui.checkbox.js-public').checkbox('is checked') ? '1' : '0',
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ app.controller('tagsCtr', ['$scope', '$filter', '$state', '$window', '$statePara
|
|||
|
||||
// getTags({});
|
||||
|
||||
var perPageItems = 20;
|
||||
var pageSize = 20;
|
||||
var dialog = null;
|
||||
var forbidTransition = false;
|
||||
var addBookmarkId = -1;
|
||||
|
|
@ -93,18 +93,18 @@ app.controller('tagsCtr', ['$scope', '$filter', '$state', '$window', '$statePara
|
|||
}, 100)
|
||||
}
|
||||
|
||||
$scope.getBookmarks = function (tagId, currentPage) {
|
||||
console.log(tagId, currentPage)
|
||||
$scope.getBookmarks = async function (tagId, page) {
|
||||
console.log(tagId, page)
|
||||
$scope.bookmarkClicked = true;
|
||||
$scope.currentTagId = tagId;
|
||||
$scope.currentPage = currentPage;
|
||||
$scope.currentPage = page;
|
||||
if (!forbidTransition) {
|
||||
$scope.loadBookmarks = true;
|
||||
}
|
||||
$scope.costomTag.bookmarkClicked = false;
|
||||
$scope.costomAllUsersTag.bookmarkClicked = false;
|
||||
|
||||
perPageItems = ($scope.showMode == 'item') ? 50 : 20;
|
||||
pageSize = ($scope.showMode == 'item') ? 50 : 20;
|
||||
|
||||
$scope.tags.forEach(function (tag) {
|
||||
tag.bookmarkClicked = false;
|
||||
|
|
@ -122,19 +122,25 @@ app.controller('tagsCtr', ['$scope', '$filter', '$state', '$window', '$statePara
|
|||
}
|
||||
|
||||
var params = {
|
||||
tagId: tagId,
|
||||
currentPage: currentPage,
|
||||
perPageItems: perPageItems,
|
||||
tagId,
|
||||
page,
|
||||
pageSize,
|
||||
createdAt: true
|
||||
};
|
||||
if (!forbidTransition) {
|
||||
$($scope.showMode == 'item' ? '.js-tag-costomTag' : '.js-tags-table').transition('hide');
|
||||
}
|
||||
|
||||
let data = await get('getBookmarksByTag', params);
|
||||
console.log(data);
|
||||
return;
|
||||
|
||||
bookmarkService.getBookmarksByTag(params)
|
||||
.then((data) => {
|
||||
$scope.bookmarkData = data;
|
||||
$scope.changeOrder($scope.order.indexOf(true));
|
||||
$scope.bookmarkCount = $scope.bookmarkData.totalItems;
|
||||
$scope.totalPages = tagId <= -1 ? 1 : Math.ceil($scope.bookmarkCount / perPageItems);
|
||||
$scope.totalPages = tagId <= -1 ? 1 : Math.ceil($scope.bookmarkCount / pageSize);
|
||||
|
||||
$scope.inputPage = '';
|
||||
$scope.loadBookmarks = false;
|
||||
|
|
@ -490,8 +496,10 @@ app.controller('tagsCtr', ['$scope', '$filter', '$state', '$window', '$statePara
|
|||
})
|
||||
});
|
||||
|
||||
async function getTags(params) {
|
||||
async function getTags() {
|
||||
$scope.loadTags = true;
|
||||
$scope.tags = [];
|
||||
|
||||
let tags = await get('tags', { bookmarkCount: true });
|
||||
let find = false;
|
||||
for (let tag of tags) {
|
||||
|
|
@ -510,8 +518,7 @@ app.controller('tagsCtr', ['$scope', '$filter', '$state', '$window', '$statePara
|
|||
|
||||
if ($scope.currentTagId) {
|
||||
if (!$scope.editMode) {
|
||||
// @todo
|
||||
// $scope.getBookmarks($scope.currentTagId, $scope.currentPage);
|
||||
await $scope.getBookmarks($scope.currentTagId, $scope.currentPage);
|
||||
}
|
||||
} else {
|
||||
toastr.info('您还没有书签分类,请点击菜单栏的添加按钮进行添加', "提示");
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
<div class="ui segment js-tags">
|
||||
<div class="ui container" ng-show="!editMode" style="cursor:default">
|
||||
<div class="ui label" style="margin:3px 15px 8px 0px;cursor:default;" ng-class="{green:costomTag.bookmarkClicked}" ng-click="getBookmarks(-1, 1)">
|
||||
{{ costomTag.name }} ({{ costomTag.cnt || 0 }})
|
||||
{{ costomTag.name }} ({{ costomTag.bookmarkCount || 0 }})
|
||||
</div>
|
||||
<div class="ui label" style="margin:3px 15px 8px 0px;cursor:default;" ng-if="tag.cnt && tag.show" ng-repeat="tag in tags" ng-class="{green:tag.bookmarkClicked}" ng-click="getBookmarks(tag.id, 1)">
|
||||
{{ tag.name }} ({{ tag.cnt || 0 }})
|
||||
<div class="ui label" style="margin:3px 15px 8px 0px;cursor:default;" ng-if="tag.bookmarkCount && tag.show" ng-repeat="tag in tags" ng-class="{green:tag.bookmarkClicked}" ng-click="getBookmarks(tag.id, 1)">
|
||||
{{ tag.name }} ({{ tag.bookmarkCount || 0 }})
|
||||
</div>
|
||||
<div class="ui label" style="margin:3px 15px 8px 0px;cursor:default;" ng-class="{green:costomAllUsersTag.bookmarkClicked}" ng-click="getBookmarks(-2, 1)">
|
||||
{{ costomAllUsersTag.name }} ({{ costomAllUsersTag.cnt || 0 }})
|
||||
{{ costomAllUsersTag.name }} ({{ costomAllUsersTag.bookmarkCount || 0 }})
|
||||
</div>
|
||||
<div class="ui label js-tag-label" style="margin:3px 15px 8px 0px;cursor:default;">
|
||||
<i class="plus icon" data-content="点击添加分类" data-position="top center" ng-click="showAddTag()"></i>
|
||||
|
|
@ -40,7 +40,7 @@
|
|||
</div>
|
||||
<div class="content" style="cursor: move" sv-handle>
|
||||
<div class="description">
|
||||
<p>书签:{{ tag.cnt || 0 }}个</p>
|
||||
<p>书签:{{ tag.bookmarkCount || 0 }}个</p>
|
||||
<p>{{ tag.last_use }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Reference in New Issue