大改动
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import Request from "@/utils/request";
|
||||
import { Article } from "@/types/app/article";
|
||||
import { getListAPI } from "@/utils";
|
||||
|
||||
// 新增文章
|
||||
export const addArticleDataAPI = (data: Article) =>
|
||||
@@ -16,22 +17,24 @@ export const editArticleDataAPI = (data: Article) =>
|
||||
// 获取文章
|
||||
export const getArticleDataAPI = (id?: number) => Request<Article>("GET", `/article/${id}`)
|
||||
|
||||
// export const getArticleListAPI = (data?: QueryData) => {
|
||||
// if (data?.pagination) {
|
||||
// return Request<Paginate<Article[]>>("POST", `/article/paging`, {
|
||||
// data: { ...data?.query },
|
||||
// params: {
|
||||
// sort: data.sort,
|
||||
// ...data.pagination
|
||||
// }
|
||||
// });
|
||||
// } else {
|
||||
// return Request<Article[]>("POST", `/article/list`, {
|
||||
// data: { ...data?.query },
|
||||
// params: {
|
||||
// sort: data?.sort
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// };
|
||||
|
||||
// 获取文章列表
|
||||
export const getArticleListAPI = (data?: QueryData) => {
|
||||
if (data?.pagination) {
|
||||
return Request<Paginate<Article[]>>("POST", `/article/paging`, {
|
||||
data: { ...data?.query },
|
||||
params: {
|
||||
sort: data.sort,
|
||||
...data.pagination
|
||||
}
|
||||
});
|
||||
} else {
|
||||
return Request<Article[]>("POST", `/article/list`, {
|
||||
data: { ...data?.query },
|
||||
params: {
|
||||
sort: data?.sort
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
export const getArticleListAPI = (data?: QueryData) => getListAPI<Article>("/article", data)
|
||||
@@ -15,21 +15,4 @@ export const editCateDataAPI = (data: Cate) => Request<Cate>("PATCH", "/cate", {
|
||||
export const getCateDataAPI = (id?: number) => Request<Cate>("GET", `/cate/${id}`)
|
||||
|
||||
// 获取分类列表
|
||||
export const getCateListAPI = (data?: QueryData) => {
|
||||
if (data?.pagination) {
|
||||
return Request<Paginate<Cate[]>>("POST", `/cate/paging`, {
|
||||
data: { ...data?.query },
|
||||
params: {
|
||||
sort: data.sort,
|
||||
...data.pagination
|
||||
}
|
||||
});
|
||||
} else {
|
||||
return Request<Cate[]>("POST", `/cate/list`, {
|
||||
data: { ...data?.query },
|
||||
params: {
|
||||
sort: data?.sort
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
export const getCateListAPI = (data?: QueryData) => getListAPI<Cate>("/cate", data)
|
||||
@@ -18,21 +18,4 @@ export const editCommentDataAPI = (data: Comment) => Request<Comment>("PATCH", "
|
||||
export const getCommentDataAPI = (id?: number) => Request<Paginate<Comment>>("GET", `/comment/${id}`)
|
||||
|
||||
// 获取评论列表
|
||||
export const getCommentListAPI = (data?: QueryData) => {
|
||||
if (data?.pagination) {
|
||||
return Request<Paginate<Comment[]>>("POST", `/comment/paging`, {
|
||||
data: { ...data?.query },
|
||||
params: {
|
||||
sort: data.sort,
|
||||
...data.pagination
|
||||
}
|
||||
});
|
||||
} else {
|
||||
return Request<Comment[]>("POST", `/comment/list`, {
|
||||
data: { ...data?.query },
|
||||
params: {
|
||||
sort: data?.sort
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
export const getCommentListAPI = (data?: QueryData) => getListAPI<Comment>("/comment", data)
|
||||
@@ -1,5 +1,6 @@
|
||||
import Request from '@/utils/request'
|
||||
import { File } from '@/types/app/file'
|
||||
import { getListAPI } from '@/utils'
|
||||
|
||||
// 删除文件
|
||||
export const delFileDataAPI = (filePath: string) => Request<File>("DELETE", `/file?filePath=${filePath}`)
|
||||
@@ -8,23 +9,7 @@ export const delFileDataAPI = (filePath: string) => Request<File>("DELETE", `/fi
|
||||
export const getFileDataAPI = (filePath: string) => Request<File>("GET", `/file/info?filePath=${filePath}`)
|
||||
|
||||
// 获取文件列表
|
||||
export const getFileListAPI = (data?: QueryData) => {
|
||||
if (data?.pagination) {
|
||||
let sort = data?.sort ? `?sort=${data?.sort}` : '?'
|
||||
let dir = data?.dir ? `dir=${data?.dir}` : ''
|
||||
const { page, size } = data.pagination
|
||||
const pagination = page && size ? `&page=${page}&size=${size}` : page && !size ? `&page=${page}` : size && !page ? `&size=${size}` : ''
|
||||
if (!dir && !pagination) sort = ''
|
||||
|
||||
return Request<Paginate<File[]>>("GET", `/file${sort}${pagination}${dir}`);
|
||||
} else {
|
||||
let sort = data?.sort ? `?sort=${data?.sort}` : '?'
|
||||
let dir = data?.dir ? `dir=${data?.dir}` : ''
|
||||
if (!dir) sort = ''
|
||||
|
||||
return Request<File[]>("GET", `/file/all${sort}${dir}`);
|
||||
}
|
||||
};
|
||||
export const getFileListAPI = (data?: QueryData) => getListAPI<File>("/file", data)
|
||||
|
||||
// 获取目录列表
|
||||
export const getDirListAPI = () => Request<string[]>("GET", '/file/dir');;
|
||||
@@ -2,4 +2,4 @@ import { Rss } from '@/types/app/rss';
|
||||
import { getListAPI } from '@/utils';
|
||||
|
||||
// 获取订阅数据列表
|
||||
export const getRssListAPI = getListAPI<Rss>("/rss")
|
||||
export const getRssListAPI = (data?: QueryData) => getListAPI<Rss>("/rss", data)
|
||||
@@ -15,4 +15,5 @@ export const editSwiperDataAPI = (data: Swiper) => Request<Swiper>("PATCH", "/sw
|
||||
export const getSwiperDataAPI = (id?: number) => Request<Swiper>("GET", `/swiper/${id}`)
|
||||
|
||||
// 获取轮播图列表
|
||||
export const getSwiperListAPI = getListAPI<Swiper>("/swiper")
|
||||
// export const getSwiperListAPI = getListAPI<Swiper>("/swiper")
|
||||
export const getSwiperListAPI = (data?: QueryData) => getListAPI<Swiper>("/swiper", data)
|
||||
@@ -15,4 +15,4 @@ export const editTagDataAPI = (data: Tag) => Request<Tag>("PATCH", "/tag", { dat
|
||||
export const getTagDataAPI = (id?: number) => Request<Tag>("GET", `/tag/${id}`)
|
||||
|
||||
// 获取标签列表
|
||||
export const getTagListAPI = getListAPI<Tag>("/tag")
|
||||
export const getTagListAPI = (data?: QueryData) => getListAPI<Tag>("/tag", data)
|
||||
@@ -15,7 +15,7 @@ export const editLinkDataAPI = (data: Web) => Request<Web>("PATCH", "/link", { d
|
||||
export const getLinkDataAPI = (id?: number) => Request<Web>("GET", `/link/${id}`)
|
||||
|
||||
// 获取网站列表
|
||||
export const getLinkListAPI = getListAPI<Web>("/link")
|
||||
export const getLinkListAPI = (data?: QueryData) => getListAPI<Web>("/link", data)
|
||||
|
||||
// 获取网站类型列表
|
||||
export const getLinkTypeListAPI = () => {
|
||||
|
||||
@@ -6,6 +6,7 @@ import { useUserStore } from '@/stores';
|
||||
import { baseURL } from '@/utils/request';
|
||||
import Compressor from 'compressorjs';
|
||||
import { useState } from 'react';
|
||||
import { UploadFile } from 'antd/es/upload';
|
||||
|
||||
const { Dragger } = Upload;
|
||||
|
||||
@@ -20,7 +21,9 @@ export default ({ dir, open, onCancel, onSuccess }: UploadFileProps) => {
|
||||
const store = useUserStore();
|
||||
const [quality, setQuality] = useState(1000);
|
||||
const [isCompressionUpload, setIsCompressionUpload] = useState(false);
|
||||
const [isLoading, setIsLoading] = useState(false); // 添加加载状态
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
|
||||
const [fileList, setFileList] = useState<UploadFile[]>([]);
|
||||
|
||||
const uploadProps: UploadProps = {
|
||||
name: 'files',
|
||||
@@ -30,63 +33,74 @@ export default ({ dir, open, onCancel, onSuccess }: UploadFileProps) => {
|
||||
headers: {
|
||||
"Authorization": `Bearer ${store.token}`
|
||||
},
|
||||
showUploadList: false, // 不显示文件列表
|
||||
showUploadList: true,
|
||||
async onChange(info) {
|
||||
const { status } = info.file;
|
||||
const { status, response } = info.file;
|
||||
|
||||
let res;
|
||||
if (status !== 'uploading') {
|
||||
res = info?.file?.response;
|
||||
if (status !== 'uploading' && response?.code === 400) return message.error(response.message);
|
||||
|
||||
setFileList(info.fileList);
|
||||
|
||||
if (res?.code === 400) return message.error(res.message);
|
||||
}
|
||||
if (status === 'done') {
|
||||
// // 复制文件链接到剪贴板
|
||||
await navigator.clipboard.writeText(res.data.join("\n"));
|
||||
console.log(5555, res.data.join("\n"));
|
||||
|
||||
message.success(`🎉 文件上传成功,URL链接已复制到剪贴板`);
|
||||
onSuccess(res.data.join("\n"));
|
||||
onCloseModel()
|
||||
message.success(`${info.file.name} 文件上传成功`);
|
||||
} else if (status === 'error') {
|
||||
message.error(`文件上传失败:${res?.message}`);
|
||||
message.error(`${info.file.name} 文件上传失败`);
|
||||
setIsLoading(false);
|
||||
return
|
||||
}
|
||||
|
||||
// setIsLoading(false); // 结束加载状态
|
||||
// if (info.fileList.some(file => file.status === "error")) {
|
||||
// message.error(`${info.file.name} 文件上传失败`);
|
||||
// setIsLoading(false);
|
||||
// return
|
||||
// }
|
||||
|
||||
// 所有文件的状态都不为uploading就证明上传成功
|
||||
if (info.fileList.every(file => file.status !== 'uploading')) {
|
||||
// 等待所有请求完毕后再执行
|
||||
const allResponses = await info.fileList.map(file => file.response?.data).filter(data => data);
|
||||
const data = await allResponses.flat().join("\n");
|
||||
|
||||
// 把数据写入到剪贴板
|
||||
await navigator.clipboard.writeText(data);
|
||||
message.success(`🎉 文件上传成功,URL链接已复制到剪贴板`);
|
||||
onSuccess(data);
|
||||
setIsLoading(false);
|
||||
onCloseModel();
|
||||
}
|
||||
},
|
||||
beforeUpload: async (file) => {
|
||||
setIsLoading(true); // 开始加载状态
|
||||
setIsLoading(true);
|
||||
|
||||
if (quality === 1000) return file
|
||||
if (quality === 1000) return file;
|
||||
|
||||
// 对图片进行压缩处理
|
||||
return new Promise((resolve, reject) => {
|
||||
new Compressor(file, {
|
||||
quality,
|
||||
success: (file) => {
|
||||
resolve(file);
|
||||
success: (compressedFile) => {
|
||||
resolve(compressedFile);
|
||||
},
|
||||
error: (err) => {
|
||||
reject(err);
|
||||
},
|
||||
});
|
||||
})
|
||||
});
|
||||
},
|
||||
className: "py-4"
|
||||
};
|
||||
|
||||
// 初始化操作
|
||||
const onCloseModel = () => {
|
||||
setIsCompressionUpload(false);
|
||||
setQuality(1000);
|
||||
setIsLoading(false); // 确保关闭时停止加载状态
|
||||
setIsLoading(false);
|
||||
setFileList([]);
|
||||
onCancel();
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Modal title="文件上传" open={open} onCancel={onCloseModel} footer={null}>
|
||||
<Spin spinning={isLoading}> {/* 包裹内容的 Spin 组件 */}
|
||||
<Spin spinning={isLoading}>
|
||||
<div className='my-4'>
|
||||
<Radio.Group defaultValue={0} value={isCompressionUpload ? 1 : 0} onChange={(e) => setIsCompressionUpload(e.target.value ? true : false)}>
|
||||
<Radio value={0}>无损上传</Radio>
|
||||
@@ -115,7 +129,7 @@ export default ({ dir, open, onCancel, onSuccess }: UploadFileProps) => {
|
||||
}
|
||||
</div>
|
||||
|
||||
<Dragger {...uploadProps}>
|
||||
<Dragger {...uploadProps} fileList={fileList}>
|
||||
<p className="ant-upload-drag-icon">
|
||||
<InboxOutlined />
|
||||
</p>
|
||||
|
||||
@@ -23,10 +23,11 @@ const CommentPage = () => {
|
||||
setLoading(false)
|
||||
}
|
||||
|
||||
const auditCommentData = async (id: number) => {
|
||||
const auditCommentData = async () => {
|
||||
setLoading(true)
|
||||
await auditCommentDataAPI(id);
|
||||
await auditCommentDataAPI(comment?.id!);
|
||||
getCommentList();
|
||||
setIsModalOpen(false)
|
||||
message.success('🎉 审核评论成功');
|
||||
};
|
||||
|
||||
@@ -155,7 +156,7 @@ const CommentPage = () => {
|
||||
: <Tag bordered={false} color="error">待审核</Tag>}
|
||||
</div>
|
||||
|
||||
{!comment?.auditStatus ? <Button type="primary" className='w-full !mt-4' onClick={() => auditCommentData(1)}>通过审核</Button> : null}
|
||||
{!comment?.auditStatus ? <Button type="primary" className='w-full !mt-4' onClick={auditCommentData}>通过审核</Button> : null}
|
||||
</div>
|
||||
</Modal>
|
||||
</>
|
||||
|
||||
@@ -10,63 +10,21 @@ export const ObjectToUrlParam = (obj: Object): string => {
|
||||
).toString();
|
||||
}
|
||||
|
||||
// 查询数据相关逻辑
|
||||
// export const getListAPI = <T>(api: string) => {
|
||||
// return (data?: QueryData) => {
|
||||
// if (data?.pagination) {
|
||||
// let sort = data?.sort ? `?sort=${data?.sort}` : '?'
|
||||
// const query = ObjectToUrlParam(data?.query as FilterData) ? "&" + ObjectToUrlParam(data?.query as FilterData) : ''
|
||||
// const { page, size } = data.pagination
|
||||
// const pagination = page && size ? `&page=${page}&size=${size}` : page && !size ? `&page=${page}` : size && !page ? `&size=${size}` : ''
|
||||
// if (!query && !pagination) sort = ''
|
||||
|
||||
// return Request<Paginate<T[]>>("GET", `${api}${sort}${pagination}${query}`);
|
||||
// } else {
|
||||
// return Request<T[]>("GET", `${api}/all`, {
|
||||
// sort: data?.sort,
|
||||
// pattern: data?.pattern,
|
||||
// ...data?.query
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
|
||||
const buildQueryParams = (params: Record<string, any>): string => {
|
||||
return Object.entries(params)
|
||||
.filter(([_, value]) => value !== undefined && value !== null)
|
||||
.map(([key, value]) => {
|
||||
if (Array.isArray(value)) {
|
||||
return `${encodeURIComponent(key)}=${encodeURIComponent(JSON.stringify(value))}`;
|
||||
export const getListAPI = <T>(api: string, data?: QueryData) => {
|
||||
if (data?.pagination) {
|
||||
return Request<Paginate<T[]>>("POST", `${api}/paging`, {
|
||||
data: { ...data?.query },
|
||||
params: {
|
||||
sort: data.sort,
|
||||
...data.pagination
|
||||
}
|
||||
return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
|
||||
})
|
||||
.join('&');
|
||||
};
|
||||
|
||||
export const getListAPI = <T>(api: string) => {
|
||||
return (data?: QueryData) => {
|
||||
let queryParams: Record<string, any> = {};
|
||||
|
||||
if (data?.sort) {
|
||||
queryParams.sort = data.sort;
|
||||
}
|
||||
|
||||
if (data?.query) {
|
||||
queryParams = { ...queryParams, ...data.query };
|
||||
}
|
||||
|
||||
if (data?.pagination) {
|
||||
const { page, size } = data.pagination;
|
||||
if (page) queryParams.page = page;
|
||||
if (size) queryParams.size = size;
|
||||
}
|
||||
|
||||
const queryString = buildQueryParams(queryParams);
|
||||
|
||||
if (data?.pagination) {
|
||||
return Request<Paginate<T[]>>("GET", `${api}?${queryString}`);
|
||||
} else {
|
||||
return Request<T[]>("GET", `${api}/all?${queryString}`);
|
||||
}
|
||||
};
|
||||
});
|
||||
} else {
|
||||
return Request<T[]>("POST", `${api}/list`, {
|
||||
data: { ...data?.query },
|
||||
params: {
|
||||
sort: data?.sort
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user