From 39023832e3a98796672f7d74030d866110c622c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A5=94=E8=B7=91=E7=9A=84=E9=9D=A2=E6=9D=A1?= <1262327911@qq.com> Date: Sat, 21 May 2022 18:03:15 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=EF=BC=8C=E4=BF=AE=E6=94=B9i8n=E9=83=A8?= =?UTF-8?q?=E5=88=86=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/axios.ts | 16 ++++++---- src/api/path/project.ts | 2 +- src/i18n/en/index.ts | 6 ++++ src/i18n/en/login.ts | 4 +-- src/i18n/en/project.ts | 4 ++- src/i18n/zh/index.ts | 6 ++++ src/i18n/zh/project.ts | 2 ++ src/utils/router.ts | 2 +- .../components/CreateModal/index.vue | 29 +++++++++++++++---- 9 files changed, 55 insertions(+), 16 deletions(-) diff --git a/src/api/axios.ts b/src/api/axios.ts index ef102ed0..659b3985 100644 --- a/src/api/axios.ts +++ b/src/api/axios.ts @@ -43,27 +43,31 @@ axiosInstance.interceptors.response.use( const { code } = res.data as { code: number } // 成功 - if (code === ResultEnum.DATA_SUCCESS) { + if (code === ResultEnum.SUCCESS) { return Promise.resolve(res.data) } // 登录过期 - if (code === ResultEnum.SERVER_FORBIDDEN) { + if (code === ResultEnum.TOKEN_OVERDUE) { + window['$message'].error(window['$t']('http.token_overdue_message')) routerTurnByName(PageEnum.BASE_LOGIN_NAME) - return Promise.reject(res.data) + return } - // 重定向 + // 固定错误码重定向 if (ErrorPageNameMap.get(code)) { redirectErrorPage(code) + return } - + + // 提示错误 + window['$message'].error(window['$t']((res.data as any).msg)) return Promise.resolve(res.data) }, (err: AxiosResponse) => { const { code } = err.data as { code: number } if (ErrorPageNameMap.get(code)) redirectErrorPage(code) - window['$message'].error('接口异常,请检查!') + window['$message'].error(window['$t']('http.error_message')) Promise.reject(err) } ) diff --git a/src/api/path/project.ts b/src/api/path/project.ts index 40f90649..58c83c4b 100644 --- a/src/api/path/project.ts +++ b/src/api/path/project.ts @@ -5,7 +5,7 @@ import { RequestHttpEnum, ModuleTypeEnum } from '@/enums/httpEnum' // * 新增项目 export const createProjectApi = async (data: object) => { try { - const res = await http(RequestHttpEnum.POST)(`${ModuleTypeEnum.SYSTEM}/project/create`, data); + const res = await http(RequestHttpEnum.POST)(`${ModuleTypeEnum.PROJECT}/create`, data); return res; } catch { httpErrorHandle(); diff --git a/src/i18n/en/index.ts b/src/i18n/en/index.ts index f398a737..c55b33bb 100644 --- a/src/i18n/en/index.ts +++ b/src/i18n/en/index.ts @@ -27,8 +27,14 @@ const global = { r_more: 'More', } +const http = { + error_message: 'The interface is abnormal, please check the interface!', + token_overdue_message: 'Login expired, please log in again!' +} + export default { global, + http, login, project } diff --git a/src/i18n/en/login.ts b/src/i18n/en/login.ts index d6f7b750..eabe86c0 100644 --- a/src/i18n/en/login.ts +++ b/src/i18n/en/login.ts @@ -2,6 +2,6 @@ export default { desc: "Login", form_auto: "Sign in automatically", form_button: "Login", - login_success: "Login success", - login_message: "Please complete the letter", + login_success: "Login success!", + login_message: "Please complete the letter!", } \ No newline at end of file diff --git a/src/i18n/en/project.ts b/src/i18n/en/project.ts index 3b7d367b..dae8146d 100644 --- a/src/i18n/en/project.ts +++ b/src/i18n/en/project.ts @@ -1,6 +1,8 @@ export default { create_btn: 'Creat', - create_tip: 'Please select a content for development', + create_success: 'Creat Success!', + create_failure: 'Failed to create, please try again later!', + create_tip: 'Please select a content for development!', project: 'Project', my: 'My', new_project: 'New Project', diff --git a/src/i18n/zh/index.ts b/src/i18n/zh/index.ts index 0fd4dd05..81918edc 100644 --- a/src/i18n/zh/index.ts +++ b/src/i18n/zh/index.ts @@ -26,8 +26,14 @@ const global = { r_more: '更多', } +const http = { + error_message: '接口异常,请检查!', + token_overdue_message: '登录过期,请重新登录!' +} + export default { global, + http, login, project } diff --git a/src/i18n/zh/project.ts b/src/i18n/zh/project.ts index 49e86567..d6f25680 100644 --- a/src/i18n/zh/project.ts +++ b/src/i18n/zh/project.ts @@ -1,6 +1,8 @@ export default { // aside create_btn: '新建', + create_success: '新建成功!', + create_failure: '新建失败,请稍后重试!', create_tip: '从哪里出发好呢?', project: '项目', my: '我的', diff --git a/src/utils/router.ts b/src/utils/router.ts index 3f1d95b0..f4a1396c 100644 --- a/src/utils/router.ts +++ b/src/utils/router.ts @@ -107,7 +107,7 @@ export const reloadRoutePage = () => { export const logout = async () => { const res:any = await logoutApi() if(res.code === ResultEnum.SUCCESS) { - window['$message'].success((`${window.$t('global.logout_success')}!`)) + window['$message'].success((`${window['$t']('global.logout_success')}!`)) } clearCookie(RequestHttpHeaderEnum.COOKIE) clearLocalStorage(StorageEnum.GO_SYSTEM_STORE) diff --git a/src/views/project/layout/components/ProjectLayoutCreate/components/CreateModal/index.vue b/src/views/project/layout/components/ProjectLayoutCreate/components/CreateModal/index.vue index d8cae3ff..dd6af50f 100644 --- a/src/views/project/layout/components/ProjectLayoutCreate/components/CreateModal/index.vue +++ b/src/views/project/layout/components/ProjectLayoutCreate/components/CreateModal/index.vue @@ -38,7 +38,9 @@ import { watch } from 'vue' import { icon } from '@/plugins' import { PageEnum, ChartEnum } from '@/enums/pageEnum' +import { ResultEnum } from '@/enums/httpEnum' import { fetchPathByName, routerTurnByPath, renderLang, getUUID } from '@/utils' +import { createProjectApi } from '@/api/path/project' const { FishIcon, CloseIcon } = icon.ionicons5 const { StoreIcon, ObjectStorageIcon } = icon.carbon @@ -82,13 +84,30 @@ const closeHandle = () => { } // 处理按钮点击 -const btnHandle = (key: string) => { +const btnHandle = async (key: string) => { switch (key) { case ChartEnum.CHART_HOME_NAME: - const id = getUUID() - const path = fetchPathByName(ChartEnum.CHART_HOME_NAME, 'href') - routerTurnByPath(path, [id], undefined, true) - closeHandle() + try { + // 新增项目 + const res:any = await createProjectApi({ + // 项目名称 + projectName: getUUID(), + // remarks + remarks: null, + // 图片地址 + indexImage: null, + }) + if(res.code === ResultEnum.SUCCESS) { + window['$message'].success(window['$t']('project.create_success')) + + const { id } = res + const path = fetchPathByName(ChartEnum.CHART_HOME_NAME, 'href') + routerTurnByPath(path, [id], undefined, true) + closeHandle() + } + } catch (error) { + window['$message'].error(window['$t']('project.create_failure')) + } break; } }