This commit is contained in:
xion 2024-10-18 02:26:14 +08:00
commit 8e7277022b
9 changed files with 136 additions and 0 deletions

61
apps/store/deploy/me.js Normal file
View File

@ -0,0 +1,61 @@
import { store } from 'https://kevisual.xiongxiao.me/system/lib';
import { query } from './query.js';
export const meStore = store.create((set, get) => {
return {
open: false,
setOpen: (open) => set({ open }),
loading: false,
setLoading: (loading) => set({ loading }),
mount: false,
setMount: (mount) => set({ mount }),
me: null,
setMe: (me) => set({ me }),
getMe: async () => {
const res = await query.post({
path: 'user',
key: 'me',
});
if (res.code === 200) {
set({ me: res.data });
}
},
init: async () => {
const { loading, mount } = get();
const isLogin = location.pathname === '/user/login';
if (isLogin) return;
if (loading || mount) return;
set({ loading: true });
const res = await query.post({
path: 'user',
key: 'me',
});
set({ loading: false });
if (res.code === 200) {
set({ me: res.data, mount: true });
}
},
switchOrg: async (username, type = undefined) => {
const res = await query.post({
path: 'user',
key: 'switchOrg',
data: {
username,
type,
},
});
if (res.code === 200) {
const { token } = res.data;
query.saveToken(token);
// message.success('Switch success');
// window.location.reload();
} else {
message.error(res.message || 'Request failed');
}
},
};
}, 'me');
meStore.getState().init();

View File

@ -0,0 +1,20 @@
import { QueryClient } from 'https://kevisual.xiongxiao.me/system/lib';
const env = window.env || {};
const isDev = location.hostname === 'localhost';
const productionUrl = env?.productionUrl || 'https://envision.xiongxiao.me/api/router';
const url = isDev ? 'http://localhost:4002/api/router' : productionUrl;
export const query = new QueryClient({
url,
});
query.after((res) => {
const pathname = window.location.pathname;
if (res.code === 401 && !pathname.includes('login')) {
console.log('401');
if (env?.needLogin) {
window.location.href = env?.needLoginUrl || '/user/login';
}
}
return res;
});

14
apps/store/index.html Normal file
View File

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script type="module" src="./deploy/me.js"></script>
</body>
</html>

8
apps/store/node_modules/.vite/deps/_metadata.json generated vendored Normal file
View File

@ -0,0 +1,8 @@
{
"hash": "5db928f7",
"configHash": "f5c9a0a4",
"lockfileHash": "e3b0c442",
"browserHash": "8fd90145",
"optimized": {},
"chunks": {}
}

3
apps/store/node_modules/.vite/deps/package.json generated vendored Normal file
View File

@ -0,0 +1,3 @@
{
"type": "module"
}

13
apps/store/package.json Normal file
View File

@ -0,0 +1,13 @@
{
"name": "store",
"version": "0.0.1",
"description": "system store",
"main": "index.js",
"scripts": {
"pub": "envision switchOrg system && envision deploy ./deploy -v 0.0.1 -k store -y y",
"dev": "vite"
},
"keywords": [],
"author": "",
"license": "ISC"
}

12
package.json Normal file
View File

@ -0,0 +1,12 @@
{
"name": "system-apps",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}

3
pnpm-workspace.yaml Normal file
View File

@ -0,0 +1,3 @@
packages:
- 'packages/*'
- 'apps/*'

2
readme.md Normal file
View File

@ -0,0 +1,2 @@
# 公共的模块