Merge branch 'refs/heads/dev_1.0.0_beta4' into preview

This commit is contained in:
xlsea 2024-06-07 14:23:31 +08:00
commit 4ad85ad942
12 changed files with 72 additions and 36 deletions

View File

@ -75,7 +75,7 @@
}, },
"devDependencies": { "devDependencies": {
"@elegant-router/vue": "0.3.7", "@elegant-router/vue": "0.3.7",
"@iconify/json": "2.2.216", "@iconify/json": "2.2.217",
"@sa/scripts": "workspace:*", "@sa/scripts": "workspace:*",
"@sa/uno-preset": "workspace:*", "@sa/uno-preset": "workspace:*",
"@soybeanjs/eslint-config": "1.3.6", "@soybeanjs/eslint-config": "1.3.6",

View File

@ -1,6 +1,6 @@
{ {
"name": "@sa/axios", "name": "@sa/axios",
"version": "1.2.0", "version": "1.2.1",
"exports": { "exports": {
".": "./src/index.ts" ".": "./src/index.ts"
}, },

View File

@ -1,6 +1,6 @@
{ {
"name": "@sa/color", "name": "@sa/color",
"version": "1.2.0", "version": "1.2.1",
"exports": { "exports": {
".": "./src/index.ts" ".": "./src/index.ts"
}, },

View File

@ -1,6 +1,6 @@
{ {
"name": "@sa/hooks", "name": "@sa/hooks",
"version": "1.2.0", "version": "1.2.1",
"exports": { "exports": {
".": "./src/index.ts" ".": "./src/index.ts"
}, },

View File

@ -1,6 +1,6 @@
{ {
"name": "@sa/materials", "name": "@sa/materials",
"version": "1.2.0", "version": "1.2.1",
"exports": { "exports": {
".": "./src/index.ts" ".": "./src/index.ts"
}, },

View File

@ -1,6 +1,6 @@
{ {
"name": "@sa/fetch", "name": "@sa/fetch",
"version": "1.2.0", "version": "1.2.1",
"exports": { "exports": {
".": "./src/index.ts" ".": "./src/index.ts"
}, },

View File

@ -1,6 +1,6 @@
{ {
"name": "@sa/scripts", "name": "@sa/scripts",
"version": "1.2.0", "version": "1.2.1",
"bin": { "bin": {
"sa": "./bin.ts" "sa": "./bin.ts"
}, },
@ -19,7 +19,7 @@
"cac": "6.7.14", "cac": "6.7.14",
"consola": "3.2.3", "consola": "3.2.3",
"enquirer": "2.4.1", "enquirer": "2.4.1",
"execa": "9.1.0", "execa": "9.2.0",
"kolorist": "1.8.0", "kolorist": "1.8.0",
"npm-check-updates": "16.14.20", "npm-check-updates": "16.14.20",
"rimraf": "5.0.7" "rimraf": "5.0.7"

View File

@ -1,6 +1,6 @@
{ {
"name": "@sa/uno-preset", "name": "@sa/uno-preset",
"version": "1.2.0", "version": "1.2.1",
"exports": { "exports": {
".": "./src/index.ts" ".": "./src/index.ts"
}, },

View File

@ -1,6 +1,6 @@
{ {
"name": "@sa/utils", "name": "@sa/utils",
"version": "1.2.0", "version": "1.2.1",
"exports": { "exports": {
".": "./src/index.ts" ".": "./src/index.ts"
}, },

View File

@ -94,8 +94,8 @@ importers:
specifier: 0.3.7 specifier: 0.3.7
version: 0.3.7 version: 0.3.7
'@iconify/json': '@iconify/json':
specifier: 2.2.216 specifier: 2.2.217
version: 2.2.216 version: 2.2.217
'@sa/scripts': '@sa/scripts':
specifier: workspace:* specifier: workspace:*
version: link:packages/scripts version: link:packages/scripts
@ -264,8 +264,8 @@ importers:
specifier: 2.4.1 specifier: 2.4.1
version: 2.4.1 version: 2.4.1
execa: execa:
specifier: 9.1.0 specifier: 9.2.0
version: 9.1.0 version: 9.2.0
kolorist: kolorist:
specifier: 1.8.0 specifier: 1.8.0
version: 1.8.0 version: 1.8.0
@ -725,8 +725,8 @@ packages:
resolution: {integrity: sha512-d2CGZR2o7fS6sWB7DG/3a95bGKQyHMACZ5aW8qGkkqQpUoZV6C0X7Pc7l4ZNMZkfNBf4VWNe9E1jRsf0G146Ew==} resolution: {integrity: sha512-d2CGZR2o7fS6sWB7DG/3a95bGKQyHMACZ5aW8qGkkqQpUoZV6C0X7Pc7l4ZNMZkfNBf4VWNe9E1jRsf0G146Ew==}
engines: {node: '>=18.18'} engines: {node: '>=18.18'}
'@iconify/json@2.2.216': '@iconify/json@2.2.217':
resolution: {integrity: sha512-dS2yVIAel1oIAGnaxR+EJyDRjKV9GGm9tUd8Pd8VEF91HB4HJrsMzkvz23GHDWyIITGdinx4ZUjMz3hOAv+D4Q==} resolution: {integrity: sha512-+sSR9iKsoThUmgG4wA9xdtyazROIqMOo5h5otOXYRyOQjMNJCpJltq5hEhHInC5aG/DUQmXDiN/YsCoJdCYUbQ==}
'@iconify/types@2.0.0': '@iconify/types@2.0.0':
resolution: {integrity: sha512-+wluvCrRhXrhyOmRDJ3q8mux9JkKy5SJ/v8ol2tu4FVjyYvtEzkc/3pK15ET6RKg4b4w4BmTk1+gsCUhf21Ykg==} resolution: {integrity: sha512-+wluvCrRhXrhyOmRDJ3q8mux9JkKy5SJ/v8ol2tu4FVjyYvtEzkc/3pK15ET6RKg4b4w4BmTk1+gsCUhf21Ykg==}
@ -2218,6 +2218,10 @@ packages:
resolution: {integrity: sha512-lSgHc4Elo2m6bUDhc3Hl/VxvUDJdQWI40RZ4KMY9bKRc+hgMOT7II/JjbNDhI8VnMtrCb7U/fhpJIkLORZozWw==} resolution: {integrity: sha512-lSgHc4Elo2m6bUDhc3Hl/VxvUDJdQWI40RZ4KMY9bKRc+hgMOT7II/JjbNDhI8VnMtrCb7U/fhpJIkLORZozWw==}
engines: {node: '>=18'} 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: expand-brackets@2.1.4:
resolution: {integrity: sha512-w/ozOKR9Obk3qoWeY/WDi6MFta9AoMR+zud60mdnbniMcBxRuFJyDt2LdX/14A1UABeqk+Uk+LDfUpvoGKppZA==} resolution: {integrity: sha512-w/ozOKR9Obk3qoWeY/WDi6MFta9AoMR+zud60mdnbniMcBxRuFJyDt2LdX/14A1UABeqk+Uk+LDfUpvoGKppZA==}
engines: {node: '>=0.10.0'} engines: {node: '>=0.10.0'}
@ -5232,7 +5236,7 @@ snapshots:
'@humanwhocodes/retry@0.3.0': {} '@humanwhocodes/retry@0.3.0': {}
'@iconify/json@2.2.216': '@iconify/json@2.2.217':
dependencies: dependencies:
'@iconify/types': 2.0.0 '@iconify/types': 2.0.0
pathe: 1.1.2 pathe: 1.1.2
@ -7037,6 +7041,21 @@ snapshots:
strip-final-newline: 4.0.0 strip-final-newline: 4.0.0
yoctocolors: 2.0.2 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: expand-brackets@2.1.4:
dependencies: dependencies:
debug: 2.6.9 debug: 2.6.9

View File

@ -10,7 +10,6 @@ import { useAuthStore } from '@/store/modules/auth';
import { useRouteStore } from '@/store/modules/route'; import { useRouteStore } from '@/store/modules/route';
import { localStg } from '@/utils/storage'; import { localStg } from '@/utils/storage';
import { $t } from '@/locales'; import { $t } from '@/locales';
import { fetchVersion } from '@/service/api';
/** /**
* create route guard * create route guard
@ -128,6 +127,11 @@ async function initRoute(to: RouteLocationNormalized): Promise<RouteLocationRaw
return null; 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 // it is captured by the "not-found" route, then check whether the route exists
if (routeStore.isInitAuthRoute && isNotFoundRoute) { if (routeStore.isInitAuthRoute && isNotFoundRoute) {
const exist = await routeStore.getIsAuthRouteExist(to.path as RoutePath); const exist = await routeStore.getIsAuthRouteExist(to.path as RoutePath);
@ -161,18 +165,8 @@ async function initRoute(to: RouteLocationNormalized): Promise<RouteLocationRaw
return location; return location;
} }
// the auth route is initialized await authStore.initAppVersion();
// it is not the "not-found" route, then it is allowed to access await authStore.initUserInfo();
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');
}
}
// initialize the auth route // initialize the auth route
await routeStore.initAuthRoute(); await routeStore.initAuthRoute();

View File

@ -4,7 +4,7 @@ import { defineStore } from 'pinia';
import { useLoading } from '@sa/hooks'; import { useLoading } from '@sa/hooks';
import { SetupStoreId } from '@/enum'; import { SetupStoreId } from '@/enum';
import { useRouterPush } from '@/hooks/common/router'; 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 { localStg } from '@/utils/storage';
import { $t } from '@/locales'; import { $t } from '@/locales';
import { roleTypeRecord } from '@/constants/business'; import { roleTypeRecord } from '@/constants/business';
@ -108,8 +108,8 @@ export const useAuthStore = defineStore(SetupStoreId.Auth, () => {
localStg.set('userNamespace', userNamespace); localStg.set('userNamespace', userNamespace);
} }
// 2. get user info and update store // 2. get user info
const pass = await updateUserInfo(); const pass = await getUserInfo();
if (pass) { if (pass) {
token.value = loginToken.token; token.value = loginToken.token;
@ -120,11 +120,13 @@ export const useAuthStore = defineStore(SetupStoreId.Auth, () => {
return false; return false;
} }
async function updateUserInfo() { async function getUserInfo() {
// update user info
const { data: info, error } = await fetchGetUserInfo(); const { data: info, error } = await fetchGetUserInfo();
if (!error) { if (!error) {
// update store // update store
info!.userId = info.id;
info!.userName = info?.username; info!.userName = info?.username;
info!.roles = [roleTypeRecord[info.role]]; info!.roles = [roleTypeRecord[info.role]];
localStg.set('userInfo', info); localStg.set('userInfo', info);
@ -133,10 +135,30 @@ export const useAuthStore = defineStore(SetupStoreId.Auth, () => {
return true; return true;
} }
await resetStore();
return false; 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) { function setNamespaceId(namespaceId: string) {
const userNamespace = localStg.get('userNamespace') || {}; const userNamespace = localStg.get('userNamespace') || {};
userNamespace[userInfo.userId] = namespaceId; userNamespace[userInfo.userId] = namespaceId;
@ -152,7 +174,8 @@ export const useAuthStore = defineStore(SetupStoreId.Auth, () => {
loginLoading, loginLoading,
resetStore, resetStore,
login, login,
updateUserInfo, initUserInfo,
initAppVersion,
setNamespaceId setNamespaceId
}; };
}); });