merge(sj_1.0.0_beta4): 合并 sa 1.2.1
This commit is contained in:
parent
5fe985ac05
commit
61c8bf6473
@ -75,7 +75,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@elegant-router/vue": "0.3.7",
|
||||
"@iconify/json": "2.2.216",
|
||||
"@iconify/json": "2.2.217",
|
||||
"@sa/scripts": "workspace:*",
|
||||
"@sa/uno-preset": "workspace:*",
|
||||
"@soybeanjs/eslint-config": "1.3.6",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@sa/axios",
|
||||
"version": "1.2.0",
|
||||
"version": "1.2.1",
|
||||
"exports": {
|
||||
".": "./src/index.ts"
|
||||
},
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@sa/color",
|
||||
"version": "1.2.0",
|
||||
"version": "1.2.1",
|
||||
"exports": {
|
||||
".": "./src/index.ts"
|
||||
},
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@sa/hooks",
|
||||
"version": "1.2.0",
|
||||
"version": "1.2.1",
|
||||
"exports": {
|
||||
".": "./src/index.ts"
|
||||
},
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@sa/materials",
|
||||
"version": "1.2.0",
|
||||
"version": "1.2.1",
|
||||
"exports": {
|
||||
".": "./src/index.ts"
|
||||
},
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@sa/fetch",
|
||||
"version": "1.2.0",
|
||||
"version": "1.2.1",
|
||||
"exports": {
|
||||
".": "./src/index.ts"
|
||||
},
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@sa/scripts",
|
||||
"version": "1.2.0",
|
||||
"version": "1.2.1",
|
||||
"bin": {
|
||||
"sa": "./bin.ts"
|
||||
},
|
||||
@ -19,7 +19,7 @@
|
||||
"cac": "6.7.14",
|
||||
"consola": "3.2.3",
|
||||
"enquirer": "2.4.1",
|
||||
"execa": "9.1.0",
|
||||
"execa": "9.2.0",
|
||||
"kolorist": "1.8.0",
|
||||
"npm-check-updates": "16.14.20",
|
||||
"rimraf": "5.0.7"
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@sa/uno-preset",
|
||||
"version": "1.2.0",
|
||||
"version": "1.2.1",
|
||||
"exports": {
|
||||
".": "./src/index.ts"
|
||||
},
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@sa/utils",
|
||||
"version": "1.2.0",
|
||||
"version": "1.2.1",
|
||||
"exports": {
|
||||
".": "./src/index.ts"
|
||||
},
|
||||
|
@ -94,8 +94,8 @@ importers:
|
||||
specifier: 0.3.7
|
||||
version: 0.3.7
|
||||
'@iconify/json':
|
||||
specifier: 2.2.216
|
||||
version: 2.2.216
|
||||
specifier: 2.2.217
|
||||
version: 2.2.217
|
||||
'@sa/scripts':
|
||||
specifier: workspace:*
|
||||
version: link:packages/scripts
|
||||
@ -264,8 +264,8 @@ importers:
|
||||
specifier: 2.4.1
|
||||
version: 2.4.1
|
||||
execa:
|
||||
specifier: 9.1.0
|
||||
version: 9.1.0
|
||||
specifier: 9.2.0
|
||||
version: 9.2.0
|
||||
kolorist:
|
||||
specifier: 1.8.0
|
||||
version: 1.8.0
|
||||
@ -725,8 +725,8 @@ packages:
|
||||
resolution: {integrity: sha512-d2CGZR2o7fS6sWB7DG/3a95bGKQyHMACZ5aW8qGkkqQpUoZV6C0X7Pc7l4ZNMZkfNBf4VWNe9E1jRsf0G146Ew==}
|
||||
engines: {node: '>=18.18'}
|
||||
|
||||
'@iconify/json@2.2.216':
|
||||
resolution: {integrity: sha512-dS2yVIAel1oIAGnaxR+EJyDRjKV9GGm9tUd8Pd8VEF91HB4HJrsMzkvz23GHDWyIITGdinx4ZUjMz3hOAv+D4Q==}
|
||||
'@iconify/json@2.2.217':
|
||||
resolution: {integrity: sha512-+sSR9iKsoThUmgG4wA9xdtyazROIqMOo5h5otOXYRyOQjMNJCpJltq5hEhHInC5aG/DUQmXDiN/YsCoJdCYUbQ==}
|
||||
|
||||
'@iconify/types@2.0.0':
|
||||
resolution: {integrity: sha512-+wluvCrRhXrhyOmRDJ3q8mux9JkKy5SJ/v8ol2tu4FVjyYvtEzkc/3pK15ET6RKg4b4w4BmTk1+gsCUhf21Ykg==}
|
||||
@ -2218,6 +2218,10 @@ packages:
|
||||
resolution: {integrity: sha512-lSgHc4Elo2m6bUDhc3Hl/VxvUDJdQWI40RZ4KMY9bKRc+hgMOT7II/JjbNDhI8VnMtrCb7U/fhpJIkLORZozWw==}
|
||||
engines: {node: '>=18'}
|
||||
|
||||
execa@9.2.0:
|
||||
resolution: {integrity: sha512-vpOyYg7UAVKLAWWtRS2gAdgkT7oJbCn0me3gmUmxZih4kd3MF/oo8kNTBTIbkO3yuuF5uB4ZCZfn8BOolITYhg==}
|
||||
engines: {node: ^18.19.0 || >=20.5.0}
|
||||
|
||||
expand-brackets@2.1.4:
|
||||
resolution: {integrity: sha512-w/ozOKR9Obk3qoWeY/WDi6MFta9AoMR+zud60mdnbniMcBxRuFJyDt2LdX/14A1UABeqk+Uk+LDfUpvoGKppZA==}
|
||||
engines: {node: '>=0.10.0'}
|
||||
@ -5232,7 +5236,7 @@ snapshots:
|
||||
|
||||
'@humanwhocodes/retry@0.3.0': {}
|
||||
|
||||
'@iconify/json@2.2.216':
|
||||
'@iconify/json@2.2.217':
|
||||
dependencies:
|
||||
'@iconify/types': 2.0.0
|
||||
pathe: 1.1.2
|
||||
@ -7037,6 +7041,21 @@ snapshots:
|
||||
strip-final-newline: 4.0.0
|
||||
yoctocolors: 2.0.2
|
||||
|
||||
execa@9.2.0:
|
||||
dependencies:
|
||||
'@sindresorhus/merge-streams': 4.0.0
|
||||
cross-spawn: 7.0.3
|
||||
figures: 6.1.0
|
||||
get-stream: 9.0.1
|
||||
human-signals: 7.0.0
|
||||
is-plain-obj: 4.1.0
|
||||
is-stream: 4.0.1
|
||||
npm-run-path: 5.3.0
|
||||
pretty-ms: 9.0.0
|
||||
signal-exit: 4.1.0
|
||||
strip-final-newline: 4.0.0
|
||||
yoctocolors: 2.0.2
|
||||
|
||||
expand-brackets@2.1.4:
|
||||
dependencies:
|
||||
debug: 2.6.9
|
||||
|
@ -10,7 +10,6 @@ import { useAuthStore } from '@/store/modules/auth';
|
||||
import { useRouteStore } from '@/store/modules/route';
|
||||
import { localStg } from '@/utils/storage';
|
||||
import { $t } from '@/locales';
|
||||
import { fetchVersion } from '@/service/api';
|
||||
|
||||
/**
|
||||
* create route guard
|
||||
@ -128,6 +127,11 @@ async function initRoute(to: RouteLocationNormalized): Promise<RouteLocationRaw
|
||||
return null;
|
||||
}
|
||||
|
||||
// the auth route is initialized
|
||||
// it is not the "not-found" route, then it is allowed to access
|
||||
if (routeStore.isInitAuthRoute && !isNotFoundRoute) {
|
||||
return null;
|
||||
}
|
||||
// it is captured by the "not-found" route, then check whether the route exists
|
||||
if (routeStore.isInitAuthRoute && isNotFoundRoute) {
|
||||
const exist = await routeStore.getIsAuthRouteExist(to.path as RoutePath);
|
||||
@ -161,18 +165,8 @@ async function initRoute(to: RouteLocationNormalized): Promise<RouteLocationRaw
|
||||
return location;
|
||||
}
|
||||
|
||||
// the auth route is initialized
|
||||
// it is not the "not-found" route, then it is allowed to access
|
||||
if (!routeStore.isInitAuthRoute && isLogin) {
|
||||
// update user info
|
||||
await authStore.updateUserInfo();
|
||||
const { data, error } = await fetchVersion();
|
||||
if (!error && data) {
|
||||
localStg.set('version', data!);
|
||||
} else {
|
||||
localStg.remove('version');
|
||||
}
|
||||
}
|
||||
await authStore.initAppVersion();
|
||||
await authStore.initUserInfo();
|
||||
|
||||
// initialize the auth route
|
||||
await routeStore.initAuthRoute();
|
||||
|
@ -4,7 +4,7 @@ import { defineStore } from 'pinia';
|
||||
import { useLoading } from '@sa/hooks';
|
||||
import { SetupStoreId } from '@/enum';
|
||||
import { useRouterPush } from '@/hooks/common/router';
|
||||
import { fetchGetUserInfo, fetchLogin } from '@/service/api';
|
||||
import { fetchGetUserInfo, fetchLogin, fetchVersion } from '@/service/api';
|
||||
import { localStg } from '@/utils/storage';
|
||||
import { $t } from '@/locales';
|
||||
import { roleTypeRecord } from '@/constants/business';
|
||||
@ -108,8 +108,8 @@ export const useAuthStore = defineStore(SetupStoreId.Auth, () => {
|
||||
localStg.set('userNamespace', userNamespace);
|
||||
}
|
||||
|
||||
// 2. get user info and update store
|
||||
const pass = await updateUserInfo();
|
||||
// 2. get user info
|
||||
const pass = await getUserInfo();
|
||||
|
||||
if (pass) {
|
||||
token.value = loginToken.token;
|
||||
@ -120,11 +120,13 @@ export const useAuthStore = defineStore(SetupStoreId.Auth, () => {
|
||||
return false;
|
||||
}
|
||||
|
||||
async function updateUserInfo() {
|
||||
async function getUserInfo() {
|
||||
// update user info
|
||||
const { data: info, error } = await fetchGetUserInfo();
|
||||
|
||||
if (!error) {
|
||||
// update store
|
||||
info!.userId = info.id;
|
||||
info!.userName = info?.username;
|
||||
info!.roles = [roleTypeRecord[info.role]];
|
||||
localStg.set('userInfo', info);
|
||||
@ -133,10 +135,30 @@ export const useAuthStore = defineStore(SetupStoreId.Auth, () => {
|
||||
return true;
|
||||
}
|
||||
|
||||
await resetStore();
|
||||
return false;
|
||||
}
|
||||
|
||||
async function initUserInfo() {
|
||||
const hasToken = getToken();
|
||||
|
||||
if (hasToken) {
|
||||
const pass = await getUserInfo();
|
||||
|
||||
if (!pass) {
|
||||
resetStore();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function initAppVersion() {
|
||||
const { data: version, error: versionError } = await fetchVersion();
|
||||
if (!versionError && version) {
|
||||
localStg.set('version', version!);
|
||||
} else {
|
||||
localStg.remove('version');
|
||||
}
|
||||
}
|
||||
|
||||
function setNamespaceId(namespaceId: string) {
|
||||
const userNamespace = localStg.get('userNamespace') || {};
|
||||
userNamespace[userInfo.userId] = namespaceId;
|
||||
@ -152,7 +174,8 @@ export const useAuthStore = defineStore(SetupStoreId.Auth, () => {
|
||||
loginLoading,
|
||||
resetStore,
|
||||
login,
|
||||
updateUserInfo,
|
||||
initUserInfo,
|
||||
initAppVersion,
|
||||
setNamespaceId
|
||||
};
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user