add submodule adn remote redirecto to login
This commit is contained in:
@@ -1,2 +1,22 @@
|
||||
import { message } from '@kevisual/system-ui/dist/message';
|
||||
export { message };
|
||||
import { toast } from 'react-toastify';
|
||||
|
||||
export const message = {
|
||||
success: (message: string) => {
|
||||
toast.success(message);
|
||||
},
|
||||
error: (message: string) => {
|
||||
toast.error(message);
|
||||
},
|
||||
warning: (message: string) => {
|
||||
toast.warning(message);
|
||||
},
|
||||
info: (message: string) => {
|
||||
toast.info(message);
|
||||
},
|
||||
loading: (message: string) => {
|
||||
const toastId = toast.loading(message);
|
||||
return () => {
|
||||
toast.dismiss(toastId);
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import { QueryClient } from '@kevisual/query';
|
||||
import { modal } from './redirect-to-login';
|
||||
import { create } from 'zustand';
|
||||
import { message } from './message';
|
||||
import { QueryLogin } from '@kevisual/query-login';
|
||||
|
||||
import { toastLogin } from '@kevisual/resources/pages/message/ToastLogin.tsx';
|
||||
export const query = new QueryClient();
|
||||
|
||||
/**
|
||||
@@ -41,7 +39,7 @@ query.afterResponse = async (res, ctx) => {
|
||||
const queryLoginRes = await queryLogin.afterCheck401ToRefreshToken(res, ctx);
|
||||
query.stop = false;
|
||||
if (queryLoginRes.code === 401) {
|
||||
modal.setOpen(true);
|
||||
toastLogin();
|
||||
}
|
||||
return queryLoginRes;
|
||||
}
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
import { DialogModal } from '@kevisual/ui';
|
||||
import '@kevisual/ui/dist/index.css';
|
||||
import { basename } from './basename';
|
||||
const content = document.createElement('div');
|
||||
|
||||
const loginHref = `${basename}/user/login`;
|
||||
content.innerHTML = `
|
||||
<div class="bg-white p-8 rounded-sm shadow-md w-full max-w-md text-center">
|
||||
<h2 class="text-2xl font-bold mb-4">Token 无效</h2>
|
||||
<p class="mb-6">您的登录凭证已失效,请重新登录。</p>
|
||||
<a href="${loginHref}" class="inline-block bg-red-500 text-white py-2 px-4 rounded-sm hover:bg-red-600 transition duration-200">确定</a>
|
||||
</div>
|
||||
`;
|
||||
export const modal = DialogModal.render(content, {
|
||||
id: 'redirect-to-login',
|
||||
contentStyle: {
|
||||
width: 'unset',
|
||||
},
|
||||
dialogTitleStyle: {
|
||||
display: 'none',
|
||||
padding: '0',
|
||||
},
|
||||
dialogContentStyle: {
|
||||
padding: '0',
|
||||
},
|
||||
mask: true,
|
||||
open: false,
|
||||
});
|
||||
@@ -109,17 +109,13 @@ export const useAppVersionStore = create<AppVersionStore>((set, get) => {
|
||||
}
|
||||
},
|
||||
publishVersion: async (data) => {
|
||||
const { getList } = get();
|
||||
const loaded = message.loading('Publishing...', 0);
|
||||
const res = await query.post({
|
||||
path: 'app',
|
||||
key: 'publish',
|
||||
data,
|
||||
});
|
||||
setTimeout(loaded, 200);
|
||||
if (res.code === 200) {
|
||||
message.success('Success');
|
||||
// getList();
|
||||
get().getApp(get().key, true);
|
||||
} else {
|
||||
message.error(res.message || 'Request failed');
|
||||
|
||||
@@ -54,9 +54,7 @@ export const useLoginStore = create<LoginStore>((set, get) => {
|
||||
return;
|
||||
}
|
||||
set({ loading: true });
|
||||
const loaded = message.loading('loading...', 0);
|
||||
const res = await queryLogin.login({ username, password });
|
||||
setTimeout(loaded, 200);
|
||||
if (res.code === 200) {
|
||||
message.success('Success');
|
||||
set({ isLogin: true });
|
||||
@@ -78,9 +76,7 @@ export const useLoginStore = create<LoginStore>((set, get) => {
|
||||
},
|
||||
register: async () => {
|
||||
set({ loading: true });
|
||||
const loaded = message.loading('loading...', 0);
|
||||
const res = await query.post({ path: 'user', key: 'register' });
|
||||
setTimeout(loaded, 200);
|
||||
if (res.code === 200) {
|
||||
message.success('Success');
|
||||
// 跳到某一个页面
|
||||
|
||||
Reference in New Issue
Block a user