From 7c5a66978e7b74b0772ef8e0e1af8392a48f2c01 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: Sun, 22 May 2022 15:25:07 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/axios.ts | 4 +- src/api/path/project.ts | 10 +++ src/utils/http.ts | 2 +- .../ProjectItemsList/hooks/useData.hook.ts | 63 ++++++++++--------- .../components/ProjectItemsList/index.vue | 2 +- 5 files changed, 48 insertions(+), 33 deletions(-) diff --git a/src/api/axios.ts b/src/api/axios.ts index 659b3985..d84b4d67 100644 --- a/src/api/axios.ts +++ b/src/api/axios.ts @@ -4,7 +4,7 @@ import { PageEnum, ErrorPageNameMap } from "@/enums/pageEnum" import { StorageEnum } from '@/enums/storageEnum' import { axiosPre } from '@/settings/httpSetting' import { SystemStoreEnum, SystemStoreUserInfoEnum } from '@/store/modules/systemStore/systemStore.d' -import { redirectErrorPage, getLocalStorage, routerTurnByName } from '@/utils' +import { redirectErrorPage, getLocalStorage, routerTurnByName, httpErrorHandle } from '@/utils' import { fetchAllowList } from './axios.config' import includes from 'lodash/includes' @@ -67,7 +67,7 @@ axiosInstance.interceptors.response.use( (err: AxiosResponse) => { const { code } = err.data as { code: number } if (ErrorPageNameMap.get(code)) redirectErrorPage(code) - window['$message'].error(window['$t']('http.error_message')) + httpErrorHandle() Promise.reject(err) } ) diff --git a/src/api/path/project.ts b/src/api/path/project.ts index 902e412a..acf6762a 100644 --- a/src/api/path/project.ts +++ b/src/api/path/project.ts @@ -20,4 +20,14 @@ export const createProjectApi = async (data: object) => { } catch { httpErrorHandle(); } +} + +// * 删除项目 +export const deleteProjectApi = async (data: object) => { + try { + const res = await http(RequestHttpEnum.DELETE)(`${ModuleTypeEnum.PROJECT}/delete`, data); + return res; + } catch { + httpErrorHandle(); + } } \ No newline at end of file diff --git a/src/utils/http.ts b/src/utils/http.ts index a8a114ca..8e92db7b 100644 --- a/src/utils/http.ts +++ b/src/utils/http.ts @@ -2,5 +2,5 @@ * * 请求失败统一处理 */ export const httpErrorHandle = () => { - window['$message'].error('请求失败,请稍后重试!') + window['$message'].error(window['$t']('http.error_message')) } \ No newline at end of file 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 1957f364..3a740275 100644 --- a/src/views/project/items/components/ProjectItemsList/hooks/useData.hook.ts +++ b/src/views/project/items/components/ProjectItemsList/hooks/useData.hook.ts @@ -1,8 +1,9 @@ import { ref, reactive } from 'vue'; -import { goDialog } from '@/utils' +import { goDialog, httpErrorHandle } from '@/utils' import { DialogEnum } from '@/enums/pluginEnum' -import { projectListApi } from '@/api/path/project' -import { ChartList } from '../../../index.d' +import { projectListApi, deleteProjectApi } from '@/api/path/project' +import { Chartype, ChartList } from '../../../index.d' +import { ResultEnum } from '@/enums/httpEnum' // 数据初始化 export const useDataListInit = () => { @@ -20,28 +21,25 @@ export const useDataListInit = () => { // 数据请求 const fetchList = async () => { - try { - const res: any = await projectListApi({ - page: paginat.page, - limit: paginat.limit + const res: any = await projectListApi({ + page: paginat.page, + limit: paginat.limit + }) + if (res.data) { + const { count } = res + paginat.count = count + list.value = res.data.map((e: any) => { + const { id, projectName, state, createTime, createUserId } = e + return { + id: id, + title: projectName, + createId: createUserId, + time: createTime, + release: state !== -1 + } }) - if (res.data) { - const { count } = res - paginat.count = count - list.value = res.data.map((e:any) => { - const {id, projectName, state, createTime, createUserId} = e - return { - id: id, - title: projectName, - createId: createUserId, - time: createTime, - release: state !== -1 - } - }) - } - } catch (error) { - window['$message'].error(window['$t']('http.error_message')) } + } // 修改页数 @@ -57,15 +55,22 @@ export const useDataListInit = () => { } // 删除 - const deleteHandle = (cardData: object, index: number) => { + const deleteHandle = (cardData: Chartype, index: number) => { goDialog({ type: DialogEnum.DELETE, promise: true, - onPositiveCallback: () => - new Promise(res => setTimeout(() => res(1), 1000)), - promiseResCallback: (e: any) => { - window['$message'].success('删除成功') - list.value.splice(index, 1) + onPositiveCallback: () => new Promise(res => { + res(deleteProjectApi({ + ids: cardData.id + })) + }), + promiseResCallback: (res: any) => { + if (res.code === ResultEnum.SUCCESS) { + window['$message'].success('删除成功') + fetchList() + return + } + httpErrorHandle() } }) } diff --git a/src/views/project/items/components/ProjectItemsList/index.vue b/src/views/project/items/components/ProjectItemsList/index.vue index 7c969e15..9276347d 100644 --- a/src/views/project/items/components/ProjectItemsList/index.vue +++ b/src/views/project/items/components/ProjectItemsList/index.vue @@ -10,7 +10,7 @@