From 72134d284f034785661256327569fedc7aad95e4 Mon Sep 17 00:00:00 2001 From: HelloWorld Date: Tue, 7 Apr 2020 22:56:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=B9=E4=BA=8E=E5=88=86=E7=B1=BB=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E4=BD=BF=E7=94=A8=E7=BC=93=E5=AD=98=E5=8A=A0=E9=80=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- www/scripts/controllers/login-controller.js | 1 - www/scripts/controllers/tags-controller.js | 38 ++++++++++++++++----- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/www/scripts/controllers/login-controller.js b/www/scripts/controllers/login-controller.js index 74308ba..10b09d9 100644 --- a/www/scripts/controllers/login-controller.js +++ b/www/scripts/controllers/login-controller.js @@ -41,7 +41,6 @@ app.controller('loginCtr', ['$scope', '$filter', '$state', '$http', '$cookieStor let data = await post('userLogin', params); // 更新token信息 - axios.defaults.headers.common['Authorization'] = data.token; localStorage.setItem("authorization", data.token); pubSubService.publish('loginCtr.login', { login: true }); diff --git a/www/scripts/controllers/tags-controller.js b/www/scripts/controllers/tags-controller.js index b1092b9..40825ad 100644 --- a/www/scripts/controllers/tags-controller.js +++ b/www/scripts/controllers/tags-controller.js @@ -341,14 +341,15 @@ app.controller('tagsCtr', ['$scope', '$filter', '$state', '$window', '$statePara }) }); - async function getTags() { + async function updateTags(_tags) { + let tags = JSON.parse(JSON.stringify(_tags)); + $scope.loadTags = true; $scope.tags = []; - let tags = await get('tags', { bookmarkCount: true }); tags.unshift({ id: -1, - bookmarkCount: 1, + bookmarkCount: '...', bookmarkClicked: false, name: '个人定制', show: 1 @@ -362,16 +363,11 @@ app.controller('tagsCtr', ['$scope', '$filter', '$state', '$window', '$statePara tag.bookmarkClicked = true; find = true; // 如果是删了分类返回来,那么要重新默认选中第一个分类 } - $scope.tags.push(tag); } if (!find) { $scope.currentTagId = -1; - $scope.tags[0].bookmarkClicked = true; - } - - if (!$scope.editMode) { - await $scope.getBookmarks(null, null, null); + tags[0].bookmarkClicked = true; } $scope.loadTags = false; @@ -379,6 +375,30 @@ app.controller('tagsCtr', ['$scope', '$filter', '$state', '$window', '$statePara login: true, index: dataService.LoginIndexTags }); + + $timeout(() => { + $scope.tags = tags; + if (!$scope.editMode) { + $scope.getBookmarks(null, null, null); + } + }) + } + + async function getTags() { + // 通过缓存tags,如果回来的tags跟缓存的一致,那么这个时间差就省下来了 + let tags = JSON.parse(localStorage.getItem("tags") || "[]"); + if (tags.length > 0) { + get('tags', { bookmarkCount: true }).then((_tags) => { + if (JSON.stringify(tags) != JSON.stringify(_tags)) { + localStorage.setItem("tags", JSON.stringify(tags)); + updateTags(tags); + } + }); + } else { + tags = await get('tags', { bookmarkCount: true }); + localStorage.setItem("tags", JSON.stringify(tags)); + } + updateTags(tags); } pubSubService.subscribe('EditCtr.inserBookmarsSuccess', $scope, function (event, data) {