个人定制第一页最近新增最后点击最多点击按照2:2:1的比例分配显示
This commit is contained in:
parent
e3647ac4d4
commit
6e4fa07ee1
|
|
@ -248,19 +248,58 @@ module.exports = class extends Base {
|
||||||
let tagId = this.get("tagId");
|
let tagId = this.get("tagId");
|
||||||
let showType = this.get("showType") || "createdAt";
|
let showType = this.get("showType") || "createdAt";
|
||||||
// tagId = -1 个人定制 从自己里面取
|
// tagId = -1 个人定制 从自己里面取
|
||||||
let where = {};
|
let condition = {};
|
||||||
let order = showType + ' DESC';
|
let order = showType + ' DESC';
|
||||||
|
let page = this.get('page');
|
||||||
|
let pageSize = parseInt(this.get('pageSize') || 50);
|
||||||
|
|
||||||
if (tagId == -1) {
|
if (tagId == -1) {
|
||||||
where = { userId: this.ctx.state.user.id };
|
condition = { userId: this.ctx.state.user.id };
|
||||||
} else if (tagId == -2) {
|
|
||||||
where = { userId: ['!=', this.ctx.state.user.id] };
|
|
||||||
} else {
|
} else {
|
||||||
where = { tagId };
|
condition = { tagId };
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let data = await this.model('bookmarks').where(where).order(order).page(this.get('page'), this.get('pageSize')).countSelect();
|
// 如果是第0页而且是个人定制的,把 最近点击 与 最近新增 的返回去。
|
||||||
|
let data = {};
|
||||||
|
if (page == 0 && tagId == -1) {
|
||||||
|
let count = await this.model('bookmarks').where(condition).count('id');
|
||||||
|
let totalPages = Math.ceil(count / pageSize);
|
||||||
|
// 按照 2:2:1取数据
|
||||||
|
let length = Math.ceil(pageSize * 2 / 5);
|
||||||
|
let bookmarks = await this.model('bookmarks').where(condition).order('createdAt DESC').limit(0, length).select(); // 这个取一半
|
||||||
|
|
||||||
|
// 取最近点击部分数据
|
||||||
|
let cnt = 0;
|
||||||
|
let bookmarks2 = await this.model('bookmarks').where(condition).order('lastClick DESC').limit(0, pageSize * 2).select(); // 这个多取一点,有可能跟上面的重复了
|
||||||
|
for (const bookmark of bookmarks2) {
|
||||||
|
let find = bookmarks.find(item => item.id == bookmark.id);
|
||||||
|
if (!find) {
|
||||||
|
bookmarks.push(bookmark);
|
||||||
|
cnt++;
|
||||||
|
if (cnt >= length) break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 取点击次数最多部分
|
||||||
|
let bookmarks3 = await this.model('bookmarks').where(condition).order('clickCount DESC').limit(0, pageSize * 2).select(); // 这个多取一点,有可能跟上面的重复了
|
||||||
|
for (const bookmark of bookmarks3) {
|
||||||
|
let find = bookmarks.find(item => item.id == bookmark.id);
|
||||||
|
if (!find) {
|
||||||
|
bookmarks.push(bookmark);
|
||||||
|
if (bookmarks.length >= pageSize) break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data = {
|
||||||
|
count,
|
||||||
|
totalPages,
|
||||||
|
pageSize,
|
||||||
|
data: bookmarks
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
data = await this.model('bookmarks').where(condition).order(order).page(page, pageSize).countSelect();
|
||||||
|
}
|
||||||
this.json({ code: 0, data });
|
this.json({ code: 0, data });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.json({ code: 1, msg: error.toString() });
|
this.json({ code: 1, msg: error.toString() });
|
||||||
|
|
|
||||||
|
|
@ -51,9 +51,6 @@ app.config(function ($stateProvider, $urlRouterProvider, $httpProvider) {
|
||||||
.state('bookmarks', {
|
.state('bookmarks', {
|
||||||
url: '/bookmarks',
|
url: '/bookmarks',
|
||||||
templateUrl: 'views/bookmarks.html',
|
templateUrl: 'views/bookmarks.html',
|
||||||
params: {
|
|
||||||
showStyle: null,
|
|
||||||
},
|
|
||||||
controller: 'bookmarksCtr'
|
controller: 'bookmarksCtr'
|
||||||
})
|
})
|
||||||
.state('weixin-article', {
|
.state('weixin-article', {
|
||||||
|
|
@ -103,9 +100,6 @@ app.config(function ($stateProvider, $urlRouterProvider, $httpProvider) {
|
||||||
.state('login', {
|
.state('login', {
|
||||||
url: '/login',
|
url: '/login',
|
||||||
templateUrl: 'views/login.html',
|
templateUrl: 'views/login.html',
|
||||||
params: {
|
|
||||||
showStyle: 'table',
|
|
||||||
},
|
|
||||||
controller: 'loginCtr'
|
controller: 'loginCtr'
|
||||||
})
|
})
|
||||||
.state('/', {
|
.state('/', {
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ app.controller('menuCtr', ['$scope', '$stateParams', '$state', '$window', '$time
|
||||||
$scope.selectLoginIndex = 0; /**< 默认登陆之后的选择的菜单索引,下表从 0 开始 */
|
$scope.selectLoginIndex = 0; /**< 默认登陆之后的选择的菜单索引,下表从 0 开始 */
|
||||||
$scope.selectNotLoginIndex = 0; /**< 默认未登陆之后的选择的菜单索引,下表从 0 开始 */
|
$scope.selectNotLoginIndex = 0; /**< 默认未登陆之后的选择的菜单索引,下表从 0 开始 */
|
||||||
$scope.keyword = ''; /**< 搜索关键字 */
|
$scope.keyword = ''; /**< 搜索关键字 */
|
||||||
$scope.showStyle = null;
|
|
||||||
$scope.searchHistory = [];
|
$scope.searchHistory = [];
|
||||||
$scope.historyTypes = dataService.historyTypes;
|
$scope.historyTypes = dataService.historyTypes;
|
||||||
$scope.quickUrl = {};
|
$scope.quickUrl = {};
|
||||||
|
|
@ -168,17 +167,6 @@ app.controller('menuCtr', ['$scope', '$stateParams', '$state', '$window', '$time
|
||||||
}, 500)
|
}, 500)
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.updateShowStyle = function (showStyle) {
|
|
||||||
console.log('updateShowStyle', showStyle);
|
|
||||||
$scope.showStyle = showStyle;
|
|
||||||
$('.js-radio-' + showStyle).checkbox('set checked');
|
|
||||||
$state.go('bookmarks', {
|
|
||||||
showStyle: showStyle,
|
|
||||||
}, {
|
|
||||||
reload: true,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
$scope.showAddBookmarkMoadl = function () {
|
$scope.showAddBookmarkMoadl = function () {
|
||||||
pubSubService.publish('MenuCtr.showAddBookmarkMoadl', {
|
pubSubService.publish('MenuCtr.showAddBookmarkMoadl', {
|
||||||
'action': 'add'
|
'action': 'add'
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ app.controller('tagsCtr', ['$scope', '$filter', '$state', '$window', '$statePara
|
||||||
$scope.tagsIndex = []; // 书签索引
|
$scope.tagsIndex = []; // 书签索引
|
||||||
$scope.bookmarks = [];
|
$scope.bookmarks = [];
|
||||||
$scope.totalPages = 0;
|
$scope.totalPages = 0;
|
||||||
$scope.currentPage = 1;
|
$scope.currentPage = 0;
|
||||||
$scope.inputPage = '';
|
$scope.inputPage = '';
|
||||||
$scope.currentTagId = ($stateParams && $stateParams.tagId) || (-1);
|
$scope.currentTagId = ($stateParams && $stateParams.tagId) || (-1);
|
||||||
$scope.editMode = false;
|
$scope.editMode = false;
|
||||||
|
|
@ -40,7 +40,7 @@ app.controller('tagsCtr', ['$scope', '$filter', '$state', '$window', '$statePara
|
||||||
|
|
||||||
$scope.bookmarks = [];
|
$scope.bookmarks = [];
|
||||||
tagId && ($scope.currentTagId = tagId);
|
tagId && ($scope.currentTagId = tagId);
|
||||||
page && ($scope.currentPage = page);
|
Number.isInteger(page) && ($scope.currentPage = page);
|
||||||
showType && ($scope.showType = showType);
|
showType && ($scope.showType = showType);
|
||||||
$scope.loading = true;
|
$scope.loading = true;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,6 @@ app.factory('dataService', [function () {
|
||||||
return $(selector).length >= 1;
|
return $(selector).length >= 1;
|
||||||
},
|
},
|
||||||
historyTypes: ['书签', '谷歌', 'Github', '栈溢出', '百度', '备忘录'],
|
historyTypes: ['书签', '谷歌', 'Github', '栈溢出', '百度', '备忘录'],
|
||||||
showStyles: ['navigate', 'costomTag', 'card', 'table'],
|
|
||||||
forbidQuickKey: {
|
forbidQuickKey: {
|
||||||
'A': '在任意界面,已用做新增备忘录',
|
'A': '在任意界面,已用做新增备忘录',
|
||||||
'C': '在有关书签页面,用作复制书签链接',
|
'C': '在有关书签页面,用作复制书签链接',
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<div class="ui segment js-tags" ng-show="!loading || tags.length > 0">
|
<div class="ui segment js-tags" ng-show="!loading || tags.length > 0">
|
||||||
<div class="ui container" ng-show="!editMode" style="cursor:default">
|
<div class="ui container" ng-show="!editMode" style="cursor:default">
|
||||||
<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, null)">
|
<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, (tag.id == -1 ? 0 : 1), null)">
|
||||||
{{ tag.name }} ({{ tag.bookmarkCount || 0 }})
|
{{ tag.name }} ({{ tag.bookmarkCount || 0 }})
|
||||||
</div>
|
</div>
|
||||||
<div class="ui label js-tag-label" style="margin:3px 15px 8px 0px;cursor:default;">
|
<div class="ui label js-tag-label" style="margin:3px 15px 8px 0px;cursor:default;">
|
||||||
|
|
@ -112,7 +112,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="ui divider"></div>
|
<div class="ui divider"></div>
|
||||||
<div class="ui grid">
|
<div class="ui grid">
|
||||||
<div class="five wide column" style="margin-top:10px;">
|
<div class="five wide column" style="margin-top:10px;" ng-show="currentPage>0">
|
||||||
<div class="ui three column grid" style="cursor: default;">
|
<div class="ui three column grid" style="cursor: default;">
|
||||||
<div class="column" ng-click="getBookmarks(null, 1, 'createdAt')">
|
<div class="column" ng-click="getBookmarks(null, 1, 'createdAt')">
|
||||||
<i class="add to calendar large icon" ng-class="{green: showType == 'createdAt'}" style="margin-bottom:4px;"></i>
|
<i class="add to calendar large icon" ng-class="{green: showType == 'createdAt'}" style="margin-bottom:4px;"></i>
|
||||||
|
|
@ -128,6 +128,8 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="five wide column" style="margin-top:10px;" ng-show="currentPage==0">
|
||||||
|
</div>
|
||||||
<div class="eleven wide column">
|
<div class="eleven wide column">
|
||||||
<pagination></pagination>
|
<pagination></pagination>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue