fix(sj_1.0.0_beta4): 修复用户记录习惯记录问题
This commit is contained in:
parent
12ad59d306
commit
a2595b5b77
@ -4,9 +4,11 @@ import { useRouter } from 'vue-router';
|
||||
import { $t } from '@/locales';
|
||||
import { localStg } from '@/utils/storage';
|
||||
import { useAppStore } from '@/store/modules/app';
|
||||
import { useAuthStore } from '@/store/modules/auth';
|
||||
|
||||
const router = useRouter();
|
||||
const appStore = useAppStore();
|
||||
const authStore = useAuthStore();
|
||||
const namespaceId = ref<string>(localStg.get('namespaceId')!);
|
||||
const userInfo = localStg.get('userInfo');
|
||||
const selectOptions = computed(() =>
|
||||
@ -22,7 +24,7 @@ const dropOptions = computed(() =>
|
||||
|
||||
const onChange = (value: string) => {
|
||||
namespaceId.value = value;
|
||||
localStg.set('namespaceId', value);
|
||||
authStore.setNamespaceId(value);
|
||||
router.go(0);
|
||||
};
|
||||
</script>
|
||||
|
@ -88,14 +88,20 @@ export const useAuthStore = defineStore(SetupStoreId.Auth, () => {
|
||||
// 1. stored in the localStorage, the later requests need it in headers
|
||||
localStg.set('token', loginToken.token);
|
||||
// localStg.set('refreshToken', loginToken.refreshToken);
|
||||
const namespaceId = localStg.get('namespaceId');
|
||||
if (!namespaceId || !loginToken.namespaceIds.map(item => item.uniqueId.includes(namespaceId))) {
|
||||
const userNamespace = localStg.get('userNamespace') || {};
|
||||
const namespaceId = userNamespace[loginToken.id];
|
||||
localStg.set('namespaceId', namespaceId);
|
||||
|
||||
if (!namespaceId || !loginToken.namespaceIds.map(item => item.uniqueId).includes(namespaceId)) {
|
||||
userNamespace[loginToken.id] = loginToken.namespaceIds[0].uniqueId;
|
||||
localStg.set('namespaceId', loginToken.namespaceIds[0].uniqueId);
|
||||
localStg.set('userNamespace', userNamespace);
|
||||
}
|
||||
|
||||
const { data: info, error } = await fetchGetUserInfo();
|
||||
|
||||
if (!error) {
|
||||
info!.userId = info?.id;
|
||||
info!.userName = info?.username;
|
||||
info!.roles = [roleTypeRecord[info.role]];
|
||||
// 2. store user info
|
||||
@ -111,6 +117,13 @@ export const useAuthStore = defineStore(SetupStoreId.Auth, () => {
|
||||
return false;
|
||||
}
|
||||
|
||||
function setNamespaceId(namespaceId: string) {
|
||||
const userNamespace = localStg.get('userNamespace') || {};
|
||||
userNamespace[userInfo.userId] = namespaceId;
|
||||
localStg.set('userNamespace', userNamespace);
|
||||
localStg.set('namespaceId', namespaceId);
|
||||
}
|
||||
|
||||
async function getInfo() {
|
||||
const { data: info, error } = await fetchGetUserInfo();
|
||||
|
||||
@ -134,6 +147,7 @@ export const useAuthStore = defineStore(SetupStoreId.Auth, () => {
|
||||
loginLoading,
|
||||
resetStore,
|
||||
login,
|
||||
getInfo
|
||||
getInfo,
|
||||
setNamespaceId
|
||||
};
|
||||
});
|
||||
|
@ -8,6 +8,7 @@ export function getToken() {
|
||||
/** Get user info */
|
||||
export function getUserInfo() {
|
||||
const emptyInfo: Api.Auth.UserInfo = {
|
||||
id: '',
|
||||
userId: '',
|
||||
username: '',
|
||||
userName: '',
|
||||
@ -31,6 +32,6 @@ export function getUserInfo() {
|
||||
export function clearAuthStorage() {
|
||||
localStg.remove('token');
|
||||
// localStg.remove('refreshToken');
|
||||
// localStg.remove('namespaceId');
|
||||
localStg.remove('namespaceId');
|
||||
localStg.remove('userInfo');
|
||||
}
|
||||
|
1
src/typings/api.d.ts
vendored
1
src/typings/api.d.ts
vendored
@ -116,6 +116,7 @@ declare namespace Api {
|
||||
}
|
||||
|
||||
interface UserInfo {
|
||||
id: string;
|
||||
userId: string;
|
||||
username: string;
|
||||
userName: string;
|
||||
|
3
src/typings/storage.d.ts
vendored
3
src/typings/storage.d.ts
vendored
@ -22,6 +22,9 @@ declare namespace StorageType {
|
||||
version: string;
|
||||
/** The namespace id */
|
||||
namespaceId: string;
|
||||
userNamespace: {
|
||||
[key: string]: string;
|
||||
};
|
||||
/** The user info */
|
||||
userInfo: Api.Auth.UserInfo;
|
||||
/** The theme color */
|
||||
|
Loading…
Reference in New Issue
Block a user