add submodule adn remote redirecto to login

This commit is contained in:
xion 2025-03-22 13:33:32 +08:00
parent cf543c7f1d
commit 2ee8ec7a29
15 changed files with 217 additions and 813 deletions

4
.gitignore vendored
View File

@ -24,4 +24,6 @@ dist-ssr
*.sw?
tsconfig.app.tsbuildinfo
tsconfig.node.tsbuildinfo
tsconfig.node.tsbuildinfo
.turbo

6
.gitmodules vendored Normal file
View File

@ -0,0 +1,6 @@
[submodule "submodules/query-login"]
path = submodules/query-login
url = git@git.xiongxiao.me:kevisual/kevsiual-query-login.git
[submodule "submodules/query-config"]
path = submodules/query-config
url = git@git.xiongxiao.me:kevisual/kevsiual-query-config.git

0
.submodules Normal file
View File

View File

@ -10,32 +10,28 @@
"lint": "eslint .",
"preview": "vite preview",
"prepub": "envision switch root",
"pub": "envision deploy ./dist -k center -v 0.0.9 -u -o root"
"pub": "envision deploy ./dist -k center -v 0.0.9 -u -o root",
"turbo:dev": "turbo dev:lib",
"turbo:build": "turbo build --filter=submodules/**"
},
"dependencies": {
"@ant-design/icons": "^6.0.0",
"@emotion/react": "^11.14.0",
"@emotion/styled": "^11.14.0",
"@icon-park/react": "^1.4.2",
"@kevisual/center-components": "workspace:*",
"@kevisual/codemirror": "workspace:*",
"@kevisual/container": "1.0.0",
"@kevisual/query": "^0.0.13",
"@kevisual/query": "^0.0.14",
"@kevisual/query-config": "workspace:*",
"@kevisual/query-login": "workspace:*",
"@kevisual/resources": "workspace:*",
"@kevisual/system-ui": "^0.0.3",
"@kevisual/ui": "^0.0.2",
"@monaco-editor/react": "^4.7.0",
"@mui/material": "^6.4.8",
"@tailwindcss/vite": "^4.0.15",
"@uiw/react-textarea-code-editor": "^3.1.0",
"@xyflow/react": "^12.4.4",
"antd": "^5.24.4",
"classnames": "^2.5.1",
"clsx": "^2.1.1",
"copy-to-clipboard": "^3.3.3",
"d3": "^7.9.0",
"dayjs": "^1.11.13",
"eventemitter3": "^5.0.1",
"i18next": "^24.2.3",
@ -57,10 +53,7 @@
"zustand": "^5.0.3"
},
"devDependencies": {
"@eslint/js": "^9.22.0",
"@tailwindcss/aspect-ratio": "^0.4.2",
"@tailwindcss/typography": "^0.5.16",
"@types/d3": "^7.4.3",
"@eslint/js": "^9.23.0",
"@types/js-yaml": "^4.0.9",
"@types/lodash-es": "^4.17.12",
"@types/node": "^22.13.11",
@ -71,7 +64,7 @@
"@vitejs/plugin-react": "^4.3.4",
"autoprefixer": "^10.4.21",
"cross-env": "^7.0.3",
"eslint": "^9.22.0",
"eslint": "^9.23.0",
"eslint-plugin-react-hooks": "^5.2.0",
"eslint-plugin-react-refresh": "^0.4.19",
"globals": "^16.0.0",
@ -83,8 +76,10 @@
"tailwind-merge": "^3.0.2",
"tailwindcss": "^4.0.15",
"tailwindcss-animate": "^1.0.7",
"turbo": "^2.4.4",
"typescript": "^5.8.2",
"typescript-eslint": "^8.27.0",
"vite": "^6.2.2"
}
},
"packageManager": "pnpm@10.6.5"
}

View File

@ -11,5 +11,5 @@ query.afterResponse = async (response) => {
noMsg: true,
};
}
return response;
return response as any;
};

View File

@ -1,24 +1,42 @@
import { toast } from 'react-toastify';
import { useTranslation } from 'react-i18next';
// Custom message component
const LoginMessage = () => {
const LoginMessage = (props: ToastLoginProps) => {
const { t } = useTranslation();
const handleClick = () => {
const currentUrl = window.location.href;
console.log(currentUrl);
const redirect = encodeURIComponent(currentUrl);
console.log('redirect', redirect);
const newUrl = location.origin + '/user/login/?redirect=' + redirect;
const redirect = encodeURIComponent(props?.redirectUrl || currentUrl);
const loginUrl = props?.loginUrl || '/user/login/';
const newUrl = location.origin + loginUrl + '?redirect=' + redirect;
window.open(newUrl, '_self');
};
return (
<div className='msg-container' onClick={handleClick} style={{ cursor: 'pointer' }}>
<p className='msg-title'>Please login</p>
<p className='msg-description'>Click here to go to the login page.</p>
<p className='msg-title'>{t('Please login')}</p>
<p className='msg-description'>{t('Click here to go to the login page.')}</p>
</div>
);
};
export const toastLogin = () => {
toast.info(<LoginMessage />);
type ToastLoginProps = {
/**
* , /user/login
*/
loginUrl?: string;
/**
* ,
*/
redirectUrl?: string;
};
/**
*
* @param props
* @example
* toastLogin({
* loginUrl: '/user/login/',
* redirectUrl: window.location.href,
* });
*/
export const toastLogin = (props: ToastLoginProps = {}) => {
toast.info(<LoginMessage {...props} />);
};

870
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -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);
};
},
};

View File

@ -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;
}

View File

@ -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,
});

View File

@ -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');

View File

@ -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');
// 跳到某一个页面

@ -0,0 +1 @@
Subproject commit f993b2466ec4680a0a6ef044ad524130a4c24c0a

@ -0,0 +1 @@
Subproject commit a457dbabe931327b3b644d88e07c41ce82af4e76

17
turbo.json Normal file
View File

@ -0,0 +1,17 @@
{
"$schema": "https://turbo.build/schema.json",
"tasks": {
"build": {
"dependsOn": [
"^build"
],
"outputs": [
"dist/**"
]
},
"dev:lib": {
"persistent": true,
"cache": false
}
}
}