✨ update clientStore
This commit is contained in:
@@ -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,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
@@ -106,10 +106,9 @@ export const resetPasswordApi = (param: ResetPassword) => {
|
|||||||
* @param user_id
|
* @param user_id
|
||||||
*/
|
*/
|
||||||
export const getUserPermissions = (user_id: string) => {
|
export const getUserPermissions = (user_id: string) => {
|
||||||
return service.Get('/api/auth/permission/get_user_permissions', {
|
return service.Post('/api/auth/permission/get_user_permissions', {
|
||||||
params: {
|
user_id: user_id,
|
||||||
user_id: user_id
|
}, {
|
||||||
},
|
|
||||||
meta: {
|
meta: {
|
||||||
ignoreToken: false,
|
ignoreToken: false,
|
||||||
}
|
}
|
||||||
|
@@ -4,7 +4,7 @@ import {ref} from "vue";
|
|||||||
export const useClientStore = defineStore(
|
export const useClientStore = defineStore(
|
||||||
'clientId',
|
'clientId',
|
||||||
() => {
|
() => {
|
||||||
const clientId = ref<string>();
|
const clientId = ref<string>('');
|
||||||
|
|
||||||
function setClientId(id: string) {
|
function setClientId(id: string) {
|
||||||
clientId.value = id;
|
clientId.value = id;
|
||||||
|
@@ -34,7 +34,6 @@ const {onAuthRequired, onResponseRefreshToken} = createServerTokenAuthentication
|
|||||||
} else {
|
} else {
|
||||||
message.error(i18n.global.t('error.loginExpired'));
|
message.error(i18n.global.t('error.loginExpired'));
|
||||||
localStorage.removeItem('user');
|
localStorage.removeItem('user');
|
||||||
localStorage.removeItem('clientId');
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
window.location.href = '/login';
|
window.location.href = '/login';
|
||||||
}, 2000);
|
}, 2000);
|
||||||
@@ -50,12 +49,7 @@ export const service = createAlova({
|
|||||||
requestAdapter: axiosRequestAdapter(),
|
requestAdapter: axiosRequestAdapter(),
|
||||||
l2Cache: localforageStorageAdapter,
|
l2Cache: localforageStorageAdapter,
|
||||||
cacheLogger: import.meta.env.VITE_NODE_ENV === 'development',
|
cacheLogger: import.meta.env.VITE_NODE_ENV === 'development',
|
||||||
cacheFor: {
|
cacheFor: {},
|
||||||
// GET: {
|
|
||||||
// mode: "restore",
|
|
||||||
// expire: 1000 * 60 * 60 * 24 * 7 // 7天过期
|
|
||||||
// }
|
|
||||||
},
|
|
||||||
// 设置全局的请求拦截器
|
// 设置全局的请求拦截器
|
||||||
beforeRequest: onAuthRequired(async (method: any) => {
|
beforeRequest: onAuthRequired(async (method: any) => {
|
||||||
if (!method.meta?.ignoreToken) {
|
if (!method.meta?.ignoreToken) {
|
||||||
@@ -74,7 +68,6 @@ export const service = createAlova({
|
|||||||
const {code} = response.data;
|
const {code} = response.data;
|
||||||
if (code === 403) {
|
if (code === 403) {
|
||||||
localStorage.removeItem('user');
|
localStorage.removeItem('user');
|
||||||
localStorage.removeItem('clientId');
|
|
||||||
message.open({
|
message.open({
|
||||||
type: 'error',
|
type: 'error',
|
||||||
content: i18n.global.t('error.loginExpired'),
|
content: i18n.global.t('error.loginExpired'),
|
||||||
|
@@ -36,12 +36,13 @@ const {t} = useI18n();
|
|||||||
const githubRedirectUrl = ref<string>('');
|
const githubRedirectUrl = ref<string>('');
|
||||||
const giteeRedirectUrl = ref<string>('');
|
const giteeRedirectUrl = ref<string>('');
|
||||||
const qqRedirectUrl = ref<string>('');
|
const qqRedirectUrl = ref<string>('');
|
||||||
|
const client = useStore().client;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the redirect url of Github OAuth
|
* Get the redirect url of Github OAuth
|
||||||
*/
|
*/
|
||||||
async function getGithubRedirectUrl() {
|
async function getGithubRedirectUrl() {
|
||||||
const clientId: string = getLocalClientId() as string;
|
const clientId: string = await getLocalClientId() as string;
|
||||||
const res: any = await getGithubUrl(clientId);
|
const res: any = await getGithubUrl(clientId);
|
||||||
if (res.code === 0 && res.data) {
|
if (res.code === 0 && res.data) {
|
||||||
githubRedirectUrl.value = res.data;
|
githubRedirectUrl.value = res.data;
|
||||||
@@ -62,7 +63,7 @@ async function getGiteeRedirectUrl() {
|
|||||||
* Get the redirect url of QQ OAuth
|
* Get the redirect url of QQ OAuth
|
||||||
*/
|
*/
|
||||||
async function getQQRedirectUrl() {
|
async function getQQRedirectUrl() {
|
||||||
const clientId: string = getLocalClientId() as string;
|
const clientId: string = await getLocalClientId() as string;
|
||||||
const res: any = await getQQUrl(clientId);
|
const res: any = await getQQUrl(clientId);
|
||||||
if (res.code === 0 && res.data) {
|
if (res.code === 0 && res.data) {
|
||||||
qqRedirectUrl.value = res.data;
|
qqRedirectUrl.value = res.data;
|
||||||
@@ -73,7 +74,6 @@ async function getQQRedirectUrl() {
|
|||||||
* 获取client_id
|
* 获取client_id
|
||||||
*/
|
*/
|
||||||
async function getClientId() {
|
async function getClientId() {
|
||||||
const client = useStore().client;
|
|
||||||
const res: any = await generateClientId();
|
const res: any = await generateClientId();
|
||||||
if (res.code === 0 && res.data) {
|
if (res.code === 0 && res.data) {
|
||||||
client.setClientId(res.data);
|
client.setClientId(res.data);
|
||||||
@@ -83,12 +83,11 @@ async function getClientId() {
|
|||||||
/**
|
/**
|
||||||
* 获取本地client_id
|
* 获取本地client_id
|
||||||
*/
|
*/
|
||||||
function getLocalClientId() {
|
async function getLocalClientId() {
|
||||||
const client = useStore().client;
|
if (client.getClientId() !== '' && client.getClientId() !== null) {
|
||||||
if (client.getClientId()) {
|
|
||||||
return client.getClientId();
|
return client.getClientId();
|
||||||
} else {
|
} else {
|
||||||
getClientId();
|
await getClientId();
|
||||||
return client.getClientId();
|
return client.getClientId();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -31,6 +31,7 @@ import {getQQUrl} from "@/api/oauth/qq.ts";
|
|||||||
import {useDebounceFn} from "@vueuse/core";
|
import {useDebounceFn} from "@vueuse/core";
|
||||||
import {generateClientId, getUserDevice} from "@/api/oauth";
|
import {generateClientId, getUserDevice} from "@/api/oauth";
|
||||||
|
|
||||||
|
const client = useStore().client;
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const {t} = useI18n();
|
const {t} = useI18n();
|
||||||
|
|
||||||
@@ -42,7 +43,7 @@ const qqRedirectUrl = ref<string>('');
|
|||||||
* Get the redirect url of Github OAuth
|
* Get the redirect url of Github OAuth
|
||||||
*/
|
*/
|
||||||
async function getGithubRedirectUrl() {
|
async function getGithubRedirectUrl() {
|
||||||
const clientId: string = getLocalClientId() as string;
|
const clientId: string = await getLocalClientId() as string;
|
||||||
const res: any = await getGithubUrl(clientId);
|
const res: any = await getGithubUrl(clientId);
|
||||||
if (res.code === 0 && res.data) {
|
if (res.code === 0 && res.data) {
|
||||||
githubRedirectUrl.value = res.data;
|
githubRedirectUrl.value = res.data;
|
||||||
@@ -63,7 +64,7 @@ async function getGiteeRedirectUrl() {
|
|||||||
* Get the redirect url of QQ OAuth
|
* Get the redirect url of QQ OAuth
|
||||||
*/
|
*/
|
||||||
async function getQQRedirectUrl() {
|
async function getQQRedirectUrl() {
|
||||||
const clientId: string = getLocalClientId() as string;
|
const clientId: string = await getLocalClientId() as string;
|
||||||
const res: any = await getQQUrl(clientId);
|
const res: any = await getQQUrl(clientId);
|
||||||
if (res.code === 0 && res.data) {
|
if (res.code === 0 && res.data) {
|
||||||
qqRedirectUrl.value = res.data;
|
qqRedirectUrl.value = res.data;
|
||||||
@@ -74,7 +75,6 @@ async function getQQRedirectUrl() {
|
|||||||
* 获取client_id
|
* 获取client_id
|
||||||
*/
|
*/
|
||||||
async function getClientId() {
|
async function getClientId() {
|
||||||
const client = useStore().client;
|
|
||||||
const res: any = await generateClientId();
|
const res: any = await generateClientId();
|
||||||
if (res.code === 0 && res.data) {
|
if (res.code === 0 && res.data) {
|
||||||
client.setClientId(res.data);
|
client.setClientId(res.data);
|
||||||
@@ -84,12 +84,11 @@ async function getClientId() {
|
|||||||
/**
|
/**
|
||||||
* 获取本地client_id
|
* 获取本地client_id
|
||||||
*/
|
*/
|
||||||
function getLocalClientId() {
|
async function getLocalClientId() {
|
||||||
const client = useStore().client;
|
if (client.getClientId() !== '' && client.getClientId() !== null) {
|
||||||
if (client.getClientId()) {
|
|
||||||
return client.getClientId();
|
return client.getClientId();
|
||||||
} else {
|
} else {
|
||||||
getClientId();
|
await getClientId();
|
||||||
return client.getClientId();
|
return client.getClientId();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user