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 { $t } from '@/locales';
|
||||||
import { localStg } from '@/utils/storage';
|
import { localStg } from '@/utils/storage';
|
||||||
import { useAppStore } from '@/store/modules/app';
|
import { useAppStore } from '@/store/modules/app';
|
||||||
|
import { useAuthStore } from '@/store/modules/auth';
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const appStore = useAppStore();
|
const appStore = useAppStore();
|
||||||
|
const authStore = useAuthStore();
|
||||||
const namespaceId = ref<string>(localStg.get('namespaceId')!);
|
const namespaceId = ref<string>(localStg.get('namespaceId')!);
|
||||||
const userInfo = localStg.get('userInfo');
|
const userInfo = localStg.get('userInfo');
|
||||||
const selectOptions = computed(() =>
|
const selectOptions = computed(() =>
|
||||||
@ -22,7 +24,7 @@ const dropOptions = computed(() =>
|
|||||||
|
|
||||||
const onChange = (value: string) => {
|
const onChange = (value: string) => {
|
||||||
namespaceId.value = value;
|
namespaceId.value = value;
|
||||||
localStg.set('namespaceId', value);
|
authStore.setNamespaceId(value);
|
||||||
router.go(0);
|
router.go(0);
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
@ -88,14 +88,20 @@ export const useAuthStore = defineStore(SetupStoreId.Auth, () => {
|
|||||||
// 1. stored in the localStorage, the later requests need it in headers
|
// 1. stored in the localStorage, the later requests need it in headers
|
||||||
localStg.set('token', loginToken.token);
|
localStg.set('token', loginToken.token);
|
||||||
// localStg.set('refreshToken', loginToken.refreshToken);
|
// localStg.set('refreshToken', loginToken.refreshToken);
|
||||||
const namespaceId = localStg.get('namespaceId');
|
const userNamespace = localStg.get('userNamespace') || {};
|
||||||
if (!namespaceId || !loginToken.namespaceIds.map(item => item.uniqueId.includes(namespaceId))) {
|
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('namespaceId', loginToken.namespaceIds[0].uniqueId);
|
||||||
|
localStg.set('userNamespace', userNamespace);
|
||||||
}
|
}
|
||||||
|
|
||||||
const { data: info, error } = await fetchGetUserInfo();
|
const { data: info, error } = await fetchGetUserInfo();
|
||||||
|
|
||||||
if (!error) {
|
if (!error) {
|
||||||
|
info!.userId = info?.id;
|
||||||
info!.userName = info?.username;
|
info!.userName = info?.username;
|
||||||
info!.roles = [roleTypeRecord[info.role]];
|
info!.roles = [roleTypeRecord[info.role]];
|
||||||
// 2. store user info
|
// 2. store user info
|
||||||
@ -111,6 +117,13 @@ export const useAuthStore = defineStore(SetupStoreId.Auth, () => {
|
|||||||
return false;
|
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() {
|
async function getInfo() {
|
||||||
const { data: info, error } = await fetchGetUserInfo();
|
const { data: info, error } = await fetchGetUserInfo();
|
||||||
|
|
||||||
@ -134,6 +147,7 @@ export const useAuthStore = defineStore(SetupStoreId.Auth, () => {
|
|||||||
loginLoading,
|
loginLoading,
|
||||||
resetStore,
|
resetStore,
|
||||||
login,
|
login,
|
||||||
getInfo
|
getInfo,
|
||||||
|
setNamespaceId
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
@ -8,6 +8,7 @@ export function getToken() {
|
|||||||
/** Get user info */
|
/** Get user info */
|
||||||
export function getUserInfo() {
|
export function getUserInfo() {
|
||||||
const emptyInfo: Api.Auth.UserInfo = {
|
const emptyInfo: Api.Auth.UserInfo = {
|
||||||
|
id: '',
|
||||||
userId: '',
|
userId: '',
|
||||||
username: '',
|
username: '',
|
||||||
userName: '',
|
userName: '',
|
||||||
@ -31,6 +32,6 @@ export function getUserInfo() {
|
|||||||
export function clearAuthStorage() {
|
export function clearAuthStorage() {
|
||||||
localStg.remove('token');
|
localStg.remove('token');
|
||||||
// localStg.remove('refreshToken');
|
// localStg.remove('refreshToken');
|
||||||
// localStg.remove('namespaceId');
|
localStg.remove('namespaceId');
|
||||||
localStg.remove('userInfo');
|
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 {
|
interface UserInfo {
|
||||||
|
id: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
username: string;
|
username: 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;
|
version: string;
|
||||||
/** The namespace id */
|
/** The namespace id */
|
||||||
namespaceId: string;
|
namespaceId: string;
|
||||||
|
userNamespace: {
|
||||||
|
[key: string]: string;
|
||||||
|
};
|
||||||
/** The user info */
|
/** The user info */
|
||||||
userInfo: Api.Auth.UserInfo;
|
userInfo: Api.Auth.UserInfo;
|
||||||
/** The theme color */
|
/** The theme color */
|
||||||
|
Loading…
Reference in New Issue
Block a user