修复搜索bug

This commit is contained in:
HelloWorld 2020-04-21 17:34:27 +08:00
parent c58a367e88
commit 28895b7019
4 changed files with 26 additions and 2 deletions

View File

@ -346,7 +346,7 @@ module.exports = class extends Base {
for (let bookmark of data.data) { for (let bookmark of data.data) {
ids.push(bookmark.tagId); ids.push(bookmark.tagId);
} }
let tags = await this.model('tags').where({ id: ['IN', ids] }).select(); let tags = ids.length > 0 ? await this.model('tags').where({ id: ['IN', ids] }).select() : [];
for (let bookmark of data.data) { for (let bookmark of data.data) {
bookmark.tagName = (tags.find((tag) => tag.id == bookmark.tagId) || { name: "未知分类" }).name; bookmark.tagName = (tags.find((tag) => tag.id == bookmark.tagId) || { name: "未知分类" }).name;
} }
@ -615,6 +615,21 @@ module.exports = class extends Base {
let note = this.post(); let note = this.post();
note.userId = this.ctx.state.user.id; note.userId = this.ctx.state.user.id;
try { try {
// 没有分类的直接放未分类里面
if (!note.tagId) {
const name = "未分类";
let tag = await this.model("tags").where({ name }).find();
if (!think.isEmpty(tag)) {
note.tagId = tag.id;
} else {
let tagId = await this.model("tags").add({
userId: this.ctx.state.user.id,
name
});
note.tagId = tagId;
}
}
let data = await this.model("notes").add(note); let data = await this.model("notes").add(note);
this.json({ code: 0, data, msg: `备忘添加成功` }); this.json({ code: 0, data, msg: `备忘添加成功` });
} catch (error) { } catch (error) {

View File

@ -8,6 +8,7 @@ app.controller('tagsCtr', ['$scope', '$filter', '$state', '$window', '$statePara
(async () => { (async () => {
await getTags(); await getTags();
$scope.user = await get('user');
})() })()
let dialog = null; let dialog = null;
@ -18,6 +19,7 @@ app.controller('tagsCtr', ['$scope', '$filter', '$state', '$window', '$statePara
$scope.showType = "createdAt"; $scope.showType = "createdAt";
$scope.loading = true; $scope.loading = true;
$scope.tags = []; // 书签数据 $scope.tags = []; // 书签数据
$scope.user = {};
$scope.tagsIndex = []; // 书签索引 $scope.tagsIndex = []; // 书签索引
$scope.bookmarks = []; $scope.bookmarks = [];
$scope.totalPages = 0; $scope.totalPages = 0;
@ -346,6 +348,10 @@ app.controller('tagsCtr', ['$scope', '$filter', '$state', '$window', '$statePara
}) })
}); });
$scope.globalTag = function () {
$state.go('settings', { formIndex: 4 });
}
async function updateTags(_tags) { async function updateTags(_tags) {
let tags = JSON.parse(JSON.stringify(_tags)); let tags = JSON.parse(JSON.stringify(_tags));

View File

@ -6,7 +6,7 @@
<a class="item" ng-class="{active:form[1]}" ng-click="changeForm(1)">我的信息 </a> <a class="item" ng-class="{active:form[1]}" ng-click="changeForm(1)">我的信息 </a>
<a class="item" ng-class="{active:form[2]}" ng-click="changeForm(2)">上传导出 </a> <a class="item" ng-class="{active:form[2]}" ng-click="changeForm(2)">上传导出 </a>
<a class="item" ng-class="{active:form[3]}" ng-click="changeForm(3)">网站说明 </a> <a class="item" ng-class="{active:form[3]}" ng-click="changeForm(3)">网站说明 </a>
<a class="item" ng-class="{active:form[4]}" ng-click="changeForm(4)">全局链接 </a> <a class="item" ng-class="{active:form[4]}" ng-click="changeForm(4)">全局书签 </a>
<a class="item" ng-class="{active:form[6]}" ng-click="changeForm(6)">请喝咖啡 </a> <a class="item" ng-class="{active:form[6]}" ng-click="changeForm(6)">请喝咖啡 </a>
</div> </div>
</div> </div>

View File

@ -3,6 +3,9 @@
<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)"> <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" ng-if="user.username != 'lcq'" style="margin: 3px 15px 8px 0px; cursor: default;" ng-click="globalTag()">
全局书签
</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;">
<i class="plus icon" data-content="点击添加分类" data-position="top center" ng-click="showAddTag()"></i> <i class="plus icon" data-content="点击添加分类" data-position="top center" ng-click="showAddTag()"></i>
<i class="pencil alternate icon" data-content="点击进入分类编辑模式" data-position="top center" ng-click="toggleMode(true)"></i> <i class="pencil alternate icon" data-content="点击进入分类编辑模式" data-position="top center" ng-click="toggleMode(true)"></i>