diff --git a/src/api/axios.ts b/src/api/axios.ts index 52b932fc..8557403e 100644 --- a/src/api/axios.ts +++ b/src/api/axios.ts @@ -8,12 +8,6 @@ import { redirectErrorPage, getLocalStorage, routerTurnByName, httpErrorHandle } import { fetchAllowList } from './axios.config' import includes from 'lodash/includes' -interface MyResponseType { - code: number; - msg: string; - data: any; -} - const axiosInstance = axios.create({ baseURL: `${import.meta.env.PROD ? import.meta.env.VITE_PRO_PATH : ''}${axiosPre}`, timeout: ResultEnum.TIMEOUT, diff --git a/src/hooks/useChartDataFetch.hook.ts b/src/hooks/useChartDataFetch.hook.ts index ac522475..e9b5a58c 100644 --- a/src/hooks/useChartDataFetch.hook.ts +++ b/src/hooks/useChartDataFetch.hook.ts @@ -43,7 +43,7 @@ export const useChartDataFetch = ( if (!completePath) return fetchInterval = setInterval(async () => { - const res:any = await http(requestHttpType.value)(completePath || '', {}) + const res = await http(requestHttpType.value)(completePath || '', {}) as unknown as MyResponseType if (res.data) { // 是否是 Echarts 组件 const isECharts = diff --git a/src/hooks/useSystemInit.hook.ts b/src/hooks/useSystemInit.hook.ts index 7e8f7573..72f2d0fa 100644 --- a/src/hooks/useSystemInit.hook.ts +++ b/src/hooks/useSystemInit.hook.ts @@ -10,7 +10,7 @@ export const useSystemInit = async () => { // 获取 OSS 信息 const getOssUrl = async () => { - const res: any = await ossUrlApi({}) + const res = await ossUrlApi({}) as unknown as MyResponseType if (res.code === ResultEnum.SUCCESS) { systemStore.setItem(SystemStoreEnum.FETCH_INFO, { OSSUrl: res.data?.bucketURL diff --git a/src/utils/router.ts b/src/utils/router.ts index 6c41b229..a748830a 100644 --- a/src/utils/router.ts +++ b/src/utils/router.ts @@ -106,7 +106,7 @@ export const reloadRoutePage = () => { */ export const logout = async () => { try { - const res:any = await logoutApi() + const res = await logoutApi() as unknown as MyResponseType if(res.code === ResultEnum.SUCCESS) { window['$message'].success(window['$t']('global.logout_success')) clearCookie(RequestHttpHeaderEnum.COOKIE) diff --git a/src/views/chart/ContentConfigurations/components/CanvasPage/index.vue b/src/views/chart/ContentConfigurations/components/CanvasPage/index.vue index 25a75aac..c4caad4d 100644 --- a/src/views/chart/ContentConfigurations/components/CanvasPage/index.vue +++ b/src/views/chart/ContentConfigurations/components/CanvasPage/index.vue @@ -288,7 +288,7 @@ const customRequest = (options: UploadCustomRequestOptions) => { ) let uploadParams = new FormData() uploadParams.append('object', newNameFile) - const uploadRes:any = await uploadFile(systemStore.getFetchInfo.OSSUrl ,uploadParams) + const uploadRes = await uploadFile(systemStore.getFetchInfo.OSSUrl ,uploadParams) as unknown as MyResponseType if(uploadRes.code === ResultEnum.SUCCESS) { chartEditStore.setEditCanvasConfig( diff --git a/src/views/chart/ContentHeader/headerTitle/index.vue b/src/views/chart/ContentHeader/headerTitle/index.vue index 87c7884c..3e3163df 100644 --- a/src/views/chart/ContentHeader/headerTitle/index.vue +++ b/src/views/chart/ContentHeader/headerTitle/index.vue @@ -61,10 +61,10 @@ const handleFocus = () => { const handleBlur = async () => { focus.value = false chartEditStore.setProjectInfo(ProjectInfoEnum.PROJECT_NAME, title.value || '') - const res:any = await updateProjectApi({ + const res = await updateProjectApi({ id: fetchRouteParamsLocation(), projectName: title.value, - }) + }) as unknown as MyResponseType if(res.code === ResultEnum.SUCCESS) { dataSyncUpdate() } else { diff --git a/src/views/chart/hooks/useSync.hook.ts b/src/views/chart/hooks/useSync.hook.ts index 528e60ff..ab551d56 100644 --- a/src/views/chart/hooks/useSync.hook.ts +++ b/src/views/chart/hooks/useSync.hook.ts @@ -95,7 +95,7 @@ export const useSync = () => { const dataSyncFetch = async () => { chartEditStore.setEditCanvas(EditCanvasTypeEnum.SAVE_STATUS, SyncEnum.START) try { - const res: any = await fetchProjectApi({ projectId: fetchRouteParamsLocation() }) + const res = await fetchProjectApi({ projectId: fetchRouteParamsLocation() }) as unknown as MyResponseType if (res.code === ResultEnum.SUCCESS) { if (res.data) { updateStoreInfo(res.data) @@ -135,7 +135,7 @@ export const useSync = () => { // 上传预览图 let uploadParams = new FormData() uploadParams.append('object', base64toFile(canvasImage.toDataURL(), `${fetchRouteParamsLocation()}_index_preview.png`)) - const uploadRes:any = await uploadFile(systemStore.getFetchInfo.OSSUrl, uploadParams) + const uploadRes = await uploadFile(systemStore.getFetchInfo.OSSUrl, uploadParams) as unknown as MyResponseType // 保存预览图 if(uploadRes.code === ResultEnum.SUCCESS) { await updateProjectApi({ @@ -148,7 +148,7 @@ export const useSync = () => { let params = new FormData() params.append('projectId', fetchRouteParamsLocation()) params.append('content', JSON.stringify(chartEditStore.getStorageInfo || {})) - const res: any = await saveProjectApi(params) + const res= await saveProjectApi(params) as unknown as MyResponseType if (res.code === ResultEnum.SUCCESS) { // 成功状态 diff --git a/src/views/login/index.vue b/src/views/login/index.vue index 6a881a6e..eaf1ab08 100644 --- a/src/views/login/index.vue +++ b/src/views/login/index.vue @@ -204,10 +204,10 @@ const handleSubmit = async (e: Event) => { const { username, password } = formInline loading.value = true // 提交请求 - const res:any = await loginApi({ + const res = await loginApi({ username, password - }) + }) as unknown as MyResponseType if(res.data) { const { tokenValue } = res.data.token const { nickname, username, id } = res.data.userinfo diff --git a/src/views/preview/utils/storage.ts b/src/views/preview/utils/storage.ts index 798ed751..b708488c 100644 --- a/src/views/preview/utils/storage.ts +++ b/src/views/preview/utils/storage.ts @@ -18,7 +18,7 @@ export const getSessionStorageInfo = async () => { // 是否本地预览 if (!storageList) { // 接口调用 - const res: any = await fetchProjectApi({ projectId: id }) + const res = await fetchProjectApi({ projectId: id }) as unknown as MyResponseType if (res.code === ResultEnum.SUCCESS) { const { content, state } = res.data if (state === -1) { diff --git a/src/views/project/items/components/ProjectItemsList/hooks/useData.hook.ts b/src/views/project/items/components/ProjectItemsList/hooks/useData.hook.ts index 29a87f1f..9c051846 100644 --- a/src/views/project/items/components/ProjectItemsList/hooks/useData.hook.ts +++ b/src/views/project/items/components/ProjectItemsList/hooks/useData.hook.ts @@ -24,10 +24,10 @@ export const useDataListInit = () => { // 数据请求 const fetchList = async () => { loading.value = true - const res: any = await projectListApi({ + const res = await projectListApi({ page: paginat.page, limit: paginat.limit - }) + }) as unknown as MyResponseType if (res.data) { const { count } = res paginat.count = count @@ -86,11 +86,11 @@ export const useDataListInit = () => { // 发布处理 const releaseHandle = async (cardData: Chartype, index: number) => { const { id, release } = cardData - const res: any = await changeProjectReleaseApi({ + const res = await changeProjectReleaseApi({ id: id, // [-1未发布, 1发布] state: !release ? 1 : -1 - }) + }) as unknown as MyResponseType if (res.code === ResultEnum.SUCCESS) { list.value = [] fetchList() 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 6d6384e0..d1b48531 100644 --- a/src/views/project/layout/components/ProjectLayoutCreate/components/CreateModal/index.vue +++ b/src/views/project/layout/components/ProjectLayoutCreate/components/CreateModal/index.vue @@ -89,14 +89,14 @@ const btnHandle = async (key: string) => { case ChartEnum.CHART_HOME_NAME: try { // 新增项目 - const res:any = await createProjectApi({ + const res = await createProjectApi({ // 项目名称 projectName: getUUID(), // remarks remarks: null, // 图片地址 indexImage: null, - }) + }) as unknown as MyResponseType if(res.code === ResultEnum.SUCCESS) { window['$message'].success(window['$t']('project.create_success')) diff --git a/types/global.d.ts b/types/global.d.ts index 74863473..b361c932 100644 --- a/types/global.d.ts +++ b/types/global.d.ts @@ -7,4 +7,11 @@ interface Window { $vue: any } + +declare interface MyResponseType { + code: number; + msg: string; + data: any; +} + declare type Recordable = Record \ No newline at end of file