update clientStore

This commit is contained in:
landaiqing
2024-09-08 15:30:19 +08:00
parent 834174c7cb
commit 52a7981beb
6 changed files with 18 additions and 43 deletions

View File

@@ -16,19 +16,4 @@ export const generateQrCode = (clientId: string) => {
}
);
};
/**
* 关闭websocket
* @param clientId
*/
export const closeWebsocket = (clientId: string) => {
return service.Get('/api/ws/delete',
{
params: {
client_id: clientId
},
meta: {
ignoreToken: true,
},
}
);
};

View File

@@ -106,10 +106,9 @@ export const resetPasswordApi = (param: ResetPassword) => {
* @param user_id
*/
export const getUserPermissions = (user_id: string) => {
return service.Get('/api/auth/permission/get_user_permissions', {
params: {
user_id: user_id
},
return service.Post('/api/auth/permission/get_user_permissions', {
user_id: user_id,
}, {
meta: {
ignoreToken: false,
}

View File

@@ -4,7 +4,7 @@ import {ref} from "vue";
export const useClientStore = defineStore(
'clientId',
() => {
const clientId = ref<string>();
const clientId = ref<string>('');
function setClientId(id: string) {
clientId.value = id;

View File

@@ -34,7 +34,6 @@ const {onAuthRequired, onResponseRefreshToken} = createServerTokenAuthentication
} else {
message.error(i18n.global.t('error.loginExpired'));
localStorage.removeItem('user');
localStorage.removeItem('clientId');
setTimeout(() => {
window.location.href = '/login';
}, 2000);
@@ -50,12 +49,7 @@ export const service = createAlova({
requestAdapter: axiosRequestAdapter(),
l2Cache: localforageStorageAdapter,
cacheLogger: import.meta.env.VITE_NODE_ENV === 'development',
cacheFor: {
// GET: {
// mode: "restore",
// expire: 1000 * 60 * 60 * 24 * 7 // 7天过期
// }
},
cacheFor: {},
// 设置全局的请求拦截器
beforeRequest: onAuthRequired(async (method: any) => {
if (!method.meta?.ignoreToken) {
@@ -74,7 +68,6 @@ export const service = createAlova({
const {code} = response.data;
if (code === 403) {
localStorage.removeItem('user');
localStorage.removeItem('clientId');
message.open({
type: 'error',
content: i18n.global.t('error.loginExpired'),

View File

@@ -36,12 +36,13 @@ const {t} = useI18n();
const githubRedirectUrl = ref<string>('');
const giteeRedirectUrl = ref<string>('');
const qqRedirectUrl = ref<string>('');
const client = useStore().client;
/**
* Get the redirect url of Github OAuth
*/
async function getGithubRedirectUrl() {
const clientId: string = getLocalClientId() as string;
const clientId: string = await getLocalClientId() as string;
const res: any = await getGithubUrl(clientId);
if (res.code === 0 && res.data) {
githubRedirectUrl.value = res.data;
@@ -62,7 +63,7 @@ async function getGiteeRedirectUrl() {
* Get the redirect url of QQ OAuth
*/
async function getQQRedirectUrl() {
const clientId: string = getLocalClientId() as string;
const clientId: string = await getLocalClientId() as string;
const res: any = await getQQUrl(clientId);
if (res.code === 0 && res.data) {
qqRedirectUrl.value = res.data;
@@ -73,7 +74,6 @@ async function getQQRedirectUrl() {
* 获取client_id
*/
async function getClientId() {
const client = useStore().client;
const res: any = await generateClientId();
if (res.code === 0 && res.data) {
client.setClientId(res.data);
@@ -83,12 +83,11 @@ async function getClientId() {
/**
* 获取本地client_id
*/
function getLocalClientId() {
const client = useStore().client;
if (client.getClientId()) {
async function getLocalClientId() {
if (client.getClientId() !== '' && client.getClientId() !== null) {
return client.getClientId();
} else {
getClientId();
await getClientId();
return client.getClientId();
}
}

View File

@@ -31,6 +31,7 @@ import {getQQUrl} from "@/api/oauth/qq.ts";
import {useDebounceFn} from "@vueuse/core";
import {generateClientId, getUserDevice} from "@/api/oauth";
const client = useStore().client;
const router = useRouter();
const {t} = useI18n();
@@ -42,7 +43,7 @@ const qqRedirectUrl = ref<string>('');
* Get the redirect url of Github OAuth
*/
async function getGithubRedirectUrl() {
const clientId: string = getLocalClientId() as string;
const clientId: string = await getLocalClientId() as string;
const res: any = await getGithubUrl(clientId);
if (res.code === 0 && res.data) {
githubRedirectUrl.value = res.data;
@@ -63,7 +64,7 @@ async function getGiteeRedirectUrl() {
* Get the redirect url of QQ OAuth
*/
async function getQQRedirectUrl() {
const clientId: string = getLocalClientId() as string;
const clientId: string = await getLocalClientId() as string;
const res: any = await getQQUrl(clientId);
if (res.code === 0 && res.data) {
qqRedirectUrl.value = res.data;
@@ -74,7 +75,6 @@ async function getQQRedirectUrl() {
* 获取client_id
*/
async function getClientId() {
const client = useStore().client;
const res: any = await generateClientId();
if (res.code === 0 && res.data) {
client.setClientId(res.data);
@@ -84,12 +84,11 @@ async function getClientId() {
/**
* 获取本地client_id
*/
function getLocalClientId() {
const client = useStore().client;
if (client.getClientId()) {
async function getLocalClientId() {
if (client.getClientId() !== '' && client.getClientId() !== null) {
return client.getClientId();
} else {
getClientId();
await getClientId();
return client.getClientId();
}
}