feat: 新增删除接口
This commit is contained in:
parent
09b31547e1
commit
f46e6ad8c8
@ -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)
|
||||
}
|
||||
)
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
@ -2,5 +2,5 @@
|
||||
* * 请求失败统一处理
|
||||
*/
|
||||
export const httpErrorHandle = () => {
|
||||
window['$message'].error('请求失败,请稍后重试!')
|
||||
window['$message'].error(window['$t']('http.error_message'))
|
||||
}
|
@ -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()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -10,7 +10,7 @@
|
||||
<project-items-card
|
||||
:cardData="item"
|
||||
@resize="resizeHandle"
|
||||
@delete="deleteHandle($event, index)"
|
||||
@delete="deleteHandle(item, index)"
|
||||
@edit="editHandle"
|
||||
></project-items-card>
|
||||
</n-grid-item>
|
||||
|
Loading…
x
Reference in New Issue
Block a user