mirror of
https://github.com/SECTL/SecScore.git
synced 2026-07-21 18:19:03 +08:00
feat: 头像设置支持从剪贴板导入图片
This commit is contained in:
@@ -14,7 +14,7 @@ import {
|
||||
Select,
|
||||
} from "antd"
|
||||
import type { ColumnsType } from "antd/es/table"
|
||||
import { UploadOutlined, MoreOutlined, PlusOutlined } from "@ant-design/icons"
|
||||
import { UploadOutlined, MoreOutlined, PlusOutlined, CopyOutlined } from "@ant-design/icons"
|
||||
import { useTranslation } from "react-i18next"
|
||||
import { TagEditorDialog } from "./TagEditorDialog"
|
||||
import { getAvatarFromExtraJson, setAvatarInExtraJson } from "../utils/studentAvatar"
|
||||
@@ -720,6 +720,28 @@ export const StudentManager: React.FC<{ canEdit: boolean }> = ({ canEdit }) => {
|
||||
}
|
||||
}
|
||||
|
||||
const handleAvatarPasteFromClipboard = async () => {
|
||||
if (typeof navigator === "undefined" || !navigator.clipboard?.read) {
|
||||
messageApi.error(t("students.avatarClipboardUnsupported"))
|
||||
return
|
||||
}
|
||||
try {
|
||||
const clipboardItems = await navigator.clipboard.read()
|
||||
for (const item of clipboardItems) {
|
||||
const imageType = item.types.find((type) => type.startsWith("image/"))
|
||||
if (!imageType) continue
|
||||
const blob = await item.getType(imageType)
|
||||
const ext = imageType.split("/")[1] || "png"
|
||||
const file = new File([blob], `avatar-clipboard.${ext}`, { type: imageType })
|
||||
await handleAvatarFileChange(file)
|
||||
return
|
||||
}
|
||||
messageApi.warning(t("students.avatarClipboardNoImage"))
|
||||
} catch {
|
||||
messageApi.error(t("students.avatarClipboardReadFailed"))
|
||||
}
|
||||
}
|
||||
|
||||
const handleSaveAvatar = async () => {
|
||||
if (!(window as any).api || !avatarStudent) return
|
||||
|
||||
@@ -2197,6 +2219,13 @@ export const StudentManager: React.FC<{ canEdit: boolean }> = ({ canEdit }) => {
|
||||
>
|
||||
{t("students.avatarUpload")}
|
||||
</Button>
|
||||
<Button
|
||||
icon={<CopyOutlined />}
|
||||
onClick={handleAvatarPasteFromClipboard}
|
||||
disabled={!canEdit}
|
||||
>
|
||||
{t("students.avatarClipboardImport")}
|
||||
</Button>
|
||||
<Button onClick={() => setAvatarValue(null)} disabled={!canEdit}>
|
||||
{t("students.avatarClear")}
|
||||
</Button>
|
||||
|
||||
Reference in New Issue
Block a user