对于分类信息使用缓存加速

This commit is contained in:
HelloWorld 2020-04-07 22:56:01 +08:00
parent 449d7122af
commit 72134d284f
2 changed files with 29 additions and 10 deletions

View File

@ -41,7 +41,6 @@ app.controller('loginCtr', ['$scope', '$filter', '$state', '$http', '$cookieStor
let data = await post('userLogin', params); let data = await post('userLogin', params);
// 更新token信息 // 更新token信息
axios.defaults.headers.common['Authorization'] = data.token;
localStorage.setItem("authorization", data.token); localStorage.setItem("authorization", data.token);
pubSubService.publish('loginCtr.login', { login: true }); pubSubService.publish('loginCtr.login', { login: true });

View File

@ -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.loadTags = true;
$scope.tags = []; $scope.tags = [];
let tags = await get('tags', { bookmarkCount: true });
tags.unshift({ tags.unshift({
id: -1, id: -1,
bookmarkCount: 1, bookmarkCount: '...',
bookmarkClicked: false, bookmarkClicked: false,
name: '个人定制', name: '个人定制',
show: 1 show: 1
@ -362,16 +363,11 @@ app.controller('tagsCtr', ['$scope', '$filter', '$state', '$window', '$statePara
tag.bookmarkClicked = true; tag.bookmarkClicked = true;
find = true; // 如果是删了分类返回来,那么要重新默认选中第一个分类 find = true; // 如果是删了分类返回来,那么要重新默认选中第一个分类
} }
$scope.tags.push(tag);
} }
if (!find) { if (!find) {
$scope.currentTagId = -1; $scope.currentTagId = -1;
$scope.tags[0].bookmarkClicked = true; tags[0].bookmarkClicked = true;
}
if (!$scope.editMode) {
await $scope.getBookmarks(null, null, null);
} }
$scope.loadTags = false; $scope.loadTags = false;
@ -379,6 +375,30 @@ app.controller('tagsCtr', ['$scope', '$filter', '$state', '$window', '$statePara
login: true, login: true,
index: dataService.LoginIndexTags 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) { pubSubService.subscribe('EditCtr.inserBookmarsSuccess', $scope, function (event, data) {