123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- import {
- axios,
- getMediaList,
- getLibraryGroup,
- addGroupUrl,
- deleteGroupUrl,
- getAllGroup,
- uploadMedia,
- editMedia,
- deleteMedia,
- downFile,
- downhash,
- PaggingReq,
- PaggingRes,
- } from "@/request";
- // 媒体库数据类型
- export type Media = {
- id?: string;
- dictName: string;
- fileTypeStr: string;
- fileFormat: string;
- fileSize: string;
- dictId: Number | string;
- status: string | number;
- fileType: string;
- dictNameStr: string;
- createTime: string;
- updateTime: string;
- };
- // 媒体库分页查询参数类型
- type MediaPaggingParams = PaggingReq<{
- name: string;
- fileType: string; // 确保这里有 fileType 字段
- dictId: Number | string; // 分组ID
- }>;
- // 获取媒体库列表数据
- export const getMediaPagging = async (params: MediaPaggingParams) =>
- (await axios.post(getMediaList, params)).data as PaggingRes<Media>;
- // 获取分组列表
- export const getGroupList = async ({type, pageNum, pageSize}) =>
- (await axios.get(getLibraryGroup, { params: { type, pageNum, pageSize } })).data;
- // 获取所有分组列表
- export const getAllGroupList = async (params) =>
- (await axios.post(getAllGroup, params)).data;
- // 新增分组
- export const addGroupItem = async (dictName: string) =>
- (await axios.post(addGroupUrl, { dictName })).data;
- // 删除分组
- export const deleteGroupItem = async (dictId: Number | string) =>
- (await axios.post(deleteGroupUrl, { id: dictId })).data;
- // 上传媒体
- export const uploadNewMedia = async (formData) => {
- return (await axios.post(uploadMedia, formData)).data;
- }
- // 编辑媒体
- export const editMediaItem = async (formData) => {
- return (await axios.post(editMedia, formData)).data;
- }
- // 删除媒体
- export const deleteMediaItem = async (id) =>
- (await axios.post(deleteMedia, { id })).data;
- // 下载媒体
- export const downloadMedia = async (id) => {
- const response = await axios.get(downFile, { params: {dictFileId: id} });
- if (response.data) {
- // 创建一个隐藏的a标签
- const link = document.createElement('a');
- link.href = response.data;
- // 从URL中提取文件名
- const fileName = response.data.split('/').pop() || `file_${id}`;
- link.setAttribute('download', fileName);
- document.body.appendChild(link);
- link.click();
- document.body.removeChild(link);
- }
- return response.data;
- }
- // 下载hash
- export const downloadHash = async (id) => {
- const response = await axios.get(downhash, { params: {dictFileId: id} });
- if (response.data) {
- // 创建一个隐藏的a标签
- const link = document.createElement('a');
- link.href = response.data;
- // 从URL中提取文件名
- const fileName = response.data.split('/').pop() || `hash_${id}.txt`;
- link.setAttribute('download', fileName);
- document.body.appendChild(link);
- link.click();
- document.body.removeChild(link);
- }
- return response.data;
- }
|