From 0852dd98f0110b39133655ab10dd51ccd52ad4e0 Mon Sep 17 00:00:00 2001 From: wangxuefeng Date: Thu, 6 Mar 2025 17:58:47 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E5=AE=8C=E6=88=90=E5=A4=A9=E6=A2=AF?= =?UTF-8?q?=E7=99=BB=E9=99=86=E4=B8=8E=E7=99=BB=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/designer/src/views/index.vue | 4 +++ apps/platform/.env.development | 5 +-- apps/platform/README.md | 43 ++----------------------- apps/platform/src/App.vue | 5 +++ apps/platform/src/io/file.ts | 16 +++++++++ apps/platform/src/io/instance.ts | 19 ++++++++--- apps/platform/src/main.ts | 5 +-- apps/platform/src/store/modules/user.ts | 23 ++++++------- 8 files changed, 58 insertions(+), 62 deletions(-) create mode 100644 apps/platform/src/io/file.ts diff --git a/apps/designer/src/views/index.vue b/apps/designer/src/views/index.vue index 3c2c6c5..7e7d928 100644 --- a/apps/designer/src/views/index.vue +++ b/apps/designer/src/views/index.vue @@ -33,6 +33,10 @@ onMounted(async () => { } }); + widgetManager.set('Templates', { + invisible: true + }); + // const handshake = new Postmate.Model({}); // await handshake.then((parent) => { // parent.emit('sync-context', 'Hello, World!'); diff --git a/apps/platform/.env.development b/apps/platform/.env.development index e0db715..d5af01a 100644 --- a/apps/platform/.env.development +++ b/apps/platform/.env.development @@ -6,8 +6,9 @@ VITE_BASE_URL = / # 前端可见变量(必须以 VITE_ 开头) VITE_PORT = 10010 -# 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-pre-api.shiyue.com/' +# VITE_BASE_API_URL = 'https://custom-chart-api.shiyuegame.com/' + VITE_DEBUG_MODE = true diff --git a/apps/platform/README.md b/apps/platform/README.md index 457b449..bf528a1 100644 --- a/apps/platform/README.md +++ b/apps/platform/README.md @@ -1,42 +1,3 @@ -## 安装使用 +# 因为项目接入了天梯登陆,使用前需要申请天梯的悦码权限 -- 安装依赖 - -```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` 开发中 +天梯地址 https://auth-pro.shiyue.com/ diff --git a/apps/platform/src/App.vue b/apps/platform/src/App.vue index 590077c..215f67f 100644 --- a/apps/platform/src/App.vue +++ b/apps/platform/src/App.vue @@ -22,9 +22,14 @@ import { useRoute } from 'vue-router'; import { theme } from 'ant-design-vue'; + import { useUserStore } from '@/store/modules/user'; + import { LockScreen } from '@/components/basic/lockscreen'; const route = useRoute(); + const userStore = useUserStore(); + userStore.login(); + const { compactAlgorithm } = theme; diff --git a/apps/platform/src/io/file.ts b/apps/platform/src/io/file.ts new file mode 100644 index 0000000..fc0ff76 --- /dev/null +++ b/apps/platform/src/io/file.ts @@ -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; +}; diff --git a/apps/platform/src/io/instance.ts b/apps/platform/src/io/instance.ts index 0d091f7..68e980b 100644 --- a/apps/platform/src/io/instance.ts +++ b/apps/platform/src/io/instance.ts @@ -2,13 +2,10 @@ import axios from 'axios'; // import { useUserStore } from '@/store/modules/user'; // import router from '@/router'; import appClient from '@/io/tianti'; - -console.log('appClient', appClient); +import { useUserStore } from '@/store/modules/user'; // axios拦截器 const { reqInterceptor, resInterceptor } = appClient.getInterceptor(); -console.log('reqInterceptor', reqInterceptor); -console.log('resInterceptor', resInterceptor); 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.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); // 导出实例 diff --git a/apps/platform/src/main.ts b/apps/platform/src/main.ts index c0cc2f7..13f8bad 100644 --- a/apps/platform/src/main.ts +++ b/apps/platform/src/main.ts @@ -13,10 +13,6 @@ import { setupStore } from '@/store'; import { setupI18n } from '@/locales'; import { setupAntd, setupAssets, setupGlobalMethods } from '@/plugins'; -import tianti from '@/io/tianti'; - -tianti.checkQuery(); - dayjs.extend(customParseFormat); dayjs.extend(utc); dayjs.extend(timezone); @@ -24,6 +20,7 @@ dayjs.extend(timezone); const app = createApp(App); app.use(VueQueryPlugin); + function setupPlugins() { // 安装图标 setupIcons(); diff --git a/apps/platform/src/store/modules/user.ts b/apps/platform/src/store/modules/user.ts index 276c9c8..4ff51ea 100644 --- a/apps/platform/src/store/modules/user.ts +++ b/apps/platform/src/store/modules/user.ts @@ -3,7 +3,7 @@ import { defineStore } from 'pinia'; import { useSSEStore } from './sse'; import { store } from '@/store'; import { resetRouter } from '@/router'; -import { login, logout } from '@/io'; +import tianti from '@/io/tianti'; export const useUserStore = defineStore( 'user', @@ -13,6 +13,10 @@ export const useUserStore = defineStore( const perms = ref([]); const userInfo = ref>({}); + const setToken = (_token: string) => { + token.value = _token; + }; + /** 清空登录态(token、userInfo...) */ const clearLoginStatus = () => { token.value = ''; @@ -23,21 +27,18 @@ export const useUserStore = defineStore( localStorage.clear(); }); }; - /** 登录成功保存token */ - const setToken = (_token: string) => { - token.value = _token; - }; /** 登录 */ - const login = async (params: any) => { - const data = await login(params); - console.log('data', data); - // @ts-ignore - setToken(data.msg); + const login = async () => { + tianti.checkQuery(); + setTimeout(() => { + const token = localStorage.getItem('y-code-access-token'); + setToken(token || ''); + }, 0); }; /** 登出 */ const logout = async () => { sseStore.closeEventSource(); - await logout(); + await tianti.logout(); clearLoginStatus(); };