diff --git a/src/controller/api.js b/src/controller/api.js index 4f166c7..08d1216 100644 --- a/src/controller/api.js +++ b/src/controller/api.js @@ -346,7 +346,7 @@ module.exports = class extends Base { for (let bookmark of data.data) { 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) { bookmark.tagName = (tags.find((tag) => tag.id == bookmark.tagId) || { name: "未知分类" }).name; } @@ -615,6 +615,21 @@ module.exports = class extends Base { let note = this.post(); note.userId = this.ctx.state.user.id; 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); this.json({ code: 0, data, msg: `备忘添加成功` }); } catch (error) { diff --git a/www/scripts/controllers/tags-controller.js b/www/scripts/controllers/tags-controller.js index dd2a737..247cc86 100644 --- a/www/scripts/controllers/tags-controller.js +++ b/www/scripts/controllers/tags-controller.js @@ -8,6 +8,7 @@ app.controller('tagsCtr', ['$scope', '$filter', '$state', '$window', '$statePara (async () => { await getTags(); + $scope.user = await get('user'); })() let dialog = null; @@ -18,6 +19,7 @@ app.controller('tagsCtr', ['$scope', '$filter', '$state', '$window', '$statePara $scope.showType = "createdAt"; $scope.loading = true; $scope.tags = []; // 书签数据 + $scope.user = {}; $scope.tagsIndex = []; // 书签索引 $scope.bookmarks = []; $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) { let tags = JSON.parse(JSON.stringify(_tags)); diff --git a/www/views/settings.html b/www/views/settings.html index 563a1c9..604ac20 100644 --- a/www/views/settings.html +++ b/www/views/settings.html @@ -6,7 +6,7 @@ 我的信息 上传导出 网站说明 - 全局链接 + 全局书签 请喝咖啡 diff --git a/www/views/tags.html b/www/views/tags.html index 87911a9..f946cfe 100644 --- a/www/views/tags.html +++ b/www/views/tags.html @@ -3,6 +3,9 @@