feat: rbac初步对接完成
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
import { post } from '@/lib/request'
|
||||
import { USE_MOCK, delay, paginate, mockId } from '@/mock'
|
||||
import type { SystemOss } from '../system'
|
||||
import type { PageResult } from '@/lib/request'
|
||||
|
||||
const BASE_URL = '/file/oss'
|
||||
|
||||
const mockFiles: SystemOss[] = [
|
||||
{ id: '1', name: 'avatar.jpg', key: 'avatars/1.jpg', url: 'https://images.unsplash.com/photo-1535713875002-d1d0cf377fde?w=800&q=80', suffix: 'jpg', createdAt: new Date().toISOString(), updatedAt: new Date().toISOString() },
|
||||
{ id: '2', name: 'bg.png', key: 'bg/1.png', url: 'https://images.unsplash.com/photo-1451187580459-43490279c0fa?w=800&q=80', suffix: 'png', createdAt: new Date().toISOString(), updatedAt: new Date().toISOString() },
|
||||
]
|
||||
|
||||
export async function getFileList(params: { current: number; pageSize: number; keyword?: string }) {
|
||||
if (USE_MOCK) {
|
||||
await delay()
|
||||
let list = [...mockFiles]
|
||||
if (params.keyword) list = list.filter(f => f.name.includes(params.keyword!))
|
||||
return paginate(list, params.current, params.pageSize)
|
||||
}
|
||||
return post<PageResult<SystemOss>>(`${BASE_URL}/getFileList`, params)
|
||||
}
|
||||
|
||||
export async function uploadFile(_file: File) {
|
||||
if (USE_MOCK) {
|
||||
await delay(1000)
|
||||
const newFile: SystemOss = {
|
||||
id: mockId(), name: _file.name, key: `upload/${_file.name}`,
|
||||
url: URL.createObjectURL(_file), suffix: _file.name.split('.').pop() || '',
|
||||
createdAt: new Date().toISOString(), updatedAt: new Date().toISOString()
|
||||
}
|
||||
mockFiles.unshift(newFile)
|
||||
return { file: newFile }
|
||||
}
|
||||
const formData = new FormData()
|
||||
formData.append('file', _file)
|
||||
return post<{ file: SystemOss }>(`${BASE_URL}/upload`, formData)
|
||||
}
|
||||
|
||||
export async function deleteFile(ids: string[]) {
|
||||
if (USE_MOCK) {
|
||||
await delay()
|
||||
const idSet = new Set(ids)
|
||||
for (let i = mockFiles.length - 1; i >= 0; i--) {
|
||||
if (idSet.has(mockFiles[i].id)) mockFiles.splice(i, 1)
|
||||
}
|
||||
return null
|
||||
}
|
||||
return post<null>(`${BASE_URL}/delete`, { ids })
|
||||
}
|
||||
Reference in New Issue
Block a user