fix:全局的 delete 封装不正确的问题

This commit is contained in:
YunaiV
2025-12-23 23:32:37 +08:00
parent 99b1f97565
commit 5e457b4afe
4 changed files with 32 additions and 18 deletions

View File

@@ -3,6 +3,18 @@ import { http } from '@/http/http'
import { useTokenStore } from '@/store/token'
import { useUserStore } from '@/store/user'
/** 文件信息 */
export interface FileVO {
id?: number
configId?: number
path: string
name?: string
url?: string
size?: number
type?: string
createTime?: Date
}
/** 文件预签名信息 */
export interface FilePresignedUrlRespVO {
configId: number // 配置编号
@@ -31,6 +43,16 @@ export function createFile(data: FileCreateReqVO) {
return http.post<string>('/infra/file/create', data)
}
/** 获取文件详情 */
export function getFile(id: number) {
return http.get<FileVO>(`/infra/file/get?id=${id}`)
}
/** 删除文件 */
export function deleteFile(id: number) {
return http.delete(`/infra/file/delete?id=${id}`)
}
/**
* 上传文件到后端
*

View File

@@ -45,7 +45,7 @@ export function updateNotifyTemplate(data: NotifyTemplate) {
/** 删除站内信模板 */
export function deleteNotifyTemplate(id: number) {
return http.delete<boolean>(`/system/notify-template/delete`, { id })
return http.delete<boolean>(`/system/notify-template/delete?id=${id}`)
}
/** 发送站内信 */

View File

@@ -143,6 +143,7 @@ export function http<T>(options: CustomRequestOptions) {
* @param url 后台地址
* @param query 请求query参数
* @param header 请求头默认为json格式
* @param options 其他配置项
* @returns
*/
export function httpGet<T>(url: string, query?: Record<string, any>, header?: Record<string, any>, options?: Partial<CustomRequestOptions>) {
@@ -161,6 +162,7 @@ export function httpGet<T>(url: string, query?: Record<string, any>, header?: Re
* @param data 请求body参数
* @param query 请求query参数post请求也支持query很多微信接口都需要
* @param header 请求头默认为json格式
* @param options 其他配置项
* @returns
*/
export function httpPost<T>(url: string, data?: Record<string, any>, query?: Record<string, any>, header?: Record<string, any>, options?: Partial<CustomRequestOptions>) {
@@ -190,9 +192,10 @@ export function httpPut<T>(url: string, data?: Record<string, any>, query?: Reco
/**
* DELETE 请求(无请求体,仅 query
*/
export function httpDelete<T>(url: string, query?: Record<string, any>, header?: Record<string, any>, options?: Partial<CustomRequestOptions>) {
export function httpDelete<T>(url: string, data?: Record<string, any>, query?: Record<string, any>, header?: Record<string, any>, options?: Partial<CustomRequestOptions>) {
return http<T>({
url,
data,
query,
method: 'DELETE',
header,

View File

@@ -51,26 +51,15 @@
</template>
<script lang="ts" setup>
import type { FileVO } from '@/api/infra/file'
import { onMounted, ref } from 'vue'
import { useToast } from 'wot-design-uni'
import { deleteFile, getFile } from '@/api/infra/file'
import { useAccess } from '@/hooks/useAccess'
import { http } from '@/http/http'
import { navigateBackPlus } from '@/utils'
import { formatDateTime } from '@/utils/date'
import { formatFileSize } from '@/utils/download'
/** 文件信息 */
interface FileInfo {
id?: number
configId?: number
path: string
name?: string
url?: string
size?: number
type?: string
createTime?: Date
}
const props = defineProps<{
id?: number | any
}>()
@@ -84,7 +73,7 @@ definePage({
const { hasAccessByCodes } = useAccess()
const toast = useToast()
const formData = ref<FileInfo>()
const formData = ref<FileVO>()
const deleting = ref(false)
/** 返回上一页 */
@@ -99,7 +88,7 @@ async function getDetail() {
}
try {
toast.loading('加载中...')
formData.value = await http.get<FileInfo>(`/infra/file/get?id=${props.id}`)
formData.value = await getFile(props.id)
} finally {
toast.close()
}
@@ -134,7 +123,7 @@ function handleDelete() {
}
deleting.value = true
try {
await http.delete(`/infra/file/delete?id=${props.id}`)
await deleteFile(props.id)
toast.success('删除成功')
setTimeout(() => {
handleBack()