chore: 完成天梯登陆与登出
This commit is contained in:
parent
9b2c728d4c
commit
0852dd98f0
@ -33,6 +33,10 @@ onMounted(async () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
widgetManager.set('Templates', {
|
||||||
|
invisible: true
|
||||||
|
});
|
||||||
|
|
||||||
// const handshake = new Postmate.Model({});
|
// const handshake = new Postmate.Model({});
|
||||||
// await handshake.then((parent) => {
|
// await handshake.then((parent) => {
|
||||||
// parent.emit('sync-context', 'Hello, World!');
|
// parent.emit('sync-context', 'Hello, World!');
|
||||||
|
@ -6,8 +6,9 @@ VITE_BASE_URL = /
|
|||||||
|
|
||||||
# 前端可见变量(必须以 VITE_ 开头)
|
# 前端可见变量(必须以 VITE_ 开头)
|
||||||
VITE_PORT = 10010
|
VITE_PORT = 10010
|
||||||
# VITE_BASE_API_URL = 'https://custom-chart-pre-api.shiyue.com/'
|
VITE_BASE_API_URL = 'https://custom-chart-pre-api.shiyue.com/'
|
||||||
VITE_BASE_API_URL = 'https://custom-chart-api.shiyuegame.com/'
|
# VITE_BASE_API_URL = 'https://custom-chart-api.shiyuegame.com/'
|
||||||
|
|
||||||
VITE_DEBUG_MODE = true
|
VITE_DEBUG_MODE = true
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,42 +1,3 @@
|
|||||||
## 安装使用
|
# 因为项目接入了天梯登陆,使用前需要申请天梯的悦码权限
|
||||||
|
|
||||||
- 安装依赖
|
天梯地址 https://auth-pro.shiyue.com/
|
||||||
|
|
||||||
```bash
|
|
||||||
pnpm install
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
- 运行
|
|
||||||
|
|
||||||
```bash
|
|
||||||
pnpm dev
|
|
||||||
```
|
|
||||||
|
|
||||||
- 打包
|
|
||||||
|
|
||||||
```bash
|
|
||||||
pnpm build
|
|
||||||
```
|
|
||||||
|
|
||||||
## vscode 配置
|
|
||||||
|
|
||||||
安装项目根目录 `.vscode` 推荐的插件,再安装 `Volar`,并禁用 `Vetur`,重启 vscode 即可。
|
|
||||||
|
|
||||||
## Git 贡献提交规范
|
|
||||||
|
|
||||||
- 参考 [vue](https://github.com/vuejs/vue/blob/dev/.github/COMMIT_CONVENTION.md) 规范 ([Angular](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-angular))
|
|
||||||
|
|
||||||
- `feat` 增加新功能
|
|
||||||
- `fix` 修复问题/BUG
|
|
||||||
- `style` 代码风格相关无影响运行结果的
|
|
||||||
- `perf` 优化/性能提升
|
|
||||||
- `refactor` 重构
|
|
||||||
- `revert` 撤销修改
|
|
||||||
- `test` 测试相关
|
|
||||||
- `docs` 文档/注释
|
|
||||||
- `chore` 依赖更新/脚手架配置修改等
|
|
||||||
- `workflow` 工作流改进
|
|
||||||
- `ci` 持续集成
|
|
||||||
- `types` 类型定义文件更改
|
|
||||||
- `wip` 开发中
|
|
||||||
|
@ -22,9 +22,14 @@
|
|||||||
import { useRoute } from 'vue-router';
|
import { useRoute } from 'vue-router';
|
||||||
import { theme } from 'ant-design-vue';
|
import { theme } from 'ant-design-vue';
|
||||||
|
|
||||||
|
import { useUserStore } from '@/store/modules/user';
|
||||||
|
|
||||||
import { LockScreen } from '@/components/basic/lockscreen';
|
import { LockScreen } from '@/components/basic/lockscreen';
|
||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
|
|
||||||
|
const userStore = useUserStore();
|
||||||
|
userStore.login();
|
||||||
|
|
||||||
const { compactAlgorithm } = theme;
|
const { compactAlgorithm } = theme;
|
||||||
</script>
|
</script>
|
||||||
|
16
apps/platform/src/io/file.ts
Normal file
16
apps/platform/src/io/file.ts
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import instance from './instance';
|
||||||
|
|
||||||
|
export const uploadFile = async (data: FormData) => {
|
||||||
|
const response = await instance.post('/api/v1/files/upload', data);
|
||||||
|
return response.data;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const deleteFile = async (id: string) => {
|
||||||
|
const response = await instance.delete(`/api/v1/files/upload/${id}`);
|
||||||
|
return response.data;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getFileList = async () => {
|
||||||
|
const response = await instance.get('/api/v1/files/upload');
|
||||||
|
return response.data;
|
||||||
|
};
|
@ -2,13 +2,10 @@ import axios from 'axios';
|
|||||||
// import { useUserStore } from '@/store/modules/user';
|
// import { useUserStore } from '@/store/modules/user';
|
||||||
// import router from '@/router';
|
// import router from '@/router';
|
||||||
import appClient from '@/io/tianti';
|
import appClient from '@/io/tianti';
|
||||||
|
import { useUserStore } from '@/store/modules/user';
|
||||||
console.log('appClient', appClient);
|
|
||||||
|
|
||||||
// axios拦截器
|
// axios拦截器
|
||||||
const { reqInterceptor, resInterceptor } = appClient.getInterceptor();
|
const { reqInterceptor, resInterceptor } = appClient.getInterceptor();
|
||||||
console.log('reqInterceptor', reqInterceptor);
|
|
||||||
console.log('resInterceptor', resInterceptor);
|
|
||||||
|
|
||||||
const baseApiUrl = import.meta.env.VITE_BASE_API_URL;
|
const baseApiUrl = import.meta.env.VITE_BASE_API_URL;
|
||||||
|
|
||||||
@ -24,6 +21,20 @@ instance.interceptors.request.use(
|
|||||||
instance.interceptors.request.use(reqInterceptor.fulfilled, reqInterceptor.rejected);
|
instance.interceptors.request.use(reqInterceptor.fulfilled, reqInterceptor.rejected);
|
||||||
|
|
||||||
// 响应拦截器
|
// 响应拦截器
|
||||||
|
instance.interceptors.response.use(
|
||||||
|
(response) => {
|
||||||
|
// 检查是否为401未授权错误
|
||||||
|
if (response.data.code === 401) {
|
||||||
|
const userStore = useUserStore();
|
||||||
|
console.log('用户未授权或登录已过期,即将跳转...');
|
||||||
|
userStore.logout();
|
||||||
|
// 返回一个永远不会resolve的Promise,防止后续代码执行
|
||||||
|
return new Promise(() => {});
|
||||||
|
}
|
||||||
|
return response;
|
||||||
|
},
|
||||||
|
(error) => Promise.reject(error),
|
||||||
|
);
|
||||||
instance.interceptors.response.use(resInterceptor.fulfilled, resInterceptor.rejected);
|
instance.interceptors.response.use(resInterceptor.fulfilled, resInterceptor.rejected);
|
||||||
|
|
||||||
// 导出实例
|
// 导出实例
|
||||||
|
@ -13,10 +13,6 @@ import { setupStore } from '@/store';
|
|||||||
import { setupI18n } from '@/locales';
|
import { setupI18n } from '@/locales';
|
||||||
import { setupAntd, setupAssets, setupGlobalMethods } from '@/plugins';
|
import { setupAntd, setupAssets, setupGlobalMethods } from '@/plugins';
|
||||||
|
|
||||||
import tianti from '@/io/tianti';
|
|
||||||
|
|
||||||
tianti.checkQuery();
|
|
||||||
|
|
||||||
dayjs.extend(customParseFormat);
|
dayjs.extend(customParseFormat);
|
||||||
dayjs.extend(utc);
|
dayjs.extend(utc);
|
||||||
dayjs.extend(timezone);
|
dayjs.extend(timezone);
|
||||||
@ -24,6 +20,7 @@ dayjs.extend(timezone);
|
|||||||
const app = createApp(App);
|
const app = createApp(App);
|
||||||
|
|
||||||
app.use(VueQueryPlugin);
|
app.use(VueQueryPlugin);
|
||||||
|
|
||||||
function setupPlugins() {
|
function setupPlugins() {
|
||||||
// 安装图标
|
// 安装图标
|
||||||
setupIcons();
|
setupIcons();
|
||||||
|
@ -3,7 +3,7 @@ import { defineStore } from 'pinia';
|
|||||||
import { useSSEStore } from './sse';
|
import { useSSEStore } from './sse';
|
||||||
import { store } from '@/store';
|
import { store } from '@/store';
|
||||||
import { resetRouter } from '@/router';
|
import { resetRouter } from '@/router';
|
||||||
import { login, logout } from '@/io';
|
import tianti from '@/io/tianti';
|
||||||
|
|
||||||
export const useUserStore = defineStore(
|
export const useUserStore = defineStore(
|
||||||
'user',
|
'user',
|
||||||
@ -13,6 +13,10 @@ export const useUserStore = defineStore(
|
|||||||
const perms = ref<string[]>([]);
|
const perms = ref<string[]>([]);
|
||||||
const userInfo = ref<Partial<API.UserEntity>>({});
|
const userInfo = ref<Partial<API.UserEntity>>({});
|
||||||
|
|
||||||
|
const setToken = (_token: string) => {
|
||||||
|
token.value = _token;
|
||||||
|
};
|
||||||
|
|
||||||
/** 清空登录态(token、userInfo...) */
|
/** 清空登录态(token、userInfo...) */
|
||||||
const clearLoginStatus = () => {
|
const clearLoginStatus = () => {
|
||||||
token.value = '';
|
token.value = '';
|
||||||
@ -23,21 +27,18 @@ export const useUserStore = defineStore(
|
|||||||
localStorage.clear();
|
localStorage.clear();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
/** 登录成功保存token */
|
|
||||||
const setToken = (_token: string) => {
|
|
||||||
token.value = _token;
|
|
||||||
};
|
|
||||||
/** 登录 */
|
/** 登录 */
|
||||||
const login = async (params: any) => {
|
const login = async () => {
|
||||||
const data = await login(params);
|
tianti.checkQuery();
|
||||||
console.log('data', data);
|
setTimeout(() => {
|
||||||
// @ts-ignore
|
const token = localStorage.getItem('y-code-access-token');
|
||||||
setToken(data.msg);
|
setToken(token || '');
|
||||||
|
}, 0);
|
||||||
};
|
};
|
||||||
/** 登出 */
|
/** 登出 */
|
||||||
const logout = async () => {
|
const logout = async () => {
|
||||||
sseStore.closeEventSource();
|
sseStore.closeEventSource();
|
||||||
await logout();
|
await tianti.logout();
|
||||||
clearLoginStatus();
|
clearLoginStatus();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user