feat: 本次提交更新内容如下
eslint规则校验
This commit is contained in:
@@ -117,7 +117,7 @@ export default function AccountSelection({
|
||||
acc =>
|
||||
acc.userName.includes(searchQuery) ||
|
||||
acc.realName.includes(searchQuery) ||
|
||||
acc.departmentName.includes(searchQuery)
|
||||
acc.departmentName.includes(searchQuery),
|
||||
);
|
||||
|
||||
// 处理账号选择
|
||||
|
||||
@@ -58,7 +58,7 @@ interface ContentLibrarySelectionProps {
|
||||
readonly?: boolean;
|
||||
onConfirm?: (
|
||||
selectedIds: string[],
|
||||
selectedItems: ContentLibraryItem[]
|
||||
selectedItems: ContentLibraryItem[],
|
||||
) => void;
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ export default function ContentLibrarySelection({
|
||||
|
||||
// 获取已选内容库详细信息
|
||||
const selectedLibraryObjs = libraries.filter(item =>
|
||||
selectedLibraries.includes(item.id)
|
||||
selectedLibraries.includes(item.id),
|
||||
);
|
||||
|
||||
// 删除已选内容库
|
||||
@@ -132,7 +132,7 @@ export default function ContentLibrarySelection({
|
||||
const fetchLibraries = async (page: number, keyword: string = "") => {
|
||||
setLoading(true);
|
||||
try {
|
||||
let params: any = {
|
||||
const params: any = {
|
||||
page,
|
||||
limit: 20,
|
||||
};
|
||||
@@ -161,7 +161,7 @@ export default function ContentLibrarySelection({
|
||||
onSelect(newSelected);
|
||||
if (onSelectDetail) {
|
||||
const selectedObjs = libraries.filter(item =>
|
||||
newSelected.includes(item.id)
|
||||
newSelected.includes(item.id),
|
||||
);
|
||||
onSelectDetail(selectedObjs);
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ const SelectionPopup: React.FC<SelectionPopupProps> = ({
|
||||
wxid: d.wechatId || "",
|
||||
nickname: d.nickname || "",
|
||||
usedInPlans: d.usedInPlans || 0,
|
||||
}))
|
||||
})),
|
||||
);
|
||||
setTotal(res.total || 0);
|
||||
}
|
||||
@@ -71,7 +71,7 @@ const SelectionPopup: React.FC<SelectionPopupProps> = ({
|
||||
setLoading(false);
|
||||
}
|
||||
},
|
||||
[]
|
||||
[],
|
||||
);
|
||||
|
||||
// 打开弹窗时获取第一页
|
||||
|
||||
@@ -98,7 +98,7 @@ export default function FriendSelection({
|
||||
const fetchFriends = async (page: number, keyword: string = "") => {
|
||||
setLoading(true);
|
||||
try {
|
||||
let params: any = {
|
||||
const params: any = {
|
||||
page,
|
||||
limit: 20,
|
||||
};
|
||||
@@ -137,7 +137,7 @@ export default function FriendSelection({
|
||||
// 如果有 onSelectDetail 回调,传递完整的好友对象
|
||||
if (onSelectDetail) {
|
||||
const selectedFriendObjs = friends.filter(friend =>
|
||||
newSelectedFriends.includes(friend.id)
|
||||
newSelectedFriends.includes(friend.id),
|
||||
);
|
||||
onSelectDetail(selectedFriendObjs);
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ export default function GroupSelection({
|
||||
|
||||
// 获取已选群聊详细信息
|
||||
const selectedGroupObjs = groups.filter(group =>
|
||||
selectedGroups.includes(group.id)
|
||||
selectedGroups.includes(group.id),
|
||||
);
|
||||
|
||||
// 删除已选群聊
|
||||
@@ -106,7 +106,7 @@ export default function GroupSelection({
|
||||
const fetchGroups = async (page: number, keyword: string = "") => {
|
||||
setLoading(true);
|
||||
try {
|
||||
let params: any = {
|
||||
const params: any = {
|
||||
page,
|
||||
limit: 20,
|
||||
};
|
||||
@@ -141,7 +141,7 @@ export default function GroupSelection({
|
||||
// 如果有 onSelectDetail 回调,传递完整的群聊对象
|
||||
if (onSelectDetail) {
|
||||
const selectedGroupObjs = groups.filter(group =>
|
||||
newSelectedGroups.includes(group.id)
|
||||
newSelectedGroups.includes(group.id),
|
||||
);
|
||||
onSelectDetail(selectedGroupObjs);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ const Layout: React.FC<LayoutProps> = ({
|
||||
const setRealHeight = () => {
|
||||
document.documentElement.style.setProperty(
|
||||
"--real-vh",
|
||||
`${window.innerHeight * 0.01}px`
|
||||
`${window.innerHeight * 0.01}px`,
|
||||
);
|
||||
};
|
||||
setRealHeight();
|
||||
|
||||
@@ -54,11 +54,50 @@ const VideoUpload: React.FC<VideoUploadProps> = ({
|
||||
};
|
||||
|
||||
// 处理文件变化
|
||||
const handleChange: UploadProps["onChange"] = info => {
|
||||
const handleChange: UploadProps["onChange"] = async info => {
|
||||
if (info.file.status === "uploading") {
|
||||
setLoading(true);
|
||||
|
||||
// 在这里处理文件上传
|
||||
try {
|
||||
const formData = new FormData();
|
||||
formData.append("file", info.file.originFileObj as File);
|
||||
|
||||
const response = await request(
|
||||
"/v1/attachment/upload",
|
||||
formData,
|
||||
"POST",
|
||||
);
|
||||
|
||||
if (response) {
|
||||
const uploadedUrl =
|
||||
typeof response === "string" ? response : response.url || response;
|
||||
|
||||
// 更新文件状态
|
||||
const updatedFile = {
|
||||
...info.file,
|
||||
status: "done" as const,
|
||||
url: uploadedUrl,
|
||||
};
|
||||
|
||||
// 更新fileList
|
||||
setFileList([updatedFile]);
|
||||
// 调用onChange
|
||||
onChange?.(uploadedUrl);
|
||||
|
||||
setLoading(false);
|
||||
message.success("上传成功");
|
||||
} else {
|
||||
throw new Error("上传失败");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("上传失败:", error);
|
||||
message.error("上传失败,请重试");
|
||||
setLoading(false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (info.file.status === "done") {
|
||||
setLoading(false);
|
||||
// 更新fileList
|
||||
@@ -68,35 +107,6 @@ const VideoUpload: React.FC<VideoUploadProps> = ({
|
||||
}
|
||||
};
|
||||
|
||||
// 自定义上传请求
|
||||
const customRequest: UploadProps["customRequest"] = async ({
|
||||
file,
|
||||
onSuccess,
|
||||
onError,
|
||||
}) => {
|
||||
try {
|
||||
setLoading(true);
|
||||
const formData = new FormData();
|
||||
formData.append("file", file as File);
|
||||
|
||||
const response = await request("/v1/attachment/upload", formData, "POST");
|
||||
|
||||
if (response) {
|
||||
const uploadedUrl =
|
||||
typeof response === "string" ? response : response.url || response;
|
||||
onSuccess?.(uploadedUrl);
|
||||
} else {
|
||||
throw new Error("上传失败");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("上传失败:", error);
|
||||
onError?.(error as Error);
|
||||
message.error("上传失败,请重试");
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// 删除文件
|
||||
const handleRemove = () => {
|
||||
setFileList([]);
|
||||
@@ -131,7 +141,6 @@ const VideoUpload: React.FC<VideoUploadProps> = ({
|
||||
showUploadList={true}
|
||||
disabled={disabled || loading}
|
||||
beforeUpload={beforeUpload}
|
||||
customRequest={customRequest}
|
||||
onChange={handleChange}
|
||||
onRemove={handleRemove}
|
||||
>
|
||||
|
||||
6
nkebao/src/components/Upload/api.ts
Normal file
6
nkebao/src/components/Upload/api.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import request from "@/api/request";
|
||||
|
||||
// 创建素材
|
||||
export function createContentItem(params: any) {
|
||||
return request("/v1/content/library/create-item", params, "POST");
|
||||
}
|
||||
@@ -60,11 +60,61 @@ const UploadComponent: React.FC<UploadComponentProps> = ({
|
||||
};
|
||||
|
||||
// 处理文件变化
|
||||
const handleChange: UploadProps["onChange"] = info => {
|
||||
const handleChange: UploadProps["onChange"] = async info => {
|
||||
console.log(info);
|
||||
|
||||
if (info.file.status === "uploading") {
|
||||
setLoading(true);
|
||||
|
||||
// 在这里处理文件上传
|
||||
try {
|
||||
const formData = new FormData();
|
||||
formData.append("file", info.file.originFileObj as File);
|
||||
|
||||
const response = await request(
|
||||
"/v1/attachment/upload",
|
||||
formData,
|
||||
"POST",
|
||||
);
|
||||
|
||||
if (response) {
|
||||
const uploadedUrl =
|
||||
typeof response === "string" ? response : response.url || response;
|
||||
|
||||
// 更新文件状态
|
||||
const updatedFile = {
|
||||
...info.file,
|
||||
status: "done" as const,
|
||||
url: uploadedUrl,
|
||||
};
|
||||
|
||||
// 更新fileList
|
||||
const newFileList = [...fileList];
|
||||
const fileIndex = newFileList.findIndex(f => f.uid === info.file.uid);
|
||||
if (fileIndex > -1) {
|
||||
newFileList[fileIndex] = updatedFile;
|
||||
} else {
|
||||
newFileList.push(updatedFile);
|
||||
}
|
||||
setFileList(newFileList);
|
||||
|
||||
// 调用onChange
|
||||
const urls = newFileList.map(f => f.url).filter(Boolean) as string[];
|
||||
onChange?.(urls);
|
||||
|
||||
setLoading(false);
|
||||
message.success("上传成功");
|
||||
} else {
|
||||
throw new Error("上传失败");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("上传失败:", error);
|
||||
message.error("上传失败,请重试");
|
||||
setLoading(false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (info.file.status === "done") {
|
||||
setLoading(false);
|
||||
// 更新fileList
|
||||
@@ -83,36 +133,6 @@ const UploadComponent: React.FC<UploadComponentProps> = ({
|
||||
}
|
||||
};
|
||||
|
||||
// 自定义上传请求
|
||||
const customRequest: UploadProps["customRequest"] = async ({
|
||||
file,
|
||||
onSuccess,
|
||||
onError,
|
||||
onProgress,
|
||||
}) => {
|
||||
try {
|
||||
setLoading(true);
|
||||
const formData = new FormData();
|
||||
formData.append("file", file as File);
|
||||
|
||||
const response = await request("/v1/attachment/upload", formData, "POST");
|
||||
|
||||
if (response) {
|
||||
const uploadedUrl =
|
||||
typeof response === "string" ? response : response.url || response;
|
||||
onSuccess?.(uploadedUrl);
|
||||
} else {
|
||||
throw new Error("上传失败");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("上传失败:", error);
|
||||
onError?.(error as Error);
|
||||
message.error("上传失败,请重试");
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// 删除文件
|
||||
const handleRemove = (file: UploadFile) => {
|
||||
const newFileList = fileList.filter(f => f.uid !== file.uid);
|
||||
@@ -151,7 +171,6 @@ const UploadComponent: React.FC<UploadComponentProps> = ({
|
||||
showUploadList={true}
|
||||
disabled={disabled || loading}
|
||||
beforeUpload={beforeUpload}
|
||||
customRequest={customRequest}
|
||||
onChange={handleChange}
|
||||
onRemove={handleRemove}
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user